comparison libpurple/protocols/jabber/buddy.c @ 22295:bb124c3e668c

Fix setting vCard buddy icons when we don't have any other user info set. Fixes #3450.
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 14 Feb 2008 13:03:34 +0000
parents ce3d42470adf
children 67f62f55fc5a
comparison
equal deleted inserted replaced
22294:33b5a0e92583 22295:bb124c3e668c
390 /* 390 /*
391 * Send vCard info to Jabber server 391 * Send vCard info to Jabber server
392 */ 392 */
393 void jabber_set_info(PurpleConnection *gc, const char *info) 393 void jabber_set_info(PurpleConnection *gc, const char *info)
394 { 394 {
395 PurpleStoredImage *img;
395 JabberIq *iq; 396 JabberIq *iq;
396 JabberStream *js = gc->proto_data; 397 JabberStream *js = gc->proto_data;
397 xmlnode *vc_node; 398 xmlnode *vc_node;
398 const struct tag_attr *tag_attr; 399 const struct tag_attr *tag_attr;
399 400
408 /* 409 /*
409 * Send only if there's actually any *information* to send 410 * Send only if there's actually any *information* to send
410 */ 411 */
411 vc_node = info ? xmlnode_from_str(info, -1) : NULL; 412 vc_node = info ? xmlnode_from_str(info, -1) : NULL;
412 413
413 if(!vc_node) { 414 if (vc_node && (!vc_node->name ||
414 vc_node = xmlnode_new("vCard"); 415 g_ascii_strncasecmp(vc_node->name, "vCard", 5))) {
415 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) 416 xmlnode_free(vc_node);
416 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); 417 vc_node = NULL;
417 } 418 }
418 419
419 if (vc_node->name && 420 if ((img = purple_buddy_icons_find_account_icon(gc->account))) {
420 !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) { 421 gconstpointer avatar_data;
421 PurpleStoredImage *img; 422 gsize avatar_len;
422 423 xmlnode *photo, *binval, *type;
423 if ((img = purple_buddy_icons_find_account_icon(gc->account))) { 424 gchar *enc;
424 gconstpointer avatar_data; 425 int i;
425 gsize avatar_len; 426 unsigned char hashval[20];
426 xmlnode *photo, *binval, *type; 427 char *p, hash[41];
427 gchar *enc; 428
428 int i; 429 if(!vc_node) {
429 unsigned char hashval[20]; 430 vc_node = xmlnode_new("vCard");
430 char *p, hash[41]; 431 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr)
431 432 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value);
432 avatar_data = purple_imgstore_get_data(img); 433 }
433 avatar_len = purple_imgstore_get_size(img); 434
434 /* have to get rid of the old PHOTO if it exists */ 435 avatar_data = purple_imgstore_get_data(img);
435 if((photo = xmlnode_get_child(vc_node, "PHOTO"))) { 436 avatar_len = purple_imgstore_get_size(img);
436 xmlnode_free(photo); 437 /* have to get rid of the old PHOTO if it exists */
437 } 438 if((photo = xmlnode_get_child(vc_node, "PHOTO"))) {
438 photo = xmlnode_new_child(vc_node, "PHOTO"); 439 xmlnode_free(photo);
439 type = xmlnode_new_child(photo, "TYPE"); 440 }
440 xmlnode_insert_data(type, "image/png", -1); 441 photo = xmlnode_new_child(vc_node, "PHOTO");
441 binval = xmlnode_new_child(photo, "BINVAL"); 442 type = xmlnode_new_child(photo, "TYPE");
442 enc = purple_base64_encode(avatar_data, avatar_len); 443 xmlnode_insert_data(type, "image/png", -1);
443 444 binval = xmlnode_new_child(photo, "BINVAL");
444 purple_cipher_digest_region("sha1", avatar_data, 445 enc = purple_base64_encode(avatar_data, avatar_len);
445 avatar_len, sizeof(hashval), 446
446 hashval, NULL); 447 purple_cipher_digest_region("sha1", avatar_data,
447 448 avatar_len, sizeof(hashval),
448 purple_imgstore_unref(img); 449 hashval, NULL);
449 450
450 p = hash; 451 purple_imgstore_unref(img);
451 for(i=0; i<20; i++, p+=2) 452
452 snprintf(p, 3, "%02x", hashval[i]); 453 p = hash;
453 js->avatar_hash = g_strdup(hash); 454 for(i=0; i<20; i++, p+=2)
454 455 snprintf(p, 3, "%02x", hashval[i]);
455 xmlnode_insert_data(binval, enc, -1); 456 js->avatar_hash = g_strdup(hash);
456 g_free(enc); 457
457 } 458 xmlnode_insert_data(binval, enc, -1);
458 459 g_free(enc);
460 }
461
462 if (vc_node != NULL) {
459 iq = jabber_iq_new(js, JABBER_IQ_SET); 463 iq = jabber_iq_new(js, JABBER_IQ_SET);
460 xmlnode_insert_child(iq->node, vc_node); 464 xmlnode_insert_child(iq->node, vc_node);
461 jabber_iq_send(iq); 465 jabber_iq_send(iq);
462 } else {
463 xmlnode_free(vc_node);
464 } 466 }
465 } 467 }
466 468
467 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) 469 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
468 { 470 {