[evolution-data-server/account-mgmt: 26/39] Adapt e-passwords.c to utilize the new ESource API.



commit a7dbdd0c071c8dd76aef19889a56f46e0fd25df6
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Dec 5 16:12:22 2010 -0600

    Adapt e-passwords.c to utilize the new ESource API.

 .../libedataserverui/libedataserverui-sections.txt |    1 -
 .../libedataserverui/tmpl/e-passwords.sgml         |   22 +-
 .../tmpl/libedataserverui-unused.sgml              |    7 +
 libedataserverui/e-passwords.c                     |  329 +++++---------------
 libedataserverui/e-passwords.h                     |   39 ++--
 5 files changed, 113 insertions(+), 285 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index cbd1a43..46b059e 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -333,7 +333,6 @@ e_passwords_add_password
 e_passwords_get_password
 e_passwords_forget_password
 e_passwords_forget_passwords
-e_passwords_clear_passwords
 EPasswordsRememberType
 e_passwords_ask_password
 </SECTION>
diff --git a/docs/reference/libedataserverui/tmpl/e-passwords.sgml b/docs/reference/libedataserverui/tmpl/e-passwords.sgml
index dacf0ca..eb28f76 100644
--- a/docs/reference/libedataserverui/tmpl/e-passwords.sgml
+++ b/docs/reference/libedataserverui/tmpl/e-passwords.sgml
@@ -57,8 +57,7 @@ e-passwords
 
 </para>
 
- unused: 
- key: 
+ source: 
 
 
 <!-- ##### FUNCTION e_passwords_add_password ##### -->
@@ -66,7 +65,7 @@ e-passwords
 
 </para>
 
- key: 
+ source: 
 @passwd: 
 
 
@@ -75,8 +74,7 @@ e-passwords
 
 </para>
 
- unused: 
- key: 
+ source: 
 @Returns: 
 
 
@@ -85,8 +83,7 @@ e-passwords
 
 </para>
 
- unused: 
- key: 
+ source: 
 
 
 <!-- ##### FUNCTION e_passwords_forget_passwords ##### -->
@@ -97,14 +94,6 @@ e-passwords
 @void: 
 
 
-<!-- ##### FUNCTION e_passwords_clear_passwords ##### -->
-<para>
-
-</para>
-
- unused: 
-
-
 <!-- ##### ENUM EPasswordsRememberType ##### -->
 <para>
 
@@ -125,9 +114,8 @@ e-passwords
 
 </para>
 
+ source: 
 @title: 
- unused: 
- key: 
 @prompt: 
 @remember_type: 
 @remember: 
diff --git a/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml b/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
index 5be9944..ed3480e 100644
--- a/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
+++ b/docs/reference/libedataserverui/tmpl/libedataserverui-unused.sgml
@@ -185,6 +185,13 @@ ESourceOptionMenu
 @user_data: 
 @Returns: 
 
+<!-- ##### FUNCTION e_passwords_clear_passwords ##### -->
+<para>
+
+</para>
+
+ component: 
+
 <!-- ##### FUNCTION e_source_option_menu_new ##### -->
 <para>
 
diff --git a/libedataserverui/e-passwords.c b/libedataserverui/e-passwords.c
index 9a14502..9641656 100644
--- a/libedataserverui/e-passwords.c
+++ b/libedataserverui/e-passwords.c
@@ -54,6 +54,9 @@
 
 #define d(x)
 
+#define KEYRING_ITEM_DISPLAY_NAME	"Evolution Data Source"
+#define KEYRING_ITEM_ATTRIBUTE_NAME	"e-source-uid"
+
 typedef struct _EPassMsg EPassMsg;
 
 struct _EPassMsg {
@@ -62,7 +65,7 @@ struct _EPassMsg {
 
 	/* input */
 	GtkWindow *parent;
-	const gchar *key;
+	const gchar *uid;
 	const gchar *title;
 	const gchar *prompt;
 	const gchar *oldpass;
@@ -104,96 +107,37 @@ ep_keyring_error_domain (void)
 	return quark;
 }
 
-static EUri *
-ep_keyring_uri_new (const gchar *string,
-                    GError **error)
-{
-	EUri *uri;
-
-	uri = e_uri_new (string);
-	g_return_val_if_fail (uri != NULL, NULL);
-
-	/* LDAP URIs do not have usernames, so use the URI as the username. */
-	if (uri->user == NULL && uri->protocol != NULL &&
-			(strcmp (uri->protocol, "ldap") == 0|| strcmp (uri->protocol, "google") == 0))
-		uri->user = g_strdelimit (g_strdup (string), "/=", '_');
-
-	/* Make sure the URI has the required components. */
-	if (uri->user == NULL && uri->host == NULL) {
-		g_set_error_literal (
-			error, EP_KEYRING_ERROR,
-			GNOME_KEYRING_RESULT_BAD_ARGUMENTS,
-			_("Keyring key is unusable: no user or host name"));
-		e_uri_free (uri);
-		uri = NULL;
-	}
-
-	return uri;
-}
-
 static gboolean
-ep_keyring_validate (const gchar *user,
-                     const gchar *server,
-                     const gchar *protocol,
+ep_keyring_validate (const gchar *source_uid,
                      GnomeKeyringAttributeList *attributes)
 {
-	const gchar *user_value = NULL;
-	const gchar *server_value = NULL;
-	const gchar *protocol_value = NULL;
+	const gchar *attr_value = NULL;
 	gint ii;
 
 	g_return_val_if_fail (attributes != NULL, FALSE);
 
 	/* Is there anything to validate? */
-	if (user == NULL && server == NULL && protocol == NULL)
+	if (source_uid == NULL)
 		return TRUE;
 
-	/* Look for "user", "server", and "protocol" attributes. */
+	/* Look for an "e-source-uid" attribute. */
 	for (ii = 0; ii < attributes->len; ii++) {
 		GnomeKeyringAttribute *attr;
 
 		attr = &g_array_index (attributes, GnomeKeyringAttribute, ii);
 
 		/* Just assume the attribute values are strings. */
-		if (strcmp (attr->name, "user") == 0)
-			user_value = attr->value.string;
-		else if (strcmp (attr->name, "server") == 0)
-			server_value = attr->value.string;
-		else if (strcmp (attr->name, "protocol") == 0)
-			protocol_value = attr->value.string;
+		if (strcmp (attr->name, KEYRING_ITEM_ATTRIBUTE_NAME) == 0) {
+			attr_value = attr->value.string;
+			break;
+		}
 	}
 
-	/* Is there a "user" attribute? */
-	if (user != NULL && user_value == NULL)
-		return FALSE;
-
-	/* Does it match what we're looking for? */
-	if (user != NULL && strcmp (user, user_value) != 0)
-		return FALSE;
-
-	/* Is there a "server" attribute? */
-	if (server != NULL && server_value == NULL)
-		return FALSE;
-
-	/* Does it match what we're looking for? */
-	if (server != NULL && strcmp (server, server_value) != 0)
-		return FALSE;
-
-	/* Is there a "protocol" attribute? */
-	if (protocol != NULL && protocol_value == NULL)
-		return FALSE;
-
-	/* Does it match what we're looking for? */
-	if (protocol != NULL && strcmp (protocol, protocol_value) != 0)
-		return FALSE;
-
-	return TRUE;
+	return (g_strcmp0 (source_uid, attr_value) == 0);
 }
 
 static gboolean
-ep_keyring_delete_passwords (const gchar *user,
-                             const gchar *server,
-                             const gchar *protocol,
+ep_keyring_delete_passwords (const gchar *source_uid,
                              GList *passwords,
                              GError **error)
 {
@@ -202,14 +146,9 @@ ep_keyring_delete_passwords (const gchar *user,
 		GnomeKeyringResult result;
 
 		/* Validate the item before deleting it. */
-		if (!ep_keyring_validate (user, server, protocol, found->attributes)) {
-			/* XXX We didn't always store protocols in the
-			 *     keyring, so for backward-compatibility
-			 *     try validating by user and server only. */
-			if (!ep_keyring_validate (user, server, NULL, found->attributes)) {
-				passwords = g_list_next (passwords);
-				continue;
-			}
+		if (!ep_keyring_validate (source_uid, found->attributes)) {
+			passwords = g_list_next (passwords);
+			continue;
 		}
 
 		result = gnome_keyring_item_delete_sync (NULL, found->item_id);
@@ -229,32 +168,23 @@ ep_keyring_delete_passwords (const gchar *user,
 }
 
 static gboolean
-ep_keyring_insert_password (const gchar *user,
-                            const gchar *server,
-                            const gchar *protocol,
-                            const gchar *display_name,
+ep_keyring_insert_password (const gchar *source_uid,
                             const gchar *password,
                             GError **error)
 {
 	GnomeKeyringAttributeList *attributes;
 	GnomeKeyringResult result;
+	gchar *display_name;
 	guint32 item_id;
 
-	g_return_val_if_fail (user != NULL, FALSE);
-	g_return_val_if_fail (server != NULL, FALSE);
-	g_return_val_if_fail (protocol != NULL, FALSE);
-	g_return_val_if_fail (display_name != NULL, FALSE);
-	g_return_val_if_fail (password != NULL, FALSE);
-
 	attributes = gnome_keyring_attribute_list_new ();
 	gnome_keyring_attribute_list_append_string (
 		attributes, "application", "Evolution");
 	gnome_keyring_attribute_list_append_string (
-		attributes, "user", user);
-	gnome_keyring_attribute_list_append_string (
-		attributes, "server", server);
-	gnome_keyring_attribute_list_append_string (
-		attributes, "protocol", protocol);
+		attributes, KEYRING_ITEM_ATTRIBUTE_NAME, source_uid);
+
+	display_name = g_strdup_printf (
+		"%s %s", KEYRING_ITEM_DISPLAY_NAME, source_uid);
 
 	/* XXX We don't use item_id but gnome-keyring doesn't allow
 	 *     for a NULL pointer.  In fact it doesn't even check! */
@@ -269,15 +199,15 @@ ep_keyring_insert_password (const gchar *user,
 			gnome_keyring_result_to_message (result));
 	}
 
+	g_free (display_name);
+
 	gnome_keyring_attribute_list_free (attributes);
 
 	return (result == GNOME_KEYRING_RESULT_OK);
 }
 
 static GList *
-ep_keyring_lookup_passwords (const gchar *user,
-                             const gchar *server,
-                             const gchar *protocol,
+ep_keyring_lookup_passwords (const gchar *source_uid,
                              GError **error)
 {
 	GnomeKeyringAttributeList *attributes;
@@ -287,15 +217,9 @@ ep_keyring_lookup_passwords (const gchar *user,
 	attributes = gnome_keyring_attribute_list_new ();
 	gnome_keyring_attribute_list_append_string (
 		attributes, "application", "Evolution");
-	if (user != NULL)
-		gnome_keyring_attribute_list_append_string (
-			attributes, "user", user);
-	if (server != NULL)
-		gnome_keyring_attribute_list_append_string (
-			attributes, "server", server);
-	if (protocol != NULL)
+	if (source_uid != NULL)
 		gnome_keyring_attribute_list_append_string (
-			attributes, "protocol", protocol);
+			attributes, KEYRING_ITEM_ATTRIBUTE_NAME, source_uid);
 
 	result = gnome_keyring_find_items_sync (
 		GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &passwords);
@@ -391,32 +315,6 @@ ep_msg_send (EPassMsg *msg)
 /* the functions that actually do the work */
 
 static void
-ep_clear_passwords (EPassMsg *msg)
-{
-	GList *passwords;
-	GError *error = NULL;
-
-	/* Find all Evolution passwords and delete them. */
-	passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error);
-	if (passwords != NULL) {
-		ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error);
-		gnome_keyring_found_list_free (passwords);
-	}
-
-	/* Not finding the requested key is acceptable, but we still
-	 * want to leave an informational message on the terminal. */
-	if (g_error_matches (error, EP_KEYRING_ERROR, GNOME_KEYRING_RESULT_NO_MATCH)) {
-		g_message ("%s", error->message);
-		g_error_free (error);
-
-	} else if (error != NULL)
-		g_propagate_error (&msg->error, error);
-
-	if (!msg->noreply)
-		e_flag_set (msg->done);
-}
-
-static void
 ep_forget_passwords (EPassMsg *msg)
 {
 	GList *passwords;
@@ -425,9 +323,9 @@ ep_forget_passwords (EPassMsg *msg)
 	g_hash_table_remove_all (password_cache);
 
 	/* Find all Evolution passwords and delete them. */
-	passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error);
+	passwords = ep_keyring_lookup_passwords (NULL, &error);
 	if (passwords != NULL) {
-		ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error);
+		ep_keyring_delete_passwords (NULL, passwords, &error);
 		gnome_keyring_found_list_free (passwords);
 	}
 
@@ -442,29 +340,22 @@ static void
 ep_remember_password (EPassMsg *msg)
 {
 	gchar *password;
-	EUri *uri;
 	GError *error = NULL;
 
-	password = g_hash_table_lookup (password_cache, msg->key);
+	password = g_hash_table_lookup (password_cache, msg->uid);
 	if (password == NULL) {
-		g_warning ("Password for key \"%s\" not found", msg->key);
+		g_warning ("Password for key \"%s\" not found", msg->uid);
 		goto exit;
 	}
 
-	uri = ep_keyring_uri_new (msg->key, &msg->error);
-	if (uri == NULL)
-		goto exit;
-
 	/* Only remove the password from the session hash
 	 * if the keyring insertion was successful. */
-	if (ep_keyring_insert_password (uri->user, uri->host, uri->protocol, msg->key, password, &error))
-		g_hash_table_remove (password_cache, msg->key);
+	if (ep_keyring_insert_password (msg->uid, password, &error))
+		g_hash_table_remove (password_cache, msg->uid);
 
 	if (error != NULL)
 		g_propagate_error (&msg->error, error);
 
-	e_uri_free (uri);
-
 exit:
 	if (!msg->noreply)
 		e_flag_set (msg->done);
@@ -474,35 +365,20 @@ static void
 ep_forget_password (EPassMsg *msg)
 {
 	GList *passwords;
-	EUri *uri;
 	GError *error = NULL;
 
-	g_hash_table_remove (password_cache, msg->key);
-
-	uri = ep_keyring_uri_new (msg->key, &msg->error);
-	if (uri == NULL)
-		goto exit;
+	g_hash_table_remove (password_cache, msg->uid);
 
-	/* Find all Evolution passwords matching the URI and delete them.
-	 *
-	 * XXX We didn't always store protocols in the keyring, so for
-	 *     backward-compatibility we need to lookup passwords by user
-	 *     and host only (no protocol).  But we do send the protocol
-	 *     to ep_keyring_delete_passwords(), which also knows about
-	 *     the backward-compatibility issue and will filter the list
-	 *     appropriately. */
-	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error);
+	/* Find all Evolution passwords matching the UID and delete them. */
+	passwords = ep_keyring_lookup_passwords (msg->uid, &error);
 	if (passwords != NULL) {
-		ep_keyring_delete_passwords (uri->user, uri->host, uri->protocol, passwords, &error);
+		ep_keyring_delete_passwords (msg->uid, passwords, &error);
 		gnome_keyring_found_list_free (passwords);
 	}
 
 	if (error != NULL)
 		g_propagate_error (&msg->error, error);
 
-	e_uri_free (uri);
-
-exit:
 	if (!msg->noreply)
 		e_flag_set (msg->done);
 }
@@ -510,24 +386,19 @@ exit:
 static void
 ep_get_password (EPassMsg *msg)
 {
-	EUri *uri;
 	GList *passwords;
 	gchar *password;
 	GError *error = NULL;
 
 	/* Check the in-memory cache first. */
-	password = g_hash_table_lookup (password_cache, msg->key);
+	password = g_hash_table_lookup (password_cache, msg->uid);
 	if (password != NULL) {
 		msg->password = g_strdup (password);
 		goto exit;
 	}
 
-	uri = ep_keyring_uri_new (msg->key, &msg->error);
-	if (uri == NULL)
-		goto exit;
-
-	/* Find the first Evolution password that matches the URI. */
-	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, uri->protocol, &error);
+	/* Find the first Evolution password that matches the UID. */
+	passwords = ep_keyring_lookup_passwords (msg->uid, &error);
 	if (passwords != NULL) {
 		GList *iter = passwords;
 
@@ -540,7 +411,7 @@ ep_get_password (EPassMsg *msg)
 				continue;
 			}
 
-			if (ep_keyring_validate (uri->user, uri->host, uri->protocol, found->attributes)) {
+			if (ep_keyring_validate (msg->uid, found->attributes)) {
 				msg->password = g_strdup (found->secret);
 				break;
 			}
@@ -559,32 +430,6 @@ ep_get_password (EPassMsg *msg)
 	if (error != NULL)
 		g_clear_error (&error);
 
-	/* XXX We didn't always store protocols in the keyring, so for
-	 *     backward-compatibility we also need to lookup passwords
-	 *     by user and host only (no protocol). */
-	passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error);
-	if (passwords != NULL) {
-		GList *iter = passwords;
-
-		while (iter != NULL) {
-			GnomeKeyringFound *found = iter->data;
-
-			if (default_keyring && strcmp (default_keyring, found->keyring) != 0) {
-				g_message ("Received a password from keyring '%s'. But looking for the password from '%s' keyring\n", found->keyring, default_keyring);
-				iter = g_list_next (iter);
-				continue;
-			}
-			if (ep_keyring_validate (uri->user, uri->host, NULL, found->attributes)) {
-				msg->password = g_strdup (found->secret);
-				break;
-			}
-
-			iter = g_list_next (iter);
-		}
-
-		gnome_keyring_found_list_free (passwords);
-	}
-
 done:
 	/* Not finding the requested key is acceptable, but we still
 	 * want to leave an informational message on the terminal. */
@@ -595,8 +440,6 @@ done:
 	} else if (error != NULL)
 		g_propagate_error (&msg->error, error);
 
-	e_uri_free (uri);
-
 exit:
 	if (!msg->noreply)
 		e_flag_set (msg->done);
@@ -606,7 +449,7 @@ static void
 ep_add_password (EPassMsg *msg)
 {
 	g_hash_table_insert (
-		password_cache, g_strdup (msg->key),
+		password_cache, g_strdup (msg->uid),
 		g_strdup (msg->oldpass));
 
 	if (!msg->noreply)
@@ -659,7 +502,7 @@ pass_response (GtkDialog *dialog,
 		if ((pending->dispatch == ep_forget_password
 		     || pending->dispatch == ep_get_password
 		     || pending->dispatch == ep_ask_password)
-			&& strcmp (pending->key, msg->key) == 0) {
+		     && strcmp (pending->uid, msg->uid) == 0) {
 
 			/* Satisfy the pending operation. */
 			pending->password = g_strdup (msg->password);
@@ -960,35 +803,20 @@ e_passwords_forget_passwords (void)
 }
 
 /**
- * e_passwords_clear_passwords:
- *
- * Forgets all disk cached passwords for the component.
- **/
-void
-e_passwords_clear_passwords (const gchar *unused)
-{
-	EPassMsg *msg = ep_msg_new (ep_clear_passwords);
-
-	ep_msg_send (msg);
-	ep_msg_free (msg);
-}
-
-/**
  * e_passwords_remember_password:
- * @key: the key
+ * @source: an #ESource
  *
- * Saves the password associated with @key to disk.
+ * Saves the password associated with @source to the default keyring.
  **/
 void
-e_passwords_remember_password (const gchar *unused,
-                               const gchar *key)
+e_passwords_remember_password (ESource *source)
 {
 	EPassMsg *msg;
 
-	g_return_if_fail (key != NULL);
+	g_return_if_fail (E_IS_SOURCE (source));
 
 	msg = ep_msg_new (ep_remember_password);
-	msg->key = key;
+	msg->uid = g_strdup (e_source_get_uid (source));
 
 	ep_msg_send (msg);
 	ep_msg_free (msg);
@@ -996,20 +824,20 @@ e_passwords_remember_password (const gchar *unused,
 
 /**
  * e_passwords_forget_password:
- * @key: the key
+ * @source: an #ESource
  *
- * Forgets the password associated with @key, in memory and on disk.
+ * Forgets the password associated with @source, in memory and on the
+ * default keyring.
  **/
 void
-e_passwords_forget_password (const gchar *unused,
-                             const gchar *key)
+e_passwords_forget_password (ESource *source)
 {
 	EPassMsg *msg;
 
-	g_return_if_fail (key != NULL);
+	g_return_if_fail (E_IS_SOURCE (source));
 
 	msg = ep_msg_new (ep_forget_password);
-	msg->key = key;
+	msg->uid = g_strdup (e_source_get_uid (source));
 
 	ep_msg_send (msg);
 	ep_msg_free (msg);
@@ -1017,22 +845,21 @@ e_passwords_forget_password (const gchar *unused,
 
 /**
  * e_passwords_get_password:
- * @key: the key
+ * @source: an #ESource
  *
- * Returns: the password associated with @key, or %NULL.  Caller
+ * Returns: the password associated with @source, or %NULL.  Caller
  * must free the returned password.
  **/
 gchar *
-e_passwords_get_password (const gchar *unused,
-                          const gchar *key)
+e_passwords_get_password (ESource *source)
 {
 	EPassMsg *msg;
 	gchar *passwd;
 
-	g_return_val_if_fail (key != NULL, NULL);
+	g_return_val_if_fail (E_IS_SOURCE (source), NULL);
 
 	msg = ep_msg_new (ep_get_password);
-	msg->key = key;
+	msg->uid = g_strdup (e_source_get_uid (source));
 
 	ep_msg_send (msg);
 
@@ -1045,23 +872,22 @@ e_passwords_get_password (const gchar *unused,
 
 /**
  * e_passwords_add_password:
- * @key: a key
- * @passwd: the password for @key
+ * @source: an #ESource
+ * @passwd: the password for @source
  *
- * This stores the @key/@passwd pair in the current session's password
- * hash.
+ * This stores @passwd in the current session's password hash.
  **/
 void
-e_passwords_add_password (const gchar *key,
+e_passwords_add_password (ESource *source,
                           const gchar *passwd)
 {
 	EPassMsg *msg;
 
-	g_return_if_fail (key != NULL);
+	g_return_if_fail (E_IS_SOURCE (source));
 	g_return_if_fail (passwd != NULL);
 
 	msg = ep_msg_new (ep_add_password);
-	msg->key = key;
+	msg->uid = g_strdup (e_source_get_uid (source));
 	msg->oldpass = passwd;
 
 	ep_msg_send (msg);
@@ -1070,9 +896,8 @@ e_passwords_add_password (const gchar *key,
 
 /**
  * e_passwords_ask_password:
+ * @source: an #ESource, or %NULL
  * @title: title for the password dialog
- * @unused: this argument is no longer used
- * @key: key to store the password under
  * @prompt: prompt string
  * @type: whether or not to offer to remember the password,
  * and for how long.
@@ -1080,7 +905,12 @@ e_passwords_add_password (const gchar *key,
  * on output, the state of the checkbox when the dialog was closed.
  * @parent: parent window of the dialog, or %NULL
  *
- * Asks the user for a password.
+ * Asks the user for a password.  If @source is %NULL, there will be
+ * no option to remember the password.
+ *
+ * Passing a %NULL #ESource is a temporary hack to accomodate prompting
+ * for certificate passwords, which have no corresponding #ESource.  We
+ * will eventually use libgcr for this.
  *
  * Returns: the password, which the caller must free, or %NULL if
  * the user cancelled the operation. * remember will be set if the
@@ -1088,9 +918,8 @@ e_passwords_add_password (const gchar *key,
  * E_PASSWORDS_DO_NOT_REMEMBER.
  **/
 gchar *
-e_passwords_ask_password (const gchar *title,
-                          const gchar *unused,
-                          const gchar *key,
+e_passwords_ask_password (ESource *source,
+                          const gchar *title,
                           const gchar *prompt,
                           EPasswordsRememberType type,
                           gboolean *remember,
@@ -1099,19 +928,23 @@ e_passwords_ask_password (const gchar *title,
 	gchar *passwd;
 	EPassMsg *msg;
 
-	g_return_val_if_fail (key != NULL, NULL);
+	g_return_val_if_fail (source == NULL || E_IS_SOURCE (source), NULL);
 
 	if ((type & E_PASSWORDS_ONLINE) && !ep_online_state)
 		return NULL;
 
 	msg = ep_msg_new (ep_ask_password);
 	msg->title = title;
-	msg->key = key;
 	msg->prompt = prompt;
 	msg->flags = type;
 	msg->remember = remember;
 	msg->parent = parent;
 
+	if (source != NULL)
+		msg->uid = g_strdup (e_source_get_uid (source));
+	else
+		msg->flags |= E_PASSWORDS_REMEMBER_NEVER;
+
 	ep_msg_send (msg);
 	passwd = msg->password;
 	msg->password = NULL;
diff --git a/libedataserverui/e-passwords.h b/libedataserverui/e-passwords.h
index 05ba0be..8e6ee45 100644
--- a/libedataserverui/e-passwords.h
+++ b/libedataserverui/e-passwords.h
@@ -20,10 +20,11 @@
  * USA.
  */
 
-#ifndef _E_PASSWORD_H_
-#define _E_PASSWORD_H_
+#ifndef E_PASSWORDS_H
+#define E_PASSWORDS_H
 
 #include <gtk/gtk.h>
+#include <libedataserver/e-source.h>
 
 G_BEGIN_DECLS
 
@@ -34,17 +35,17 @@ G_BEGIN_DECLS
  *
  * e_passwords_shutdown should be called at exit time to synch the
  * password on-disk storage, and to free up in-memory storage. */
-void e_passwords_init (void);
+void		e_passwords_init		(void);
 
-void        e_passwords_shutdown          (void);
-void	    e_passwords_cancel (void);
-void        e_passwords_set_online (gint state);
-void        e_passwords_remember_password (const gchar *unused, const gchar *key);
-void        e_passwords_add_password      (const gchar *key, const gchar *passwd);
-gchar       *e_passwords_get_password      (const gchar *unused, const gchar *key);
-void        e_passwords_forget_password   (const gchar *unused, const gchar *key);
-void        e_passwords_forget_passwords  (void);
-void        e_passwords_clear_passwords (const gchar *unused);
+void		e_passwords_shutdown		(void);
+void		e_passwords_cancel		(void);
+void		e_passwords_set_online		(gint state);
+void		e_passwords_remember_password	(ESource *source);
+void		e_passwords_add_password	(ESource *source,
+						 const gchar *passwd);
+gchar *		e_passwords_get_password	(ESource *source);
+void		e_passwords_forget_password	(ESource *source);
+void		e_passwords_forget_passwords	(void);
 
 typedef enum {
 	E_PASSWORDS_REMEMBER_NEVER,
@@ -60,13 +61,13 @@ typedef enum {
 	E_PASSWORDS_PASSPHRASE = 1<<12 /* We are asking a passphrase */
 } EPasswordsRememberType;
 
-gchar *      e_passwords_ask_password      (const gchar *title,
-					   const gchar *unused, const gchar *key,
-					   const gchar *prompt,
-					   EPasswordsRememberType remember_type,
-					   gboolean *remember,
-					   GtkWindow *parent);
+gchar *		e_passwords_ask_password	(ESource *source,
+						 const gchar *title,
+						 const gchar *prompt,
+						 EPasswordsRememberType remember_type,
+						 gboolean *remember,
+						 GtkWindow *parent);
 
 G_END_DECLS
 
-#endif /* _E_PASSWORD_H_ */
+#endif /* E_PASSWORDS_H */



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