cpw.darkrain42.xmpp.iq-handlers: a7d6ab07: Convert IBB parser (and everything that ...
paul at darkrain42.org
paul at darkrain42.org
Sat Apr 4 03:35:41 EDT 2009
-----------------------------------------------------------------
Revision: a7d6ab07b988776e830ffb6befb18179ff46e24e
Ancestor: 7c48937e8ad8d3fb0546f7d8292474cc54a00c0e
Author: paul at darkrain42.org
Date: 2009-04-04T07:05:23
Branch: im.pidgin.cpw.darkrain42.xmpp.iq-handlers
URL: http://d.pidgin.im/viewmtn/revision/info/a7d6ab07b988776e830ffb6befb18179ff46e24e
Modified files:
libpurple/protocols/jabber/ibb.c
libpurple/protocols/jabber/ibb.h
libpurple/protocols/jabber/iq.c
libpurple/protocols/jabber/si.c
ChangeLog:
Convert IBB parser (and everything that then stems from that) to new iq-handler
Apparently I completely missed this when propagating earlier
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/ibb.c 8f8e8be282e9cd727a5a430ec742bc3eae721ac5
+++ libpurple/protocols/jabber/ibb.c f975b3ca8f7c1e2f2fdb9c7b64e646904e85211b
@@ -46,12 +46,10 @@ JabberIBBSession *
}
JabberIBBSession *
-jabber_ibb_session_create_from_xmlnode(JabberStream *js, xmlnode *packet,
- gpointer user_data)
+jabber_ibb_session_create_from_xmlnode(JabberStream *js, const char *from,
+ const char *id, xmlnode *open, gpointer user_data)
{
JabberIBBSession *sess = NULL;
- xmlnode *open = xmlnode_get_child_with_namespace(packet, "open",
- XEP_0047_NAMESPACE);
const gchar *sid = xmlnode_get_attrib(open, "sid");
const gchar *block_size = xmlnode_get_attrib(open, "block-size");
@@ -66,9 +64,8 @@ jabber_ibb_session_create_from_xmlnode(J
return NULL;
}
- sess = jabber_ibb_session_create(js, sid,
- xmlnode_get_attrib(packet, "from"), user_data);
- sess->id = g_strdup(xmlnode_get_attrib(packet, "id"));
+ sess = jabber_ibb_session_create(js, sid, from, user_data);
+ sess->id = g_strdup(id);
sess->block_size = atoi(block_size);
/* if we create a session from an incoming <open/> request, it means the
session is immediatly open... */
@@ -354,7 +351,7 @@ static void
}
static void
-jabber_ibb_send_error_response(JabberStream *js, xmlnode *packet)
+jabber_ibb_send_error_response(JabberStream *js, const char *to, const char *id)
{
JabberIq *result = jabber_iq_new(js, JABBER_IQ_ERROR);
xmlnode *error = xmlnode_new("error");
@@ -364,9 +361,8 @@ jabber_ibb_send_error_response(JabberStr
"urn:ietf:params:xml:ns:xmpp-stanzas");
xmlnode_set_attrib(error, "code", "440");
xmlnode_set_attrib(error, "type", "cancel");
- jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
- xmlnode_set_attrib(result->node, "to",
- xmlnode_get_attrib(packet, "from"));
+ jabber_iq_set_id(result, id);
+ xmlnode_set_attrib(result->node, "to", to);
xmlnode_insert_child(error, item_not_found);
xmlnode_insert_child(result->node, error);
@@ -374,20 +370,17 @@ void
}
void
-jabber_ibb_parse(JabberStream *js, xmlnode *packet)
+jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type,
+ const char *id, xmlnode *child)
{
- xmlnode *data = xmlnode_get_child_with_namespace(packet, "data",
- XEP_0047_NAMESPACE);
- xmlnode *close = xmlnode_get_child_with_namespace(packet, "close",
- XEP_0047_NAMESPACE);
- xmlnode *open = xmlnode_get_child_with_namespace(packet, "open",
- XEP_0047_NAMESPACE);
- const gchar *sid =
- data ? xmlnode_get_attrib(data, "sid") :
- close ? xmlnode_get_attrib(close, "sid") : NULL;
+ const char *name = child->name;
+ gboolean data = g_str_equal(name, "data");
+ gboolean close = g_str_equal(name, "close");
+ gboolean open = g_str_equal(name, "open");
+ const gchar *sid = (data || close) ?
+ xmlnode_get_attrib(child, "sid") : NULL;
JabberIBBSession *sess =
sid ? g_hash_table_lookup(jabber_ibb_sessions, sid) : NULL;
- const gchar *who = xmlnode_get_attrib(packet, "from");
if (sess) {
@@ -397,7 +390,7 @@ jabber_ibb_parse(JabberStream *js, xmlno
purple_debug_error("jabber",
"Got IBB iq from wrong JID, ignoring\n");
} else if (data) {
- const gchar *seq_attr = xmlnode_get_attrib(data, "seq");
+ const gchar *seq_attr = xmlnode_get_attrib(child, "seq");
guint16 seq = (seq_attr ? atoi(seq_attr) : 0);
/* reject the data, and set the session in error if we get an
@@ -406,12 +399,11 @@ jabber_ibb_parse(JabberStream *js, xmlno
/* sequence # is the expected... */
JabberIq *result = jabber_iq_new(js, JABBER_IQ_RESULT);
- jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
- xmlnode_set_attrib(result->node, "to",
- xmlnode_get_attrib(packet, "from"));
+ jabber_iq_set_id(result, id);
+ xmlnode_set_attrib(result->node, "to", who);
if (sess->data_received_cb) {
- gchar *base64 = xmlnode_get_data(data);
+ gchar *base64 = xmlnode_get_data(child);
gsize size;
gpointer rawdata = purple_base64_decode(base64, &size);
@@ -478,20 +470,19 @@ jabber_ibb_parse(JabberStream *js, xmlno
iterator = g_list_next(iterator)) {
JabberIBBOpenHandler *handler = iterator->data;
- if (handler(js, packet)) {
+ if (handler(js, who, id, child)) {
result = jabber_iq_new(js, JABBER_IQ_RESULT);
- xmlnode_set_attrib(result->node, "to",
- xmlnode_get_attrib(packet, "from"));
- jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id"));
+ xmlnode_set_attrib(result->node, "to", who);
+ jabber_iq_set_id(result, id);
jabber_iq_send(result);
return;
}
}
/* no open callback returned success, reject */
- jabber_ibb_send_error_response(js, packet);
+ jabber_ibb_send_error_response(js, who, id);
} else {
/* send error reply */
- jabber_ibb_send_error_response(js, packet);
+ jabber_ibb_send_error_response(js, who, id);
}
}
============================================================
--- libpurple/protocols/jabber/ibb.h 4a5131f44dea294228092fc83ace02651e10b962
+++ libpurple/protocols/jabber/ibb.h fc9b99d46502c00aa067b6688a5adb11d3749e77
@@ -32,7 +32,8 @@ typedef void (JabberIBBSentCallback)(Jab
typedef void (JabberIBBErrorCallback)(JabberIBBSession *);
typedef void (JabberIBBSentCallback)(JabberIBBSession *);
-typedef gboolean (JabberIBBOpenHandler)(JabberStream *js, xmlnode *packet);
+typedef gboolean (JabberIBBOpenHandler)(JabberStream *js, const char *from,
+ const char *id, xmlnode *open);
typedef enum {
JABBER_IBB_SESSION_NOT_OPENED,
@@ -71,7 +72,7 @@ JabberIBBSession *jabber_ibb_session_cre
JabberIBBSession *jabber_ibb_session_create(JabberStream *js, const gchar *sid,
const gchar *who, gpointer user_data);
JabberIBBSession *jabber_ibb_session_create_from_xmlnode(JabberStream *js,
- xmlnode *packet, gpointer user_data);
+ const gchar *from, const gchar *id, xmlnode *open, gpointer user_data);
void jabber_ibb_session_destroy(JabberIBBSession *sess);
@@ -107,7 +108,8 @@ gpointer jabber_ibb_session_get_user_dat
gpointer jabber_ibb_session_get_user_data(JabberIBBSession *sess);
/* handle incoming packet */
-void jabber_ibb_parse(JabberStream *js, xmlnode *packet);
+void jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type,
+ const char *id, xmlnode *child);
/* add a handler for open session */
void jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb);
============================================================
--- libpurple/protocols/jabber/iq.c 83440d87f39f3c0b4d43e49fbc6ed0c34d4026bd
+++ libpurple/protocols/jabber/iq.c 155242ede2fa4b69fb86367b33e6bb604c297e5c
@@ -428,6 +428,10 @@ void jabber_iq_init(void)
jabber_iq_register_handler("ping", "urn:xmpp:ping", jabber_ping_parse);
jabber_iq_register_handler("time", "urn:xmpp:time", jabber_iq_time_parse);
+ jabber_iq_register_handler("data", XEP_0047_NAMESPACE, jabber_ibb_parse);
+ jabber_iq_register_handler("close", XEP_0047_NAMESPACE, jabber_ibb_parse);
+ jabber_iq_register_handler("open", XEP_0047_NAMESPACE, jabber_ibb_parse);
+
jabber_iq_register_handler("jingle", JINGLE, jingle_parse);
jabber_iq_register_handler("query", GOOGLE_JINGLE_INFO_NAMESPACE,
jabber_google_handle_jingle_info);
============================================================
--- libpurple/protocols/jabber/si.c edc3b1d782486cc7a71a745c457bdc9f6e51b7ba
+++ libpurple/protocols/jabber/si.c 1c1df0ad838327bfe6c119ff43667c7d59f7b093
@@ -1015,16 +1015,15 @@ static gboolean
}
static gboolean
-jabber_si_xfer_ibb_open_cb(JabberStream *js, xmlnode *packet)
+jabber_si_xfer_ibb_open_cb(JabberStream *js, const char *who, const char *id,
+ xmlnode *open)
{
- const gchar *who = xmlnode_get_attrib(packet, "from");
- xmlnode *open = xmlnode_get_child(packet, "open");
const gchar *sid = xmlnode_get_attrib(open, "sid");
PurpleXfer *xfer = jabber_si_xfer_find(js, sid, who);
if (xfer) {
JabberSIXfer *jsx = (JabberSIXfer *) xfer->data;
JabberIBBSession *sess =
- jabber_ibb_session_create_from_xmlnode(js, packet, xfer);
+ jabber_ibb_session_create_from_xmlnode(js, who, id, open, xfer);
const char *filename;
jabber_si_bytestreams_ibb_timeout_remove(jsx);
More information about the Commits
mailing list