[evolution-data-server/meego-eds: 12/47] Add a hack: where the daemon emits ask-password signal and let the client ask for password and save



commit 7009c975decabbbfdbdbdc034b8af62f3587d2ee
Author: Srinivasa Ragavan <sragavan gnome org>
Date:   Tue Apr 19 19:31:35 2011 +0530

    Add a hack: where the daemon emits ask-password signal and let the
    client ask for password and save it. the daemon checks it after a minute
    to see if the password is set or not. Does this thrice before it returns
    NULL. Ideally the backends should retunr NEED_PASSWORD and clients
    should prompt for it and redo the command.

 mail/daemon/e-mail-data-session.c   |    8 ++++
 mail/daemon/e-mail-data-session.h   |    1 +
 mail/daemon/e-mail-data-session.xml |    5 +++
 mail/daemon/mail-session.c          |   61 +++++++++++++++-------------------
 4 files changed, 41 insertions(+), 34 deletions(-)
---
diff --git a/mail/daemon/e-mail-data-session.c b/mail/daemon/e-mail-data-session.c
index 1d57825..7aa2875 100644
--- a/mail/daemon/e-mail-data-session.c
+++ b/mail/daemon/e-mail-data-session.c
@@ -412,3 +412,11 @@ e_mail_session_get_folder_from_path (EMailDataSession *msession, const char *pat
 
 	return NULL;	
 }
+
+void
+e_mail_session_emit_ask_password (EMailDataSession *msession, const char *title, const gchar *prompt, const gchar *key)
+{
+	EMailDataSessionPrivate *priv = DATA_SESSION_PRIVATE(msession);
+
+	egdbus_session_cs_emit_get_password (priv->gdbus_object, title, prompt, key);
+}
diff --git a/mail/daemon/e-mail-data-session.h b/mail/daemon/e-mail-data-session.h
index 66a771d..bf2b46a 100644
--- a/mail/daemon/e-mail-data-session.h
+++ b/mail/daemon/e-mail-data-session.h
@@ -46,6 +46,7 @@ guint e_mail_data_session_register_gdbus_object (EMailDataSession *msession, GDB
 void e_mail_data_session_release (EMailDataSession *session, GDBusConnection *connection, const char *name);
 const char * e_mail_data_session_get_path_from_store (EMailDataSession *msession, gpointer store);
 CamelFolder * e_mail_session_get_folder_from_path (EMailDataSession *msession, const char *path);
+void e_mail_session_emit_ask_password (EMailDataSession *msession, const char *title, const gchar *prompt, const gchar *key);
 
 
 G_END_DECLS
diff --git a/mail/daemon/e-mail-data-session.xml b/mail/daemon/e-mail-data-session.xml
index 18219d9..a1f1f6b 100644
--- a/mail/daemon/e-mail-data-session.xml
+++ b/mail/daemon/e-mail-data-session.xml
@@ -28,6 +28,11 @@
       <arg name="type" type="s" direction="in"/>	    
       <arg name="folder" type="o" direction="out"/>
     </method>
+    <signal name="GetPassword">
+      <arg name="title" type="s"/>
+      <arg name="prompt" type="s"/>
+      <arg name="key" type="s"/>
+    </signal>
 
   </interface>
 
diff --git a/mail/daemon/mail-session.c b/mail/daemon/mail-session.c
index c062935..bdacd06 100644
--- a/mail/daemon/mail-session.c
+++ b/mail/daemon/mail-session.c
@@ -52,10 +52,13 @@
 #include "mail-session.h"
 #include "mail-tools.h"
 #include "mail-send-recv.h"
+#include "e-mail-data-session.h"
 
 #define d(x)
 
 CamelSession *session;
+extern EMailDataSession *data_session;
+
 static guint session_check_junk_notify_id;
 static guint session_gconf_proxy_id;
 
@@ -192,10 +195,16 @@ get_password (CamelSession *session,
 	} else {
 		gchar *key = make_key(service, item);
 		EAccountService *config_service = NULL;
+		EFlag *timer;
+		GTimeVal tval;
+		int count=0;
+
+		timer = e_flag_new ();
+		tval.tv_sec = 60; /* Reprompt every 60sec*/
 
 		if (domain == NULL)
 			domain = "Mail";
-
+repeat:
 		ret = e_passwords_get_password(domain, key);
 		if (ret == NULL || (flags & CAMEL_SESSION_PASSWORD_REPROMPT)) {
 			gboolean remember;
@@ -213,7 +222,6 @@ get_password (CamelSession *session,
 			remember = config_service?config_service->save_passwd:FALSE;
 
 			if (!config_service || (config_service && !config_service->get_password_canceled)) {
-				guint32 eflags;
 				gchar *title;
 
 				if (flags & CAMEL_SESSION_PASSPHRASE) {
@@ -227,34 +235,17 @@ get_password (CamelSession *session,
 					else
 						title = g_strdup (_("Enter Password"));
 				}
-				if ((flags & CAMEL_SESSION_PASSWORD_STATIC) != 0)
-					eflags = E_PASSWORDS_REMEMBER_NEVER;
-				else if (config_service == NULL)
-					eflags = E_PASSWORDS_REMEMBER_SESSION;
-				else
-					eflags = E_PASSWORDS_REMEMBER_FOREVER;
-
-				if (flags & CAMEL_SESSION_PASSWORD_REPROMPT)
-					eflags |= E_PASSWORDS_REPROMPT;
-
-				if (flags & CAMEL_SESSION_PASSWORD_SECRET)
-					eflags |= E_PASSWORDS_SECRET;
-
-				if (flags & CAMEL_SESSION_PASSPHRASE)
-					eflags |= E_PASSWORDS_PASSPHRASE;
-
-				/* HACK: breaks abstraction ...
-				   e_account_writable doesn't use the eaccount, it also uses the same writable key for
-				   source and transport */
-				if (!e_account_writable(NULL, E_ACCOUNT_SOURCE_SAVE_PASSWD))
-					eflags |= E_PASSWORDS_DISABLE_REMEMBER;
-
-				ret = e_passwords_ask_password(title, domain, key, prompt, eflags, &remember, NULL);
-
-				if (!ret)
-					e_passwords_forget_password (domain, key);
-
+				
+				e_mail_session_emit_ask_password (data_session, title, prompt, key);
 				g_free(title);
+				
+				/* Repeat three times, every minute to check if password is available */
+				count++;
+				if (count <= 2) {
+					/* FIXME: This is an ugly hack for now. Ideally we should return and let the backends requery when NEED_PASSWORD error is returned. */
+					e_flag_timed_wait (timer, &tval);
+					goto repeat;
+				}
 
 				if (ret && config_service)
 					mail_config_service_set_save_passwd(config_service, remember);
@@ -263,17 +254,19 @@ get_password (CamelSession *session,
 					config_service->get_password_canceled = ret == NULL;
 			}
 		}
-
+		
+		e_flag_free (timer);
 		g_free(key);
 	}
 
 	g_free(url);
 
-	if (ret == NULL)
+	if (ret == NULL && error) {
 		g_set_error (
-			error, G_IO_ERROR,
-			G_IO_ERROR_CANCELLED,
-			_("User canceled operation."));
+			error, CAMEL_SERVICE_ERROR,
+			CAMEL_SERVICE_ERROR_NEED_PASSWORD,
+			_("Need password for authentication"));
+	}
 
 	return ret;
 }



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