[evolution-kolab/ek-wip-porting-imapx] CamelKolabImapxMetadata: API extension (added update function)



commit d31ffc34daaa37b55387aead1585526d85811efc
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Dec 5 15:55:04 2011 +0100

    CamelKolabImapxMetadata: API extension (added update function)
    
    * added API function to update a CamelKolabImapxMetadata*
      from a CamelImapxMetadata*
    * used in CamelKolabIMAPXServer

 src/camel/camel-kolab-imapx-metadata.c |  110 ++++++++++++++++---------------
 src/camel/camel-kolab-imapx-metadata.h |    7 ++
 2 files changed, 64 insertions(+), 53 deletions(-)
---
diff --git a/src/camel/camel-kolab-imapx-metadata.c b/src/camel/camel-kolab-imapx-metadata.c
index 96a58ba..d1ad480 100644
--- a/src/camel/camel-kolab-imapx-metadata.c
+++ b/src/camel/camel-kolab-imapx-metadata.c
@@ -33,30 +33,28 @@
 
 /*----------------------------------------------------------------------------*/
 
-#if 0 /* TODO functions to be moved to CamelKolabIMAPXServer */
 static CamelKolabImapxFolderMetadata*
-camel_kolab_imapx_folder_metadata_new_from_imapx_annotation (CamelImapxMetadataAnnotation *man,
-                                                             CamelIMAPXServer *server,
-                                                             GError **err)
+camel_kolab_imapx_metadata_folder_metadata_new_from_imapx (CamelImapxMetadataAnnotation *man,
+                                                           camel_imapx_metadata_proto_t proto,
+                                                           GError **err)
 {
 	CamelKolabImapxFolderMetadata *kfmd = NULL;
 	CamelImapxMetadataAttrib *ma = NULL;
 	CamelImapxMetadataSpec *spec = NULL;
-	camel_imapx_metadata_proto_t proto = CAMEL_IMAPX_METADATA_PROTO_INVAL;	
 	gchar *typestring = NULL;
 	GError *tmp_err = NULL;
 
 	/* man may be NULL */
-	g_assert (CAMEL_IS_IMAPX_SERVER (server));
-	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
-
+	g_assert ((proto > CAMEL_IMAPX_METADATA_PROTO_INVAL) &&
+	          (proto < CAMEL_IMAPX_METADATA_LAST_PROTO));
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+	
 	if (man == NULL)
 		return NULL;
 	
 	g_assert (man->entries != NULL);
 
 	/* search for folder type info */
-	proto = camel_imapx_server_metadata_get_proto (server);
 	spec = camel_imapx_metadata_spec_new (proto, /* IMAP metadata protocol type */
 	                                      NULL, /* search starts at annotation */
 	                                      "/vendor/kolab/folder-type",
@@ -95,58 +93,21 @@ camel_kolab_imapx_folder_metadata_new_from_imapx_annotation (CamelImapxMetadataA
 	}
 
 	typestring = (gchar*) ma->data[CAMEL_IMAPX_METADATA_ACCESS_SHARED]->data;
-	kfmd->folder_type = camel_kolab_imapx_folder_map_get_type_id (typestring, &tmp_err);
+	kfmd->folder_type = kolab_util_folder_type_get_id (typestring);
 	if (kfmd->folder_type == KOLAB_FOLDER_TYPE_INVAL) {
 		/* protocol violation - invalid kolab folder type string */
 		camel_kolab_imapx_folder_metadata_free (kfmd);
-		g_propagate_error (err, tmp_err);
+		g_set_error (err,
+		             KOLAB_CAMEL_KOLAB_ERROR,
+		             KOLAB_CAMEL_KOLAB_ERROR_TYPE,
+		             "%s: invalid folder type string",
+		             __func__);
 		return NULL;
 	}
 
 	return kfmd;
 }
 
-static void
-camel_kolab_imapx_metadata_addreplace_from_imapx (CamelKolabImapxMetadata *kmd,
-                                                  CamelImapxMetadata *md,
-                                                  CamelIMAPXServer *server)
-{
-	/* TODO error reporting */
-
-	GHashTableIter mbox_iter;
-	gpointer mbox_key = NULL;
-	gpointer mbox_value = NULL;
-	gchar *foldername = NULL;
-	CamelImapxMetadataAnnotation *man = NULL;
-	CamelKolabImapxFolderMetadata *kfmd = NULL;
-	GError *tmp_err = NULL;
-
-	g_assert (kmd != NULL);
-	g_assert (md != NULL);
-	g_assert (CAMEL_IS_IMAPX_SERVER (server));
-
-	g_hash_table_iter_init (&mbox_iter, md->mboxes);
-	while (g_hash_table_iter_next (&mbox_iter, &mbox_key, &mbox_value)) {
-		foldername = (gchar*) mbox_key;
-		man = (CamelImapxMetadataAnnotation*) mbox_value;
-
-		kfmd = camel_kolab_imapx_folder_metadata_new_from_imapx_annotation (man,
-		                                                                    server,
-		                                                                    &tmp_err);
-		if (kfmd == NULL) {
-			g_warning ("%s: kolab annotation error for [%s]: %s",
-			           __func__, foldername, tmp_err->message);
-			g_clear_error (&tmp_err);
-			continue;
-		}
-		/* need hash table with key:value destroy functions set */
-		g_hash_table_replace (kmd->kolab_metadata,
-		                      g_strdup (foldername),
-		                      kfmd);
-	}
-}
-#endif
-
 /*----------------------------------------------------------------------------*/
 
 CamelKolabImapxMetadata*
@@ -178,7 +139,7 @@ camel_kolab_imapx_metadata_free (CamelKolabImapxMetadata *kmd)
 gboolean
 camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd,
                                  const gchar *cachepath,
-				 GError **err)
+                                 GError **err)
 {
 	gboolean db_ok = FALSE;
 	GError *tmp_err = NULL;
@@ -270,4 +231,47 @@ camel_kolab_imapx_metadata_remove (CamelKolabImapxMetadata *kmd,
 	return TRUE;
 }
 
+void
+camel_kolab_imapx_metadata_update (CamelKolabImapxMetadata *kmd,
+                                   CamelImapxMetadata *md,
+                                   camel_imapx_metadata_proto_t proto)
+{
+	/* TODO better error reporting */
+	
+	CamelImapxMetadataAnnotation *man = NULL;
+	CamelKolabImapxFolderMetadata *kfmd = NULL;
+	GHashTableIter mbox_iter;
+	gpointer mbox_key = NULL;
+	gpointer mbox_value = NULL;
+	gchar *foldername = NULL;
+	GError *tmp_err = NULL;
+
+	g_assert (kmd != NULL);
+	g_assert (md != NULL);
+	g_assert ((proto > CAMEL_IMAPX_METADATA_PROTO_INVAL) &&
+	          (proto < CAMEL_IMAPX_METADATA_LAST_PROTO));
+
+	g_hash_table_iter_init (&mbox_iter, md->mboxes);
+	while (g_hash_table_iter_next (&mbox_iter, &mbox_key, &mbox_value)) {
+		foldername = (gchar*) mbox_key;
+		man = (CamelImapxMetadataAnnotation*) mbox_value;
+
+		kfmd = camel_kolab_imapx_metadata_folder_metadata_new_from_imapx \
+			(man,
+			 proto,
+			 &tmp_err);
+			 
+		if (kfmd == NULL) {
+			g_warning ("%s: kolab annotation error for [%s]: %s",
+			           __func__, foldername, tmp_err->message);
+			g_clear_error (&tmp_err);
+			continue;
+		}
+		/* need hash table with key:value destroy functions set */
+		g_hash_table_replace (kmd->kolab_metadata,
+		                      g_strdup (foldername),
+		                      kfmd);
+	}
+}
+
 /*----------------------------------------------------------------------------*/
diff --git a/src/camel/camel-kolab-imapx-metadata.h b/src/camel/camel-kolab-imapx-metadata.h
index c9c9154..2acfafb 100644
--- a/src/camel/camel-kolab-imapx-metadata.h
+++ b/src/camel/camel-kolab-imapx-metadata.h
@@ -36,6 +36,8 @@
 #include <libekolabutil/camel-system-headers.h>
 #include <libekolabutil/kolab-util-folder.h>
 
+#include <camel/providers/imapx/camel-imapx-metadata.h>
+
 #include "camel-kolab-imapx-metadata-db.h"
 #include "camel-kolab-imapx-folder.h"
 
@@ -68,6 +70,11 @@ camel_kolab_imapx_metadata_remove (CamelKolabImapxMetadata *kmd,
                                    const gchar *foldername,
                                    GError **err);
 
+void
+camel_kolab_imapx_metadata_update (CamelKolabImapxMetadata *kmd,
+                                   CamelImapxMetadata *md,
+                                   camel_imapx_metadata_proto_t proto);
+
 /*----------------------------------------------------------------------------*/
 
 #endif /* _CAMEL_KOLAB_IMAPX_METADATA_H_ */



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