Mercurial > pidgin.yaz
changeset 25062:e30e9779e7bf
In jabber_iq_parse, xmlnode_get_child is called for a few special cases,
and then the original xmlnode is passed to the handler. That seems kind of
pointless, since jabber_iq_parse has all the data. So I just passed the
data necessary for each handler instead. I didn't change the query handlers
since they seem to require the parent.
I assume the point was to go for a unified prototype, but since these
handlers are all special cases, I think it's okay to give them a special
signature as well.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Thu, 05 Feb 2009 05:42:58 +0000 |
parents | 575b2b9f3ac9 |
children | 8f5a63aebdb6 36c73d036026 |
files | libpurple/protocols/jabber/data.c libpurple/protocols/jabber/data.h libpurple/protocols/jabber/google.c libpurple/protocols/jabber/google.h libpurple/protocols/jabber/iq.c libpurple/protocols/jabber/ping.c libpurple/protocols/jabber/ping.h libpurple/protocols/jabber/si.c libpurple/protocols/jabber/si.h |
diffstat | 9 files changed, 28 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/data.c Thu Feb 05 05:42:58 2009 +0000 @@ -200,11 +200,9 @@ } void -jabber_data_parse(JabberStream *js, xmlnode *packet) +jabber_data_parse(JabberStream *js, xmlnode *data_node, const char *who, const char *id) { JabberIq *result = NULL; - const char *who = xmlnode_get_attrib(packet, "from"); - xmlnode *data_node = xmlnode_get_child(packet, "data"); const JabberData *data = jabber_data_find_local_by_cid(xmlnode_get_attrib(data_node, "cid")); @@ -213,12 +211,12 @@ result = jabber_iq_new(js, JABBER_IQ_ERROR); xmlnode_set_attrib(result->node, "to", who); - xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id")); + xmlnode_set_attrib(result->node, "id", id); xmlnode_insert_child(result->node, item_not_found); } else { result = jabber_iq_new(js, JABBER_IQ_RESULT); xmlnode_set_attrib(result->node, "to", who); - xmlnode_set_attrib(result->node, "id", xmlnode_get_attrib(packet, "id")); + xmlnode_set_attrib(result->node, "id", id); xmlnode_insert_child(result->node, jabber_data_get_xml_definition(data)); }
--- a/libpurple/protocols/jabber/data.h Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/data.h Thu Feb 05 05:42:58 2009 +0000 @@ -65,7 +65,8 @@ void jabber_data_associate_remote(JabberData *data); /* handles iq requests */ -void jabber_data_parse(JabberStream *js, xmlnode *packet); +void jabber_data_parse(JabberStream *js, xmlnode *data_node, + const char *who, const char *id); void jabber_data_init(void); void jabber_data_uninit(void);
--- a/libpurple/protocols/jabber/google.c Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/google.c Thu Feb 05 05:42:58 2009 +0000 @@ -144,9 +144,8 @@ } void -jabber_gmail_poke(JabberStream *js, xmlnode *packet) +jabber_gmail_poke(JabberStream *js, const char *type) { - const char *type; xmlnode *query; JabberIq *iq; @@ -154,11 +153,8 @@ if (!purple_account_get_check_mail(js->gc->account)) return; - type = xmlnode_get_attrib(packet, "type"); - - /* Is this an initial incoming mail notification? If so, send a request for more info */ - if (strcmp(type, "set") || !xmlnode_get_child(packet, "new-mail")) + if (strcmp(type, "set")) return; purple_debug(PURPLE_DEBUG_MISC, "jabber",
--- a/libpurple/protocols/jabber/google.h Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/google.h Thu Feb 05 05:42:58 2009 +0000 @@ -27,7 +27,7 @@ #include "jabber.h" void jabber_gmail_init(JabberStream *js); -void jabber_gmail_poke(JabberStream *js, xmlnode *node); +void jabber_gmail_poke(JabberStream *js, const char *type); void jabber_google_roster_init(JabberStream *js); void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item);
--- a/libpurple/protocols/jabber/iq.c Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/iq.c Thu Feb 05 05:42:58 2009 +0000 @@ -309,7 +309,7 @@ void jabber_iq_parse(JabberStream *js, xmlnode *packet) { JabberCallbackData *jcd; - xmlnode *query, *error, *x; + xmlnode *child, *query, *error, *x; const char *xmlns; const char *type, *id, *from; JabberIqHandler *jih; @@ -371,25 +371,25 @@ } } - if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { - jabber_si_parse(js, packet); + if ((child = xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si"))) { + jabber_si_parse(js, child, from, id); return; } - if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { - jabber_gmail_poke(js, packet); + if (xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { + jabber_gmail_poke(js, type); return; } purple_debug_info("jabber", "jabber_iq_parse\n"); - if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { - jabber_ping_parse(js, packet); + if (xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { + jabber_ping_parse(js, from, id); return; } - if (xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE)) { - jabber_data_parse(js, packet); + if ((child = xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE))) { + jabber_data_parse(js, child, from, id); return; }
--- a/libpurple/protocols/jabber/ping.c Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/ping.c Thu Feb 05 05:42:58 2009 +0000 @@ -30,7 +30,7 @@ #include "iq.h" void -jabber_ping_parse(JabberStream *js, xmlnode *packet) +jabber_ping_parse(JabberStream *js, const char *from, const char *id) { JabberIq *iq; @@ -38,9 +38,9 @@ iq = jabber_iq_new(js, JABBER_IQ_RESULT); - xmlnode_set_attrib(iq->node, "to", xmlnode_get_attrib(packet, "from") ); + xmlnode_set_attrib(iq->node, "to", from); - jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); + jabber_iq_set_id(iq, id); jabber_iq_send(iq); }
--- a/libpurple/protocols/jabber/ping.h Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/ping.h Thu Feb 05 05:42:58 2009 +0000 @@ -26,7 +26,8 @@ #include "conversation.h" void jabber_ping_parse(JabberStream *js, - xmlnode *packet); + const char *from, + const char *id); gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid);
--- a/libpurple/protocols/jabber/si.c Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/si.c Thu Feb 05 05:42:58 2009 +0000 @@ -1182,17 +1182,14 @@ purple_xfer_request(xfer); } -void jabber_si_parse(JabberStream *js, xmlnode *packet) +void jabber_si_parse(JabberStream *js, xmlnode *si, const char *from, const char *id) { JabberSIXfer *jsx; PurpleXfer *xfer; - xmlnode *si, *file, *feature, *x, *field, *option, *value; - const char *stream_id, *filename, *filesize_c, *profile, *from; + xmlnode *file, *feature, *x, *field, *option, *value; + const char *stream_id, *filename, *filesize_c, *profile; size_t filesize = 0; - if(!(si = xmlnode_get_child(packet, "si"))) - return; - if(!(profile = xmlnode_get_attrib(si, "profile")) || strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer")) return; @@ -1215,7 +1212,7 @@ if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data"))) return; - if(!(from = xmlnode_get_attrib(packet, "from"))) + if(!from) return; /* if they've already sent us this file transfer with the same damn id @@ -1256,7 +1253,7 @@ jsx->js = js; jsx->stream_id = g_strdup(stream_id); - jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id")); + jsx->iq_id = g_strdup(id); xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE, from); if (xfer)
--- a/libpurple/protocols/jabber/si.h Thu Feb 05 04:23:14 2009 +0000 +++ b/libpurple/protocols/jabber/si.h Thu Feb 05 05:42:58 2009 +0000 @@ -27,7 +27,7 @@ #include "jabber.h" void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet); -void jabber_si_parse(JabberStream *js, xmlnode *packet); +void jabber_si_parse(JabberStream *js, xmlnode *si, const char *from, const char *id); PurpleXfer *jabber_si_new_xfer(PurpleConnection *gc, const char *who); void jabber_si_xfer_send(PurpleConnection *gc, const char *who, const char *file);