Tue, 26 Sep 2006 17:38:09 +0000
[gaim-migrate @ 17356]
After the comments on gaim-devel about 'bad' code, I looked into the function referenced. It appears that yahoo_buddy_icon_upload_connected() is only called as a callback. It's registered from yahoo_buddy_icon_upload(). yahoo_buddy_icon_upload() is only called twice. In neither case can a NULL make it down to yahoo_buddy_icon_upload_connected(). As this is an exceptional case rather than a normal one, a g_return_if_fail() is more appropriate. That adds logging, makes the intent clearer, and will help the Coverity software detect violations of this assumption.
| 9306 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | */ | |
| 23 | ||
| 24 | #include "internal.h" | |
| 25 | ||
| 26 | #include "account.h" | |
| 27 | #include "accountopt.h" | |
| 28 | #include "blist.h" | |
| 29 | #include "debug.h" | |
| 30 | #include "prpl.h" | |
| 31 | #include "proxy.h" | |
| 32 | #include "util.h" | |
| 33 | ||
| 34 | #include "yahoo.h" | |
| 10392 | 35 | #include "yahoo_packet.h" |
| 9306 | 36 | #include "yahoo_friend.h" |
| 37 | #include "yahoo_picture.h" | |
| 38 | ||
| 39 | ||
| 40 | struct yahoo_fetch_picture_data { | |
| 41 | GaimConnection *gc; | |
| 42 | char *who; | |
| 43 | int checksum; | |
| 44 | }; | |
| 45 | ||
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
46 | static void |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
47 | yahoo_fetch_picture_cb(GaimUtilFetchUrlData *url_data, gpointer user_data, |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
48 | const gchar *pic_data, size_t len, const gchar *error_message) |
| 9306 | 49 | { |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
50 | struct yahoo_fetch_picture_data *d; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
51 | struct yahoo_data *yd; |
| 9306 | 52 | GaimBuddy *b; |
| 53 | ||
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
54 | d = user_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
55 | yd = d->gc->proto_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
56 | yd->url_datas = g_slist_remove(yd->url_datas, url_data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
57 | |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
58 | if (error_message != NULL) { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
59 | gaim_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
60 | } else if (len == 0) { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
61 | gaim_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
62 | } else { |
| 9306 | 63 | gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len); |
| 64 | b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who); | |
| 65 | if (b) | |
| 66 | gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); | |
| 67 | } | |
| 68 | ||
| 69 | g_free(d->who); | |
| 70 | g_free(d); | |
| 71 | } | |
| 72 | ||
| 73 | void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 74 | { | |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
75 | struct yahoo_data *yd; |
| 9306 | 76 | GSList *l = pkt->hash; |
| 77 | char *who = NULL, *us = NULL; | |
| 78 | gboolean got_icon_info = FALSE, send_icon_info = FALSE; | |
| 79 | char *url = NULL; | |
| 80 | int checksum = 0; | |
| 81 | ||
| 82 | while (l) { | |
| 83 | struct yahoo_pair *pair = l->data; | |
| 84 | ||
| 85 | switch (pair->key) { | |
| 86 | case 1: | |
| 87 | case 4: | |
| 88 | who = pair->value; | |
| 89 | break; | |
| 90 | case 5: | |
| 91 | us = pair->value; | |
| 92 | break; | |
| 93 | case 13: { | |
| 94 | int tmp; | |
| 95 | tmp = strtol(pair->value, NULL, 10); | |
| 96 | if (tmp == 1) { | |
| 97 | send_icon_info = TRUE; | |
| 98 | } else if (tmp == 2) { | |
| 99 | got_icon_info = TRUE; | |
| 100 | } | |
| 101 | break; | |
| 102 | } | |
| 103 | case 20: | |
| 104 | url = pair->value; | |
| 105 | break; | |
| 106 | case 192: | |
| 107 | checksum = strtol(pair->value, NULL, 10); | |
| 108 | break; | |
| 109 | } | |
| 110 | ||
| 111 | l = l->next; | |
| 112 | } | |
| 113 | ||
|
9675
127db3bbb4f2
[gaim-migrate @ 10527]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9329
diff
changeset
|
114 | /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ |
|
127db3bbb4f2
[gaim-migrate @ 10527]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9329
diff
changeset
|
115 | if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { |
| 9306 | 116 | /* TODO: make this work p2p, try p2p before the url */ |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
117 | GaimUtilFetchUrlData *url_data; |
| 9306 | 118 | struct yahoo_fetch_picture_data *data; |
| 119 | GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
| 120 | if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
| 121 | return; | |
| 122 | ||
| 123 | data = g_new0(struct yahoo_fetch_picture_data, 1); | |
| 124 | data->gc = gc; | |
| 125 | data->who = g_strdup(who); | |
| 126 | data->checksum = checksum; | |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
127 | url_data = gaim_util_fetch_url(url, FALSE, |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
128 | "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
129 | yahoo_fetch_picture_cb, data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
130 | if (url_data != NULL) { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
131 | yd = gc->proto_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
132 | yd->url_datas = g_slist_prepend(yd->url_datas, url_data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
133 | } else { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
134 | g_free(data->who); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
135 | g_free(data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
136 | } |
| 9306 | 137 | } else if (who && send_icon_info) { |
| 138 | yahoo_send_picture_info(gc, who); | |
| 139 | } | |
| 140 | } | |
| 141 | ||
| 142 | void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 143 | { | |
| 144 | GSList *l = pkt->hash; | |
| 145 | char *who = NULL; | |
| 146 | int icon = 0; | |
| 147 | ||
| 148 | while (l) { | |
| 149 | struct yahoo_pair *pair = l->data; | |
| 150 | ||
| 151 | switch (pair->key) { | |
| 152 | case 4: | |
| 153 | who = pair->value; | |
| 154 | break; | |
| 155 | case 5: | |
| 156 | /* us */ | |
| 157 | break; | |
| 158 | case 206: | |
| 159 | icon = strtol(pair->value, NULL, 10); | |
| 160 | break; | |
| 161 | } | |
| 162 | l = l->next; | |
| 163 | } | |
| 164 | ||
| 165 | if (who) { | |
| 166 | if (icon == 2) | |
| 9310 | 167 | yahoo_send_picture_request(gc, who); |
| 9322 | 168 | else if ((icon == 0) || (icon == 1)) { |
| 9325 | 169 | GaimBuddy *b = gaim_find_buddy(gc->account, who); |
| 170 | YahooFriend *f; | |
| 9306 | 171 | gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
| 9325 | 172 | if (b) |
| 173 | gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | |
| 174 | if ((f = yahoo_friend_find(gc, who))) | |
| 175 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
| 9322 | 176 | gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
| 177 | } | |
| 9306 | 178 | } |
| 179 | } | |
| 180 | ||
| 181 | void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 182 | { | |
| 183 | GSList *l = pkt->hash; | |
| 184 | char *who = NULL; | |
| 185 | int checksum = 0; | |
| 186 | ||
| 187 | while (l) { | |
| 188 | struct yahoo_pair *pair = l->data; | |
| 189 | ||
| 190 | switch (pair->key) { | |
| 191 | case 4: | |
| 192 | who = pair->value; | |
| 193 | break; | |
| 194 | case 5: | |
| 195 | /* us */ | |
| 196 | break; | |
| 197 | case 192: | |
| 198 | checksum = strtol(pair->value, NULL, 10); | |
| 199 | break; | |
| 200 | } | |
| 201 | l = l->next; | |
| 202 | } | |
| 203 | ||
| 204 | if (who) { | |
| 205 | GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
| 206 | if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
| 9310 | 207 | yahoo_send_picture_request(gc, who); |
| 9306 | 208 | } |
| 209 | } | |
| 210 | ||
| 211 | void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 212 | { | |
| 213 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 214 | struct yahoo_data *yd = gc->proto_data; | |
| 215 | GSList *l = pkt->hash; | |
| 216 | char *url = NULL; | |
| 217 | ||
| 218 | while (l) { | |
| 219 | struct yahoo_pair *pair = l->data; | |
| 220 | ||
| 221 | switch (pair->key) { | |
| 222 | case 5: | |
| 223 | /* us */ | |
| 224 | break; | |
| 225 | case 27: | |
| 226 | /* filename on our computer. */ | |
| 227 | break; | |
| 228 | case 20: /* url at yahoo */ | |
| 229 | url = pair->value; | |
| 230 | case 38: /* timestamp */ | |
| 231 | break; | |
| 232 | } | |
| 233 | l = l->next; | |
| 234 | } | |
| 235 | ||
| 236 | if (url) { | |
| 237 | if (yd->picture_url) | |
| 238 | g_free(yd->picture_url); | |
| 239 | yd->picture_url = g_strdup(url); | |
| 240 | gaim_account_set_string(account, YAHOO_PICURL_SETTING, url); | |
| 241 | gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); | |
| 9310 | 242 | yahoo_send_picture_update(gc, 2); |
| 243 | yahoo_send_picture_checksum(gc); | |
| 9306 | 244 | } |
| 245 | } | |
| 246 | ||
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
247 | void yahoo_process_avatar_update(GaimConnection *gc, struct yahoo_packet *pkt) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
248 | { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
249 | GSList *l = pkt->hash; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
250 | char *who = NULL; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
251 | int avatar = 0; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
252 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
253 | while (l) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
254 | struct yahoo_pair *pair = l->data; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
255 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
256 | switch (pair->key) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
257 | case 4: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
258 | who = pair->value; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
259 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
260 | case 5: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
261 | /* us */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
262 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
263 | case 206: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
264 | /* |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
265 | * 0 - No icon or avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
266 | * 1 - Using an avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
267 | * 2 - Using an icon |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
268 | */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
269 | avatar = strtol(pair->value, NULL, 10); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
270 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
271 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
272 | l = l->next; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
273 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
274 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
275 | if (who) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
276 | if (avatar == 2) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
277 | yahoo_send_picture_request(gc, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
278 | else if ((avatar == 0) || (avatar == 1)) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
279 | GaimBuddy *b = gaim_find_buddy(gc->account, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
280 | YahooFriend *f; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
281 | gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
282 | if (b) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
283 | gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
284 | if ((f = yahoo_friend_find(gc, who))) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
285 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
286 | gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
287 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
288 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
289 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
290 | |
| 9322 | 291 | void yahoo_send_picture_info(GaimConnection *gc, const char *who) |
| 292 | { | |
| 293 | struct yahoo_data *yd = gc->proto_data; | |
| 294 | struct yahoo_packet *pkt; | |
| 295 | ||
| 9329 | 296 | if (!yd->picture_url) { |
| 297 | gaim_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); | |
| 9322 | 298 | return; |
| 9329 | 299 | } |
| 9322 | 300 | |
| 301 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 10394 | 302 | yahoo_packet_hash(pkt, "sssssi", 1, gaim_connection_get_display_name(gc), |
| 303 | 4, gaim_connection_get_display_name(gc), 5, who, | |
| 304 | 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); | |
| 10392 | 305 | yahoo_packet_send_and_free(pkt, yd); |
| 9322 | 306 | } |
| 9306 | 307 | |
| 9310 | 308 | void yahoo_send_picture_request(GaimConnection *gc, const char *who) |
| 9306 | 309 | { |
| 310 | struct yahoo_data *yd = gc->proto_data; | |
| 311 | struct yahoo_packet *pkt; | |
| 312 | ||
| 313 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 10394 | 314 | yahoo_packet_hash_str(pkt, 4, gaim_connection_get_display_name(gc)); /* me */ |
| 315 | yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ | |
| 316 | yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | |
| 10392 | 317 | yahoo_packet_send_and_free(pkt, yd); |
| 9306 | 318 | } |
| 319 | ||
| 9310 | 320 | void yahoo_send_picture_checksum(GaimConnection *gc) |
| 321 | { | |
| 322 | struct yahoo_data *yd = gc->proto_data; | |
| 323 | struct yahoo_packet *pkt; | |
| 324 | ||
| 325 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | |
|
11384
aa52418a603f
[gaim-migrate @ 13611]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
10651
diff
changeset
|
326 | yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), |
| 10394 | 327 | 212, "1", 192, yd->picture_checksum); |
| 10392 | 328 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 329 | } |
| 330 | ||
| 331 | void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type) | |
| 332 | { | |
| 333 | struct yahoo_data *yd = gc->proto_data; | |
| 334 | struct yahoo_packet *pkt; | |
| 335 | ||
| 336 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | |
|
11384
aa52418a603f
[gaim-migrate @ 13611]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
10651
diff
changeset
|
337 | yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), 5, who, 206, type); |
| 10392 | 338 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 339 | } |
| 340 | ||
| 341 | struct yspufe { | |
| 342 | GaimConnection *gc; | |
| 343 | int type; | |
| 344 | }; | |
| 345 | ||
| 346 | static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | |
| 347 | { | |
| 348 | char *who = key; | |
| 349 | YahooFriend *f = value; | |
| 350 | struct yspufe *d = data; | |
| 351 | ||
| 352 | if (f->status != YAHOO_STATUS_OFFLINE) | |
| 353 | yahoo_send_picture_update_to_user(d->gc, who, d->type); | |
| 354 | } | |
| 355 | ||
| 356 | void yahoo_send_picture_update(GaimConnection *gc, int type) | |
| 357 | { | |
| 358 | struct yahoo_data *yd = gc->proto_data; | |
| 359 | struct yspufe data; | |
| 360 | ||
| 361 | data.gc = gc; | |
| 362 | data.type = type; | |
| 363 | ||
| 364 | g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | |
| 365 | } | |
| 366 | ||
| 9306 | 367 | void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) |
| 368 | { | |
| 369 | gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); | |
| 370 | ||
| 371 | if (d->str) | |
| 372 | g_string_free(d->str, TRUE); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
373 | g_free(d->filename); |
| 9306 | 374 | if (d->watcher) |
| 375 | gaim_input_remove(d->watcher); | |
| 376 | if (d->fd != -1) | |
| 377 | close(d->fd); | |
| 378 | g_free(d); | |
| 379 | } | |
| 380 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
381 | /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ |
| 9306 | 382 | static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition) |
| 383 | { | |
| 384 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 385 | GaimConnection *gc = d->gc; | |
| 386 | char buf[1024]; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
387 | int ret; |
| 9306 | 388 | |
| 389 | if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
| 390 | yahoo_buddy_icon_upload_data_free(d); | |
| 391 | return; | |
| 392 | } | |
| 393 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
394 | ret = read(d->fd, buf, sizeof(buf)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
395 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
396 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
397 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
398 | else if (ret <= 0) |
| 9306 | 399 | yahoo_buddy_icon_upload_data_free(d); |
| 400 | } | |
| 401 | ||
| 402 | static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition) | |
| 403 | { | |
| 404 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 405 | GaimConnection *gc = d->gc; | |
| 406 | ssize_t wrote; | |
| 407 | ||
| 408 | if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
| 409 | yahoo_buddy_icon_upload_data_free(d); | |
| 410 | return; | |
| 411 | } | |
| 412 | ||
| 413 | wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
414 | if (wrote < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
415 | return; |
| 9306 | 416 | if (wrote <= 0) { |
| 417 | yahoo_buddy_icon_upload_data_free(d); | |
| 418 | return; | |
| 419 | } | |
| 420 | d->pos += wrote; | |
| 421 | if (d->pos >= d->str->len) { | |
| 422 | gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n"); | |
| 423 | gaim_input_remove(d->watcher); | |
| 424 | d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d); | |
| 425 | } | |
| 426 | } | |
| 427 | ||
|
14182
517f4531b8a0
[gaim-migrate @ 16754]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
428 | static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) |
| 9306 | 429 | { |
| 430 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 431 | struct yahoo_packet *pkt; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
432 | gchar *size, *header; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
433 | guchar *pkt_buf; |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
434 | const char *host; |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
435 | int port; |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13272
diff
changeset
|
436 | size_t content_length, pkt_buf_len; |
| 9306 | 437 | GaimConnection *gc; |
| 438 | GaimAccount *account; | |
| 439 | struct yahoo_data *yd; | |
| 440 | ||
|
14686
f3d13f21350c
[gaim-migrate @ 17356]
Richard Laager <rlaager@pidgin.im>
parents:
14508
diff
changeset
|
441 | g_return_if_fail(d != NULL); |
| 9306 | 442 | |
| 443 | gc = d->gc; | |
| 444 | account = gaim_connection_get_account(gc); | |
| 445 | yd = gc->proto_data; | |
| 446 | ||
| 447 | if (source < 0) { | |
| 448 | gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n"); | |
| 449 | yahoo_buddy_icon_upload_data_free(d); | |
| 450 | return; | |
| 451 | } | |
| 452 | ||
| 453 | ||
| 454 | pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id); | |
| 455 | ||
| 10111 | 456 | size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); |
| 9306 | 457 | /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ |
| 10394 | 458 | yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc)); |
| 459 | yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ | |
| 9306 | 460 | gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); |
| 10394 | 461 | yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc)); |
| 462 | yahoo_packet_hash_str(pkt, 28, size); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
463 | g_free(size); |
| 10394 | 464 | yahoo_packet_hash_str(pkt, 27, d->filename); |
| 465 | yahoo_packet_hash_str(pkt, 14, ""); | |
| 9306 | 466 | |
| 467 | content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | |
| 468 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
469 | host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
470 | port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
471 | header = g_strdup_printf( |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
472 | "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
473 | "Content-length: %" G_GSIZE_FORMAT "\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
474 | "Host: %s:%d\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
475 | "Cookie: Y=%s; T=%s\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
476 | "\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
477 | host, port, content_length + 4 + d->str->len, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
478 | host, port, yd->cookie_y, yd->cookie_t); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
479 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
480 | /* There's no magic here, we just need to prepend in reverse order */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
481 | g_string_prepend(d->str, "29\xc0\x80"); |
| 9306 | 482 | |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14416
diff
changeset
|
483 | pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, yd->jp, &pkt_buf); |
| 9306 | 484 | yahoo_packet_free(pkt); |
| 14321 | 485 | g_string_prepend_len(d->str, (char *)pkt_buf, pkt_buf_len); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
486 | g_free(pkt_buf); |
| 9306 | 487 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
488 | g_string_prepend(d->str, header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
489 | g_free(header); |
| 9306 | 490 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
491 | d->fd = source; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
492 | d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
493 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
494 | yahoo_buddy_icon_upload_pending(d, d->fd, GAIM_INPUT_WRITE); |
| 9306 | 495 | } |
| 496 | ||
| 497 | void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d) | |
| 498 | { | |
| 499 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 500 | struct yahoo_data *yd = gc->proto_data; | |
| 501 | ||
|
14686
f3d13f21350c
[gaim-migrate @ 17356]
Richard Laager <rlaager@pidgin.im>
parents:
14508
diff
changeset
|
502 | g_return_if_fail(d != NULL); |
|
f3d13f21350c
[gaim-migrate @ 17356]
Richard Laager <rlaager@pidgin.im>
parents:
14508
diff
changeset
|
503 | |
| 9306 | 504 | if (yd->jp) { |
| 505 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), | |
| 506 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
14170
f611621bc8a0
[gaim-migrate @ 16742]
Mark Doliner <markdoliner@pidgin.im>
parents:
14151
diff
changeset
|
507 | yahoo_buddy_icon_upload_connected, d) == NULL) |
| 9306 | 508 | { |
| 509 | gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
| 510 | yahoo_buddy_icon_upload_data_free(d); | |
| 511 | } | |
| 512 | } else { | |
| 513 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), | |
| 514 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
14170
f611621bc8a0
[gaim-migrate @ 16742]
Mark Doliner <markdoliner@pidgin.im>
parents:
14151
diff
changeset
|
515 | yahoo_buddy_icon_upload_connected, d) == NULL) |
| 9306 | 516 | { |
| 517 | gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
| 518 | yahoo_buddy_icon_upload_data_free(d); | |
| 519 | } | |
| 520 | } | |
| 521 | } | |
| 522 | ||
| 523 | void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile) | |
| 524 | { | |
| 525 | struct yahoo_data *yd = gc->proto_data; | |
| 526 | GaimAccount *account = gc->account; | |
| 527 | FILE *file; | |
| 528 | struct stat st; | |
| 529 | ||
| 530 | if (iconfile == NULL) { | |
| 531 | if (yd->picture_url) | |
| 532 | g_free(yd->picture_url); | |
| 533 | yd->picture_url = NULL; | |
| 534 | ||
| 535 | gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); | |
| 536 | gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 537 | gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 9310 | 538 | if (yd->logged_in) |
| 539 | yahoo_send_picture_update(gc, 0); | |
| 9306 | 540 | /* TODO: check if we're connected and tell everyone we ain't not one no more */ |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10576
diff
changeset
|
541 | } else if (!g_stat(iconfile, &st)) { |
|
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10576
diff
changeset
|
542 | file = g_fopen(iconfile, "rb"); |
| 9306 | 543 | if (file) { |
| 544 | GString *s = g_string_sized_new(st.st_size); | |
| 545 | size_t len; | |
| 546 | struct yahoo_buddy_icon_upload_data *d; | |
| 547 | int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 548 | int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 549 | const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); | |
| 550 | ||
| 551 | g_string_set_size(s, st.st_size); | |
| 552 | len = fread(s->str, 1, st.st_size, file); | |
| 553 | fclose(file); | |
| 554 | g_string_set_size(s, len); | |
| 555 | yd->picture_checksum = g_string_hash(s); | |
| 556 | ||
| 557 | if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) && | |
| 558 | oldcksum && expire && oldurl) { | |
| 559 | gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); | |
| 560 | g_string_free(s, TRUE); | |
| 561 | if (yd->picture_url) | |
| 562 | g_free(yd->picture_url); | |
| 563 | yd->picture_url = g_strdup(oldurl); | |
| 564 | return; | |
| 565 | } | |
| 566 | ||
| 567 | d = g_new0(struct yahoo_buddy_icon_upload_data, 1); | |
| 568 | d->gc = gc; | |
| 569 | d->str = s; | |
| 570 | d->fd = -1; | |
| 571 | d->filename = g_strdup(iconfile); | |
| 572 | ||
| 573 | if (!yd->logged_in) { | |
| 574 | yd->picture_upload_todo = d; | |
| 575 | return; | |
| 576 | } | |
| 577 | ||
| 578 | yahoo_buddy_icon_upload(gc, d); | |
| 579 | } else | |
| 580 | gaim_debug_error("yahoo", | |
| 581 | "Can't open buddy icon file!\n"); | |
| 582 | } else | |
|
9779
ddbddc8d6081
[gaim-migrate @ 10647]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9675
diff
changeset
|
583 | gaim_debug_error("yahoo", |
| 9306 | 584 | "Can't stat buddy icon file!\n"); |
| 585 | } |