libpurple/account.c

branch
soc.2008.masterpassword
changeset 33997
035d8594b66a
parent 33996
ca5e901a5311
child 33998
5fcfc69be362
--- a/libpurple/account.c	Sat Aug 16 06:07:22 2008 +0000
+++ b/libpurple/account.c	Sun Aug 17 01:28:28 2008 +0000
@@ -110,11 +110,11 @@
 
 static void purple_account_connect_got_password_cb(PurpleAccount * account,
        gchar * password, GError * error, gpointer data);
-static void request_password_ok_cb_continue(const PurpleAccount * account, 
-	GError * error,	gpointer data);
 
 static void purple_account_get_password_async_finish(PurpleAccount * account,
 	char * password, GError * error, gpointer data);
+
+static void purple_accounts_delete_finish(PurpleAccount * account, GError * error, gpointer data);
 /*********************************************************************
  * Writing to disk                                                   *
  *********************************************************************/
@@ -819,8 +819,8 @@
 	xmlnode *child;
 	char *protocol_id = NULL;
 	char *name = NULL;
-	char *keyring_id = NULL;
-	char *mode = NULL;
+	const char *keyring_id = NULL;
+	const char *mode = NULL;
 	char *data = NULL;
 	gboolean result = FALSE;
 	GError * error = NULL;
@@ -936,16 +936,11 @@
 
 		if (result == TRUE) {
 			purple_debug_info("accounts", "password imported successfully.\n");
-			purple_account_set_remember_password(ret, TRUE);
-			/*
-			g_free(keyring_id);	TODO :
-			g_free(mode);		This was commented becaus eof a double free.
-			g_free(data); 		I should figure out which one causes the bug to avoid leaks
-			*/
+			purple_account_set_remember_password(ret, TRUE);		
 		} else {
 			purple_debug_info("accounts", "failed to imported password.\n");
-			/* TODO handle error */
-		}
+		} 
+		g_free(data); 
 	}
 
 	return ret;
@@ -1118,28 +1113,26 @@
 {
 	g_return_if_fail(account != NULL);
 
-	/* FIXME : handle error properly */
- 
 	purple_connection_new(account, TRUE, password);
 }
 
-struct _unregister_data
+typedef struct
 {
 	PurpleAccountUnregistrationCb cb;
 	void *user_data;
-};
+} UnregisterData;
 
 void
 purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data)
 {
-	struct _unregister_data * data;
+	UnregisterData * data;
 
 	g_return_if_fail(account != NULL);
 
 	purple_debug_info("account", "Unregistering account %s\n",
 					  purple_account_get_username(account));
 
-	data = g_malloc(sizeof(struct _unregister_data));
+	data = g_new0(UnregisterData, 1);
 	data->cb = cb;
 	data->user_data = user_data;
 
@@ -1150,21 +1143,25 @@
 static void
 purple_account_unregister_got_password_cb(PurpleAccount * account, char * password, GError * error, gpointer data)
 {
-	struct _unregister_data * unregdata;
-
+	UnregisterData * unregdata;
+	
 	g_return_if_fail(account != NULL);
 
 	/* FIXME : handle error properly */
 
 	unregdata = data;
+	g_return_if_fail(unregdata != NULL);
+
 	purple_connection_new_unregister(account, password, unregdata->cb, unregdata->user_data);
+
+	g_free(unregdata);
 }
 
-
 static void
 request_password_ok_cb(PurpleAccount *account, PurpleRequestFields *fields)
 {
 	const char *entry;
+	char * password;
 	gboolean remember;
 
 	entry = purple_request_fields_get_string(fields, "password");
@@ -1181,23 +1178,14 @@
 
 	purple_account_set_remember_password(account, remember);
 
-	purple_account_set_password(account, entry);
+	password = g_strdup(entry);
+	purple_account_set_password(account, password);
+	g_free(password);
 	purple_connection_new(account, FALSE, entry);
 
 }
 
 static void
-request_password_ok_cb_continue(const PurpleAccount * account, 
-				GError * error,
-				gpointer data)
-{
-	char * password = data;
-
-	purple_connection_new(account, FALSE, password);
-	g_free(password);
-}
-
-static void
 request_password_cancel_cb(PurpleAccount *account, PurpleRequestFields *fields)
 {
 	/* Disable the account as the user has canceled connecting */
@@ -1251,7 +1239,6 @@
 {
 	PurplePlugin *prpl;
 	PurplePluginProtocolInfo *prpl_info;
-	const char *password;
 
 	g_return_if_fail(account != NULL);
 
@@ -1632,7 +1619,7 @@
 }
 
 void
-purple_account_set_password(PurpleAccount *account, const char *password)
+purple_account_set_password(PurpleAccount *account, char *password)
 {
 	schedule_accounts_save();
 
@@ -1644,7 +1631,7 @@
 	account->password = g_strdup(password);
 
 	if (purple_account_get_remember_password(account) == TRUE)
-		purple_keyring_set_password_sync(account, password);
+		purple_keyring_set_password_async(account, password, NULL, NULL, NULL);
 }
 
 void 
@@ -1658,30 +1645,28 @@
 	 * This is so we can force an account sync by calling
 	 * it with account == NULL.
 	 */
-	if(account != NULL) {
-
-		if (account->password != NULL)
-			g_free(account->password);
+	schedule_accounts_save();
+
+	g_return_if_fail(account != NULL);
+
+	if (account->password != NULL)
+		g_free(account->password);
+	account->password = g_strdup(password);
+
+	if (purple_account_get_remember_password(account) == FALSE) {
+
 		account->password = g_strdup(password);
-
-		if (purple_account_get_remember_password(account) == FALSE) {
-
-			account->password = g_strdup(password);
-			purple_debug_info("account",
-				"Password for %s set, not sent to keyring.\n",
-				purple_account_get_username(account));
-
-			if (cb != NULL)
-				cb(account, NULL, data);
-
-		} else {
-
-			purple_keyring_set_password_async(account, password,
-				destroypassword, cb, data);
-
-		}
+		purple_debug_info("account",
+			"Password for %s set, not sent to keyring.\n",
+			purple_account_get_username(account));
+
+		if (cb != NULL)
+			cb(account, NULL, data);
+
+	} else {
+		purple_keyring_set_password_async(account, password,
+			destroypassword, cb, data);
 	}
-	schedule_accounts_save();
 }
 void
 purple_account_set_alias(PurpleAccount *account, const char *alias)
@@ -2103,12 +2088,15 @@
 				  PurpleKeyringReadCallback cb,
 				  gpointer data)
 {
-	char * password;
-
 	CbInfo * info = g_new0(CbInfo,1);
 	info->cb = cb;
 	info->data = data;
 
+	if(account == NULL) {
+		cb(NULL, NULL, NULL, data);
+		return;
+	}
+
 	if (account->password != NULL) {
 		purple_debug_info("accounts",
 			"Reading password for account %s (%s) from cached (async).\n",
@@ -2122,7 +2110,7 @@
 			purple_account_get_username(account),
 			purple_account_get_protocol_id(account));
 		purple_keyring_get_password_async(account, 
-			purple_account_get_password_async_finish, data);
+			purple_account_get_password_async_finish, info);
 	}
 }
 
@@ -2135,6 +2123,8 @@
 	CbInfo * info;
 	PurpleKeyringReadCallback cb;
 
+	
+
 	purple_debug_info("accounts",
 		"Read password for account %s (%s) from async keyring.\n",
 		purple_account_get_username(account),
@@ -2143,10 +2133,10 @@
 	info = data;
 
 	g_return_if_fail(account != NULL);
+	g_free(account->password);
+	account->password = g_strdup(password);
 	g_return_if_fail(info != NULL);
 
-	account->password = g_strdup(password);
-
 	cb = info->cb;
 	if (cb != NULL)
 		cb(account, password, error, info->data);
@@ -2803,7 +2793,18 @@
 	/* This will cause the deletion of an old buddy icon. */
 	purple_buddy_icons_set_account_icon(account, NULL, 0);
 
-	purple_account_destroy(account);
+	/* this is async because we do not want the
+	 * account overwritten before we are done.
+	 */
+	purple_keyring_set_password_async(account, NULL, NULL, 
+		purple_accounts_delete_finish, NULL);
+
+}
+
+static void
+purple_accounts_delete_finish(PurpleAccount * account, GError * error, gpointer data)
+{
+		purple_account_destroy(account);
 }
 
 void

mercurial