[evolution-kolab/ek-wip-acl: 18/21] CamelImapxAcl: new function for getting rights from list



commit bf76e51e9ad6a3ec418268c7becdf2c66bdf1341
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Thu Oct 11 12:17:49 2012 +0200

    CamelImapxAcl: new function for getting rights from list
    
    * added convenience function for searching a
      GList of CamelImapxAclEntry instances and
      retrieve the ACL rights string for a given
      ACL access_id

 src/libekolab/camel-imapx-acl.c |   59 +++++++++++++++++++++++++++++++++++++++
 src/libekolab/camel-imapx-acl.h |    5 +++
 2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index 749473b..9948d71 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -60,6 +60,9 @@ imapx_acl_entry_validate_rights (const gchar *rights,
 	/* rights may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	if (rights == NULL)
+		return TRUE;
+
 	/* FIXME implement me */
 	g_warning ("%s[%u] FIXME implement me", __func__, __LINE__);
 
@@ -353,6 +356,62 @@ camel_imapx_acl_clone_list (GList *entries,
 	return new_lst;
 }
 
+const gchar*
+camel_imapx_acl_get_rights_from_list (const GList *entries,
+                                      const gchar *access_id,
+                                      GError **err)
+{
+	const CamelImapxAclEntry *entry = NULL;
+	const GList *entries_ptr = NULL;
+	const gchar *rights = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
+
+	g_return_val_if_fail (entries != NULL, NULL);
+	g_return_val_if_fail (access_id != NULL, NULL);
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
+
+	ok = imapx_acl_entry_validate_access_id (access_id,
+	                                         &tmp_err);
+	if (! ok)
+		goto exit;
+
+	entries_ptr = entries;
+	while (entries_ptr != NULL) {
+		entry = (const CamelImapxAclEntry *) entries_ptr->data;
+
+		if (entry == NULL) {
+			g_warning ("%s()[%u] NULL CamelImapxAclEntry in list, skipping!",
+			           __func__, __LINE__);
+			goto skip;
+		}
+
+		if (entry->access_id == NULL) {
+			g_warning ("%s()[%u] NULL access_id in CamelImapxAclEntry, skipping!",
+			           __func__, __LINE__);
+			goto skip;
+		}
+
+		if (g_strcmp0 (access_id, entry->access_id) == 0) {
+			ok = imapx_acl_entry_validate_rights (entry->rights,
+			                                      &tmp_err);
+			if (! ok)
+				goto exit;
+
+			rights = entry->rights;
+			break;
+		}
+
+	skip:
+		entries_ptr = g_list_next (entries_ptr);
+	}
+
+ exit:
+	if (tmp_err != NULL)
+		g_propagate_error (err, tmp_err);
+	return rights;
+}
+
 void
 camel_imapx_acl_free_list (GList *entries)
 {
diff --git a/src/libekolab/camel-imapx-acl.h b/src/libekolab/camel-imapx-acl.h
index 11a170a..455d23f 100644
--- a/src/libekolab/camel-imapx-acl.h
+++ b/src/libekolab/camel-imapx-acl.h
@@ -107,6 +107,11 @@ GList*
 camel_imapx_acl_clone_list (GList *entries,
                             GError **err);
 
+const gchar*
+camel_imapx_acl_get_rights_from_list (const GList *entries,
+                                      const gchar *access_id,
+                                      GError **err);
+
 void
 camel_imapx_acl_free_list (GList *entries);
 



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