Mercurial > pidgin.yaz
changeset 25717:907ca9a36fe0
explicit merge of '714a7c7f903d11c96ffade34966121da549d998f'
and 'd2c40fe4e2181eda5c1c631c7805f17e6b5d22c3'
to branch 'org.darkrain42.pidgin.xmpp'
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Thu, 20 Nov 2008 21:13:56 +0000 |
parents | 94ccccab4e98 (diff) ba362a67278c (current diff) |
children | 9ab681f23007 |
files | libpurple/protocols/jabber/Makefile.mingw libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/msn/slpsession.c libpurple/protocols/msn/slpsession.h libpurple/protocols/msn/soap2.c libpurple/protocols/msn/soap2.h libpurple/protocols/qq/buddy_status.c libpurple/protocols/qq/buddy_status.h libpurple/protocols/qq/keep_alive.c libpurple/protocols/qq/keep_alive.h libpurple/protocols/qq/login_logout.c libpurple/protocols/qq/login_logout.h libpurple/protocols/qq/qq_proxy.c libpurple/protocols/qq/qq_proxy.h libpurple/protocols/qq/recv_core.c libpurple/protocols/qq/recv_core.h libpurple/protocols/qq/send_core.c libpurple/protocols/qq/send_core.h libpurple/protocols/qq/sendqueue.c libpurple/protocols/qq/sendqueue.h libpurple/protocols/qq/udp_proxy_s5.c libpurple/protocols/qq/udp_proxy_s5.h |
diffstat | 7 files changed, 511 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/Makefile.am Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/Makefile.am Thu Nov 20 21:13:56 2008 +0000 @@ -9,6 +9,8 @@ auth.h \ buddy.c \ buddy.h \ + bosh.c \ + bosh.h \ chat.c \ chat.h \ disco.c \
--- a/libpurple/protocols/jabber/Makefile.mingw Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/Makefile.mingw Thu Nov 20 21:13:56 2008 +0000 @@ -46,6 +46,7 @@ adhoccommands.c \ auth.c \ buddy.c \ + bosh.c caps.c \ chat.c \ disco.c \
--- a/libpurple/protocols/jabber/bosh.c Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/bosh.c Thu Nov 20 21:13:56 2008 +0000 @@ -36,14 +36,419 @@ #include "xdata.h" #include "pep.h" #include "adhoccommands.h" +#include "connection.h" -PurpleHTTPHeaderField* jabber_bosh_http_header_field(const char *name, *const char *value) { - PurpleHTTPHeaderField *tmp = g_new0(PurpleHTTPHeaderField, 0); - tmp->name = g_strdup(name); - tmp->value = g_strdup(value); - return tmp; +void jabber_bosh_connection_init(PurpleBOSHConnection *conn, PurpleAccount *account, JabberStream *js, char *url) { + conn->pipelining = TRUE; + conn->account = account; + if (!purple_url_parse(url, &(conn->host), &(conn->port), &(conn->path), &(conn->user), &(conn->passwd))) { + purple_debug_info("jabber", "Unable to parse given URL.\n"); + return; + } + if (conn->user || conn->passwd) { + purple_debug_info("jabber", "Sorry, HTTP Authentication isn't supported yet. Username and password in the BOSH URL will be ignored.\n"); + } + conn->js = js; + conn->rid = rand() % 100000 + 1728679472; + conn->ready = FALSE; + conn->conn_a = g_new0(PurpleHTTPConnection, 1); + jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port); + conn->conn_a->userdata = conn; +} + +void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) { + xmlnode *restart = xmlnode_new("body"); + char *tmp = NULL; + conn->rid++; + xmlnode_set_attrib(restart, "rid", tmp = g_strdup_printf("%d", conn->rid)); + g_free(tmp); + xmlnode_set_attrib(restart, "sid", conn->sid); + xmlnode_set_attrib(restart, "to", conn->js->user->domain); + xmlnode_set_attrib(restart, "xml:lang", "en"); + xmlnode_set_attrib(restart, "xmpp:restart", "true"); + xmlnode_set_attrib(restart, "xmlns", "http://jabber.org/protocol/httpbind"); + xmlnode_set_attrib(restart, "xmlns:xmpp", "urn:xmpp:xbosh"); + + jabber_bosh_connection_send_native(conn, restart); +} + +gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { + char *type; + + if (!node) return FALSE; + type = xmlnode_get_attrib(node, "type"); + + if (type != NULL && !strcmp(type, "terminate")) { + conn->ready = FALSE; + purple_connection_error_reason (conn->js->gc, + PURPLE_CONNECTION_ERROR_OTHER_ERROR, + _("The BOSH conncetion manager suggested to terminate your session.")); + return TRUE; + } + return FALSE; +} + +void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { + xmlnode *child; + JabberStream *js = conn->js; + + if (node == NULL) return; + + if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; + + child = node->child; + while (child != 0) { + if (child->type == XMLNODE_TYPE_TAG) { + xmlnode *session = NULL; + if (!strcmp(child->name, "iq")) session = xmlnode_get_child(child, "session"); + if (session) { + conn->ready = TRUE; + } + jabber_process_packet(js, &child); + } + child = child->next; + } +} + +void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node) { + xmlnode *child = node->child; + + if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; + + while(child != NULL && child->type != XMLNODE_TYPE_TAG) { + child = child->next; + } + + 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 printf("\n!! no child!!\n"); +} + +void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node) { + char *version; + + if (jabber_bosh_connection_error_check(conn, node) == TRUE) return; + + 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"); + } +} + +static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { + char *tmp; + xmlnode *init = xmlnode_new("body"); + xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); + xmlnode_set_attrib(init, "secure", "true"); + //xmlnode_set_attrib(init, "route", tmp = g_strdup_printf("xmpp:%s:5222", conn->js->user->domain)); + //g_free(tmp); + xmlnode_set_attrib(init, "to", conn->js->user->domain); + xmlnode_set_attrib(init, "xml:lang", "en"); + xmlnode_set_attrib(init, "xmpp:version", "1.0"); + xmlnode_set_attrib(init, "ver", "1.6"); + xmlnode_set_attrib(init, "xmlns:xmpp", "urn:xmpp:xbosh"); + 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, "xmlns", "http://jabber.org/protocol/httpbind"); + xmlnode_set_attrib(init, "hold", "1"); + + 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) { + PurpleBOSHConnection *conn = userdata; + if (conn->receive_cb) { + xmlnode *node = xmlnode_from_str(res->data, res->data_len); + if (node) { + char *txt = xmlnode_to_formatted_str(node, NULL); + printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt); + g_free(txt); + conn->receive_cb(conn, node); + xmlnode_free(node); + } else { + printf("\njabber_bosh_connection_http_received_cb: XML ERROR: %s\n", res->data); + } + } else purple_debug_info("jabber", "missing receive_cb of PurpleBOSHConnection.\n"); +} + +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); + + if (node) { + xmlnode_insert_child(packet, node); + if (conn->ready == TRUE) xmlnode_set_attrib(node, "xmlns", "jabber:client"); + } + 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)); + jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data))); + jabber_bosh_http_connection_send_request(conn->conn_a, request); +} + +static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { + PurpleBOSHConnection *bosh_conn = conn->userdata; + if (bosh_conn->ready == TRUE && bosh_conn->connect_cb) { + purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); + bosh_conn->receive_cb = jabber_bosh_connection_received; + bosh_conn->connect_cb(bosh_conn); + } else jabber_bosh_connection_boot(bosh_conn); +} + +static void jabber_bosh_connection_refresh(PurpleHTTPConnection *conn) { + PurpleBOSHConnection *bosh_conn = conn->userdata; + jabber_bosh_connection_send(bosh_conn, NULL); +} + +static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { + PurpleBOSHConnection *bosh_conn = conn->userdata; + bosh_conn->conn_a->connect_cb = jabber_bosh_connection_connected; + jabber_bosh_http_connection_connect(bosh_conn->conn_a); +} + +void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) { + conn->conn_a->connect_cb = jabber_bosh_connection_connected; + jabber_bosh_http_connection_connect(conn->conn_a); +} + +void jabber_bosh_http_connection_receive_parse_header(PurpleHTTPResponse *response, char **data, int *len) { + GHashTable *header = response->header; + char *beginning = *data; + char *found = g_strstr_len(*data, len, "\r\n\r\n"); + char *field = NULL; + char *value = NULL; + char *old_data = *data; + + while (*beginning != 'H') ++beginning; + beginning[12] = 0; + response->status = atoi(&beginning[9]); + beginning = &beginning[13]; + do { + ++beginning; + } while (*beginning != '\n'); + ++beginning; + /* parse HTTP response header */ + for (;beginning != found; ++beginning) { + if (!field) field = beginning; + if (*beginning == ':') { + *beginning = 0; + value = beginning + 1; + } else if (*beginning == '\r') { + *beginning = 0; + g_hash_table_replace(header, g_strdup(field), g_strdup(value)); + value = field = 0; + ++beginning; + } + } + ++beginning; ++beginning; ++beginning; ++beginning; + /* remove the header from data buffer */ + *data = g_strdup(beginning); + *len = *len - (beginning - old_data); + g_free(old_data); +} + +static void jabber_bosh_http_connection_receive(gpointer data, gint source, PurpleInputCondition condition) { + char buffer[1025]; + int len; + PurpleHTTPConnection *conn = data; + PurpleBOSHConnection *bosh_conn = conn->userdata; + PurpleHTTPResponse *response = conn->current_response; + + purple_debug_info("jabber", "jabber_bosh_http_connection_receive\n"); + + len = read(source, buffer, 1024); + if (len > 0) { + buffer[len] = 0; + if (conn->current_data == NULL) { + conn->current_len = len; + conn->current_data = g_strdup_printf("%s", buffer); + } else { + char *old_data = conn->current_data; + conn->current_len += len; + conn->current_data = g_strdup_printf("%s%s", conn->current_data, buffer); + g_free(old_data); + } + + if (!response) { + /* check for header footer */ + char *found = NULL; + if (found = g_strstr_len(conn->current_data, conn->current_len, "\r\n\r\n")) { + + // new response + response = conn->current_response = g_new0(PurpleHTTPResponse, 1); + jabber_bosh_http_response_init(response); + jabber_bosh_http_connection_receive_parse_header(response, &(conn->current_data), &(conn->current_len)); + response->data_len = atoi(g_hash_table_lookup(response->header, "Content-Length")); + } else { + printf("\nDid not receive HTTP header\n"); + } + } + + if (response) { + if (conn->current_len >= response->data_len) { + PurpleHTTPRequest *request = g_queue_pop_head(conn->requests); + + #warning for a pure HTTP 1.1 stack this would be needed to be handled elsewhereƄ + if (bosh_conn->ready == TRUE && g_queue_is_empty(conn->requests) == TRUE) { + jabber_bosh_connection_send(bosh_conn, NULL); + printf("\n SEND AN EMPTY REQUEST \n"); + } + + if (request) { + char *old_data = conn->current_data; + response->data = g_memdup(conn->current_data, response->data_len); + conn->current_data = g_strdup(&conn->current_data[response->data_len]); + conn->current_len -= response->data_len; + g_free(old_data); + + if (request->cb) request->cb(request, response, conn->userdata); + else purple_debug_info("jabber", "missing request callback!\n"); + + jabber_bosh_http_request_clean(request); + jabber_bosh_http_response_clean(response); + conn->current_response = NULL; + g_free(request); + g_free(response); + } else { + purple_debug_info("jabber", "received HTTP response but haven't requested anything yet.\n"); + } + } + } + } else if (len == 0) { + purple_input_remove(conn->ie_handle); + if (conn->disconnect_cb) conn->disconnect_cb(conn); + } else { + purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data (%d)\n", len); + } +} + +void jabber_bosh_http_connection_init(PurpleHTTPConnection *conn, PurpleAccount *account, char *host, int port) { + conn->account = account; + conn->host = host; + conn->port = port; + conn->connect_cb = NULL; + conn->current_response = NULL; + conn->current_data = NULL; + conn->requests = g_queue_new(); +} + +void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn) { + g_queue_free(conn->requests); +} + +static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) { + PurpleHTTPConnection *conn = data; + if (source < 0) { + purple_debug_info("jabber", "Couldn't connect becasue of: %s\n", error); + return; + } + conn->fd = source; + if (conn->connect_cb) conn->connect_cb(conn); + else purple_debug_info("jabber", "No connect callback for HTTP connection.\n"); + conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ, jabber_bosh_http_connection_receive, conn); } void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn) { - -} \ No newline at end of file + if((purple_proxy_connect(&(conn->handle), conn->account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) { + purple_debug_info("jabber", "Unable to connect to %s.\n", conn->host); + } +} + +static void jabber_bosh_http_connection_send_request_add_field_to_string(gpointer key, gpointer value, gpointer user_data) { + char **ppacket = user_data; + char *tmp = *ppacket; + char *field = key; + char *val = value; + *ppacket = g_strdup_printf("%s%s: %s\r\n", tmp, field, val); + g_free(tmp); +} + +void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req) { + char *packet; + char *tmp; + jabber_bosh_http_request_add_to_header(req, "Host", conn->host); + jabber_bosh_http_request_add_to_header(req, "User-Agent", "libpurple"); + packet = tmp = g_strdup_printf("%s %s HTTP/1.1\r\n", req->method, req->path); + g_hash_table_foreach(req->header, jabber_bosh_http_connection_send_request_add_field_to_string, &packet); + tmp = packet; + packet = g_strdup_printf("%s\r\n%s", tmp, req->data); + g_free(tmp); + if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n"); + g_queue_push_tail(conn->requests, req); +} + +void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata) { + req->method = g_strdup(method); + req->path = g_strdup(path); + req->cb = cb; + req->userdata = userdata; + req->header = g_hash_table_new(g_str_hash, g_str_equal); +} + +void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) { + g_hash_table_replace(req->header, field, value); +} + +void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len) { + req->data = data; + req->data_len = len; +} + +void jabber_bosh_http_request_clean(PurpleHTTPRequest *req) { + g_hash_table_destroy(req->header); + g_free(req->method); + g_free(req->path); + g_free(req->data); +} + +void jabber_bosh_http_response_init(PurpleHTTPResponse *res) { + res->status = 0; + res->header = g_hash_table_new(g_str_hash, g_str_equal); +} + + +void jabber_bosh_http_response_clean(PurpleHTTPResponse *res) { + g_hash_table_destroy(res->header); + g_free(res->data); +}
--- a/libpurple/protocols/jabber/bosh.h Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/bosh.h Thu Nov 20 21:13:56 2008 +0000 @@ -26,50 +26,91 @@ typedef struct _PurpleHTTPRequest PurpleHTTPRequest; typedef struct _PurpleHTTPResponse PurpleHTTPResponse; -typedef struct _PurpleHTTPHeaderField PurpleHTTPHeaderField; +typedef struct _PurpleHTTPConnection PurpleHTTPConnection; +typedef struct _PurpleBOSHConnection PurpleBOSHConnection; +typedef void (*PurpleHTTPConnectionConnectFunction)(PurpleHTTPConnection *conn); +typedef void (*PurpleHTTPConnectionDisconnectFunction)(PurpleHTTPConnection *conn); typedef void (*PurpleHTTPRequestCallback)(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata); +typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); +typedef void (*PurpleBOSHConnectionReciveFunction)(PurpleBOSHConnection *conn, xmlnode *node); -typedef struct { - int fd; - PurpleConnection *conn; - GQueue *requests; +struct _PurpleBOSHConnection { + /* decoded URL */ + char *host; + int port; + char *path; + char *user; + char *passwd; + + int rid; + char *sid; + int wait; + + JabberStream *js; void *userdata; -} PurpleHTTPConnection; - -typedef struct { - char *url; + PurpleAccount *account; gboolean pipelining; PurpleHTTPConnection *conn_a; PurpleHTTPConnection *conn_b; -} PurpleBOSHConnection; + + gboolean ready; + PurpleBOSHConnectionConnectFunction connect_cb; + PurpleBOSHConnectionReciveFunction receive_cb; +}; + +struct _PurpleHTTPConnection { + int fd; + char *host; + int port; + int handle; + int ie_handle; + PurpleConnection *conn; + PurpleAccount *account; + GQueue *requests; + + PurpleHTTPResponse *current_response; + char *current_data; + int current_len; + + int pih; + PurpleHTTPConnectionConnectFunction connect_cb; + PurpleHTTPConnectionConnectFunction disconnect_cb; + void *userdata; +}; struct _PurpleHTTPRequest { PurpleHTTPRequestCallback cb; char *method; - char *url; - GList *header; + char *path; + GHashTable *header; char *data; + int data_len; void *userdata; }; struct _PurpleHTTPResponse { int status; - GList *header; + GHashTable *header; char *data; -}; - -struct _PurpleHTTPHeaderField { - char *name; - char *value; + int data_len; }; -PurpleHTTPHeaderField *jabber_bosh_http_header_field(const char *name, const char *value); +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); void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn); -void jabber_bosh_http_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req); +void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req); void jabber_bosh_http_connection_clean(PurpleHTTPConnection *conn); -void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *url, PurpleHTTPRequestCallback cb, void *userdata); +void jabber_bosh_http_request_init(PurpleHTTPRequest *req, const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata); +void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value); +void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len); void jabber_bosh_http_request_clean(PurpleHTTPRequest *req); + +void jabber_bosh_http_response_init(PurpleHTTPResponse *res); +void jabber_bosh_http_response_clean(PurpleHTTPResponse *res); #endif /* _PURPLE_JABBER_BOSH_H_ */
--- a/libpurple/protocols/jabber/caps.h Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/caps.h Thu Nov 20 21:13:56 2008 +0000 @@ -81,6 +81,9 @@ */ gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info, const char *hash); +/** + * Calcualte SHA1 hash for own featureset. + */ void jabber_caps_calculate_own_hash(); /** Get the current caps hash. @@ -89,7 +92,7 @@ const gchar* jabber_caps_get_own_hash(); /** - * + * Broadcast a new calculated hash using a <presence> stanza. */ void jabber_caps_broadcast_change();
--- a/libpurple/protocols/jabber/jabber.c Sun Aug 03 23:16:24 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Thu Nov 20 21:13:56 2008 +0000 @@ -146,7 +146,7 @@ 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)) @@ -355,7 +355,19 @@ } #endif - do_jabber_send_raw(js, data, len); + if (len == -1) + len = strlen(data); + + if (js->use_bosh) { + xmlnode *xnode = xmlnode_from_str(data, len); + if (xnode) jabber_bosh_connection_send(&(js->bosh), xnode); + else { + purple_connection_error_reason(js->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, + _("Someone tried to send non-XML in a Jabber world.")); + } + } else { + do_jabber_send_raw(js, data, len); + } } int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len) @@ -518,6 +530,12 @@ jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING_ENCRYPTION); } +static void +jabber_bosh_login_callback(PurpleBOSHConnection *conn) +{ + purple_debug_info("jabber","YAY...BOSH connection established.\n"); +} + static void txt_resolved_cb(PurpleTxtResponse *resp, int results, gpointer data) { @@ -530,7 +548,8 @@ tmp = g_strdup_printf(_("Could not find alternative XMPP connection methods after failing to connect directly.\n")); purple_connection_error_reason (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); - g_free(tmp); + g_free(tmp); + return; } for (n = 0; n < results; n++) { @@ -538,12 +557,18 @@ token = g_strsplit(resp[n].content, "=", 2); if (!strcmp(token[0], "_xmpp-client-xbosh")) { purple_debug_info("jabber","Found alternative connection method using %s at %s.\n", token[0], token[1]); - js->bosh.url = g_strdup(token[1]); + jabber_bosh_connection_init(&(js->bosh), gc->account, js, token[1]); g_strfreev(token); break; } g_strfreev(token); } + if (js->bosh.host) { + js->bosh.userdata = gc; + jabber_bosh_connection_connect(&(js->bosh)); + } else { + purple_debug_info("jabber","Didn't find an alternative connection method.\n"); + } } static void