[evolution-patches] Patch for async authentication to Evolution Calendar



hi,

 The patch is a fix for #55802 and allows async authentication to the
Evolution calendar -decoupling authentication to the backend and getting
the password in the UI into different threads.

harishIndex: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.241
diff -u -p -r1.241 ChangeLog
--- ChangeLog	12 Apr 2004 06:53:50 -0000	1.241
+++ ChangeLog	14 Apr 2004 10:53:26 -0000
@@ -1,3 +1,13 @@
+2004-04-14  Harish Krishnaswamy  <kharish novell com>
+
+	Fixes #55802
+	
+	* libecal/e-cal.c: (open_calendar): Create and lock
+	op mutex and unlock ecal before attempting to authenticate.
+	(open_async, async_auth_idle_cb,async_auth_func_cb): implement 
+	async authentication to calendar.
+ 
+
 2004-04-12  Sarfraaz Ahmed <asarfraaz novell com>
 
 	Fixes #56517
Index: libecal/e-cal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal.c,v
retrieving revision 1.54
diff -u -p -r1.54 e-cal.c
--- libecal/e-cal.c	12 Apr 2004 06:53:50 -0000	1.54
+++ libecal/e-cal.c	14 Apr 2004 10:53:27 -0000
@@ -1465,6 +1465,12 @@ open_calendar (ECal *ecal, gboolean only
 		E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_BUSY, error);
 	}
 
+	/* start the open operation */
+	our_op = e_calendar_new_op (ecal);
+	g_mutex_lock (our_op->mutex);
+
+	g_mutex_unlock (priv->mutex);
+
 	/* see if the backend needs authentication */
 	if (e_source_get_property (priv->source, "auth")) {
 		char *prompt, *key;
@@ -1472,13 +1478,13 @@ open_calendar (ECal *ecal, gboolean only
 		priv->load_state = E_CAL_LOAD_AUTHENTICATING;
 
 		if (priv->auth_func == NULL) {
-			g_mutex_unlock (priv->mutex);
+			g_mutex_unlock (our_op->mutex);
 			E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED,
error);
 		}
 
 		username = e_source_get_property (priv->source, "username");
 		if (!username) {
-			g_mutex_unlock (priv->mutex);
+			g_mutex_unlock (our_op->mutex);
 			E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED,
error);
 		}
 
@@ -1489,7 +1495,7 @@ open_calendar (ECal *ecal, gboolean only
 
 		password = priv->auth_func (ecal, prompt, key, priv->auth_user_data);
 		if (!password) {
-			g_mutex_unlock (priv->mutex);
+			g_mutex_unlock (our_op->mutex);
 			E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED,
error);
 		}
 
@@ -1497,10 +1503,6 @@ open_calendar (ECal *ecal, gboolean only
 		g_free (key);
 	}
 
-	/* start the open operation */
-	our_op = e_calendar_new_op (ecal);
-
-	g_mutex_lock (our_op->mutex);
 
 	CORBA_exception_init (&ev);
 
@@ -1544,8 +1546,6 @@ open_calendar (ECal *ecal, gboolean only
 	else
 		priv->load_state = E_CAL_LOAD_NOT_LOADED;
 
-	g_mutex_unlock (ecal->priv->mutex);
-
 	E_CALENDAR_CHECK_STATUS (*status, error);
 }
 
@@ -1581,29 +1581,74 @@ typedef struct {
 	gboolean exists;
 	gboolean result;
 	ECalendarStatus status;
+	ECalAuthFunc real_auth_func;
+	gpointer real_auth_user_data;
+	const char *auth_prompt;
+	const char *auth_key;
+	char *password;
+	GMutex *mutex;
+	GCond *cond;
 } ECalAsyncData;
 
 static gboolean
-async_idle_cb (gpointer data)
+async_auth_idle_cb (gpointer data)
 {
 	ECalAsyncData *ccad = data;
 
-	ccad->result = open_calendar (ccad->ecal, ccad->exists, NULL,
&ccad->status);
-	g_signal_emit (G_OBJECT (ccad->ecal), e_cal_signals[CAL_OPENED], 0,
ccad->status);
+	g_mutex_lock (ccad->mutex);
+	ccad->password = ccad->real_auth_func (ccad->ecal, ccad->auth_prompt,
ccad->auth_key, ccad->real_auth_user_data);
+	g_cond_signal (ccad->cond);
+	g_mutex_unlock (ccad->mutex);
+	
+	return FALSE;
+}
 
-	/* free memory */
-	g_object_unref (ccad->ecal);
-	g_free (ccad);
+static char *
+async_auth_func_cb (ECal *ecal, const char *prompt, const char *key,
gpointer user_data)
+{
+	ECalAsyncData *ccad = user_data;
+	char * password;
 
-	return FALSE;
+	ccad->auth_prompt = prompt;
+	ccad->auth_key = key;
+
+	g_idle_add ((GSourceFunc) async_auth_idle_cb, ccad);
+		
+	g_mutex_lock (ccad->mutex);
+	g_cond_wait (ccad->cond, ccad->mutex);
+	password = ccad->password;
+	ccad->password = NULL;
+	g_mutex_unlock (ccad->mutex);	
+
+	return password;
 }
 
+
 static gpointer
 open_async (gpointer data) 
 {
 	ECalAsyncData *ccad = data;
 
-	g_idle_add ((GSourceFunc) async_idle_cb, ccad);
+	ccad->mutex = g_mutex_new ();
+	ccad->cond = g_cond_new ();
+
+	ccad->real_auth_func = ccad->ecal->priv->auth_func;
+	ccad->real_auth_user_data = ccad->ecal->priv->auth_user_data;
+	ccad->ecal->priv->auth_func = async_auth_func_cb;
+	ccad->ecal->priv->auth_user_data = ccad;
+
+	ccad->result = open_calendar (ccad->ecal, ccad->exists, NULL,
&ccad->status);
+	g_signal_emit (G_OBJECT (ccad->ecal), e_cal_signals[CAL_OPENED], 0,
ccad->status);
+
+	ccad->ecal->priv->auth_func = ccad->real_auth_func;
+	ccad->ecal->priv->auth_user_data = ccad->real_auth_user_data;
+	g_mutex_free (ccad->mutex);
+	g_cond_free (ccad->cond);
+
+	/* free memory */
+	g_object_unref (ccad->ecal);
+	g_free (ccad);
+
 
 	return GINT_TO_POINTER (ccad->result);
 }
@@ -1614,7 +1659,6 @@ e_cal_open_async (ECal *ecal, gboolean o
 	ECalAsyncData *ccad;
 	GThread *thread;
 	GError *error = NULL;
-	
 	g_return_if_fail (ecal != NULL);
 	g_return_if_fail (E_IS_CAL (ecal));
 




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