comparison src/protocols/yahoo/yahoo.c @ 9284:fe0291162312

[gaim-migrate @ 10087] Yahoo "picture" buddy icon support. It still kind of sucks, and you can't set your own yet. But expect it to improve. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Tue, 15 Jun 2004 01:17:16 +0000
parents 66ff39319900
children 7a8aa87164ae
comparison
equal deleted inserted replaced
9283:66ff39319900 9284:fe0291162312
45 extern char *yahoo_crypt(const char *, const char *); 45 extern char *yahoo_crypt(const char *, const char *);
46 46
47 /* #define YAHOO_DEBUG */ 47 /* #define YAHOO_DEBUG */
48 48
49 static void yahoo_add_buddy(GaimConnection *gc, const char *who, GaimGroup *); 49 static void yahoo_add_buddy(GaimConnection *gc, const char *who, GaimGroup *);
50 50 static void yahoo_send_buddy_icon_request(GaimConnection *gc, const char *who);
51 51
52 struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) 52 struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id)
53 { 53 {
54 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); 54 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1);
55 55
686 686
687 struct _yahoo_im { 687 struct _yahoo_im {
688 char *from; 688 char *from;
689 int time; 689 int time;
690 int utf8; 690 int utf8;
691 int buddy_icon;
691 char *msg; 692 char *msg;
692 }; 693 };
693 694
694 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt) 695 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt)
695 { 696 {
710 if (im) 711 if (im)
711 im->utf8 = strtol(pair->value, NULL, 10); 712 im->utf8 = strtol(pair->value, NULL, 10);
712 if (pair->key == 15) 713 if (pair->key == 15)
713 if (im) 714 if (im)
714 im->time = strtol(pair->value, NULL, 10); 715 im->time = strtol(pair->value, NULL, 10);
716 if (pair->key == 206)
717 if (im)
718 im->buddy_icon = strtol(pair->value, NULL, 10);
715 if (pair->key == 14) { 719 if (pair->key == 14) {
716 if (im) 720 if (im)
717 im->msg = pair->value; 721 im->msg = pair->value;
718 } 722 }
719 l = l->next; 723 l = l->next;
724 } 728 }
725 729
726 for (l = list; l; l = l->next) { 730 for (l = list; l; l = l->next) {
727 char *m, *m2; 731 char *m, *m2;
728 im = l->data; 732 im = l->data;
733 YahooFriend *f;
729 734
730 if (!im->from || !im->msg) { 735 if (!im->from || !im->msg) {
731 g_free(im); 736 g_free(im);
732 continue; 737 continue;
733 } 738 }
747 752
748 m2 = yahoo_codes_to_html(m); 753 m2 = yahoo_codes_to_html(m);
749 g_free(m); 754 g_free(m);
750 serv_got_im(gc, im->from, m2, 0, im->time); 755 serv_got_im(gc, im->from, m2, 0, im->time);
751 g_free(m2); 756 g_free(m2);
757
758 if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) {
759 if (yahoo_friend_get_buddy_icon_need_request(f)) {
760 yahoo_send_buddy_icon_request(gc, im->from);
761 yahoo_friend_set_buddy_icon_need_request(f, FALSE);
762 }
763 }
764
752 g_free(im); 765 g_free(im);
753 } 766 }
754 g_slist_free(list); 767 g_slist_free(list);
755 } 768 }
756 769
1842 yahoo_friend_set_ip(f, tmp2); 1855 yahoo_friend_set_ip(f, tmp2);
1843 g_free(tmp2); 1856 g_free(tmp2);
1844 } 1857 }
1845 } 1858 }
1846 1859
1860 struct yahoo_fetch_picture_data {
1861 GaimConnection *gc;
1862 char *who;
1863 int checksum;
1864 };
1865
1866 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len)
1867 {
1868 struct yahoo_fetch_picture_data *d = user_data;
1869
1870 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
1871 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, pic_data, len);
1872 }
1873
1874 g_free(d->who);
1875 g_free(d);
1876 }
1877
1878 static void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt)
1879 {
1880 GSList *l = pkt->hash;
1881 char *who = NULL, *us = NULL;
1882 gboolean got_icon_info = FALSE;
1883 char *url = NULL;
1884 int checksum = 0; /* ?? */
1885
1886 while (l) {
1887 struct yahoo_pair *pair = l->data;
1888
1889 switch (pair->key) {
1890 case 1:
1891 case 4:
1892 who = pair->value;
1893 break;
1894 case 5:
1895 us = pair->value;
1896 break;
1897 case 13: {
1898 int tmp;
1899 tmp = strtol(pair->value, NULL, 10);
1900 if (tmp == 1) {
1901 /* send them info about our buddy icon */
1902 } else if (tmp == 2) {
1903 got_icon_info = TRUE;
1904 }
1905 break;
1906 }
1907 case 20:
1908 url = pair->value;
1909 break;
1910 case 192:
1911 checksum = strtol(pair->value, NULL, 10); /* just a guess for now */
1912 break;
1913 }
1914
1915 l = l->next;
1916 }
1917
1918 if (got_icon_info && url) {
1919 /* TODO: make this work p2p, try p2p before the url, check the checksum
1920 * (if that's what it is) before fetching the icon.
1921 */
1922 struct yahoo_fetch_picture_data *data = g_new0(struct yahoo_fetch_picture_data, 1);
1923 data->gc = gc;
1924 data->who = g_strdup(who);
1925 data->checksum = checksum;
1926 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
1927 yahoo_fetch_picture_cb, data);
1928 }
1929
1930 }
1931
1847 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) 1932 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
1848 { 1933 {
1849 switch (pkt->service) { 1934 switch (pkt->service) {
1850 case YAHOO_SERVICE_LOGON: 1935 case YAHOO_SERVICE_LOGON:
1851 case YAHOO_SERVICE_LOGOFF: 1936 case YAHOO_SERVICE_LOGOFF:
1932 case YAHOO_SERVICE_FILETRANSFER: 2017 case YAHOO_SERVICE_FILETRANSFER:
1933 yahoo_process_filetransfer(gc, pkt); 2018 yahoo_process_filetransfer(gc, pkt);
1934 break; 2019 break;
1935 case YAHOO_SERVICE_PEEPTOPEER: 2020 case YAHOO_SERVICE_PEEPTOPEER:
1936 yahoo_process_p2p(gc, pkt); 2021 yahoo_process_p2p(gc, pkt);
2022 break;
2023 case YAHOO_SERVICE_PICTURE:
2024 yahoo_process_picture(gc, pkt);
1937 break; 2025 break;
1938 default: 2026 default:
1939 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", 2027 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
1940 "Unhandled service 0x%02x\n", pkt->service); 2028 "Unhandled service 0x%02x\n", pkt->service);
1941 break; 2029 break;
3074 yahoo_packet_hash(pkt, 67, gpn); 3162 yahoo_packet_hash(pkt, 67, gpn);
3075 yahoo_send_packet(yd, pkt); 3163 yahoo_send_packet(yd, pkt);
3076 yahoo_packet_free(pkt); 3164 yahoo_packet_free(pkt);
3077 g_free(gpn); 3165 g_free(gpn);
3078 g_free(gpo); 3166 g_free(gpo);
3167 }
3168
3169 static void yahoo_send_buddy_icon_request(GaimConnection *gc, const char *who)
3170 {
3171 struct yahoo_data *yd = gc->proto_data;
3172 struct yahoo_packet *pkt;
3173
3174 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
3175 yahoo_packet_hash(pkt, 4, gaim_connection_get_display_name(gc)); /* me */
3176 yahoo_packet_hash(pkt, 5, who); /* the other guy */
3177 yahoo_packet_hash(pkt, 13, "1"); /* 1 = request, 2 = reply */
3178 yahoo_send_packet(yd, pkt);
3179 yahoo_packet_free(pkt);
3079 } 3180 }
3080 3181
3081 #if 0 3182 #if 0
3082 static gboolean yahoo_has_send_file(GaimConnection *gc, const char *who) 3183 static gboolean yahoo_has_send_file(GaimConnection *gc, const char *who)
3083 { 3184 {