comparison src/protocols/oscar/oscar.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 e67b8cd33c6c
children 3313eab5033d
comparison
equal deleted inserted replaced
9284:fe0291162312 9285:7a8aa87164ae
4330 gaim_buddy_icons_set_for_user(gaim_connection_get_account(gc), 4330 gaim_buddy_icons_set_for_user(gaim_connection_get_account(gc),
4331 sn, icon, iconlen); 4331 sn, icon, iconlen);
4332 b16 = gaim_base16_encode(iconcsum, iconcsumlen); 4332 b16 = gaim_base16_encode(iconcsum, iconcsumlen);
4333 if (b16) { 4333 if (b16) {
4334 gaim_blist_node_set_string((GaimBlistNode*)b, "icon_checksum", b16); 4334 gaim_blist_node_set_string((GaimBlistNode*)b, "icon_checksum", b16);
4335 gaim_blist_save();
4336 g_free(b16); 4335 g_free(b16);
4337 } 4336 }
4338 } 4337 }
4339 4338
4340 cur = od->requesticon; 4339 cur = od->requesticon;
4929 if (info->uin && info->nick && info->nick[0] && (utf8 = gaim_utf8_try_convert(info->nick))) { 4928 if (info->uin && info->nick && info->nick[0] && (utf8 = gaim_utf8_try_convert(info->nick))) {
4930 g_snprintf(who, sizeof(who), "%u", info->uin); 4929 g_snprintf(who, sizeof(who), "%u", info->uin);
4931 serv_got_alias(gc, who, utf8); 4930 serv_got_alias(gc, who, utf8);
4932 if ((b = gaim_find_buddy(gc->account, who))) { 4931 if ((b = gaim_find_buddy(gc->account, who))) {
4933 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", utf8); 4932 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", utf8);
4934 gaim_blist_save();
4935 } 4933 }
4936 g_free(utf8); 4934 g_free(utf8);
4937 } 4935 }
4938 4936
4939 return 1; 4937 return 1;
5508 static void oscar_warn(GaimConnection *gc, const char *name, int anon) { 5506 static void oscar_warn(GaimConnection *gc, const char *name, int anon) {
5509 OscarData *od = (OscarData *)gc->proto_data; 5507 OscarData *od = (OscarData *)gc->proto_data;
5510 aim_im_warn(od->sess, od->conn, name, anon ? AIM_WARN_ANON : 0); 5508 aim_im_warn(od->sess, od->conn, name, anon ? AIM_WARN_ANON : 0);
5511 } 5509 }
5512 5510
5513 static void oscar_add_buddy(GaimConnection *gc, const char *name, GaimGroup *g) { 5511 static void oscar_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {
5514 OscarData *od = (OscarData *)gc->proto_data; 5512 OscarData *od = (OscarData *)gc->proto_data;
5515 GaimBuddy *b; 5513
5516 5514 if (!aim_snvalid(buddy->name)) {
5517 if (g == NULL) {
5518 /* If we were called from oscar_add_buddies... */
5519 b = gaim_find_buddy(gaim_connection_get_account(gc), name);
5520 g = gaim_find_buddys_group(b);
5521 } else
5522 b = gaim_find_buddy_in_group(gaim_connection_get_account(gc), name, g);
5523
5524 if (!aim_snvalid(name)) {
5525 gchar *buf; 5515 gchar *buf;
5526 buf = g_strdup_printf(_("Could not add the buddy %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers."), name); 5516 buf = g_strdup_printf(_("Could not add the buddy %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers."), buddy->name);
5527 gaim_notify_error(gc, NULL, _("Unable To Add"), buf); 5517 gaim_notify_error(gc, NULL, _("Unable To Add"), buf);
5528 g_free(buf); 5518 g_free(buf);
5529 5519
5530 /* Remove from local list */ 5520 /* Remove from local list */
5531 gaim_blist_remove_buddy(b); 5521 gaim_blist_remove_buddy(buddy);
5532 5522
5533 return; 5523 return;
5534 } 5524 }
5535 5525
5536 #ifdef NOSSI 5526 #ifdef NOSSI
5537 aim_buddylist_addbuddy(od->sess, od->conn, name); 5527 aim_buddylist_addbuddy(od->sess, od->conn, buddy->name);
5538 #else 5528 #else
5539 if ((od->sess->ssi.received_data) && !(aim_ssi_itemlist_exists(od->sess->ssi.local, name))) { 5529 if ((od->sess->ssi.received_data) && !(aim_ssi_itemlist_finditem(od->sess->ssi.local, group->name, buddy->name, AIM_SSI_TYPE_BUDDY))) {
5540 if (b && g) { 5530 if (buddy && group) {
5541 gaim_debug_info("oscar", 5531 gaim_debug_info("oscar",
5542 "ssi: adding buddy %s to group %s\n", name, g->name); 5532 "ssi: adding buddy %s to group %s\n", buddy->name, group->name);
5543 aim_ssi_addbuddy(od->sess, b->name, g->name, gaim_get_buddy_alias_only(b), NULL, NULL, 0); 5533 aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_get_buddy_alias_only(buddy), NULL, NULL, 0);
5544 } 5534 }
5545 } 5535 }
5546 #endif 5536 #endif
5547 5537
5548 if (od->icq) 5538 if (od->icq)
5549 aim_icq_getalias(od->sess, name); 5539 aim_icq_getalias(od->sess, buddy->name);
5550 } 5540 }
5551 5541
5552 static void oscar_add_buddies(GaimConnection *gc, GList *buddies) { 5542 static void oscar_add_buddies(GaimConnection *gc, GList *buddies, GList *groups) {
5553 OscarData *od = (OscarData *)gc->proto_data; 5543 OscarData *od = (OscarData *)gc->proto_data;
5554 #ifdef NOSSI 5544 #ifdef NOSSI
5555 char buf[MSG_LEN]; 5545 char buf[MSG_LEN];
5556 int n=0; 5546 int n=0;
5547
5557 while (buddies) { 5548 while (buddies) {
5558 if (n > MSG_LEN - 18) { 5549 if (n > MSG_LEN - 18) {
5559 aim_buddylist_set(od->sess, od->conn, buf); 5550 aim_buddylist_set(od->sess, od->conn, buf);
5560 n = 0; 5551 n = 0;
5561 } 5552 }
5562 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (const char *)buddies->data); 5553 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (const char *)buddies->data);
5563 buddies = buddies->next; 5554 buddies = buddies->next;
5564 } 5555 }
5565 aim_buddylist_set(od->sess, od->conn, buf); 5556 aim_buddylist_set(od->sess, od->conn, buf);
5566 #else 5557 #else
5558
5567 if (od->sess->ssi.received_data) { 5559 if (od->sess->ssi.received_data) {
5568 while (buddies) { 5560 GList *curb = buddies;
5569 oscar_add_buddy(gc, buddies->data, NULL); 5561 GList *curg = groups;
5570 buddies = buddies->next; 5562 while ((curb != NULL) && (curg != NULL)) {
5563 GaimBuddy *buddy = curb->data;
5564 GaimGroup *group = curg->data;
5565 oscar_add_buddy(gc, buddy, group);
5566 curb = curb->next;
5567 curg = curg->next;
5571 } 5568 }
5572 } 5569 }
5573 #endif 5570 #endif
5574 } 5571 }
5575 5572
5576 static void oscar_remove_buddy(GaimConnection *gc, const char *name, const char *group) { 5573 static void oscar_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {
5577 OscarData *od = (OscarData *)gc->proto_data; 5574 OscarData *od = (OscarData *)gc->proto_data;
5575
5578 #ifdef NOSSI 5576 #ifdef NOSSI
5579 aim_buddylist_removebuddy(od->sess, od->conn, name); 5577 aim_buddylist_removebuddy(od->sess, od->conn, buddy->name);
5580 #else 5578 #else
5581 if (od->sess->ssi.received_data) { 5579 if (od->sess->ssi.received_data) {
5582 gaim_debug_info("oscar", 5580 gaim_debug_info("oscar",
5583 "ssi: deleting buddy %s from group %s\n", name, group); 5581 "ssi: deleting buddy %s from group %s\n", buddy->name, group->name);
5584 aim_ssi_delbuddy(od->sess, name, group); 5582 aim_ssi_delbuddy(od->sess, buddy->name, group->name);
5585 } 5583 }
5586 #endif 5584 #endif
5587 } 5585 }
5588 5586
5589 static void oscar_remove_buddies(GaimConnection *gc, GList *buddies, const char *group) { 5587 static void oscar_remove_buddies(GaimConnection *gc, GList *buddies, GList *groups) {
5590 OscarData *od = (OscarData *)gc->proto_data; 5588 OscarData *od = (OscarData *)gc->proto_data;
5589
5591 #ifdef NOSSI 5590 #ifdef NOSSI
5592 GList *cur; 5591 for (cur = buddies; cur != NULL; cur = cur->next) {
5593 for (cur=buddies; cur; cur=cur->next) 5592 GaimBuddy *buddy = cur->data;
5594 aim_buddylist_removebuddy(od->sess, od->conn, cur->data); 5593 aim_buddylist_removebuddy(od->sess, od->conn, buddy->name);
5594 }
5595 #else 5595 #else
5596 if (od->sess->ssi.received_data) { 5596 if (od->sess->ssi.received_data) {
5597 while (buddies) { 5597 GList *curb = buddies;
5598 oscar_remove_buddy(gc, buddies->data, group); 5598 GList *curg = groups;
5599 buddies = buddies->next; 5599 while ((curb != NULL) && (curg != NULL)) {
5600 GaimBuddy *buddy = curb->data;
5601 GaimGroup *group = curg->data;
5602 oscar_remove_buddy(gc, buddy, group);
5603 curb = curb->next;
5604 curg = curg->next;
5600 } 5605 }
5601 } 5606 }
5602 #endif 5607 #endif
5603 } 5608 }
5604 5609
5622 aim_ssi_aliasbuddy(od->sess, gname, name, alias); 5627 aim_ssi_aliasbuddy(od->sess, gname, name, alias);
5623 } 5628 }
5624 } 5629 }
5625 } 5630 }
5626 5631
5627 static void oscar_rename_group(GaimConnection *gc, const char *old_group, const char *new_group, GList *members) { 5632 static void oscar_rename_group(GaimConnection *gc, const char *old_name, GaimGroup *group, GList *moved_buddies) {
5628 OscarData *od = (OscarData *)gc->proto_data; 5633 OscarData *od = (OscarData *)gc->proto_data;
5629 5634
5630 if (od->sess->ssi.received_data) { 5635 if (od->sess->ssi.received_data) {
5631 if (aim_ssi_itemlist_finditem(od->sess->ssi.local, new_group, NULL, AIM_SSI_TYPE_GROUP)) { 5636 if (aim_ssi_itemlist_finditem(od->sess->ssi.local, group->name, NULL, AIM_SSI_TYPE_GROUP)) {
5632 oscar_remove_buddies(gc, members, old_group); 5637 GList *cur, *groups = NULL;
5633 oscar_add_buddies(gc, members); 5638
5639 /* Make a list of what the groups each buddy is in */
5640 for (cur = moved_buddies; cur != NULL; cur = cur->next) {
5641 GaimBlistNode *node = cur->data;
5642 groups = g_list_append(groups, node->parent);
5643 }
5644
5645 oscar_remove_buddies(gc, moved_buddies, groups);
5646 oscar_add_buddies(gc, moved_buddies, groups);
5647 g_list_free(groups);
5634 gaim_debug_info("oscar", 5648 gaim_debug_info("oscar",
5635 "ssi: moved all buddies from group %s to %s\n", old_group, new_group); 5649 "ssi: moved all buddies from group %s to %s\n", old_name, group->name);
5636 } else { 5650 } else {
5637 aim_ssi_rename_group(od->sess, old_group, new_group); 5651 aim_ssi_rename_group(od->sess, old_name, group->name);
5638 gaim_debug_info("oscar", 5652 gaim_debug_info("oscar",
5639 "ssi: renamed group %s to %s\n", old_group, new_group); 5653 "ssi: renamed group %s to %s\n", old_name, group->name);
5640 } 5654 }
5641 } 5655 }
5642 } 5656 }
5643 5657
5644 static gboolean gaim_ssi_rerequestdata(gpointer data) { 5658 static gboolean gaim_ssi_rerequestdata(gpointer data) {
5841 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans")); 5855 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans"));
5842 gaim_blist_add_group(g, NULL); 5856 gaim_blist_add_group(g, NULL);
5843 } 5857 }
5844 5858
5845 gaim_debug_info("oscar", 5859 gaim_debug_info("oscar",
5846 "ssi: adding b %s to group %s to local list\n", curitem->name, gname_utf8 ? gname_utf8 : _("Orphans")); 5860 "ssi: adding buddy %s to group %s to local list\n", curitem->name, gname_utf8 ? gname_utf8 : _("Orphans"));
5847 gaim_blist_add_buddy(b, NULL, g, NULL); 5861 gaim_blist_add_buddy(b, NULL, g, NULL);
5848 } 5862 }
5849 if (!aim_sncmp(curitem->name, account->username)) { 5863 if (!aim_sncmp(curitem->name, account->username)) {
5850 char *comment = aim_ssi_getcomment(sess->ssi.local, gname, curitem->name); 5864 char *comment = aim_ssi_getcomment(sess->ssi.local, gname, curitem->name);
5851 gaim_check_comment(od, comment); 5865 gaim_check_comment(od, comment);
6002 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans")); 6016 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans"));
6003 gaim_blist_add_group(g, NULL); 6017 gaim_blist_add_group(g, NULL);
6004 } 6018 }
6005 6019
6006 gaim_debug_info("oscar", 6020 gaim_debug_info("oscar",
6007 "ssi: adding b %s to group %s to local list\n", name, gname_utf8 ? gname_utf8 : _("Orphans")); 6021 "ssi: adding buddy %s to group %s to local list\n", name, gname_utf8 ? gname_utf8 : _("Orphans"));
6008 gaim_blist_add_buddy(b, NULL, g, NULL); 6022 gaim_blist_add_buddy(b, NULL, g, NULL);
6009 } 6023 }
6010 g_free(gname_utf8); 6024 g_free(gname_utf8);
6011 g_free(alias_utf8); 6025 g_free(alias_utf8);
6012 6026