| 379 const char *keyring_id; |
379 const char *keyring_id; |
| 380 const char *mode; |
380 const char *mode; |
| 381 char *data; |
381 char *data; |
| 382 PurplePresence *presence; |
382 PurplePresence *presence; |
| 383 PurpleProxyInfo *proxy_info; |
383 PurpleProxyInfo *proxy_info; |
| 384 GError * error; |
384 GError * error = NULL; |
| 385 GDestroyNotify destroy; |
385 GDestroyNotify destroy; |
| 386 |
386 |
| 387 node = xmlnode_new("account"); |
387 node = xmlnode_new("account"); |
| 388 |
388 |
| 389 child = xmlnode_new_child(node, "protocol"); |
389 child = xmlnode_new_child(node, "protocol"); |
| 392 child = xmlnode_new_child(node, "name"); |
392 child = xmlnode_new_child(node, "name"); |
| 393 xmlnode_insert_data(child, purple_account_get_username(account), -1); |
393 xmlnode_insert_data(child, purple_account_get_username(account), -1); |
| 394 |
394 |
| 395 if (purple_account_get_remember_password(account)) |
395 if (purple_account_get_remember_password(account)) |
| 396 { |
396 { |
| 397 purple_debug_info("accounts", "Exporting password.\n"); |
397 purple_debug_info("accounts", "Exporting password for account %s.\n", |
| |
398 purple_account_get_username(account)); |
| 398 purple_keyring_export_password(account, &keyring_id, |
399 purple_keyring_export_password(account, &keyring_id, |
| 399 &mode, &data, &error, &destroy); |
400 &mode, &data, &error, &destroy); |
| 400 |
401 |
| 401 if (error != NULL) { |
402 if (error != NULL) { |
| 402 |
403 |
| 403 /* Output debug info */ |
404 purple_debug_info("accounts", |
| |
405 "failed to export password for account %s : %s.\n", |
| |
406 purple_account_get_username(account), |
| |
407 error->message); |
| 404 |
408 |
| 405 } else { |
409 } else { |
| 406 |
410 |
| 407 child = xmlnode_new_child(node, "password"); |
411 child = xmlnode_new_child(node, "password"); |
| 408 xmlnode_set_attrib(child, "keyringid", keyring_id); |
412 xmlnode_set_attrib(child, "keyring_id", keyring_id); |
| 409 xmlnode_set_attrib(child, "mode", mode); |
413 xmlnode_set_attrib(child, "mode", mode); |
| 410 xmlnode_insert_data(child, data, -1); |
414 xmlnode_insert_data(child, data, -1); |
| 411 |
415 |
| 412 if (destroy != NULL) |
416 if (destroy != NULL) |
| 413 destroy(data); |
417 destroy(data); |
| 484 { |
488 { |
| 485 purple_debug_error("account", "Attempted to save accounts before " |
489 purple_debug_error("account", "Attempted to save accounts before " |
| 486 "they were read!\n"); |
490 "they were read!\n"); |
| 487 return; |
491 return; |
| 488 } |
492 } |
| |
493 |
| |
494 purple_debug_info("account", "Syncing accounts.\n"); |
| 489 |
495 |
| 490 node = accounts_to_xmlnode(); |
496 node = accounts_to_xmlnode(); |
| 491 data = xmlnode_to_formatted_str(node, NULL); |
497 data = xmlnode_to_formatted_str(node, NULL); |
| 492 purple_util_write_data_to_file("accounts.xml", data, -1); |
498 purple_util_write_data_to_file("accounts.xml", data, -1); |
| 493 g_free(data); |
499 g_free(data); |
| 802 char *protocol_id = NULL; |
808 char *protocol_id = NULL; |
| 803 char *name = NULL; |
809 char *name = NULL; |
| 804 const char *keyring_id = NULL; |
810 const char *keyring_id = NULL; |
| 805 const char *mode = NULL; |
811 const char *mode = NULL; |
| 806 char *data = NULL; |
812 char *data = NULL; |
| 807 gboolean result; |
813 gboolean result = FALSE; |
| 808 GError * error = NULL; |
814 GError * error = NULL; |
| 809 |
815 |
| 810 child = xmlnode_get_child(node, "protocol"); |
816 child = xmlnode_get_child(node, "protocol"); |
| 811 if (child != NULL) |
817 if (child != NULL) |
| 812 protocol_id = xmlnode_get_data(child); |
818 protocol_id = xmlnode_get_data(child); |
| 904 { |
910 { |
| 905 parse_current_error(child, ret); |
911 parse_current_error(child, ret); |
| 906 } |
912 } |
| 907 |
913 |
| 908 /* Read the password */ |
914 /* Read the password */ |
| |
915 |
| 909 child = xmlnode_get_child(node, "password"); |
916 child = xmlnode_get_child(node, "password"); |
| 910 if (child != NULL) |
917 if (child != NULL) |
| 911 { |
918 { |
| 912 keyring_id = xmlnode_get_attrib(child, "keyring_id"); |
919 keyring_id = xmlnode_get_attrib(child, "keyring_id"); |
| 913 mode = xmlnode_get_attrib(child, "mode"); |
920 mode = xmlnode_get_attrib(child, "mode"); |
| 916 result = purple_keyring_import_password(ret, keyring_id, mode, data, &error); |
923 result = purple_keyring_import_password(ret, keyring_id, mode, data, &error); |
| 917 |
924 |
| 918 if (result == TRUE) { |
925 if (result == TRUE) { |
| 919 purple_debug_info("accounts", "password imported successfully.\n"); |
926 purple_debug_info("accounts", "password imported successfully.\n"); |
| 920 purple_account_set_remember_password(ret, TRUE); |
927 purple_account_set_remember_password(ret, TRUE); |
| 921 g_free(keyring_id); |
928 /* |
| 922 g_free(mode); |
929 g_free(keyring_id); TODO : |
| 923 g_free(data); |
930 g_free(mode); This was commented becaus eof a double free. |
| |
931 g_free(data); I should figure out which one causes the bug to avoid leaks |
| |
932 */ |
| 924 } else { |
933 } else { |
| 925 purple_debug_info("accounts", "failed to imported password.\n"); |
934 purple_debug_info("accounts", "failed to imported password.\n"); |
| 926 // FIXME handle error |
935 /* TODO handle error */ |
| 927 } |
936 } |
| 928 } |
937 } |
| 929 |
938 |
| 930 return ret; |
939 return ret; |
| 931 } |
940 } |
| 1608 purple_keyring_set_password_sync(account, password); |
1617 purple_keyring_set_password_sync(account, password); |
| 1609 |
1618 |
| 1610 schedule_accounts_save(); |
1619 schedule_accounts_save(); |
| 1611 } |
1620 } |
| 1612 |
1621 |
| |
1622 void |
| |
1623 purple_account_set_password_async(PurpleAccount * account, |
| |
1624 gchar * password, |
| |
1625 GDestroyNotify destroypassword, |
| |
1626 PurpleKeyringSaveCallback cb, |
| |
1627 gpointer data) |
| |
1628 { |
| |
1629 /** |
| |
1630 * This is so we can force an account sync by calling |
| |
1631 * it with account == NULL. |
| |
1632 */ |
| |
1633 if(account != NULL) { |
| |
1634 |
| |
1635 if (purple_account_get_remember_password(account) == FALSE) { |
| |
1636 |
| |
1637 account->password = g_strdup(password); |
| |
1638 purple_debug_info("account", |
| |
1639 "Password for %s set, not sent to keyring.\n", |
| |
1640 purple_account_get_username(account)); |
| |
1641 |
| |
1642 if (cb != NULL) |
| |
1643 cb(account, NULL, data); |
| |
1644 |
| |
1645 } else { |
| |
1646 |
| |
1647 purple_keyring_set_password_async(account, password, |
| |
1648 destroypassword, cb, data); |
| |
1649 |
| |
1650 } |
| |
1651 } |
| |
1652 schedule_accounts_save(); |
| |
1653 } |
| 1613 void |
1654 void |
| 1614 purple_account_set_alias(PurpleAccount *account, const char *alias) |
1655 purple_account_set_alias(PurpleAccount *account, const char *alias) |
| 1615 { |
1656 { |
| 1616 g_return_if_fail(account != NULL); |
1657 g_return_if_fail(account != NULL); |
| 1617 |
1658 |