[evolution-kolab] CamelIMAPXExtdServer: integrate with CamelIMAPXServer changes



commit b3406187ec0653443ee12d325cc1d8623f0ae18b
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Jun 22 17:38:35 2012 +0200

    CamelIMAPXExtdServer: integrate with CamelIMAPXServer changes
    
    * provide an init function which registers
      the new capabilities flags and the associated
      untagged response handler with CamelIMAPXServer
    * removed the untagged response handler for ANNOTATION
      from public API (does no longer need to be public)

 src/camel/camel-imapx-extd-server.c |  109 +++++++++++++++++++++++------------
 src/camel/camel-imapx-extd-server.h |   14 ++++-
 2 files changed, 82 insertions(+), 41 deletions(-)
---
diff --git a/src/camel/camel-imapx-extd-server.c b/src/camel/camel-imapx-extd-server.c
index e9f6749..96917b9 100644
--- a/src/camel/camel-imapx-extd-server.c
+++ b/src/camel/camel-imapx-extd-server.c
@@ -37,20 +37,22 @@
 
 /*----------------------------------------------------------------------------*/
 
-/* FIXME
- *
- * Capabilities flags need to be made known to
- * CamelIMAPXServer, so they can be checked for
- * here. As of E-D-S, the capability flags are
- * part of the tokenizer (structs)
- */
-enum {
-	IMAPX_ANNOTATEMORE = 1 << 0, /* FIXME! */
+static guint32 imapx_capa_flag_annotatemore = 0;
+
+static gboolean
+camel_imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
+                                             GCancellable *cancellable,
+                                             GError **err);
+
+static const CamelIMAPXUntaggedRespHandlerDesc desc = {
+	camel_imapx_extd_server_untagged_annotation, /* handler               */
+	NULL,                                        /* next_response         */
+	TRUE                                         /* skip_stream_when_done */
 };
 
 /*----------------------------------------------------------------------------*/
 
-gboolean
+static gboolean
 camel_imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
                                              GCancellable *cancellable,
                                              GError **err)
@@ -68,7 +70,7 @@ camel_imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
 	estore = CAMEL_IMAPX_EXTD_STORE (is->store);
 
 	/* capability check */
-	capa = is->cinfo->capa & IMAPX_ANNOTATEMORE;
+	capa = is->cinfo->capa & imapx_capa_flag_annotatemore;
 	if (! capa) {
 		g_set_error (err,
 		             CAMEL_IMAPX_ERROR,
@@ -93,6 +95,40 @@ camel_imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
 	return TRUE;
 }
 
+/*----------------------------------------------------------------------------*/
+
+gboolean
+camel_imapx_extd_server_init (CamelIMAPXServer *is,
+                              GCancellable *cancellable,
+                              GError **err)
+{
+	const CamelIMAPXUntaggedRespHandlerDesc *prev = NULL;
+	static gboolean is_inited = FALSE;
+
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	(void)cancellable; /* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* TODO change this for a g_once() */
+	if (is_inited)
+		return TRUE;
+
+	/* ANNOTATEMORE server capability flag */
+	imapx_capa_flag_annotatemore =
+		imapx_register_capability (IMAPX_IMAP_TOKEN_ANNOTATEMORE);
+	g_assert (imapx_capa_flag_annotatemore > 0);
+
+	prev = camel_imapx_server_register_untagged_handler (is,
+	                                                     IMAPX_IMAP_TOKEN_ANNOTATION,
+	                                                     &desc);
+	/* make sure we do not have been registered before */
+	g_assert (prev == NULL);
+
+	is_inited = TRUE;
+
+	return TRUE;
+}
+
 gboolean
 camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
                                       CamelImapxMetadataSpec *spec,
@@ -114,31 +150,34 @@ camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
 	 *      (add a function to return proper string depending
 	 *      on protocol type)
 	 */
-	cmd = g_strdup_printf ("GETANNOTATION \"%s\" \"%s\" \"%s\"",
+	cmd = g_strdup_printf ("%s \"%s\" \"%s\" \"%s\"",
+	                       IMAPX_IMAP_TOKEN_GETANNOTATION,
 	                       spec->mailbox_name,
 	                       spec->entry_name,
 	                       spec->attrib_name);
 	ic = camel_imapx_command_new (is,
-	                              "GETANNOTATION",
+	                              IMAPX_IMAP_TOKEN_GETANNOTATION,
 	                              NULL,
 	                              cmd);
 	job = camel_imapx_job_new (cancellable);
 	camel_imapx_command_set_job (ic, job);
 	/* TODO set more job details like priority? */
 
-	/* FIXME CamelIMAPXServer needs to expose API for running custom commands */
-	g_warning ("%s()[%u] FIXME CamelIMAPXServer needs to expose API for running custom commands",
-	           __func__, __LINE__);
-#if 0
-	/* run GETANNOTATION command synchronously
-	 * (TODO can we change this to async operation?)
-	 */
-	ok = camel_imapx_server_command_run_sync (is,
-	                                          ic,
-	                                          cancellable,
-	                                          &tmp_err);
-#endif
+	/* run GETANNOTATION command */
+	ok = camel_imapx_server_command_run (is,
+	                                     ic,
+	                                     cancellable,
+	                                     &tmp_err);
 	g_free (cmd);
+
+	/* wait for the command to complete
+	 * (will improve our chances that the server will
+	 * already have sent an untagged response when we
+	 * want to read the metadata information)
+	 */
+	if (ok)
+		camel_imapx_command_wait (ic);
+
 	camel_imapx_command_done (ic);
 	camel_imapx_command_unref (ic);
 
@@ -180,25 +219,19 @@ camel_imapx_extd_server_set_metadata (CamelIMAPXServer *is,
 		 *      on protocol type)
 		 */
 		ic = camel_imapx_command_new (is,
-		                              "SETANNOTATION",
+		                              IMAPX_IMAP_TOKEN_SETANNOTATION,
 		                              NULL,
 		                              (gchar *) cur_cmd->data);
 		job = camel_imapx_job_new (cancellable);
 		camel_imapx_command_set_job (ic, job);
 		/* TODO set more job details like priority? */
 
-		/* FIXME CamelIMAPXServer needs to expose API for running custom commands */
-		g_warning ("%s()[%u] FIXME CamelIMAPXServer needs to expose API for running custom commands",
-		           __func__, __LINE__);
-#if 0
-		/* run SETANNOTATION command synchronously
-		 * (TODO can we change this to async operation?)
-		 */
-		ok = camel_imapx_server_command_run_sync (is,
-		                                          ic,
-		                                          cancellable,
-		                                          &tmp_err);
-#endif
+		/* run SETANNOTATION command */
+		ok = camel_imapx_server_command_run (is,
+		                                     ic,
+		                                     cancellable,
+		                                     &tmp_err);
+
 		camel_imapx_command_done (ic);
 		camel_imapx_command_unref (ic);
 
diff --git a/src/camel/camel-imapx-extd-server.h b/src/camel/camel-imapx-extd-server.h
index c886c34..e07a496 100644
--- a/src/camel/camel-imapx-extd-server.h
+++ b/src/camel/camel-imapx-extd-server.h
@@ -40,10 +40,18 @@
 
 /*----------------------------------------------------------------------------*/
 
+#define IMAPX_IMAP_TOKEN_ANNOTATEMORE  "ANNOTATEMORE"
+#define IMAPX_IMAP_TOKEN_ANNOTATION    "ANNOTATION"
+#define IMAPX_IMAP_TOKEN_SETANNOTATION "SETANNOTATION"
+#define IMAPX_IMAP_TOKEN_GETANNOTATION "GETANNOTATION"
+
+/*----------------------------------------------------------------------------*/
+
 gboolean
-camel_imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
-                                             GCancellable *cancellable,
-                                             GError **err);
+camel_imapx_extd_server_init (CamelIMAPXServer *is,
+                              GCancellable *cancellable,
+                              GError **err);
+
 gboolean
 camel_imapx_extd_server_get_metadata (CamelIMAPXServer *self,
                                       CamelImapxMetadataSpec *spec,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]