[evolution-kolab/ek-wip-acl] CamelImapxAcl: added rights strings merger



commit 1ba43d10b6c9a88a1b58887554313d99a59e34d6
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Oct 12 12:24:51 2012 +0200

    CamelImapxAcl: added rights strings merger
    
    * new function for merging two ACL rights
      strings
    * unknown rights (characters) in the original
      string are preserved
    * known rights are set as per the new
      rights string

 src/libekolab/camel-imapx-acl.c |   81 +++++++++++++++++++++++++++++++++++++++
 src/libekolab/camel-imapx-acl.h |    5 ++
 2 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index 0d159c3..0c020a0 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -40,6 +40,10 @@
 
 /*----------------------------------------------------------------------------*/
 
+#define CAMEL_IMAPX_ACL_KNOWN_RIGHTS "lrswipkxteacd"
+
+/*----------------------------------------------------------------------------*/
+
 static gboolean
 imapx_acl_entry_validate_access_id (const gchar *access_id,
                                     GError **err)
@@ -224,6 +228,24 @@ imapx_acl_validate (CamelImapxAcl *acl,
 	return ok;
 }
 
+static gchar*
+imapx_acl_rights_get_unknown (const gchar *rights)
+{
+	gchar *residue = NULL;
+	gchar **set = NULL;
+
+	if (rights == NULL)
+		return NULL;
+
+	set = g_strsplit_set (rights,
+	                      CAMEL_IMAPX_ACL_KNOWN_RIGHTS,
+	                      -1);
+	residue = g_strjoinv (NULL, set);
+	g_strfreev (set);
+
+	return residue;
+}
+
 /*----------------------------------------------------------------------------*/
 
 CamelImapxAclSpec*
@@ -985,4 +1007,63 @@ camel_imapx_acl_new_commandlist (CamelImapxAcl *acl,
 	return NULL;
 }
 
+gchar*
+camel_imapx_acl_merge_rights (const gchar *oldrights,
+                              const gchar *newrights,
+                              GError **err)
+{
+	gchar *mergedrights = NULL;
+	gchar *residue = NULL;
+	gboolean ok = FALSE;
+
+	/* oldrights may be NULL */
+	/* newrights may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
+
+	/* validate both rights strings */
+	ok = imapx_acl_entry_validate_rights (oldrights,
+	                                      err);
+	if (! ok)
+		return NULL;
+	ok = imapx_acl_entry_validate_rights (newrights,
+	                                      err);
+	if (! ok)
+		return NULL;
+
+	/* from the old rights string, we kill all
+	 * known RFC4314 rights characters, including
+	 * the virtual rights 'd' and 'c', while
+	 * keeping unknown rights characters (as is
+	 * mandated by the RFC)
+	 */
+
+	residue = imapx_acl_rights_get_unknown (oldrights);
+
+	/* we now prepend our new rights string
+	 * to the string of unknown rights chars
+	 * from the oldrights, and let the server
+	 * handle setting the virtual 'd' and
+	 * 'c' rights if it is so inclined (i.e.,
+	 * let the server append them as appropriate
+	 * in the next GETACL response, since the
+	 * server implementation decides how to group
+	 * rights for the virtual 'c' and 'd' rights,
+	 * and we have thereby ignored these virtual
+	 * rights as we are supposed to)
+	 */
+
+	if ((newrights == NULL) && (residue == NULL))
+		return NULL;
+
+	if (newrights == NULL)
+		return residue;
+
+	mergedrights = g_strjoin (NULL, newrights, residue, NULL);
+
+	if (residue != NULL)
+		g_free (residue);
+
+	return mergedrights;
+}
+
 /*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-imapx-acl.h b/src/libekolab/camel-imapx-acl.h
index 455d23f..578adb4 100644
--- a/src/libekolab/camel-imapx-acl.h
+++ b/src/libekolab/camel-imapx-acl.h
@@ -151,6 +151,11 @@ GSList*
 camel_imapx_acl_new_commandlist (CamelImapxAcl *acl,
                                  GError **err);
 
+gchar*
+camel_imapx_acl_merge_rights (const gchar *oldrights,
+                              const gchar *newrights,
+                              GError **err);
+
 /*----------------------------------------------------------------------------*/
 
 #endif /* _CAMEL_IMAPX_ACL_H_ */



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