[evolution-mapi/gnome-2-28] Bug #571579 - Evolution Core Dumps when creating a MAPI account



commit 54e97a62d00422020db11056f72c0d95e9f198d0
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 17 13:47:11 2010 +0100

    Bug #571579 - Evolution Core Dumps when creating a MAPI account

 src/libexchangemapi/exchange-mapi-connection.c |  141 ++++++++++++------------
 1 files changed, 71 insertions(+), 70 deletions(-)
---
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 1624904..c8556b7 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -64,33 +64,67 @@ static GStaticRecMutex connect_lock = G_STATIC_REC_MUTEX_INIT;
 #define STREAM_ACCESS_WRITE     0x0001
 #define STREAM_ACCESS_READWRITE 0x0002
 
+static gboolean
+ensure_mapi_init_called (void)
+{
+	static gboolean called = FALSE;
+	gchar *profpath;
+	enum MAPISTATUS status;
+
+	LOCK ();
+	if (called) {
+		UNLOCK ();
+		return TRUE;
+	}
+
+	profpath = g_build_filename (g_get_home_dir (), DEFAULT_PROF_PATH, NULL);
+
+	if (!g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+		/* Create a ProfileStore */
+		status = CreateProfileStore (profpath, LIBMAPI_LDIF_DIR);
+		if (status != MAPI_E_SUCCESS && (status != MAPI_E_NO_ACCESS || !g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
+			mapi_errstr ("CreateProfileStore", GetLastError());
+			g_free (profpath);
+
+			UNLOCK ();
+			return FALSE;
+		}
+	}
+
+	status = MAPIInitialize (profpath);
+	if (status == MAPI_E_SESSION_LIMIT) {
+		/* do nothing, the profile store is already initialized */
+		/* but this shouldn't happen */
+		mapi_errstr ("MAPIInitialize", GetLastError());
+	} else if (status != MAPI_E_SUCCESS) {
+		mapi_errstr ("MAPIInitialize", GetLastError());
+		g_free (profpath);
+
+		UNLOCK ();
+		return FALSE;
+	}
+
+	g_free (profpath);
+
+	called = TRUE;
+	UNLOCK ();
+
+	return TRUE;
+}
+
 static struct mapi_session *
 mapi_profile_load (const char *profname, const char *password)
 {
 	enum MAPISTATUS	retval = MAPI_E_SUCCESS;
 	struct mapi_session *session = NULL;
-	gchar *profpath = NULL;
 	gchar *default_profile_name = NULL;
 	const char *profile = NULL;
 	guint32 debug_log_level = 0;
 
 	d(g_print("\n%s: Entering %s ", G_STRLOC, G_STRFUNC));
 
-	profpath = g_build_filename (g_get_home_dir(), DEFAULT_PROF_PATH, NULL);
-	if (!g_file_test (profpath, G_FILE_TEST_EXISTS)) {
-		g_warning ("\nMAPI profile database @ %s not found ", profpath);
-		goto cleanup;
-	}
-
-	MAPIUninitialize ();
-
-	retval = MAPIInitialize(profpath);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("MAPIInitialize", GetLastError());
-		if (retval == MAPI_E_SESSION_LIMIT)
-			g_print("\n%s: %s: Already connected ", G_STRLOC, G_STRFUNC);
+	if (!ensure_mapi_init_called ())
 		goto cleanup;
-	}
 
 	if (g_getenv ("MAPI_DEBUG")) {
 		debug_log_level = atoi (g_getenv ("MAPI_DEBUG"));
@@ -117,12 +151,6 @@ mapi_profile_load (const char *profname, const char *password)
 	}
 
 cleanup:
-	if (retval != MAPI_E_SUCCESS && retval != MAPI_E_SESSION_LIMIT &&
-	    retval != MAPI_E_LOGON_FAILED)
-		MAPIUninitialize ();
-
-	g_free (profpath);
-
 	d(g_print("\n%s: Leaving %s ", G_STRLOC, G_STRFUNC));
 
 	return session;
@@ -151,13 +179,27 @@ exchange_mapi_connection_new (const char *profile, const char *password)
 }
 
 void
-exchange_mapi_connection_close ()
+exchange_mapi_connection_close (void)
 {
 	LOCK();
+
+	if (global_mapi_session) {
+		mapi_object_t obj_store;
+		enum MAPISTATUS status;
+
+		mapi_object_init (&obj_store);
+
+		/* Open the message store */
+		status = OpenMsgStore (global_mapi_session, &obj_store);
+		if (status != MAPI_E_SUCCESS) {
+			mapi_errstr ("OpenMsgStore", GetLastError());
+		} else {
+			Logoff (&obj_store);
+		}
+	}
 	global_mapi_session = NULL;
-	MAPIUninitialize ();	
+
 	UNLOCK();
-	/* TODO :  Return status. get last error ? */
 }
 
 static gboolean 
@@ -3020,7 +3062,7 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 	enum MAPISTATUS	retval;
 	gboolean result = FALSE; 
 	const gchar *workstation = "localhost";
-	gchar *profname = NULL, *profpath = NULL;
+	gchar *profname = NULL;
 	struct mapi_session *session = NULL;
 
 	/*We need all the params before proceeding.*/
@@ -3031,31 +3073,9 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 
 	LOCK ();
 
-	profpath = g_build_filename (g_get_home_dir(), DEFAULT_PROF_PATH, NULL);
 	profname = g_strdup_printf("%s %s", username, domain);
 
-	if (!g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-		/* Create a ProfileStore */
-		retval = CreateProfileStore (profpath, LIBMAPI_LDIF_DIR); 
-		if (retval != MAPI_E_SUCCESS) {
-			manage_mapi_error ("CreateProfileStore", GetLastError(), error_msg);
-			g_free (profpath);
-			g_free (profname);
-			
-			UNLOCK ();
-			return FALSE;
-		}
-	}
-
-	retval = MAPIInitialize(profpath); 
-	if (retval == MAPI_E_SESSION_LIMIT)
-	/* do nothing, the profile store is already initialized */
-		manage_mapi_error ("MAPIInitialize", GetLastError(), error_msg); 
-	else if (retval != MAPI_E_SUCCESS) {
-		manage_mapi_error ("MAPIInitialize", GetLastError(), error_msg);
-		g_free (profpath);
-		g_free (profname);
-		
+	if (!ensure_mapi_init_called ()) {
 		UNLOCK ();
 		return FALSE;
 	}
@@ -3118,13 +3138,9 @@ exchange_mapi_create_profile (const char *username, const char *password, const
 	} else 
 		goto exit;
 
-cleanup: 
-	if (!result)
-		MAPIUninitialize ();
-
-exit:
+ cleanup: 
+ exit:
 	g_free (profname);
-	g_free (profpath);
 
 	UNLOCK ();
 
@@ -3136,23 +3152,10 @@ exchange_mapi_delete_profile (const char *profile)
 {
 	enum MAPISTATUS	retval;
 	gboolean result = FALSE; 
-	gchar *profpath = NULL;
 
 	LOCK ();
 
-	profpath = g_build_filename (g_get_home_dir(), DEFAULT_PROF_PATH, NULL);
-	if (!g_file_test (profpath, G_FILE_TEST_EXISTS)) {
-		g_warning ("No need to delete profile. DB itself is missing \n");
-		result = TRUE;
-		goto cleanup; 
-	}
-
-	retval = MAPIInitialize(profpath); 
-	if (retval == MAPI_E_SESSION_LIMIT)
-	/* do nothing, the profile store is already initialized */
-		; 
-	else if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("MAPIInitialize", GetLastError());
+	if (!ensure_mapi_init_called ()) {
 		goto cleanup; 
 	}
 
@@ -3167,8 +3170,6 @@ exchange_mapi_delete_profile (const char *profile)
 	result = TRUE; 
 
 cleanup: 
-	g_free(profpath);
-
 	UNLOCK ();
 
 	return result;



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