libpurple/protocols/jabber/buddy.c

changeset 15884
4de1981757fc
parent 15727
0754583ceeae
child 16238
33bf2fd32108
child 16437
7ff7c3405ea2
child 16490
68c22924d66b
child 20478
46933dc62880
equal deleted inserted replaced
15883:969b74a3e27a 15884:4de1981757fc
1 /* 1 /*
2 * gaim - Jabber Protocol Plugin 2 * purple - Jabber Protocol Plugin
3 * 3 *
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
376 } 376 }
377 377
378 /* 378 /*
379 * Send vCard info to Jabber server 379 * Send vCard info to Jabber server
380 */ 380 */
381 void jabber_set_info(GaimConnection *gc, const char *info) 381 void jabber_set_info(PurpleConnection *gc, const char *info)
382 { 382 {
383 JabberIq *iq; 383 JabberIq *iq;
384 JabberStream *js = gc->proto_data; 384 JabberStream *js = gc->proto_data;
385 xmlnode *vc_node; 385 xmlnode *vc_node;
386 char *avatar_file = NULL; 386 char *avatar_file = NULL;
391 391
392 /* 392 /*
393 * Send only if there's actually any *information* to send 393 * Send only if there's actually any *information* to send
394 */ 394 */
395 vc_node = info ? xmlnode_from_str(info, -1) : NULL; 395 vc_node = info ? xmlnode_from_str(info, -1) : NULL;
396 avatar_file = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(gc->account)); 396 avatar_file = purple_buddy_icons_get_full_path(purple_account_get_buddy_icon(gc->account));
397 397
398 if(!vc_node) { 398 if(!vc_node) {
399 vc_node = xmlnode_new("vCard"); 399 vc_node = xmlnode_new("vCard");
400 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) 400 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr)
401 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); 401 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value);
416 char *p, hash[41]; 416 char *p, hash[41];
417 417
418 avatar_data = (guchar *) avatar_data_tmp; 418 avatar_data = (guchar *) avatar_data_tmp;
419 photo = xmlnode_new_child(vc_node, "PHOTO"); 419 photo = xmlnode_new_child(vc_node, "PHOTO");
420 binval = xmlnode_new_child(photo, "BINVAL"); 420 binval = xmlnode_new_child(photo, "BINVAL");
421 enc = gaim_base64_encode(avatar_data, avatar_len); 421 enc = purple_base64_encode(avatar_data, avatar_len);
422 422
423 gaim_cipher_digest_region("sha1", (guchar *)avatar_data, 423 purple_cipher_digest_region("sha1", (guchar *)avatar_data,
424 avatar_len, sizeof(hashval), 424 avatar_len, sizeof(hashval),
425 hashval, NULL); 425 hashval, NULL);
426 426
427 p = hash; 427 p = hash;
428 for(i=0; i<20; i++, p+=2) 428 for(i=0; i<20; i++, p+=2)
443 } else { 443 } else {
444 xmlnode_free(vc_node); 444 xmlnode_free(vc_node);
445 } 445 }
446 } 446 }
447 447
448 void jabber_set_buddy_icon(GaimConnection *gc, const char *iconfile) 448 void jabber_set_buddy_icon(PurpleConnection *gc, const char *iconfile)
449 { 449 {
450 GaimPresence *gpresence; 450 PurplePresence *gpresence;
451 GaimStatus *status; 451 PurpleStatus *status;
452 452
453 jabber_set_info(gc, gaim_account_get_user_info(gc->account)); 453 jabber_set_info(gc, purple_account_get_user_info(gc->account));
454 454
455 gpresence = gaim_account_get_presence(gc->account); 455 gpresence = purple_account_get_presence(gc->account);
456 status = gaim_presence_get_active_status(gpresence); 456 status = purple_presence_get_active_status(gpresence);
457 jabber_presence_send(gc->account, status); 457 jabber_presence_send(gc->account, status);
458 } 458 }
459 459
460 /* 460 /*
461 * This is the callback from the "ok clicked" for "set vCard" 461 * This is the callback from the "ok clicked" for "set vCard"
465 * 465 *
466 * g_free()'ing the returned string space is the responsibility of 466 * g_free()'ing the returned string space is the responsibility of
467 * the caller. 467 * the caller.
468 */ 468 */
469 static void 469 static void
470 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) 470 jabber_format_info(PurpleConnection *gc, PurpleRequestFields *fields)
471 { 471 {
472 xmlnode *vc_node; 472 xmlnode *vc_node;
473 GaimRequestField *field; 473 PurpleRequestField *field;
474 const char *text; 474 const char *text;
475 char *p; 475 char *p;
476 const struct vcard_template *vc_tp; 476 const struct vcard_template *vc_tp;
477 struct tag_attr *tag_attr; 477 struct tag_attr *tag_attr;
478 478
483 483
484 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { 484 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) {
485 if (*vc_tp->label == '\0') 485 if (*vc_tp->label == '\0')
486 continue; 486 continue;
487 487
488 field = gaim_request_fields_get_field(fields, vc_tp->tag); 488 field = purple_request_fields_get_field(fields, vc_tp->tag);
489 text = gaim_request_field_string_get_value(field); 489 text = purple_request_field_string_get_value(field);
490 490
491 491
492 if (text != NULL && *text != '\0') { 492 if (text != NULL && *text != '\0') {
493 xmlnode *xp; 493 xmlnode *xp;
494 494
495 gaim_debug(GAIM_DEBUG_INFO, "jabber", 495 purple_debug(PURPLE_DEBUG_INFO, "jabber",
496 "Setting %s to '%s'\n", vc_tp->tag, text); 496 "Setting %s to '%s'\n", vc_tp->tag, text);
497 497
498 if ((xp = insert_tag_to_parent_tag(vc_node, 498 if ((xp = insert_tag_to_parent_tag(vc_node,
499 NULL, vc_tp->tag)) != NULL) { 499 NULL, vc_tp->tag)) != NULL) {
500 500
504 } 504 }
505 505
506 p = xmlnode_to_str(vc_node, NULL); 506 p = xmlnode_to_str(vc_node, NULL);
507 xmlnode_free(vc_node); 507 xmlnode_free(vc_node);
508 508
509 gaim_account_set_user_info(gaim_connection_get_account(gc), p); 509 purple_account_set_user_info(purple_connection_get_account(gc), p);
510 serv_set_info(gc, p); 510 serv_set_info(gc, p);
511 511
512 g_free(p); 512 g_free(p);
513 } 513 }
514 514
515 /* 515 /*
516 * This gets executed by the proto action 516 * This gets executed by the proto action
517 * 517 *
518 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info 518 * Creates a new PurpleRequestFields struct, gets the XML-formatted user_info
519 * string (if any) into GSLists for the (multi-entry) edit dialog and 519 * string (if any) into GSLists for the (multi-entry) edit dialog and
520 * calls the set_vcard dialog. 520 * calls the set_vcard dialog.
521 */ 521 */
522 void jabber_setup_set_info(GaimPluginAction *action) 522 void jabber_setup_set_info(PurplePluginAction *action)
523 { 523 {
524 GaimConnection *gc = (GaimConnection *) action->context; 524 PurpleConnection *gc = (PurpleConnection *) action->context;
525 GaimRequestFields *fields; 525 PurpleRequestFields *fields;
526 GaimRequestFieldGroup *group; 526 PurpleRequestFieldGroup *group;
527 GaimRequestField *field; 527 PurpleRequestField *field;
528 const struct vcard_template *vc_tp; 528 const struct vcard_template *vc_tp;
529 const char *user_info; 529 const char *user_info;
530 char *cdata = NULL; 530 char *cdata = NULL;
531 xmlnode *x_vc_data = NULL; 531 xmlnode *x_vc_data = NULL;
532 532
533 fields = gaim_request_fields_new(); 533 fields = purple_request_fields_new();
534 group = gaim_request_field_group_new(NULL); 534 group = purple_request_field_group_new(NULL);
535 gaim_request_fields_add_group(fields, group); 535 purple_request_fields_add_group(fields, group);
536 536
537 /* 537 /*
538 * Get existing, XML-formatted, user info 538 * Get existing, XML-formatted, user info
539 */ 539 */
540 if((user_info = gaim_account_get_user_info(gc->account)) != NULL) 540 if((user_info = purple_account_get_user_info(gc->account)) != NULL)
541 x_vc_data = xmlnode_from_str(user_info, -1); 541 x_vc_data = xmlnode_from_str(user_info, -1);
542 542
543 /* 543 /*
544 * Set up GSLists for edit with labels from "template," data from user info 544 * Set up GSLists for edit with labels from "template," data from user info
545 */ 545 */
559 if(data_node) 559 if(data_node)
560 cdata = xmlnode_get_data(data_node); 560 cdata = xmlnode_get_data(data_node);
561 } 561 }
562 562
563 if(strcmp(vc_tp->tag, "DESC") == 0) { 563 if(strcmp(vc_tp->tag, "DESC") == 0) {
564 field = gaim_request_field_string_new(vc_tp->tag, 564 field = purple_request_field_string_new(vc_tp->tag,
565 _(vc_tp->label), cdata, 565 _(vc_tp->label), cdata,
566 TRUE); 566 TRUE);
567 } else { 567 } else {
568 field = gaim_request_field_string_new(vc_tp->tag, 568 field = purple_request_field_string_new(vc_tp->tag,
569 _(vc_tp->label), cdata, 569 _(vc_tp->label), cdata,
570 FALSE); 570 FALSE);
571 } 571 }
572 572
573 g_free(cdata); 573 g_free(cdata);
574 cdata = NULL; 574 cdata = NULL;
575 575
576 gaim_request_field_group_add_field(group, field); 576 purple_request_field_group_add_field(group, field);
577 } 577 }
578 578
579 if(x_vc_data != NULL) 579 if(x_vc_data != NULL)
580 xmlnode_free(x_vc_data); 580 xmlnode_free(x_vc_data);
581 581
582 gaim_request_fields(gc, _("Edit Jabber vCard"), 582 purple_request_fields(gc, _("Edit Jabber vCard"),
583 _("Edit Jabber vCard"), 583 _("Edit Jabber vCard"),
584 _("All items below are optional. Enter only the " 584 _("All items below are optional. Enter only the "
585 "information with which you feel comfortable."), 585 "information with which you feel comfortable."),
586 fields, 586 fields,
587 _("Save"), G_CALLBACK(jabber_format_info), 587 _("Save"), G_CALLBACK(jabber_format_info),
599 599
600 static void jabber_buddy_info_destroy(JabberBuddyInfo *jbi) 600 static void jabber_buddy_info_destroy(JabberBuddyInfo *jbi)
601 { 601 {
602 /* Remove the timeout, which would otherwise trigger jabber_buddy_get_info_timeout() */ 602 /* Remove the timeout, which would otherwise trigger jabber_buddy_get_info_timeout() */
603 if (jbi->timeout_handle > 0) 603 if (jbi->timeout_handle > 0)
604 gaim_timeout_remove(jbi->timeout_handle); 604 purple_timeout_remove(jbi->timeout_handle);
605 605
606 g_free(jbi->jid); 606 g_free(jbi->jid);
607 g_hash_table_destroy(jbi->resources); 607 g_hash_table_destroy(jbi->resources);
608 g_free(jbi->vcard_text); 608 g_free(jbi->vcard_text);
609 g_free(jbi); 609 g_free(jbi);
613 { 613 {
614 char *resource_name, *tmp; 614 char *resource_name, *tmp;
615 JabberBuddyResource *jbr; 615 JabberBuddyResource *jbr;
616 JabberBuddyInfoResource *jbir = NULL; 616 JabberBuddyInfoResource *jbir = NULL;
617 GList *resources; 617 GList *resources;
618 GaimNotifyUserInfo *user_info; 618 PurpleNotifyUserInfo *user_info;
619 619
620 /* not yet */ 620 /* not yet */
621 if(jbi->ids) 621 if(jbi->ids)
622 return; 622 return;
623 623
624 user_info = gaim_notify_user_info_new(); 624 user_info = purple_notify_user_info_new();
625 resource_name = jabber_get_resource(jbi->jid); 625 resource_name = jabber_get_resource(jbi->jid);
626 626
627 if(resource_name) { 627 if(resource_name) {
628 jbr = jabber_buddy_find_resource(jbi->jb, resource_name); 628 jbr = jabber_buddy_find_resource(jbi->jb, resource_name);
629 jbir = g_hash_table_lookup(jbi->resources, resource_name); 629 jbir = g_hash_table_lookup(jbi->resources, resource_name);
630 if(jbr) { 630 if(jbr) {
631 char *purdy = NULL; 631 char *purdy = NULL;
632 if(jbr->status) 632 if(jbr->status)
633 purdy = gaim_strdup_withhtml(jbr->status); 633 purdy = purple_strdup_withhtml(jbr->status);
634 tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state), 634 tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state),
635 (purdy ? ": " : ""), 635 (purdy ? ": " : ""),
636 (purdy ? purdy : "")); 636 (purdy ? purdy : ""));
637 gaim_notify_user_info_add_pair(user_info, _("Status"), tmp); 637 purple_notify_user_info_add_pair(user_info, _("Status"), tmp);
638 g_free(tmp); 638 g_free(tmp);
639 g_free(purdy); 639 g_free(purdy);
640 } else { 640 } else {
641 gaim_notify_user_info_add_pair(user_info, _("Status"), _("Unknown")); 641 purple_notify_user_info_add_pair(user_info, _("Status"), _("Unknown"));
642 } 642 }
643 if(jbir) { 643 if(jbir) {
644 if(jbir->idle_seconds > 0) { 644 if(jbir->idle_seconds > 0) {
645 char *idle = gaim_str_seconds_to_string(jbir->idle_seconds); 645 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
646 gaim_notify_user_info_add_pair(user_info, _("Idle"), idle); 646 purple_notify_user_info_add_pair(user_info, _("Idle"), idle);
647 g_free(idle); 647 g_free(idle);
648 } 648 }
649 } 649 }
650 if(jbr && jbr->client.name) { 650 if(jbr && jbr->client.name) {
651 tmp = g_strdup_printf("%s%s%s", jbr->client.name, 651 tmp = g_strdup_printf("%s%s%s", jbr->client.name,
652 (jbr->client.version ? " " : ""), 652 (jbr->client.version ? " " : ""),
653 (jbr->client.version ? jbr->client.version : "")); 653 (jbr->client.version ? jbr->client.version : ""));
654 gaim_notify_user_info_add_pair(user_info, _("Client"), tmp); 654 purple_notify_user_info_add_pair(user_info, _("Client"), tmp);
655 g_free(tmp); 655 g_free(tmp);
656 656
657 if(jbr->client.os) { 657 if(jbr->client.os) {
658 gaim_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os); 658 purple_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os);
659 } 659 }
660 } 660 }
661 } else { 661 } else {
662 for(resources = jbi->jb->resources; resources; resources = resources->next) { 662 for(resources = jbi->jb->resources; resources; resources = resources->next) {
663 char *purdy = NULL; 663 char *purdy = NULL;
664 jbr = resources->data; 664 jbr = resources->data;
665 if(jbr->status) 665 if(jbr->status)
666 purdy = gaim_strdup_withhtml(jbr->status); 666 purdy = purple_strdup_withhtml(jbr->status);
667 if(jbr->name) 667 if(jbr->name)
668 gaim_notify_user_info_add_pair(user_info, _("Resource"), jbr->name); 668 purple_notify_user_info_add_pair(user_info, _("Resource"), jbr->name);
669 tmp = g_strdup_printf("%d", jbr->priority); 669 tmp = g_strdup_printf("%d", jbr->priority);
670 gaim_notify_user_info_add_pair(user_info, _("Priority"), tmp); 670 purple_notify_user_info_add_pair(user_info, _("Priority"), tmp);
671 g_free(tmp); 671 g_free(tmp);
672 672
673 tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state), 673 tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state),
674 (purdy ? ": " : ""), 674 (purdy ? ": " : ""),
675 (purdy ? purdy : "")); 675 (purdy ? purdy : ""));
676 gaim_notify_user_info_add_pair(user_info, _("Status"), tmp); 676 purple_notify_user_info_add_pair(user_info, _("Status"), tmp);
677 g_free(tmp); 677 g_free(tmp);
678 g_free(purdy); 678 g_free(purdy);
679 679
680 if(jbr->name) 680 if(jbr->name)
681 jbir = g_hash_table_lookup(jbi->resources, jbr->name); 681 jbir = g_hash_table_lookup(jbi->resources, jbr->name);
682 682
683 if(jbir) { 683 if(jbir) {
684 if(jbir->idle_seconds > 0) { 684 if(jbir->idle_seconds > 0) {
685 char *idle = gaim_str_seconds_to_string(jbir->idle_seconds); 685 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
686 gaim_notify_user_info_add_pair(user_info, _("Idle"), idle); 686 purple_notify_user_info_add_pair(user_info, _("Idle"), idle);
687 g_free(idle); 687 g_free(idle);
688 } 688 }
689 } 689 }
690 if(jbr && jbr->client.name) { 690 if(jbr && jbr->client.name) {
691 tmp = g_strdup_printf("%s%s%s", jbr->client.name, 691 tmp = g_strdup_printf("%s%s%s", jbr->client.name,
692 (jbr->client.version ? " " : ""), 692 (jbr->client.version ? " " : ""),
693 (jbr->client.version ? jbr->client.version : "")); 693 (jbr->client.version ? jbr->client.version : ""));
694 gaim_notify_user_info_add_pair(user_info, 694 purple_notify_user_info_add_pair(user_info,
695 _("Client"), tmp); 695 _("Client"), tmp);
696 g_free(tmp); 696 g_free(tmp);
697 697
698 if(jbr->client.os) { 698 if(jbr->client.os) {
699 gaim_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os); 699 purple_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os);
700 } 700 }
701 } 701 }
702 } 702 }
703 } 703 }
704 704
705 g_free(resource_name); 705 g_free(resource_name);
706 706
707 if (jbi->vcard_text != NULL) { 707 if (jbi->vcard_text != NULL) {
708 gaim_notify_user_info_add_section_break(user_info); 708 purple_notify_user_info_add_section_break(user_info);
709 /* Should this have some sort of label? */ 709 /* Should this have some sort of label? */
710 gaim_notify_user_info_add_pair(user_info, NULL, jbi->vcard_text); 710 purple_notify_user_info_add_pair(user_info, NULL, jbi->vcard_text);
711 } 711 }
712 712
713 gaim_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL); 713 purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL);
714 gaim_notify_user_info_destroy(user_info); 714 purple_notify_user_info_destroy(user_info);
715 715
716 while(jbi->vcard_imgids) { 716 while(jbi->vcard_imgids) {
717 gaim_imgstore_unref(GPOINTER_TO_INT(jbi->vcard_imgids->data)); 717 purple_imgstore_unref(GPOINTER_TO_INT(jbi->vcard_imgids->data));
718 jbi->vcard_imgids = g_slist_delete_link(jbi->vcard_imgids, jbi->vcard_imgids); 718 jbi->vcard_imgids = g_slist_delete_link(jbi->vcard_imgids, jbi->vcard_imgids);
719 } 719 }
720 720
721 jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi); 721 jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi);
722 722
747 const char *id, *from; 747 const char *id, *from;
748 GString *info_text; 748 GString *info_text;
749 char *bare_jid; 749 char *bare_jid;
750 char *text; 750 char *text;
751 xmlnode *vcard; 751 xmlnode *vcard;
752 GaimBuddy *b; 752 PurpleBuddy *b;
753 JabberBuddyInfo *jbi = data; 753 JabberBuddyInfo *jbi = data;
754 754
755 from = xmlnode_get_attrib(packet, "from"); 755 from = xmlnode_get_attrib(packet, "from");
756 id = xmlnode_get_attrib(packet, "id"); 756 id = xmlnode_get_attrib(packet, "id");
757 757
768 768
769 /* XXX: handle the error case */ 769 /* XXX: handle the error case */
770 770
771 bare_jid = jabber_get_bare_jid(from); 771 bare_jid = jabber_get_bare_jid(from);
772 772
773 b = gaim_find_buddy(js->gc->account, bare_jid); 773 b = purple_find_buddy(js->gc->account, bare_jid);
774 774
775 info_text = g_string_new(""); 775 info_text = g_string_new("");
776 776
777 if((vcard = xmlnode_get_child(packet, "vCard")) || 777 if((vcard = xmlnode_get_child(packet, "vCard")) ||
778 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { 778 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
813 g_free(text2); 813 g_free(text2);
814 } 814 }
815 } else if(text && !strcmp(child->name, "NICKNAME")) { 815 } else if(text && !strcmp(child->name, "NICKNAME")) {
816 serv_got_alias(js->gc, from, text); 816 serv_got_alias(js->gc, from, text);
817 if(b) { 817 if(b) {
818 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); 818 purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", text);
819 } 819 }
820 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", 820 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
821 _("Nickname"), text); 821 _("Nickname"), text);
822 } else if(text && !strcmp(child->name, "BDAY")) { 822 } else if(text && !strcmp(child->name, "BDAY")) {
823 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", 823 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
886 g_string_append_printf(info_text, 886 g_string_append_printf(info_text,
887 "<b>%s:</b> %s<br/>", _("Telephone"), number); 887 "<b>%s:</b> %s<br/>", _("Telephone"), number);
888 g_free(number); 888 g_free(number);
889 } 889 }
890 } else if((number = xmlnode_get_data(child))) { 890 } else if((number = xmlnode_get_data(child))) {
891 /* lots of clients (including gaim) do this, but it's 891 /* lots of clients (including purple) do this, but it's
892 * out of spec */ 892 * out of spec */
893 g_string_append_printf(info_text, 893 g_string_append_printf(info_text,
894 "<b>%s:</b> %s<br/>", _("Telephone"), number); 894 "<b>%s:</b> %s<br/>", _("Telephone"), number);
895 g_free(number); 895 g_free(number);
896 } 896 }
904 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", 904 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>",
905 _("E-Mail"), userid, userid); 905 _("E-Mail"), userid, userid);
906 g_free(userid); 906 g_free(userid);
907 } 907 }
908 } else if((userid = xmlnode_get_data(child))) { 908 } else if((userid = xmlnode_get_data(child))) {
909 /* lots of clients (including gaim) do this, but it's 909 /* lots of clients (including purple) do this, but it's
910 * out of spec */ 910 * out of spec */
911 g_string_append_printf(info_text, 911 g_string_append_printf(info_text,
912 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", 912 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>",
913 _("E-Mail"), userid, userid); 913 _("E-Mail"), userid, userid);
914 g_free(userid); 914 g_free(userid);
955 int i; 955 int i;
956 unsigned char hashval[20]; 956 unsigned char hashval[20];
957 char *p, hash[41]; 957 char *p, hash[41];
958 gboolean photo = (strcmp(child->name, "PHOTO") == 0); 958 gboolean photo = (strcmp(child->name, "PHOTO") == 0);
959 959
960 data = gaim_base64_decode(bintext, &size); 960 data = purple_base64_decode(bintext, &size);
961 961
962 jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(gaim_imgstore_add(data, size, "logo.png"))); 962 jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add(data, size, "logo.png")));
963 g_string_append_printf(info_text, 963 g_string_append_printf(info_text,
964 "<b>%s:</b> <img id='%d'><br/>", 964 "<b>%s:</b> <img id='%d'><br/>",
965 photo ? _("Photo") : _("Logo"), 965 photo ? _("Photo") : _("Logo"),
966 GPOINTER_TO_INT(jbi->vcard_imgids->data)); 966 GPOINTER_TO_INT(jbi->vcard_imgids->data));
967 967
968 gaim_buddy_icons_set_for_user(js->gc->account, bare_jid, 968 purple_buddy_icons_set_for_user(js->gc->account, bare_jid,
969 data, size); 969 data, size);
970 970
971 gaim_cipher_digest_region("sha1", (guchar *)data, size, 971 purple_cipher_digest_region("sha1", (guchar *)data, size,
972 sizeof(hashval), hashval, NULL); 972 sizeof(hashval), hashval, NULL);
973 p = hash; 973 p = hash;
974 for(i=0; i<20; i++, p+=2) 974 for(i=0; i<20; i++, p+=2)
975 snprintf(p, 3, "%02x", hashval[i]); 975 snprintf(p, 3, "%02x", hashval[i]);
976 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); 976 purple_blist_node_set_string((PurpleBlistNode*)b, "avatar_hash", hash);
977 977
978 g_free(data); 978 g_free(data);
979 g_free(bintext); 979 g_free(bintext);
980 } 980 }
981 } 981 }
982 g_free(text); 982 g_free(text);
983 } 983 }
984 } 984 }
985 985
986 jbi->vcard_text = gaim_strdup_withhtml(info_text->str); 986 jbi->vcard_text = purple_strdup_withhtml(info_text->str);
987 g_string_free(info_text, TRUE); 987 g_string_free(info_text, TRUE);
988 g_free(bare_jid); 988 g_free(bare_jid);
989 989
990 jabber_buddy_info_show_if_ready(jbi); 990 jabber_buddy_info_show_if_ready(jbi);
991 } 991 }
1188 1188
1189 g_free(full_jid); 1189 g_free(full_jid);
1190 } 1190 }
1191 1191
1192 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi); 1192 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi);
1193 jbi->timeout_handle = gaim_timeout_add(30000, jabber_buddy_get_info_timeout, jbi); 1193 jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi);
1194 } 1194 }
1195 1195
1196 void jabber_buddy_get_info(GaimConnection *gc, const char *who) 1196 void jabber_buddy_get_info(PurpleConnection *gc, const char *who)
1197 { 1197 {
1198 JabberStream *js = gc->proto_data; 1198 JabberStream *js = gc->proto_data;
1199 char *bare_jid = jabber_get_bare_jid(who); 1199 char *bare_jid = jabber_get_bare_jid(who);
1200 1200
1201 if(bare_jid) { 1201 if(bare_jid) {
1202 jabber_buddy_get_info_for_jid(js, bare_jid); 1202 jabber_buddy_get_info_for_jid(js, bare_jid);
1203 g_free(bare_jid); 1203 g_free(bare_jid);
1204 } 1204 }
1205 } 1205 }
1206 1206
1207 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, 1207 void jabber_buddy_get_info_chat(PurpleConnection *gc, int id,
1208 const char *resource) 1208 const char *resource)
1209 { 1209 {
1210 JabberStream *js = gc->proto_data; 1210 JabberStream *js = gc->proto_data;
1211 JabberChat *chat = jabber_chat_find_by_id(js, id); 1211 JabberChat *chat = jabber_chat_find_by_id(js, id);
1212 char *full_jid; 1212 char *full_jid;
1221 1221
1222 1222
1223 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, 1223 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who,
1224 gboolean invisible) 1224 gboolean invisible)
1225 { 1225 {
1226 GaimPresence *gpresence; 1226 PurplePresence *gpresence;
1227 GaimAccount *account; 1227 PurpleAccount *account;
1228 GaimStatus *status; 1228 PurpleStatus *status;
1229 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); 1229 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE);
1230 xmlnode *presence; 1230 xmlnode *presence;
1231 JabberBuddyState state; 1231 JabberBuddyState state;
1232 char *msg; 1232 char *msg;
1233 int priority; 1233 int priority;
1234 1234
1235 account = gaim_connection_get_account(js->gc); 1235 account = purple_connection_get_account(js->gc);
1236 gpresence = gaim_account_get_presence(account); 1236 gpresence = purple_account_get_presence(account);
1237 status = gaim_presence_get_active_status(gpresence); 1237 status = purple_presence_get_active_status(gpresence);
1238 1238
1239 gaim_status_to_jabber(status, &state, &msg, &priority); 1239 purple_status_to_jabber(status, &state, &msg, &priority);
1240 presence = jabber_presence_create(state, msg, priority); 1240 presence = jabber_presence_create(state, msg, priority);
1241 1241
1242 g_free(msg); 1242 g_free(msg);
1243 1243
1244 xmlnode_set_attrib(presence, "to", who); 1244 xmlnode_set_attrib(presence, "to", who);
1251 1251
1252 jabber_send(js, presence); 1252 jabber_send(js, presence);
1253 xmlnode_free(presence); 1253 xmlnode_free(presence);
1254 } 1254 }
1255 1255
1256 static void jabber_buddy_make_invisible(GaimBlistNode *node, gpointer data) 1256 static void jabber_buddy_make_invisible(PurpleBlistNode *node, gpointer data)
1257 { 1257 {
1258 GaimBuddy *buddy; 1258 PurpleBuddy *buddy;
1259 GaimConnection *gc; 1259 PurpleConnection *gc;
1260 JabberStream *js; 1260 JabberStream *js;
1261 1261
1262 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); 1262 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1263 1263
1264 buddy = (GaimBuddy *) node; 1264 buddy = (PurpleBuddy *) node;
1265 gc = gaim_account_get_connection(buddy->account); 1265 gc = purple_account_get_connection(buddy->account);
1266 js = gc->proto_data; 1266 js = gc->proto_data;
1267 1267
1268 jabber_buddy_set_invisibility(js, buddy->name, TRUE); 1268 jabber_buddy_set_invisibility(js, buddy->name, TRUE);
1269 } 1269 }
1270 1270
1271 static void jabber_buddy_make_visible(GaimBlistNode *node, gpointer data) 1271 static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data)
1272 { 1272 {
1273 GaimBuddy *buddy; 1273 PurpleBuddy *buddy;
1274 GaimConnection *gc; 1274 PurpleConnection *gc;
1275 JabberStream *js; 1275 JabberStream *js;
1276 1276
1277 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); 1277 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1278 1278
1279 buddy = (GaimBuddy *) node; 1279 buddy = (PurpleBuddy *) node;
1280 gc = gaim_account_get_connection(buddy->account); 1280 gc = purple_account_get_connection(buddy->account);
1281 js = gc->proto_data; 1281 js = gc->proto_data;
1282 1282
1283 jabber_buddy_set_invisibility(js, buddy->name, FALSE); 1283 jabber_buddy_set_invisibility(js, buddy->name, FALSE);
1284 } 1284 }
1285 1285
1286 static void jabber_buddy_cancel_presence_notification(GaimBlistNode *node, 1286 static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node,
1287 gpointer data) 1287 gpointer data)
1288 { 1288 {
1289 GaimBuddy *buddy; 1289 PurpleBuddy *buddy;
1290 GaimConnection *gc; 1290 PurpleConnection *gc;
1291 JabberStream *js; 1291 JabberStream *js;
1292 1292
1293 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); 1293 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1294 1294
1295 buddy = (GaimBuddy *) node; 1295 buddy = (PurpleBuddy *) node;
1296 gc = gaim_account_get_connection(buddy->account); 1296 gc = purple_account_get_connection(buddy->account);
1297 js = gc->proto_data; 1297 js = gc->proto_data;
1298 1298
1299 /* I wonder if we should prompt the user before doing this */ 1299 /* I wonder if we should prompt the user before doing this */
1300 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); 1300 jabber_presence_subscription_set(js, buddy->name, "unsubscribed");
1301 } 1301 }
1302 1302
1303 static void jabber_buddy_rerequest_auth(GaimBlistNode *node, gpointer data) 1303 static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data)
1304 { 1304 {
1305 GaimBuddy *buddy; 1305 PurpleBuddy *buddy;
1306 GaimConnection *gc; 1306 PurpleConnection *gc;
1307 JabberStream *js; 1307 JabberStream *js;
1308 1308
1309 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); 1309 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1310 1310
1311 buddy = (GaimBuddy *) node; 1311 buddy = (PurpleBuddy *) node;
1312 gc = gaim_account_get_connection(buddy->account); 1312 gc = purple_account_get_connection(buddy->account);
1313 js = gc->proto_data; 1313 js = gc->proto_data;
1314 1314
1315 jabber_presence_subscription_set(js, buddy->name, "subscribe"); 1315 jabber_presence_subscription_set(js, buddy->name, "subscribe");
1316 } 1316 }
1317 1317
1318 1318
1319 static void jabber_buddy_unsubscribe(GaimBlistNode *node, gpointer data) 1319 static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data)
1320 { 1320 {
1321 GaimBuddy *buddy; 1321 PurpleBuddy *buddy;
1322 GaimConnection *gc; 1322 PurpleConnection *gc;
1323 JabberStream *js; 1323 JabberStream *js;
1324 1324
1325 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); 1325 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1326 1326
1327 buddy = (GaimBuddy *) node; 1327 buddy = (PurpleBuddy *) node;
1328 gc = gaim_account_get_connection(buddy->account); 1328 gc = purple_account_get_connection(buddy->account);
1329 js = gc->proto_data; 1329 js = gc->proto_data;
1330 1330
1331 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); 1331 jabber_presence_subscription_set(js, buddy->name, "unsubscribe");
1332 } 1332 }
1333 1333
1334 1334
1335 static GList *jabber_buddy_menu(GaimBuddy *buddy) 1335 static GList *jabber_buddy_menu(PurpleBuddy *buddy)
1336 { 1336 {
1337 GaimConnection *gc = gaim_account_get_connection(buddy->account); 1337 PurpleConnection *gc = purple_account_get_connection(buddy->account);
1338 JabberStream *js = gc->proto_data; 1338 JabberStream *js = gc->proto_data;
1339 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); 1339 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE);
1340 1340
1341 GList *m = NULL; 1341 GList *m = NULL;
1342 GaimMenuAction *act; 1342 PurpleMenuAction *act;
1343 1343
1344 if(!jb) 1344 if(!jb)
1345 return m; 1345 return m;
1346 1346
1347 /* XXX: fix the NOT ME below */ 1347 /* XXX: fix the NOT ME below */
1348 1348
1349 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { 1349 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) {
1350 if(jb->invisible & JABBER_INVIS_BUDDY) { 1350 if(jb->invisible & JABBER_INVIS_BUDDY) {
1351 act = gaim_menu_action_new(_("Un-hide From"), 1351 act = purple_menu_action_new(_("Un-hide From"),
1352 GAIM_CALLBACK(jabber_buddy_make_visible), 1352 PURPLE_CALLBACK(jabber_buddy_make_visible),
1353 NULL, NULL); 1353 NULL, NULL);
1354 } else { 1354 } else {
1355 act = gaim_menu_action_new(_("Temporarily Hide From"), 1355 act = purple_menu_action_new(_("Temporarily Hide From"),
1356 GAIM_CALLBACK(jabber_buddy_make_invisible), 1356 PURPLE_CALLBACK(jabber_buddy_make_invisible),
1357 NULL, NULL); 1357 NULL, NULL);
1358 } 1358 }
1359 m = g_list_append(m, act); 1359 m = g_list_append(m, act);
1360 } 1360 }
1361 1361
1362 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { 1362 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) {
1363 act = gaim_menu_action_new(_("Cancel Presence Notification"), 1363 act = purple_menu_action_new(_("Cancel Presence Notification"),
1364 GAIM_CALLBACK(jabber_buddy_cancel_presence_notification), 1364 PURPLE_CALLBACK(jabber_buddy_cancel_presence_notification),
1365 NULL, NULL); 1365 NULL, NULL);
1366 m = g_list_append(m, act); 1366 m = g_list_append(m, act);
1367 } 1367 }
1368 1368
1369 if(!(jb->subscription & JABBER_SUB_TO)) { 1369 if(!(jb->subscription & JABBER_SUB_TO)) {
1370 act = gaim_menu_action_new(_("(Re-)Request authorization"), 1370 act = purple_menu_action_new(_("(Re-)Request authorization"),
1371 GAIM_CALLBACK(jabber_buddy_rerequest_auth), 1371 PURPLE_CALLBACK(jabber_buddy_rerequest_auth),
1372 NULL, NULL); 1372 NULL, NULL);
1373 m = g_list_append(m, act); 1373 m = g_list_append(m, act);
1374 1374
1375 } else /* if(NOT ME) */{ 1375 } else /* if(NOT ME) */{
1376 1376
1377 /* shouldn't this just happen automatically when the buddy is 1377 /* shouldn't this just happen automatically when the buddy is
1378 removed? */ 1378 removed? */
1379 act = gaim_menu_action_new(_("Unsubscribe"), 1379 act = purple_menu_action_new(_("Unsubscribe"),
1380 GAIM_CALLBACK(jabber_buddy_unsubscribe), 1380 PURPLE_CALLBACK(jabber_buddy_unsubscribe),
1381 NULL, NULL); 1381 NULL, NULL);
1382 m = g_list_append(m, act); 1382 m = g_list_append(m, act);
1383 } 1383 }
1384 1384
1385 return m; 1385 return m;
1386 } 1386 }
1387 1387
1388 GList * 1388 GList *
1389 jabber_blist_node_menu(GaimBlistNode *node) 1389 jabber_blist_node_menu(PurpleBlistNode *node)
1390 { 1390 {
1391 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { 1391 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
1392 return jabber_buddy_menu((GaimBuddy *) node); 1392 return jabber_buddy_menu((PurpleBuddy *) node);
1393 } else { 1393 } else {
1394 return NULL; 1394 return NULL;
1395 } 1395 }
1396 } 1396 }
1397 1397
1504 return "offline"; 1504 return "offline";
1505 } 1505 }
1506 return NULL; 1506 return NULL;
1507 } 1507 }
1508 1508
1509 static void user_search_result_add_buddy_cb(GaimConnection *gc, GList *row, void *user_data) 1509 static void user_search_result_add_buddy_cb(PurpleConnection *gc, GList *row, void *user_data)
1510 { 1510 {
1511 /* XXX find out the jid */ 1511 /* XXX find out the jid */
1512 gaim_blist_request_add_buddy(gaim_connection_get_account(gc), 1512 purple_blist_request_add_buddy(purple_connection_get_account(gc),
1513 g_list_nth_data(row, 0), NULL, NULL); 1513 g_list_nth_data(row, 0), NULL, NULL);
1514 } 1514 }
1515 1515
1516 static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 1516 static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
1517 { 1517 {
1518 GaimNotifySearchResults *results; 1518 PurpleNotifySearchResults *results;
1519 GaimNotifySearchColumn *column; 1519 PurpleNotifySearchColumn *column;
1520 xmlnode *x, *query, *item, *field; 1520 xmlnode *x, *query, *item, *field;
1521 1521
1522 /* XXX error checking? */ 1522 /* XXX error checking? */
1523 if(!(query = xmlnode_get_child(packet, "query"))) 1523 if(!(query = xmlnode_get_child(packet, "query")))
1524 return; 1524 return;
1525 1525
1526 results = gaim_notify_searchresults_new(); 1526 results = purple_notify_searchresults_new();
1527 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { 1527 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) {
1528 xmlnode *reported; 1528 xmlnode *reported;
1529 gaim_debug_info("jabber", "new-skool\n"); 1529 purple_debug_info("jabber", "new-skool\n");
1530 if((reported = xmlnode_get_child(x, "reported"))) { 1530 if((reported = xmlnode_get_child(x, "reported"))) {
1531 xmlnode *field = xmlnode_get_child(reported, "field"); 1531 xmlnode *field = xmlnode_get_child(reported, "field");
1532 while(field) { 1532 while(field) {
1533 /* XXX keep track of this order, use it below */ 1533 /* XXX keep track of this order, use it below */
1534 const char *var = xmlnode_get_attrib(field, "var"); 1534 const char *var = xmlnode_get_attrib(field, "var");
1535 const char *label = xmlnode_get_attrib(field, "label"); 1535 const char *label = xmlnode_get_attrib(field, "label");
1536 if(var) { 1536 if(var) {
1537 column = gaim_notify_searchresults_column_new(label ? label : var); 1537 column = purple_notify_searchresults_column_new(label ? label : var);
1538 gaim_notify_searchresults_column_add(results, column); 1538 purple_notify_searchresults_column_add(results, column);
1539 } 1539 }
1540 field = xmlnode_get_next_twin(field); 1540 field = xmlnode_get_next_twin(field);
1541 } 1541 }
1542 } 1542 }
1543 item = xmlnode_get_child(x, "item"); 1543 item = xmlnode_get_child(x, "item");
1550 char *value = xmlnode_get_data(valuenode); 1550 char *value = xmlnode_get_data(valuenode);
1551 row = g_list_append(row, value); 1551 row = g_list_append(row, value);
1552 } 1552 }
1553 field = xmlnode_get_next_twin(field); 1553 field = xmlnode_get_next_twin(field);
1554 } 1554 }
1555 gaim_notify_searchresults_row_add(results, row); 1555 purple_notify_searchresults_row_add(results, row);
1556 1556
1557 item = xmlnode_get_next_twin(item); 1557 item = xmlnode_get_next_twin(item);
1558 } 1558 }
1559 } else { 1559 } else {
1560 /* old skool */ 1560 /* old skool */
1561 gaim_debug_info("jabber", "old-skool\n"); 1561 purple_debug_info("jabber", "old-skool\n");
1562 1562
1563 column = gaim_notify_searchresults_column_new(_("JID")); 1563 column = purple_notify_searchresults_column_new(_("JID"));
1564 gaim_notify_searchresults_column_add(results, column); 1564 purple_notify_searchresults_column_add(results, column);
1565 column = gaim_notify_searchresults_column_new(_("First Name")); 1565 column = purple_notify_searchresults_column_new(_("First Name"));
1566 gaim_notify_searchresults_column_add(results, column); 1566 purple_notify_searchresults_column_add(results, column);
1567 column = gaim_notify_searchresults_column_new(_("Last Name")); 1567 column = purple_notify_searchresults_column_new(_("Last Name"));
1568 gaim_notify_searchresults_column_add(results, column); 1568 purple_notify_searchresults_column_add(results, column);
1569 column = gaim_notify_searchresults_column_new(_("Nickname")); 1569 column = purple_notify_searchresults_column_new(_("Nickname"));
1570 gaim_notify_searchresults_column_add(results, column); 1570 purple_notify_searchresults_column_add(results, column);
1571 column = gaim_notify_searchresults_column_new(_("E-Mail")); 1571 column = purple_notify_searchresults_column_new(_("E-Mail"));
1572 gaim_notify_searchresults_column_add(results, column); 1572 purple_notify_searchresults_column_add(results, column);
1573 1573
1574 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) { 1574 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) {
1575 const char *jid; 1575 const char *jid;
1576 xmlnode *node; 1576 xmlnode *node;
1577 GList *row = NULL; 1577 GList *row = NULL;
1586 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); 1586 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
1587 node = xmlnode_get_child(item, "nick"); 1587 node = xmlnode_get_child(item, "nick");
1588 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); 1588 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
1589 node = xmlnode_get_child(item, "email"); 1589 node = xmlnode_get_child(item, "email");
1590 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); 1590 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
1591 gaim_debug_info("jabber", "row=%d\n", row); 1591 purple_debug_info("jabber", "row=%d\n", row);
1592 gaim_notify_searchresults_row_add(results, row); 1592 purple_notify_searchresults_row_add(results, row);
1593 } 1593 }
1594 } 1594 }
1595 1595
1596 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD, 1596 purple_notify_searchresults_button_add(results, PURPLE_NOTIFY_BUTTON_ADD,
1597 user_search_result_add_buddy_cb); 1597 user_search_result_add_buddy_cb);
1598 1598
1599 gaim_notify_searchresults(js->gc, NULL, NULL, _("The following are the results of your search"), results, NULL, NULL); 1599 purple_notify_searchresults(js->gc, NULL, NULL, _("The following are the results of your search"), results, NULL, NULL);
1600 } 1600 }
1601 1601
1602 static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) 1602 static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
1603 { 1603 {
1604 xmlnode *query; 1604 xmlnode *query;
1619 struct user_search_info { 1619 struct user_search_info {
1620 JabberStream *js; 1620 JabberStream *js;
1621 char *directory_server; 1621 char *directory_server;
1622 }; 1622 };
1623 1623
1624 static void user_search_cancel_cb(struct user_search_info *usi, GaimRequestFields *fields) 1624 static void user_search_cancel_cb(struct user_search_info *usi, PurpleRequestFields *fields)
1625 { 1625 {
1626 g_free(usi->directory_server); 1626 g_free(usi->directory_server);
1627 g_free(usi); 1627 g_free(usi);
1628 } 1628 }
1629 1629
1630 static void user_search_cb(struct user_search_info *usi, GaimRequestFields *fields) 1630 static void user_search_cb(struct user_search_info *usi, PurpleRequestFields *fields)
1631 { 1631 {
1632 JabberStream *js = usi->js; 1632 JabberStream *js = usi->js;
1633 JabberIq *iq; 1633 JabberIq *iq;
1634 xmlnode *query; 1634 xmlnode *query;
1635 GList *groups, *flds; 1635 GList *groups, *flds;
1636 1636
1637 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search"); 1637 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search");
1638 query = xmlnode_get_child(iq->node, "query"); 1638 query = xmlnode_get_child(iq->node, "query");
1639 1639
1640 for(groups = gaim_request_fields_get_groups(fields); groups; groups = groups->next) { 1640 for(groups = purple_request_fields_get_groups(fields); groups; groups = groups->next) {
1641 for(flds = gaim_request_field_group_get_fields(groups->data); 1641 for(flds = purple_request_field_group_get_fields(groups->data);
1642 flds; flds = flds->next) { 1642 flds; flds = flds->next) {
1643 GaimRequestField *field = flds->data; 1643 PurpleRequestField *field = flds->data;
1644 const char *id = gaim_request_field_get_id(field); 1644 const char *id = purple_request_field_get_id(field);
1645 const char *value = gaim_request_field_string_get_value(field); 1645 const char *value = purple_request_field_string_get_value(field);
1646 1646
1647 if(value && (!strcmp(id, "first") || !strcmp(id, "last") || !strcmp(id, "nick") || !strcmp(id, "email"))) { 1647 if(value && (!strcmp(id, "first") || !strcmp(id, "last") || !strcmp(id, "nick") || !strcmp(id, "email"))) {
1648 xmlnode *y = xmlnode_new_child(query, id); 1648 xmlnode *y = xmlnode_new_child(query, id);
1649 xmlnode_insert_data(y, value, -1); 1649 xmlnode_insert_data(y, value, -1);
1650 } 1650 }
1665 /* 1665 /*
1666 * An incomplete list of server generated original language search 1666 * An incomplete list of server generated original language search
1667 * comments for Jabber User Directories 1667 * comments for Jabber User Directories
1668 * 1668 *
1669 * See discussion thread "Search comment for Jabber is not translatable" 1669 * See discussion thread "Search comment for Jabber is not translatable"
1670 * in gaim-i18n@lists.sourceforge.net (March 2006) 1670 * in purple-i18n@lists.sourceforge.net (March 2006)
1671 */ 1671 */
1672 static const char * jabber_user_dir_comments [] = { 1672 static const char * jabber_user_dir_comments [] = {
1673 /* current comment from Jabber User Directory users.jabber.org */ 1673 /* current comment from Jabber User Directory users.jabber.org */
1674 N_("Find a contact by entering the search criteria in the given fields. " 1674 N_("Find a contact by entering the search criteria in the given fields. "
1675 "Note: Each field supports wild card searches (%)"), 1675 "Note: Each field supports wild card searches (%)"),
1689 char *msg = jabber_parse_error(js, packet); 1689 char *msg = jabber_parse_error(js, packet);
1690 1690
1691 if(!msg) 1691 if(!msg)
1692 msg = g_strdup(_("Unknown error")); 1692 msg = g_strdup(_("Unknown error"));
1693 1693
1694 gaim_notify_error(js->gc, _("Directory Query Failed"), 1694 purple_notify_error(js->gc, _("Directory Query Failed"),
1695 _("Could not query the directory server."), msg); 1695 _("Could not query the directory server."), msg);
1696 g_free(msg); 1696 g_free(msg);
1697 1697
1698 return; 1698 return;
1699 } 1699 }
1707 return; 1707 return;
1708 } else { 1708 } else {
1709 struct user_search_info *usi; 1709 struct user_search_info *usi;
1710 xmlnode *instnode; 1710 xmlnode *instnode;
1711 char *instructions = NULL; 1711 char *instructions = NULL;
1712 GaimRequestFields *fields; 1712 PurpleRequestFields *fields;
1713 GaimRequestFieldGroup *group; 1713 PurpleRequestFieldGroup *group;
1714 GaimRequestField *field; 1714 PurpleRequestField *field;
1715 1715
1716 /* old skool */ 1716 /* old skool */
1717 fields = gaim_request_fields_new(); 1717 fields = purple_request_fields_new();
1718 group = gaim_request_field_group_new(NULL); 1718 group = purple_request_field_group_new(NULL);
1719 gaim_request_fields_add_group(fields, group); 1719 purple_request_fields_add_group(fields, group);
1720 1720
1721 if((instnode = xmlnode_get_child(query, "instructions"))) 1721 if((instnode = xmlnode_get_child(query, "instructions")))
1722 { 1722 {
1723 char *tmp = xmlnode_get_data(instnode); 1723 char *tmp = xmlnode_get_data(instnode);
1724 1724
1736 instructions = g_strdup(_("Fill in one or more fields to search " 1736 instructions = g_strdup(_("Fill in one or more fields to search "
1737 "for any matching Jabber users.")); 1737 "for any matching Jabber users."));
1738 } 1738 }
1739 1739
1740 if(xmlnode_get_child(query, "first")) { 1740 if(xmlnode_get_child(query, "first")) {
1741 field = gaim_request_field_string_new("first", _("First Name"), 1741 field = purple_request_field_string_new("first", _("First Name"),
1742 NULL, FALSE); 1742 NULL, FALSE);
1743 gaim_request_field_group_add_field(group, field); 1743 purple_request_field_group_add_field(group, field);
1744 } 1744 }
1745 if(xmlnode_get_child(query, "last")) { 1745 if(xmlnode_get_child(query, "last")) {
1746 field = gaim_request_field_string_new("last", _("Last Name"), 1746 field = purple_request_field_string_new("last", _("Last Name"),
1747 NULL, FALSE); 1747 NULL, FALSE);
1748 gaim_request_field_group_add_field(group, field); 1748 purple_request_field_group_add_field(group, field);
1749 } 1749 }
1750 if(xmlnode_get_child(query, "nick")) { 1750 if(xmlnode_get_child(query, "nick")) {
1751 field = gaim_request_field_string_new("nick", _("Nickname"), 1751 field = purple_request_field_string_new("nick", _("Nickname"),
1752 NULL, FALSE); 1752 NULL, FALSE);
1753 gaim_request_field_group_add_field(group, field); 1753 purple_request_field_group_add_field(group, field);
1754 } 1754 }
1755 if(xmlnode_get_child(query, "email")) { 1755 if(xmlnode_get_child(query, "email")) {
1756 field = gaim_request_field_string_new("email", _("E-Mail Address"), 1756 field = purple_request_field_string_new("email", _("E-Mail Address"),
1757 NULL, FALSE); 1757 NULL, FALSE);
1758 gaim_request_field_group_add_field(group, field); 1758 purple_request_field_group_add_field(group, field);
1759 } 1759 }
1760 1760
1761 usi = g_new0(struct user_search_info, 1); 1761 usi = g_new0(struct user_search_info, 1);
1762 usi->js = js; 1762 usi->js = js;
1763 usi->directory_server = g_strdup(from); 1763 usi->directory_server = g_strdup(from);
1764 1764
1765 gaim_request_fields(js->gc, _("Search for Jabber users"), 1765 purple_request_fields(js->gc, _("Search for Jabber users"),
1766 _("Search for Jabber users"), instructions, fields, 1766 _("Search for Jabber users"), instructions, fields,
1767 _("Search"), G_CALLBACK(user_search_cb), 1767 _("Search"), G_CALLBACK(user_search_cb),
1768 _("Cancel"), G_CALLBACK(user_search_cancel_cb), usi); 1768 _("Cancel"), G_CALLBACK(user_search_cancel_cb), usi);
1769 1769
1770 g_free(instructions); 1770 g_free(instructions);
1775 { 1775 {
1776 JabberIq *iq; 1776 JabberIq *iq;
1777 1777
1778 /* XXX: should probably better validate the directory we're given */ 1778 /* XXX: should probably better validate the directory we're given */
1779 if(!directory || !*directory) { 1779 if(!directory || !*directory) {
1780 gaim_notify_error(js->gc, _("Invalid Directory"), _("Invalid Directory"), NULL); 1780 purple_notify_error(js->gc, _("Invalid Directory"), _("Invalid Directory"), NULL);
1781 return; 1781 return;
1782 } 1782 }
1783 1783
1784 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search"); 1784 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search");
1785 xmlnode_set_attrib(iq->node, "to", directory); 1785 xmlnode_set_attrib(iq->node, "to", directory);
1787 jabber_iq_set_callback(iq, user_search_fields_result_cb, NULL); 1787 jabber_iq_set_callback(iq, user_search_fields_result_cb, NULL);
1788 1788
1789 jabber_iq_send(iq); 1789 jabber_iq_send(iq);
1790 } 1790 }
1791 1791
1792 void jabber_user_search_begin(GaimPluginAction *action) 1792 void jabber_user_search_begin(PurplePluginAction *action)
1793 { 1793 {
1794 GaimConnection *gc = (GaimConnection *) action->context; 1794 PurpleConnection *gc = (PurpleConnection *) action->context;
1795 JabberStream *js = gc->proto_data; 1795 JabberStream *js = gc->proto_data;
1796 1796
1797 gaim_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), 1797 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"),
1798 _("Select a user directory to search"), 1798 _("Select a user directory to search"),
1799 js->user_directories ? js->user_directories->data : "users.jabber.org", 1799 js->user_directories ? js->user_directories->data : "users.jabber.org",
1800 FALSE, FALSE, NULL, 1800 FALSE, FALSE, NULL,
1801 _("Search Directory"), GAIM_CALLBACK(jabber_user_search_ok), 1801 _("Search Directory"), PURPLE_CALLBACK(jabber_user_search_ok),
1802 _("Cancel"), NULL, js); 1802 _("Cancel"), NULL, js);
1803 } 1803 }
1804 1804
1805 1805
1806 1806

mercurial