[evolution-kolab/ek-wip-porting: 11/15] CamelIMAPXExtdServerMetadata: serialized annotation handler, getter, setter



commit 7e450d202c0f7febc2a6d0adc848cecae1e19b36
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Sat Sep 8 18:37:24 2012 +0200

    CamelIMAPXExtdServerMetadata: serialized annotation handler, getter, setter

 src/libekolab/camel-imapx-extd-server-metadata.c |   45 ++++++++++++++-------
 1 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-extd-server-metadata.c b/src/libekolab/camel-imapx-extd-server-metadata.c
index 160254e..fbac613 100644
--- a/src/libekolab/camel-imapx-extd-server-metadata.c
+++ b/src/libekolab/camel-imapx-extd-server-metadata.c
@@ -58,6 +58,7 @@ imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
                                        GCancellable *cancellable,
                                        GError **err)
 {
+	static GMutex handler_lock;
 	CamelIMAPXStore *store;
 	CamelIMAPXExtdStore *estore = NULL;
 	CamelImapxMetadata *md = NULL;
@@ -71,8 +72,9 @@ imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	g_mutex_lock (&handler_lock);
+	
 	store = camel_imapx_server_ref_store (is);
-
 	estore = CAMEL_IMAPX_EXTD_STORE (store);
 
 	/* capability check */
@@ -105,6 +107,8 @@ imapx_extd_server_untagged_annotation (CamelIMAPXServer *is,
 exit:
 	g_object_unref (store);
 
+	g_mutex_unlock (&handler_lock);
+	
 	return success;
 }
 
@@ -125,6 +129,7 @@ camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
                                       GCancellable *cancellable,
                                       GError **err)
 {
+	static GMutex getter_lock;
 	CamelIMAPXCommand *ic = NULL;
 	gchar *cmd = NULL;
 	GError *tmp_err = NULL;
@@ -135,6 +140,8 @@ camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	g_mutex_lock (&getter_lock);
+	
 	/* TODO move GETANNOTATION string to -metadata.[hc]
 	 *      (add a function to return proper string depending
 	 *      on protocol type)
@@ -158,12 +165,12 @@ camel_imapx_extd_server_get_metadata (CamelIMAPXServer *is,
 	g_free (cmd);
 	camel_imapx_command_unref (ic);
 
-	if (! ok) {
+	if (! ok)
 		g_propagate_error (err, tmp_err);
-		return FALSE;
-	}
 
-	return TRUE;
+	g_mutex_unlock (&getter_lock);
+	
+	return ok;
 }
 
 gboolean
@@ -172,21 +179,24 @@ camel_imapx_extd_server_set_metadata (CamelIMAPXServer *is,
                                       GCancellable *cancellable,
                                       GError **err)
 {
+	static GMutex setter_lock;
 	CamelIMAPXCommand *ic = NULL;
 	GSList *commands = NULL;
 	GSList *cur_cmd = NULL;
 	GError *tmp_err = NULL;
-	gboolean ok = FALSE;
+	gboolean ok = TRUE;
 
 	g_assert (CAMEL_IS_IMAPX_SERVER (is));
 	g_assert (md != NULL);
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	g_mutex_lock (&setter_lock);
+
 	commands = camel_imapx_metadata_new_commandlist (md);
 
 	if (commands == NULL)
-		return TRUE;
+		goto exit;
 
 	cur_cmd = commands;
 	while (cur_cmd != NULL) {
@@ -209,18 +219,23 @@ camel_imapx_extd_server_set_metadata (CamelIMAPXServer *is,
 
 		camel_imapx_command_unref (ic);
 
-		if (! ok) {
-			g_slist_free (commands);
-			g_propagate_error (err, tmp_err);
-			return FALSE;
-		}
+		if (! ok)
+			goto exit;
 
 		cur_cmd = g_slist_next (cur_cmd);
 	}
 
-	g_slist_free (commands);
-
-	return TRUE;
+ exit:
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+	if (commands != NULL)
+		g_slist_free (commands);
+	
+	g_mutex_unlock (&setter_lock);
+	
+	return ok;
 }
 
 /*----------------------------------------------------------------------------*/



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