[evolution-kolab] CamelIMAPXExtdServer: removed extension code from vanilla CamelIMAPXExtdServer



commit 886dd629c728511ace1d0e2f4624c57f12fa9f4a
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Jul 30 16:42:29 2012 +0200

    CamelIMAPXExtdServer: removed extension code from vanilla CamelIMAPXExtdServer
    
    * camel-imapx-extd-server.[hc] files now host only the
      extensibility infrastructure, while the extension code
      for the IMAP extensions lives in separate files
    * it shows that the binding between CamelIMAPXServer and
      CamelIMAPXStore is rather tight, as the capability
      flags need to continue to live inside CamelIMAPXExtdStore
      instead of being moved to their own files, along with
      the untagged handlers and friends
    * this part will remain work in progress for a while I guess,
      especially in the light of getting the IMAP extensions
      upstream one day

 src/libekolab/camel-imapx-extd-server.c |  205 ++++++-------------------------
 src/libekolab/camel-imapx-extd-server.h |   22 +---
 2 files changed, 41 insertions(+), 186 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-extd-server.c b/src/libekolab/camel-imapx-extd-server.c
index d90195d..90e6fca 100644
--- a/src/libekolab/camel-imapx-extd-server.c
+++ b/src/libekolab/camel-imapx-extd-server.c
@@ -37,81 +37,58 @@
 
 /*----------------------------------------------------------------------------*/
 
-static gboolean
-imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
-                                       GCancellable *cancellable,
-                                       GError **err);
-
-static const CamelIMAPXUntaggedRespHandlerDesc desc = {
-	imapx_extd_server_untagged_annotation, /* handler               */
-	NULL,                                  /* next_response         */
-	TRUE                                   /* skip_stream_when_done */
-};
+static gpointer
+imapx_extd_server_register_desc_list (CamelIMAPXServer *is,
+                                      KolabGConstList *desc_lst)
+{
+	const CamelIMAPXUntaggedRespHandlerDesc *desc = NULL;
+	const CamelIMAPXUntaggedRespHandlerDesc *prev = NULL;
+	KolabGConstList *desc_lst_ptr = NULL;
+
+	desc_lst_ptr = desc_lst;
+	while (desc_lst_ptr != NULL) {
+		desc = (const CamelIMAPXUntaggedRespHandlerDesc *) (desc_lst_ptr->const_data);
+		prev = camel_imapx_server_register_untagged_handler (is,
+		                                                     desc->untagged_response,
+		                                                     desc);
+		if (prev != NULL)
+			return (gpointer) prev;
+
+		desc_lst_ptr = desc_lst_ptr->next;
+	}
 
-/*----------------------------------------------------------------------------*/
+	return NULL;
+}
 
 static gpointer
 imapx_extd_server_register_untagged_fn (gpointer data)
 {
 	CamelIMAPXServer *is = CAMEL_IMAPX_SERVER (data);
 	const CamelIMAPXUntaggedRespHandlerDesc *prev = NULL;
+	KolabGConstList *desc_lst = NULL;
 
-	prev = camel_imapx_server_register_untagged_handler (is,
-	                                                     IMAPX_IMAP_TOKEN_ANNOTATION,
-	                                                     &desc);
-	/* Make sure we do not have been registered before.
-	 * Returning non-NULL here means that the handler
+	/* We need to make sure that the untagged handler
+	 * functions do not have been registered before.
+	 * Returning non-NULL here means that any handler
 	 * has been registered before, which is an error.
 	 * This needs to be checked for all handlers which
 	 * are registered here.
 	 */
-	return (gpointer)prev;
-}
 
-static gboolean
-imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
-                                       GCancellable *cancellable,
-                                       GError **err)
-{
-	CamelIMAPXExtdStore *estore = NULL;
-	CamelImapxMetadata *md = NULL;
-	guint32 capa = 0;
-	guint32 capa_flag_id = 0;
-	GError *tmp_err = NULL;
-	gboolean parse_and_add_ok = FALSE;
-
-	g_assert (CAMEL_IS_IMAPX_SERVER (is));
-	/* cancellable may be NULL */
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
-
-	estore = CAMEL_IMAPX_EXTD_STORE (is->store);
-
-	/* capability check */
-	capa_flag_id =
-		camel_imapx_extd_store_get_capa_flag_id (estore,
-		                                         CAMEL_IMAPX_EXTD_STORE_CAPA_FLAG_ANNOTATEMORE);
-	capa = is->cinfo->capa & capa_flag_id;
-	if (! capa) {
-		g_set_error (err,
-		             CAMEL_IMAPX_ERROR,
-		             1, /* FIXME define and add a sensible code here */
-		             _("Got ANNOTATION response but server did not advertise ANNOTATEMORE capability"));
-		return FALSE;
-	}
-
-	md = camel_imapx_extd_store_get_md_table (estore);
-	parse_and_add_ok =
-		camel_imapx_metadata_add_from_server_response (md,
-		                                               is->stream,
-		                                               cancellable,
-		                                               &tmp_err);
-
-	if (! parse_and_add_ok) {
-		g_propagate_error (err, tmp_err);
-		return FALSE;
-	}
-
-	return TRUE;
+	/* METADATA handlers */
+	desc_lst = camel_imapx_extd_server_metadata_get_handler_descriptors ();
+	prev = imapx_extd_server_register_desc_list (is, desc_lst);
+	kolab_util_glib_gconstlist_free (desc_lst);
+	if (prev != NULL)
+		goto exit;
+#if 0
+	/* ACL handlers */
+	desc_lst = camel_imapx_extd_server_acl_get_handler_descriptors ();
+	prev = imapx_extd_server_register_desc_list (is, desc_lst);
+	kolab_util_glib_gconstlist_free (desc_lst);
+#endif
+ exit:
+	return (gpointer) prev;
 }
 
 /*----------------------------------------------------------------------------*/
@@ -142,108 +119,4 @@ camel_imapx_extd_server_init (CamelIMAPXServer *is,
 	return TRUE;
 }
 
-gboolean
-camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
-                                      CamelImapxMetadataSpec *spec,
-                                      GCancellable *cancellable,
-                                      GError **err)
-{
-	CamelIMAPXCommand *ic = NULL;
-	gchar *cmd = NULL;
-	GError *tmp_err = NULL;
-	gboolean ok = FALSE;
-
-	g_assert (CAMEL_IS_IMAPX_SERVER (is));
-	g_assert (spec != NULL);
-	/* cancellable may be NULL */
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
-
-	/* TODO move GETANNOTATION string to -metadata.[hc]
-	 *      (add a function to return proper string depending
-	 *      on protocol type)
-	 */
-	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,
-	                              IMAPX_IMAP_TOKEN_GETANNOTATION,
-	                              NULL,
-	                              cmd);
-
-	/* run GETANNOTATION command */
-	ok = camel_imapx_server_command_run (is,
-	                                     ic,
-	                                     cancellable,
-	                                     &tmp_err);
-	g_free (cmd);
-	camel_imapx_command_unref (ic);
-
-	if (! ok) {
-		g_propagate_error (err, tmp_err);
-		return FALSE;
-	}
-
-	return TRUE;
-}
-
-gboolean
-camel_imapx_extd_server_set_metadata (CamelIMAPXServer *is,
-                                      CamelImapxMetadata *md,
-                                      GCancellable *cancellable,
-                                      GError **err)
-{
-	CamelIMAPXCommand *ic = NULL;
-	GSList *commands = NULL;
-	GSList *cur_cmd = NULL;
-	GError *tmp_err = NULL;
-	gboolean ok = FALSE;
-
-	g_assert (CAMEL_IS_IMAPX_SERVER (is));
-	g_assert (md != NULL);
-	/* cancellable may be NULL */
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
-
-	commands = camel_imapx_metadata_new_commandlist (md);
-
-	if (commands == NULL)
-		return TRUE;
-
-	cur_cmd = commands;
-	while (cur_cmd != NULL) {
-		/* TODO move SETANNOTATION string to -metadata.[hc]
-		 *      (add a function to return proper string depending
-		 *      on protocol type)
-		 */
-		ic = camel_imapx_command_new (is,
-		                              IMAPX_IMAP_TOKEN_SETANNOTATION,
-		                              NULL,
-		                              (gchar *) cur_cmd->data);
-
-		/* TODO set more job details like priority? */
-
-		/* run SETANNOTATION command */
-		ok = camel_imapx_server_command_run (is,
-		                                     ic,
-		                                     cancellable,
-		                                     &tmp_err);
-
-		camel_imapx_command_unref (ic);
-
-		if (! ok) {
-			g_slist_free (commands);
-			g_propagate_error (err, tmp_err);
-			return FALSE;
-		}
-
-		cur_cmd = g_slist_next (cur_cmd);
-	}
-
-	g_slist_free (commands);
-
-	return TRUE;
-}
-
 /*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-extd-server.h b/src/libekolab/camel-imapx-extd-server.h
index e07a496..453f775 100644
--- a/src/libekolab/camel-imapx-extd-server.h
+++ b/src/libekolab/camel-imapx-extd-server.h
@@ -36,14 +36,8 @@
 
 #include <libekolabutil/camel-system-headers.h>
 
-#include "camel-imapx-metadata.h"
-
-/*----------------------------------------------------------------------------*/
-
-#define IMAPX_IMAP_TOKEN_ANNOTATEMORE  "ANNOTATEMORE"
-#define IMAPX_IMAP_TOKEN_ANNOTATION    "ANNOTATION"
-#define IMAPX_IMAP_TOKEN_SETANNOTATION "SETANNOTATION"
-#define IMAPX_IMAP_TOKEN_GETANNOTATION "GETANNOTATION"
+/* CamelIMAPXExtdServer protocol extensions */
+#include "camel-imapx-extd-server-metadata.h"
 
 /*----------------------------------------------------------------------------*/
 
@@ -52,18 +46,6 @@ camel_imapx_extd_server_init (CamelIMAPXServer *is,
                               GCancellable *cancellable,
                               GError **err);
 
-gboolean
-camel_imapx_extd_server_get_metadata (CamelIMAPXServer *self,
-                                      CamelImapxMetadataSpec *spec,
-                                      GCancellable *cancellable,
-                                      GError **err);
-
-gboolean
-camel_imapx_extd_server_set_metadata (CamelIMAPXServer *self,
-                                      CamelImapxMetadata *md,
-                                      GCancellable *cancellable,
-                                      GError **err);
-
 G_END_DECLS
 
 /*----------------------------------------------------------------------------*/



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