comparison libpurple/protocols/yahoo/yahoochat.c @ 32672:3828a61c44da

A boring and large patch so I can merge heads.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 23 Dec 2011 08:21:58 +0000
parents a8cc50c2279f
children
comparison
equal deleted inserted replaced
32671:0e69949b3e61 32672:3828a61c44da
51 static void yahoo_chat_leave(PurpleConnection *gc, const char *room, const char *dn, gboolean logout); 51 static void yahoo_chat_leave(PurpleConnection *gc, const char *room, const char *dn, gboolean logout);
52 52
53 /* special function to log us on to the yahoo chat service */ 53 /* special function to log us on to the yahoo chat service */
54 static void yahoo_chat_online(PurpleConnection *gc) 54 static void yahoo_chat_online(PurpleConnection *gc)
55 { 55 {
56 YahooData *yd = gc->proto_data; 56 YahooData *yd = purple_connection_get_protocol_data(gc);
57 struct yahoo_packet *pkt; 57 struct yahoo_packet *pkt;
58 const char *rll; 58 const char *rll;
59 59
60 if (yd->wm) { 60 if (yd->wm) {
61 ycht_connection_open(gc); 61 ycht_connection_open(gc);
99 static PurpleConversation *yahoo_find_conference(PurpleConnection *gc, const char *name) 99 static PurpleConversation *yahoo_find_conference(PurpleConnection *gc, const char *name)
100 { 100 {
101 YahooData *yd; 101 YahooData *yd;
102 GSList *l; 102 GSList *l;
103 103
104 yd = gc->proto_data; 104 yd = purple_connection_get_protocol_data(gc);
105 105
106 for (l = yd->confs; l; l = l->next) { 106 for (l = yd->confs; l; l = l->next) {
107 PurpleConversation *c = l->data; 107 PurpleConversation *c = l->data;
108 if (!purple_utf8_strcasecmp(purple_conversation_get_name(c), name)) 108 if (!purple_utf8_strcasecmp(purple_conversation_get_name(c), name))
109 return c; 109 return c;
370 g_free(room); 370 g_free(room);
371 } 371 }
372 372
373 static void yahoo_chat_join(PurpleConnection *gc, const char *dn, const char *room, const char *topic, const char *id) 373 static void yahoo_chat_join(PurpleConnection *gc, const char *dn, const char *room, const char *topic, const char *id)
374 { 374 {
375 YahooData *yd = gc->proto_data; 375 YahooData *yd = purple_connection_get_protocol_data(gc);
376 struct yahoo_packet *pkt; 376 struct yahoo_packet *pkt;
377 char *room2; 377 char *room2;
378 gboolean utf8 = TRUE; 378 gboolean utf8 = TRUE;
379 379
380 if (yd->wm) { 380 if (yd->wm) {
398 } 398 }
399 399
400 /* this is a confirmation of yahoo_chat_online(); */ 400 /* this is a confirmation of yahoo_chat_online(); */
401 void yahoo_process_chat_online(PurpleConnection *gc, struct yahoo_packet *pkt) 401 void yahoo_process_chat_online(PurpleConnection *gc, struct yahoo_packet *pkt)
402 { 402 {
403 YahooData *yd = (YahooData *) gc->proto_data; 403 YahooData *yd = purple_connection_get_protocol_data(gc);
404 404
405 if (pkt->status == 1) { 405 if (pkt->status == 1) {
406 yd->chat_online = TRUE; 406 yd->chat_online = TRUE;
407 407
408 /* We need to goto a user in chat */ 408 /* We need to goto a user in chat */
430 } 430 }
431 431
432 /* this is basicly the opposite of chat_online */ 432 /* this is basicly the opposite of chat_online */
433 void yahoo_process_chat_logout(PurpleConnection *gc, struct yahoo_packet *pkt) 433 void yahoo_process_chat_logout(PurpleConnection *gc, struct yahoo_packet *pkt)
434 { 434 {
435 YahooData *yd = (YahooData *) gc->proto_data; 435 YahooData *yd = purple_connection_get_protocol_data(gc);
436 GSList *l; 436 GSList *l;
437 437
438 for (l = pkt->hash; l; l = l->next) { 438 for (l = pkt->hash; l; l = l->next) {
439 struct yahoo_pair *pair = l->data; 439 struct yahoo_pair *pair = l->data;
440 440
460 } 460 }
461 461
462 void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt) 462 void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt)
463 { 463 {
464 PurpleAccount *account = purple_connection_get_account(gc); 464 PurpleAccount *account = purple_connection_get_account(gc);
465 YahooData *yd = (YahooData *) gc->proto_data; 465 YahooData *yd = purple_connection_get_protocol_data(gc);
466 PurpleConversation *c = NULL; 466 PurpleConversation *c = NULL;
467 GSList *l; 467 GSList *l;
468 GList *members = NULL; 468 GList *members = NULL;
469 GList *roomies = NULL; 469 GList *roomies = NULL;
470 char *room = NULL; 470 char *room = NULL;
784 } 784 }
785 785
786 static int yahoo_conf_send(PurpleConnection *gc, const char *dn, const char *room, 786 static int yahoo_conf_send(PurpleConnection *gc, const char *dn, const char *room,
787 GList *members, const char *what) 787 GList *members, const char *what)
788 { 788 {
789 YahooData *yd = gc->proto_data; 789 YahooData *yd = purple_connection_get_protocol_data(gc);
790 struct yahoo_packet *pkt; 790 struct yahoo_packet *pkt;
791 GList *who; 791 GList *who;
792 char *msg, *msg2; 792 char *msg, *msg2;
793 int utf8 = 1; 793 int utf8 = 1;
794 794
841 } 841 }
842 842
843 static void yahoo_conf_invite(PurpleConnection *gc, PurpleConversation *c, 843 static void yahoo_conf_invite(PurpleConnection *gc, PurpleConversation *c,
844 const char *dn, const char *buddy, const char *room, const char *msg) 844 const char *dn, const char *buddy, const char *room, const char *msg)
845 { 845 {
846 YahooData *yd = gc->proto_data; 846 YahooData *yd = purple_connection_get_protocol_data(gc);
847 struct yahoo_packet *pkt; 847 struct yahoo_packet *pkt;
848 GList *members; 848 GList *members;
849 char *msg2 = NULL; 849 char *msg2 = NULL;
850 850
851 if (msg) 851 if (msg)
871 * Functions dealing with chats 871 * Functions dealing with chats
872 */ 872 */
873 873
874 static void yahoo_chat_leave(PurpleConnection *gc, const char *room, const char *dn, gboolean logout) 874 static void yahoo_chat_leave(PurpleConnection *gc, const char *room, const char *dn, gboolean logout)
875 { 875 {
876 YahooData *yd = gc->proto_data; 876 YahooData *yd = purple_connection_get_protocol_data(gc);
877 struct yahoo_packet *pkt; 877 struct yahoo_packet *pkt;
878 878
879 char *eroom; 879 char *eroom;
880 gboolean utf8 = 1; 880 gboolean utf8 = 1;
881 881
922 g_free(eroom); 922 g_free(eroom);
923 } 923 }
924 924
925 static int yahoo_chat_send(PurpleConnection *gc, const char *dn, const char *room, const char *what, PurpleMessageFlags flags) 925 static int yahoo_chat_send(PurpleConnection *gc, const char *dn, const char *room, const char *what, PurpleMessageFlags flags)
926 { 926 {
927 YahooData *yd = gc->proto_data; 927 YahooData *yd = purple_connection_get_protocol_data(gc);
928 struct yahoo_packet *pkt; 928 struct yahoo_packet *pkt;
929 int me = 0; 929 int me = 0;
930 char *msg1, *msg2, *room2; 930 char *msg1, *msg2, *room2;
931 gboolean utf8 = TRUE; 931 gboolean utf8 = TRUE;
932 932
967 967
968 968
969 static void yahoo_chat_invite(PurpleConnection *gc, const char *dn, const char *buddy, 969 static void yahoo_chat_invite(PurpleConnection *gc, const char *dn, const char *buddy,
970 const char *room, const char *msg) 970 const char *room, const char *msg)
971 { 971 {
972 YahooData *yd = gc->proto_data; 972 YahooData *yd = purple_connection_get_protocol_data(gc);
973 struct yahoo_packet *pkt; 973 struct yahoo_packet *pkt;
974 char *room2, *msg2 = NULL; 974 char *room2, *msg2 = NULL;
975 gboolean utf8 = TRUE; 975 gboolean utf8 = TRUE;
976 976
977 if (yd->wm) { 977 if (yd->wm) {
995 void yahoo_chat_goto(PurpleConnection *gc, const char *name) 995 void yahoo_chat_goto(PurpleConnection *gc, const char *name)
996 { 996 {
997 YahooData *yd; 997 YahooData *yd;
998 struct yahoo_packet *pkt; 998 struct yahoo_packet *pkt;
999 999
1000 yd = gc->proto_data; 1000 yd = purple_connection_get_protocol_data(gc);
1001 1001
1002 if (yd->wm) { 1002 if (yd->wm) {
1003 g_return_if_fail(yd->ycht != NULL); 1003 g_return_if_fail(yd->ycht != NULL);
1004 ycht_chat_goto_user(yd->ycht, name); 1004 ycht_chat_goto_user(yd->ycht, name);
1005 return; 1005 return;
1027 * which get called for both chats and conferences. 1027 * which get called for both chats and conferences.
1028 */ 1028 */
1029 1029
1030 void yahoo_c_leave(PurpleConnection *gc, int id) 1030 void yahoo_c_leave(PurpleConnection *gc, int id)
1031 { 1031 {
1032 YahooData *yd = (YahooData *) gc->proto_data; 1032 YahooData *yd = purple_connection_get_protocol_data(gc);
1033 PurpleConversation *c; 1033 PurpleConversation *c;
1034 1034
1035 if (!yd) 1035 if (!yd)
1036 return; 1036 return;
1037 1037
1054 { 1054 {
1055 PurpleConversation *c; 1055 PurpleConversation *c;
1056 int ret; 1056 int ret;
1057 YahooData *yd; 1057 YahooData *yd;
1058 1058
1059 yd = (YahooData *) gc->proto_data; 1059 yd = purple_connection_get_protocol_data(gc);
1060 if (!yd) 1060 if (!yd)
1061 return -1; 1061 return -1;
1062 1062
1063 c = purple_find_chat(gc, id); 1063 c = purple_find_chat(gc, id);
1064 if (!c) 1064 if (!c)
1112 { 1112 {
1113 YahooData *yd; 1113 YahooData *yd;
1114 char *room, *topic, *type; 1114 char *room, *topic, *type;
1115 PurpleConversation *c; 1115 PurpleConversation *c;
1116 1116
1117 yd = (YahooData *) gc->proto_data; 1117 yd = purple_connection_get_protocol_data(gc);
1118 if (!yd) 1118 if (!yd)
1119 return; 1119 return;
1120 1120
1121 room = g_hash_table_lookup(data, "room"); 1121 room = g_hash_table_lookup(data, "room");
1122 if (!room) 1122 if (!room)
1164 void yahoo_c_invite(PurpleConnection *gc, int id, const char *msg, const char *name) 1164 void yahoo_c_invite(PurpleConnection *gc, int id, const char *msg, const char *name)
1165 { 1165 {
1166 PurpleConversation *c; 1166 PurpleConversation *c;
1167 1167
1168 c = purple_find_chat(gc, id); 1168 c = purple_find_chat(gc, id);
1169 if (!c || !c->name) 1169 if (!c || !purple_conversation_get_name(c))
1170 return; 1170 return;
1171 1171
1172 if (id != YAHOO_CHAT_ID) { 1172 if (id != YAHOO_CHAT_ID) {
1173 yahoo_conf_invite(gc, c, purple_connection_get_display_name(gc), name, 1173 yahoo_conf_invite(gc, c, purple_connection_get_display_name(gc), name,
1174 purple_conversation_get_name(c), msg); 1174 purple_conversation_get_name(c), msg);
1373 static void yahoo_roomlist_cleanup(PurpleRoomlist *list, struct yahoo_roomlist *yrl) 1373 static void yahoo_roomlist_cleanup(PurpleRoomlist *list, struct yahoo_roomlist *yrl)
1374 { 1374 {
1375 purple_roomlist_set_in_progress(list, FALSE); 1375 purple_roomlist_set_in_progress(list, FALSE);
1376 1376
1377 if (yrl) { 1377 if (yrl) {
1378 list->proto_data = g_list_remove(list->proto_data, yrl); 1378 GList *proto_data = purple_roomlist_get_proto_data(list);
1379 proto_data = g_list_remove(proto_data, yrl);
1380 purple_roomlist_set_proto_data(list, proto_data);
1379 yahoo_roomlist_destroy(yrl); 1381 yahoo_roomlist_destroy(yrl);
1380 } 1382 }
1381 1383
1382 purple_roomlist_unref(list); 1384 purple_roomlist_unref(list);
1383 } 1385 }
1449 else if (written <= 0) { 1451 else if (written <= 0) {
1450 purple_input_remove(yrl->inpa); 1452 purple_input_remove(yrl->inpa);
1451 yrl->inpa = 0; 1453 yrl->inpa = 0;
1452 g_free(yrl->txbuf); 1454 g_free(yrl->txbuf);
1453 yrl->txbuf = NULL; 1455 yrl->txbuf = NULL;
1454 purple_notify_error(purple_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); 1456 purple_notify_error(purple_account_get_connection(purple_roomlist_get_account(list)), NULL, _("Unable to connect"), _("Fetching the room list failed."));
1455 yahoo_roomlist_cleanup(list, yrl); 1457 yahoo_roomlist_cleanup(list, yrl);
1456 return; 1458 return;
1457 } 1459 }
1458 1460
1459 if (written < remaining) { 1461 if (written < remaining) {
1472 1474
1473 static void yahoo_roomlist_got_connected(gpointer data, gint source, const gchar *error_message) 1475 static void yahoo_roomlist_got_connected(gpointer data, gint source, const gchar *error_message)
1474 { 1476 {
1475 struct yahoo_roomlist *yrl = data; 1477 struct yahoo_roomlist *yrl = data;
1476 PurpleRoomlist *list = yrl->list; 1478 PurpleRoomlist *list = yrl->list;
1477 YahooData *yd = purple_account_get_connection(list->account)->proto_data; 1479 PurpleAccount *account = purple_roomlist_get_account(list);
1480 PurpleConnection *pc = purple_account_get_connection(account);
1481 YahooData *yd = purple_connection_get_protocol_data(pc);
1478 1482
1479 if (source < 0) { 1483 if (source < 0) {
1480 purple_notify_error(purple_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); 1484 purple_notify_error(pc, NULL, _("Unable to connect"), _("Fetching the room list failed."));
1481 yahoo_roomlist_cleanup(list, yrl); 1485 yahoo_roomlist_cleanup(list, yrl);
1482 return; 1486 return;
1483 } 1487 }
1484 1488
1485 yrl->fd = source; 1489 yrl->fd = source;
1504 PurpleRoomlistField *f; 1508 PurpleRoomlistField *f;
1505 GList *fields = NULL; 1509 GList *fields = NULL;
1506 struct yahoo_roomlist *yrl; 1510 struct yahoo_roomlist *yrl;
1507 const char *rll, *rlurl; 1511 const char *rll, *rlurl;
1508 char *url; 1512 char *url;
1513 GList *proto_data;
1509 1514
1510 account = purple_connection_get_account(gc); 1515 account = purple_connection_get_account(gc);
1511 1516
1512 /* for Yahoo Japan, it appears there is only one valid URL and locale */ 1517 /* for Yahoo Japan, it appears there is only one valid URL and locale */
1513 if(purple_account_get_bool(account, "yahoojp", FALSE)) { 1518 if(purple_account_get_bool(account, "yahoojp", FALSE)) {
1554 purple_notify_error(gc, NULL, _("Connection problem"), _("Unable to fetch room list.")); 1559 purple_notify_error(gc, NULL, _("Connection problem"), _("Unable to fetch room list."));
1555 yahoo_roomlist_cleanup(rl, yrl); 1560 yahoo_roomlist_cleanup(rl, yrl);
1556 return NULL; 1561 return NULL;
1557 } 1562 }
1558 1563
1559 rl->proto_data = g_list_append(rl->proto_data, yrl); 1564 proto_data = purple_roomlist_get_proto_data(rl);
1565 proto_data = g_list_append(proto_data, yrl);
1566 purple_roomlist_set_proto_data(rl, proto_data);
1560 1567
1561 purple_roomlist_set_in_progress(rl, TRUE); 1568 purple_roomlist_set_in_progress(rl, TRUE);
1562 return rl; 1569 return rl;
1563 } 1570 }
1564 1571
1565 void yahoo_roomlist_cancel(PurpleRoomlist *list) 1572 void yahoo_roomlist_cancel(PurpleRoomlist *list)
1566 { 1573 {
1567 GList *l, *k; 1574 GList *l, *k;
1568 1575
1569 k = l = list->proto_data; 1576 k = l = purple_roomlist_get_proto_data(list);
1570 list->proto_data = NULL; 1577 purple_roomlist_set_proto_data(list, NULL);
1571 1578
1572 purple_roomlist_set_in_progress(list, FALSE); 1579 purple_roomlist_set_in_progress(list, FALSE);
1573 1580
1574 for (; l; l = l->next) { 1581 for (; l; l = l->next) {
1575 yahoo_roomlist_destroy(l->data); 1582 yahoo_roomlist_destroy(l->data);
1578 g_list_free(k); 1585 g_list_free(k);
1579 } 1586 }
1580 1587
1581 void yahoo_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category) 1588 void yahoo_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category)
1582 { 1589 {
1590 PurpleAccount *account;
1583 struct yahoo_roomlist *yrl; 1591 struct yahoo_roomlist *yrl;
1584 char *url; 1592 char *url;
1585 char *id; 1593 char *id;
1586 const char *rll; 1594 const char *rll;
1587 1595 GList *proto_data;
1588 if (category->type != PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) 1596
1589 return; 1597 if (purple_roomlist_room_get_type(category) != PURPLE_ROOMLIST_ROOMTYPE_CATEGORY)
1590 1598 return;
1591 if (!(id = g_list_nth_data(category->fields, 1))) { 1599
1600 if (!(id = g_list_nth_data(purple_roomlist_room_get_fields(category), 1))) {
1592 purple_roomlist_set_in_progress(list, FALSE); 1601 purple_roomlist_set_in_progress(list, FALSE);
1593 return; 1602 return;
1594 } 1603 }
1595 1604
1596 rll = purple_account_get_string(list->account, "room_list_locale", 1605 account = purple_roomlist_get_account(list);
1606 rll = purple_account_get_string(account, "room_list_locale",
1597 YAHOO_ROOMLIST_LOCALE); 1607 YAHOO_ROOMLIST_LOCALE);
1598 1608
1599 if (rll != NULL && *rll != '\0') { 1609 if (rll != NULL && *rll != '\0') {
1600 url = g_strdup_printf("%s?chatroom_%s=0&intl=%s", 1610 url = g_strdup_printf("%s?chatroom_%s=0&intl=%s",
1601 purple_account_get_string(list->account,"room_list", 1611 purple_account_get_string(account,"room_list",
1602 YAHOO_ROOMLIST_URL), id, rll); 1612 YAHOO_ROOMLIST_URL), id, rll);
1603 } else { 1613 } else {
1604 url = g_strdup_printf("%s?chatroom_%s=0", 1614 url = g_strdup_printf("%s?chatroom_%s=0",
1605 purple_account_get_string(list->account,"room_list", 1615 purple_account_get_string(account,"room_list",
1606 YAHOO_ROOMLIST_URL), id); 1616 YAHOO_ROOMLIST_URL), id);
1607 } 1617 }
1608 1618
1609 yrl = g_new0(struct yahoo_roomlist, 1); 1619 yrl = g_new0(struct yahoo_roomlist, 1);
1610 yrl->list = list; 1620 yrl->list = list;
1611 yrl->cat = category; 1621 yrl->cat = category;
1612 list->proto_data = g_list_append(list->proto_data, yrl); 1622
1623 proto_data = purple_roomlist_get_proto_data(list);
1624 proto_data = g_list_append(proto_data, yrl);
1625 purple_roomlist_set_proto_data(list, proto_data);
1613 1626
1614 purple_url_parse(url, &(yrl->host), NULL, &(yrl->path), NULL, NULL); 1627 purple_url_parse(url, &(yrl->host), NULL, &(yrl->path), NULL, NULL);
1615 g_free(url); 1628 g_free(url);
1616 1629
1617 yrl->ucat = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_CATEGORY, _("User Rooms"), yrl->cat); 1630 yrl->ucat = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_CATEGORY, _("User Rooms"), yrl->cat);
1618 purple_roomlist_room_add(list, yrl->ucat); 1631 purple_roomlist_room_add(list, yrl->ucat);
1619 1632
1620 if (purple_proxy_connect(purple_account_get_connection(list->account), 1633 if (purple_proxy_connect(purple_account_get_connection(account),
1621 list->account, yrl->host, 80, 1634 account, yrl->host, 80,
1622 yahoo_roomlist_got_connected, yrl) == NULL) 1635 yahoo_roomlist_got_connected, yrl) == NULL)
1623 { 1636 {
1624 purple_notify_error(purple_account_get_connection(list->account), 1637 purple_notify_error(purple_account_get_connection(account),
1625 NULL, _("Connection problem"), _("Unable to fetch room list.")); 1638 NULL, _("Connection problem"), _("Unable to fetch room list."));
1626 purple_roomlist_ref(list); 1639 purple_roomlist_ref(list);
1627 yahoo_roomlist_cleanup(list, yrl); 1640 yahoo_roomlist_cleanup(list, yrl);
1628 return; 1641 return;
1629 } 1642 }