# HG changeset patch # User Jonathan Sailor # Date 1227838782 0 # Node ID 7ec139c84d363d91634fd3bf0affe10fd5bc299d # Parent 4caae7801f4df1a5c2cf582a2f1be6d03610ba85 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 diff -r 4caae7801f4d -r 7ec139c84d36 COPYRIGHT --- 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 Pradyumna Sampath diff -r 4caae7801f4d -r 7ec139c84d36 ChangeLog --- 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 diff -r 4caae7801f4d -r 7ec139c84d36 libpurple/protocols/jabber/jabber.c --- 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);