[evolution-kolab/ek-wip-porting-imapx] CamelKolabSession: build fixes, derive from CamelSession
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab/ek-wip-porting-imapx] CamelKolabSession: build fixes, derive from CamelSession
- Date: Wed, 7 Dec 2011 14:52:34 +0000 (UTC)
commit f1086c454378480da8fa00bf22e7c628d9bc9f0c
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Wed Dec 7 15:43:59 2011 +0100
CamelKolabSession: build fixes, derive from CamelSession
* replaced CamelType with GType
* replaced CamelException with GError
* cleanly derive from CamelSession, put private
members into CamelKolabSessionPrivate struct
* reflect CamelSession API changes
* public getters/setters need to be reworked
for CamelSettings and GObject properties
src/camel/camel-kolab-session.c | 336 +++++++++++++++++++++------------------
src/camel/camel-kolab-session.h | 103 ++++++++-----
2 files changed, 248 insertions(+), 191 deletions(-)
---
diff --git a/src/camel/camel-kolab-session.c b/src/camel/camel-kolab-session.c
index 18123a8..b19d9cd 100644
--- a/src/camel/camel-kolab-session.c
+++ b/src/camel/camel-kolab-session.c
@@ -53,161 +53,102 @@
/*----------------------------------------------------------------------------*/
-static CamelSessionClass *parent_class = NULL;
static gchar *nss_tok_pin = NULL; /* FIXME better solution for this */
/*----------------------------------------------------------------------------*/
-static gchar* camel_kolab_session_get_password (CamelSession*, CamelService*, const gchar*, const gchar*, const gchar*, guint32, CamelException*);
-static void camel_kolab_session_forget_password (CamelSession*, CamelService*, const gchar*, const gchar*, CamelException*);
+typedef struct _CamelKolabSessionPrivate CamelKolabSessionPrivate;
+struct _CamelKolabSessionPrivate {
+ /* TODO these should be retrieved
+ * from CamelKolabSettings instead
+ */
+ gchar *data_dir;
+ gchar *config_dir;
+ gchar *passwd;
+
+ /* TODO get rid of this workaround */
+ gchar *nss_tok_pwd;
+
+ gboolean is_initialized;
+};
+
+#define CAMEL_KOLAB_SESSION_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CAMEL_TYPE_KOLAB_SESSION, CamelKolabSessionPrivate))
+
+G_DEFINE_TYPE (CamelKolabSession, camel_kolab_session, CAMEL_TYPE_SESSION)
/*----------------------------------------------------------------------------*/
static void
camel_kolab_session_init (CamelKolabSession *self)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
+ CamelKolabSessionPrivate *priv = NULL;
- self->data_dir = NULL;
- self->config_dir = NULL;
- self->nss_tok_pwd = NULL;
- self->passwd = NULL;
- self->is_initialized = FALSE;
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+ priv->data_dir = NULL;
+ priv->config_dir = NULL;
+ priv->nss_tok_pwd = NULL;
+ priv->passwd = NULL;
+ priv->is_initialized = FALSE;
}
static void
-camel_kolab_session_finalize (CamelKolabSession *self)
+camel_kolab_session_dispose (GObject *object)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
-
- if (self->data_dir != NULL)
- g_free (self->data_dir);
- if (self->config_dir != NULL)
- g_free (self->config_dir);
- if (self->nss_tok_pwd != NULL)
- g_free (self->nss_tok_pwd);
- if (self->passwd)
- g_free (self->passwd);
-}
-
-static void
-camel_kolab_session_class_init (CamelKolabSessionClass *klass)
-{
- CamelSessionClass *camel_session_class = CAMEL_SESSION_CLASS (klass);
- parent_class = CAMEL_SESSION_CLASS (camel_type_get_global_classfuncs (CAMEL_SESSION_TYPE));
-
- /* virtual method definition */
- camel_session_class->get_service = parent_class->get_service;
- camel_session_class->get_storage_path = parent_class->get_storage_path;
-
- camel_session_class->thread_msg_new = parent_class->thread_msg_new;
- camel_session_class->thread_msg_free = parent_class->thread_msg_free;
- camel_session_class->thread_queue = parent_class->thread_queue;
- camel_session_class->thread_wait = parent_class->thread_wait;
- camel_session_class->thread_status = parent_class->thread_status;
-
- camel_session_class->forward_to = parent_class->forward_to;
+ g_assert (CAMEL_IS_KOLAB_SESSION (object));
- /* virtual method override */
- camel_session_class->get_password = camel_kolab_session_get_password;
- camel_session_class->forget_password = camel_kolab_session_forget_password;
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (camel_kolab_session_parent_class)->dispose (object);
}
-CamelType
-camel_kolab_session_get_type (void)
+static void
+camel_kolab_session_finalize (GObject *object)
{
- /* TODO might need another mechanism than 'static'
- * when dealing with multiple session instances
- */
- static CamelType camel_kolab_session_type = CAMEL_INVALID_TYPE;
+ CamelKolabSession *self = NULL;
+ CamelKolabSessionPrivate *priv = NULL;
- /* TODO check whether one single KolabSession type
- * is okay (it should, as all Camel.Providers
- * we use will be IMAPX providers under the hood)
- */
- if (camel_kolab_session_type == CAMEL_INVALID_TYPE) {
- camel_kolab_session_type = \
- camel_type_register (camel_session_get_type (),
- "CamelKolabSession",
- sizeof (CamelKolabSession),
- sizeof (CamelKolabSessionClass),
- (CamelObjectClassInitFunc) camel_kolab_session_class_init,
- NULL,
- (CamelObjectInitFunc) camel_kolab_session_init,
- (CamelObjectFinalizeFunc) camel_kolab_session_finalize);
- }
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
- return camel_kolab_session_type;
-}
+ self = CAMEL_KOLAB_SESSION (object);
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
-/*----------------------------------------------------------------------------*/
-/* passwords */
-
-static gchar*
-camel_kolab_session_get_password (CamelSession *self,
- CamelService *service,
- const gchar *domain,
- const gchar *prompt,
- const gchar *item,
- guint32 flags,
- CamelException *ex)
-{
- CamelKolabSession *myself = CAMEL_KOLAB_SESSION (self);
+ if (priv->data_dir != NULL)
+ g_free (priv->data_dir);
+ if (priv->config_dir != NULL)
+ g_free (priv->config_dir);
+ if (priv->nss_tok_pwd != NULL)
+ g_free (priv->nss_tok_pwd);
+ if (priv->passwd)
+ g_free (priv->passwd);
- (void)service;
- (void)domain;
- (void)prompt;
- (void)item;
- (void)flags;
- (void)ex;
-
- return g_strdup (myself->passwd);
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (camel_kolab_session_parent_class)->finalize (object);
}
static void
-camel_kolab_session_forget_password (CamelSession *self,
- CamelService *service,
- const gchar *domain,
- const gchar *item,
- CamelException *ex)
+camel_kolab_session_class_init (CamelKolabSessionClass *klass)
{
- CamelKolabSession *myself = CAMEL_KOLAB_SESSION (self);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ CamelSessionClass *session_class = CAMEL_SESSION_CLASS (klass);
+ CamelSessionClass *parent_class = CAMEL_SESSION_CLASS (camel_kolab_session_parent_class);
- (void)service;
- (void)domain;
- (void)item;
- (void)ex;
+ g_type_class_add_private (klass, sizeof (CamelKolabSessionPrivate));
- if (myself->passwd != NULL)
- g_free (myself->passwd);
+ object_class->set_property = G_OBJECT_CLASS (parent_class)->set_property;
+ object_class->get_property = G_OBJECT_CLASS (parent_class)->get_property;
+ object_class->dispose = camel_kolab_session_dispose;
+ object_class->finalize = camel_kolab_session_finalize;
- myself->passwd = NULL;
-}
+ session_class->add_service = parent_class->add_service; /* TODO need to override this */
-void
-camel_kolab_session_set_password (CamelKolabSession *self,
- const gchar *passwd)
-{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
-
- if (self->passwd != NULL)
- g_free (self->passwd);
-
- self->passwd = g_strdup (passwd);
+ session_class->authenticate_sync = parent_class->authenticate_sync;
+ session_class->authenticate = parent_class->authenticate;
+ session_class->authenticate_finish = parent_class->authenticate_finish;
}
-void
-camel_kolab_session_set_token_pin (CamelKolabSession *self,
- const gchar *pin)
-{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
-
- if (nss_tok_pin != NULL)
- g_free (nss_tok_pin);
-
- nss_tok_pin = g_strdup (pin);
-}
+/*----------------------------------------------------------------------------*/
+/* password callbacks */
/* NSS token pin callback */
static gchar* PR_CALLBACK
@@ -227,27 +168,20 @@ pk11_password (PK11SlotInfo *slot,
/*----------------------------------------------------------------------------*/
-CamelKolabSession*
-camel_kolab_session_new (void)
-{
- CamelKolabSession *session = NULL;
-
- session = CAMEL_KOLAB_SESSION (camel_object_new (CAMEL_KOLAB_SESSION_TYPE));
-
- /* init the EAccount setup */
- /* e_account_writable (NULL, E_ACCOUNT_SOURCE_SAVE_PASSWD); */
-
- return session;
-}
-
gboolean
camel_kolab_session_bringup (CamelKolabSession *self,
GError **err)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
+ /* TODO rework to use GInitable */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- if (self->is_initialized)
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ if (priv->is_initialized)
return TRUE;
/* TODO need to supply (parts of) storage paths here so the imap
@@ -258,7 +192,7 @@ camel_kolab_session_bringup (CamelKolabSession *self,
/* TODO check whether this is The Right Way to
* initialize the session parent
*/
- if (self->data_dir == NULL) {
+ if (priv->data_dir == NULL) {
g_set_error (err,
KOLAB_CAMEL_KOLAB_ERROR,
KOLAB_CAMEL_KOLAB_ERROR_GENERIC,
@@ -266,14 +200,13 @@ camel_kolab_session_bringup (CamelKolabSession *self,
__func__);
return FALSE;
}
- camel_session_construct (CAMEL_SESSION (self), self->data_dir);
/* TODO junk settings */
/* setup further NSS bits here */
PK11_SetPasswordFunc (pk11_password);
- self->is_initialized = TRUE;
+ priv->is_initialized = TRUE;
g_debug ("%s: camel session initialized",
__func__);
@@ -284,10 +217,14 @@ gboolean
camel_kolab_session_shutdown (CamelKolabSession *self,
GError **err)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- if (! self->is_initialized)
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ if (! priv->is_initialized)
return TRUE;
g_debug ("%s: camel session shut down",
@@ -302,40 +239,131 @@ void
camel_kolab_session_set_data_dir (CamelKolabSession *self,
gchar *datadir)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
+ /* TODO rework to use CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
g_assert (datadir != NULL);
- if (self->data_dir != NULL)
- g_free (self->data_dir);
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
- self->data_dir = datadir;
+ if (priv->data_dir != NULL)
+ g_free (priv->data_dir);
+
+ priv->data_dir = datadir;
}
const gchar*
camel_kolab_session_get_data_dir (CamelKolabSession *self)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
- return self->data_dir;
+ /* TODO rework to use CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ return priv->data_dir;
}
void
camel_kolab_session_set_config_dir (CamelKolabSession *self,
- gchar *configdir)
+ const gchar *configdir)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
+ /* TODO rework to use CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
g_assert (configdir != NULL);
- if (self->config_dir != NULL)
- g_free (self->config_dir);
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ if (priv->config_dir != NULL)
+ g_free (priv->config_dir);
- self->config_dir = configdir;
+ priv->config_dir = g_strdup (configdir);
}
const gchar*
camel_kolab_session_get_config_dir (CamelKolabSession *self)
{
- g_assert (CAMEL_KOLAB_IS_SESSION (self));
- return self->config_dir;
+ /* TODO rework to use CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ return priv->config_dir;
+}
+
+const gchar*
+camel_kolab_session_get_password (CamelKolabSession *self)
+{
+ /* TODO rework to CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ return priv->passwd;
+}
+
+void
+camel_kolab_session_forget_password (CamelKolabSession *self)
+{
+ /* TODO rework to CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ if (priv->passwd != NULL) {
+ g_free (priv->passwd);
+ priv->passwd = NULL;
+ }
+}
+
+void
+camel_kolab_session_set_password (CamelKolabSession *self,
+ const gchar *passwd)
+{
+ /* TODO rework to CamelSettings */
+
+ CamelKolabSessionPrivate *priv = NULL;
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+ priv = CAMEL_KOLAB_SESSION_PRIVATE (self);
+
+ if (priv->passwd != NULL)
+ g_free (priv->passwd);
+
+ priv->passwd = g_strdup (passwd);
+}
+
+void
+camel_kolab_session_set_token_pin (CamelKolabSession *self,
+ const gchar *pin)
+{
+ /* TODO rework
+ *
+ * The entire NSS token handling needs
+ * to be rewritten (it is a mere demonstrator
+ * presently, and should not be relied upon
+ * in critical environments
+ *
+ */
+
+ g_assert (CAMEL_IS_KOLAB_SESSION (self));
+
+ if (nss_tok_pin != NULL)
+ g_free (nss_tok_pin);
+
+ nss_tok_pin = g_strdup (pin);
}
/*----------------------------------------------------------------------------*/
diff --git a/src/camel/camel-kolab-session.h b/src/camel/camel-kolab-session.h
index 2a74dec..baaf064 100644
--- a/src/camel/camel-kolab-session.h
+++ b/src/camel/camel-kolab-session.h
@@ -27,19 +27,10 @@
/*
* The CamelSession class for Kolab access. To be instantiated once for
- * each IMAPX Camel.Provider we have. Within EDS, this is one for address book
- * and one for calendar access. Within Evolution, there should be one more
- * for email (if at all we can supply our own IMAPX provider there).
+ * each IMAPX CamelKolabIMAPXProvider we have. Within EDS, this is one for
+ * address book and one for calendar access. Within Evolution, a CamelSession
+ * object is already instantiated and will be used for the CamelKolabIMAPXProvider
*
- * Since we have three independent connections to the one same
- * Kolab IMAP server for email, addresses and calendar, we will
- * (most probably) need three CamelSession instances. To avoid confusion,
- * we will declare one within the address book backend (process), one in
- * the calendar backend (process) and one in the email process.
- *
- * To hide these CamelSession objects from one another, we will declare
- * them within the libs which will use them only, rather than making
- * them visible system-wide.
*/
/*----------------------------------------------------------------------------*/
@@ -50,47 +41,85 @@
/*----------------------------------------------------------------------------*/
#include <glib.h>
+#include <glib-object.h>
#include <libekolabutil/camel-system-headers.h>
/*----------------------------------------------------------------------------*/
-
-#define CAMEL_KOLAB_SESSION_TYPE (camel_kolab_session_get_type ())
-#define CAMEL_KOLAB_SESSION(obj) (CAMEL_CHECK_CAST((obj), CAMEL_KOLAB_SESSION_TYPE, CamelKolabSession))
-#define CAMEL_KOLAB_SESSION_CLASS(klass) (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_KOLAB_SESSION_TYPE, CamelKolabSessionClass))
-#define CAMEL_KOLAB_IS_SESSION(obj) (CAMEL_CHECK_TYPE((obj), CAMEL_KOLAB_SESSION_TYPE))
+/* Standard GObject macros */
+
+#define CAMEL_TYPE_KOLAB_SESSION \
+ (camel_kolab_session_get_type ())
+#define CAMEL_KOLAB_SESSION(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), CAMEL_TYPE_KOLAB_SESSION, CamelKolabSession))
+#define CAMEL_KOLAB_SESSION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((klass), CAMEL_TYPE_KOLAB_SESSION, CamelKolabSessionClass))
+#define CAMEL_IS_KOLAB_SESSION(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), CAMEL_TYPE_KOLAB_SESSION))
+#define CAMEL_IS_KOLAB_SESSION_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((klass), CAMEL_TYPE_KOLAB_SESSION))
+#define CAMEL_KOLAB_SESSION_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), CAMEL_TYPE_KOLAB_SESSION, CamelKolabSessionClass))
G_BEGIN_DECLS
-typedef struct _CamelKolabSession {
- CamelSession parent_instance;
+typedef struct _CamelKolabSession CamelKolabSession;
+struct _CamelKolabSession {
+ CamelSession parent;
+};
- gchar *data_dir;
- gchar *config_dir;
- gchar *nss_tok_pwd;
- gchar *passwd;
- gboolean is_initialized;
-} CamelKolabSession;
-typedef struct _CamelKolabSessionClass {
+typedef struct _CamelKolabSessionClass CamelKolabSessionClass;
+struct _CamelKolabSessionClass {
CamelSessionClass parent_class;
/* TODO check what else is needed here */
+};
+
+GType
+camel_kolab_session_get_type (void);
+
+gboolean
+camel_kolab_session_bringup (CamelKolabSession *self,
+ GError **err);
+
+gboolean
+camel_kolab_session_shutdown (CamelKolabSession *self,
+ GError **err);
+
+void
+camel_kolab_session_set_password (CamelKolabSession *self,
+ const gchar *passwd);
+
+void
+camel_kolab_session_set_token_pin (CamelKolabSession *self,
+ const gchar *pin);
+
+void
+camel_kolab_session_set_data_dir (CamelKolabSession *self,
+ gchar *datadir);
+
+const gchar*
+camel_kolab_session_get_data_dir (CamelKolabSession *self);
+
+void
+camel_kolab_session_set_config_dir (CamelKolabSession *self,
+ const gchar *configdir);
-} CamelKolabSessionClass;
+const gchar*
+camel_kolab_session_get_config_dir (CamelKolabSession *self);
-GType camel_kolab_session_get_type (void);
+const gchar*
+camel_kolab_session_get_password (CamelKolabSession *self);
-CamelKolabSession* camel_kolab_session_new (void);
-gboolean camel_kolab_session_bringup (CamelKolabSession *self, GError **err);
-gboolean camel_kolab_session_shutdown (CamelKolabSession *self, GError **err);
+void
+camel_kolab_session_forget_password (CamelKolabSession *self);
-void camel_kolab_session_set_password (CamelKolabSession *self, const gchar *passwd);
-void camel_kolab_session_set_token_pin (CamelKolabSession *self, const gchar *pin);
-void camel_kolab_session_set_data_dir (CamelKolabSession *self, gchar *datadir);
-const gchar* camel_kolab_session_get_data_dir (CamelKolabSession *self);
-void camel_kolab_session_set_config_dir (CamelKolabSession *self, gchar *configdir);
-const gchar* camel_kolab_session_get_config_dir (CamelKolabSession *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]