--- a/libpurple/protocols/bonjour/bonjour_ft.c Wed Nov 30 00:58:50 2011 +0000
+++ b/libpurple/protocols/bonjour/bonjour_ft.c Wed Nov 30 01:01:09 2011 +0000
@@ -426,77 +426,119 @@
type = xmlnode_get_attrib(packet, "type");
id = xmlnode_get_attrib(packet, "id");
- if(!strcmp(type, "set")) {
- gboolean parsed_receive = FALSE;
- si = xmlnode_get_child(packet, "si");
+ if(!strcmp(type, "set")) { + gboolean parsed_receive = FALSE; - purple_debug_info("bonjour", "si offer Message type - SET.\n");
- if (si && (profile = xmlnode_get_attrib(si, "profile"))
- && !strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer")) {
- const char *filename = NULL, *filesize_str = NULL;
+ si = xmlnode_get_child(packet, "si"); - const char *sid = xmlnode_get_attrib(si, "id");
- if ((file = xmlnode_get_child(si, "file"))) {
- filename = xmlnode_get_attrib(file, "name");
- if((filesize_str = xmlnode_get_attrib(file, "size")))
- filesize = atoi(filesize_str);
+ purple_debug_info("bonjour", "si offer Message type - SET.\n"); + if (si && (profile = xmlnode_get_attrib(si, "profile")) + && !strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer")) { + const char *filename = NULL, *filesize_str = NULL; - /* TODO: Make sure that it is advertising a bytestreams transfer */
+ const char *sid = xmlnode_get_attrib(si, "id");
- bonjour_xfer_receive(pc, id, sid, name, filesize, filename, XEP_BYTESTREAMS);
+ if ((file = xmlnode_get_child(si, "file"))) { + filename = xmlnode_get_attrib(file, "name"); + if((filesize_str = xmlnode_get_attrib(file, "size"))) + filesize = atoi(filesize_str);
- BonjourData *bd = purple_connection_get_protocol_data(pc);
+ /* TODO: Make sure that it is advertising a bytestreams transfer */ + bonjour_xfer_receive(pc, id, sid, name, filesize, filename, XEP_BYTESTREAMS); + BonjourData *bd = purple_connection_get_protocol_data(pc); - purple_debug_info("bonjour", "rejecting unrecognized si SET offer.\n");
- xep_ft_si_reject(bd, id, name, "403", "cancel");
- /*TODO: Send Cancel (501) */
- } else if(!strcmp(type, "result")) {
- purple_debug_info("bonjour", "si offer Message type - RESULT.\n");
+ purple_debug_info("bonjour", "rejecting unrecognized si SET offer.\n"); + xep_ft_si_reject(bd, id, name, "403", "cancel"); + /*TODO: Send Cancel (501) */ + } else if(!strcmp(type, "result")) { + purple_debug_info("bonjour", "si offer Message type - RESULT.\n"); + xfer = bonjour_si_xfer_find(bd, id, name); - xfer = bonjour_si_xfer_find(bd, id, name);
+ BonjourData *bd = purple_connection_get_protocol_data(pc); + purple_debug_info("bonjour", "xfer find fail.\n"); + xep_ft_si_reject(bd, id, name, "403", "cancel"); + bonjour_bytestreams_init(xfer); + } else if(!strcmp(type, "error")) { + purple_debug_info("bonjour", "si offer Message type - ERROR.\n"); + xfer = bonjour_si_xfer_find(bd, id, name);
- BonjourData *bd = purple_connection_get_protocol_data(pc);
- purple_debug_info("bonjour", "xfer find fail.\n");
- xep_ft_si_reject(bd, id, name, "403", "cancel");
- bonjour_bytestreams_init(xfer);
+ purple_debug_info("bonjour", "xfer find fail.\n"); + purple_xfer_cancel_remote(xfer); + purple_debug_info("bonjour", "si offer Message type - Unknown-%s.\n", type); - } else if(!strcmp(type, "error")) {
- purple_debug_info("bonjour", "si offer Message type - ERROR.\n");
+__xep_bytestreams_parse(PurpleBuddy *pb, PurpleXfer *xfer, xmlnode *query, + const char *jid, *host, *port; + xf = (XepXfer*)xfer->data; + for(streamhost = xmlnode_get_child(query, "streamhost"); + streamhost = xmlnode_get_next_twin(streamhost)) { - xfer = bonjour_si_xfer_find(bd, id, name);
+ if(!(jid = xmlnode_get_attrib(streamhost, "jid")) || + !(host = xmlnode_get_attrib(streamhost, "host")) || + !(port = xmlnode_get_attrib(streamhost, "port")) || + !(portnum = atoi(port))) { + purple_debug_info("bonjour", "bytestream offer Message parse error.\n"); + if(strcmp(host, xf->buddy_ip))
- purple_debug_info("bonjour", "xfer find fail.\n");
- purple_xfer_cancel_remote(xfer);
- purple_debug_info("bonjour", "si offer Message type - Unknown-%s.\n", type);
+ xf->iq_id = g_strdup(iq_id); + xf->jid = g_strdup(jid); + xf->proxy_host = g_strdup(host); + xf->proxy_port = portnum; + purple_debug_info("bonjour", "bytestream offer parse" + "jid=%s host=%s port=%d.\n", jid, host, portnum); + bonjour_bytestreams_connect(xfer, pb); xep_bytestreams_parse(PurpleConnection *pc, xmlnode *packet, PurpleBuddy *pb)
- const char *type, *from;
+ const char *type, *from, *iq_id, *sid; g_return_if_fail(pc != NULL);
g_return_if_fail(packet != NULL);
@@ -511,66 +553,27 @@
type = xmlnode_get_attrib(packet, "type");
from = purple_buddy_get_name(pb);
query = xmlnode_get_child(packet,"query");
- if(!strcmp(type, "set")) {
- const char *iq_id, *sid;
- gboolean found = FALSE;
- purple_debug_info("bonjour", "bytestream offer Message type - SET.\n");
- iq_id = xmlnode_get_attrib(packet, "id");
- sid = xmlnode_get_attrib(query, "sid");
- xfer = bonjour_si_xfer_find(bd, sid, from);
- const char *jid, *host, *port;
+ if(strcmp(type, "set")) { + purple_debug_info("bonjour", "bytestream offer Message type - Unknown-%s.\n", type); - xf = (XepXfer*)xfer->data;
- for(streamhost = xmlnode_get_child(query, "streamhost");
- streamhost = xmlnode_get_next_twin(streamhost)) {
- if((jid = xmlnode_get_attrib(streamhost, "jid")) &&
- (host = xmlnode_get_attrib(streamhost, "host")) &&
- (port = xmlnode_get_attrib(streamhost, "port")) &&
- (portnum = atoi(port))) {
+ purple_debug_info("bonjour", "bytestream offer Message type - SET.\n"); - if(!strcmp(host, xf->buddy_ip)) {
- xf->iq_id = g_strdup(iq_id);
- xf->jid = g_strdup(jid);
- xf->proxy_host = g_strdup(host);
- xf->proxy_port = portnum;
- purple_debug_info("bonjour", "bytestream offer parse"
- "jid=%s host=%s port=%d.\n", jid, host, portnum);
- bonjour_bytestreams_connect(xfer, pb);
- purple_debug_info("bonjour", "bytestream offer Message parse error.\n");
+ iq_id = xmlnode_get_attrib(packet, "id");
- purple_debug_error("bonjour", "Didn't find an acceptable streamhost.\n");
+ sid = xmlnode_get_attrib(query, "sid"); + xfer = bonjour_si_xfer_find(bd, sid, from); + if(xfer && __xep_bytestreams_parse(pb, xfer, query, iq_id)) - if (iq_id && xfer != NULL)
- xep_ft_si_reject(bd, iq_id, xfer->who, "404", "cancel");
+ purple_debug_error("bonjour", "Didn't find an acceptable streamhost.\n");
- purple_debug_info("bonjour", "bytestream offer Message type - Unknown-%s.\n", type);
+ if (iq_id && xfer != NULL) + xep_ft_si_reject(bd, iq_id, xfer->who, "404", "cancel");