/cpw/tomkiewicz/masterpassword: 0680f2c10db3: Validation for int...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat May 11 11:19:01 EDT 2013


Changeset: 0680f2c10db3c658249d91c74a9e0aee97f8ef8e
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-05-11 17:18 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/0680f2c10db3

Description:

Validation for internal keyring settings

diffstat:

 libpurple/keyring.c                          |   4 +-
 libpurple/keyring.h                          |   5 ++-
 libpurple/plugins/keyrings/internalkeyring.c |  35 ++++++++++++++++++++++++----
 pidgin/gtkprefs.c                            |   4 ++-
 4 files changed, 38 insertions(+), 10 deletions(-)

diffs (124 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -922,7 +922,7 @@ purple_keyring_read_settings(void)
 }
 
 gboolean
-purple_keyring_apply_settings(PurpleRequestFields *fields)
+purple_keyring_apply_settings(void *notify_handle, PurpleRequestFields *fields)
 {
 	PurpleKeyring *inuse;
 	PurpleKeyringApplySettings apply_settings;
@@ -947,7 +947,7 @@ purple_keyring_apply_settings(PurpleRequ
 			"supported.\n");
 		return FALSE;
 	}
-	return apply_settings(fields);
+	return apply_settings(notify_handle, fields);
 }
 
 /**************************************************************************/
diff --git a/libpurple/keyring.h b/libpurple/keyring.h
--- a/libpurple/keyring.h
+++ b/libpurple/keyring.h
@@ -175,7 +175,8 @@ typedef gboolean (*PurpleKeyringExportPa
 typedef PurpleRequestFields * (*PurpleKeyringReadSettings)(void);
 
 /* TODO: documentation */
-typedef gboolean (*PurpleKeyringApplySettings)(PurpleRequestFields *fields);
+typedef gboolean (*PurpleKeyringApplySettings)(void *notify_handle,
+	PurpleRequestFields *fields);
 
 /*@}*/
 
@@ -323,7 +324,7 @@ purple_keyring_read_settings(void);
 
 /* TODO: documentation */
 gboolean
-purple_keyring_apply_settings(PurpleRequestFields *fields);
+purple_keyring_apply_settings(void *notify_handle, PurpleRequestFields *fields);
 
 /*@}*/
 
diff --git a/libpurple/plugins/keyrings/internalkeyring.c b/libpurple/plugins/keyrings/internalkeyring.c
--- a/libpurple/plugins/keyrings/internalkeyring.c
+++ b/libpurple/plugins/keyrings/internalkeyring.c
@@ -192,17 +192,17 @@ internal_keyring_read_settings(void)
 	group = purple_request_field_group_new(NULL);
 	purple_request_fields_add_group(fields, group);
 
-	field = purple_request_field_bool_new("encrypt", "Use encryption", FALSE);
+	field = purple_request_field_bool_new("encrypt", _("Encrypt passwords"), FALSE);
 	purple_request_field_group_add_field(group, field);
 
-	group = purple_request_field_group_new("Master password");
+	group = purple_request_field_group_new(_("Master password"));
 	purple_request_fields_add_group(fields, group);
 
-	field = purple_request_field_string_new("passphrase1", "New passphrase:", "", FALSE);
+	field = purple_request_field_string_new("passphrase1", _("New passphrase:"), "", FALSE);
 	purple_request_field_string_set_masked(field, TRUE);
 	purple_request_field_group_add_field(group, field);
 
-	field = purple_request_field_string_new("passphrase2", "Re-enter passphrase:", "", FALSE);
+	field = purple_request_field_string_new("passphrase2", _("New passphrase (again):"), "", FALSE);
 	purple_request_field_string_set_masked(field, TRUE);
 	purple_request_field_group_add_field(group, field);
 
@@ -210,8 +210,33 @@ internal_keyring_read_settings(void)
 }
 
 static gboolean
-internal_keyring_apply_settings(PurpleRequestFields *fields)
+internal_keyring_apply_settings(void *notify_handle,
+	PurpleRequestFields *fields)
 {
+	const gchar *passphrase, *passphrase2;
+
+	passphrase = purple_request_fields_get_string(fields, "passphrase1");
+	if (g_strcmp0(passphrase, "") == 0)
+		passphrase = NULL;
+	passphrase2 = purple_request_fields_get_string(fields, "passphrase2");
+	if (g_strcmp0(passphrase2, "") == 0)
+		passphrase2 = NULL;
+
+	if (g_strcmp0(passphrase, passphrase2) != 0) {
+		purple_notify_error(notify_handle,
+			_("Internal keyring settings"),
+			_("Passphrases do not match"), NULL);
+		return FALSE;
+	}
+
+	if (purple_request_fields_get_bool(fields, "encrypt") && !passphrase) {
+		purple_notify_error(notify_handle,
+			_("Internal keyring settings"),
+			_("You have to set up a Master password, if you want "
+			"to enable encryption"), NULL);
+		return FALSE;
+	}
+
 	return TRUE;
 }
 
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -533,6 +533,8 @@ delete_prefs(GtkWidget *asdf, void *gdsa
 	/* Close any "select sound" request dialogs */
 	purple_request_close_with_handle(prefs);
 
+	purple_notify_close_with_handle(prefs);
+
 	/* Unregister callbacks. */
 	purple_prefs_disconnect_by_handle(prefs);
 
@@ -2750,7 +2752,7 @@ keyring_page_add_settings(PurpleRequestF
 static void
 keyring_page_settings_apply(GtkButton *button, gpointer _unused)
 {
-	if (!purple_keyring_apply_settings(keyring_settings))
+	if (!purple_keyring_apply_settings(prefs, keyring_settings))
 		return;
 
 	gtk_widget_set_sensitive(keyring_apply, FALSE);



More information about the Commits mailing list