Add camel_imapx_command_failed().
authorMatthew Barnes <mbarnes@redhat.com>
Mon, 12 Aug 2013 10:26:24 +0000 (06:26 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Mon, 12 Aug 2013 11:23:01 +0000 (07:23 -0400)
Sets an error to return in camel_imapx_command_set_error_if_failed().
Call this function if a networking or parsing error occurred to force
all active IMAP commands to abort processing.

camel/camel-imapx-command.c
camel/camel-imapx-command.h
docs/reference/camel/camel-sections.txt

index d297b56..11338f6 100644 (file)
@@ -42,6 +42,9 @@ struct _CamelIMAPXRealCommand {
        /* For building the part. */
        GString *buffer;
 
+       /* For network/parse errors. */
+       GError *error;
+
        /* Used for running some commands synchronously. */
        GCond done_sync_cond;
        GMutex done_sync_mutex;
@@ -141,6 +144,8 @@ camel_imapx_command_unref (CamelIMAPXCommand *ic)
 
                g_string_free (real_ic->buffer, TRUE);
 
+               g_clear_error (&real_ic->error);
+
                g_cond_clear (&real_ic->done_sync_cond);
                g_mutex_clear (&real_ic->done_sync_mutex);
 
@@ -577,12 +582,50 @@ camel_imapx_command_done (CamelIMAPXCommand *ic)
        g_mutex_unlock (&real_ic->done_sync_mutex);
 }
 
+/**
+ * camel_imapx_command_failed:
+ * @ic: a #CamelIMAPXCommand
+ * @error: the error which caused the failure
+ *
+ * Copies @error to be returned in camel_imapx_command_set_error_if_failed().
+ * Call this function if a networking or parsing error occurred to force all
+ * active IMAP commands to abort processing.
+ *
+ * Since: 3.10
+ **/
+void
+camel_imapx_command_failed (CamelIMAPXCommand *ic,
+                            const GError *error)
+{
+       CamelIMAPXRealCommand *real_ic;
+
+       g_return_if_fail (CAMEL_IS_IMAPX_COMMAND (ic));
+       g_return_if_fail (error != NULL);
+
+       real_ic = (CamelIMAPXRealCommand *) ic;
+       g_return_if_fail (real_ic->error == NULL);
+
+       real_ic->error = g_error_copy (error);
+}
+
 gboolean
 camel_imapx_command_set_error_if_failed (CamelIMAPXCommand *ic,
                                          GError **error)
 {
+       CamelIMAPXRealCommand *real_ic;
+
        g_return_val_if_fail (CAMEL_IS_IMAPX_COMMAND (ic), FALSE);
 
+       real_ic = (CamelIMAPXRealCommand *) ic;
+
+       /* Check for a networking or parsing error. */
+       if (real_ic->error != NULL) {
+               g_propagate_error (error, real_ic->error);
+               real_ic->error = NULL;
+               return TRUE;
+       }
+
+       /* Check if the IMAP server rejected the command. */
        if (ic->status != NULL && ic->status->result != IMAPX_OK) {
 
                /* FIXME Map IMAP response codes to more
index ac9e77b..ecaa8ea 100644 (file)
@@ -120,6 +120,8 @@ void                camel_imapx_command_add_part    (CamelIMAPXCommand *ic,
 void           camel_imapx_command_close       (CamelIMAPXCommand *ic);
 void           camel_imapx_command_wait        (CamelIMAPXCommand *ic);
 void           camel_imapx_command_done        (CamelIMAPXCommand *ic);
+void           camel_imapx_command_failed      (CamelIMAPXCommand *ic,
+                                                const GError *error);
 gboolean       camel_imapx_command_set_error_if_failed
                                                (CamelIMAPXCommand *ic,
                                                 GError **error);
index ae71fb4..6b9d327 100644 (file)
@@ -754,6 +754,7 @@ camel_imapx_command_add_part
 camel_imapx_command_close
 camel_imapx_command_wait
 camel_imapx_command_done
+camel_imapx_command_failed
 camel_imapx_command_set_error_if_failed
 CamelIMAPXCommandQueue
 camel_imapx_command_queue_new