Mercurial > pidgin.yaz
changeset 26530:d4af753e0e33
Pass all messages to BOSH as text, so they pass through the sending-text
signal and debug output.
This also (I believe) saves one redundant text->xmlnode->text copy.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 04 Apr 2009 04:34:57 +0000 |
parents | 1ecbda91458a |
children | 345165fc51b6 |
files | libpurple/protocols/jabber/bosh.c libpurple/protocols/jabber/bosh.h libpurple/protocols/jabber/jabber.c |
diffstat | 3 files changed, 21 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c Sat Apr 04 03:40:43 2009 +0000 +++ b/libpurple/protocols/jabber/bosh.c Sat Apr 04 04:34:57 2009 +0000 @@ -94,7 +94,7 @@ static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn); static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node); static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node); -static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, PurpleBOSHPacketType, xmlnode *node); +static void jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, const char *data); static void http_connection_connect(PurpleHTTPConnection *conn); static void http_connection_send_request(PurpleHTTPConnection *conn, const GString *req); @@ -225,11 +225,11 @@ void jabber_bosh_connection_close(PurpleBOSHConnection *conn) { - jabber_bosh_connection_send_native(conn, PACKET_TERMINATE, NULL); + jabber_bosh_connection_send(conn, PACKET_TERMINATE, NULL); } static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) { - jabber_bosh_connection_send_native(conn, PACKET_STREAM_RESTART, NULL); + jabber_bosh_connection_send(conn, PACKET_STREAM_RESTART, NULL); } static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node) { @@ -252,7 +252,7 @@ { PurpleBOSHConnection *bosh = data; - jabber_bosh_connection_send(bosh, NULL); + jabber_bosh_connection_send(bosh, PACKET_NORMAL, NULL); return TRUE; } @@ -452,36 +452,18 @@ } } -void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { - jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); -} - void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, - const char *data, int len) + const char *data) { - xmlnode *node = xmlnode_from_str(data, len); - if (node) { - jabber_bosh_connection_send_native(conn, PACKET_NORMAL, node); - xmlnode_free(node); - } else { - /* - * This best emulates what a normal XMPP server would do - * if you send bad XML. - */ - purple_connection_error_reason(conn->js->gc, - PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - _("Cannot send malformed XML")); - } + jabber_bosh_connection_send(conn, PACKET_NORMAL, data); } static void -jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, - xmlnode *node) +jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, + const char *data) { PurpleHTTPConnection *chosen; GString *packet = NULL; - char *buf = NULL; - int len; chosen = find_available_http_connection(conn); @@ -497,9 +479,6 @@ "things may happen.\n"); } - if (node) - buf = xmlnode_to_str(node, &len); - if (type == PACKET_NORMAL && (!chosen || (conn->max_requests > 0 && conn->requests == conn->max_requests))) { /* @@ -507,9 +486,9 @@ * connection ready (likely, we're currently opening a second connection and * will send these packets when connected). */ - if (buf) { - purple_circ_buffer_append(conn->pending, buf, len); - g_free(buf); + if (data) { + int len = data ? strlen(data) : 0; + purple_circ_buffer_append(conn->pending, data, len); } return; } @@ -541,13 +520,11 @@ purple_circ_buffer_mark_read(conn->pending, read_amt); } - if (buf) - packet = g_string_append_len(packet, buf, len); + if (data) + packet = g_string_append(packet, data); packet = g_string_append(packet, "</body>"); } - g_free(buf); - http_connection_send_request(chosen, packet); } @@ -568,7 +545,7 @@ purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n"); if (conn->bosh->pending->bufused > 0) { /* Send the pending data */ - jabber_bosh_connection_send_native(conn->bosh, PACKET_NORMAL, NULL); + jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL); } #if 0 conn->bosh->receive_cb = jabber_bosh_connection_received; @@ -581,7 +558,7 @@ void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn) { - jabber_bosh_connection_send(conn, NULL); + jabber_bosh_connection_send(conn, PACKET_NORMAL, NULL); } static void http_connection_disconnected(PurpleHTTPConnection *conn) @@ -670,7 +647,7 @@ if (conn->bosh->ready && (conn->bosh->requests == 0 || conn->bosh->pending->bufused > 0)) { - jabber_bosh_connection_send(conn->bosh, NULL); + jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL); purple_debug_misc("jabber", "BOSH: Sending an empty request\n"); }
--- a/libpurple/protocols/jabber/bosh.h Sat Apr 04 03:40:43 2009 +0000 +++ b/libpurple/protocols/jabber/bosh.h Sat Apr 04 04:34:57 2009 +0000 @@ -36,7 +36,6 @@ void jabber_bosh_connection_connect(PurpleBOSHConnection *conn); void jabber_bosh_connection_close(PurpleBOSHConnection *conn); -void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node); -void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, const char *data, int len); +void jabber_bosh_connection_send_raw(PurpleBOSHConnection *conn, const char *data); void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn); #endif /* _PURPLE_JABBER_BOSH_H_ */
--- a/libpurple/protocols/jabber/jabber.c Sat Apr 04 03:40:43 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Sat Apr 04 04:34:57 2009 +0000 @@ -428,7 +428,7 @@ len = strlen(data); if (js->use_bosh) - jabber_bosh_connection_send_raw(js->bosh, data, len); + jabber_bosh_connection_send_raw(js->bosh, data); else do_jabber_send_raw(js, data, len); } @@ -451,13 +451,9 @@ if(NULL == packet) return; - 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); - } + 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 unused)