Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 25438:4b8c4870b13a
propagate from branch 'im.pidgin.pidgin.next.minor' (head 7305b29db7bd00d3261f348c71674c93aa31b327)
to branch 'im.pidgin.pidgin' (head d8c03c68d591d9392607d954942ee58b8618d946)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Mon, 02 Mar 2009 04:18:40 +0000 |
parents | c0b42d6c2785 b90c26f391b0 |
children | 13574de83636 |
comparison
equal
deleted
inserted
replaced
25437:8998ca47e6d0 | 25438:4b8c4870b13a |
---|---|
146 | 146 |
147 jabber_session_init(js); | 147 jabber_session_init(js); |
148 } | 148 } |
149 | 149 |
150 static char *jabber_prep_resource(char *input) { | 150 static char *jabber_prep_resource(char *input) { |
151 char hostname[256]; /* current hostname */ | 151 char hostname[256], /* current hostname */ |
152 *dot = NULL; | |
152 | 153 |
153 /* Empty resource == don't send any */ | 154 /* Empty resource == don't send any */ |
154 if (input == NULL || *input == '\0') | 155 if (input == NULL || *input == '\0') |
155 return NULL; | 156 return NULL; |
156 | 157 |
167 instead | 168 instead |
168 */ | 169 */ |
169 strcpy(hostname, "localhost"); | 170 strcpy(hostname, "localhost"); |
170 } | 171 } |
171 hostname[sizeof(hostname) - 1] = '\0'; | 172 hostname[sizeof(hostname) - 1] = '\0'; |
173 | |
174 /* We want only the short hostname, not the FQDN - this will prevent the | |
175 * resource string from being unreasonably long on systems which stuff the | |
176 * whole FQDN in the hostname */ | |
177 if((dot = strchr(hostname, '.'))) | |
178 dot = '\0'; | |
172 | 179 |
173 return purple_strreplace(input, "__HOSTNAME__", hostname); | 180 return purple_strreplace(input, "__HOSTNAME__", hostname); |
174 } | 181 } |
175 | 182 |
176 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | 183 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) |
800 if(js->registration) { | 807 if(js->registration) { |
801 buf = g_strdup_printf(_("Registration of %s@%s successful"), | 808 buf = g_strdup_printf(_("Registration of %s@%s successful"), |
802 js->user->node, js->user->domain); | 809 js->user->node, js->user->domain); |
803 if(account->registration_cb) | 810 if(account->registration_cb) |
804 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); | 811 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); |
805 } | 812 } else { |
806 else | 813 g_return_if_fail(to != NULL); |
807 buf = g_strdup_printf(_("Registration to %s successful"), | 814 buf = g_strdup_printf(_("Registration to %s successful"), |
808 to); | 815 to); |
816 } | |
809 purple_notify_info(NULL, _("Registration Successful"), | 817 purple_notify_info(NULL, _("Registration Successful"), |
810 _("Registration Successful"), buf); | 818 _("Registration Successful"), buf); |
811 g_free(buf); | 819 g_free(buf); |
812 } else { | 820 } else { |
813 char *msg = jabber_parse_error(js, packet, NULL); | 821 char *msg = jabber_parse_error(js, packet, NULL); |
830 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | 838 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
831 { | 839 { |
832 const char *type = xmlnode_get_attrib(packet, "type"); | 840 const char *type = xmlnode_get_attrib(packet, "type"); |
833 char *buf; | 841 char *buf; |
834 char *to = data; | 842 char *to = data; |
835 | 843 |
844 /* This function is never called for unregistering our XMPP account from | |
845 * the server, so there should always be a 'to' address. */ | |
846 g_return_if_fail(to != NULL); | |
847 | |
836 if(!strcmp(type, "result")) { | 848 if(!strcmp(type, "result")) { |
837 buf = g_strdup_printf(_("Registration from %s successfully removed"), | 849 buf = g_strdup_printf(_("Registration from %s successfully removed"), |
838 to); | 850 to); |
839 purple_notify_info(NULL, _("Unregistration Successful"), | 851 purple_notify_info(NULL, _("Unregistration Successful"), |
840 _("Unregistration Successful"), buf); | 852 _("Unregistration Successful"), buf); |
865 JabberIq *iq; | 877 JabberIq *iq; |
866 char *username; | 878 char *username; |
867 | 879 |
868 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); | 880 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); |
869 query = xmlnode_get_child(iq->node, "query"); | 881 query = xmlnode_get_child(iq->node, "query"); |
870 xmlnode_set_attrib(iq->node, "to", cbdata->who); | 882 if (cbdata->who) |
883 xmlnode_set_attrib(iq->node, "to", cbdata->who); | |
871 | 884 |
872 for(groups = purple_request_fields_get_groups(fields); groups; | 885 for(groups = purple_request_fields_get_groups(fields); groups; |
873 groups = groups->next) { | 886 groups = groups->next) { |
874 for(flds = purple_request_field_group_get_fields(groups->data); | 887 for(flds = purple_request_field_group_get_fields(groups->data); |
875 flds; flds = flds->next) { | 888 flds; flds = flds->next) { |
881 /* unregister from service. this doesn't include any of the fields, so remove them from the stanza by recreating it | 894 /* unregister from service. this doesn't include any of the fields, so remove them from the stanza by recreating it |
882 (there's no "remove child" function for xmlnode) */ | 895 (there's no "remove child" function for xmlnode) */ |
883 jabber_iq_free(iq); | 896 jabber_iq_free(iq); |
884 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); | 897 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); |
885 query = xmlnode_get_child(iq->node, "query"); | 898 query = xmlnode_get_child(iq->node, "query"); |
886 xmlnode_set_attrib(iq->node,"to",cbdata->who); | 899 if (cbdata->who) |
900 xmlnode_set_attrib(iq->node,"to",cbdata->who); | |
887 xmlnode_new_child(query, "remove"); | 901 xmlnode_new_child(query, "remove"); |
888 | 902 |
889 jabber_iq_set_callback(iq, jabber_unregistration_result_cb, cbdata->who); | 903 jabber_iq_set_callback(iq, jabber_unregistration_result_cb, cbdata->who); |
890 | 904 |
891 jabber_iq_send(iq); | 905 jabber_iq_send(iq); |
926 } else { | 940 } else { |
927 continue; | 941 continue; |
928 } | 942 } |
929 xmlnode_insert_data(y, value, -1); | 943 xmlnode_insert_data(y, value, -1); |
930 if(cbdata->js->registration && !strcmp(id, "username")) { | 944 if(cbdata->js->registration && !strcmp(id, "username")) { |
931 if(cbdata->js->user->node) | 945 g_free(cbdata->js->user->node); |
932 g_free(cbdata->js->user->node); | |
933 cbdata->js->user->node = g_strdup(value); | 946 cbdata->js->user->node = g_strdup(value); |
934 } | 947 } |
935 if(cbdata->js->registration && !strcmp(id, "password")) | 948 if(cbdata->js->registration && !strcmp(id, "password")) |
936 purple_account_set_password(cbdata->js->gc->account, value); | 949 purple_account_set_password(cbdata->js->gc->account, value); |
937 } | 950 } |
970 JabberIq *iq; | 983 JabberIq *iq; |
971 char *to = data; | 984 char *to = data; |
972 | 985 |
973 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | 986 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); |
974 query = xmlnode_get_child(iq->node, "query"); | 987 query = xmlnode_get_child(iq->node, "query"); |
975 xmlnode_set_attrib(iq->node,"to",to); | 988 if (to) |
989 xmlnode_set_attrib(iq->node,"to",to); | |
976 | 990 |
977 xmlnode_insert_child(query, result); | 991 xmlnode_insert_child(query, result); |
978 | 992 |
979 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); | 993 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
980 jabber_iq_send(iq); | 994 jabber_iq_send(iq); |
995 | 1009 |
996 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) | 1010 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) |
997 return; | 1011 return; |
998 | 1012 |
999 from = xmlnode_get_attrib(packet, "from"); | 1013 from = xmlnode_get_attrib(packet, "from"); |
1000 if (!from) | 1014 |
1001 from = js->serverFQDN; | |
1002 g_return_if_fail(from != NULL); | |
1003 | |
1004 if(js->registration) { | 1015 if(js->registration) { |
1005 /* get rid of the login thingy */ | 1016 /* get rid of the login thingy */ |
1006 purple_connection_set_state(js->gc, PURPLE_CONNECTED); | 1017 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
1007 } | 1018 } |
1008 | 1019 |
1019 jabber_connection_schedule_close(js); | 1030 jabber_connection_schedule_close(js); |
1020 return; | 1031 return; |
1021 } | 1032 } |
1022 } | 1033 } |
1023 | 1034 |
1024 if((x = xmlnode_get_child_with_namespace(packet, "x", "jabber:x:data"))) { | 1035 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { |
1025 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); | 1036 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); |
1026 return; | 1037 return; |
1027 | 1038 |
1028 } else if((x = xmlnode_get_child_with_namespace(packet, "x", "jabber:x:oob"))) { | 1039 } else if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:oob"))) { |
1029 xmlnode *url; | 1040 xmlnode *url; |
1030 | 1041 |
1031 if((url = xmlnode_get_child(x, "url"))) { | 1042 if((url = xmlnode_get_child(x, "url"))) { |
1032 char *href; | 1043 char *href; |
1033 if((href = xmlnode_get_data(url))) { | 1044 if((href = xmlnode_get_data(url))) { |
1143 _("Register"), G_CALLBACK(jabber_register_cb), | 1154 _("Register"), G_CALLBACK(jabber_register_cb), |
1144 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), | 1155 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), |
1145 purple_connection_get_account(js->gc), NULL, NULL, | 1156 purple_connection_get_account(js->gc), NULL, NULL, |
1146 cbdata); | 1157 cbdata); |
1147 else { | 1158 else { |
1148 char *title = registered?g_strdup_printf(_("Change Account Registration at %s"), from) | 1159 char *title; |
1160 g_return_if_fail(from != NULL); | |
1161 title = registered ? g_strdup_printf(_("Change Account Registration at %s"), from) | |
1149 :g_strdup_printf(_("Register New Account at %s"), from); | 1162 :g_strdup_printf(_("Register New Account at %s"), from); |
1150 purple_request_fields(js->gc, title, | 1163 purple_request_fields(js->gc, title, |
1151 title, instructions, fields, | 1164 title, instructions, fields, |
1152 (registered ? _("Change Registration") : _("Register")), G_CALLBACK(jabber_register_cb), | 1165 (registered ? _("Change Registration") : _("Register")), G_CALLBACK(jabber_register_cb), |
1153 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), | 1166 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), |
1870 m = g_list_append(m, _("Invisible")); | 1883 m = g_list_append(m, _("Invisible")); |
1871 */ | 1884 */ |
1872 | 1885 |
1873 type = purple_status_type_new_with_attrs(PURPLE_STATUS_OFFLINE, | 1886 type = purple_status_type_new_with_attrs(PURPLE_STATUS_OFFLINE, |
1874 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_UNAVAILABLE), | 1887 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_UNAVAILABLE), |
1875 NULL, FALSE, TRUE, FALSE, | 1888 NULL, TRUE, TRUE, FALSE, |
1876 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1889 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1877 NULL); | 1890 NULL); |
1878 types = g_list_append(types, type); | 1891 types = g_list_append(types, type); |
1879 | 1892 |
1880 type = purple_status_type_new_with_attrs(PURPLE_STATUS_TUNE, | 1893 type = purple_status_type_new_with_attrs(PURPLE_STATUS_TUNE, |