comparison src/account.c @ 10740:94cc67130789

[gaim-migrate @ 12342] More big changes, yay. I combined gaim_connection_new and gaim_connection_connect. Earlier today I realized that it's dumb to have a GaimConnection that isn't connected. I'm about to combine gaim_connection_disconnect and gaim_connection_destroy, as well. I added a "password" field to GaimConnection. It holds the password used to login a specific GaimConnection. Now, when "remember password" is false, account->password is NEVER set. When the user tries to sign on and Gaim prompts for the password, it goes directly into the GaimConnection. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 26 Mar 2005 23:25:18 +0000
parents 55af3fa46329
children 4228b6d78506
comparison
equal deleted inserted replaced
10739:42dbc4ba1325 10740:94cc67130789
739 gaim_log_free(account->system_log); 739 gaim_log_free(account->system_log);
740 740
741 g_free(account); 741 g_free(account);
742 } 742 }
743 743
744 GaimConnection * 744 void
745 gaim_account_register(GaimAccount *account) 745 gaim_account_register(GaimAccount *account)
746 { 746 {
747 GaimConnection *gc; 747 g_return_if_fail(account != NULL);
748 748
749 g_return_val_if_fail(account != NULL, NULL); 749 gaim_debug_info("account", "Registering account %s\n",
750 750 gaim_account_get_username(account));
751 if (gaim_account_get_connection(account) != NULL) 751
752 return NULL; 752 gaim_connection_new(account, TRUE, NULL);
753 753 }
754 gc = gaim_connection_new(account); 754
755 755 static void
756 gaim_debug_info("account", "Registering account %p. gc = %p\n", 756 request_password_ok_cb(GaimAccount *account, const char *entry)
757 account, gc); 757 {
758 758 if (!entry || !*entry)
759 gaim_connection_register(gc); 759 {
760 760 gaim_notify_error(account, NULL, _("Password is required to sign on."), NULL);
761 return gc; 761 return;
762 } 762 }
763 763
764 GaimConnection * 764 if (gaim_account_get_remember_password(account))
765 gaim_account_set_password(account, entry);
766
767 gaim_connection_new(account, FALSE, entry);
768 }
769
770 static void
771 request_password(GaimAccount *account)
772 {
773 gchar *primary;
774 gchar *escaped;
775 const gchar *username;
776
777 username = gaim_account_get_username(account);
778 escaped = g_markup_escape_text(username, strlen(username));
779 primary = g_strdup_printf(_("Enter password for %s (%s)"), escaped,
780 gaim_account_get_protocol_name(account));
781 gaim_request_input(account, _("Enter Password"), primary, NULL, NULL,
782 FALSE, TRUE, NULL,
783 _("OK"), G_CALLBACK(request_password_ok_cb),
784 _("Cancel"), NULL, account);
785 g_free(primary);
786 g_free(escaped);
787 }
788
789 void
765 gaim_account_connect(GaimAccount *account) 790 gaim_account_connect(GaimAccount *account)
766 { 791 {
767 GaimConnection *gc; 792 GaimPlugin *prpl;
768 793 GaimPluginProtocolInfo *prpl_info;
769 g_return_val_if_fail(account != NULL, NULL); 794 const char *password;
770 795
771 if (gaim_account_get_connection(account) != NULL) 796 g_return_if_fail(account != NULL);
772 return NULL; 797
773 798 gaim_debug_info("account", "Connecting to account %s\n",
774 gc = gaim_connection_new(account); 799 gaim_account_get_username(account));
775 800
776 gaim_debug_info("account", "Connecting to account %p. gc = %p\n", 801 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
777 account, gc); 802 if (prpl == NULL)
778 803 {
779 gaim_connection_connect(gc); 804 gchar *message;
780 805
781 return gc; 806 message = g_strdup_printf(_("Missing protocol plugin for %s"),
807 gaim_account_get_username(account));
808 gaim_notify_error(NULL, _("Connection Error"), message, NULL);
809 g_free(message);
810 return;
811 }
812
813 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
814 password = gaim_account_get_password(account);
815 if ((password == NULL) &&
816 !(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
817 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
818 request_password(account);
819 else
820 gaim_connection_new(account, FALSE, password);
782 } 821 }
783 822
784 void 823 void
785 gaim_account_disconnect(GaimAccount *account) 824 gaim_account_disconnect(GaimAccount *account)
786 { 825 {
938 void 977 void
939 gaim_account_set_username(GaimAccount *account, const char *username) 978 gaim_account_set_username(GaimAccount *account, const char *username)
940 { 979 {
941 g_return_if_fail(account != NULL); 980 g_return_if_fail(account != NULL);
942 981
943 if (account->username != NULL) 982 g_free(account->username);
944 g_free(account->username);
945
946 account->username = (username == NULL ? NULL : g_strdup(username)); 983 account->username = (username == NULL ? NULL : g_strdup(username));
947 984
948 schedule_accounts_save(); 985 schedule_accounts_save();
949 } 986 }
950 987
951 void 988 void
952 gaim_account_set_password(GaimAccount *account, const char *password) 989 gaim_account_set_password(GaimAccount *account, const char *password)
953 { 990 {
954 g_return_if_fail(account != NULL); 991 g_return_if_fail(account != NULL);
955 992
956 if (account->password != NULL) 993 g_free(account->password);
957 g_free(account->password); 994 account->password = NULL;
995
996 if (!gaim_account_get_remember_password(account))
997 return;
958 998
959 account->password = (password == NULL ? NULL : g_strdup(password)); 999 account->password = (password == NULL ? NULL : g_strdup(password));
960 1000
961 schedule_accounts_save(); 1001 schedule_accounts_save();
962 } 1002 }
964 void 1004 void
965 gaim_account_set_alias(GaimAccount *account, const char *alias) 1005 gaim_account_set_alias(GaimAccount *account, const char *alias)
966 { 1006 {
967 g_return_if_fail(account != NULL); 1007 g_return_if_fail(account != NULL);
968 1008
969 if (account->alias != NULL) 1009 g_free(account->alias);
970 g_free(account->alias);
971
972 account->alias = (alias == NULL ? NULL : g_strdup(alias)); 1010 account->alias = (alias == NULL ? NULL : g_strdup(alias));
973 1011
974 schedule_accounts_save(); 1012 schedule_accounts_save();
975 } 1013 }
976 1014
977 void 1015 void
978 gaim_account_set_user_info(GaimAccount *account, const char *user_info) 1016 gaim_account_set_user_info(GaimAccount *account, const char *user_info)
979 { 1017 {
980 g_return_if_fail(account != NULL); 1018 g_return_if_fail(account != NULL);
981 1019
982 if (account->user_info != NULL) 1020 g_free(account->user_info);
983 g_free(account->user_info);
984
985 account->user_info = (user_info == NULL ? NULL : g_strdup(user_info)); 1021 account->user_info = (user_info == NULL ? NULL : g_strdup(user_info));
986 1022
987 schedule_accounts_save(); 1023 schedule_accounts_save();
988 } 1024 }
989 1025
990 void 1026 void
991 gaim_account_set_buddy_icon(GaimAccount *account, const char *icon) 1027 gaim_account_set_buddy_icon(GaimAccount *account, const char *icon)
992 { 1028 {
993 g_return_if_fail(account != NULL); 1029 g_return_if_fail(account != NULL);
994 1030
995 if (account->buddy_icon != NULL) 1031 g_free(account->buddy_icon);
996 g_free(account->buddy_icon);
997
998 account->buddy_icon = (icon == NULL ? NULL : g_strdup(icon)); 1032 account->buddy_icon = (icon == NULL ? NULL : g_strdup(icon));
999 if (account->gc) 1033 if (gaim_account_is_connected(account))
1000 serv_set_buddyicon(account->gc, icon); 1034 serv_set_buddyicon(account->gc, icon);
1001 1035
1002 schedule_accounts_save(); 1036 schedule_accounts_save();
1003 } 1037 }
1004 1038
1006 gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id) 1040 gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id)
1007 { 1041 {
1008 g_return_if_fail(account != NULL); 1042 g_return_if_fail(account != NULL);
1009 g_return_if_fail(protocol_id != NULL); 1043 g_return_if_fail(protocol_id != NULL);
1010 1044
1011 if (account->protocol_id != NULL) 1045 g_free(account->protocol_id);
1012 g_free(account->protocol_id);
1013
1014 account->protocol_id = g_strdup(protocol_id); 1046 account->protocol_id = g_strdup(protocol_id);
1015 1047
1016 schedule_accounts_save(); 1048 schedule_accounts_save();
1017 } 1049 }
1018 1050