comparison src/server.c @ 9285:7a8aa87164ae

[gaim-migrate @ 10088] Ok I'm done. This started out as shx's patch to make add/remove buddy/buddies take GaimBuddy and GaimGroup's in various places. I think his diff was like 2000 lines and mine is like 5000. I tried to clean up blist.c a bit and make it more uniform. There are some more g_return_if_fail() checks. Removed some code that was deprecated--it's probably been long enough. Removed some #include <multi.h>'s. Make blist.xml saving happen on a timer, like prefs.xml and accounts.xml. Sorry if this doesn't merge cleanly with whatever you're doing. People should really test this a lot. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 15 Jun 2004 02:37:27 +0000
parents fac583b4ecdf
children 3313eab5033d
comparison
equal deleted inserted replaced
9284:fe0291162312 9285:7a8aa87164ae
22 */ 22 */
23 #include "internal.h" 23 #include "internal.h"
24 #include "conversation.h" 24 #include "conversation.h"
25 #include "debug.h" 25 #include "debug.h"
26 #include "log.h" 26 #include "log.h"
27 #include "multi.h"
28 #include "notify.h" 27 #include "notify.h"
29 #include "prefs.h" 28 #include "prefs.h"
30 #include "prpl.h" 29 #include "prpl.h"
31 #include "request.h" 30 #include "request.h"
32 #include "signals.h" 31 #include "signals.h"
39 #include "gtkimhtml.h" 38 #include "gtkimhtml.h"
40 #include "gtkutils.h" 39 #include "gtkutils.h"
41 #include "ui.h" 40 #include "ui.h"
42 41
43 #define SECS_BEFORE_RESENDING_AUTORESPONSE 600 42 #define SECS_BEFORE_RESENDING_AUTORESPONSE 600
43 #define SEX_BEFORE_RESENDING_AUTORESPONSE "Only after you're married"
44 44
45 static void add_idle_buddy(GaimBuddy *buddy); 45 static void add_idle_buddy(GaimBuddy *buddy);
46 static void remove_idle_buddy(GaimBuddy *buddy); 46 static void remove_idle_buddy(GaimBuddy *buddy);
47 47
48 void serv_login(GaimAccount *account) 48 void serv_login(GaimAccount *account)
284 gaim_conv_im_stop_type_again_timeout(GAIM_CONV_IM(c)); 284 gaim_conv_im_stop_type_again_timeout(GAIM_CONV_IM(c));
285 285
286 return val; 286 return val;
287 } 287 }
288 288
289 void serv_get_info(GaimConnection *g, const char *name) 289 void serv_get_info(GaimConnection *gc, const char *name)
290 { 290 {
291 GaimPluginProtocolInfo *prpl_info = NULL; 291 GaimPluginProtocolInfo *prpl_info = NULL;
292 292
293 if (g != NULL && g->prpl != NULL) 293 if (gc != NULL && gc->prpl != NULL)
294 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); 294 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
295 295
296 if (g && prpl_info && prpl_info->get_info) 296 if (gc && prpl_info && prpl_info->get_info)
297 prpl_info->get_info(g, name); 297 prpl_info->get_info(gc, name);
298 } 298 }
299 299
300 void serv_set_away(GaimConnection *gc, const char *state, const char *message) 300 void serv_set_away(GaimConnection *gc, const char *state, const char *message)
301 { 301 {
302 GaimPluginProtocolInfo *prpl_info = NULL; 302 GaimPluginProtocolInfo *prpl_info = NULL;
352 352
353 serv_set_away(g, GAIM_AWAY_CUSTOM, message); 353 serv_set_away(g, GAIM_AWAY_CUSTOM, message);
354 } 354 }
355 } 355 }
356 356
357 void serv_set_info(GaimConnection *g, const char *info) 357 void serv_set_info(GaimConnection *gc, const char *info)
358 { 358 {
359 GaimPluginProtocolInfo *prpl_info = NULL; 359 GaimPluginProtocolInfo *prpl_info = NULL;
360 GaimAccount *account; 360 GaimAccount *account;
361 361
362 if (g != NULL && g->prpl != NULL) 362 if (gc != NULL && gc->prpl != NULL)
363 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); 363 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
364 364
365 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && 365 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) &&
366 prpl_info->set_info) { 366 prpl_info->set_info) {
367 367
368 account = gaim_connection_get_account(g); 368 account = gaim_connection_get_account(gc);
369 369
370 if (gaim_signal_emit_return_1(gaim_accounts_get_handle(), 370 if (gaim_signal_emit_return_1(gaim_accounts_get_handle(),
371 "account-setting-info", account, info)) 371 "account-setting-info", account, info))
372 return; 372 return;
373 373
374 prpl_info->set_info(g, info); 374 prpl_info->set_info(gc, info);
375 375
376 gaim_signal_emit(gaim_accounts_get_handle(), 376 gaim_signal_emit(gaim_accounts_get_handle(),
377 "account-set-info", account, info); 377 "account-set-info", account, info);
378 } 378 }
379 } 379 }
380 380
381 void serv_change_passwd(GaimConnection *g, const char *orig, const char *new) 381 void serv_change_passwd(GaimConnection *gc, const char *orig, const char *new)
382 {
383 GaimPluginProtocolInfo *prpl_info = NULL;
384
385 if (g != NULL && g->prpl != NULL)
386 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl);
387
388 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->change_passwd)
389 prpl_info->change_passwd(g, orig, new);
390 }
391
392 void serv_add_buddy(GaimConnection *g, const char *name, GaimGroup *group)
393 {
394 GaimPluginProtocolInfo *prpl_info = NULL;
395
396 if (g != NULL && g->prpl != NULL)
397 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl);
398
399 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->add_buddy)
400 prpl_info->add_buddy(g, name, group);
401 }
402
403 void serv_add_buddies(GaimConnection *gc, GList *buddies)
404 { 382 {
405 GaimPluginProtocolInfo *prpl_info = NULL; 383 GaimPluginProtocolInfo *prpl_info = NULL;
406 384
407 if (gc != NULL && gc->prpl != NULL) 385 if (gc != NULL && gc->prpl != NULL)
408 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 386 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
409 387
388 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && prpl_info->change_passwd)
389 prpl_info->change_passwd(gc, orig, new);
390 }
391
392 void serv_add_buddy(GaimConnection *gc, GaimBuddy *buddy)
393 {
394 GaimPluginProtocolInfo *prpl_info = NULL;
395
396 if (gc != NULL && gc->prpl != NULL)
397 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
398
399 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && prpl_info->add_buddy)
400 prpl_info->add_buddy(gc, buddy, gaim_find_buddys_group(buddy));
401 }
402
403 void serv_add_buddies(GaimConnection *gc, GList *buddies)
404 {
405 GaimPluginProtocolInfo *prpl_info = NULL;
406
407 if (gc != NULL && gc->prpl != NULL)
408 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
409
410 if (prpl_info && g_list_find(gaim_connections_get_all(), gc)) { 410 if (prpl_info && g_list_find(gaim_connections_get_all(), gc)) {
411 GList *cur, *groups = NULL;
412
413 /* Make a list of what the groups each buddy is in */
414 for (cur = buddies; cur != NULL; cur = cur->next) {
415 GaimBlistNode *node = cur->data;
416 groups = g_list_append(groups, node->parent);
417 }
418
411 if (prpl_info->add_buddies) 419 if (prpl_info->add_buddies)
412 prpl_info->add_buddies(gc, buddies); 420 prpl_info->add_buddies(gc, buddies, groups);
413 else if (prpl_info->add_buddy) { 421 else if (prpl_info->add_buddy) {
414 while (buddies) { 422 GList *curb = buddies;
415 prpl_info->add_buddy(gc, buddies->data, NULL); 423 GList *curg = groups;
416 buddies = buddies->next; 424 while ((curb != NULL) && (curg != NULL)) {
425 prpl_info->add_buddy(gc, curb->data, curg->data);
426 curb = curb->next;
427 curg = curg->next;
417 } 428 }
418 } 429 }
419 } 430
420 } 431 g_list_free(groups);
421 432 }
422 433 }
423 void serv_remove_buddy(GaimConnection *g, const char *name, const char *group) 434
424 { 435
425 GaimPluginProtocolInfo *prpl_info = NULL; 436 void serv_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
426 GaimBuddy *buddy; 437 {
427 438 GaimPluginProtocolInfo *prpl_info = NULL;
428 buddy = gaim_find_buddy(gaim_connection_get_account(g), name);
429 439
430 if (buddy->idle > 0) 440 if (buddy->idle > 0)
431 remove_idle_buddy(buddy); 441 remove_idle_buddy(buddy);
432 442
433 if (g != NULL && g->prpl != NULL) 443 if (gc != NULL && gc->prpl != NULL)
434 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); 444 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
435 445
436 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->remove_buddy) 446 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && prpl_info->remove_buddy)
437 prpl_info->remove_buddy(g, name, group); 447 prpl_info->remove_buddy(gc, buddy, group);
438 } 448 }
439 449
440 void 450 void serv_remove_buddies(GaimConnection *gc, GList *buddies, GList *groups)
441 serv_remove_group(GaimConnection *gc, const char *name) 451 {
452 GaimPluginProtocolInfo *prpl_info = NULL;
453
454 if (!g_list_find(gaim_connections_get_all(), gc))
455 return;
456
457 if (gc != NULL && gc->prpl != NULL)
458 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
459
460 if (prpl_info && g_list_find(gaim_connections_get_all(), gc)) {
461 if (prpl_info->remove_buddies) {
462 GList *curb;
463 for (curb = buddies; curb != NULL; curb = curb->next) {
464 GaimBuddy *buddy = curb->data;
465 if (buddy->idle > 0)
466 remove_idle_buddy(buddy);
467 }
468 prpl_info->remove_buddies(gc, buddies, groups);
469 } else {
470 GList *curb = buddies;
471 GList *curg = groups;
472 while ((curb != NULL) && (curg != NULL)) {
473 serv_remove_buddy(gc, curb->data, curg->data);
474 curb = curb->next;
475 curg = curg->next;
476 }
477 }
478 }
479 }
480
481 void serv_remove_group(GaimConnection *gc, GaimGroup *group)
442 { 482 {
443 GaimPluginProtocolInfo *prpl_info = NULL; 483 GaimPluginProtocolInfo *prpl_info = NULL;
444 484
445 if (gc != NULL && gc->prpl != NULL) 485 if (gc != NULL && gc->prpl != NULL)
446 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 486 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
447 487
448 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && 488 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) &&
449 prpl_info->remove_group) 489 prpl_info->remove_group)
450 { 490 {
451 prpl_info->remove_group(gc, name); 491 prpl_info->remove_group(gc, group);
452 }
453 }
454
455 void serv_remove_buddies(GaimConnection *gc, GList *g, const char *group)
456 {
457 GaimPluginProtocolInfo *prpl_info = NULL;
458
459 if (!g_list_find(gaim_connections_get_all(), gc))
460 return;
461
462 if (!gc->prpl)
463 return; /* how the hell did that happen? */
464
465 if (gc != NULL && gc->prpl != NULL)
466 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
467
468 if (prpl_info->remove_buddies)
469 prpl_info->remove_buddies(gc, g, group);
470 else {
471 while (g) {
472 serv_remove_buddy(gc, g->data, group);
473 g = g->next;
474 }
475 } 492 }
476 } 493 }
477 494
478 /* 495 /*
479 * Set buddy's alias on server roster/list 496 * Set buddy's alias on server roster/list
522 539
523 /* 540 /*
524 * Move a buddy from one group to another on server. 541 * Move a buddy from one group to another on server.
525 * 542 *
526 * Note: For now we'll not deal with changing gc's at the same time, but 543 * Note: For now we'll not deal with changing gc's at the same time, but
527 * it should be possible. Probably needs to be done, someday. 544 * it should be possible. Probably needs to be done, someday. Although,
545 * the UI for that would be difficult, because groups are Gaim-wide.
528 */ 546 */
529 void serv_move_buddy(GaimBuddy *b, GaimGroup *og, GaimGroup *ng) 547 void serv_move_buddy(GaimBuddy *b, GaimGroup *og, GaimGroup *ng)
530 { 548 {
531 GaimPluginProtocolInfo *prpl_info = NULL; 549 GaimPluginProtocolInfo *prpl_info = NULL;
532 550
541 } 559 }
542 560
543 /* 561 /*
544 * Rename a group on server roster/list. 562 * Rename a group on server roster/list.
545 */ 563 */
546 void serv_rename_group(GaimConnection *g, GaimGroup *old_group, 564 void serv_rename_group(GaimConnection *gc, const char *old_name,
547 const char *new_name) 565 GaimGroup *group, GList *moved_buddies)
548 { 566 {
549 GaimPluginProtocolInfo *prpl_info = NULL; 567 GaimPluginProtocolInfo *prpl_info = NULL;
550 568
551 if (g != NULL && g->prpl != NULL) 569 if (gc != NULL && gc->prpl != NULL)
552 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); 570 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
553 571
554 if (prpl_info && old_group && new_name) { 572 if (prpl_info && old_name && group && strcmp(old_name, group->name)) {
555 GList *tobemoved = NULL;
556 GaimBlistNode *cnode, *bnode;
557
558 for(cnode = ((GaimBlistNode*)old_group)->child; cnode; cnode = cnode->next) {
559 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode))
560 continue;
561 for(bnode = cnode->child; bnode; bnode = bnode->next) {
562 GaimBuddy *b;
563 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
564 continue;
565 b = (GaimBuddy*)bnode;
566
567 if(b->account == g->account)
568 tobemoved = g_list_append(tobemoved, b->name);
569
570 }
571
572 }
573
574 if (prpl_info->rename_group) { 573 if (prpl_info->rename_group) {
575 /* prpl's might need to check if the group already 574 /* prpl's might need to check if the group already
576 * exists or not, and handle that differently */ 575 * exists or not, and handle that differently */
577 prpl_info->rename_group(g, old_group->name, new_name, tobemoved); 576 prpl_info->rename_group(gc, old_name, group, moved_buddies);
578 } else { 577 } else {
579 serv_remove_buddies(g, tobemoved, old_group->name); 578 GList *cur, *groups = NULL;
580 serv_add_buddies(g, tobemoved); 579
581 } 580 /* Make a list of what the groups each buddy is in */
582 581 for (cur = moved_buddies; cur != NULL; cur = cur->next) {
583 g_list_free(tobemoved); 582 GaimBlistNode *node = cur->data;
583 groups = g_list_append(groups, node->parent);
584 }
585
586 serv_remove_buddies(gc, moved_buddies, groups);
587 g_list_free(groups);
588 serv_add_buddies(gc, moved_buddies);
589 }
584 } 590 }
585 } 591 }
586 592
587 void serv_add_permit(GaimConnection *g, const char *name) 593 void serv_add_permit(GaimConnection *g, const char *name)
588 { 594 {
1146 /* This code will 'align' the name from the TOC */ 1152 /* This code will 'align' the name from the TOC */
1147 /* server with what's in our record. We want to */ 1153 /* server with what's in our record. We want to */
1148 /* store things how THEY want it... */ 1154 /* store things how THEY want it... */
1149 if (strcmp(name, b->name)) { 1155 if (strcmp(name, b->name)) {
1150 gaim_blist_rename_buddy(b, name); 1156 gaim_blist_rename_buddy(b, name);
1151 gaim_blist_save();
1152 } 1157 }
1153 1158
1154 old_idle = b->idle; 1159 old_idle = b->idle;
1155 1160
1156 if (loggedin) { 1161 if (loggedin) {