Mercurial > pidgin.yaz
changeset 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 | 4caae7801f4d |
children | 8e7e6f60e053 |
files | COPYRIGHT ChangeLog libpurple/protocols/jabber/jabber.c |
diffstat | 3 files changed, 30 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Fri Nov 28 01:49:58 2008 +0000 +++ b/COPYRIGHT Fri Nov 28 02:19:42 2008 +0000 @@ -349,6 +349,7 @@ Michael Ruprecht Sam S. Thanumalayan S. +Jonathan Sailor Elliott Sales de Andrade Tomasz Sałaciński <tsalacinski@gmail.com> Pradyumna Sampath
--- a/ChangeLog Fri Nov 28 01:49:58 2008 +0000 +++ b/ChangeLog Fri Nov 28 02:19:42 2008 +0000 @@ -17,6 +17,10 @@ * Fix a crash in SIMPLE when a malformed message is received. * Fix the namespace URL we look for in PEP reply stanzas to match the URL used in the 'get' requests (Paul Aurich) + * XMPP resources can default to the local machine's hostname by using + __HOSTNAME__ as the resource string (Jonathan Sailor) + * XMPP resources can now be left blank, causing the server to generate a + resource for us (Jonathan Sailor) Pidgin: * On GTK+ 2.14 and higher, we're using the gtk-tooltip-delay setting
--- a/libpurple/protocols/jabber/jabber.c Fri Nov 28 01:49:58 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Fri Nov 28 02:19:42 2008 +0000 @@ -146,10 +146,27 @@ jabber_session_init(js); } +static char *jabber_prep_resource(char *input) { + char hostname[256]; /* current hostname */ + + /* Empty resource == don't send any */ + if (strlen(input) == 0) + return NULL; + + /* Replace __HOSTNAME__ with hostname */ + if (gethostname(hostname, sizeof(hostname))) { + purple_debug_warning("jabber", "gethostname() failed -- is your hostname set?"); + strcpy(hostname, "localhost"); + } + + return purple_strreplace(input, "__HOSTNAME__", hostname); +} + static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) { if(xmlnode_get_child(packet, "starttls")) { if(jabber_process_starttls(js, packet)) + return; } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) { purple_connection_error_reason (js->gc, @@ -164,11 +181,17 @@ jabber_auth_start(js, packet); } else if(xmlnode_get_child(packet, "bind")) { xmlnode *bind, *resource; + char *requested_resource; JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); bind = xmlnode_new_child(iq->node, "bind"); xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind"); - resource = xmlnode_new_child(bind, "resource"); - xmlnode_insert_data(resource, js->user->resource, -1); + requested_resource = jabber_prep_resource(js->user->resource); + + if (requested_resource != NULL) { + resource = xmlnode_new_child(bind, "resource"); + xmlnode_insert_data(resource, requested_resource, -1); + free(requested_resource); + } jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL);