comparison src/protocols/yahoo/yahoo.c @ 9292:750d9b56a465

[gaim-migrate @ 10095] Some improvements to our yahoo buddy icon support. Someone should tell me how to unset a buddy icon for a buddy. Because the way KingAnt told me (which he wasn't sure about anyway) just produces a failed g_return thingy, and does nothing. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Tue, 15 Jun 2004 06:16:23 +0000
parents 7a8aa87164ae
children 04a3e9e869ee
comparison
equal deleted inserted replaced
9291:9da77e36d177 9292:750d9b56a465
42 #include "yahoo_filexfer.h" 42 #include "yahoo_filexfer.h"
43 #include "md5.h" 43 #include "md5.h"
44 44
45 extern char *yahoo_crypt(const char *, const char *); 45 extern char *yahoo_crypt(const char *, const char *);
46 46
47 #define YAHOO_ICON_CHECKSUM_KEY "icon_checksum"
47 /* #define YAHOO_DEBUG */ 48 /* #define YAHOO_DEBUG */
48 49
49 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *); 50 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *);
50 static void yahoo_send_buddy_icon_request(GaimConnection *gc, const char *who); 51 static void yahoo_send_buddy_icon_request(GaimConnection *gc, const char *who);
51 52
382 if (f) { 383 if (f) {
383 f->sms = strtol(pair->value, NULL, 10); 384 f->sms = strtol(pair->value, NULL, 10);
384 yahoo_update_status(gc, name, f); 385 yahoo_update_status(gc, name, f);
385 } 386 }
386 break; 387 break;
387 case 197: /* Avatars? */ 388 case 197: /* Avatars */
388 { 389 {
389 char *decoded, *tmp; 390 char *decoded, *tmp;
390 guint len; 391 guint len;
391 392
392 if (pair->value) { 393 if (pair->value) {
396 gaim_debug_info("yahoo", "Got key 197, value = %s\n", tmp); 397 gaim_debug_info("yahoo", "Got key 197, value = %s\n", tmp);
397 g_free(tmp); 398 g_free(tmp);
398 } 399 }
399 g_free(decoded); 400 g_free(decoded);
400 } 401 }
402 break;
403 }
404 case 192: /* Pictures, aka Buddy Icons, checksum */
405 {
406 int cksum = strtol(pair->value, NULL, 10);
407 GaimBuddy *b;
408
409 if (!name)
410 break;
411
412 if (!cksum || (cksum == -1)) {
413 gaim_buddy_icons_set_for_user(gc->account, name, NULL, 0);
414 break;
415 }
416
417 if (!f)
418 break;
419 b = gaim_find_buddy(gc->account, name);
420 yahoo_friend_set_buddy_icon_need_request(f, FALSE);
421 if (cksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))
422 yahoo_send_buddy_icon_request(gc, name);
423
401 break; 424 break;
402 } 425 }
403 case 16: /* Custom error message */ 426 case 16: /* Custom error message */
404 { 427 {
405 char *tmp = yahoo_string_decode(gc, pair->value, TRUE); 428 char *tmp = yahoo_string_decode(gc, pair->value, TRUE);
1855 }; 1878 };
1856 1879
1857 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len) 1880 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len)
1858 { 1881 {
1859 struct yahoo_fetch_picture_data *d = user_data; 1882 struct yahoo_fetch_picture_data *d = user_data;
1883 GaimBuddy *b;
1860 1884
1861 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) { 1885 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
1862 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, pic_data, len); 1886 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len);
1887 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who);
1888 if (b)
1889 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum);
1863 } 1890 }
1864 1891
1865 g_free(d->who); 1892 g_free(d->who);
1866 g_free(d); 1893 g_free(d);
1867 } 1894 }
1870 { 1897 {
1871 GSList *l = pkt->hash; 1898 GSList *l = pkt->hash;
1872 char *who = NULL, *us = NULL; 1899 char *who = NULL, *us = NULL;
1873 gboolean got_icon_info = FALSE; 1900 gboolean got_icon_info = FALSE;
1874 char *url = NULL; 1901 char *url = NULL;
1875 int checksum = 0; /* ?? */ 1902 int checksum = 0;
1876 1903
1877 while (l) { 1904 while (l) {
1878 struct yahoo_pair *pair = l->data; 1905 struct yahoo_pair *pair = l->data;
1879 1906
1880 switch (pair->key) { 1907 switch (pair->key) {
1904 } 1931 }
1905 1932
1906 l = l->next; 1933 l = l->next;
1907 } 1934 }
1908 1935
1909 if (got_icon_info && url) { 1936 if (who && got_icon_info && url) {
1910 /* TODO: make this work p2p, try p2p before the url, check the checksum 1937 /* TODO: make this work p2p, try p2p before the url */
1911 * (if that's what it is) before fetching the icon. 1938 struct yahoo_fetch_picture_data *data;
1912 */ 1939 GaimBuddy *b = gaim_find_buddy(gc->account, who);
1913 struct yahoo_fetch_picture_data *data = g_new0(struct yahoo_fetch_picture_data, 1); 1940 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
1914 data->gc = gc; 1941 return;
1915 data->who = g_strdup(who); 1942
1916 data->checksum = checksum; 1943 data = g_new0(struct yahoo_fetch_picture_data, 1);
1917 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, 1944 data->gc = gc;
1918 yahoo_fetch_picture_cb, data); 1945 data->who = g_strdup(who);
1919 } 1946 data->checksum = checksum;
1920 1947 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
1948 yahoo_fetch_picture_cb, data);
1949 }
1950
1951 }
1952
1953 static void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt)
1954 {
1955 GSList *l = pkt->hash;
1956 char *who = NULL;
1957 int icon = 0;
1958
1959 while (l) {
1960 struct yahoo_pair *pair = l->data;
1961
1962 switch (pair->key) {
1963 case 4:
1964 who = pair->value;
1965 break;
1966 case 5:
1967 /* us */
1968 break;
1969 case 206:
1970 icon = strtol(pair->value, NULL, 10);
1971 break;
1972 }
1973 l = l->next;
1974 }
1975
1976 if (who) {
1977 if (icon == 2)
1978 yahoo_send_buddy_icon_request(gc, who);
1979 else if (icon == 0)
1980 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0);
1981 }
1982 }
1983
1984 static void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt)
1985 {
1986 GSList *l = pkt->hash;
1987 char *who = NULL;
1988 int checksum = 0;
1989
1990 while (l) {
1991 struct yahoo_pair *pair = l->data;
1992
1993 switch (pair->key) {
1994 case 4:
1995 who = pair->value;
1996 break;
1997 case 5:
1998 /* us */
1999 break;
2000 case 192:
2001 checksum = strtol(pair->value, NULL, 10);
2002 break;
2003 }
2004 l = l->next;
2005 }
2006
2007 if (who) {
2008 GaimBuddy *b = gaim_find_buddy(gc->account, who);
2009 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
2010 yahoo_send_buddy_icon_request(gc, who);
2011 }
1921 } 2012 }
1922 2013
1923 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) 2014 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
1924 { 2015 {
1925 switch (pkt->service) { 2016 switch (pkt->service) {
2011 case YAHOO_SERVICE_PEEPTOPEER: 2102 case YAHOO_SERVICE_PEEPTOPEER:
2012 yahoo_process_p2p(gc, pkt); 2103 yahoo_process_p2p(gc, pkt);
2013 break; 2104 break;
2014 case YAHOO_SERVICE_PICTURE: 2105 case YAHOO_SERVICE_PICTURE:
2015 yahoo_process_picture(gc, pkt); 2106 yahoo_process_picture(gc, pkt);
2107 break;
2108 case YAHOO_SERVICE_PICTURE_UPDATE:
2109 yahoo_process_picture_update(gc, pkt);
2110 break;
2111 case YAHOO_SERVICE_PICTURE_CHECKSUM:
2112 yahoo_process_picture_checksum(gc, pkt);
2016 break; 2113 break;
2017 default: 2114 default:
2018 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", 2115 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
2019 "Unhandled service 0x%02x\n", pkt->service); 2116 "Unhandled service 0x%02x\n", pkt->service);
2020 break; 2117 break;