soc.2008.xmpp: de95a7af: * using libpurple's internal SASL mechan...
tfar at soc.pidgin.im
tfar at soc.pidgin.im
Fri Aug 15 10:11:31 EDT 2008
-----------------------------------------------------------------
Revision: de95a7afc369e5877464e0098ab59e236d09bca9
Ancestor: 353be693745f8780bebaccfa1869ebdf77560f53
Author: tfar at soc.pidgin.im
Date: 2008-08-15T14:02:21
Branch: im.pidgin.soc.2008.xmpp
URL: http://d.pidgin.im/viewmtn/revision/info/de95a7afc369e5877464e0098ab59e236d09bca9
Modified files:
libpurple/protocols/jabber/bosh.c
libpurple/protocols/jabber/bosh.h
libpurple/protocols/jabber/jabber.c
libpurple/protocols/jabber/jabber.h
ChangeLog:
* using libpurple's internal SASL mechanisms during BOSH authentication phase
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c 57391ab3dc17ff2d33dfef5c798567e4127a9469
+++ libpurple/protocols/jabber/bosh.c ae5225332327f85b40924d5e65d096f0569e3da6
@@ -56,8 +56,31 @@ void jabber_bosh_connection_init(PurpleB
conn->conn_a->userdata = conn;
}
-void jabber_bosh_connection_bood_response(PurpleBOSHConnection *conn, xmlnode *node) {
+void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node) {
+
+}
+
+void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node) {
+ char *version;
+ if (xmlnode_get_attrib(node, "sid")) {
+ conn->sid = g_strdup(xmlnode_get_attrib(node, "sid"));
+ } else {
+ purple_debug_info("jabber", "Connection manager doesn't behave BOSH-like!\n");
+ }
+ if (version = xmlnode_get_attrib(node, "ver")) {
+ version[1] = 0;
+ if (!(atoi(version) >= 1 && atoi(&version[2]) >= 6)) purple_debug_info("jabber", "Unsupported version of BOSH protocol. The connection manager must at least support version 1.6!\n");
+ else {
+ xmlnode *packet = xmlnode_get_child(node, "features");
+ conn->js->use_bosh = TRUE;
+ conn->receive_cb = jabber_bosh_connection_auth_response;
+ jabber_stream_features_parse(conn->js, packet);
+ }
+ version[1] = '.';
+ } else {
+ purple_debug_info("jabber", "Missing version in session creation response!\n");
+ }
}
void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
@@ -80,12 +103,11 @@ static void jabber_bosh_connection_boot(
xmlnode_set_attrib(init, "rid", tmp = g_strdup_printf("%d", conn->rid));
g_free(tmp);
xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */
- xmlnode_set_attrib(init, "ack", "0");
xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind");
xmlnode_set_attrib(init, "hold", "1");
- conn->receive_cb = jabber_bosh_connection_bood_response;
- jabber_bosh_connection_send(conn, init);
+ conn->receive_cb = jabber_bosh_connection_boot_response;
+ jabber_bosh_connection_send_native(conn, init);
}
void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) {
@@ -100,7 +122,27 @@ void jabber_bosh_connection_send(PurpleB
}
void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) {
+ xmlnode *packet = xmlnode_new("body");
+ char *tmp;
+ conn->rid++;
+ xmlnode_set_attrib(packet, "xmlns", "http://jabber.org/protocol/httpbind");
+ xmlnode_set_attrib(packet, "sid", conn->sid);
+ tmp = g_strdup_printf("%d", conn->rid);
+ xmlnode_set_attrib(packet, "rid", tmp);
+ g_free(tmp);
+
+ xmlnode_insert_child(packet, node);
+
+ jabber_bosh_connection_send_native(conn, packet);
+}
+
+void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node) {
PurpleHTTPRequest *request = g_new0(PurpleHTTPRequest, 1);
+
+ char *txt = xmlnode_to_formatted_str(node, NULL);
+ printf("\njabber_bosh_connection_send\n%s\n", txt);
+ g_free(txt);
+
jabber_bosh_http_request_init(request, "POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_http_received_cb, conn);
jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8");
request->data = xmlnode_to_str(node, &(request->data_len));
@@ -177,6 +219,7 @@ static void jabber_bosh_http_connection_
request->cb(request, response, conn->userdata);
jabber_bosh_http_request_clean(request);
jabber_bosh_http_response_clean(response);
+ conn->current_response = NULL;
} else {
purple_debug_info("jabber", "received HTTP response but haven't requested anything yet.\n");
}
============================================================
--- libpurple/protocols/jabber/bosh.h 1c911c687265fc0f984ff62770fb78f15f3dde7f
+++ libpurple/protocols/jabber/bosh.h 09223623dfb469cbaca5065bf0339971d192198b
@@ -43,6 +43,8 @@ struct _PurpleBOSHConnection {
char *passwd;
int rid;
+ char *sid;
+ int wait;
JabberStream *js;
void *userdata;
@@ -93,6 +95,7 @@ void jabber_bosh_connection_connect(Purp
void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, JabberStream *js, char *url);
void jabber_bosh_connection_connect(PurpleBOSHConnection *conn);
+void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node);
void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node);
void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port);
============================================================
--- libpurple/protocols/jabber/jabber.c 27719fb593c3228ba6f956a7e5aa78efb5f0c359
+++ libpurple/protocols/jabber/jabber.c 8e349ced3bc11f30abe05f18ff77f2182d856b69
@@ -145,7 +145,7 @@ static void jabber_bind_result_cb(Jabber
jabber_session_init(js);
}
-static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet)
+void jabber_stream_features_parse(JabberStream *js, xmlnode *packet)
{
if(xmlnode_get_child(packet, "starttls")) {
if(jabber_process_starttls(js, packet))
@@ -388,9 +388,13 @@ void jabber_send(JabberStream *js, xmlno
if(NULL == packet)
return;
- txt = xmlnode_to_str(packet, &len);
- jabber_send_raw(js, txt, len);
- g_free(txt);
+ if (js->use_bosh) {
+ jabber_bosh_connection_send(&(js->bosh), packet);
+ } else {
+ txt = xmlnode_to_str(packet, &len);
+ jabber_send_raw(js, txt, len);
+ g_free(txt);
+ }
}
static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout)
============================================================
--- libpurple/protocols/jabber/jabber.h fa8b8cb851eb4d70b80afac5dea164a9164f02fc
+++ libpurple/protocols/jabber/jabber.h 19aa389596c359eab1ef26c673e669f06f00ec9a
@@ -204,6 +204,7 @@ struct _JabberStream
int keepalive_timeout;
/* BOSH stuff*/
+ gboolean use_bosh;
PurpleBOSHConnection bosh;
};
More information about the Commits
mailing list