Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 24500:7ec139c84d36
Some improvements to XMPP resource handling:
* Blank resources cause us to expect the server to assign one to us.
* Using "__HOSTNAME__" as the resource will cause us to replace this
string with the actual hostname of the machine we're running on.
Fixes #5565.
committer: John Bailey <rekkanoryo@rekkanoryo.org>
author | Jonathan Sailor <jsailor@jesnetplus.com> |
---|---|
date | Fri, 28 Nov 2008 02:19:42 +0000 |
parents | 3a3d36791a47 |
children | 8e7e6f60e053 |
comparison
equal
deleted
inserted
replaced
24499:4caae7801f4d | 24500:7ec139c84d36 |
---|---|
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 (strlen(input) == 0) | |
154 return NULL; | |
155 | |
156 /* Replace __HOSTNAME__ with hostname */ | |
157 if (gethostname(hostname, sizeof(hostname))) { | |
158 purple_debug_warning("jabber", "gethostname() failed -- is your hostname set?"); | |
159 strcpy(hostname, "localhost"); | |
160 } | |
161 | |
162 return purple_strreplace(input, "__HOSTNAME__", hostname); | |
163 } | |
164 | |
149 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) | 165 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) |
150 { | 166 { |
151 if(xmlnode_get_child(packet, "starttls")) { | 167 if(xmlnode_get_child(packet, "starttls")) { |
152 if(jabber_process_starttls(js, packet)) | 168 if(jabber_process_starttls(js, packet)) |
169 | |
153 return; | 170 return; |
154 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) { | 171 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) { |
155 purple_connection_error_reason (js->gc, | 172 purple_connection_error_reason (js->gc, |
156 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 173 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
157 _("You require encryption, but it is not available on this server.")); | 174 _("You require encryption, but it is not available on this server.")); |
162 jabber_register_start(js); | 179 jabber_register_start(js); |
163 } else if(xmlnode_get_child(packet, "mechanisms")) { | 180 } else if(xmlnode_get_child(packet, "mechanisms")) { |
164 jabber_auth_start(js, packet); | 181 jabber_auth_start(js, packet); |
165 } else if(xmlnode_get_child(packet, "bind")) { | 182 } else if(xmlnode_get_child(packet, "bind")) { |
166 xmlnode *bind, *resource; | 183 xmlnode *bind, *resource; |
184 char *requested_resource; | |
167 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); | 185 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
168 bind = xmlnode_new_child(iq->node, "bind"); | 186 bind = xmlnode_new_child(iq->node, "bind"); |
169 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); | 187 xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); |
170 resource = xmlnode_new_child(bind, "resource"); | 188 requested_resource = jabber_prep_resource(js->user->resource); |
171 xmlnode_insert_data(resource, js->user->resource, -1); | 189 |
190 if (requested_resource != NULL) { | |
191 resource = xmlnode_new_child(bind, "resource"); | |
192 xmlnode_insert_data(resource, requested_resource, -1); | |
193 free(requested_resource); | |
194 } | |
172 | 195 |
173 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); | 196 jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL); |
174 | 197 |
175 jabber_iq_send(iq); | 198 jabber_iq_send(iq); |
176 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { | 199 } else /* if(xmlnode_get_child_with_namespace(packet, "auth")) */ { |