[evolution-mapi] Bug #627999 - Cannot autocomplete with contacts



commit bdfbaf6fa7cc7eb953e01181803d54636288bc6b
Author: Milan Crha <mcrha redhat com>
Date:   Tue Aug 31 16:44:59 2010 +0200

    Bug #627999 - Cannot autocomplete with contacts

 src/addressbook/e-book-backend-mapi.c          |   29 ++++++++++------
 src/calendar/e-cal-backend-mapi.c              |   19 ++++++----
 src/camel/camel-mapi-store.c                   |    3 +-
 src/libexchangemapi/exchange-mapi-connection.c |   42 ++++++++++++++++++------
 4 files changed, 63 insertions(+), 30 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index 08ef743..1067ac4 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -242,7 +242,9 @@ ebbm_fetch_contacts (EBookBackendMAPI *ebma, struct mapi_SRestriction *restricti
 	g_return_if_fail (ebmac != NULL);
 	g_return_if_fail (ebmac->op_fetch_contacts != NULL);
 
+	e_file_cache_freeze_changes (E_FILE_CACHE (ebma->priv->cache));
 	ebmac->op_fetch_contacts (ebma, restriction, book_view, &notify_data, error);
+	e_file_cache_thaw_changes (E_FILE_CACHE (ebma->priv->cache));
 
 	if (last_modification_secs && *last_modification_secs < notify_data.last_modification)
 		*last_modification_secs = notify_data.last_modification;
@@ -406,13 +408,16 @@ ebbm_load_source (EBookBackendMAPI *ebma, ESource *source, gboolean only_if_exis
 	priv->summary = e_book_backend_summary_new (summary_file_name, SUMMARY_FLUSH_TIMEOUT_SECS * 1000);
 
 	if (g_file_test (summary_file_name, G_FILE_TEST_EXISTS)) {
-		e_book_backend_summary_load (priv->summary);
+		if (!e_book_backend_summary_load (priv->summary))
+			g_unlink (summary_file_name);
 	}
 
+	g_free (summary_file_name);
+
 	if (priv->cache)
 		g_object_unref (priv->cache);
+	summary_file_name = g_build_filename (cache_dir, "cache.xml", NULL);
 	priv->cache = e_book_backend_cache_new (summary_file_name);
-
 	g_free (summary_file_name);
 
 	e_book_backend_set_is_loaded (E_BOOK_BACKEND (ebma), TRUE);
@@ -506,6 +511,7 @@ ebbm_authenticate_user (EBookBackendMAPI *ebma, const gchar *user, const gchar *
 {
 	EBookBackendMAPIPrivate *priv = ebma->priv;
 	GError *mapi_error = NULL;
+	ExchangeMapiConnection *old_conn;
 
 	switch (priv->mode) {
 	case E_DATA_BOOK_MODE_LOCAL:
@@ -521,17 +527,18 @@ ebbm_authenticate_user (EBookBackendMAPI *ebma, const gchar *user, const gchar *
 
 		e_book_backend_mapi_lock_connection (ebma);
 
-		if (priv->conn) {
-			g_object_unref (priv->conn);
-			priv->conn = NULL;
+		old_conn = priv->conn;
+		priv->conn = NULL;
+
+		priv->conn = exchange_mapi_connection_new (priv->profile, passwd, &mapi_error);
+		if (!priv->conn) {
+			priv->conn = exchange_mapi_connection_find (priv->profile);
+			if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
+				exchange_mapi_connection_reconnect (priv->conn, passwd, &mapi_error);
 		}
 
-		/* rather reuse already established connection */
-		priv->conn = exchange_mapi_connection_find (priv->profile);
-		if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
-			exchange_mapi_connection_reconnect (priv->conn, passwd, &mapi_error);
-		else if (!priv->conn)
-			priv->conn = exchange_mapi_connection_new (priv->profile, passwd, &mapi_error);
+		if (old_conn)
+			g_object_unref (old_conn);
 
 		if (!priv->conn || mapi_error) {
 			if (priv->conn) {
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index bd0b5c9..de4cc27 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -183,20 +183,23 @@ ecbm_authenticate (ECalBackend *backend, GError **perror)
 {
 	ECalBackendMAPI *cbmapi;
 	ECalBackendMAPIPrivate *priv;
+	ExchangeMapiConnection *old_conn;
 	GError *mapi_error = NULL;
 
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
 	priv = cbmapi->priv;
 
-	if (priv->conn)
-		g_object_unref (priv->conn);
+	old_conn = priv->conn;
+
+	priv->conn = exchange_mapi_connection_new (priv->profile, priv->password, &mapi_error);
+	if (!priv->conn) {
+		priv->conn = exchange_mapi_connection_find (priv->profile);
+		if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
+			exchange_mapi_connection_reconnect (priv->conn, priv->password, &mapi_error);
+	}
 
-	/* rather reuse already established connection */
-	priv->conn = exchange_mapi_connection_find (priv->profile);
-	if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
-		exchange_mapi_connection_reconnect (priv->conn, priv->password, &mapi_error);
-	else if (!priv->conn)
-		priv->conn = exchange_mapi_connection_new (priv->profile, priv->password, &mapi_error);
+	if (old_conn)
+		g_object_unref (old_conn);
 
 	if (priv->conn && exchange_mapi_connection_connected (priv->conn)) {
 		/* Success */;
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index f677e7c..587d621 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -430,7 +430,8 @@ mapi_connect(CamelService *service, GError **error)
 	event_mask = fnevNewMail | fnevObjectCreated | fnevObjectDeleted |
 		fnevObjectModified | fnevObjectMoved | fnevObjectCopied;
 
-	if (!store->priv->notification_data)
+	/* use MAPI_LISTEN_NOTIFY=1 to enable notifications */
+	if (!store->priv->notification_data && g_getenv ("MAPI_LISTEN_NOTIFY") != NULL)
 		store->priv->notification_data = camel_mapi_notification_listener_start (store, event_mask, MAPI_EVENTS_USE_STORE);
 
 	camel_store_summary_save ((CamelStoreSummary *) store->summary);
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index ab42dd2..d39e6c1 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -41,6 +41,8 @@
 static void register_connection (ExchangeMapiConnection *conn);
 static void unregister_connection (ExchangeMapiConnection *conn);
 static struct mapi_session *mapi_profile_load (const gchar *profname, const gchar *password, GError **perror);
+static void ema_global_lock (void);
+static void ema_global_unlock (void);
 
 /* GObject foo - begin */
 
@@ -49,8 +51,8 @@ G_DEFINE_TYPE (ExchangeMapiConnection, exchange_mapi_connection, G_TYPE_OBJECT)
 #define EXCHANGE_MAPI_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EXCHANGE_TYPE_MAPI_CONNECTION, ExchangeMapiConnectionPrivate))
 
 /* These two macros require 'priv' variable of type ExchangeMapiConnectionPrivate */
-#define LOCK()		g_debug ("%s: %s: lock(session_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_lock (&priv->session_lock);
-#define UNLOCK()	g_debug ("%s: %s: unlock(session_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_unlock (&priv->session_lock);
+#define LOCK()		g_debug ("%s: %s: lock(session/global_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_lock (&priv->session_lock); ema_global_lock();
+#define UNLOCK()	g_debug ("%s: %s: unlock(session/global_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_unlock (&priv->session_lock); ema_global_unlock();
 
 #define e_return_val_mapi_error_if_fail(expr, _code, _val)				\
 	G_STMT_START {									\
@@ -1114,12 +1116,14 @@ exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn, struct mapi_SR
 			break;
 		}
 		if (aRowSet->cRows) {
+			ema_global_unlock ();
 			for (i = 0; i < aRowSet->cRows; i++, count++) {
 				if (!cb (conn, count, n_rows, &aRowSet->aRow[i], data)) {
 					ms = MAPI_E_RESERVED;
 					break;
 				}
 			}
+			ema_global_lock ();
 		} else {
 			MAPIFreeBuffer (aRowSet);
 			break;
@@ -1685,7 +1689,9 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 				item_data->total = count; //Total entries in the table.
 				item_data->index = cursor_pos + i; //cursor_pos + current_table_index
 
+				ema_global_unlock ();
 				cb_retval = cb (item_data, data);
+				ema_global_lock ();
 
 				g_free (item_data);
 			} else {
@@ -1832,8 +1838,10 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 		item_data->recipients = recip_list;
 		item_data->attachments = attach_list;
 
+		ema_global_unlock ();
 		/* NOTE: stream_list, recipient_list and attach_list should be freed by the callback */
 		cb (item_data, data);
+		ema_global_lock ();
 
 		g_free (item_data);
 	} else {
@@ -3468,7 +3476,21 @@ ensure_mapi_init_called (GError **perror)
 }
 
 /* used when dealing with profiles */
-static GStaticMutex profile_mutex = G_STATIC_MUTEX_INIT;
+static GStaticRecMutex profile_mutex = G_STATIC_REC_MUTEX_INIT;
+
+/* because openchange/samba4 is not thread safe */
+static void
+ema_global_lock (void)
+{
+	g_static_rec_mutex_lock (&profile_mutex);
+}
+
+/* because openchange/samba4 is not thread safe */
+static void
+ema_global_unlock (void)
+{
+	g_static_rec_mutex_unlock (&profile_mutex);
+}
 
 static struct mapi_session *
 mapi_profile_load (const gchar *profname, const gchar *password, GError **perror)
@@ -3479,7 +3501,7 @@ mapi_profile_load (const gchar *profname, const gchar *password, GError **perror
 
 	e_return_val_mapi_error_if_fail (profname != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
-	g_static_mutex_lock (&profile_mutex);
+	g_static_rec_mutex_lock (&profile_mutex);
 
 	/* Initialize libexchangemapi logger*/
 	if (g_getenv ("EXCHANGEMAPI_DEBUG")) {
@@ -3508,7 +3530,7 @@ mapi_profile_load (const gchar *profname, const gchar *password, GError **perror
 	}
 
  cleanup:
-	g_static_mutex_unlock (&profile_mutex);
+	g_static_rec_mutex_unlock (&profile_mutex);
 	g_debug ("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
 	return session;
@@ -3530,12 +3552,12 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 	e_return_val_mapi_error_if_fail (username && *username && password && *password &&
 			      domain && *domain && server && *server, MAPI_E_INVALID_PARAMETER, FALSE);
 
-	g_static_mutex_lock (&profile_mutex);
+	g_static_rec_mutex_lock (&profile_mutex);
 
 	g_debug ("Create profile with %s %s %s\n", username, domain, server);
 
 	if (!ensure_mapi_init_called (perror)) {
-		g_static_mutex_unlock (&profile_mutex);
+		g_static_rec_mutex_unlock (&profile_mutex);
 		return FALSE;
 	}
 
@@ -3605,7 +3627,7 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 		mapi_object_release (&msg_store);
 	}*/
 
-	g_static_mutex_unlock (&profile_mutex);
+	g_static_rec_mutex_unlock (&profile_mutex);
 
 	return result;
 }
@@ -3615,7 +3637,7 @@ exchange_mapi_delete_profile (const gchar *profile, GError **perror)
 {
 	gboolean result = FALSE;
 
-	g_static_mutex_lock (&profile_mutex);
+	g_static_rec_mutex_lock (&profile_mutex);
 
 	if (ensure_mapi_init_called (perror)) {
 		enum MAPISTATUS ms;
@@ -3630,7 +3652,7 @@ exchange_mapi_delete_profile (const gchar *profile, GError **perror)
 		}
 	}
 
-	g_static_mutex_unlock (&profile_mutex);
+	g_static_rec_mutex_unlock (&profile_mutex);
 
 	return result;
 }



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