[evolution-kolab/ek-wip-porting-imapx] CamelKolabIMAPXServer; added API functions (foldertype getters/setters)
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab/ek-wip-porting-imapx] CamelKolabIMAPXServer; added API functions (foldertype getters/setters)
- Date: Mon, 5 Dec 2011 15:27:38 +0000 (UTC)
commit 3c66f899c3a984430cc4f28c7fddaca1debe5e73
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Mon Dec 5 16:13:00 2011 +0100
CamelKolabIMAPXServer; added API functions (foldertype getters/setters)
* added Kolab folder type getter/setter functions
which previously lived in camel-kolab-imapx-metadata.[hc]
since in gnome-2-30 we did not have a CamelKolabIMAPXServer
* added a CamelKolabIMAPXStore* member (likewise,
CamelKolabIMAPXStore will get a CamelKolabIMAPXServer*
private member, both descendants of their respective
CamelIMAPXExtd* classes, this is mainly to ensure via
the GType system that we always deal with the correct
flavor of the various IMAPX classes)
* reindented
src/camel/camel-kolab-imapx-server.c | 353 ++++++++++++++++++++++++++++++----
src/camel/camel-kolab-imapx-server.h | 81 +++++---
2 files changed, 365 insertions(+), 69 deletions(-)
---
diff --git a/src/camel/camel-kolab-imapx-server.c b/src/camel/camel-kolab-imapx-server.c
index 8f51f6f..24bea39 100644
--- a/src/camel/camel-kolab-imapx-server.c
+++ b/src/camel/camel-kolab-imapx-server.c
@@ -1,37 +1,41 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/***************************************************************************
-* camel-kolab-imapx-server.c
-*
-* 2011-12-02, 17:05:41
-* Copyright 2011, Christian Hilberg
-* <hilberg unix-ag org>
-****************************************************************************/
+ * camel-kolab-imapx-server.c
+ *
+ * 2011-12-02, 17:05:41
+ * Copyright 2011, Christian Hilberg
+ * <hilberg unix-ag org>
+ ****************************************************************************/
/*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with main.c; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
-*/
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with main.c; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
+ */
/*----------------------------------------------------------------------------*/
+#include <string.h>
+
+#include "camel-kolab-imapx-store.h"
#include "camel-kolab-imapx-server.h"
/*----------------------------------------------------------------------------*/
typedef struct _CamelKolabIMAPXServerPrivate CamelKolabIMAPXServerPrivate;
struct _CamelKolabIMAPXServerPrivate {
- CamelKolabImapxMetadata *metadata;
+ CamelKolabIMAPXStore *kstore; /* Kolab Camel store */
+ CamelKolabImapxMetadata *kmd; /* Kolab metadata (differs from IMAPX metadata!) */
};
#define CAMEL_KOLAB_IMAPX_SERVER_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServerPrivate))
@@ -52,7 +56,7 @@ camel_kolab_imapx_server_init (CamelKolabIMAPXServer *object)
self = object;
priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
- priv->metadata = NULL;
+ priv->kmd = NULL;
}
static void
@@ -71,11 +75,11 @@ camel_kolab_imapx_server_finalize (GObject *object)
g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (object));
- self = object;
+ self = CAMEL_KOLAB_IMAPX_SERVER (object);
priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
- camel_kolab_imapx_metadata_free (priv->metadata);
-
+ camel_kolab_imapx_metadata_free (priv->kmd);
+
G_OBJECT_CLASS (camel_kolab_imapx_server_parent_class)->finalize (object);
}
@@ -100,17 +104,17 @@ camel_kolab_imapx_server_get_metadata (CamelKolabIMAPXServer *server,
{
CamelKolabIMAPXServer *self = NULL;
CamelKolabIMAPXServerPrivate *priv = NULL;
-
- g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
- (void)do_resect; /* FIXME */
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+ (void)do_resect; /* FIXME */
g_return_val_if_fail (err == NULL || *err == NULL, NULL);
- self = server;
- priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
-
+ self = server;
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
/* FIXME */
g_error ("%s: FIXME: implement me", __func__);
-
+
return NULL;
}
@@ -121,17 +125,290 @@ camel_kolab_imapx_server_set_metadata (CamelKolabIMAPXServer *server,
{
CamelKolabIMAPXServer *self = NULL;
CamelKolabIMAPXServerPrivate *priv = NULL;
-
- g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+ g_assert (kmd != NULL);
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- self = server;
- priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
-
+ self = server;
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
/* FIXME */
g_error ("%s: FIXME: implement me", __func__);
-
+
return FALSE;
}
+KolabFolderTypeID
+camel_kolab_imapx_server_get_foldertype (CamelKolabIMAPXServer *server,
+ const gchar *foldername,
+ gboolean do_updatedb,
+ GCancellable *cancellable,
+ GError **err)
+{
+ /* TODO better error reporting */
+ CamelKolabIMAPXServer *self = NULL;
+ CamelKolabIMAPXServerPrivate *priv = NULL;
+ CamelIMAPXExtdServer *eserver = NULL;
+ CamelOfflineStore *ostore = 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 (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+ g_assert (foldername != NULL);
+ g_assert (G_IS_CANCELLABLE (cancellable));
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+ self = server;
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
+ /* hash table lookup */
+ kfmd = g_hash_table_lookup (priv->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 (priv->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 (priv->kmd->kolab_metadata,
+ g_strdup (foldername),
+ kfmd);
+ return kfmd->folder_type;
+ }
+
+ /* check whether we are online */
+ ostore = CAMEL_OFFLINE_STORE (priv->kstore);
+ if (! camel_offline_store_get_online (ostore)) {
+ /* TODO turn this into proper GError */
+ g_warning ("%s: must be online to complete this operation",
+ __func__);
+ return KOLAB_FOLDER_TYPE_UNKNOWN;
+ }
+
+ /* TODO check whether we're authenticated */
+ g_warning ("%s: FIXME implement authenticated check",
+ __func__);
+
+ /* if not in sqlite db: issue IMAP query */
+ eserver = CAMEL_IMAPX_EXTD_SERVER (self);
+ proto = camel_imapx_extd_server_metadata_get_proto (eserver);
+ spec = camel_imapx_metadata_spec_new (proto,
+ foldername,
+ "/vendor/kolab/folder-type",
+ "value",
+ &tmp_err);
+ if (spec == NULL) {
+ g_propagate_error (err, tmp_err);
+ return KOLAB_FOLDER_TYPE_INVAL;
+ }
+
+ /* resect all metadata gathered so far from CamelIMAPXServer */
+ md = camel_imapx_extd_server_get_metadata (eserver,
+ spec,
+ TRUE,
+ &tmp_err);
+ camel_imapx_metadata_spec_free (spec);
+
+ if (tmp_err != NULL) {
+ g_propagate_error (err, tmp_err);
+ return KOLAB_FOLDER_TYPE_INVAL;
+ }
+
+ if (md != NULL) {
+ /* create kolab "flat" data structure */
+ camel_kolab_imapx_metadata_update (priv->kmd,
+ md,
+ proto);
+ camel_imapx_metadata_free (md);
+
+ /* stuff folder types into metadata_db */
+ if (do_updatedb) {
+ db_ok = camel_kolab_imapx_metadata_db_update (priv->kmd->mdb,
+ priv->kmd->kolab_metadata,
+ &tmp_err);
+ if (!db_ok) {
+ g_propagate_error (err, tmp_err);
+ return KOLAB_FOLDER_TYPE_INVAL;
+ }
+ }
+ }
+
+ /* final hash table lookup */
+ kfmd = g_hash_table_lookup (priv->kmd->kolab_metadata,
+ foldername);
+ if (kfmd == NULL)
+ return KOLAB_FOLDER_TYPE_UNKNOWN;
+
+ return kfmd->folder_type;
+}
+
+gboolean
+camel_kolab_imapx_server_set_foldertype (CamelKolabIMAPXServer *server,
+ const gchar *foldername,
+ KolabFolderTypeID foldertype,
+ GCancellable *cancellable,
+ GError **err)
+{
+ CamelKolabIMAPXServer *self = NULL;
+ CamelKolabIMAPXServerPrivate *priv = NULL;
+ CamelIMAPXExtdServer *eserver = NULL;
+ CamelOfflineStore *ostore = NULL;
+ CamelImapxMetadata *md = NULL;
+ CamelImapxMetadataAnnotation *man = NULL;
+ CamelImapxMetadataEntry *me = NULL;
+ CamelImapxMetadataAttrib *ma = NULL;
+ const gchar *typestring = 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;
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+ g_assert (foldername != NULL);
+ g_assert (G_IS_CANCELLABLE (cancellable));
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+ self = server;
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
+ /* check whether we're online */
+ ostore = CAMEL_OFFLINE_STORE (priv->kstore);
+ if (! camel_offline_store_get_online (ostore)) {
+ /* TODO turn this into proper GError */
+ g_warning ("%s: must be online to complete this operation",
+ __func__);
+ return FALSE;
+ }
+
+ /* TODO check whether we're authenticated */
+ g_warning ("%s: FIXME implement authenticated check",
+ __func__);
+
+ eserver = CAMEL_IMAPX_EXTD_SERVER (self);
+
+ /* 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;
+ typestring = kolab_util_folder_type_get_string (foldertype);
+ ma->data[acc] = g_byte_array_new ();
+ g_byte_array_append (ma->data[acc],
+ (guchar *) g_strdup (typestring),
+ strlen (typestring));
+ 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_extd_server_metadata_get_proto (eserver);
+ 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_extd_server_set_metadata (eserver,
+ md,
+ &tmp_err);
+ if (! metadata_ok) {
+ camel_imapx_metadata_free (md);
+ g_propagate_error (err, tmp_err);
+ return FALSE;
+ }
+
+ /* create kolab "flat" data structure */
+ camel_kolab_imapx_metadata_update (priv->kmd, md, proto);
+
+ /* stuff folder types into metadata_db */
+ db_ok = camel_kolab_imapx_metadata_db_update (priv->kmd->mdb,
+ priv->kmd->kolab_metadata,
+ &tmp_err);
+ if (! db_ok) {
+ g_propagate_error (err, tmp_err);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* CAUTION -- TESTING purposes only! The server response may
+ * become too long to properly handle it!
+ */
+gboolean
+camel_kolab_imapx_server_retrieve_all_folder_types (CamelKolabIMAPXServer *server,
+ GCancellable *cancellable,
+ GError **err)
+{
+ CamelKolabIMAPXServer *self = NULL;
+ CamelKolabIMAPXServerPrivate *priv = NULL;
+ CamelIMAPXExtdServer *eserver = NULL;
+ CamelOfflineStore *ostore = NULL;
+ CamelImapxMetadataSpec *spec = NULL;
+ camel_imapx_metadata_proto_t proto = CAMEL_IMAPX_METADATA_PROTO_INVAL;
+ GError *tmp_err = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (server));
+ g_assert (G_IS_CANCELLABLE (cancellable));
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+ self = server;
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
+ /* check whether we're online */
+ ostore = CAMEL_OFFLINE_STORE (priv->kstore);
+ if (! camel_offline_store_get_online (ostore)) {
+ /* TODO turn this into proper GError */
+ g_warning ("%s: must be online to complete this operation",
+ __func__);
+ return FALSE;
+ }
+
+ /* TODO check whether we're authenticated */
+ g_warning ("%s: FIXME implement authenticated check",
+ __func__);
+
+ eserver = CAMEL_IMAPX_EXTD_SERVER (self);
+
+ proto = camel_imapx_extd_server_metadata_get_proto (eserver);
+ 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;
+ }
+
+ /* fetch annotations from server, do not resect the data
+ * from CamelIMAPXExtdServer as yet
+ */
+ (void)camel_imapx_extd_server_get_metadata (eserver,
+ spec,
+ FALSE,
+ &tmp_err);
+ camel_imapx_metadata_spec_free (spec);
+ if (tmp_err != NULL) {
+ g_propagate_error (err, tmp_err);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/*----------------------------------------------------------------------------*/
diff --git a/src/camel/camel-kolab-imapx-server.h b/src/camel/camel-kolab-imapx-server.h
index 4fd4b4c..342a5b5 100644
--- a/src/camel/camel-kolab-imapx-server.h
+++ b/src/camel/camel-kolab-imapx-server.h
@@ -1,27 +1,27 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/***************************************************************************
-* camel-kolab-imapx-server.h
-*
-* 2011-12-02, 17:05:40
-* Copyright 2011, Christian Hilberg
-* <hilberg unix-ag org>
-****************************************************************************/
+ * camel-kolab-imapx-server.h
+ *
+ * 2011-12-02, 17:05:40
+ * Copyright 2011, Christian Hilberg
+ * <hilberg unix-ag org>
+ ****************************************************************************/
/*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with main.c; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
-*/
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with main.c; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
+ */
/*----------------------------------------------------------------------------*/
@@ -44,21 +44,21 @@
#define CAMEL_TYPE_KOLAB_IMAPX_SERVER \
(camel_kolab_imapx_server_get_type ())
-#define CAMEL_KOLAB_IMAPX_SERVER(obj) \
+#define CAMEL_KOLAB_IMAPX_SERVER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
- ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServer))
-#define CAMEL_KOLAB_IMAPX_SERVER_CLASS(klass) \
+ ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServer))
+#define CAMEL_KOLAB_IMAPX_SERVER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST \
- ((klass), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServerClass))
-#define CAMEL_IS_KOLAB_IMAPX_SERVER(obj) \
+ ((klass), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServerClass))
+#define CAMEL_IS_KOLAB_IMAPX_SERVER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
- ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER))
-#define CAMEL_IS_KOLAB_IMAPX_SERVER_CLASS(klass) \
+ ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER))
+#define CAMEL_IS_KOLAB_IMAPX_SERVER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE \
- ((klass), CAMEL_TYPE_KOLAB_IMAPX_SERVER))
-#define CAMEL_KOLAB_IMAPX_SERVER_GET_CLASS(obj) \
+ ((klass), CAMEL_TYPE_KOLAB_IMAPX_SERVER))
+#define CAMEL_KOLAB_IMAPX_SERVER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS \
- ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServerClass))
+ ((obj), CAMEL_TYPE_KOLAB_IMAPX_SERVER, CamelKolabIMAPXServerClass))
G_BEGIN_DECLS
@@ -86,10 +86,29 @@ camel_kolab_imapx_server_set_metadata (CamelKolabIMAPXServer *server,
CamelKolabImapxMetadata *kmd,
GError **err);
+KolabFolderTypeID
+camel_kolab_imapx_server_get_foldertype (CamelKolabIMAPXServer *server,
+ const gchar *foldername,
+ gboolean do_updatedb,
+ GCancellable *cancellable,
+ GError **err);
+
+gboolean
+camel_kolab_imapx_server_set_foldertype (CamelKolabIMAPXServer *server,
+ const gchar *foldername,
+ KolabFolderTypeID foldertype,
+ GCancellable *cancellable,
+ GError **err);
+
+gboolean
+camel_kolab_imapx_server_retrieve_all_folder_types (CamelKolabIMAPXServer *server,
+ GCancellable *cancellable,
+ GError **err);
+
G_END_DECLS
/*----------------------------------------------------------------------------*/
-#endif /* CAMEL_IMAPX_SERVER_EXTN_H_ */
+#endif /* CAMEL_KOLAB_IMAPX_SERVER_H_ */
/*----------------------------------------------------------------------------*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]