soc.2008.masterpassword: 301e7684: Added support for master password in pid...
scrouaf at soc.pidgin.im
scrouaf at soc.pidgin.im
Sun Aug 17 02:11:04 EDT 2008
-----------------------------------------------------------------
Revision: 301e7684c9c6f66509bab94dd1ec79a064649151
Ancestor: db9aa84228006c5777c2e8469198955bd0c3c231
Author: scrouaf at soc.pidgin.im
Date: 2008-08-17T06:07:02
Branch: im.pidgin.soc.2008.masterpassword
URL: http://d.pidgin.im/viewmtn/revision/info/301e7684c9c6f66509bab94dd1ec79a064649151
Modified files:
finch/gntaccount.c libpurple/account.c libpurple/account.h
libpurple/connection.c libpurple/connection.h
libpurple/keyring.c libpurple/keyring.h
libpurple/plugins/keyrings/gnomekeyring.c
libpurple/plugins/keyrings/internalkeyring.c
pidgin/gtkaccount.c pidgin/gtkprefs.c
ChangeLog:
Added support for master password in pidgin's pref interface.
Set strings as translatable.
Corrected a few bugs.
Removed dead code.
-------------- next part --------------
============================================================
--- finch/gntaccount.c db9f6a557df501b32bf6e187bc68b4c7821ba5d9
+++ finch/gntaccount.c 85b3c758ca6c6b23e7258f8c3cfa1cfe61909091
@@ -58,9 +58,6 @@ static FinchAccountList accounts;
static FinchAccountList accounts;
-static void edit_account_continue(PurpleAccount * account,
- const gchar * password, GError * error, gpointer user_data);
-
typedef struct
{
PurpleAccount *account; /* NULL for a new account */
@@ -86,6 +83,10 @@ static GList *accountdialogs;
/* This is necessary to close an edit-dialog when an account is deleted */
static GList *accountdialogs;
+
+static void edit_account_continue(PurpleAccount * account,
+ gchar * password, GError * error, gpointer user_data);
+
static void
account_add(PurpleAccount *account)
{
@@ -492,7 +493,7 @@ edit_account_continue(PurpleAccount * ac
static void
edit_account_continue(PurpleAccount * account,
- const gchar * password, GError * error, gpointer user_data)
+ gchar * password, GError * error, gpointer user_data)
{
GntWidget *window, *hbox;
GntWidget *combo, *button, *entry;
============================================================
--- libpurple/account.c f3e650479b9aa90305308bfa2355de9e3500eddd
+++ libpurple/account.c 1948f698f064ab12cd62167d6d481c38d1fd3ae8
@@ -222,8 +222,7 @@ status_attr_to_xmlnode(const PurpleStatu
gboolean boolean_value = purple_value_get_boolean(attr_value);
if (boolean_value == purple_value_get_boolean(default_value))
return NULL;
- value = g_strdup(boolean_value ?
- "true" : "false");
+ value = g_strdup(boolean_value ? "true" : "false");
}
else
{
@@ -1147,8 +1146,6 @@ purple_account_unregister_got_password_c
g_return_if_fail(account != NULL);
- /* FIXME : handle error properly */
-
unregdata = data;
g_return_if_fail(unregdata != NULL);
@@ -1298,12 +1295,6 @@ purple_account_disconnect(PurpleAccount
gc = purple_account_get_connection(account);
purple_connection_destroy(gc);
-/* FIXME : if this works, remove the commented code. */
-#if 0
- if (!purple_account_get_remember_password(account))
- purple_account_set_password_async(account, NULL, NULL, NULL, NULL);
-
-#endif
purple_account_set_connection(account, NULL);
account->disconnecting = FALSE;
}
@@ -1735,10 +1726,6 @@ purple_account_set_connection(PurpleAcco
account->gc = gc;
}
-/**
- * FIXME :
- * This should be async
- */
void
purple_account_set_remember_password(PurpleAccount *account, gboolean value)
{
============================================================
--- libpurple/account.h fbac72f02a9e773c9275f7fb8871b017c163fefd
+++ libpurple/account.h 085ec64844db2c06663d15219e556863f05db3bf
@@ -328,7 +328,7 @@ void purple_account_set_username(PurpleA
* @param account The account.
* @param password The password.
*/
-void purple_account_set_password(PurpleAccount *account, char *password) __attribute__ ((deprecated));
+void purple_account_set_password(PurpleAccount *account, char *password);
/**
* Set a password to be remembered.
@@ -572,7 +572,7 @@ const char *purple_account_get_username(
*
* @return The password.
*/
-const char *purple_account_get_password(PurpleAccount *account) __attribute__ ((deprecated));
+const char *purple_account_get_password(PurpleAccount *account);
/**
* Reads the password for the account and passes it to the callback
============================================================
--- libpurple/connection.c a1835ad0d55af9951fc9aa8b592f46777abf3898
+++ libpurple/connection.c 35b742592c0c80b40501ee6c1373f35bcc9ab821
@@ -39,8 +39,6 @@
#include "util.h"
#define KEEPALIVE_INTERVAL 30
-static void purple_connection_disconnect_got_pw_cb(PurpleAccount * account,
- gchar * password, GError * error, gpointer data);
static GList *connections = NULL;
static GList *connections_connecting = NULL;
@@ -452,22 +450,6 @@ purple_connection_get_password(const Pur
}
}
-void
-purple_connection_get_password_async(PurpleConnection *gc,
- PurpleKeyringReadCallback cb,
- gpointer data)
-{
- char * password;
- g_return_if_fail(gc != NULL);
-
- if (gc->password != NULL) {
- /* casted to prevent warning */
- cb((PurpleAccount *)gc, gc->password, NULL, data);
- } else {
- purple_account_get_password_async(gc->account, cb, gc);
- }
-}
-
const char *
purple_connection_get_display_name(const PurpleConnection *gc)
{
============================================================
--- libpurple/connection.h 9cbb0460921eba42411d0987d9ed4be8177a2a14
+++ libpurple/connection.h ba7d8172045ceec6f9186bb9ee481d4fe797796b
@@ -398,19 +398,9 @@ PurplePlugin * purple_connection_get_prp
*
* @return The connection's password.
*/
-const char *purple_connection_get_password(const PurpleConnection *gc) __attribute__ ((deprecated));
+const char *purple_connection_get_password(const PurpleConnection *gc);
/**
- * Passes the connection's keyring to the callback.
- *
- * @param gc The connection.
- * @param cb The callback to pass the password to.
- * @param data A pointer passed to the callback.
- */
-void
-purple_connection_get_password_async(PurpleConnection *gc,
- PurpleKeyringReadCallback cb, gpointer data);
-/**
* Returns the connection's displayed name.
*
* @param gc The connection.
============================================================
--- libpurple/keyring.c 156b33dcbfc3c0d5c5887deb7b8003b29e5ba7fd
+++ libpurple/keyring.c b0ef204e4a9c3a70fb1cfe46623c6f909a5edc03
@@ -33,6 +33,7 @@
#include "signals.h"
#include "core.h"
#include "debug.h"
+#include "internal.h"
typedef struct _PurpleKeyringCbInfo PurpleKeyringCbInfo;
typedef struct _PurpleKeyringChangeTracker PurpleKeyringChangeTracker;
@@ -471,9 +472,9 @@ purple_keyring_set_inuse_check_error_cb(
purple_debug_info("keyring",
"Failed to change keyring, aborting");
- /**
- * FIXME : call purple_notify()
- */
+ purple_notify_error(NULL, _("Keyrings"), _("Failed to change the keyring."),
+ _("Aborting changes."));
+ purple_keyring_inuse = tracker->old;
purple_prefs_disconnect_callback(purple_keyring_pref_cb_id);
purple_prefs_set_string("/purple/keyring/active",
purple_keyring_get_id(tracker->old));
@@ -486,7 +487,6 @@ purple_keyring_set_inuse_check_error_cb(
if (close != NULL)
close(&error);
- purple_keyring_inuse = tracker->new;
purple_keyring_drop_passwords(tracker->old);
purple_debug_info("keyring",
@@ -579,7 +579,6 @@ purple_keyring_set_inuse(const PurpleKey
PurpleKeyringRead read = NULL;
PurpleKeyringClose close;
PurpleKeyringChangeTracker * tracker;
- GError * error = NULL;
if (newkeyring != NULL)
purple_debug_info("keyring", "Attempting to set new keyring : %s.\n",
@@ -616,6 +615,8 @@ purple_keyring_set_inuse(const PurpleKey
tracker = g_malloc(sizeof(PurpleKeyringChangeTracker));
oldkeyring = purple_keyring_get_inuse();
+ purple_keyring_inuse = newkeyring;
+
tracker->cb = cb;
tracker->data = data;
tracker->new = newkeyring;
@@ -964,7 +965,7 @@ void
* to 3.0, while dropping purple_keyring_set_password_sync().
*/
void
-purple_keyring_set_password_async(const PurpleAccount * account,
+purple_keyring_set_password_async(PurpleAccount * account,
gchar * password,
GDestroyNotify destroypassword,
PurpleKeyringSaveCallback cb,
@@ -1010,14 +1011,19 @@ purple_keyring_set_password_async_cb(Pur
GError * error,
gpointer data)
{
+ PurpleKeyringCbInfo * cbinfo;
+ PurpleKeyringSaveCallback cb;
+
g_return_if_fail(data != NULL);
g_return_if_fail(account != NULL);
- PurpleKeyringCbInfo * cbinfo = data;
- PurpleKeyringSaveCallback cb = cbinfo->cb;
+ cbinfo = data;
+ cb = cbinfo->cb;
if (error != NULL) {
- /* FIXME : purple_notify_warning() */
+ purple_notify_error(NULL, _("Keyrings"),
+ _("Failed to save password in keyring.")
+ error->message);
}
if (cb != NULL)
@@ -1129,9 +1135,8 @@ purple_keyring_change_master(PurpleKeyri
if (inuse == NULL) {
error = g_error_new(ERR_PIDGINKEYRING, ERR_NOCAP,
"Keyring doesn't support master passwords.");
-
- cb(FALSE, error, data);
-
+ if (cb)
+ cb(FALSE, error, data);
g_error_free(error);
} else {
@@ -1141,9 +1146,9 @@ purple_keyring_change_master(PurpleKeyri
if (change == NULL) {
error = g_error_new(ERR_PIDGINKEYRING, ERR_NOCAP,
"Keyring doesn't support master passwords.");
+ if (cb)
+ cb(FALSE, error, data);
- cb(FALSE, error, data);
-
g_error_free(error);
} else {
@@ -1164,7 +1169,7 @@ GQuark purple_keyring_error_domain(void)
GQuark purple_keyring_error_domain(void)
{
- return g_quark_from_static_string("Libpurple keyring");
+ return g_quark_from_static_string("libpurple keyring");
}
/*}@*/
============================================================
--- libpurple/keyring.h 291fa07f017f9f51ee37158cd0ec29133629dce4
+++ libpurple/keyring.h 83fb87d62413b4a350765e22d444cc844fbcee4d
@@ -79,7 +79,7 @@ typedef void (*PurpleKeyringReadCallback
* @param account The account of which the password was saved.
* @param data Data passed to the callback.
*/
-typedef void (*PurpleKeyringSaveCallback)(const PurpleAccount * account,
+typedef void (*PurpleKeyringSaveCallback)(PurpleAccount * account,
GError * error,
gpointer data);
@@ -349,7 +349,7 @@ void
* @param data A pointer to be passed to the callback.
*/
void
-purple_keyring_set_password_async(const PurpleAccount * account,
+purple_keyring_set_password_async(PurpleAccount * account,
gchar * password,
GDestroyNotify destroypassword,
PurpleKeyringSaveCallback cb,
============================================================
--- libpurple/plugins/keyrings/gnomekeyring.c 7f9f6f7cc2c008611a362eefd9df1c2c3c66d840
+++ libpurple/plugins/keyrings/gnomekeyring.c 9243e0da1c359b64c55b8b4a70665ba20e02edd5
@@ -54,12 +54,13 @@
#include "keyring.h"
#include "debug.h"
#include "plugin.h"
+#include "internal.h"
-#define GNOMEKEYRING_NAME "Gnome-Keyring"
-#define GNOMEKEYRING_VERSION "0.2"
-#define GNOMEKEYRING_DESCRIPTION "This plugin provides the default password storage behaviour for libpurple."
+#define GNOMEKEYRING_NAME N_("Gnome-Keyring")
+#define GNOMEKEYRING_VERSION "0.3b"
+#define GNOMEKEYRING_DESCRIPTION N_("This plugin will store passwords in Gnome-Keyring.")
#define GNOMEKEYRING_AUTHOR "Scrouaf (scrouaf[at]soc.pidgin.im)"
-#define GNOMEKEYRING_ID "core-scrouaf-gnomekeyring"
+#define GNOMEKEYRING_ID "core-scrouaf-gnomekeyring"
#define ERR_GNOMEKEYRINGPLUGIN gkp_error_domain()
@@ -75,9 +76,6 @@ struct _InfoStorage
char * name;
};
-
-
-
/* a few prototypes : */
static GQuark gkp_error_domain(void);
static void gkp_read(PurpleAccount *, PurpleKeyringReadCallback, gpointer);
@@ -95,6 +93,8 @@ static void gkp_destroy(PurplePlugin *)
static gboolean gkp_unload(PurplePlugin *);
static void gkp_destroy(PurplePlugin *);
+static void gkp_change_master(PurpleKeyringChangeMasterCallback cb, gpointer data);
+
GQuark gkp_error_domain(void)
{
return g_quark_from_static_string("Gnome-Keyring plugin");
@@ -187,7 +187,6 @@ gkp_save(PurpleAccount * account,
PurpleKeyringSaveCallback cb,
gpointer data)
{
- /* FIXME : the name will leak */
InfoStorage * storage = g_new0(InfoStorage,1);
storage->account = account;
@@ -404,9 +403,20 @@ gkp_export_password(PurpleAccount * acco
return TRUE;
}
+/* this was written just to test the pref change */
+static void
+gkp_change_master(PurpleKeyringChangeMasterCallback cb, gpointer data)
+{
+ purple_debug_info("Gnome-Keyring plugin",
+ "This keyring does not support master passwords.\n");
+ purple_notify_info(NULL, _("Gnome-Keyring plugin"),
+ _("Failed to change master password."),
+ _("This plugin does not really support master passwords, it just pretends to."));
+ if(cb)
+ cb(FALSE, NULL, data);
+}
-
static gboolean
gkp_init()
{
@@ -423,7 +433,7 @@ gkp_init()
purple_keyring_set_read_password(keyring_handler, gkp_read);
purple_keyring_set_save_password(keyring_handler, gkp_save);
purple_keyring_set_close_keyring(keyring_handler, gkp_close);
- purple_keyring_set_change_master(keyring_handler, NULL);
+ purple_keyring_set_change_master(keyring_handler, gkp_change_master);
purple_keyring_set_import_password(keyring_handler, gkp_import_password);
purple_keyring_set_export_password(keyring_handler, gkp_export_password);
============================================================
--- libpurple/plugins/keyrings/internalkeyring.c 66aaf2d96c9b726e0bcb68d13bda37a8053fe1a9
+++ libpurple/plugins/keyrings/internalkeyring.c c9c9d27e5b6608a09d11f40795b01e12eed314f2
@@ -50,10 +50,11 @@
#include "keyring.h"
#include "debug.h"
#include "plugin.h"
+#include "internal.h"
-#define INTERNALKEYRING_NAME "Internal keyring"
-#define INTERNALKEYRING_VERSION "0.7"
-#define INTERNALKEYRING_DESCRIPTION "This plugin provides the default password storage behaviour for libpurple."
+#define INTERNALKEYRING_NAME N_("Internal keyring")
+#define INTERNALKEYRING_VERSION "0.8b"
+#define INTERNALKEYRING_DESCRIPTION N_("This plugin provides the default password storage behaviour for libpurple. Password will be stored unencrypted.")
#define INTERNALKEYRING_AUTHOR "Scrouaf (scrouaf[at]soc.pidgin.im)"
#define INTERNALKEYRING_ID FALLBACK_KEYRING
============================================================
--- pidgin/gtkaccount.c f268cd6fe62a189495bb33bd53e76882072925b0
+++ pidgin/gtkaccount.c 6cd7c497ca7dc7b107dcf1b2970c9685777102f5
@@ -1189,6 +1189,7 @@ ok_account_prefs_cb(GtkWidget *w, Accoun
gboolean new_acct = FALSE, icon_change = FALSE;
PurpleAccount *account;
gboolean remember;
+ char * copy;
/* Build the username string. */
username = g_strdup(gtk_entry_get_text(GTK_ENTRY(dialog->screenname_entry)));
@@ -1315,12 +1316,14 @@ ok_account_prefs_cb(GtkWidget *w, Accoun
* the account editor (but has not checked the 'save' box), then we
* don't want to prompt them.
*/
- if ((purple_account_get_remember_password(account) || new_acct) && (*value != '\0'))
+ if ((purple_account_get_remember_password(account) || new_acct) && (*value != '\0')) {
+ copy = g_strdup(value);
purple_account_set_password(account, value);
- else
+ g_free(value);
+ } else {
purple_account_set_password(account, NULL);
+ }
-
purple_account_set_username(account, username);
g_free(username);
============================================================
--- pidgin/gtkprefs.c cf2f94bbb38876801c5be326e4d8bf987b901fd0
+++ pidgin/gtkprefs.c c60ca6d9c030bed077735d3318093cb779bbbe4c
@@ -1632,34 +1632,76 @@ logging_page(void)
return ret;
}
+static void
+change_master_password_cb(GtkWidget * button, gpointer ptr)
+{
+ purple_keyring_change_master(NULL, NULL);
+}
+static void
+keyring_page_pref_changed(const char *name, PurplePrefType type, gconstpointer val, gpointer data)
+{
+ GtkWidget * button = data;
+ PurpleKeyring * keyring;
+
+ g_return_if_fail(type == PURPLE_PREF_STRING);
+ g_return_if_fail(g_strcmp0(val,"/purple/keyring/active") == 0);
+
+ /**
+ * This part is annoying.
+ * Since we do not know if purple_keyring_inuse was changed yet,
+ * as we do not know the order the callbacks are called in, we
+ * have to rely on the prefs system, and find the keyring that
+ * is (or will be) used, from there.
+ */
+ keyring = purple_keyring_get_keyring_by_id(val);
+
+ if (purple_keyring_get_change_master(keyring))
+ gtk_widget_set_sensitive(button,TRUE);
+ else
+ gtk_widget_set_sensitive(button,FALSE);
+}
+
+
static GtkWidget *
keyring_page(void)
{
GtkWidget *ret;
GtkWidget *vbox;
- GtkWidget *menu;
- GtkWidget *changemaster;
+ GtkWidget * button;
GList *names;
+ void * prefs;
+ const char * keyring_id;
+ PurpleKeyring * keyring;
+ keyring_id = purple_prefs_get_string("/purple/keyring/active");
+ keyring = purple_keyring_get_keyring_by_id(keyring_id);
- purple_debug_info("prefs", "drawing keyring prefs page.\n");
+ prefs = purple_prefs_get_handle();
+
ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE);
gtk_container_set_border_width (GTK_CONTAINER (ret), PIDGIN_HIG_BORDER);
-
+ /* Keyring selection */
vbox = pidgin_make_frame (ret, _("Keyring"));
-
names = purple_keyring_get_options();
-
- pidgin_prefs_dropdown_from_list(vbox, _("Keyring"), PURPLE_PREF_STRING,
+ pidgin_prefs_dropdown_from_list(vbox, _("Keyring :"), PURPLE_PREF_STRING,
"/purple/keyring/active", names);
-
g_list_free(names);
+ /* Change master password */
+ button = gtk_button_new_with_mnemonic(_("_Change master password."));
+
+ g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(change_master_password_cb), NULL);
+ purple_prefs_connect_callback (prefs, "/purple/keyring/active", keyring_page_pref_changed, button);
- gtk_widget_show_all(ret);
+ if (purple_keyring_get_change_master(keyring))
+ gtk_widget_set_sensitive(button,TRUE);
+ else
+ gtk_widget_set_sensitive(button,FALSE);
+ gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 1);
+ gtk_widget_show_all(ret);
return ret;
}
More information about the Commits
mailing list