[evolution-kolab/ek-wip-acl: 20/21] CamelImapxAcl: implemented ACL list updater



commit 3c14bc9443f437377655919b05e7de971ebc8c14
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Thu Oct 11 15:07:19 2012 +0200

    CamelImapxAcl: implemented ACL list updater
    
    * implemented function which updates the CamelImapxAcl
      hash table that holds the ACL strings for the mailboxes
      from a GList of CamelImapxAclEntry instances

 src/libekolab/camel-imapx-acl.c |   99 +++++++++++++++++++++++++++++++++++----
 1 files changed, 89 insertions(+), 10 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index 20a2281..d2fbd93 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -69,6 +69,25 @@ imapx_acl_entry_validate_rights (const gchar *rights,
 	return TRUE;
 }
 
+static gboolean
+imapx_acl_entry_validate (const CamelImapxAclEntry *entry,
+                          GError **err)
+{
+	gboolean ok = FALSE;
+
+	g_return_val_if_fail (entry != NULL, FALSE);
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	ok = imapx_acl_entry_validate_access_id (entry->access_id,
+	                                         err);
+	if (! ok)
+		return FALSE;
+
+	ok = imapx_acl_entry_validate_rights (entry->rights,
+	                                      err);
+	return ok;
+}
+
 static void
 imapx_acl_entry_gdestroy (gpointer data)
 {
@@ -82,6 +101,18 @@ imapx_acl_entry_gdestroy (gpointer data)
 }
 
 static GHashTable*
+imapx_acl_myrights_table_new (void)
+{
+	GHashTable *tbl = NULL;
+
+	tbl = g_hash_table_new_full (g_str_hash,
+	                             g_str_equal,
+	                             g_free,
+	                             g_free);
+	return tbl;
+}
+
+static GHashTable*
 imapx_acl_entries_table_new (void)
 {
 	GHashTable *tbl = NULL;
@@ -93,6 +124,18 @@ imapx_acl_entries_table_new (void)
 	return tbl;
 }
 
+static GHashTable*
+imapx_acl_mboxes_table_new (void)
+{
+	GHashTable *tbl = NULL;
+
+	tbl = g_hash_table_new_full (g_str_hash,
+	                             g_str_equal,
+	                             g_free,
+	                             (GDestroyNotify) g_hash_table_destroy);
+	return tbl;
+}
+
 /*----------------------------------------------------------------------------*/
 
 CamelImapxAclSpec*
@@ -203,16 +246,11 @@ camel_imapx_acl_new (gboolean locked)
 		g_mutex_lock (&(acl->lock));
 
 	/* foldername:myrights */
-	acl->myrights = g_hash_table_new_full (g_str_hash,
-	                                       g_str_equal,
-	                                       g_free,
-	                                       g_free);
+	acl->myrights = imapx_acl_myrights_table_new ();
 
 	/* foldername:access_id:rights */
-	acl->mboxes = g_hash_table_new_full (g_str_hash,
-	                                     g_str_equal,
-	                                     g_free,
-	                                     (GDestroyNotify) g_hash_table_destroy);
+	acl->mboxes = imapx_acl_mboxes_table_new ();
+
 	return acl;
 }
 
@@ -527,18 +565,59 @@ camel_imapx_acl_update_from_list (CamelImapxAcl *acl,
                                   const GList *entries,
                                   GError **err)
 {
+	const CamelImapxAclEntry *entry = NULL;
+	const GList *entries_ptr = NULL;
+	GHashTable *new_entries_tbl = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
+
 	g_return_val_if_fail (acl != NULL, FALSE);
+	g_return_val_if_fail (acl->mboxes != NULL, FALSE);
 	g_return_val_if_fail (mbox_name != NULL, FALSE);
 	/* entries may be NULL (used for deletion) */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	/* We replace the whole ACL for the
+	 * named mailbox with the list contents
+	 * instead of doing some merge operation
+	 */
+
 	if (entries == NULL)
-		return TRUE;
+		goto skip;
+
+	new_entries_tbl = imapx_acl_mboxes_table_new ();
+	entries_ptr = entries;
+	while (entries_ptr != NULL) {
+		entry = (const CamelImapxAclEntry *) entries_ptr->data;
+
+		ok = imapx_acl_entry_validate (entry,
+		                               &tmp_err);
+		if (! ok) {
+			g_propagate_error (err, tmp_err);
+			g_hash_table_destroy (new_entries_tbl);
+			return FALSE;
+		}
+
+		g_hash_table_insert (new_entries_tbl,
+		                     g_strdup (entry->access_id),
+		                     g_strdup (entry->rights));
+
+		entries_ptr = g_list_next (entries_ptr);
+	}
+
+ skip:
 
 	/* (acquire acl lock) */
 	g_mutex_lock (&(acl->lock));
 
-	g_warning ("%s()[%u] FIXME implement me", __func__, __LINE__);
+	if (new_entries_tbl != NULL) {
+		g_hash_table_replace (acl->mboxes,
+		                      g_strdup (mbox_name),
+		                      new_entries_tbl);
+	} else {
+		g_hash_table_remove (acl->mboxes,
+		                     mbox_name);
+	}
 
 	/* (release acl lock) */
 	g_mutex_unlock (&(acl->lock));



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