Mercurial > pidgin.yaz
comparison libpurple/protocols/yahoo/yahoo_picture.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | de619a9523f9 |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 * gaim | 2 * purple |
3 * | 3 * |
4 * Gaim is the legal property of its developers, whose names are too numerous | 4 * Purple 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 | 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
6 * source distribution. | 6 * source distribution. |
7 * | 7 * |
8 * This program is free software; you can redistribute it and/or modify | 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 | 9 * it under the terms of the GNU General Public License as published by |
36 #include "yahoo_friend.h" | 36 #include "yahoo_friend.h" |
37 #include "yahoo_picture.h" | 37 #include "yahoo_picture.h" |
38 | 38 |
39 | 39 |
40 struct yahoo_fetch_picture_data { | 40 struct yahoo_fetch_picture_data { |
41 GaimConnection *gc; | 41 PurpleConnection *gc; |
42 char *who; | 42 char *who; |
43 int checksum; | 43 int checksum; |
44 }; | 44 }; |
45 | 45 |
46 static void | 46 static void |
47 yahoo_fetch_picture_cb(GaimUtilFetchUrlData *url_data, gpointer user_data, | 47 yahoo_fetch_picture_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, |
48 const gchar *pic_data, size_t len, const gchar *error_message) | 48 const gchar *pic_data, size_t len, const gchar *error_message) |
49 { | 49 { |
50 struct yahoo_fetch_picture_data *d; | 50 struct yahoo_fetch_picture_data *d; |
51 struct yahoo_data *yd; | 51 struct yahoo_data *yd; |
52 GaimBuddy *b; | 52 PurpleBuddy *b; |
53 | 53 |
54 d = user_data; | 54 d = user_data; |
55 yd = d->gc->proto_data; | 55 yd = d->gc->proto_data; |
56 yd->url_datas = g_slist_remove(yd->url_datas, url_data); | 56 yd->url_datas = g_slist_remove(yd->url_datas, url_data); |
57 | 57 |
58 if (error_message != NULL) { | 58 if (error_message != NULL) { |
59 gaim_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); | 59 purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); |
60 } else if (len == 0) { | 60 } else if (len == 0) { |
61 gaim_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); | 61 purple_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); |
62 } else { | 62 } else { |
63 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len); | 63 purple_buddy_icons_set_for_user(purple_connection_get_account(d->gc), d->who, (void *)pic_data, len); |
64 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who); | 64 b = purple_find_buddy(purple_connection_get_account(d->gc), d->who); |
65 if (b) | 65 if (b) |
66 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); | 66 purple_blist_node_set_int((PurpleBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); |
67 } | 67 } |
68 | 68 |
69 g_free(d->who); | 69 g_free(d->who); |
70 g_free(d); | 70 g_free(d); |
71 } | 71 } |
72 | 72 |
73 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt) | 73 void yahoo_process_picture(PurpleConnection *gc, struct yahoo_packet *pkt) |
74 { | 74 { |
75 struct yahoo_data *yd; | 75 struct yahoo_data *yd; |
76 GSList *l = pkt->hash; | 76 GSList *l = pkt->hash; |
77 char *who = NULL, *us = NULL; | 77 char *who = NULL, *us = NULL; |
78 gboolean got_icon_info = FALSE, send_icon_info = FALSE; | 78 gboolean got_icon_info = FALSE, send_icon_info = FALSE; |
112 } | 112 } |
113 | 113 |
114 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ | 114 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ |
115 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { | 115 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { |
116 /* TODO: make this work p2p, try p2p before the url */ | 116 /* TODO: make this work p2p, try p2p before the url */ |
117 GaimUtilFetchUrlData *url_data; | 117 PurpleUtilFetchUrlData *url_data; |
118 struct yahoo_fetch_picture_data *data; | 118 struct yahoo_fetch_picture_data *data; |
119 GaimBuddy *b = gaim_find_buddy(gc->account, who); | 119 PurpleBuddy *b = purple_find_buddy(gc->account, who); |
120 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | 120 if (b && (checksum == purple_blist_node_get_int((PurpleBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) |
121 return; | 121 return; |
122 | 122 |
123 data = g_new0(struct yahoo_fetch_picture_data, 1); | 123 data = g_new0(struct yahoo_fetch_picture_data, 1); |
124 data->gc = gc; | 124 data->gc = gc; |
125 data->who = g_strdup(who); | 125 data->who = g_strdup(who); |
126 data->checksum = checksum; | 126 data->checksum = checksum; |
127 url_data = gaim_util_fetch_url(url, FALSE, | 127 url_data = purple_util_fetch_url(url, FALSE, |
128 "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, | 128 "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, |
129 yahoo_fetch_picture_cb, data); | 129 yahoo_fetch_picture_cb, data); |
130 if (url_data != NULL) { | 130 if (url_data != NULL) { |
131 yd = gc->proto_data; | 131 yd = gc->proto_data; |
132 yd->url_datas = g_slist_prepend(yd->url_datas, url_data); | 132 yd->url_datas = g_slist_prepend(yd->url_datas, url_data); |
137 } else if (who && send_icon_info) { | 137 } else if (who && send_icon_info) { |
138 yahoo_send_picture_info(gc, who); | 138 yahoo_send_picture_info(gc, who); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt) | 142 void yahoo_process_picture_update(PurpleConnection *gc, struct yahoo_packet *pkt) |
143 { | 143 { |
144 GSList *l = pkt->hash; | 144 GSList *l = pkt->hash; |
145 char *who = NULL; | 145 char *who = NULL; |
146 int icon = 0; | 146 int icon = 0; |
147 | 147 |
164 | 164 |
165 if (who) { | 165 if (who) { |
166 if (icon == 2) | 166 if (icon == 2) |
167 yahoo_send_picture_request(gc, who); | 167 yahoo_send_picture_request(gc, who); |
168 else if ((icon == 0) || (icon == 1)) { | 168 else if ((icon == 0) || (icon == 1)) { |
169 GaimBuddy *b = gaim_find_buddy(gc->account, who); | 169 PurpleBuddy *b = purple_find_buddy(gc->account, who); |
170 YahooFriend *f; | 170 YahooFriend *f; |
171 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); | 171 purple_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
172 if (b) | 172 if (b) |
173 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | 173 purple_blist_node_remove_setting((PurpleBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); |
174 if ((f = yahoo_friend_find(gc, who))) | 174 if ((f = yahoo_friend_find(gc, who))) |
175 yahoo_friend_set_buddy_icon_need_request(f, TRUE); | 175 yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
176 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); | 176 purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
177 } | 177 } |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt) | 181 void yahoo_process_picture_checksum(PurpleConnection *gc, struct yahoo_packet *pkt) |
182 { | 182 { |
183 GSList *l = pkt->hash; | 183 GSList *l = pkt->hash; |
184 char *who = NULL; | 184 char *who = NULL; |
185 int checksum = 0; | 185 int checksum = 0; |
186 | 186 |
200 } | 200 } |
201 l = l->next; | 201 l = l->next; |
202 } | 202 } |
203 | 203 |
204 if (who) { | 204 if (who) { |
205 GaimBuddy *b = gaim_find_buddy(gc->account, who); | 205 PurpleBuddy *b = purple_find_buddy(gc->account, who); |
206 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | 206 if (b && (checksum != purple_blist_node_get_int((PurpleBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) |
207 yahoo_send_picture_request(gc, who); | 207 yahoo_send_picture_request(gc, who); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt) | 211 void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt) |
212 { | 212 { |
213 GaimAccount *account = gaim_connection_get_account(gc); | 213 PurpleAccount *account = purple_connection_get_account(gc); |
214 struct yahoo_data *yd = gc->proto_data; | 214 struct yahoo_data *yd = gc->proto_data; |
215 GSList *l = pkt->hash; | 215 GSList *l = pkt->hash; |
216 char *url = NULL; | 216 char *url = NULL; |
217 | 217 |
218 while (l) { | 218 while (l) { |
235 | 235 |
236 if (url) { | 236 if (url) { |
237 if (yd->picture_url) | 237 if (yd->picture_url) |
238 g_free(yd->picture_url); | 238 g_free(yd->picture_url); |
239 yd->picture_url = g_strdup(url); | 239 yd->picture_url = g_strdup(url); |
240 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url); | 240 purple_account_set_string(account, YAHOO_PICURL_SETTING, url); |
241 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); | 241 purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); |
242 yahoo_send_picture_update(gc, 2); | 242 yahoo_send_picture_update(gc, 2); |
243 yahoo_send_picture_checksum(gc); | 243 yahoo_send_picture_checksum(gc); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void yahoo_process_avatar_update(GaimConnection *gc, struct yahoo_packet *pkt) | 247 void yahoo_process_avatar_update(PurpleConnection *gc, struct yahoo_packet *pkt) |
248 { | 248 { |
249 GSList *l = pkt->hash; | 249 GSList *l = pkt->hash; |
250 char *who = NULL; | 250 char *who = NULL; |
251 int avatar = 0; | 251 int avatar = 0; |
252 | 252 |
274 | 274 |
275 if (who) { | 275 if (who) { |
276 if (avatar == 2) | 276 if (avatar == 2) |
277 yahoo_send_picture_request(gc, who); | 277 yahoo_send_picture_request(gc, who); |
278 else if ((avatar == 0) || (avatar == 1)) { | 278 else if ((avatar == 0) || (avatar == 1)) { |
279 GaimBuddy *b = gaim_find_buddy(gc->account, who); | 279 PurpleBuddy *b = purple_find_buddy(gc->account, who); |
280 YahooFriend *f; | 280 YahooFriend *f; |
281 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); | 281 purple_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
282 if (b) | 282 if (b) |
283 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | 283 purple_blist_node_remove_setting((PurpleBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); |
284 if ((f = yahoo_friend_find(gc, who))) | 284 if ((f = yahoo_friend_find(gc, who))) |
285 yahoo_friend_set_buddy_icon_need_request(f, TRUE); | 285 yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
286 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); | 286 purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
287 } | 287 } |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 void yahoo_send_picture_info(GaimConnection *gc, const char *who) | 291 void yahoo_send_picture_info(PurpleConnection *gc, const char *who) |
292 { | 292 { |
293 struct yahoo_data *yd = gc->proto_data; | 293 struct yahoo_data *yd = gc->proto_data; |
294 struct yahoo_packet *pkt; | 294 struct yahoo_packet *pkt; |
295 | 295 |
296 if (!yd->picture_url) { | 296 if (!yd->picture_url) { |
297 gaim_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); | 297 purple_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); |
298 return; | 298 return; |
299 } | 299 } |
300 | 300 |
301 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | 301 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); |
302 yahoo_packet_hash(pkt, "sssssi", 1, gaim_connection_get_display_name(gc), | 302 yahoo_packet_hash(pkt, "sssssi", 1, purple_connection_get_display_name(gc), |
303 4, gaim_connection_get_display_name(gc), 5, who, | 303 4, purple_connection_get_display_name(gc), 5, who, |
304 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); | 304 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); |
305 yahoo_packet_send_and_free(pkt, yd); | 305 yahoo_packet_send_and_free(pkt, yd); |
306 } | 306 } |
307 | 307 |
308 void yahoo_send_picture_request(GaimConnection *gc, const char *who) | 308 void yahoo_send_picture_request(PurpleConnection *gc, const char *who) |
309 { | 309 { |
310 struct yahoo_data *yd = gc->proto_data; | 310 struct yahoo_data *yd = gc->proto_data; |
311 struct yahoo_packet *pkt; | 311 struct yahoo_packet *pkt; |
312 | 312 |
313 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | 313 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); |
314 yahoo_packet_hash_str(pkt, 4, gaim_connection_get_display_name(gc)); /* me */ | 314 yahoo_packet_hash_str(pkt, 4, purple_connection_get_display_name(gc)); /* me */ |
315 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ | 315 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ |
316 yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | 316 yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ |
317 yahoo_packet_send_and_free(pkt, yd); | 317 yahoo_packet_send_and_free(pkt, yd); |
318 } | 318 } |
319 | 319 |
320 void yahoo_send_picture_checksum(GaimConnection *gc) | 320 void yahoo_send_picture_checksum(PurpleConnection *gc) |
321 { | 321 { |
322 struct yahoo_data *yd = gc->proto_data; | 322 struct yahoo_data *yd = gc->proto_data; |
323 struct yahoo_packet *pkt; | 323 struct yahoo_packet *pkt; |
324 | 324 |
325 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | 325 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); |
326 yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), | 326 yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), |
327 212, "1", 192, yd->picture_checksum); | 327 212, "1", 192, yd->picture_checksum); |
328 yahoo_packet_send_and_free(pkt, yd); | 328 yahoo_packet_send_and_free(pkt, yd); |
329 } | 329 } |
330 | 330 |
331 void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type) | 331 void yahoo_send_picture_update_to_user(PurpleConnection *gc, const char *who, int type) |
332 { | 332 { |
333 struct yahoo_data *yd = gc->proto_data; | 333 struct yahoo_data *yd = gc->proto_data; |
334 struct yahoo_packet *pkt; | 334 struct yahoo_packet *pkt; |
335 | 335 |
336 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | 336 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); |
337 yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), 5, who, 206, type); | 337 yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), 5, who, 206, type); |
338 yahoo_packet_send_and_free(pkt, yd); | 338 yahoo_packet_send_and_free(pkt, yd); |
339 } | 339 } |
340 | 340 |
341 struct yspufe { | 341 struct yspufe { |
342 GaimConnection *gc; | 342 PurpleConnection *gc; |
343 int type; | 343 int type; |
344 }; | 344 }; |
345 | 345 |
346 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | 346 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) |
347 { | 347 { |
351 | 351 |
352 if (f->status != YAHOO_STATUS_OFFLINE) | 352 if (f->status != YAHOO_STATUS_OFFLINE) |
353 yahoo_send_picture_update_to_user(d->gc, who, d->type); | 353 yahoo_send_picture_update_to_user(d->gc, who, d->type); |
354 } | 354 } |
355 | 355 |
356 void yahoo_send_picture_update(GaimConnection *gc, int type) | 356 void yahoo_send_picture_update(PurpleConnection *gc, int type) |
357 { | 357 { |
358 struct yahoo_data *yd = gc->proto_data; | 358 struct yahoo_data *yd = gc->proto_data; |
359 struct yspufe data; | 359 struct yspufe data; |
360 | 360 |
361 data.gc = gc; | 361 data.gc = gc; |
364 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | 364 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); |
365 } | 365 } |
366 | 366 |
367 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) | 367 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) |
368 { | 368 { |
369 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); | 369 purple_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); |
370 | 370 |
371 if (d->str) | 371 if (d->str) |
372 g_string_free(d->str, TRUE); | 372 g_string_free(d->str, TRUE); |
373 g_free(d->filename); | 373 g_free(d->filename); |
374 if (d->watcher) | 374 if (d->watcher) |
375 gaim_input_remove(d->watcher); | 375 purple_input_remove(d->watcher); |
376 if (d->fd != -1) | 376 if (d->fd != -1) |
377 close(d->fd); | 377 close(d->fd); |
378 g_free(d); | 378 g_free(d); |
379 } | 379 } |
380 | 380 |
381 /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ | 381 /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ |
382 static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition) | 382 static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, PurpleInputCondition condition) |
383 { | 383 { |
384 struct yahoo_buddy_icon_upload_data *d = data; | 384 struct yahoo_buddy_icon_upload_data *d = data; |
385 GaimConnection *gc = d->gc; | 385 PurpleConnection *gc = d->gc; |
386 char buf[1024]; | 386 char buf[1024]; |
387 int ret; | 387 int ret; |
388 | 388 |
389 if (!GAIM_CONNECTION_IS_VALID(gc)) { | 389 if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
390 yahoo_buddy_icon_upload_data_free(d); | 390 yahoo_buddy_icon_upload_data_free(d); |
391 return; | 391 return; |
392 } | 392 } |
393 | 393 |
394 ret = read(d->fd, buf, sizeof(buf)); | 394 ret = read(d->fd, buf, sizeof(buf)); |
397 return; | 397 return; |
398 else if (ret <= 0) | 398 else if (ret <= 0) |
399 yahoo_buddy_icon_upload_data_free(d); | 399 yahoo_buddy_icon_upload_data_free(d); |
400 } | 400 } |
401 | 401 |
402 static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition) | 402 static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, PurpleInputCondition condition) |
403 { | 403 { |
404 struct yahoo_buddy_icon_upload_data *d = data; | 404 struct yahoo_buddy_icon_upload_data *d = data; |
405 GaimConnection *gc = d->gc; | 405 PurpleConnection *gc = d->gc; |
406 ssize_t wrote; | 406 ssize_t wrote; |
407 | 407 |
408 if (!GAIM_CONNECTION_IS_VALID(gc)) { | 408 if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
409 yahoo_buddy_icon_upload_data_free(d); | 409 yahoo_buddy_icon_upload_data_free(d); |
410 return; | 410 return; |
411 } | 411 } |
412 | 412 |
413 wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos); | 413 wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos); |
417 yahoo_buddy_icon_upload_data_free(d); | 417 yahoo_buddy_icon_upload_data_free(d); |
418 return; | 418 return; |
419 } | 419 } |
420 d->pos += wrote; | 420 d->pos += wrote; |
421 if (d->pos >= d->str->len) { | 421 if (d->pos >= d->str->len) { |
422 gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n"); | 422 purple_debug_misc("yahoo", "Finished uploading buddy icon.\n"); |
423 gaim_input_remove(d->watcher); | 423 purple_input_remove(d->watcher); |
424 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d); | 424 d->watcher = purple_input_add(d->fd, PURPLE_INPUT_READ, yahoo_buddy_icon_upload_reading, d); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) | 428 static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) |
429 { | 429 { |
432 gchar *size, *header; | 432 gchar *size, *header; |
433 guchar *pkt_buf; | 433 guchar *pkt_buf; |
434 const char *host; | 434 const char *host; |
435 int port; | 435 int port; |
436 size_t content_length, pkt_buf_len; | 436 size_t content_length, pkt_buf_len; |
437 GaimConnection *gc; | 437 PurpleConnection *gc; |
438 GaimAccount *account; | 438 PurpleAccount *account; |
439 struct yahoo_data *yd; | 439 struct yahoo_data *yd; |
440 | 440 |
441 gc = d->gc; | 441 gc = d->gc; |
442 account = gaim_connection_get_account(gc); | 442 account = purple_connection_get_account(gc); |
443 yd = gc->proto_data; | 443 yd = gc->proto_data; |
444 | 444 |
445 /* Buddy icon connect is now complete; clear the GaimProxyConnectData */ | 445 /* Buddy icon connect is now complete; clear the PurpleProxyConnectData */ |
446 yd->buddy_icon_connect_data = NULL; | 446 yd->buddy_icon_connect_data = NULL; |
447 | 447 |
448 if (source < 0) { | 448 if (source < 0) { |
449 gaim_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message); | 449 purple_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message); |
450 yahoo_buddy_icon_upload_data_free(d); | 450 yahoo_buddy_icon_upload_data_free(d); |
451 return; | 451 return; |
452 } | 452 } |
453 | 453 |
454 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id); | 454 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id); |
455 | 455 |
456 size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); | 456 size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); |
457 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ | 457 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ |
458 yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc)); | 458 yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc)); |
459 yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ | 459 yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ |
460 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); | 460 purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); |
461 yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc)); | 461 yahoo_packet_hash_str(pkt, 0, purple_connection_get_display_name(gc)); |
462 yahoo_packet_hash_str(pkt, 28, size); | 462 yahoo_packet_hash_str(pkt, 28, size); |
463 g_free(size); | 463 g_free(size); |
464 yahoo_packet_hash_str(pkt, 27, d->filename); | 464 yahoo_packet_hash_str(pkt, 27, d->filename); |
465 yahoo_packet_hash_str(pkt, 14, ""); | 465 yahoo_packet_hash_str(pkt, 14, ""); |
466 | 466 |
467 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | 467 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); |
468 | 468 |
469 host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); | 469 host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
470 port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); | 470 port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
471 header = g_strdup_printf( | 471 header = g_strdup_printf( |
472 "POST http://%s:%d/notifyft HTTP/1.0\r\n" | 472 "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
473 "Content-length: %" G_GSIZE_FORMAT "\r\n" | 473 "Content-length: %" G_GSIZE_FORMAT "\r\n" |
474 "Host: %s:%d\r\n" | 474 "Host: %s:%d\r\n" |
475 "Cookie: Y=%s; T=%s\r\n" | 475 "Cookie: Y=%s; T=%s\r\n" |
487 | 487 |
488 g_string_prepend(d->str, header); | 488 g_string_prepend(d->str, header); |
489 g_free(header); | 489 g_free(header); |
490 | 490 |
491 d->fd = source; | 491 d->fd = source; |
492 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); | 492 d->watcher = purple_input_add(d->fd, PURPLE_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); |
493 | 493 |
494 yahoo_buddy_icon_upload_pending(d, d->fd, GAIM_INPUT_WRITE); | 494 yahoo_buddy_icon_upload_pending(d, d->fd, PURPLE_INPUT_WRITE); |
495 } | 495 } |
496 | 496 |
497 void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d) | 497 void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d) |
498 { | 498 { |
499 GaimAccount *account = gaim_connection_get_account(gc); | 499 PurpleAccount *account = purple_connection_get_account(gc); |
500 struct yahoo_data *yd = gc->proto_data; | 500 struct yahoo_data *yd = gc->proto_data; |
501 | 501 |
502 if (yd->buddy_icon_connect_data != NULL) { | 502 if (yd->buddy_icon_connect_data != NULL) { |
503 /* Cancel any in-progress buddy icon upload */ | 503 /* Cancel any in-progress buddy icon upload */ |
504 gaim_proxy_connect_cancel(yd->buddy_icon_connect_data); | 504 purple_proxy_connect_cancel(yd->buddy_icon_connect_data); |
505 yd->buddy_icon_connect_data = NULL; | 505 yd->buddy_icon_connect_data = NULL; |
506 } | 506 } |
507 | 507 |
508 yd->buddy_icon_connect_data = gaim_proxy_connect(NULL, account, | 508 yd->buddy_icon_connect_data = purple_proxy_connect(NULL, account, |
509 yd->jp ? gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST) | 509 yd->jp ? purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST) |
510 : gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), | 510 : purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), |
511 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | 511 purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
512 yahoo_buddy_icon_upload_connected, d); | 512 yahoo_buddy_icon_upload_connected, d); |
513 | 513 |
514 if (yd->buddy_icon_connect_data == NULL) | 514 if (yd->buddy_icon_connect_data == NULL) |
515 { | 515 { |
516 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | 516 purple_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); |
517 yahoo_buddy_icon_upload_data_free(d); | 517 yahoo_buddy_icon_upload_data_free(d); |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile) | 521 void yahoo_set_buddy_icon(PurpleConnection *gc, const char *iconfile) |
522 { | 522 { |
523 struct yahoo_data *yd = gc->proto_data; | 523 struct yahoo_data *yd = gc->proto_data; |
524 GaimAccount *account = gc->account; | 524 PurpleAccount *account = gc->account; |
525 gchar *icondata; | 525 gchar *icondata; |
526 gsize len; | 526 gsize len; |
527 GError *error = NULL; | 527 GError *error = NULL; |
528 | 528 |
529 if (iconfile == NULL) { | 529 if (iconfile == NULL) { |
530 g_free(yd->picture_url); | 530 g_free(yd->picture_url); |
531 yd->picture_url = NULL; | 531 yd->picture_url = NULL; |
532 | 532 |
533 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); | 533 purple_account_set_string(account, YAHOO_PICURL_SETTING, NULL); |
534 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | 534 purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); |
535 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | 535 purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); |
536 if (yd->logged_in) | 536 if (yd->logged_in) |
537 /* Tell everyone we ain't got one no more */ | 537 /* Tell everyone we ain't got one no more */ |
538 yahoo_send_picture_update(gc, 0); | 538 yahoo_send_picture_update(gc, 0); |
539 | 539 |
540 } else if (g_file_get_contents(iconfile, &icondata, &len, &error)) { | 540 } else if (g_file_get_contents(iconfile, &icondata, &len, &error)) { |
541 GString *s = g_string_new_len(icondata, len); | 541 GString *s = g_string_new_len(icondata, len); |
542 struct yahoo_buddy_icon_upload_data *d; | 542 struct yahoo_buddy_icon_upload_data *d; |
543 int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); | 543 int oldcksum = purple_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); |
544 int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | 544 int expire = purple_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); |
545 const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); | 545 const char *oldurl = purple_account_get_string(account, YAHOO_PICURL_SETTING, NULL); |
546 | 546 |
547 yd->picture_checksum = g_string_hash(s); | 547 yd->picture_checksum = g_string_hash(s); |
548 | 548 |
549 if ((yd->picture_checksum == oldcksum) && | 549 if ((yd->picture_checksum == oldcksum) && |
550 (expire > (time(NULL) + 60*60*24)) && oldurl) | 550 (expire > (time(NULL) + 60*60*24)) && oldurl) |
551 { | 551 { |
552 gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); | 552 purple_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); |
553 g_string_free(s, TRUE); | 553 g_string_free(s, TRUE); |
554 g_free(yd->picture_url); | 554 g_free(yd->picture_url); |
555 yd->picture_url = g_strdup(oldurl); | 555 yd->picture_url = g_strdup(oldurl); |
556 return; | 556 return; |
557 } | 557 } |
568 } | 568 } |
569 | 569 |
570 yahoo_buddy_icon_upload(gc, d); | 570 yahoo_buddy_icon_upload(gc, d); |
571 | 571 |
572 } else { | 572 } else { |
573 gaim_debug_error("yahoo", | 573 purple_debug_error("yahoo", |
574 "Could not read buddy icon file '%s': %s\n", | 574 "Could not read buddy icon file '%s': %s\n", |
575 iconfile, error->message); | 575 iconfile, error->message); |
576 g_error_free(error); | 576 g_error_free(error); |
577 } | 577 } |
578 } | 578 } |