comparison libpurple/protocols/jabber/jabber.c @ 19696:481749fc0b6b

merge of '1c7910841138381c841363256ca3c7905b1f26b0' and '5818cbd5fe95d6a167f1555b882526f36790b141'
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 10 Sep 2007 13:57:15 +0000
parents 1d2002a5735e 44b4e8bd759b
children eedf2918aace
comparison
equal deleted inserted replaced
19695:301f1597d41f 19696:481749fc0b6b
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 * 19 *
20 */ 20 */
21 #include "internal.h" 21 #include "internal.h"
22 22
23 #include "account.h" 23 #include "account.h"
69 static void jabber_stream_init(JabberStream *js) 69 static void jabber_stream_init(JabberStream *js)
70 { 70 {
71 char *open_stream; 71 char *open_stream;
72 72
73 open_stream = g_strdup_printf("<stream:stream to='%s' " 73 open_stream = g_strdup_printf("<stream:stream to='%s' "
74 "xmlns='jabber:client' " 74 "xmlns='jabber:client' "
75 "xmlns:stream='http://etherx.jabber.org/streams' " 75 "xmlns:stream='http://etherx.jabber.org/streams' "
76 "version='1.0'>", 76 "version='1.0'>",
77 js->user->domain); 77 js->user->domain);
78 /* setup the parser fresh for each stream */ 78 /* setup the parser fresh for each stream */
79 jabber_parser_setup(js); 79 jabber_parser_setup(js);
459 purple_ssl_close(gsc); 459 purple_ssl_close(gsc);
460 return; 460 return;
461 } 461 }
462 462
463 js = gc->proto_data; 463 js = gc->proto_data;
464 464
465 if(js->state == JABBER_STREAM_CONNECTING) 465 if(js->state == JABBER_STREAM_CONNECTING)
466 jabber_send_raw(js, "<?xml version='1.0' ?>", -1); 466 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
467 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); 467 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
468 purple_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); 468 purple_ssl_input_add(gsc, jabber_recv_cb_ssl, gc);
469 469
628 static gboolean 628 static gboolean
629 conn_close_cb(gpointer data) 629 conn_close_cb(gpointer data)
630 { 630 {
631 JabberStream *js = data; 631 JabberStream *js = data;
632 PurpleAccount *account = purple_connection_get_account(js->gc); 632 PurpleAccount *account = purple_connection_get_account(js->gc);
633 633
634 jabber_parser_free(js); 634 jabber_parser_free(js);
635 635
636 purple_account_disconnect(account); 636 purple_account_disconnect(account);
637 637
638 return FALSE; 638 return FALSE;
652 char *buf; 652 char *buf;
653 char *to = data; 653 char *to = data;
654 654
655 if(!strcmp(type, "result")) { 655 if(!strcmp(type, "result")) {
656 if(js->registration) { 656 if(js->registration) {
657 buf = g_strdup_printf(_("Registration of %s@%s successful"), 657 buf = g_strdup_printf(_("Registration of %s@%s successful"),
658 js->user->node, js->user->domain); 658 js->user->node, js->user->domain);
659 if(account->registration_cb) 659 if(account->registration_cb)
660 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); 660 (account->registration_cb)(account, TRUE, account->registration_cb_user_data);
661 } 661 }
662 else 662 else
677 if(account->registration_cb) 677 if(account->registration_cb)
678 (account->registration_cb)(account, FALSE, account->registration_cb_user_data); 678 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
679 } 679 }
680 g_free(to); 680 g_free(to);
681 if(js->registration) 681 if(js->registration)
682 jabber_connection_schedule_close(js); 682 jabber_connection_schedule_close(js);
683 } 683 }
684 684
685 static void 685 static void
686 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 686 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
687 { 687 {
747 jabber_iq_send(iq); 747 jabber_iq_send(iq);
748 g_free(cbdata); 748 g_free(cbdata);
749 return; 749 return;
750 } 750 }
751 } else { 751 } else {
752 const char *value = purple_request_field_string_get_value(field); 752 const char *value = purple_request_field_string_get_value(field);
753 753
754 if(!strcmp(id, "username")) { 754 if(!strcmp(id, "username")) {
755 y = xmlnode_new_child(query, "username"); 755 y = xmlnode_new_child(query, "username");
756 } else if(!strcmp(id, "password")) { 756 } else if(!strcmp(id, "password")) {
757 y = xmlnode_new_child(query, "password"); 757 y = xmlnode_new_child(query, "password");
758 } else if(!strcmp(id, "name")) { 758 } else if(!strcmp(id, "name")) {
759 y = xmlnode_new_child(query, "name"); 759 y = xmlnode_new_child(query, "name");
760 } else if(!strcmp(id, "email")) { 760 } else if(!strcmp(id, "email")) {
761 y = xmlnode_new_child(query, "email"); 761 y = xmlnode_new_child(query, "email");
762 } else if(!strcmp(id, "nick")) { 762 } else if(!strcmp(id, "nick")) {
763 y = xmlnode_new_child(query, "nick"); 763 y = xmlnode_new_child(query, "nick");
764 } else if(!strcmp(id, "first")) { 764 } else if(!strcmp(id, "first")) {
765 y = xmlnode_new_child(query, "first"); 765 y = xmlnode_new_child(query, "first");
766 } else if(!strcmp(id, "last")) { 766 } else if(!strcmp(id, "last")) {
767 y = xmlnode_new_child(query, "last"); 767 y = xmlnode_new_child(query, "last");
768 } else if(!strcmp(id, "address")) { 768 } else if(!strcmp(id, "address")) {
769 y = xmlnode_new_child(query, "address"); 769 y = xmlnode_new_child(query, "address");
770 } else if(!strcmp(id, "city")) { 770 } else if(!strcmp(id, "city")) {
771 y = xmlnode_new_child(query, "city"); 771 y = xmlnode_new_child(query, "city");
772 } else if(!strcmp(id, "state")) { 772 } else if(!strcmp(id, "state")) {
773 y = xmlnode_new_child(query, "state"); 773 y = xmlnode_new_child(query, "state");
774 } else if(!strcmp(id, "zip")) { 774 } else if(!strcmp(id, "zip")) {
775 y = xmlnode_new_child(query, "zip"); 775 y = xmlnode_new_child(query, "zip");
776 } else if(!strcmp(id, "phone")) { 776 } else if(!strcmp(id, "phone")) {
777 y = xmlnode_new_child(query, "phone"); 777 y = xmlnode_new_child(query, "phone");
778 } else if(!strcmp(id, "url")) { 778 } else if(!strcmp(id, "url")) {
779 y = xmlnode_new_child(query, "url"); 779 y = xmlnode_new_child(query, "url");
780 } else if(!strcmp(id, "date")) { 780 } else if(!strcmp(id, "date")) {
781 y = xmlnode_new_child(query, "date"); 781 y = xmlnode_new_child(query, "date");
782 } else { 782 } else {
783 continue; 783 continue;
784 } 784 }
785 xmlnode_insert_data(y, value, -1); 785 xmlnode_insert_data(y, value, -1);
786 if(cbdata->js->registration && !strcmp(id, "username")) { 786 if(cbdata->js->registration && !strcmp(id, "username")) {
787 if(cbdata->js->user->node) 787 if(cbdata->js->user->node)
788 g_free(cbdata->js->user->node); 788 g_free(cbdata->js->user->node);
789 cbdata->js->user->node = g_strdup(value); 789 cbdata->js->user->node = g_strdup(value);
790 } 790 }
791 if(cbdata->js->registration && !strcmp(id, "password")) 791 if(cbdata->js->registration && !strcmp(id, "password"))
792 purple_account_set_password(cbdata->js->gc->account, value); 792 purple_account_set_password(cbdata->js->gc->account, value);
793 } 793 }
794 } 794 }
795 } 795 }
796 796
797 if(cbdata->js->registration) { 797 if(cbdata->js->registration) {
798 username = g_strdup_printf("%s@%s/%s", cbdata->js->user->node, cbdata->js->user->domain, 798 username = g_strdup_printf("%s@%s/%s", cbdata->js->user->node, cbdata->js->user->domain,
799 cbdata->js->user->resource); 799 cbdata->js->user->resource);
800 purple_account_set_username(cbdata->js->gc->account, username); 800 purple_account_set_username(cbdata->js->gc->account, username);
801 g_free(username); 801 g_free(username);
802 } 802 }
803 803
804 jabber_iq_set_callback(iq, jabber_registration_result_cb, cbdata->who); 804 jabber_iq_set_callback(iq, jabber_registration_result_cb, cbdata->who);
805 805
806 jabber_iq_send(iq); 806 jabber_iq_send(iq);
813 PurpleAccount *account = purple_connection_get_account(cbdata->js->gc); 813 PurpleAccount *account = purple_connection_get_account(cbdata->js->gc);
814 if(account && cbdata->js->registration) { 814 if(account && cbdata->js->registration) {
815 if(account->registration_cb) 815 if(account->registration_cb)
816 (account->registration_cb)(account, FALSE, account->registration_cb_user_data); 816 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
817 jabber_connection_schedule_close(cbdata->js); 817 jabber_connection_schedule_close(cbdata->js);
818 } 818 }
819 g_free(cbdata->who); 819 g_free(cbdata->who);
820 g_free(cbdata); 820 g_free(cbdata);
821 } 821 }
822 822
823 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) 823 static void jabber_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
839 void jabber_register_parse(JabberStream *js, xmlnode *packet) 839 void jabber_register_parse(JabberStream *js, xmlnode *packet)
840 { 840 {
841 PurpleAccount *account = purple_connection_get_account(js->gc); 841 PurpleAccount *account = purple_connection_get_account(js->gc);
842 const char *type; 842 const char *type;
843 const char *from = xmlnode_get_attrib(packet, "from"); 843 const char *from = xmlnode_get_attrib(packet, "from");
844 PurpleRequestFields *fields; 844 PurpleRequestFields *fields;
845 PurpleRequestFieldGroup *group; 845 PurpleRequestFieldGroup *group;
846 PurpleRequestField *field; 846 PurpleRequestField *field;
847 xmlnode *query, *x, *y; 847 xmlnode *query, *x, *y;
848 char *instructions; 848 char *instructions;
849 JabberRegisterCBData *cbdata; 849 JabberRegisterCBData *cbdata;
850 gboolean registered = FALSE; 850 gboolean registered = FALSE;
851 851
852 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) 852 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result"))
853 return; 853 return;
854 854
855 if(js->registration) 855 if(js->registration)
856 /* get rid of the login thingy */ 856 /* get rid of the login thingy */
857 purple_connection_set_state(js->gc, PURPLE_CONNECTED); 857 purple_connection_set_state(js->gc, PURPLE_CONNECTED);
858 858
859 query = xmlnode_get_child(packet, "query"); 859 query = xmlnode_get_child(packet, "query");
860 860
861 if(xmlnode_get_child(query, "registered")) { 861 if(xmlnode_get_child(query, "registered")) {
862 registered = TRUE; 862 registered = TRUE;
863 863
864 if(js->registration) { 864 if(js->registration) {
865 purple_notify_error(NULL, _("Already Registered"), 865 purple_notify_error(NULL, _("Already Registered"),
866 _("Already Registered"), NULL); 866 _("Already Registered"), NULL);
869 jabber_connection_schedule_close(js); 869 jabber_connection_schedule_close(js);
870 return; 870 return;
871 } 871 }
872 } 872 }
873 873
874 if((x = xmlnode_get_child_with_namespace(packet, "x", 874 if((x = xmlnode_get_child_with_namespace(packet, "x",
875 "jabber:x:data"))) { 875 "jabber:x:data"))) {
876 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); 876 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from));
877 return; 877 return;
878 } else if((x = xmlnode_get_child_with_namespace(packet, "x", 878 } else if((x = xmlnode_get_child_with_namespace(packet, "x",
879 "jabber:x:oob"))) { 879 "jabber:x:oob"))) {
880 xmlnode *url; 880 xmlnode *url;
881 881
882 if((url = xmlnode_get_child(x, "url"))) { 882 if((url = xmlnode_get_child(x, "url"))) {
883 char *href; 883 char *href;
884 if((href = xmlnode_get_data(url))) { 884 if((href = xmlnode_get_data(url))) {
885 purple_notify_uri(NULL, href); 885 purple_notify_uri(NULL, href);
886 g_free(href); 886 g_free(href);
887 if(js->registration) { 887 if(js->registration) {
888 js->gc->wants_to_die = TRUE; 888 js->gc->wants_to_die = TRUE;
889 if(account->registration_cb) /* succeeded, but we have no login info */ 889 if(account->registration_cb) /* succeeded, but we have no login info */
890 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); 890 (account->registration_cb)(account, TRUE, account->registration_cb_user_data);
891 jabber_connection_schedule_close(js); 891 jabber_connection_schedule_close(js);
892 } 892 }
893 return; 893 return;
894 }
894 } 895 }
895 } 896 }
896 } 897
897 898 /* as a last resort, use the old jabber:iq:register syntax */
898 /* as a last resort, use the old jabber:iq:register syntax */ 899
899 900 fields = purple_request_fields_new();
900 fields = purple_request_fields_new(); 901 group = purple_request_field_group_new(NULL);
901 group = purple_request_field_group_new(NULL); 902 purple_request_fields_add_group(fields, group);
902 purple_request_fields_add_group(fields, group);
903 903
904 if(js->registration) 904 if(js->registration)
905 field = purple_request_field_string_new("username", _("Username"), 905 field = purple_request_field_string_new("username", _("Username"),
906 js->user->node, FALSE); 906 js->user->node, FALSE);
907 else 907 else
908 field = purple_request_field_string_new("username", _("Username"), 908 field = purple_request_field_string_new("username", _("Username"),
909 NULL, FALSE); 909 NULL, FALSE);
910 910
911 purple_request_field_group_add_field(group, field); 911 purple_request_field_group_add_field(group, field);
912 912
913 if(js->registration) 913 if(js->registration)
914 field = purple_request_field_string_new("password", _("Password"), 914 field = purple_request_field_string_new("password", _("Password"),
915 purple_connection_get_password(js->gc), FALSE); 915 purple_connection_get_password(js->gc), FALSE);
916 else 916 else
917 field = purple_request_field_string_new("password", _("Password"), 917 field = purple_request_field_string_new("password", _("Password"),
918 NULL, FALSE); 918 NULL, FALSE);
919 919
920 purple_request_field_string_set_masked(field, TRUE); 920 purple_request_field_string_set_masked(field, TRUE);
921 purple_request_field_group_add_field(group, field); 921 purple_request_field_group_add_field(group, field);
922 922
923 if(xmlnode_get_child(query, "name")) { 923 if(xmlnode_get_child(query, "name")) {
924 if(js->registration) 924 if(js->registration)
925 field = purple_request_field_string_new("name", _("Name"), 925 field = purple_request_field_string_new("name", _("Name"),
926 purple_account_get_alias(js->gc->account), FALSE); 926 purple_account_get_alias(js->gc->account), FALSE);
927 else 927 else
928 field = purple_request_field_string_new("name", _("Name"), 928 field = purple_request_field_string_new("name", _("Name"),
929 NULL, FALSE); 929 NULL, FALSE);
930 purple_request_field_group_add_field(group, field); 930 purple_request_field_group_add_field(group, field);
931 } 931 }
932 if(xmlnode_get_child(query, "email")) { 932 if(xmlnode_get_child(query, "email")) {
933 field = purple_request_field_string_new("email", _("E-mail"), 933 field = purple_request_field_string_new("email", _("E-mail"),
934 NULL, FALSE); 934 NULL, FALSE);
935 purple_request_field_group_add_field(group, field); 935 purple_request_field_group_add_field(group, field);
936 } 936 }
937 if(xmlnode_get_child(query, "nick")) { 937 if(xmlnode_get_child(query, "nick")) {
938 field = purple_request_field_string_new("nick", _("Nickname"), 938 field = purple_request_field_string_new("nick", _("Nickname"),
939 NULL, FALSE); 939 NULL, FALSE);
940 purple_request_field_group_add_field(group, field); 940 purple_request_field_group_add_field(group, field);
941 } 941 }
942 if(xmlnode_get_child(query, "first")) { 942 if(xmlnode_get_child(query, "first")) {
943 field = purple_request_field_string_new("first", _("First name"), 943 field = purple_request_field_string_new("first", _("First name"),
944 NULL, FALSE); 944 NULL, FALSE);
945 purple_request_field_group_add_field(group, field); 945 purple_request_field_group_add_field(group, field);
946 } 946 }
947 if(xmlnode_get_child(query, "last")) { 947 if(xmlnode_get_child(query, "last")) {
948 field = purple_request_field_string_new("last", _("Last name"), 948 field = purple_request_field_string_new("last", _("Last name"),
949 NULL, FALSE); 949 NULL, FALSE);
950 purple_request_field_group_add_field(group, field); 950 purple_request_field_group_add_field(group, field);
951 } 951 }
952 if(xmlnode_get_child(query, "address")) { 952 if(xmlnode_get_child(query, "address")) {
953 field = purple_request_field_string_new("address", _("Address"), 953 field = purple_request_field_string_new("address", _("Address"),
954 NULL, FALSE); 954 NULL, FALSE);
955 purple_request_field_group_add_field(group, field); 955 purple_request_field_group_add_field(group, field);
956 } 956 }
957 if(xmlnode_get_child(query, "city")) { 957 if(xmlnode_get_child(query, "city")) {
958 field = purple_request_field_string_new("city", _("City"), 958 field = purple_request_field_string_new("city", _("City"),
959 NULL, FALSE); 959 NULL, FALSE);
960 purple_request_field_group_add_field(group, field); 960 purple_request_field_group_add_field(group, field);
961 } 961 }
962 if(xmlnode_get_child(query, "state")) { 962 if(xmlnode_get_child(query, "state")) {
963 field = purple_request_field_string_new("state", _("State"), 963 field = purple_request_field_string_new("state", _("State"),
964 NULL, FALSE); 964 NULL, FALSE);
965 purple_request_field_group_add_field(group, field); 965 purple_request_field_group_add_field(group, field);
966 } 966 }
967 if(xmlnode_get_child(query, "zip")) { 967 if(xmlnode_get_child(query, "zip")) {
968 field = purple_request_field_string_new("zip", _("Postal code"), 968 field = purple_request_field_string_new("zip", _("Postal code"),
969 NULL, FALSE); 969 NULL, FALSE);
970 purple_request_field_group_add_field(group, field); 970 purple_request_field_group_add_field(group, field);
971 } 971 }
972 if(xmlnode_get_child(query, "phone")) { 972 if(xmlnode_get_child(query, "phone")) {
973 field = purple_request_field_string_new("phone", _("Phone"), 973 field = purple_request_field_string_new("phone", _("Phone"),
974 NULL, FALSE); 974 NULL, FALSE);
975 purple_request_field_group_add_field(group, field); 975 purple_request_field_group_add_field(group, field);
976 } 976 }
977 if(xmlnode_get_child(query, "url")) { 977 if(xmlnode_get_child(query, "url")) {
978 field = purple_request_field_string_new("url", _("URL"), 978 field = purple_request_field_string_new("url", _("URL"),
979 NULL, FALSE); 979 NULL, FALSE);
980 purple_request_field_group_add_field(group, field); 980 purple_request_field_group_add_field(group, field);
981 } 981 }
982 if(xmlnode_get_child(query, "date")) { 982 if(xmlnode_get_child(query, "date")) {
983 field = purple_request_field_string_new("date", _("Date"), 983 field = purple_request_field_string_new("date", _("Date"),
984 NULL, FALSE); 984 NULL, FALSE);
985 purple_request_field_group_add_field(group, field); 985 purple_request_field_group_add_field(group, field);
986 } 986 }
987 if(registered) { 987 if(registered) {
988 field = purple_request_field_bool_new("unregister", _("Unregister"), FALSE); 988 field = purple_request_field_bool_new("unregister", _("Unregister"), FALSE);
989 purple_request_field_group_add_field(group, field); 989 purple_request_field_group_add_field(group, field);
990 } 990 }
991 991
992 if((y = xmlnode_get_child(query, "instructions"))) 992 if((y = xmlnode_get_child(query, "instructions")))
993 instructions = xmlnode_get_data(y); 993 instructions = xmlnode_get_data(y);
994 else if(registered) 994 else if(registered)
995 instructions = g_strdup(_("Please fill out the information below " 995 instructions = g_strdup(_("Please fill out the information below "
996 "to change your account registration.")); 996 "to change your account registration."));
997 else 997 else
998 instructions = g_strdup(_("Please fill out the information below " 998 instructions = g_strdup(_("Please fill out the information below "
999 "to register your new account.")); 999 "to register your new account."));
1000 1000
1001 cbdata = g_new0(JabberRegisterCBData, 1); 1001 cbdata = g_new0(JabberRegisterCBData, 1);
1002 cbdata->js = js; 1002 cbdata->js = js;
1003 cbdata->who = g_strdup(from); 1003 cbdata->who = g_strdup(from);
1004 1004
1005 if(js->registration) 1005 if(js->registration)
1019 purple_connection_get_account(js->gc), NULL, NULL, 1019 purple_connection_get_account(js->gc), NULL, NULL,
1020 cbdata); 1020 cbdata);
1021 g_free(title); 1021 g_free(title);
1022 } 1022 }
1023 1023
1024 g_free(instructions); 1024 g_free(instructions);
1025 } 1025 }
1026 1026
1027 void jabber_register_start(JabberStream *js) 1027 void jabber_register_start(JabberStream *js)
1028 { 1028 {
1029 JabberIq *iq; 1029 JabberIq *iq;
1030 1030
1098 } 1098 }
1099 1099
1100 if(!js->gsc) { 1100 if(!js->gsc) {
1101 if (connect_server[0]) { 1101 if (connect_server[0]) {
1102 jabber_login_connect(js, js->user->domain, server, 1102 jabber_login_connect(js, js->user->domain, server,
1103 purple_account_get_int(account, 1103 purple_account_get_int(account,
1104 "port", 5222)); 1104 "port", 5222));
1105 } else { 1105 } else {
1106 js->srv_query_data = purple_srv_resolve("xmpp-client", 1106 js->srv_query_data = purple_srv_resolve("xmpp-client",
1107 "tcp", 1107 "tcp",
1108 js->user->domain, 1108 js->user->domain,
1109 srv_resolved_cb, 1109 srv_resolved_cb,
1110 js); 1110 js);
1111 } 1111 }
1112 } 1112 }
1113 } 1113 }
1114 1114
1115 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) { 1115 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) {
1461 1461
1462 purple_notify_user_info_add_pair(user_info, _("Mood"), moodplustext); 1462 purple_notify_user_info_add_pair(user_info, _("Mood"), moodplustext);
1463 g_free(moodplustext); 1463 g_free(moodplustext);
1464 } else 1464 } else
1465 purple_notify_user_info_add_pair(user_info, _("Mood"), mood); 1465 purple_notify_user_info_add_pair(user_info, _("Mood"), mood);
1466 } 1466 }
1467 } 1467 }
1468 1468
1469 for(l=jb->resources; l; l = l->next) { 1469 for(l=jb->resources; l; l = l->next) {
1470 char *text = NULL; 1470 char *text = NULL;
1471 char *res = NULL; 1471 char *res = NULL;
1741 JabberStream *js = gc->proto_data; 1741 JabberStream *js = gc->proto_data;
1742 GList *m = NULL; 1742 GList *m = NULL;
1743 PurplePluginAction *act; 1743 PurplePluginAction *act;
1744 1744
1745 act = purple_plugin_action_new(_("Set User Info..."), 1745 act = purple_plugin_action_new(_("Set User Info..."),
1746 jabber_setup_set_info); 1746 jabber_setup_set_info);
1747 m = g_list_append(m, act); 1747 m = g_list_append(m, act);
1748 1748
1749 /* if (js->protocol_options & CHANGE_PASSWORD) { */ 1749 /* if (js->protocol_options & CHANGE_PASSWORD) { */
1750 act = purple_plugin_action_new(_("Change Password..."), 1750 act = purple_plugin_action_new(_("Change Password..."),
1751 jabber_password_change); 1751 jabber_password_change);
1752 m = g_list_append(m, act); 1752 m = g_list_append(m, act);
1753 /* } */ 1753 /* } */
1754 1754
1755 act = purple_plugin_action_new(_("Search for Users..."), 1755 act = purple_plugin_action_new(_("Search for Users..."),
1756 jabber_user_search_begin); 1756 jabber_user_search_begin);
1757 m = g_list_append(m, act); 1757 m = g_list_append(m, act);
1758 1758
1759 purple_debug_info("jabber", "jabber_actions: have pep: %s\n", js->pep?"YES":"NO"); 1759 purple_debug_info("jabber", "jabber_actions: have pep: %s\n", js->pep?"YES":"NO");
1760 1760
1761 if(js->pep) 1761 if(js->pep)
2056 2056
2057 if (!chat || !args || !args[0] || !args[1]) 2057 if (!chat || !args || !args[0] || !args[1])
2058 return PURPLE_CMD_RET_FAILED; 2058 return PURPLE_CMD_RET_FAILED;
2059 2059
2060 if (strcmp(args[1], "owner") != 0 && 2060 if (strcmp(args[1], "owner") != 0 &&
2061 strcmp(args[1], "admin") != 0 && 2061 strcmp(args[1], "admin") != 0 &&
2062 strcmp(args[1], "member") != 0 && 2062 strcmp(args[1], "member") != 0 &&
2063 strcmp(args[1], "outcast") != 0 && 2063 strcmp(args[1], "outcast") != 0 &&
2064 strcmp(args[1], "none") != 0) { 2064 strcmp(args[1], "none") != 0) {
2065 *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]); 2065 *error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]);
2066 return PURPLE_CMD_RET_FAILED; 2066 return PURPLE_CMD_RET_FAILED;
2067 } 2067 }
2068 2068
2069 if (!jabber_chat_affiliate_user(chat, args[0], args[1])) { 2069 if (!jabber_chat_affiliate_user(chat, args[0], args[1])) {
2081 2081
2082 if (!chat || !args || !args[0] || !args[1]) 2082 if (!chat || !args || !args[0] || !args[1])
2083 return PURPLE_CMD_RET_FAILED; 2083 return PURPLE_CMD_RET_FAILED;
2084 2084
2085 if (strcmp(args[1], "moderator") != 0 && 2085 if (strcmp(args[1], "moderator") != 0 &&
2086 strcmp(args[1], "participant") != 0 && 2086 strcmp(args[1], "participant") != 0 &&
2087 strcmp(args[1], "visitor") != 0 && 2087 strcmp(args[1], "visitor") != 0 &&
2088 strcmp(args[1], "none") != 0) { 2088 strcmp(args[1], "none") != 0) {
2089 *error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]); 2089 *error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]);
2090 return PURPLE_CMD_RET_FAILED; 2090 return PURPLE_CMD_RET_FAILED;
2091 } 2091 }
2092 2092
2093 if (!jabber_chat_role_user(chat, args[0], args[1])) { 2093 if (!jabber_chat_role_user(chat, args[0], args[1])) {
2094 *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"), 2094 *error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),
2095 args[1], args[0]); 2095 args[1], args[0]);
2096 return PURPLE_CMD_RET_FAILED; 2096 return PURPLE_CMD_RET_FAILED;
2097 } 2097 }
2098 2098
2099 return PURPLE_CMD_RET_OK; 2099 return PURPLE_CMD_RET_OK;
2100 } 2100 }
2239 } 2239 }
2240 2240
2241 void jabber_register_commands(void) 2241 void jabber_register_commands(void)
2242 { 2242 {
2243 purple_cmd_register("config", "", PURPLE_CMD_P_PRPL, 2243 purple_cmd_register("config", "", PURPLE_CMD_P_PRPL,
2244 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2244 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,
2245 "prpl-jabber", jabber_cmd_chat_config, 2245 "prpl-jabber", jabber_cmd_chat_config,
2246 _("config: Configure a chat room."), NULL); 2246 _("config: Configure a chat room."), NULL);
2247 purple_cmd_register("configure", "", PURPLE_CMD_P_PRPL, 2247 purple_cmd_register("configure", "", PURPLE_CMD_P_PRPL,
2248 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2248 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,
2249 "prpl-jabber", jabber_cmd_chat_config, 2249 "prpl-jabber", jabber_cmd_chat_config,
2250 _("configure: Configure a chat room."), NULL); 2250 _("configure: Configure a chat room."), NULL);
2251 purple_cmd_register("nick", "s", PURPLE_CMD_P_PRPL, 2251 purple_cmd_register("nick", "s", PURPLE_CMD_P_PRPL,
2252 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2252 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,
2253 "prpl-jabber", jabber_cmd_chat_nick, 2253 "prpl-jabber", jabber_cmd_chat_nick,
2254 _("nick &lt;new nickname&gt;: Change your nickname."), 2254 _("nick &lt;new nickname&gt;: Change your nickname."),
2255 NULL); 2255 NULL);
2256 purple_cmd_register("part", "s", PURPLE_CMD_P_PRPL, 2256 purple_cmd_register("part", "s", PURPLE_CMD_P_PRPL,
2257 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2257 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2258 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2258 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2259 jabber_cmd_chat_part, _("part [room]: Leave the room."), 2259 jabber_cmd_chat_part, _("part [room]: Leave the room."),
2260 NULL); 2260 NULL);
2261 purple_cmd_register("register", "", PURPLE_CMD_P_PRPL, 2261 purple_cmd_register("register", "", PURPLE_CMD_P_PRPL,
2262 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2262 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,
2263 "prpl-jabber", jabber_cmd_chat_register, 2263 "prpl-jabber", jabber_cmd_chat_register,
2264 _("register: Register with a chat room."), NULL); 2264 _("register: Register with a chat room."), NULL);
2265 /* XXX: there needs to be a core /topic cmd, methinks */ 2265 /* XXX: there needs to be a core /topic cmd, methinks */
2266 purple_cmd_register("topic", "s", PURPLE_CMD_P_PRPL, 2266 purple_cmd_register("topic", "s", PURPLE_CMD_P_PRPL,
2267 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2267 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2268 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2268 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2269 jabber_cmd_chat_topic, 2269 jabber_cmd_chat_topic,
2270 _("topic [new topic]: View or change the topic."), 2270 _("topic [new topic]: View or change the topic."),
2271 NULL); 2271 NULL);
2272 purple_cmd_register("ban", "ws", PURPLE_CMD_P_PRPL, 2272 purple_cmd_register("ban", "ws", PURPLE_CMD_P_PRPL,
2273 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2273 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2274 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2274 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2275 jabber_cmd_chat_ban, 2275 jabber_cmd_chat_ban,
2276 _("ban &lt;user&gt; [room]: Ban a user from the room."), 2276 _("ban &lt;user&gt; [room]: Ban a user from the room."),
2277 NULL); 2277 NULL);
2278 purple_cmd_register("affiliate", "ws", PURPLE_CMD_P_PRPL, 2278 purple_cmd_register("affiliate", "ws", PURPLE_CMD_P_PRPL,
2279 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2279 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2280 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2280 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2281 jabber_cmd_chat_affiliate, 2281 jabber_cmd_chat_affiliate,
2282 _("affiliate &lt;user&gt; &lt;owner|admin|member|outcast|none&gt;: Set a user's affiliation with the room."), 2282 _("affiliate &lt;user&gt; &lt;owner|admin|member|outcast|none&gt;: Set a user's affiliation with the room."),
2283 NULL); 2283 NULL);
2284 purple_cmd_register("role", "ws", PURPLE_CMD_P_PRPL, 2284 purple_cmd_register("role", "ws", PURPLE_CMD_P_PRPL,
2285 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2285 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2286 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2286 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2287 jabber_cmd_chat_role, 2287 jabber_cmd_chat_role,
2288 _("role &lt;user&gt; &lt;moderator|participant|visitor|none&gt;: Set a user's role in the room."), 2288 _("role &lt;user&gt; &lt;moderator|participant|visitor|none&gt;: Set a user's role in the room."),
2289 NULL); 2289 NULL);
2290 purple_cmd_register("invite", "ws", PURPLE_CMD_P_PRPL, 2290 purple_cmd_register("invite", "ws", PURPLE_CMD_P_PRPL,
2291 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2291 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2292 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2292 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2293 jabber_cmd_chat_invite, 2293 jabber_cmd_chat_invite,
2294 _("invite &lt;user&gt; [message]: Invite a user to the room."), 2294 _("invite &lt;user&gt; [message]: Invite a user to the room."),
2295 NULL); 2295 NULL);
2296 purple_cmd_register("join", "ws", PURPLE_CMD_P_PRPL, 2296 purple_cmd_register("join", "ws", PURPLE_CMD_P_PRPL,
2297 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2297 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2298 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2298 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2299 jabber_cmd_chat_join, 2299 jabber_cmd_chat_join,
2300 _("join: &lt;room&gt; [server]: Join a chat on this server."), 2300 _("join: &lt;room&gt; [server]: Join a chat on this server."),
2301 NULL); 2301 NULL);
2302 purple_cmd_register("kick", "ws", PURPLE_CMD_P_PRPL, 2302 purple_cmd_register("kick", "ws", PURPLE_CMD_P_PRPL,
2303 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY | 2303 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |
2304 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber", 2304 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",
2305 jabber_cmd_chat_kick, 2305 jabber_cmd_chat_kick,
2306 _("kick &lt;user&gt; [room]: Kick a user from the room."), 2306 _("kick &lt;user&gt; [room]: Kick a user from the room."),
2307 NULL); 2307 NULL);
2308 purple_cmd_register("msg", "ws", PURPLE_CMD_P_PRPL, 2308 purple_cmd_register("msg", "ws", PURPLE_CMD_P_PRPL,
2309 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY, 2309 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,
2310 "prpl-jabber", jabber_cmd_chat_msg, 2310 "prpl-jabber", jabber_cmd_chat_msg,
2311 _("msg &lt;user&gt; &lt;message&gt;: Send a private message to another user."), 2311 _("msg &lt;user&gt; &lt;message&gt;: Send a private message to another user."),
2312 NULL); 2312 NULL);
2313 purple_cmd_register("ping", "w", PURPLE_CMD_P_PRPL, 2313 purple_cmd_register("ping", "w", PURPLE_CMD_P_PRPL,
2314 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | 2314 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM |
2315 PURPLE_CMD_FLAG_PRPL_ONLY, 2315 PURPLE_CMD_FLAG_PRPL_ONLY,
2316 "prpl-jabber", jabber_cmd_ping, 2316 "prpl-jabber", jabber_cmd_ping,
2317 _("ping &lt;jid&gt;: Ping a user/component/server."), 2317 _("ping &lt;jid&gt;: Ping a user/component/server."),
2323 } 2323 }
2324 2324
2325 void 2325 void
2326 jabber_init_plugin(PurplePlugin *plugin) 2326 jabber_init_plugin(PurplePlugin *plugin)
2327 { 2327 {
2328 my_protocol = plugin; 2328 my_protocol = plugin;
2329 } 2329 }