[evolution-kolab] CamelImapxAcl: ACL command list implementation



commit 5eb1be31b9c0c66bc89e183c4edd0a53527820d7
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Oct 16 15:28:31 2012 +0200

    CamelImapxAcl: ACL command list implementation
    
    * added implementation for generating
      ACL command lists from a GList of
      CamelImapxAclEntry instances
    * a NULL CamelImapxAclEntry::rights member
      leads to a DELETEACL command, non-NULL
      to a SETACL command
    * API change: we expected a CamelImapxAcl
      instance previously, but changed that
      for a GList of CamelImapxAclEntry instances
      (easier implementation, and we get the
      list representation from the UI - collecting
      the server's untagged responses is still
      done in a CamelImapxAcl instance)

 src/libekolab/camel-imapx-acl.c |  141 +++++++++++++++++++++++++++++++++++----
 src/libekolab/camel-imapx-acl.h |   24 ++++++-
 2 files changed, 150 insertions(+), 15 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index 40fe98a..db1c501 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -174,6 +174,48 @@ imapx_acl_entry_gdestroy (gpointer data)
 	imapx_acl_entry_free (entry);
 }
 
+static CamelImapxAclCmd*
+imapx_acl_cmd_new (const gchar *token,
+                   const gchar *command)
+{
+	CamelImapxAclCmd *cmd = NULL;
+
+	g_return_val_if_fail (token != NULL, NULL);
+	g_return_val_if_fail (command != NULL, NULL);
+
+	cmd = g_new0 (CamelImapxAclCmd, 1);
+	cmd->token = g_strdup (token);
+	cmd->command = g_strdup (command);
+
+	return cmd;
+}
+
+static void
+imapx_acl_cmd_free (CamelImapxAclCmd *cmd)
+{
+	if (cmd == NULL)
+		return;
+
+	if (cmd->token != NULL)
+		g_free (cmd->token);
+	if (cmd->command != NULL)
+		g_free (cmd->command);
+
+	g_free (cmd);
+}
+
+static void
+imapx_acl_cmd_gdestroy (gpointer data)
+{
+	CamelImapxAclCmd *cmd = NULL;
+
+	if (data == NULL)
+		return;
+
+	cmd = (CamelImapxAclCmd *) data;
+	imapx_acl_cmd_free (cmd);
+}
+
 static GHashTable*
 imapx_acl_myrights_table_new (void)
 {
@@ -316,6 +358,16 @@ imapx_acl_rights_get_unknown (const gchar *rights)
 	return residue;
 }
 
+static void
+imapx_acl_commandlist_free (GList *commands)
+{
+	if (commands == NULL)
+		return;
+
+	g_list_free_full (commands,
+	                  imapx_acl_cmd_gdestroy);
+}
+
 /*----------------------------------------------------------------------------*/
 
 CamelImapxAclSpec*
@@ -407,6 +459,19 @@ camel_imapx_acl_entry_free (CamelImapxAclEntry *entry)
 	imapx_acl_entry_free (entry);
 }
 
+CamelImapxAclCmd*
+camel_imapx_acl_cmd_new (const gchar *token,
+                         const gchar *command)
+{
+	return imapx_acl_cmd_new (token, command);
+}
+
+void
+camel_imapx_acl_cmd_free (CamelImapxAclCmd *cmd)
+{
+	imapx_acl_cmd_free (cmd);
+}
+
 CamelImapxAcl*
 camel_imapx_acl_new (gboolean locked)
 {
@@ -699,7 +764,7 @@ camel_imapx_acl_update_from_list (CamelImapxAcl *acl,
 	if (entries == NULL)
 		goto skip;
 
-	new_entries_tbl = imapx_acl_mboxes_table_new ();
+	new_entries_tbl = imapx_acl_entries_table_new ();
 	entries_ptr = entries;
 	while (entries_ptr != NULL) {
 		entry = (const CamelImapxAclEntry *) entries_ptr->data;
@@ -1203,30 +1268,78 @@ camel_imapx_acl_rights_merge (const gchar *oldrights,
 }
 
 GList*
-camel_imapx_acl_commandlist_new (CamelImapxAcl *acl,
+camel_imapx_acl_commandlist_new (const GList *entries,
+                                 const gchar *foldername,
                                  GError **err)
 {
-	g_return_val_if_fail (acl != NULL, NULL);
-	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+	const CamelImapxAclEntry *entry = NULL;
+	CamelImapxAclCmd *cmd = NULL;
+	GList *commands = NULL;
+	const GList *entries_ptr = NULL;
+	const gchar *token = NULL;
+	gchar *command = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
 
-	/* (acquire acl lock) */
-	g_mutex_lock (&(acl->lock));
+	g_return_val_if_fail (entries != NULL, NULL);
+	g_return_val_if_fail (foldername != NULL, NULL);
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
-	g_warning ("%s()[%u] FIXME implement me", __func__, __LINE__);
+	entries_ptr = entries;
+	while (entries_ptr != NULL) {
+		entry = (const CamelImapxAclEntry *) (entries_ptr->data);
+		if (entry == NULL)
+			goto skip;
+		ok = imapx_acl_entry_validate (entry,
+		                               &tmp_err);
+		if (! ok)
+			goto exit;
 
-	/* (release acl lock) */
-	g_mutex_unlock (&(acl->lock));
+		if (entry->rights == NULL) {
+			/* delete from IMAP ACL */
+			token = IMAPX_IMAP_TOKEN_DELETEACL;
+			command = g_strdup_printf ("%s %s %s",
+			                           token,
+			                           foldername,
+			                           entry->access_id);
+		} else {
+			/* add to IMAP ACL */
+			token = IMAPX_IMAP_TOKEN_SETACL;
+			command = g_strdup_printf ("%s %s %s %s",
+			                           token,
+			                           foldername,
+			                           entry->access_id,
+			                           entry->rights);
+		}
+
+		cmd = imapx_acl_cmd_new (token,
+		                         command);
+		g_free (command);
+		commands = g_list_prepend (commands, cmd);
+
+	skip:
+		entries_ptr = g_list_next (entries_ptr);
+	}
+
+	commands = g_list_reverse (commands);
+
+ exit:
 
-	return NULL;
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		if (commands != NULL) {
+			imapx_acl_commandlist_free (commands);
+			commands = NULL;
+		}
+	}
+
+	return commands;
 }
 
 void
 camel_imapx_acl_commandlist_free (GList *commands)
 {
-	if (commands == NULL)
-		return;
-
-	kolab_util_glib_glist_free (commands);
+	imapx_acl_commandlist_free (commands);
 }
 
 /*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-acl.h b/src/libekolab/camel-imapx-acl.h
index 0e8eca4..90b7380 100644
--- a/src/libekolab/camel-imapx-acl.h
+++ b/src/libekolab/camel-imapx-acl.h
@@ -39,6 +39,14 @@
 
 /*----------------------------------------------------------------------------*/
 
+#define IMAPX_IMAP_TOKEN_ACL       "ACL"
+#define IMAPX_IMAP_TOKEN_MYRIGHTS  "MYRIGHTS"
+#define IMAPX_IMAP_TOKEN_SETACL    "SETACL"
+#define IMAPX_IMAP_TOKEN_GETACL    "GETACL"
+#define IMAPX_IMAP_TOKEN_DELETEACL "DELETEACL"
+
+/*----------------------------------------------------------------------------*/
+
 typedef enum {
 	CAMEL_IMAPX_ACL_TYPE_NONE     = 0,
 	CAMEL_IMAPX_ACL_TYPE_MYRIGHTS = 1 << 0,
@@ -59,6 +67,12 @@ struct _CamelImapxAclEntry {
 	gchar *rights;
 };
 
+typedef struct _CamelImapxAclCmd CamelImapxAclCmd;
+struct _CamelImapxAclCmd {
+	gchar *token;
+	gchar *command;
+};
+
 typedef struct _CamelImapxAcl CamelImapxAcl;
 struct _CamelImapxAcl {
 	GHashTable *myrights; /* MYRIGHTS per folder */
@@ -87,6 +101,13 @@ camel_imapx_acl_entry_clone (const CamelImapxAclEntry *entry,
 void
 camel_imapx_acl_entry_free (CamelImapxAclEntry *entry);
 
+CamelImapxAclCmd*
+camel_imapx_acl_cmd_new (const gchar *token,
+                         const gchar *command);
+
+void
+camel_imapx_acl_cmd_free (CamelImapxAclCmd *cmd);
+
 CamelImapxAcl*
 camel_imapx_acl_new (gboolean locked);
 
@@ -164,7 +185,8 @@ camel_imapx_acl_rights_merge (const gchar *oldrights,
                               GError **err);
 
 GList*
-camel_imapx_acl_commandlist_new (CamelImapxAcl *acl,
+camel_imapx_acl_commandlist_new (const GList *entries,
+                                 const gchar *foldername,
                                  GError **err);
 
 void



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