diff options
author | Gustavo Noronha Silva <gns@gnome.org> | 2009-12-15 23:17:54 +0800 |
---|---|---|
committer | Gustavo Noronha Silva <gns@gnome.org> | 2009-12-15 23:24:26 +0800 |
commit | 9d419181e0630431de079b777f1e537452fc69e4 (patch) | |
tree | 37b8dc477222282e151275a3829e864818dbb598 | |
parent | efb097c929407bb264b90d31feadac34c31a85e7 (diff) | |
download | gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar.gz gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar.bz2 gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar.lz gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar.xz gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.tar.zst gsoc2013-epiphany-9d419181e0630431de079b777f1e537452fc69e4.zip |
Add a new utility function to query the keyring for the form password
This is used to make all policy regarding what and how we save data be
in one place.
-rw-r--r-- | lib/ephy-profile-migration.c | 119 | ||||
-rw-r--r-- | lib/ephy-profile-migration.h | 11 |
2 files changed, 97 insertions, 33 deletions
diff --git a/lib/ephy-profile-migration.c b/lib/ephy-profile-migration.c index ee57aed89..b5a32f17f 100644 --- a/lib/ephy-profile-migration.c +++ b/lib/ephy-profile-migration.c @@ -33,6 +33,7 @@ #include "ephy-profile-migration.h" +#include "ephy-debug.h" #include "ephy-file-helpers.h" #ifdef ENABLE_NSS #include "ephy-nss-glue.h" @@ -425,6 +426,27 @@ store_form_password_cb (GnomeKeyringResult result, /* FIXME: should we do anything if the operation failed? */ } +static void +normalize_and_prepare_uri (SoupURI *uri, + const char *form_username, + const char *form_password) +{ + /* We normalize https? schemes here so that we use passwords + * we stored in https sites in their http counterparts, and + * vice-versa. */ + if (g_str_equal (uri->scheme, SOUP_URI_SCHEME_HTTPS)) + soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP); + + /* Store the form login and password names encoded in the + * URL. A bit of an abuse of keyring, but oh well */ + soup_uri_set_query_from_fields (uri, + FORM_USERNAME_KEY, + form_username, + FORM_PASSWORD_KEY, + form_password, + NULL); +} + void _ephy_profile_store_form_auth_data (const char *uri, const char *form_username, @@ -432,39 +454,70 @@ _ephy_profile_store_form_auth_data (const char *uri, const char *username, const char *password) { - SoupURI *fake_uri; - char *fake_uri_str; - - g_return_if_fail (uri); - g_return_if_fail (form_username); - g_return_if_fail (form_password); - g_return_if_fail (username); - g_return_if_fail (password); - - fake_uri = soup_uri_new (uri); - /* Store the form login and password names encoded in the - * URL. A bit of an abuse of keyring, but oh well */ - soup_uri_set_query_from_fields (fake_uri, - FORM_USERNAME_KEY, - form_username, - FORM_PASSWORD_KEY, - form_password, - NULL); - fake_uri_str = soup_uri_to_string (fake_uri, FALSE); - gnome_keyring_set_network_password (NULL, - username, - NULL, - fake_uri_str, - NULL, - fake_uri->scheme, - NULL, - fake_uri->port, - password, - (GnomeKeyringOperationGetIntCallback)store_form_password_cb, - NULL, - NULL); - soup_uri_free (fake_uri); - g_free (fake_uri_str); + SoupURI *fake_uri; + char *fake_uri_str; + + g_return_if_fail (uri); + g_return_if_fail (form_username); + g_return_if_fail (form_password); + g_return_if_fail (username); + g_return_if_fail (password); + + fake_uri = soup_uri_new (uri); + normalize_and_prepare_uri (fake_uri, form_username, form_password); + fake_uri_str = soup_uri_to_string (fake_uri, FALSE); + + gnome_keyring_set_network_password (NULL, + username, + NULL, + fake_uri_str, + NULL, + fake_uri->scheme, + NULL, + fake_uri->port, + password, + (GnomeKeyringOperationGetIntCallback)store_form_password_cb, + NULL, + NULL); + soup_uri_free (fake_uri); + g_free (fake_uri_str); +} + +GList* +_ephy_profile_query_form_auth_data (const char *uri, + const char *form_username, + const char *form_password, + GnomeKeyringOperationGetListCallback callback, + gpointer data, + GDestroyNotify destroy_data) +{ + SoupURI *key; + char *key_str; + GList *results = NULL; + + g_return_val_if_fail (uri, NULL); + g_return_val_if_fail (form_username, NULL); + g_return_val_if_fail (form_password, NULL); + + key = soup_uri_new (uri); + normalize_and_prepare_uri (key, form_username, form_password); + key_str = soup_uri_to_string (key, FALSE); + + LOG ("Querying Keyring: %s", key_str); + gnome_keyring_find_network_password (NULL, + NULL, + key_str, + NULL, + NULL, + NULL, + 0, + callback, + data, + destroy_data); + soup_uri_free (key); + g_free (key_str); + + return results; } #define PROFILE_MIGRATION_FILE ".migrated" diff --git a/lib/ephy-profile-migration.h b/lib/ephy-profile-migration.h index 7fe4945c7..33d14bf81 100644 --- a/lib/ephy-profile-migration.h +++ b/lib/ephy-profile-migration.h @@ -20,6 +20,9 @@ #ifndef EPHY_PROFILE_MIGRATION_H #define EPHY_PROFILE_MIGRATION_H +#include <glib.h> +#include <gnome-keyring.h> + #define FORM_USERNAME_KEY "form_username" #define FORM_PASSWORD_KEY "form_password" @@ -31,4 +34,12 @@ void _ephy_profile_store_form_auth_data (const char *uri, const char *username, const char *password); +GList* +_ephy_profile_query_form_auth_data (const char *uri, + const char *form_username, + const char *form_password, + GnomeKeyringOperationGetListCallback callback, + gpointer data, + GDestroyNotify destroy_data); + #endif |