[evolution-kolab/ek-wip-porting-imapx] CamelKolabImapxMetadata: major API cleanup, internal cleanup
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab/ek-wip-porting-imapx] CamelKolabImapxMetadata: major API cleanup, internal cleanup
- Date: Sat, 3 Dec 2011 22:31:09 +0000 (UTC)
commit c8b47a242e1a05e0b98f2e6bb8714e92af2647ea
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Sat Dec 3 21:15:21 2011 +0100
CamelKolabImapxMetadata: major API cleanup, internal cleanup
* removed CamelService, CamelSession args from metadata
init() function, let it take a path argument instead
* retrieving the storage path is better done in the class
which *uses* CamelKolabImapxMetadata
* removed functions dealing with folder types (these now
live in kolab-util-folder.[hc])
* commented out code which is misplaced here but should
live in CamelKolabIMAPXServer (needs to move there)
* renamed the uninit() function to shutdown() (to follow
out common naming scheme for this)
src/camel/camel-kolab-imapx-metadata.c | 468 ++++----------------------------
src/camel/camel-kolab-imapx-metadata.h | 28 ++-
2 files changed, 66 insertions(+), 430 deletions(-)
---
diff --git a/src/camel/camel-kolab-imapx-metadata.c b/src/camel/camel-kolab-imapx-metadata.c
index 0c3e0c1..96a58ba 100644
--- a/src/camel/camel-kolab-imapx-metadata.c
+++ b/src/camel/camel-kolab-imapx-metadata.c
@@ -27,111 +27,13 @@
#include <string.h>
-#include <libekolabutil/camel-system-headers.h>
-
-#include <camel/providers/imapx/camel-imapx-store.h>
-#include <camel/providers/imapx/camel-imapx-server.h>
-#include <camel/providers/imapx/camel-imapx-server-extn.h>
-#include <camel/providers/imapx/camel-imapx-utils.h>
-
-/* Kolab error reporting */
#include <libekolabutil/kolab-util-error.h>
#include "camel-kolab-imapx-metadata.h"
/*----------------------------------------------------------------------------*/
-static gchar *kolab_folder_type_inv_map[] = {
- "---INVALID---", /* KOLAB_FOLDER_TYPE_INVAL */
- "---UNKNOWN---", /* KOLAB_FOLDER_TYPE_UNKNOWN */
-
- "mail", /* KOLAB_FOLDER_TYPE_EMAIL */
- "mail.inbox", /* KOLAB_FOLDER_TYPE_EMAIL_INBOX */
- "mail.drafts", /* KOLAB_FOLDER_TYPE_EMAIL_DRAFTS */
- "mail.sentitems", /* KOLAB_FOLDER_TYPE_EMAIL_SENTITEMS */
- "mail.junkemail", /* KOLAB_FOLDER_TYPE_EMAIL_JUNKEMAIL */
-
- "event", /* KOLAB_FOLDER_TYPE_EVENT */
- "event.default", /* KOLAB_FOLDER_TYPE_EVENT_DEFAULT */
- "journal", /* KOLAB_FOLDER_TYPE_JOURNAL */
- "journal.default", /* KOLAB_FOLDER_TYPE_JOURNAL_DEFAULT */
- "task", /* KOLAB_FOLDER_TYPE_TASK */
- "task.default", /* KOLAB_FOLDER_TYPE_TASK_DEFAULT */
- "note", /* KOLAB_FOLDER_TYPE_NOTE */
- "note.default", /* KOLAB_FOLDER_TYPE_NOTE_DEFAULT */
-
- "contact", /* KOLAB_FOLDER_TYPE_CONTACT */
- "contact.default" /* KOLAB_FOLDER_TYPE_CONTACT_DEFAULT */
-};
-
-static KolabFolderTypeID kolab_folder_type_nums[KOLAB_FOLDER_LAST_TYPE];
-static GHashTable *kolab_folder_type_map = NULL;
-
-/*----------------------------------------------------------------------------*/
-
-static void
-camel_kolab_imapx_folder_destroy_type_map (void)
-{
- if (kolab_folder_type_map != NULL) {
- g_hash_table_destroy (kolab_folder_type_map);
- kolab_folder_type_map = NULL;
- }
-}
-
-static void
-camel_kolab_imapx_folder_build_type_map (void)
-{
- gint ii = 0;
- camel_kolab_imapx_folder_destroy_type_map ();
- kolab_folder_type_map = g_hash_table_new (g_str_hash, g_str_equal);
- for (ii = 0; ii < KOLAB_FOLDER_LAST_TYPE; ii++) {
- kolab_folder_type_nums[ii] = ii;
- g_hash_table_insert (kolab_folder_type_map,
- kolab_folder_type_inv_map[ii],
- &(kolab_folder_type_nums[ii]));
- }
-}
-
-static KolabFolderTypeID
-camel_kolab_imapx_folder_map_get_type_id (const gchar *typestring,
- GError **err)
-{
- /* when looking up a value from kolab_folder_type_map, store
- * it in gpointer, check for NULL, then dereference and cast
- * to KolabFolderTypeID
- */
- gpointer map_entry = NULL;
- KolabFolderTypeID id = KOLAB_FOLDER_TYPE_INVAL;
-
- g_assert (kolab_folder_type_map != NULL);
- g_assert (typestring != NULL);
- g_return_val_if_fail (err == NULL || *err == NULL, KOLAB_FOLDER_TYPE_INVAL);
-
- map_entry = g_hash_table_lookup (kolab_folder_type_map, typestring);
-
- if (map_entry == NULL) {
- /* this would be a Kolab format error from server */
- g_set_error (err,
- KOLAB_CAMEL_KOLAB_ERROR,
- KOLAB_CAMEL_KOLAB_ERROR_FORMAT,
- "%s: invalid folder type string",
- __func__);
- return KOLAB_FOLDER_TYPE_INVAL;
- }
-
- id = *((KolabFolderTypeID*)map_entry);
- return id;
-}
-
-static gchar*
-camel_kolab_imapx_folder_map_get_type_string (KolabFolderTypeID foldertype)
-{
- g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
- return kolab_folder_type_inv_map[foldertype];
-}
-
-/*----------------------------------------------------------------------------*/
-
+#if 0 /* TODO functions to be moved to CamelKolabIMAPXServer */
static CamelKolabImapxFolderMetadata*
camel_kolab_imapx_folder_metadata_new_from_imapx_annotation (CamelImapxMetadataAnnotation *man,
CamelIMAPXServer *server,
@@ -204,93 +106,6 @@ camel_kolab_imapx_folder_metadata_new_from_imapx_annotation (CamelImapxMetadataA
return kfmd;
}
-/*----------------------------------------------------------------------------*/
-
-CamelKolabImapxMetadata*
-camel_kolab_imapx_metadata_new (void)
-{
- CamelKolabImapxMetadata *kmd = g_new0 (CamelKolabImapxMetadata, 1);
- kmd->mdb = NULL;
- kmd->kolab_metadata = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- camel_kolab_imapx_folder_metadata_gdestroy);
-
- return kmd;
-}
-
-void
-camel_kolab_imapx_metadata_free (CamelKolabImapxMetadata *kmd)
-{
- if (kmd == NULL)
- return;
-
- if (kmd->kolab_metadata)
- /* need hash table with key:val destroy function set */
- g_hash_table_destroy (kmd->kolab_metadata);
-
- g_free (kmd);
-}
-
-gboolean
-camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd,
- CamelService *service,
- CamelSession *session,
- GError **err)
-{
- gboolean db_ok = FALSE;
- GError *tmp_err = NULL;
-
- g_assert (kmd != NULL);
- g_assert (CAMEL_IS_SERVICE (service));
- g_assert (CAMEL_IS_SESSION (session));
- g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
-
- if (kmd->mdb == NULL)
- kmd->mdb = camel_kolab_imapx_metadata_db_new ();
-
- db_ok = camel_kolab_imapx_metadata_db_open (kmd->mdb, service, session, &tmp_err);
- if (!db_ok) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
-
- db_ok = camel_kolab_imapx_metadata_db_init (kmd->mdb, &tmp_err);
- if (!db_ok) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
-
- camel_kolab_imapx_folder_build_type_map ();
-
- /* TODO call to camel_kolab_imapx_metadata_init? */
-
- return TRUE;
-}
-
-gboolean
-camel_kolab_imapx_metadata_uninit (CamelKolabImapxMetadata *kmd,
- GError **err)
-{
- GError *tmp_err = NULL;
- gboolean db_ok = FALSE;
-
- g_assert (kmd != NULL);
- g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
-
- db_ok = camel_kolab_imapx_metadata_db_close (kmd->mdb, &tmp_err);
- if (!db_ok) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
-
- camel_kolab_imapx_folder_destroy_type_map ();
-
- /* TODO call to camel_kolab_imapx_metadata_uninit? */
-
- return TRUE;
-}
-
static void
camel_kolab_imapx_metadata_addreplace_from_imapx (CamelKolabImapxMetadata *kmd,
CamelImapxMetadata *md,
@@ -330,271 +145,82 @@ camel_kolab_imapx_metadata_addreplace_from_imapx (CamelKolabImapxMetadata *kmd,
kfmd);
}
}
+#endif
-/* FIXME CAUTION -- TESTING purposes only! The server response may
- * become too long!
- */
-gboolean
-camel_kolab_imapx_metadata_query_all_folder_types (CamelService *service,
- GCancellable *cancellable,
- GError **err)
-{
- CamelIMAPXServer *server = NULL;
- CamelImapxMetadataSpec *spec = NULL;
- camel_imapx_metadata_proto_t proto = CAMEL_IMAPX_METADATA_PROTO_INVAL;
- GError *tmp_err = NULL;
+/*----------------------------------------------------------------------------*/
- g_assert (CAMEL_IS_SERVICE (service));
- g_assert (G_IS_CANCELLABLE (cancellable));
- g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+CamelKolabImapxMetadata*
+camel_kolab_imapx_metadata_new (void)
+{
+ CamelKolabImapxMetadata *kmd = g_new0 (CamelKolabImapxMetadata, 1);
+ kmd->mdb = NULL;
+ kmd->kolab_metadata = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ camel_kolab_imapx_folder_metadata_gdestroy);
- server = camel_imapx_store_get_server (CAMEL_IMAPX_STORE (service),
- (const gchar*)NULL, /* FIXME does that work?? */
- cancellable,
- &tmp_err);
- if (server == NULL) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
+ return kmd;
+}
- proto = camel_imapx_server_metadata_get_proto (server);
- spec = camel_imapx_metadata_spec_new (proto,
- "*",
- "/vendor/kolab/folder-type",
- "value",
- &tmp_err);
- if (spec == NULL) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
+void
+camel_kolab_imapx_metadata_free (CamelKolabImapxMetadata *kmd)
+{
+ if (kmd == NULL)
+ return;
- /* fetch annotations from server, do not resect the data
- * from CamelIMAPXServer as yet
- */
- (void)camel_imapx_server_get_metadata (server, spec, FALSE, &tmp_err);
- if (tmp_err != NULL) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
- camel_imapx_metadata_spec_free (spec);
+ if (kmd->kolab_metadata)
+ /* need hash table with key:val destroy function set */
+ g_hash_table_destroy (kmd->kolab_metadata);
- return TRUE;
+ g_free (kmd);
}
-KolabFolderTypeID
-camel_kolab_imapx_metadata_get_foldertype (CamelKolabImapxMetadata *kmd,
- CamelService *service,
- const gchar *foldername,
- gboolean do_updatedb,
- GCancellable *cancellable,
- GError **err)
+gboolean
+camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd,
+ const gchar *cachepath,
+ GError **err)
{
- /* TODO better error reporting */
-
- CamelIMAPXServer *server = NULL;
- CamelStore *store = NULL;
- CamelImapxMetadata *md = NULL;
- CamelKolabImapxFolderMetadata *kfmd = NULL;
- CamelImapxMetadataSpec *spec = NULL;
- camel_imapx_metadata_proto_t proto = CAMEL_IMAPX_METADATA_PROTO_INVAL;
gboolean db_ok = FALSE;
GError *tmp_err = NULL;
g_assert (kmd != NULL);
- g_assert (kmd->kolab_metadata != NULL);
- g_assert (kmd->mdb != NULL);
- g_assert (CAMEL_IS_SERVICE (service));
- g_assert (foldername != NULL);
- g_assert (G_IS_CANCELLABLE (cancellable));
- g_return_val_if_fail (err == NULL || *err == NULL, KOLAB_FOLDER_TYPE_INVAL);
-
- /* hash table lookup */
- kfmd = g_hash_table_lookup (kmd->kolab_metadata, foldername);
- if (kfmd != NULL)
- return kfmd->folder_type;
-
- /* if not in hash table: sqlite db lookup */
- kfmd = camel_kolab_imapx_metadata_db_lookup (kmd->mdb,
- foldername,
- &tmp_err);
- if (tmp_err != NULL) {
- g_propagate_error (err, tmp_err);
- return KOLAB_FOLDER_TYPE_INVAL;
- }
- if (kfmd != NULL) {
- g_hash_table_insert (kmd->kolab_metadata,
- g_strdup (foldername),
- kfmd);
- return kfmd->folder_type;
- }
-
- /* check whether we're online */
- store = CAMEL_STORE (service);
- if (! camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
- return KOLAB_FOLDER_TYPE_UNKNOWN;
+ g_assert (cachepath != NULL);
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- /* TODO check whether we're authenticated */
+ if (kmd->mdb == NULL)
+ kmd->mdb = camel_kolab_imapx_metadata_db_new ();
- /* if not in sqlite db: issue IMAP query */
- server = camel_imapx_store_get_server (CAMEL_IMAPX_STORE (service),
- foldername,
- cancellable,
- &tmp_err);
- if (tmp_err != NULL) {
+ db_ok = camel_kolab_imapx_metadata_db_open (kmd->mdb,
+ cachepath,
+ &tmp_err);
+ if (!db_ok) {
g_propagate_error (err, tmp_err);
- return KOLAB_FOLDER_TYPE_INVAL;
+ return FALSE;
}
- proto = camel_imapx_server_metadata_get_proto (server);
- spec = camel_imapx_metadata_spec_new (proto,
- foldername,
- "/vendor/kolab/folder-type",
- "value",
- &tmp_err);
- if (spec == NULL) {
- g_object_unref (server);
+ db_ok = camel_kolab_imapx_metadata_db_init (kmd->mdb,
+ &tmp_err);
+ if (!db_ok) {
g_propagate_error (err, tmp_err);
- return KOLAB_FOLDER_TYPE_INVAL;
- }
-
- /* resect all metadata gathered so far from CamelIMAPXServer */
- md = camel_imapx_server_get_metadata (server, spec, TRUE, &tmp_err);
-
- if (md == NULL) {
- if (tmp_err != NULL) {
- g_object_unref (server);
- camel_imapx_metadata_spec_free (spec);
- g_propagate_error (err, tmp_err);
- return KOLAB_FOLDER_TYPE_INVAL;
- }
- }
- camel_imapx_metadata_spec_free (spec);
-
- /* create kolab "flat" data structure */
- camel_kolab_imapx_metadata_addreplace_from_imapx (kmd, md, server);
- camel_imapx_metadata_free (md);
-
- /* unref server */
- g_object_unref (server);
-
- /* stuff folder types into metadata_db */
- if (do_updatedb) {
- db_ok = camel_kolab_imapx_metadata_db_update (kmd->mdb,
- kmd->kolab_metadata,
- &tmp_err);
- if (!db_ok) {
- g_propagate_error (err, tmp_err);
- return KOLAB_FOLDER_TYPE_INVAL;
- }
+ return FALSE;
}
- /* final hash table lookup */
- kfmd = g_hash_table_lookup (kmd->kolab_metadata, foldername);
- if (kfmd == NULL)
- return KOLAB_FOLDER_TYPE_UNKNOWN;
-
- return kfmd->folder_type;
+ return TRUE;
}
gboolean
-camel_kolab_imapx_metadata_set_foldertype (CamelKolabImapxMetadata *kmd,
- CamelService *service,
- const gchar *foldername,
- KolabFolderTypeID foldertype,
- GCancellable *cancellable,
- GError **err)
+camel_kolab_imapx_metadata_shutdown (CamelKolabImapxMetadata *kmd,
+ GError **err)
{
- CamelIMAPXServer *server = NULL;
- CamelStore *store = NULL;
- CamelImapxMetadata *md = NULL;
- CamelImapxMetadataAnnotation *man = NULL;
- CamelImapxMetadataEntry *me = NULL;
- CamelImapxMetadataAttrib *ma = NULL;
- gchar *type_str = NULL;
- camel_imapx_metadata_access_t acc = CAMEL_IMAPX_METADATA_ACCESS_SHARED;
- camel_imapx_metadata_proto_t proto = CAMEL_IMAPX_METADATA_PROTO_INVAL;
- gboolean metadata_ok = FALSE;
- gboolean db_ok = FALSE;
GError *tmp_err = NULL;
+ gboolean db_ok = FALSE;
g_assert (kmd != NULL);
- g_assert (kmd->kolab_metadata != NULL);
- g_assert (kmd->mdb != NULL);
- g_assert (CAMEL_IS_SERVICE (service));
- g_assert (foldername != NULL);
- g_assert ((foldertype > KOLAB_FOLDER_TYPE_UNKNOWN) && (foldertype < KOLAB_FOLDER_LAST_TYPE));
- g_assert (G_IS_CANCELLABLE (cancellable));
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- /* check whether we're online */
- store = CAMEL_STORE (service);
- if (! camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
- g_set_error (err,
- KOLAB_CAMEL_KOLAB_ERROR,
- KOLAB_CAMEL_KOLAB_ERROR_SERVER,
- "%s: must be online to complete this operation",
- __func__);
- return FALSE;
- }
-
- /* TODO check whether we're authenticated */
-
- /* get the server object */
- server = camel_imapx_store_get_server (CAMEL_IMAPX_STORE (service),
- foldername,
- cancellable,
- &tmp_err);
- if (tmp_err != NULL) {
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
-
- /* create local CamelImapxMetadata for setting type */
- acc = CAMEL_IMAPX_METADATA_ACCESS_SHARED;
- ma = camel_imapx_metadata_attrib_new ();
- ma->type[acc] = CAMEL_IMAPX_METADATA_ATTRIB_TYPE_UTF8;
- type_str = camel_kolab_imapx_folder_map_get_type_string (foldertype);
- ma->data[acc] = g_byte_array_new ();
- g_byte_array_append (ma->data[acc],
- (guchar *) type_str,
- strlen (type_str));
- me = camel_imapx_metadata_entry_new ();
- g_hash_table_insert (me->attributes,
- g_strdup ("value"),
- ma);
- man = camel_imapx_metadata_annotation_new ();
- g_hash_table_insert (man->entries,
- g_strdup ("/vendor/kolab/folder-type"),
- me);
- proto = camel_imapx_server_metadata_get_proto (server);
- md = camel_imapx_metadata_new (proto, FALSE);
- g_hash_table_insert (md->mboxes,
- g_strdup (foldername),
- man);
-
- /* set folder type on the server */
- metadata_ok = camel_imapx_server_set_metadata (server,
- md,
- &tmp_err);
- if (! metadata_ok) {
- camel_imapx_metadata_free (md);
- g_object_unref (server);
- g_propagate_error (err, tmp_err);
- return FALSE;
- }
-
- /* create kolab "flat" data structure */
- camel_kolab_imapx_metadata_addreplace_from_imapx (kmd, md, server);
- camel_imapx_metadata_free (md);
-
- /* unref server */
- g_object_unref (server);
-
- /* stuff folder types into metadata_db */
- db_ok = camel_kolab_imapx_metadata_db_update (kmd->mdb,
- kmd->kolab_metadata,
- &tmp_err);
- if (! db_ok) {
+ db_ok = camel_kolab_imapx_metadata_db_close (kmd->mdb,
+ &tmp_err);
+ if (!db_ok) {
g_propagate_error (err, tmp_err);
return FALSE;
}
diff --git a/src/camel/camel-kolab-imapx-metadata.h b/src/camel/camel-kolab-imapx-metadata.h
index 5529097..c9c9154 100644
--- a/src/camel/camel-kolab-imapx-metadata.h
+++ b/src/camel/camel-kolab-imapx-metadata.h
@@ -48,15 +48,25 @@ typedef struct _CamelKolabImapxMetadata {
/*----------------------------------------------------------------------------*/
-CamelKolabImapxMetadata *camel_kolab_imapx_metadata_new (void);
-void camel_kolab_imapx_metadata_free (CamelKolabImapxMetadata *kmd);
-gboolean camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd, CamelService *service, CamelSession *session, GError **err);
-gboolean camel_kolab_imapx_metadata_uninit (CamelKolabImapxMetadata *kmd, GError **err);
-
-gboolean camel_kolab_imapx_metadata_query_all_folder_types (CamelService *service, GCancellable *cancellable, GError **err);
-KolabFolderTypeID camel_kolab_imapx_metadata_get_foldertype (CamelKolabImapxMetadata *kmd, CamelService *service, const gchar *foldername, gboolean do_updatedb, GCancellable *cancellable, GError **err);
-gboolean camel_kolab_imapx_metadata_set_foldertype (CamelKolabImapxMetadata *kmd, CamelService *serivce, const gchar *foldername, KolabFolderTypeID foldertype, GCancellable *cancellable, GError **err);
-gboolean camel_kolab_imapx_metadata_remove (CamelKolabImapxMetadata *kmd, const gchar *foldername, GError **err);
+CamelKolabImapxMetadata*
+camel_kolab_imapx_metadata_new (void);
+
+void
+camel_kolab_imapx_metadata_free (CamelKolabImapxMetadata *kmd);
+
+gboolean
+camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd,
+ const gchar *cachepath,
+ GError **err);
+
+gboolean
+camel_kolab_imapx_metadata_shutdown (CamelKolabImapxMetadata *kmd,
+ GError **err);
+
+gboolean
+camel_kolab_imapx_metadata_remove (CamelKolabImapxMetadata *kmd,
+ const gchar *foldername,
+ GError **err);
/*----------------------------------------------------------------------------*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]