[evolution-kolab/ek-wip-porting] CamelIMAPXServer: expose symbols for subclasses



commit caeb5659ed33aecdb0cc777b9865e87e0fcfdf0c
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Jan 23 22:17:38 2012 +0100

    CamelIMAPXServer: expose symbols for subclasses
    
    * added a "friend" API with its own header file,
      exposing internal CamelIMAPXServer functions
      needed by CamelIMAPXExtdServer
    * added a header file with temporary declarations
      of CamelIMAPXServer-internal macros and strucutres
      for use inside CamelIMAPXExtdServer
    * both of these can be dropped once upstream picks up
      the extended versions of our IMAPX classes

 src/camel/providers/imapx/Makefile.am              |    4 +-
 .../providers/imapx/camel-imapx-server-defs.h      |  249 ++++++++++++++++++++
 .../providers/imapx/camel-imapx-server-friend.h    |  127 ++++++++++
 src/camel/providers/imapx/camel-imapx-server.c     |  217 +++++++++++++++++
 4 files changed, 596 insertions(+), 1 deletions(-)
---
diff --git a/src/camel/providers/imapx/Makefile.am b/src/camel/providers/imapx/Makefile.am
index 0e0a869..edb7224 100644
--- a/src/camel/providers/imapx/Makefile.am
+++ b/src/camel/providers/imapx/Makefile.am
@@ -46,6 +46,8 @@ noinst_HEADERS =				\
 	camel-imapx-extd-folder.h		\
 	camel-imapx-metadata.h			\
 	camel-imapx-server.h			\
+	camel-imapx-server-defs.h		\
+	camel-imapx-server-friend.h		\
 	camel-imapx-extd-server.h		\
 	camel-imapx-settings.h			\
 	camel-imapx-store-summary.h		\
@@ -58,7 +60,7 @@ noinst_HEADERS =				\
 camel-imapx-tokenise.h: camel-imapx-tokens.txt
 	@GPERF@ -H imapx_hash -N imapx_tokenise_struct -L ANSI-C -o -t -k1,$$ $< --output-file=$@
 camel-imapx-extd-tokenise.h: camel-imapx-extd-tokens.txt
-	@GPERF@ -H imapx_hash -N imapx_extd_tokenise_struct -L ANSI-C -o -t -k1,$$ $< --output-file=$@
+	@GPERF@ -H imapx_hash -N imapx_tokenise_struct -L ANSI-C -o -t -k1,$$ $< --output-file=$@
 
 libcamelimapx_la_LIBADD = \
         $(CAMEL_LIBS)				\
diff --git a/src/camel/providers/imapx/camel-imapx-server-defs.h b/src/camel/providers/imapx/camel-imapx-server-defs.h
new file mode 100644
index 0000000..b00c5f0
--- /dev/null
+++ b/src/camel/providers/imapx/camel-imapx-server-defs.h
@@ -0,0 +1,249 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-server-defs.h
+ *
+ *  2012-01-20, 19:07:18
+ *  Copyright 2012, 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 file holds definitions needed by CamelIMAPXExtdServer,
+ * but not exported by its parent class. In order not to mess with
+ * upstream code, we (temporarily) dupe the symbols here.
+ * Once the *Extd* classes get merged into their upstream counterparts,
+ * these dupes can be removed
+ */
+
+/*----------------------------------------------------------------------------*/
+
+#ifndef _CAMEL_IMAPX_SERVER_DEFS_H_
+#define _CAMEL_IMAPX_SERVER_DEFS_H_
+
+/*----------------------------------------------------------------------------*/
+
+#define c(...) camel_imapx_debug(command, __VA_ARGS__)
+#define e(...) camel_imapx_debug(extra, __VA_ARGS__)
+
+#define QUEUE_LOCK(x) (g_static_rec_mutex_lock(&(x)->queue_lock))
+#define QUEUE_UNLOCK(x) (g_static_rec_mutex_unlock(&(x)->queue_lock))
+
+#define IDLE_LOCK(x) (g_mutex_lock((x)->idle_lock))
+#define IDLE_UNLOCK(x) (g_mutex_unlock((x)->idle_lock))
+
+enum {SELECT_CHANGED,
+      SHUTDOWN,
+      LAST_SIGNAL
+};
+
+struct _refresh_info {
+	gchar *uid;
+	gboolean exists;
+	guint32 server_flags;
+	CamelFlag *server_user_flags;
+};
+
+struct _uidset_state {
+	struct _CamelIMAPXEngine *ie;
+	gint entries, uids;
+	gint total, limit;
+	guint32 start;
+	guint32 last;
+};
+
+struct _CamelIMAPXJob {
+	volatile gint ref_count;
+
+	GCond *done_cond;
+	GMutex *done_mutex;
+	gboolean done_flag;
+
+	GCancellable *cancellable;
+	GError *error;
+	gboolean with_operation_msg;
+
+	void (*start)(CamelIMAPXServer *is, struct _CamelIMAPXJob *job);
+
+	guint noreply:1;	/* dont wait for reply */
+	guint32 type;		/* operation type */
+	gint pri;		/* the command priority */
+	gshort commands;	/* counts how many commands are outstanding */
+
+	CamelFolder *folder;
+
+	union {
+		struct {
+			/* in: uid requested */
+			gchar *uid;
+			/* in/out: message content stream output */
+			CamelStream *stream;
+			/* working variables */
+			gsize body_offset;
+			gssize body_len;
+			gsize fetch_offset;
+			gsize size;
+			gboolean use_multi_fetch;
+		} get_message;
+		struct {
+			/* array of refresh info's */
+			GArray *infos;
+			/* used for biulding uidset stuff */
+			gint index;
+			gint last_index;
+			gboolean update_unseen;
+			struct _uidset_state uidset;
+			/* changes during refresh */
+			CamelFolderChangeInfo *changes;
+		} refresh_info;
+		struct {
+			GPtrArray *changed_uids;
+			guint32 on_set;
+			guint32 off_set;
+			GArray *on_user; /* imapx_flag_change */
+			GArray *off_user;
+			gint unread_change;
+		} sync_changes;
+		struct {
+			gchar *path;
+			CamelMessageInfo *info;
+		} append_message;
+		struct {
+			CamelFolder *dest;
+			GPtrArray *uids;
+			gboolean delete_originals;
+			gint index;
+			gint last_index;
+			struct _uidset_state uidset;
+		} copy_messages;
+		struct {
+			gchar *pattern;
+			guint32 flags;
+			const gchar *ext;
+			GHashTable *folders;
+		} list;
+
+		struct {
+			const gchar *folder_name;
+			gboolean subscribe;
+		} manage_subscriptions;
+
+		struct {
+			const gchar *ofolder_name;
+			const gchar *nfolder_name;
+		} rename_folder;
+
+		const gchar *folder_name;
+	} u;
+};
+
+typedef enum {
+	CAMEL_IMAPX_COMMAND_SIMPLE = 0,
+	CAMEL_IMAPX_COMMAND_DATAWRAPPER,
+	CAMEL_IMAPX_COMMAND_STREAM,
+	CAMEL_IMAPX_COMMAND_AUTH,
+	CAMEL_IMAPX_COMMAND_FILE,
+	CAMEL_IMAPX_COMMAND_STRING,
+	CAMEL_IMAPX_COMMAND_MASK = 0xff,
+	CAMEL_IMAPX_COMMAND_LITERAL_PLUS = 0x4000, /* continuation with literal+ */
+	CAMEL_IMAPX_COMMAND_CONTINUATION = 0x8000 /* does this command expect continuation? */
+} camel_imapx_command_part_t;
+
+struct _CamelIMAPXCommandPart {
+	struct _CamelIMAPXCommandPart *next;
+	struct _CamelIMAPXCommandPart *prev;
+
+	struct _CamelIMAPXCommand *parent;
+
+	gint data_size;
+	gchar *data;
+
+	camel_imapx_command_part_t type;
+
+	gint ob_size;
+	gpointer ob;
+};
+
+typedef void (*CamelIMAPXCommandFunc)(struct _CamelIMAPXServer *engine, struct _CamelIMAPXCommand *);
+
+struct _CamelIMAPXCommand {
+	struct _CamelIMAPXCommand *next, *prev;
+
+	volatile gint ref_count;
+
+	CamelIMAPXServer *is;
+	gint pri;
+
+	const gchar *name;	/* command name/type (e.g. FETCH) */
+
+	CamelFolder *select;		/* folder to select */
+
+	struct _status_info *status; /* status for command, indicates it is complete if != NULL */
+
+	/* If exception is set, it means we were not able to parse above status, it might be
+	 * because user cancelled the operation or io error */
+	GCancellable *cancellable;
+	GError *error;
+
+	guint32 tag;
+
+	struct _CamelStreamMem *mem;	/* for building the part TOOD: just use a GString? */
+	CamelDList parts;
+	struct _CamelIMAPXCommandPart *current;
+
+	/* used for running some commands syncronously */
+	gboolean run_sync_done;
+	GCond *run_sync_cond;
+	GMutex *run_sync_mutex;
+
+	/* responsible for free'ing the command */
+	CamelIMAPXCommandFunc complete;
+	struct _CamelIMAPXJob *job;
+};
+
+/* states for the connection? */
+enum {
+	IMAPX_DISCONNECTED,
+	IMAPX_SHUTDOWN,
+	IMAPX_CONNECTED,
+	IMAPX_AUTHENTICATED,
+	IMAPX_INITIALISED,
+	IMAPX_SELECTED
+};
+enum {
+	IMAPX_JOB_GET_MESSAGE = 1 << 0,
+	IMAPX_JOB_APPEND_MESSAGE = 1 << 1,
+	IMAPX_JOB_COPY_MESSAGE = 1 << 2,
+	IMAPX_JOB_FETCH_NEW_MESSAGES = 1 << 3,
+	IMAPX_JOB_REFRESH_INFO = 1 << 4,
+	IMAPX_JOB_SYNC_CHANGES = 1 << 5,
+	IMAPX_JOB_EXPUNGE = 1 << 6,
+	IMAPX_JOB_NOOP = 1 << 7,
+	IMAPX_JOB_IDLE = 1 << 8,
+	IMAPX_JOB_LIST = 1 << 9,
+	IMAPX_JOB_MANAGE_SUBSCRIPTION = 1 << 10,
+	IMAPX_JOB_CREATE_FOLDER = 1 << 11,
+	IMAPX_JOB_DELETE_FOLDER = 1 << 12,
+	IMAPX_JOB_RENAME_FOLDER = 1 << 13,
+};
+
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* _CAMEL_IMAPX_SERVER_DEFS_H_ */
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/camel/providers/imapx/camel-imapx-server-friend.h b/src/camel/providers/imapx/camel-imapx-server-friend.h
new file mode 100644
index 0000000..7ccfeae
--- /dev/null
+++ b/src/camel/providers/imapx/camel-imapx-server-friend.h
@@ -0,0 +1,127 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-server-friend.h
+ *
+ *  2012-01-20, 18:57:18
+ *  Copyright 2012, 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 file holds function prototypes needed by CamelIMAPXExtdServer,
+ * but not exported by its parent class. In order not to mess with
+ * upstream code, we (temporarily) declare the symbols here.
+ * Once the *Extd* classes get merged into their upstream counterparts,
+ * these can be removed
+ */
+
+/*----------------------------------------------------------------------------*/
+
+#ifndef _CAMEL_IMAPX_SERVER_FRIEND_H_
+#define _CAMEL_IMAPX_SERVER_FRIEND_H_
+
+/*----------------------------------------------------------------------------*/
+
+struct _CamelIMAPXJob*
+camel_imapx_server_match_active_job (CamelIMAPXServer *self,
+                                     guint32 type,
+                                     const gchar *uid);
+
+gchar*
+camel_imapx_server_get_uid_from_index (CamelIMAPXServer *self,
+                                       CamelFolderSummary *summary,
+                                       guint id);
+
+void
+camel_imapx_server_expunge_uid_from_summary (CamelIMAPXServer *self,
+                                             gchar *uid,
+                                             gboolean unsolicited);
+
+gboolean
+camel_imapx_server_idle_supported (CamelIMAPXServer *self);
+
+void
+camel_imapx_server_init_idle (CamelIMAPXServer *self);
+
+gboolean
+camel_imapx_server_in_idle (CamelIMAPXServer *self);
+
+gboolean
+camel_imapx_server_stop_idle (CamelIMAPXServer *self,
+                              GError **err);
+
+gint
+camel_imapx_server_refresh_info_uid_cmp (CamelIMAPXServer *self,
+                                         gconstpointer ap,
+                                         gconstpointer bp,
+                                         gboolean ascending);
+
+void
+camel_imapx_server_invalidate_local_cache (CamelIMAPXServer *self,
+                                           CamelIMAPXFolder *ifolder,
+                                           guint64 new_uidvalidity);
+
+gint
+camel_imapx_server_completion (CamelIMAPXServer *self,
+                               guchar *token,
+                               gint len,
+                               GCancellable *cancellable,
+                               GError **err);
+
+gint
+camel_imapx_server_continuation (CamelIMAPXServer *self,
+                                 gboolean litplus,
+                                 GCancellable *cancellable,
+                                 GError **err);
+
+void
+camel_imapx_server_command_close (CamelIMAPXServer *self,
+                                  CamelIMAPXCommand *ic);
+
+gboolean
+camel_imapx_server_command_start (CamelIMAPXServer *self,
+                                  CamelIMAPXCommand *ic);
+
+gboolean
+camel_imapx_server_connect_to_server_process (CamelIMAPXServer *self,
+                                              const gchar *cmd,
+                                              GError **err);
+
+struct _CamelIMAPXCommand*
+camel_imapx_server_command_new (CamelIMAPXServer *self,
+                                const gchar *name,
+                                CamelFolder *select,
+                                GCancellable *cancellable,
+                                const gchar *fmt, ...);
+
+void
+camel_imapx_server_command_unref (CamelIMAPXServer *self,
+                                  struct _CamelIMAPXCommand *ic);
+
+gboolean
+camel_imapx_server_disconnect (CamelIMAPXServer *self);
+
+void
+camel_imapx_server_cancel_all_jobs (CamelIMAPXServer *self,
+                                    GError *err_to_copy);
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* _CAMEL_IMAPX_SERVER_FRIEND_H_ */
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index 0781b64..fa9c866 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -1380,6 +1380,9 @@ imapx_untagged (CamelIMAPXServer *imap,
 	gboolean lsub = FALSE;
 	struct _status_info *sinfo;
 
+	/* FIXME remove this */
+	g_assert_not_reached ();
+
 	service = CAMEL_SERVICE (imap->store);
 	settings = camel_service_get_settings (service);
 
@@ -6216,3 +6219,217 @@ camel_imapx_server_get_job_queue_info (CamelIMAPXServer *is)
 
 	return jinfo;
 }
+
+/*----------------------------------------------------------------------------*/
+/* "friend" API for subclasses */
+
+#include "camel-imapx-server-friend.h"
+
+struct _CamelIMAPXJob*
+camel_imapx_server_match_active_job (CamelIMAPXServer *self,
+                                     guint32 type,
+                                     const gchar *uid)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (uid != NULL);
+
+	return imapx_match_active_job (self,
+	                               type,
+	                               uid);
+}
+
+gchar*
+camel_imapx_server_get_uid_from_index (CamelIMAPXServer *self,
+                                       CamelFolderSummary *summary,
+                                       guint id)
+{
+	/* util */
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (CAMEL_IS_FOLDER_SUMMARY (summary));
+
+	return imapx_get_uid_from_index (summary, id);
+}
+
+void
+camel_imapx_server_expunge_uid_from_summary (CamelIMAPXServer *self,
+                                             gchar *uid,
+                                             gboolean unsolicited)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (uid != NULL);
+
+	imapx_expunge_uid_from_summary (self,
+	                                uid,
+	                                unsolicited);
+}
+
+gboolean
+camel_imapx_server_idle_supported (CamelIMAPXServer *self)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	return imapx_idle_supported (self);
+}
+
+void
+camel_imapx_server_init_idle (CamelIMAPXServer *self)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	imapx_init_idle (self);
+}
+
+gboolean
+camel_imapx_server_in_idle (CamelIMAPXServer *self)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	return imapx_in_idle (self);
+}
+
+gboolean
+camel_imapx_server_stop_idle (CamelIMAPXServer *self,
+                              GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	return imapx_stop_idle (self, err);
+}
+
+gint
+camel_imapx_server_refresh_info_uid_cmp (CamelIMAPXServer *self,
+                                         gconstpointer ap,
+                                         gconstpointer bp,
+                                         gboolean ascending)
+{
+	/* util */
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	return imapx_refresh_info_uid_cmp (ap, bp, ascending);
+}
+
+void
+camel_imapx_server_invalidate_local_cache (CamelIMAPXServer *self,
+                                           CamelIMAPXFolder *ifolder,
+                                           guint64 new_uidvalidity)
+{
+	/* util */
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	invalidate_local_cache (ifolder, new_uidvalidity);
+}
+
+gint
+camel_imapx_server_completion (CamelIMAPXServer *self,
+                               guchar *token,
+                               gint len,
+                               GCancellable *cancellable,
+                               GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (token != NULL);
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, -1);
+
+	return imapx_completion (self, token, len, cancellable, err);
+}
+
+gint
+camel_imapx_server_continuation (CamelIMAPXServer *self,
+                                 gboolean litplus,
+                                 GCancellable *cancellable,
+                                 GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, -1);
+
+	return imapx_continuation (self, litplus, cancellable, err);
+}
+
+void
+camel_imapx_server_command_close (CamelIMAPXServer *self,
+                                  CamelIMAPXCommand *ic)
+{
+	/* util */
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (ic != NULL);
+
+	imapx_command_close (ic);
+}
+
+/* Must hold QUEUE_LOCK */
+gboolean
+camel_imapx_server_command_start (CamelIMAPXServer *self,
+                                  CamelIMAPXCommand *ic)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (ic != NULL);
+
+	return imapx_command_start (self, ic);
+}
+
+gboolean
+camel_imapx_server_connect_to_server_process (CamelIMAPXServer *self,
+                                              const gchar *cmd,
+                                              GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (cmd != NULL);
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	return connect_to_server_process (self, cmd, err);
+}
+
+struct _CamelIMAPXCommand*
+camel_imapx_server_command_new (CamelIMAPXServer *self,
+                                const gchar *name,
+                                CamelFolder *select,
+                                GCancellable *cancellable,
+                                const gchar *fmt, ...)
+{
+	struct _CamelIMAPXCommand *cmd = NULL;
+	va_list ap;
+
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+	g_assert (name != NULL);
+	g_assert (CAMEL_IS_FOLDER (select));
+	/* camcellable may be NULL */
+	g_assert (fmt != NULL);
+
+	va_start (ap, fmt);
+	cmd = imapx_command_new (self, name, select, cancellable, fmt, ap);
+	va_end (ap);
+
+	return cmd;
+}
+
+void
+camel_imapx_server_command_unref (CamelIMAPXServer *self,
+                                  struct _CamelIMAPXCommand *ic)
+{
+	/* util */
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	imapx_command_unref (ic);
+}
+
+gboolean
+camel_imapx_server_disconnect (CamelIMAPXServer *self)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	return imapx_disconnect (self);
+}
+
+void
+camel_imapx_server_cancel_all_jobs (CamelIMAPXServer *self,
+                                    GError *err_to_copy)
+{
+
+	g_assert (CAMEL_IS_IMAPX_SERVER (self));
+
+	/* err is copied, hence not **err */
+	cancel_all_jobs (self, err_to_copy);
+}



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