cpw.darkrain42.xmpp.bosh: 482c324d: Pass all messages to BOSH as text, so th...
paul at darkrain42.org
paul at darkrain42.org
Sat Apr 4 01:30:51 EDT 2009
-----------------------------------------------------------------
Revision: 482c324d2ba1367588ccd1b26a94d318e099e8bf
Ancestor: 9af1e1f665d3daa2e845a4c1fcc4be300adad70f
Author: paul at darkrain42.org
Date: 2009-04-04T04:34:57
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/482c324d2ba1367588ccd1b26a94d318e099e8bf
Modified files:
libpurple/protocols/jabber/bosh.c
libpurple/protocols/jabber/bosh.h
libpurple/protocols/jabber/jabber.c
ChangeLog:
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.
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c 2ef839317154c9a20e2ede7f8faf4bb7f876ff20
+++ libpurple/protocols/jabber/bosh.c c225b2a39524a9628ba05e9f865ad8cc352d6fac
@@ -94,7 +94,7 @@ static void jabber_bosh_connection_recei
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(Purple
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 @@ bosh_inactivity_cb(gpointer data)
{
PurpleBOSHConnection *bosh = data;
- jabber_bosh_connection_send(bosh, NULL);
+ jabber_bosh_connection_send(bosh, PACKET_NORMAL, NULL);
return TRUE;
}
@@ -452,36 +452,18 @@ http_received_cb(const char *data, int l
}
}
-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 @@ jabber_bosh_connection_send_native(Purpl
"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 @@ jabber_bosh_connection_send_native(Purpl
* 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 @@ jabber_bosh_connection_send_native(Purpl
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 @@ connection_common_established_cb(PurpleH
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(Purp
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 @@ jabber_bosh_http_connection_process(Purp
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");
}
============================================================
--- libpurple/protocols/jabber/bosh.h a2e951257d8f86e3ababc2586a09eb9139241624
+++ libpurple/protocols/jabber/bosh.h 8e0061ffac5f3acdd0848748efdfec7faaa74f16
@@ -36,7 +36,6 @@ void jabber_bosh_connection_close(Purple
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_ */
============================================================
--- libpurple/protocols/jabber/jabber.c ef3c420067b22508c3513caa1cf39fa352ed3f6a
+++ libpurple/protocols/jabber/jabber.c 219a396e1c00ebe335501839792060a60a5d05d7
@@ -428,7 +428,7 @@ void jabber_send_raw(JabberStream *js, c
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 @@ void jabber_send(JabberStream *js, xmlno
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)
More information about the Commits
mailing list