comparison src/protocols/yahoo/yahoo_picture.c @ 9310:085190b9dd64

[gaim-migrate @ 10118] This is supposed to make us alert our buddies when we change our buddy icon, or turn it off. Except it crashes when we turn it off. But I think that's either Sean's fault or else Chip's fault. Also its supposed to make us announce our buddy icon when we log on if we have an old one set. But I don't think it does. Or was that the last commit that was supposed to do taht? either way it doesn't work for some reason, I need more packet dumps. It does succeed in announing our buddy icon to everyone when we set one. Well except people not on our list. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Sat, 19 Jun 2004 07:11:53 +0000
parents 04a3e9e869ee
children 119f8a2c00b6
comparison
equal deleted inserted replaced
9309:ade6b9c0dc8a 9310:085190b9dd64
40 GaimConnection *gc; 40 GaimConnection *gc;
41 char *who; 41 char *who;
42 int checksum; 42 int checksum;
43 }; 43 };
44 44
45
46
45 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len) 47 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len)
46 { 48 {
47 struct yahoo_fetch_picture_data *d = user_data; 49 struct yahoo_fetch_picture_data *d = user_data;
48 GaimBuddy *b; 50 GaimBuddy *b;
49 51
165 l = l->next; 167 l = l->next;
166 } 168 }
167 169
168 if (who) { 170 if (who) {
169 if (icon == 2) 171 if (icon == 2)
170 yahoo_send_buddy_icon_request(gc, who); 172 yahoo_send_picture_request(gc, who);
171 else if (icon == 0) 173 else if (icon == 0)
172 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); 174 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0);
173 } 175 }
174 } 176 }
175 177
197 } 199 }
198 200
199 if (who) { 201 if (who) {
200 GaimBuddy *b = gaim_find_buddy(gc->account, who); 202 GaimBuddy *b = gaim_find_buddy(gc->account, who);
201 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) 203 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
202 yahoo_send_buddy_icon_request(gc, who); 204 yahoo_send_picture_request(gc, who);
203 } 205 }
204 } 206 }
205 207
206 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt) 208 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt)
207 { 209 {
232 if (yd->picture_url) 234 if (yd->picture_url)
233 g_free(yd->picture_url); 235 g_free(yd->picture_url);
234 yd->picture_url = g_strdup(url); 236 yd->picture_url = g_strdup(url);
235 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url); 237 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url);
236 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); 238 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum);
237 } 239 yahoo_send_picture_update(gc, 2);
238 } 240 yahoo_send_picture_checksum(gc);
239 241 }
240 242 }
241 void yahoo_send_buddy_icon_request(GaimConnection *gc, const char *who) 243
244
245 void yahoo_send_picture_request(GaimConnection *gc, const char *who)
242 { 246 {
243 struct yahoo_data *yd = gc->proto_data; 247 struct yahoo_data *yd = gc->proto_data;
244 struct yahoo_packet *pkt; 248 struct yahoo_packet *pkt;
245 249
246 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); 250 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
247 yahoo_packet_hash(pkt, 4, gaim_connection_get_display_name(gc)); /* me */ 251 yahoo_packet_hash(pkt, 4, gaim_connection_get_display_name(gc)); /* me */
248 yahoo_packet_hash(pkt, 5, who); /* the other guy */ 252 yahoo_packet_hash(pkt, 5, who); /* the other guy */
249 yahoo_packet_hash(pkt, 13, "1"); /* 1 = request, 2 = reply */ 253 yahoo_packet_hash(pkt, 13, "1"); /* 1 = request, 2 = reply */
250 yahoo_send_packet(yd, pkt); 254 yahoo_send_packet(yd, pkt);
251 yahoo_packet_free(pkt); 255 yahoo_packet_free(pkt);
256 }
257
258 void yahoo_send_picture_checksum(GaimConnection *gc)
259 {
260 struct yahoo_data *yd = gc->proto_data;
261 struct yahoo_packet *pkt;
262 char *cksum = g_strdup_printf("%d", yd->picture_checksum);
263
264 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0);
265 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
266 yahoo_packet_hash(pkt, 212, "1");
267 yahoo_packet_hash(pkt, 192, cksum);
268 yahoo_send_packet(yd, pkt);
269 yahoo_packet_free(pkt);
270 g_free(cksum);
271 }
272
273 void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type)
274 {
275 struct yahoo_data *yd = gc->proto_data;
276 struct yahoo_packet *pkt;
277 char *typestr = g_strdup_printf("%d", type);
278
279 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
280 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
281 yahoo_packet_hash(pkt, 5, who);
282 yahoo_packet_hash(pkt, 206, typestr);
283 yahoo_send_packet(yd, pkt);
284 yahoo_packet_free(pkt);
285
286 g_free(typestr);
287 }
288
289 struct yspufe {
290 GaimConnection *gc;
291 int type;
292 };
293
294 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data)
295 {
296 char *who = key;
297 YahooFriend *f = value;
298 struct yspufe *d = data;
299
300 if (f->status != YAHOO_STATUS_OFFLINE)
301 yahoo_send_picture_update_to_user(d->gc, who, d->type);
302 }
303
304 void yahoo_send_picture_update(GaimConnection *gc, int type)
305 {
306 struct yahoo_data *yd = gc->proto_data;
307 struct yspufe data;
308
309 data.gc = gc;
310 data.type = type;
311
312 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data);
252 } 313 }
253 314
254 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) 315 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d)
255 { 316 {
256 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); 317 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n");
408 yd->picture_url = NULL; 469 yd->picture_url = NULL;
409 470
410 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); 471 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL);
411 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); 472 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0);
412 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); 473 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0);
474 if (yd->logged_in)
475 yahoo_send_picture_update(gc, 0);
413 /* TODO: check if we're connected and tell everyone we ain't not one no more */ 476 /* TODO: check if we're connected and tell everyone we ain't not one no more */
414 } else if (!stat(iconfile, &st)) { 477 } else if (!stat(iconfile, &st)) {
415 file = fopen(iconfile, "rb"); 478 file = fopen(iconfile, "rb");
416 if (file) { 479 if (file) {
417 GString *s = g_string_sized_new(st.st_size); 480 GString *s = g_string_sized_new(st.st_size);