cpw.malu.ft_thumbnails: 813e3f95: Actually request the thumbnail when gett...

malu at pidgin.im malu at pidgin.im
Wed Jul 1 13:35:40 EDT 2009


-----------------------------------------------------------------
Revision: 813e3f95cc04f7df9bad88849580ca989721fca4
Ancestor: 8fadf2c4c313e276d7c4eea64a921d82ef9a2bba
Author: malu at pidgin.im
Date: 2009-07-01T17:31:47
Branch: im.pidgin.cpw.malu.ft_thumbnails
URL: http://d.pidgin.im/viewmtn/revision/info/813e3f95cc04f7df9bad88849580ca989721fca4

Modified files:
        libpurple/protocols/jabber/data.c
        libpurple/protocols/jabber/si.c

ChangeLog: 

Actually request the thumbnail when getting one in an offer.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/data.c	4f90165b441ec31f31f80867b78dc8d920948081
+++ libpurple/protocols/jabber/data.c	b0a9e61be9406a77ca353bca262cd614d517c0c9
@@ -234,7 +234,6 @@ jabber_data_parse(JabberStream *js, cons
 		 to it */
 		if (data->ephemeral) {
 			g_hash_table_remove(local_data_by_cid, cid);
-			jabber_data_destroy(data);
 		}
 	}
 	jabber_iq_send(result);
============================================================
--- libpurple/protocols/jabber/si.c	7e6534f12d83607239600ac3da36d5cbe5479819
+++ libpurple/protocols/jabber/si.c	87fa345e213e1f7bd28d8fe7e84bce6414873817
@@ -1623,12 +1623,37 @@ void jabber_si_xfer_send(PurpleConnectio
 		purple_xfer_request(xfer);
 }
 
+static void
+jabber_si_thumbnail_cb(JabberStream *js, const char *from, JabberIqType type, 
+	const char *id, xmlnode *packet, gpointer data)
+{
+	PurpleXfer *xfer = (PurpleXfer *) data;
+	xmlnode *data_element = xmlnode_get_child(packet, "data");
+	xmlnode *item_not_found = xmlnode_get_child(packet, "item-not-found");
+
+	if (data_element) {
+		JabberData *data = jabber_data_create_from_xml(data_element);
+
+		if (data) {
+			purple_xfer_set_thumbnail(xfer, jabber_data_get_data(data),
+				jabber_data_get_size(data));
+			jabber_data_destroy(data);
+		}
+	} else if (item_not_found) {
+		purple_debug_info("jabber",
+			"Responder didn't recognize requested data\n");
+	} else {
+		purple_debug_error("jabber", "Unknown response to data request\n");
+	}
+	purple_xfer_request(xfer);
+}
+
 void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type,
                      const char *id, xmlnode *si)
 {
 	JabberSIXfer *jsx;
 	PurpleXfer *xfer;
-	xmlnode *file, *feature, *x, *field, *option, *value;
+	xmlnode *file, *feature, *x, *field, *option, *value, *thumbnail;
 	const char *stream_id, *filename, *filesize_c, *profile;
 	size_t filesize = 0;
 
@@ -1710,10 +1735,29 @@ void jabber_si_parse(JabberStream *js, c
 	purple_xfer_set_request_denied_fnc(xfer, jabber_si_xfer_request_denied);
 	purple_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv);
 	purple_xfer_set_end_fnc(xfer, jabber_si_xfer_end);
+				   
+	js->file_transfers = g_list_append(js->file_transfers, xfer);
 
-	js->file_transfers = g_list_append(js->file_transfers, xfer);
+	/* if there is a thumbnail, we should request it... */
+	if ((thumbnail = xmlnode_get_child(file, "thumbnail"))) {
+		const char *cid = xmlnode_get_attrib(thumbnail, "cid");
+		if (cid) {
+			JabberIq *request = 
+				jabber_iq_new(jsx->js, JABBER_IQ_GET);
 
-	purple_xfer_request(xfer);
+			purple_debug_info("jabber", "got file thumbnail, request it\n");
+			xmlnode_insert_child(request->node, 
+				jabber_data_get_xml_request(cid));
+			xmlnode_set_attrib(request->node, "to", 
+				purple_xfer_get_remote_user(xfer));
+			jabber_iq_set_callback(request, jabber_si_thumbnail_cb, xfer);
+			jabber_iq_send(request);
+		} else {
+			purple_xfer_request(xfer);
+		}
+	} else {
+		purple_xfer_request(xfer);
+	}
 }
 
 void


More information about the Commits mailing list