comparison src/account.c @ 5943:a4f2aba0848d

[gaim-migrate @ 6384] This should fix corruption in the blist, accounts, and pounces when some protocol plugins cannot load. Some parts of gaim now use the new unique Plugin or Protocol Plugin IDs, while some still use the old protocol numbers. Accounts kind of used both, and when prpls were missing, it had trouble finding accounts. It would find the names, even without mapping the protocol numbers to IDs, and any duplicate accounts would get nuked. That would then affect pounce saving. Anyhow, long story short (well, it's already long, too late for that), this should fix all that mess. And introduce new mess, but hopefully temporary mess. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 23 Jun 2003 02:00:15 +0000
parents d0320de18feb
children bc71bd31c223
comparison
equal deleted inserted replaced
5942:d0320de18feb 5943:a4f2aba0848d
112 if (!accounts_save_timer) 112 if (!accounts_save_timer)
113 accounts_save_timer = g_timeout_add(5000, accounts_save_cb, NULL); 113 accounts_save_timer = g_timeout_add(5000, accounts_save_cb, NULL);
114 } 114 }
115 115
116 GaimAccount * 116 GaimAccount *
117 gaim_account_new(const char *username, GaimProtocol protocol) 117 gaim_account_new(const char *username, const char *protocol_id)
118 { 118 {
119 GaimAccount *account; 119 GaimAccount *account;
120 120
121 g_return_val_if_fail(username != NULL, NULL); 121 g_return_val_if_fail(username != NULL, NULL);
122 122 g_return_val_if_fail(protocol_id != NULL, NULL);
123 account = gaim_accounts_find(username, protocol); 123
124 account = gaim_accounts_find_with_prpl_id(username, protocol_id);
124 125
125 if (account != NULL) 126 if (account != NULL)
126 return account; 127 return account;
127 128
128 account = g_new0(GaimAccount, 1); 129 account = g_new0(GaimAccount, 1);
129 130
130 gaim_account_set_username(account, username); 131 gaim_account_set_username(account, username);
131 gaim_account_set_protocol(account, protocol); 132 gaim_account_set_protocol_id(account, protocol_id);
132 133
133 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, 134 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
134 g_free, delete_setting); 135 g_free, delete_setting);
135 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, 136 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
136 g_free, (GDestroyNotify)g_hash_table_destroy); 137 g_free, (GDestroyNotify)g_hash_table_destroy);
268 } 269 }
269 270
270 void 271 void
271 gaim_account_set_protocol(GaimAccount *account, GaimProtocol protocol) 272 gaim_account_set_protocol(GaimAccount *account, GaimProtocol protocol)
272 { 273 {
273 GaimPlugin *plugin; 274 g_return_if_fail(account != NULL);
274 275
275 g_return_if_fail(account != NULL); 276 gaim_account_set_protocol_id(account, gaim_prpl_num_to_id(protocol));
276 277 }
277 plugin = gaim_find_prpl(protocol); 278
278 279 void
279 g_return_if_fail(plugin != NULL); 280 gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id)
280 281 {
281 account->protocol = protocol; 282 g_return_if_fail(account != NULL);
283 g_return_if_fail(protocol_id != NULL);
282 284
283 if (account->protocol_id != NULL) 285 if (account->protocol_id != NULL)
284 g_free(account->protocol_id); 286 g_free(account->protocol_id);
285 287
286 account->protocol_id = g_strdup(plugin->info->id); 288 account->protocol_id = g_strdup(protocol_id);
287 289
288 schedule_accounts_save(); 290 schedule_accounts_save();
289 } 291 }
290 292
291 void 293 void
545 GaimProtocol 547 GaimProtocol
546 gaim_account_get_protocol(const GaimAccount *account) 548 gaim_account_get_protocol(const GaimAccount *account)
547 { 549 {
548 g_return_val_if_fail(account != NULL, -1); 550 g_return_val_if_fail(account != NULL, -1);
549 551
550 return account->protocol; 552 return gaim_prpl_id_to_num(gaim_account_get_protocol_id(account));
553 }
554
555 const char *
556 gaim_account_get_protocol_id(const GaimAccount *account)
557 {
558 g_return_val_if_fail(account != NULL, NULL);
559
560 return account->protocol_id;
551 } 561 }
552 562
553 GaimConnection * 563 GaimConnection *
554 gaim_account_get_connection(const GaimAccount *account) 564 gaim_account_get_connection(const GaimAccount *account)
555 { 565 {
812 822
813 buffer = g_string_free(data->buffer, FALSE); 823 buffer = g_string_free(data->buffer, FALSE);
814 data->buffer = NULL; 824 data->buffer = NULL;
815 825
816 if (data->tag == TAG_PROTOCOL) { 826 if (data->tag == TAG_PROTOCOL) {
817 GList *l;
818 GaimPlugin *plugin;
819
820 data->protocol_id = g_strdup(buffer); 827 data->protocol_id = g_strdup(buffer);
821 data->protocol = -1;
822
823 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) {
824 plugin = (GaimPlugin *)l->data;
825
826 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) {
827 if (!strcmp(plugin->info->id, buffer)) {
828 data->protocol =
829 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol;
830
831 break;
832 }
833 }
834 }
835 } 828 }
836 else if (data->tag == TAG_NAME) { 829 else if (data->tag == TAG_NAME) {
837 if (data->in_proxy) { 830 if (data->in_proxy) {
838 gaim_proxy_info_set_username(data->proxy_info, buffer); 831 gaim_proxy_info_set_username(data->proxy_info, buffer);
839 } 832 }
840 else { 833 else {
841 data->account = gaim_account_new(buffer, data->protocol); 834 data->account = gaim_account_new(buffer, data->protocol_id);
842
843 if (data->account->protocol_id != NULL)
844 g_free(data->account->protocol_id);
845
846 data->account->protocol_id = data->protocol_id;
847 835
848 gaim_accounts_add(data->account); 836 gaim_accounts_add(data->account);
837
838 g_free(data->protocol_id);
849 839
850 data->protocol_id = NULL; 840 data->protocol_id = NULL;
851 } 841 }
852 } 842 }
853 else if (data->tag == TAG_PASSWORD) { 843 else if (data->tag == TAG_PASSWORD) {
1299 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { 1289 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
1300 account = (GaimAccount *)l->data; 1290 account = (GaimAccount *)l->data;
1301 1291
1302 if (!strcmp(normalize(gaim_account_get_username(account)), who)) { 1292 if (!strcmp(normalize(gaim_account_get_username(account)), who)) {
1303 if (protocol != -1) { 1293 if (protocol != -1) {
1304 if (account->protocol == protocol) 1294 if (gaim_account_get_protocol(account) == protocol)
1305 break; 1295 break;
1306 } 1296 }
1307 else 1297 else
1308 break; 1298 break;
1309 } 1299 }
1313 1303
1314 g_free(who); 1304 g_free(who);
1315 1305
1316 return account; 1306 return account;
1317 } 1307 }
1308
1309 GaimAccount *
1310 gaim_accounts_find_with_prpl_id(const char *name, const char *protocol_id)
1311 {
1312 GaimAccount *account = NULL;
1313 GList *l;
1314 char *who;
1315
1316 g_return_val_if_fail(name != NULL, NULL);
1317
1318 who = g_strdup(normalize(name));
1319
1320 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
1321 account = (GaimAccount *)l->data;
1322
1323 if (!strcmp(normalize(gaim_account_get_username(account)), who) &&
1324 !strcmp(account->protocol_id, protocol_id)) {
1325
1326 break;
1327 }
1328
1329 account = NULL;
1330 }
1331
1332 g_free(who);
1333
1334 return account;
1335 }