# HG changeset patch # User Paul Aurich # Date 1251218298 0 # Node ID b357216b7b79c9ce102df240c389dbb5c7930eed # Parent 0b3142f3edb4a8f74d32547659e7ad55aac45e3c jabber: Fix using BOSH and legacy auth together. Closes #9990. Thanks to Perel for testing. diff -r 0b3142f3edb4 -r b357216b7b79 ChangeLog --- a/ChangeLog Tue Aug 25 09:37:38 2009 +0000 +++ b/ChangeLog Tue Aug 25 16:38:18 2009 +0000 @@ -5,7 +5,7 @@ * Fix --disable-avahi to actually disable it in configure, as opposed to just making the warning non-fatal. * Sending custom smileys in MSN chats is now supported. - * Fix using GNOME proxy settings properly. + * Fix using GNOME proxy settings properly. (Erik van Pienbroek) XMPP: * Prompt the user before cancelling a presence subscription. @@ -13,6 +13,7 @@ * Fix connecting to XMPP domains with no SRV records from Pidgin on Windows. * Fix typing notifications with Pidgin 2.5.9 or earlier. + * Fix connecting using BOSH and legacy authentication (XEP-0078). Finch: * Properly detect libpanel on OpenBSD. (Brad Smith) diff -r 0b3142f3edb4 -r b357216b7b79 libpurple/protocols/jabber/auth.c --- a/libpurple/protocols/jabber/auth.c Tue Aug 25 09:37:38 2009 +0000 +++ b/libpurple/protocols/jabber/auth.c Tue Aug 25 16:38:18 2009 +0000 @@ -575,6 +575,7 @@ xmlnode *packet, gpointer data) { if (type == JABBER_IQ_RESULT) { + jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); jabber_disco_items_server(js); } else { PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; @@ -1072,7 +1073,12 @@ } #endif - jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING); + /* + * The stream will be reinitialized later in jabber_recv_cb_ssl() or + * jabber_bosh_connection_send. + */ + js->reinit = TRUE; + jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); } void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) diff -r 0b3142f3edb4 -r b357216b7b79 libpurple/protocols/jabber/bosh.c --- a/libpurple/protocols/jabber/bosh.c Tue Aug 25 09:37:38 2009 +0000 +++ b/libpurple/protocols/jabber/bosh.c Tue Aug 25 16:38:18 2009 +0000 @@ -70,7 +70,6 @@ gboolean pipelining; gboolean ssl; - gboolean needs_restart; enum { BOSH_CONN_OFFLINE, @@ -197,7 +196,6 @@ conn->path = g_strdup_printf("/%s", path); g_free(path); conn->pipelining = TRUE; - conn->needs_restart = FALSE; if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { purple_debug_info("jabber", "Ignoring unexpected username and password " @@ -377,10 +375,10 @@ conn->sid, conn->js->user->domain); - if (conn->needs_restart) { + if (conn->js->reinit) { packet = g_string_append(packet, " xmpp:restart='true'/>"); /* TODO: Do we need to wait for a response? */ - conn->needs_restart = FALSE; + conn->js->reinit = FALSE; } else { gsize read_amt; if (type == PACKET_TERMINATE) @@ -406,12 +404,6 @@ jabber_bosh_connection_send(conn, PACKET_TERMINATE, NULL); } -static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) -{ - conn->needs_restart = TRUE; - jabber_bosh_connection_send(conn, PACKET_NORMAL, NULL); -} - static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { const char *type; @@ -490,35 +482,8 @@ } } -static void auth_response_cb(PurpleBOSHConnection *conn, xmlnode *node) { - xmlnode *child; - - g_return_if_fail(node != NULL); - if (jabber_bosh_connection_error_check(conn, node)) - return; - - child = node->child; - while(child != NULL && child->type != XMLNODE_TYPE_TAG) { - child = child->next; - } - - /* We're only expecting one XML node here, so only process the first one */ - if (child != NULL && child->type == XMLNODE_TYPE_TAG) { - JabberStream *js = conn->js; - if (!strcmp(child->name, "success")) { - jabber_bosh_connection_stream_restart(conn); - jabber_process_packet(js, &child); - conn->receive_cb = jabber_bosh_connection_received; - } else { - js->state = JABBER_STREAM_AUTHENTICATING; - jabber_process_packet(js, &child); - } - } else { - purple_debug_warning("jabber", "Received unexepcted empty BOSH packet.\n"); - } -} - static void boot_response_cb(PurpleBOSHConnection *conn, xmlnode *node) { + JabberStream *js = conn->js; const char *sid, *version; const char *inactivity, *requests; xmlnode *packet; @@ -536,7 +501,7 @@ if (sid) { conn->sid = g_strdup(sid); } else { - purple_connection_error_reason(conn->js->gc, + purple_connection_error_reason(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("No session ID given")); return; @@ -553,7 +518,7 @@ minor = atoi(dot + 1); if (major != 1 || minor < 6) { - purple_connection_error_reason(conn->js->gc, + purple_connection_error_reason(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unsupported version of BOSH protocol")); return; @@ -583,11 +548,13 @@ if (requests) conn->max_requests = atoi(requests); + jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); + /* FIXME: Depending on receiving features might break with some hosts */ packet = xmlnode_get_child(node, "features"); conn->state = BOSH_CONN_ONLINE; - conn->receive_cb = auth_response_cb; - jabber_stream_features_parse(conn->js, packet); + conn->receive_cb = jabber_bosh_connection_received; + jabber_stream_features_parse(js, packet); } static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { @@ -663,8 +630,8 @@ conn->headers_done = FALSE; conn->handled_len = conn->body_len = 0; - if (conn->bosh->needs_restart) - jabber_bosh_connection_stream_restart(conn->bosh); + if (conn->bosh->js->reinit) + jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL); else if (conn->bosh->state == BOSH_CONN_ONLINE) { purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); if (conn->bosh->requests == 0 || conn->bosh->pending->bufused > 0) { diff -r 0b3142f3edb4 -r b357216b7b79 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Tue Aug 25 09:37:38 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Tue Aug 25 16:38:18 2009 +0000 @@ -1605,13 +1605,10 @@ jabber_auth_start_old(js); } break; - case JABBER_STREAM_REINITIALIZING: + case JABBER_STREAM_POST_AUTH: purple_connection_update_progress(js->gc, _("Re-initializing Stream"), (js->gsc ? 8 : 4), JABBER_CONNECT_STEPS); - /* The stream will be reinitialized later, in jabber_recv_cb_ssl() */ - js->reinit = TRUE; - break; case JABBER_STREAM_CONNECTED: /* Send initial presence */ diff -r 0b3142f3edb4 -r b357216b7b79 libpurple/protocols/jabber/jabber.h --- a/libpurple/protocols/jabber/jabber.h Tue Aug 25 09:37:38 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.h Tue Aug 25 16:38:18 2009 +0000 @@ -87,7 +87,7 @@ JABBER_STREAM_INITIALIZING, JABBER_STREAM_INITIALIZING_ENCRYPTION, JABBER_STREAM_AUTHENTICATING, - JABBER_STREAM_REINITIALIZING, + JABBER_STREAM_POST_AUTH, JABBER_STREAM_CONNECTED } JabberStreamState;