[evolution-kolab/ek-wip-acl: 2/2] libekolab: stubbed in basic infrastructure for IMAP ACL support



commit 72a8810d16971cbcd7718588401a4aaa2872320c
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Jul 31 11:44:41 2012 +0200

    libekolab: stubbed in basic infrastructure for IMAP ACL support
    
    * register ACL capability in CamelIMAPXExtdStore
    * added CamelImapxAcl datastructure (analogous
      to CamelImapxMetadata) and util functions
      (new(), free(), resect())
    * added stub implementations of CamelIMAPXExtdServer
      extensions (API not yet stabilized)
    * added CamelImapxAcl* private member to
      CamelIMAPXExtdStore

 src/libekolab/Makefile.am                     |    4 +
 src/libekolab/camel-imapx-acl.c               |  111 +++++++++++++++++
 src/libekolab/camel-imapx-acl.h               |   65 ++++++++++
 src/libekolab/camel-imapx-extd-server-acl.c   |  162 +++++++++++++++++++++++++
 src/libekolab/camel-imapx-extd-server-acl.h   |   77 ++++++++++++
 src/libekolab/camel-imapx-extd-server.h       |    1 +
 src/libekolab/camel-imapx-extd-store-friend.h |    3 +
 src/libekolab/camel-imapx-extd-store.c        |   25 ++++
 8 files changed, 448 insertions(+), 0 deletions(-)
---
diff --git a/src/libekolab/Makefile.am b/src/libekolab/Makefile.am
index 9886b8d..6c01ee8 100644
--- a/src/libekolab/Makefile.am
+++ b/src/libekolab/Makefile.am
@@ -38,9 +38,11 @@ libekolab_la_SOURCES =				\
 	camel-kolab-imapx-settings.c		\
 	camel-kolab-imapx-store.c		\
 	camel-kolab-session.c			\
+	camel-imapx-extd-server-acl.c		\
 	camel-imapx-extd-server-metadata.c	\
 	camel-imapx-extd-server.c		\
 	camel-imapx-extd-store.c		\
+	camel-imapx-acl.c			\
 	camel-imapx-metadata.c			\
 	kolab-data-folder-metadata.c		\
 	kolab-data-folder-permissions.c		\
@@ -55,10 +57,12 @@ noinst_HEADERS =				\
 	camel-kolab-imapx-settings.h		\
 	camel-kolab-imapx-store.h		\
 	camel-kolab-session.h			\
+	camel-imapx-extd-server-acl.h		\
 	camel-imapx-extd-server-metadata.h	\
 	camel-imapx-extd-server.h		\
 	camel-imapx-extd-store.h		\
 	camel-imapx-extd-store-friend.h		\
+	camel-imapx-acl.h			\
 	camel-imapx-metadata.h			\
 	kolab-backend-types.h			\
 	kolab-data-folder-metadata.h		\
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
new file mode 100644
index 0000000..998e8b6
--- /dev/null
+++ b/src/libekolab/camel-imapx-acl.c
@@ -0,0 +1,111 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-acl.c
+ *
+ *  2012-07-30, 19:09:28
+ *  Copyright 2012, Christian Hilberg
+ *  <hilberg kernelconcepts de>
+ ****************************************************************************/
+
+/*
+ * 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
+ */
+
+/*----------------------------------------------------------------------------*/
+/* ACL (RFC 4314) */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <glib/gi18n-lib.h>
+
+#include "camel-imapx-acl.h"
+
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+
+CamelImapxAcl*
+camel_imapx_acl_new (gboolean locked)
+{
+	CamelImapxAcl *acl = g_new0 (CamelImapxAcl, 1);
+	g_mutex_init (&(acl->acl_lock));
+
+	if (locked)
+		g_mutex_lock (&(acl->acl_lock));
+
+	acl->myrights = g_hash_table_new_full (g_str_hash,
+	                                       g_str_equal,
+	                                       g_free,
+	                                       g_free);
+	acl->mboxes = g_hash_table_new_full (g_str_hash,
+	                                     g_str_equal,
+	                                     g_free,
+	                                     g_free);
+	return acl;
+}
+
+void
+camel_imapx_acl_free (CamelImapxAcl *acl)
+{
+	if (acl == NULL)
+		return;
+
+	if (acl->myrights)
+		g_hash_table_destroy (acl->myrights);
+	if (acl->mboxes)
+		g_hash_table_destroy (acl->mboxes);
+
+	while (! g_mutex_trylock (&(acl->acl_lock)));
+	g_mutex_unlock (&(acl->acl_lock));
+	g_mutex_clear (&(acl->acl_lock));
+
+	g_free (acl);
+}
+
+CamelImapxAcl*
+camel_imapx_acl_resect (CamelImapxAcl *acl)
+{
+	CamelImapxAcl *tmp_acl = NULL;
+	GHashTable *myrights = NULL;
+	GHashTable *mboxes = NULL;
+
+	if (acl == NULL)
+		return NULL;
+
+	/* (acquire acl lock) */
+	g_mutex_lock (&(acl->acl_lock));
+
+	tmp_acl = camel_imapx_acl_new (FALSE);
+
+	myrights = acl->myrights;
+	mboxes = acl->mboxes;
+
+	acl->myrights = tmp_acl->myrights;
+	acl->mboxes = tmp_acl->mboxes;
+
+	tmp_acl->myrights = myrights;
+	tmp_acl->mboxes = mboxes;
+
+	/* (release acl lock) */
+	g_mutex_unlock (&(acl->acl_lock));
+
+	return tmp_acl;
+}
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-acl.h b/src/libekolab/camel-imapx-acl.h
new file mode 100644
index 0000000..c33e548
--- /dev/null
+++ b/src/libekolab/camel-imapx-acl.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-acl.h
+ *
+ *  2012-07-30, 19:09:28
+ *  Copyright 2012, Christian Hilberg
+ *  <hilberg kernelconcepts de>
+ ****************************************************************************/
+
+/*
+ * 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
+ */
+
+/*----------------------------------------------------------------------------*/
+/* ACL (RFC 4314) */
+
+#ifndef _CAMEL_IMAPX_ACL_H_
+#define _CAMEL_IMAPX_ACL_H_
+
+/*----------------------------------------------------------------------------*/
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <libekolabutil/camel-system-headers.h>
+
+/*----------------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------------*/
+
+typedef struct _CamelImapxAcl {
+	GHashTable *myrights; /* MYRIGHTS per folder */
+	GHashTable *mboxes;   /* ACL per folder      */
+	GMutex acl_lock;
+} CamelImapxAcl;
+
+/*----------------------------------------------------------------------------*/
+
+CamelImapxAcl*
+camel_imapx_acl_new (gboolean locked);
+
+void
+camel_imapx_acl_free (CamelImapxAcl *acl);
+
+CamelImapxAcl*
+camel_imapx_acl_resect (CamelImapxAcl *acl);
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* _CAMEL_IMAPX_ACL_H_ */
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-extd-server-acl.c b/src/libekolab/camel-imapx-extd-server-acl.c
new file mode 100644
index 0000000..46c3d17
--- /dev/null
+++ b/src/libekolab/camel-imapx-extd-server-acl.c
@@ -0,0 +1,162 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-extd-server-acl.c
+ *
+ *  2012-07-30, 17:13:28
+ *  Copyright 2012, Christian Hilberg
+ *  <hilberg kernelconcepts de>
+ ****************************************************************************/
+
+/*
+ * 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
+ */
+
+/*----------------------------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+
+#include "camel-imapx-extd-store.h"
+#include "camel-imapx-extd-store-friend.h"
+#include "camel-imapx-extd-server.h"
+
+#include "camel-imapx-extd-server-acl.h"
+
+/*----------------------------------------------------------------------------*/
+
+static gboolean
+imapx_extd_server_untagged_acl (CamelIMAPXServer *is,
+                                GCancellable *cancellable,
+                                GError **err);
+
+static gboolean
+imapx_extd_server_untagged_myrights (CamelIMAPXServer *is,
+                                     GCancellable *cancellable,
+                                     GError **err);
+
+static const CamelIMAPXUntaggedRespHandlerDesc desc_acl = {
+	IMAPX_IMAP_TOKEN_ACL,                  /* untagged_response     */
+	imapx_extd_server_untagged_acl,        /* handler               */
+	NULL,                                  /* next_response         */
+	TRUE                                   /* skip_stream_when_done */
+};
+
+static const CamelIMAPXUntaggedRespHandlerDesc desc_myrights = {
+	IMAPX_IMAP_TOKEN_MYRIGHTS,             /* untagged_response     */
+	imapx_extd_server_untagged_myrights,   /* handler               */
+	NULL,                                  /* next_response         */
+	TRUE                                   /* skip_stream_when_done */
+};
+
+/*----------------------------------------------------------------------------*/
+
+static gboolean
+imapx_extd_server_untagged_acl (CamelIMAPXServer *is,
+                                GCancellable *cancellable,
+                                GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* FIXME implement me */
+	g_assert_not_reached ();
+
+	return TRUE;
+}
+
+static gboolean
+imapx_extd_server_untagged_myrights (CamelIMAPXServer *is,
+                                     GCancellable *cancellable,
+                                     GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* FIXME implement me */
+	g_assert_not_reached ();
+
+	return TRUE;
+}
+
+/*----------------------------------------------------------------------------*/
+
+KolabGConstList*
+camel_imapx_extd_server_acl_get_handler_descriptors (void)
+{
+	KolabGConstList *list = NULL;
+	list = kolab_util_glib_gconstlist_prepend (list,
+	                                           (gconstpointer)(&desc_myrights));
+	list = kolab_util_glib_gconstlist_prepend (list,
+	                                           (gconstpointer)(&desc_acl));
+	return list;
+}
+
+gboolean
+camel_imapx_extd_server_get_myrights (CamelIMAPXServer *is,
+                                      /* something */
+                                      GCancellable *cancellable,
+                                      GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	/* assert something */
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* FIXME implement me */
+	g_assert_not_reached ();
+
+	return TRUE;
+}
+
+gboolean
+camel_imapx_extd_server_get_acl (CamelIMAPXServer *is,
+                                 /* something */
+                                 GCancellable *cancellable,
+                                 GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	/* assert something */
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* FIXME implement me */
+	g_assert_not_reached ();
+
+	return TRUE;
+}
+
+gboolean
+camel_imapx_extd_server_set_acl (CamelIMAPXServer *is,
+                                 /* something */
+                                 GCancellable *cancellable,
+                                 GError **err)
+{
+	g_assert (CAMEL_IS_IMAPX_SERVER (is));
+	/* assert something */
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* FIXME implement me */
+	g_assert_not_reached ();
+
+	return TRUE;
+}
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-extd-server-acl.h b/src/libekolab/camel-imapx-extd-server-acl.h
new file mode 100644
index 0000000..cee0d32
--- /dev/null
+++ b/src/libekolab/camel-imapx-extd-server-acl.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/***************************************************************************
+ *            camel-imapx-extd-server-acl.h
+ *
+ *  2012-07-30, 17:13:28
+ *  Copyright 2012, Christian Hilberg
+ *  <hilberg kernelconcepts de>
+ ****************************************************************************/
+
+/*
+ * 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
+ */
+
+/*----------------------------------------------------------------------------*/
+
+#ifndef _CAMEL_IMAPX_EXTD_SERVER_ACL_H_
+#define _CAMEL_IMAPX_EXTD_SERVER_ACL_H_
+
+/*----------------------------------------------------------------------------*/
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include <libekolabutil/kolab-util-glib.h>
+
+#include "camel-imapx-acl.h"
+
+/*----------------------------------------------------------------------------*/
+
+#define IMAPX_IMAP_TOKEN_ACL      "ACL"
+#define IMAPX_IMAP_TOKEN_MYRIGHTS "MYRIGHTS"
+#define IMAPX_IMAP_TOKEN_SETACL   "SETACL"
+#define IMAPX_IMAP_TOKEN_GETACL   "GETACL"
+
+/*----------------------------------------------------------------------------*/
+
+KolabGConstList*
+camel_imapx_extd_server_acl_get_handler_descriptors (void);
+
+gboolean
+camel_imapx_extd_server_get_myrights (CamelIMAPXServer *self,
+                                      /* something */
+                                      GCancellable *cancellable,
+                                      GError **err);
+
+gboolean
+camel_imapx_extd_server_get_acl (CamelIMAPXServer *self,
+                                 /* something */
+                                 GCancellable *cancellable,
+                                 GError **err);
+
+gboolean
+camel_imapx_extd_server_set_acl (CamelIMAPXServer *self,
+                                 /* something */
+                                 GCancellable *cancellable,
+                                 GError **err);
+
+G_END_DECLS
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* CAMEL_IMAPX_EXTD_SERVER_ACL_H_ */
+
+/*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-extd-server.h b/src/libekolab/camel-imapx-extd-server.h
index 453f775..f8e26db 100644
--- a/src/libekolab/camel-imapx-extd-server.h
+++ b/src/libekolab/camel-imapx-extd-server.h
@@ -37,6 +37,7 @@
 #include <libekolabutil/camel-system-headers.h>
 
 /* CamelIMAPXExtdServer protocol extensions */
+#include "camel-imapx-extd-server-acl.h"
 #include "camel-imapx-extd-server-metadata.h"
 
 /*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-extd-store-friend.h b/src/libekolab/camel-imapx-extd-store-friend.h
index 39230f9..be48d90 100644
--- a/src/libekolab/camel-imapx-extd-store-friend.h
+++ b/src/libekolab/camel-imapx-extd-store-friend.h
@@ -42,6 +42,9 @@ typedef enum {
 CamelImapxMetadata*
 camel_imapx_extd_store_get_md_table (CamelIMAPXExtdStore *self);
 
+CamelImapxAcl*
+camel_imapx_extd_store_get_acl_table (CamelIMAPXExtdStore *self);
+
 guint32
 camel_imapx_extd_store_get_capa_flag_id (CamelIMAPXExtdStore *self,
                                          camel_imapx_extd_store_capa_flag_t flag);
diff --git a/src/libekolab/camel-imapx-extd-store.c b/src/libekolab/camel-imapx-extd-store.c
index 132e54b..3ab7c8d 100644
--- a/src/libekolab/camel-imapx-extd-store.c
+++ b/src/libekolab/camel-imapx-extd-store.c
@@ -57,6 +57,7 @@ extern CamelServiceAuthType camel_imapx_password_authtype;
 typedef struct _CamelIMAPXExtdStorePrivate CamelIMAPXExtdStorePrivate;
 struct _CamelIMAPXExtdStorePrivate {
 	CamelImapxMetadata *md; /* raw annotation data (different from CamelKolabImapxMetadata) */
+	CamelImapxAcl *acl; /* IMAP ACL data */
 	guint32 imapx_capa_flag_ids[CAMEL_IMAPX_EXTD_STORE_CAPA_LAST_FLAG];
 };
 
@@ -92,6 +93,7 @@ camel_imapx_extd_store_init (CamelIMAPXExtdStore *self)
 	                                     FALSE);
 	for (ii = 0; ii < CAMEL_IMAPX_EXTD_STORE_CAPA_LAST_FLAG; ii++)
 		priv->imapx_capa_flag_ids[ii] = 0;
+	priv->acl = camel_imapx_acl_new (FALSE);
 
 	/* remove existing conn manager.
 	 * should not normally be necessary
@@ -171,6 +173,8 @@ camel_imapx_extd_store_finalize (GObject *object)
 
 	if (priv->md != NULL)
 		camel_imapx_metadata_free (priv->md);
+	if (priv->acl != NULL)
+		camel_imapx_acl_free (priv->acl);
 
 	G_OBJECT_CLASS (camel_imapx_extd_store_parent_class)->finalize (object);
 }
@@ -221,8 +225,15 @@ imapx_extd_store_register_capability_flags (CamelIMAPXExtdStore *self)
 	imapx_extd_store_set_capa_flag_id (self,
 	                                   CAMEL_IMAPX_EXTD_STORE_CAPA_FLAG_ANNOTATEMORE,
 	                                   capa_flag_id);
+
 	/* (register METADATA server capability flag here) */
 
+	/* ACL server capability flag */
+	capa_flag_id = imapx_register_capability (IMAPX_IMAP_TOKEN_ACL);
+	g_return_val_if_fail (capa_flag_id > 0, FALSE);
+	imapx_extd_store_set_capa_flag_id (self,
+	                                   CAMEL_IMAPX_EXTD_STORE_CAPA_FLAG_ACL,
+	                                   capa_flag_id);
 	return TRUE;
 }
 
@@ -799,6 +810,20 @@ camel_imapx_extd_store_get_md_table (CamelIMAPXExtdStore *self)
 	return priv->md;
 }
 
+CamelImapxAcl*
+camel_imapx_extd_store_get_acl_table (CamelIMAPXExtdStore *self)
+{
+	CamelIMAPXExtdStorePrivate *priv = NULL;
+
+	g_assert (CAMEL_IS_IMAPX_EXTD_STORE (self));
+
+	priv = CAMEL_IMAPX_EXTD_STORE_PRIVATE (self);
+
+	/* TODO does this need to be thread-safe? */
+
+	return priv->acl;
+}
+
 guint32
 camel_imapx_extd_store_get_capa_flag_id (CamelIMAPXExtdStore *self,
                                          camel_imapx_extd_store_capa_flag_t flag)



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