Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 25745:c974d4453f12
propagate from branch 'im.pidgin.pidgin' (head d3440d677dd69ed30a8158b515bd26d210dacb9d)
to branch 'im.pidgin.cpw.malu.xmpp.ibb_ft' (head 0272db32424bf245d924c833b771e3f6c2ebe286)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 30 Nov 2008 19:41:51 +0000 |
parents | 6b9552b09de0 |
children | fb5a11ec8be6 6f94b4a27372 b4a2ce33b3d5 aa1fe87558d8 89b95d143116 |
comparison
equal
deleted
inserted
replaced
25744:487a750cc924 | 25745:c974d4453f12 |
---|---|
144 } | 144 } |
145 | 145 |
146 jabber_session_init(js); | 146 jabber_session_init(js); |
147 } | 147 } |
148 | 148 |
149 static char *jabber_prep_resource(char *input) { | |
150 char hostname[256]; /* current hostname */ | |
151 | |
152 /* Empty resource == don't send any */ | |
153 if (*input == '\0') | |
154 return NULL; | |
155 | |
156 if (strstr(input, "__HOSTNAME__") == NULL) | |
157 return input; | |
158 | |
159 /* Replace __HOSTNAME__ with hostname */ | |
160 if (gethostname(hostname, sizeof(hostname) - 1)) { | |
161 purple_debug_warning("jabber", "gethostname: %s\n", g_strerror(errno)); | |
162 /* according to glibc doc, the only time an error is returned | |
163 is if the hostname is longer than the buffer, in which case | |
164 glibc 2.2+ would still fill the buffer with partial | |
165 hostname, so maybe we want to detect that and use it | |
166 instead | |
167 */ | |
168 strcpy(hostname, "localhost"); | |
169 } | |
170 hostname[sizeof(hostname) - 1] = '\0'; | |
171 | |
172 return purple_strreplace(input, "__HOSTNAME__", hostname); | |
173 } | |
174 | |
149 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | 175 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) |
150 { | 176 { |
151 if(xmlnode_get_child(packet, "starttls")) { | 177 if(xmlnode_get_child(packet, "starttls")) { |
152 if(jabber_process_starttls(js, packet)) | 178 if(jabber_process_starttls(js, packet)) |
179 | |
153 return; | 180 return; |
154 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) { | 181 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) { |
155 purple_connection_error_reason (js->gc, | 182 purple_connection_error_reason (js->gc, |
156 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 183 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
157 _("You require encryption, but it is not available on this server.")); | 184 _("You require encryption, but it is not available on this server.")); |
162 jabber_register_start(js); | 189 jabber_register_start(js); |
163 } else if(xmlnode_get_child(packet, "mechanisms")) { | 190 } else if(xmlnode_get_child(packet, "mechanisms")) { |
164 jabber_auth_start(js, packet); | 191 jabber_auth_start(js, packet); |
165 } else if(xmlnode_get_child(packet, "bind")) { | 192 } else if(xmlnode_get_child(packet, "bind")) { |
166 xmlnode *bind, *resource; | 193 xmlnode *bind, *resource; |
194 char *requested_resource; | |
167 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | 195 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
168 bind = xmlnode_new_child(iq->node, "bind"); | 196 bind = xmlnode_new_child(iq->node, "bind"); |
169 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); | 197 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); |
170 resource = xmlnode_new_child(bind, "resource"); | 198 requested_resource = jabber_prep_resource(js->user->resource); |
171 xmlnode_insert_data(resource, js->user->resource, -1); | 199 |
200 if (requested_resource != NULL) { | |
201 resource = xmlnode_new_child(bind, "resource"); | |
202 xmlnode_insert_data(resource, requested_resource, -1); | |
203 free(requested_resource); | |
204 } | |
172 | 205 |
173 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); | 206 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); |
174 | 207 |
175 jabber_iq_send(iq); | 208 jabber_iq_send(iq); |
176 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { | 209 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { |
677 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, | 710 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, |
678 _("Invalid XMPP ID. Domain must be set.")); | 711 _("Invalid XMPP ID. Domain must be set.")); |
679 return; | 712 return; |
680 } | 713 } |
681 | 714 |
682 if(!js->user->resource) { | |
683 char *me; | |
684 js->user->resource = g_strdup("Home"); | |
685 if(!js->user->node) { | |
686 js->user->node = js->user->domain; | |
687 js->user->domain = g_strdup("jabber.org"); | |
688 } | |
689 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
690 js->user->resource); | |
691 purple_account_set_username(account, me); | |
692 g_free(me); | |
693 } | |
694 | |
695 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE))) | 715 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE))) |
696 my_jb->subscription |= JABBER_SUB_BOTH; | 716 my_jb->subscription |= JABBER_SUB_BOTH; |
697 | 717 |
698 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); | 718 jabber_stream_set_state(js, JABBER_STREAM_CONNECTING); |
699 | 719 |
1156 _("Invalid XMPP ID")); | 1176 _("Invalid XMPP ID")); |
1157 return; | 1177 return; |
1158 } | 1178 } |
1159 | 1179 |
1160 js->write_buffer = purple_circ_buffer_new(512); | 1180 js->write_buffer = purple_circ_buffer_new(512); |
1161 | |
1162 if(!js->user->resource) { | |
1163 char *me; | |
1164 js->user->resource = g_strdup("Home"); | |
1165 if(!js->user->node) { | |
1166 js->user->node = js->user->domain; | |
1167 js->user->domain = g_strdup("jabber.org"); | |
1168 } | |
1169 me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, | |
1170 js->user->resource); | |
1171 purple_account_set_username(account, me); | |
1172 g_free(me); | |
1173 } | |
1174 | 1181 |
1175 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE))) | 1182 if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE))) |
1176 my_jb->subscription |= JABBER_SUB_BOTH; | 1183 my_jb->subscription |= JABBER_SUB_BOTH; |
1177 | 1184 |
1178 server = connect_server[0] ? connect_server : js->user->domain; | 1185 server = connect_server[0] ? connect_server : js->user->domain; |