Mercurial > pidgin.yaz
comparison src/protocols/yahoo/yahoo.c @ 6760:e7e21e5d1d16
[gaim-migrate @ 7292]
Jesse Farmer (farmerje) added ignore support for yahoo
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 06 Sep 2003 01:21:30 +0000 |
parents | 7b878ee8f064 |
children | ddbe06989d46 |
comparison
equal
deleted
inserted
replaced
6759:f9efcba2d02f | 6760:e7e21e5d1d16 |
---|---|
21 */ | 21 */ |
22 #include "internal.h" | 22 #include "internal.h" |
23 | 23 |
24 #include "account.h" | 24 #include "account.h" |
25 #include "accountopt.h" | 25 #include "accountopt.h" |
26 #include "blist.h" | |
26 #include "debug.h" | 27 #include "debug.h" |
27 #include "multi.h" | 28 #include "multi.h" |
28 #include "notify.h" | 29 #include "notify.h" |
30 #include "privacy.h" | |
29 #include "prpl.h" | 31 #include "prpl.h" |
30 #include "proxy.h" | 32 #include "proxy.h" |
31 #include "request.h" | 33 #include "request.h" |
32 #include "server.h" | 34 #include "server.h" |
33 #include "util.h" | 35 #include "util.h" |
381 | 383 |
382 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt) | 384 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt) |
383 { | 385 { |
384 GSList *l = pkt->hash; | 386 GSList *l = pkt->hash; |
385 gboolean export = FALSE; | 387 gboolean export = FALSE; |
388 gboolean got_serv_list = FALSE; | |
386 GaimBuddy *b; | 389 GaimBuddy *b; |
387 GaimGroup *g; | 390 GaimGroup *g; |
388 | 391 |
389 while (l) { | 392 while (l) { |
390 char **lines; | 393 char **lines; |
393 char **tmp, **bud; | 396 char **tmp, **bud; |
394 | 397 |
395 struct yahoo_pair *pair = l->data; | 398 struct yahoo_pair *pair = l->data; |
396 l = l->next; | 399 l = l->next; |
397 | 400 |
398 if (pair->key != 87) | 401 switch (pair->key) { |
399 continue; | 402 case 87: |
400 | 403 lines = g_strsplit(pair->value, "\n", -1); |
401 lines = g_strsplit(pair->value, "\n", -1); | 404 for (tmp = lines; *tmp; tmp++) { |
402 for (tmp = lines; *tmp; tmp++) { | 405 split = g_strsplit(*tmp, ":", 2); |
403 split = g_strsplit(*tmp, ":", 2); | 406 if (!split) |
404 if (!split) | 407 continue; |
405 continue; | 408 if (!split[0] || !split[1]) { |
406 if (!split[0] || !split[1]) { | 409 g_strfreev(split); |
410 continue; | |
411 } | |
412 buddies = g_strsplit(split[1], ",", -1); | |
413 for (bud = buddies; bud && *bud; bud++) | |
414 if (!(b = gaim_find_buddy(gc->account, *bud))) { | |
415 if (!(g = gaim_find_group(split[0]))) { | |
416 g = gaim_group_new(split[0]); | |
417 gaim_blist_add_group(g, NULL); | |
418 } | |
419 b = gaim_buddy_new(gc->account, *bud, NULL); | |
420 gaim_blist_add_buddy(b, NULL, g, NULL); | |
421 export = TRUE; | |
422 } | |
423 g_strfreev(buddies); | |
407 g_strfreev(split); | 424 g_strfreev(split); |
408 continue; | |
409 } | 425 } |
410 buddies = g_strsplit(split[1], ",", -1); | 426 g_strfreev(lines); |
411 for (bud = buddies; bud && *bud; bud++) | 427 break; |
412 if (!(b = gaim_find_buddy(gc->account, *bud))) { | 428 case 88: |
413 if (!(g = gaim_find_group(split[0]))) { | 429 buddies = g_strsplit(pair->value, ",", -1); |
414 g = gaim_group_new(split[0]); | 430 for (bud = buddies; bud && *bud; bud++) { |
415 gaim_blist_add_group(g, NULL); | 431 /* The server is already ignoring the user */ |
416 } | 432 got_serv_list = TRUE; |
417 b = gaim_buddy_new(gc->account, *bud, NULL); | 433 gaim_privacy_deny_add(gc->account, *bud, 1); |
418 gaim_blist_add_buddy(b, NULL, g, NULL); | 434 } |
419 export = TRUE; | |
420 } | |
421 g_strfreev(buddies); | 435 g_strfreev(buddies); |
422 g_strfreev(split); | 436 break; |
423 } | 437 } |
424 g_strfreev(lines); | 438 |
439 if (got_serv_list) { | |
440 gc->account->perm_deny = 4; | |
441 serv_set_permit_deny(gc); | |
442 } | |
425 } | 443 } |
426 | 444 |
427 if (export) | 445 if (export) |
428 gaim_blist_save(); | 446 gaim_blist_save(); |
429 } | 447 } |
798 | 816 |
799 yahoo_packet_free(pack); | 817 yahoo_packet_free(pack); |
800 } | 818 } |
801 } | 819 } |
802 | 820 |
821 static void ignore_buddy(GaimBuddy *b) { | |
822 GaimGroup *g; | |
823 GaimConversation *c; | |
824 GaimAccount *account; | |
825 gchar *name; | |
826 | |
827 if (!b) | |
828 return; | |
829 | |
830 g = gaim_find_buddys_group(b); | |
831 name = g_strdup(b->name); | |
832 account = b->account; | |
833 | |
834 gaim_debug(GAIM_DEBUG_INFO, "blist", | |
835 "Removing '%s' from buddy list.\n", b->name); | |
836 serv_remove_buddy(account->gc, name, g->name); | |
837 gaim_blist_remove_buddy(b); | |
838 | |
839 gaim_privacy_deny_add(account, name, 0); | |
840 | |
841 gaim_blist_save(); | |
842 | |
843 c = gaim_find_conversation_with_account(name, account); | |
844 | |
845 if (c != NULL) | |
846 gaim_conversation_update(c, GAIM_CONV_UPDATE_REMOVE); | |
847 | |
848 g_free(name); | |
849 } | |
850 | |
851 static void keep_buddy(GaimBuddy *b) { | |
852 gaim_privacy_deny_remove(b->account, b->name, 1); | |
853 } | |
854 | |
855 static void yahoo_process_ignore(GaimConnection *gc, struct yahoo_packet *pkt) { | |
856 GaimBuddy *b; | |
857 GSList *l; | |
858 gchar *who = NULL; | |
859 gchar *sn = NULL; | |
860 gchar buf[BUF_LONG]; | |
861 gint ignore = 0; | |
862 gint status = 0; | |
863 | |
864 for (l = pkt->hash; l; l = l->next) { | |
865 struct yahoo_pair *pair = l->data; | |
866 switch (pair->key) { | |
867 case 0: | |
868 who = pair->value; | |
869 break; | |
870 case 1: | |
871 sn = pair->value; | |
872 break; | |
873 case 13: | |
874 ignore = strtol(pair->value, NULL, 10); | |
875 break; | |
876 case 66: | |
877 status = strtol(pair->value, NULL, 10); | |
878 break; | |
879 default: | |
880 break; | |
881 } | |
882 } | |
883 | |
884 switch (status) { | |
885 case 12: | |
886 b = gaim_find_buddy(gc->account, who); | |
887 g_snprintf(buf, sizeof(buf), _("You have tried to ignore %s, but the " | |
888 "user is on your buddy list. Clicking \"Yes\" " | |
889 "will remove and ignore the buddy."), who); | |
890 gaim_request_yes_no(gc, NULL, _("Ignore buddy?"), buf, 0, b, | |
891 G_CALLBACK(ignore_buddy), | |
892 G_CALLBACK(keep_buddy)); | |
893 break; | |
894 case 2: | |
895 case 3: | |
896 case 0: | |
897 default: | |
898 break; | |
899 } | |
900 } | |
901 | |
803 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) | 902 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) |
804 { | 903 { |
805 switch (pkt->service) | 904 switch (pkt->service) { |
806 { | |
807 case YAHOO_SERVICE_LOGON: | 905 case YAHOO_SERVICE_LOGON: |
808 case YAHOO_SERVICE_LOGOFF: | 906 case YAHOO_SERVICE_LOGOFF: |
809 case YAHOO_SERVICE_ISAWAY: | 907 case YAHOO_SERVICE_ISAWAY: |
810 case YAHOO_SERVICE_ISBACK: | 908 case YAHOO_SERVICE_ISBACK: |
811 case YAHOO_SERVICE_GAMELOGON: | 909 case YAHOO_SERVICE_GAMELOGON: |
831 case YAHOO_SERVICE_LIST: | 929 case YAHOO_SERVICE_LIST: |
832 yahoo_process_list(gc, pkt); | 930 yahoo_process_list(gc, pkt); |
833 break; | 931 break; |
834 case YAHOO_SERVICE_AUTH: | 932 case YAHOO_SERVICE_AUTH: |
835 yahoo_process_auth(gc, pkt); | 933 yahoo_process_auth(gc, pkt); |
934 break; | |
935 case YAHOO_SERVICE_IGNORECONTACT: | |
936 yahoo_process_ignore(gc, pkt); | |
836 break; | 937 break; |
837 case YAHOO_SERVICE_CONFINVITE: | 938 case YAHOO_SERVICE_CONFINVITE: |
838 case YAHOO_SERVICE_CONFADDINVITE: | 939 case YAHOO_SERVICE_CONFADDINVITE: |
839 yahoo_process_conference_invite(gc, pkt); | 940 yahoo_process_conference_invite(gc, pkt); |
840 break; | 941 break; |
1438 yahoo_packet_hash(pkt, 65, group); | 1539 yahoo_packet_hash(pkt, 65, group); |
1439 yahoo_send_packet(yd, pkt); | 1540 yahoo_send_packet(yd, pkt); |
1440 yahoo_packet_free(pkt); | 1541 yahoo_packet_free(pkt); |
1441 } | 1542 } |
1442 | 1543 |
1544 static void yahoo_add_deny(GaimConnection *gc, const char *who) { | |
1545 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1546 struct yahoo_packet *pkt; | |
1547 | |
1548 if (!yd->logged_in) | |
1549 return; | |
1550 | |
1551 if (gc->account->perm_deny != 4) | |
1552 return; | |
1553 | |
1554 if (!who || who[0] == '\0') | |
1555 return; | |
1556 | |
1557 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | |
1558 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
1559 yahoo_packet_hash(pkt, 7, who); | |
1560 yahoo_packet_hash(pkt, 13, "1"); | |
1561 yahoo_send_packet(yd, pkt); | |
1562 yahoo_packet_free(pkt); | |
1563 } | |
1564 | |
1565 static void yahoo_rem_deny(GaimConnection *gc, const char *who) { | |
1566 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1567 struct yahoo_packet *pkt; | |
1568 | |
1569 if (!yd->logged_in) | |
1570 return; | |
1571 | |
1572 if (!who || who[0] == '\0') | |
1573 return; | |
1574 | |
1575 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | |
1576 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
1577 yahoo_packet_hash(pkt, 7, who); | |
1578 yahoo_packet_hash(pkt, 13, "2"); | |
1579 yahoo_send_packet(yd, pkt); | |
1580 yahoo_packet_free(pkt); | |
1581 } | |
1582 | |
1583 static void yahoo_set_permit_deny(GaimConnection *gc) { | |
1584 GaimAccount *acct; | |
1585 GSList *deny; | |
1586 | |
1587 acct = gc->account; | |
1588 | |
1589 switch (acct->perm_deny) { | |
1590 case 1: | |
1591 case 3: | |
1592 case 5: | |
1593 for (deny = acct->deny;deny;deny = deny->next) | |
1594 yahoo_rem_deny(gc, deny->data); | |
1595 break; | |
1596 case 4: | |
1597 for (deny = acct->deny;deny;deny = deny->next) | |
1598 yahoo_add_deny(gc, deny->data); | |
1599 break; | |
1600 case 2: | |
1601 default: | |
1602 break; | |
1603 } | |
1604 } | |
1605 | |
1443 static gboolean yahoo_unload_plugin(GaimPlugin *plugin) | 1606 static gboolean yahoo_unload_plugin(GaimPlugin *plugin) |
1444 { | 1607 { |
1445 yahoo_dest_colorht(); | 1608 yahoo_dest_colorht(); |
1446 return TRUE; | 1609 return TRUE; |
1447 } | 1610 } |
1647 yahoo_add_buddy, | 1810 yahoo_add_buddy, |
1648 NULL, /* add_buddies */ | 1811 NULL, /* add_buddies */ |
1649 yahoo_remove_buddy, | 1812 yahoo_remove_buddy, |
1650 NULL, /*remove_buddies */ | 1813 NULL, /*remove_buddies */ |
1651 NULL, /* add_permit */ | 1814 NULL, /* add_permit */ |
1652 NULL, /* add_dey */ | 1815 yahoo_add_deny, |
1653 NULL, /* rem_permit */ | 1816 NULL, /* rem_permit */ |
1654 NULL, /* rem_deny */ | 1817 yahoo_rem_deny, |
1655 NULL, /* set_permit_deny */ | 1818 yahoo_set_permit_deny, |
1656 NULL, /* warn */ | 1819 NULL, /* warn */ |
1657 yahoo_c_join, | 1820 yahoo_c_join, |
1658 yahoo_c_invite, | 1821 yahoo_c_invite, |
1659 yahoo_c_leave, | 1822 yahoo_c_leave, |
1660 NULL, /* chat whisper */ | 1823 NULL, /* chat whisper */ |