Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 25833:394252b681bc
propagate from branch 'im.pidgin.pidgin' (head be64dc9cd9d255a5a6a0f790f5fc505091313e6d)
to branch 'im.pidgin.cpw.darkrain42.xmpp.bosh' (head 6ea1275dfc036db492ab63dcbef17f47a40a94d7)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 17 Feb 2009 03:39:22 +0000 |
parents | af2b883df9a3 b90c26f391b0 |
children | 7d2e85f78aec |
comparison
equal
deleted
inserted
replaced
25828:6a369035fd20 | 25833:394252b681bc |
---|---|
149 | 149 |
150 jabber_session_init(js); | 150 jabber_session_init(js); |
151 } | 151 } |
152 | 152 |
153 static char *jabber_prep_resource(char *input) { | 153 static char *jabber_prep_resource(char *input) { |
154 char hostname[256]; /* current hostname */ | 154 char hostname[256], /* current hostname */ |
155 *dot = NULL; | |
155 | 156 |
156 /* Empty resource == don't send any */ | 157 /* Empty resource == don't send any */ |
157 if (input == NULL || *input == '\0') | 158 if (input == NULL || *input == '\0') |
158 return NULL; | 159 return NULL; |
159 | 160 |
170 instead | 171 instead |
171 */ | 172 */ |
172 strcpy(hostname, "localhost"); | 173 strcpy(hostname, "localhost"); |
173 } | 174 } |
174 hostname[sizeof(hostname) - 1] = '\0'; | 175 hostname[sizeof(hostname) - 1] = '\0'; |
176 | |
177 /* We want only the short hostname, not the FQDN - this will prevent the | |
178 * resource string from being unreasonably long on systems which stuff the | |
179 * whole FQDN in the hostname */ | |
180 if((dot = strchr(hostname, '.'))) | |
181 dot = '\0'; | |
175 | 182 |
176 return purple_strreplace(input, "__HOSTNAME__", hostname); | 183 return purple_strreplace(input, "__HOSTNAME__", hostname); |
177 } | 184 } |
178 | 185 |
179 void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | 186 void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) |
858 if(js->registration) { | 865 if(js->registration) { |
859 buf = g_strdup_printf(_("Registration of %s@%s successful"), | 866 buf = g_strdup_printf(_("Registration of %s@%s successful"), |
860 js->user->node, js->user->domain); | 867 js->user->node, js->user->domain); |
861 if(account->registration_cb) | 868 if(account->registration_cb) |
862 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); | 869 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); |
863 } | 870 } else { |
864 else | 871 g_return_if_fail(to != NULL); |
865 buf = g_strdup_printf(_("Registration to %s successful"), | 872 buf = g_strdup_printf(_("Registration to %s successful"), |
866 to); | 873 to); |
874 } | |
867 purple_notify_info(NULL, _("Registration Successful"), | 875 purple_notify_info(NULL, _("Registration Successful"), |
868 _("Registration Successful"), buf); | 876 _("Registration Successful"), buf); |
869 g_free(buf); | 877 g_free(buf); |
870 } else { | 878 } else { |
871 char *msg = jabber_parse_error(js, packet, NULL); | 879 char *msg = jabber_parse_error(js, packet, NULL); |
888 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | 896 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
889 { | 897 { |
890 const char *type = xmlnode_get_attrib(packet, "type"); | 898 const char *type = xmlnode_get_attrib(packet, "type"); |
891 char *buf; | 899 char *buf; |
892 char *to = data; | 900 char *to = data; |
893 | 901 |
902 /* This function is never called for unregistering our XMPP account from | |
903 * the server, so there should always be a 'to' address. */ | |
904 g_return_if_fail(to != NULL); | |
905 | |
894 if(!strcmp(type, "result")) { | 906 if(!strcmp(type, "result")) { |
895 buf = g_strdup_printf(_("Registration from %s successfully removed"), | 907 buf = g_strdup_printf(_("Registration from %s successfully removed"), |
896 to); | 908 to); |
897 purple_notify_info(NULL, _("Unregistration Successful"), | 909 purple_notify_info(NULL, _("Unregistration Successful"), |
898 _("Unregistration Successful"), buf); | 910 _("Unregistration Successful"), buf); |
923 JabberIq *iq; | 935 JabberIq *iq; |
924 char *username; | 936 char *username; |
925 | 937 |
926 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); | 938 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); |
927 query = xmlnode_get_child(iq->node, "query"); | 939 query = xmlnode_get_child(iq->node, "query"); |
928 xmlnode_set_attrib(iq->node, "to", cbdata->who); | 940 if (cbdata->who) |
941 xmlnode_set_attrib(iq->node, "to", cbdata->who); | |
929 | 942 |
930 for(groups = purple_request_fields_get_groups(fields); groups; | 943 for(groups = purple_request_fields_get_groups(fields); groups; |
931 groups = groups->next) { | 944 groups = groups->next) { |
932 for(flds = purple_request_field_group_get_fields(groups->data); | 945 for(flds = purple_request_field_group_get_fields(groups->data); |
933 flds; flds = flds->next) { | 946 flds; flds = flds->next) { |
939 /* unregister from service. this doesn't include any of the fields, so remove them from the stanza by recreating it | 952 /* unregister from service. this doesn't include any of the fields, so remove them from the stanza by recreating it |
940 (there's no "remove child" function for xmlnode) */ | 953 (there's no "remove child" function for xmlnode) */ |
941 jabber_iq_free(iq); | 954 jabber_iq_free(iq); |
942 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); | 955 iq = jabber_iq_new_query(cbdata->js, JABBER_IQ_SET, "jabber:iq:register"); |
943 query = xmlnode_get_child(iq->node, "query"); | 956 query = xmlnode_get_child(iq->node, "query"); |
944 xmlnode_set_attrib(iq->node,"to",cbdata->who); | 957 if (cbdata->who) |
958 xmlnode_set_attrib(iq->node,"to",cbdata->who); | |
945 xmlnode_new_child(query, "remove"); | 959 xmlnode_new_child(query, "remove"); |
946 | 960 |
947 jabber_iq_set_callback(iq, jabber_unregistration_result_cb, cbdata->who); | 961 jabber_iq_set_callback(iq, jabber_unregistration_result_cb, cbdata->who); |
948 | 962 |
949 jabber_iq_send(iq); | 963 jabber_iq_send(iq); |
984 } else { | 998 } else { |
985 continue; | 999 continue; |
986 } | 1000 } |
987 xmlnode_insert_data(y, value, -1); | 1001 xmlnode_insert_data(y, value, -1); |
988 if(cbdata->js->registration && !strcmp(id, "username")) { | 1002 if(cbdata->js->registration && !strcmp(id, "username")) { |
989 if(cbdata->js->user->node) | 1003 g_free(cbdata->js->user->node); |
990 g_free(cbdata->js->user->node); | |
991 cbdata->js->user->node = g_strdup(value); | 1004 cbdata->js->user->node = g_strdup(value); |
992 } | 1005 } |
993 if(cbdata->js->registration && !strcmp(id, "password")) | 1006 if(cbdata->js->registration && !strcmp(id, "password")) |
994 purple_account_set_password(cbdata->js->gc->account, value); | 1007 purple_account_set_password(cbdata->js->gc->account, value); |
995 } | 1008 } |
1028 JabberIq *iq; | 1041 JabberIq *iq; |
1029 char *to = data; | 1042 char *to = data; |
1030 | 1043 |
1031 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); | 1044 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register"); |
1032 query = xmlnode_get_child(iq->node, "query"); | 1045 query = xmlnode_get_child(iq->node, "query"); |
1033 xmlnode_set_attrib(iq->node,"to",to); | 1046 if (to) |
1047 xmlnode_set_attrib(iq->node,"to",to); | |
1034 | 1048 |
1035 xmlnode_insert_child(query, result); | 1049 xmlnode_insert_child(query, result); |
1036 | 1050 |
1037 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); | 1051 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
1038 jabber_iq_send(iq); | 1052 jabber_iq_send(iq); |
1053 | 1067 |
1054 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) | 1068 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) |
1055 return; | 1069 return; |
1056 | 1070 |
1057 from = xmlnode_get_attrib(packet, "from"); | 1071 from = xmlnode_get_attrib(packet, "from"); |
1058 if (!from) | 1072 |
1059 from = js->serverFQDN; | |
1060 g_return_if_fail(from != NULL); | |
1061 | |
1062 if(js->registration) { | 1073 if(js->registration) { |
1063 /* get rid of the login thingy */ | 1074 /* get rid of the login thingy */ |
1064 purple_connection_set_state(js->gc, PURPLE_CONNECTED); | 1075 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
1065 } | 1076 } |
1066 | 1077 |
1077 jabber_connection_schedule_close(js); | 1088 jabber_connection_schedule_close(js); |
1078 return; | 1089 return; |
1079 } | 1090 } |
1080 } | 1091 } |
1081 | 1092 |
1082 if((x = xmlnode_get_child_with_namespace(packet, "x", "jabber:x:data"))) { | 1093 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { |
1083 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); | 1094 jabber_x_data_request(js, x, jabber_register_x_data_cb, g_strdup(from)); |
1084 return; | 1095 return; |
1085 | 1096 |
1086 } else if((x = xmlnode_get_child_with_namespace(packet, "x", "jabber:x:oob"))) { | 1097 } else if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:oob"))) { |
1087 xmlnode *url; | 1098 xmlnode *url; |
1088 | 1099 |
1089 if((url = xmlnode_get_child(x, "url"))) { | 1100 if((url = xmlnode_get_child(x, "url"))) { |
1090 char *href; | 1101 char *href; |
1091 if((href = xmlnode_get_data(url))) { | 1102 if((href = xmlnode_get_data(url))) { |
1201 _("Register"), G_CALLBACK(jabber_register_cb), | 1212 _("Register"), G_CALLBACK(jabber_register_cb), |
1202 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), | 1213 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), |
1203 purple_connection_get_account(js->gc), NULL, NULL, | 1214 purple_connection_get_account(js->gc), NULL, NULL, |
1204 cbdata); | 1215 cbdata); |
1205 else { | 1216 else { |
1206 char *title = registered?g_strdup_printf(_("Change Account Registration at %s"), from) | 1217 char *title; |
1218 g_return_if_fail(from != NULL); | |
1219 title = registered ? g_strdup_printf(_("Change Account Registration at %s"), from) | |
1207 :g_strdup_printf(_("Register New Account at %s"), from); | 1220 :g_strdup_printf(_("Register New Account at %s"), from); |
1208 purple_request_fields(js->gc, title, | 1221 purple_request_fields(js->gc, title, |
1209 title, instructions, fields, | 1222 title, instructions, fields, |
1210 (registered ? _("Change Registration") : _("Register")), G_CALLBACK(jabber_register_cb), | 1223 (registered ? _("Change Registration") : _("Register")), G_CALLBACK(jabber_register_cb), |
1211 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), | 1224 _("Cancel"), G_CALLBACK(jabber_register_cancel_cb), |