cpw.malu.xmpp.jingle_ft: db7704ba: Move the thumbnail-handling stuff to xfe...
malu at pidgin.im
malu at pidgin.im
Mon May 31 17:05:45 EDT 2010
-----------------------------------------------------------------
Revision: db7704ba8c1d93c5a9056eb4d2bef771ede2351d
Ancestor: 57060e1fa703ca5de3a573631d511a0e317889d3
Author: malu at pidgin.im
Date: 2010-05-31T21:01:30
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/db7704ba8c1d93c5a9056eb4d2bef771ede2351d
Modified files:
libpurple/protocols/jabber/si.c
libpurple/protocols/jabber/xfer.c
libpurple/protocols/jabber/xfer.h
ChangeLog:
Move the thumbnail-handling stuff to xfer.c to prepare to integrate thumbnail
support for Jingle FTs as well
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/si.c 3944118f9aeb5efcdbb4375e626d7fb7cd046fcd
+++ libpurple/protocols/jabber/si.c 48d0679e2f34e8054eada9480d557ed7c613ba44
@@ -42,7 +42,7 @@
#include "xfer.h"
#define STREAMHOST_CONNECT_TIMEOUT 15
-#define ENABLE_FT_THUMBNAILS 0
+#define ENABLE_FT_THUMBNAILS 1
typedef struct _JabberSIXfer {
JabberStream *js;
@@ -953,13 +953,8 @@ static void jabber_si_xfer_send_request(
{
JabberSIXfer *jsx = xfer->data;
JabberIq *iq;
- xmlnode *si, *feature, *x, *field, *option, *value;
-#if ENABLE_FT_THUMBNAILS
- gconstpointer thumb;
- gsize thumb_size;
+ xmlnode *si, *feature, *x, *field, *option, *value, *file;
- purple_xfer_prepare_thumbnail(xfer, "jpeg,png");
-#endif
xfer->filename = g_path_get_basename(xfer->local_filename);
iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
@@ -971,23 +966,11 @@ static void jabber_si_xfer_send_request(
xmlnode_set_attrib(si, "profile",
"http://jabber.org/protocol/si/profile/file-transfer");
- xmlnode_insert_child(si, jabber_xfer_create_file_element(xfer));
+ file = jabber_xfer_create_file_element(xfer);
+ xmlnode_insert_child(si, file);
#if ENABLE_FT_THUMBNAILS
- /* add thumbnail, if appropriate */
- if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
- const gchar *mimetype = purple_xfer_get_thumbnail_mimetype(xfer);
- JabberData *thumbnail_data =
- jabber_data_create_from_data(thumb, thumb_size,
- mimetype, TRUE, jsx->js);
- xmlnode *thumbnail = xmlnode_new_child(file, "thumbnail");
- xmlnode_set_namespace(thumbnail, NS_THUMBS);
- xmlnode_set_attrib(thumbnail, "cid",
- jabber_data_get_cid(thumbnail_data));
- xmlnode_set_attrib(thumbnail, "mime-type", mimetype);
- /* cache data */
- jabber_data_associate_local(thumbnail_data, NULL);
- }
+ jabber_xfer_add_thumbnail(jsx->js, file, xfer);
#endif
feature = xmlnode_new_child(si, "feature");
@@ -1288,29 +1271,12 @@ void jabber_si_xfer_send(PurpleConnectio
purple_xfer_request(xfer);
}
-#if ENABLE_FT_THUMBNAILS
-static void
-jabber_si_thumbnail_cb(JabberData *data, gchar *alt, gpointer userdata)
-{
- PurpleXfer *xfer = (PurpleXfer *) userdata;
-
- if (data) {
- purple_xfer_set_thumbnail(xfer, jabber_data_get_data(data),
- jabber_data_get_size(data), jabber_data_get_type(data));
- /* data is ephemeral, get rid of now (the xfer re-owned the thumbnail */
- jabber_data_destroy(data);
- }
-
- purple_xfer_request(xfer);
-}
-#endif
-
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, *thumbnail;
+ xmlnode *file, *feature, *x, *field, *option, *value;
const char *stream_id, *profile;
if(!(profile = xmlnode_get_attrib(si, "profile")) ||
@@ -1385,22 +1351,9 @@ void jabber_si_parse(JabberStream *js, c
js->file_transfers = g_list_append(js->file_transfers, xfer);
#if ENABLE_FT_THUMBNAILS
- /* if there is a thumbnail, we should request it... */
- if ((thumbnail = xmlnode_get_child_with_namespace(file, "thumbnail",
- NS_THUMBS))) {
- const char *cid = xmlnode_get_attrib(thumbnail, "cid");
- if (cid) {
- jabber_data_request(js, cid, purple_xfer_get_remote_user(xfer),
- NULL, TRUE, jabber_si_thumbnail_cb, xfer);
- } else {
- purple_xfer_request(xfer);
- }
- } else {
+ jabber_xfer_request_thumbnail(js, file, xfer);
+#else
purple_xfer_request(xfer);
- }
-#else
- thumbnail = NULL; /* Silence warning */
- purple_xfer_request(xfer);
#endif
}
}
============================================================
--- libpurple/protocols/jabber/xfer.c 79f1d75483a326c5ceadb7e8cf0e0f723d30794e
+++ libpurple/protocols/jabber/xfer.c d5c71410896fc9c0a0fe6638c4f296c1ba485ee1
@@ -18,10 +18,13 @@
#include "debug.h"
#include "request.h"
#include "buddy.h"
+#include "data.h"
#include "jingle/jingle.h"
#include "jingle/file-transfer.h"
#include "si.h"
+#define ENABLE_FT_THUMBNAILS 1
+
static gboolean
jabber_xfer_support_jingle_ft(const PurpleConnection *gc, const gchar *who)
{
@@ -229,4 +232,62 @@ jabber_xfer_create_from_xml(PurpleAccoun
}
return xfer;
-}
\ No newline at end of file
+}
+
+static void
+jabber_xfer_thumbnail_cb(JabberData *data, gchar *alt, gpointer userdata)
+{
+ PurpleXfer *xfer = (PurpleXfer *) userdata;
+
+ if (data) {
+ purple_xfer_set_thumbnail(xfer, jabber_data_get_data(data),
+ jabber_data_get_size(data), jabber_data_get_type(data));
+ /* data is ephemeral, get rid of now (the xfer re-owned the thumbnail */
+ jabber_data_destroy(data);
+ }
+
+ purple_xfer_request(xfer);
+}
+
+void jabber_xfer_request_thumbnail(JabberStream *js, const xmlnode *file,
+ PurpleXfer *xfer)
+{
+ xmlnode *thumbnail = NULL;
+ /* if there is a thumbnail, we should request it... */
+ if ((thumbnail = xmlnode_get_child_with_namespace(file, "thumbnail",
+ NS_THUMBS))) {
+ const char *cid = xmlnode_get_attrib(thumbnail, "cid");
+ if (cid) {
+ jabber_data_request(js, cid, purple_xfer_get_remote_user(xfer),
+ NULL, TRUE, jabber_xfer_thumbnail_cb, xfer);
+ } else {
+ purple_xfer_request(xfer);
+ }
+ } else {
+ purple_xfer_request(xfer);
+ }
+}
+
+void jabber_xfer_add_thumbnail(JabberStream *js, const xmlnode *file,
+ PurpleXfer *xfer)
+{
+ gconstpointer thumb;
+ gsize thumb_size;
+
+ purple_xfer_prepare_thumbnail(xfer, "jpeg,png");
+
+ /* add thumbnail, if appropriate */
+ if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
+ const gchar *mimetype = purple_xfer_get_thumbnail_mimetype(xfer);
+ JabberData *thumbnail_data =
+ jabber_data_create_from_data(thumb, thumb_size,
+ mimetype, TRUE, js);
+ xmlnode *thumbnail = xmlnode_new_child(file, "thumbnail");
+ xmlnode_set_namespace(thumbnail, NS_THUMBS);
+ xmlnode_set_attrib(thumbnail, "cid",
+ jabber_data_get_cid(thumbnail_data));
+ xmlnode_set_attrib(thumbnail, "mime-type", mimetype);
+ /* cache data */
+ jabber_data_associate_local(thumbnail_data, NULL);
+ }
+}
============================================================
--- libpurple/protocols/jabber/xfer.h 67fe5eb82c447a3ec04505ea9fbda2465c58fec2
+++ libpurple/protocols/jabber/xfer.h 2961f368261beb490b0878a84ae87d2813b01675
@@ -21,13 +21,24 @@
#include "connection.h"
#include "ft.h"
-
+#include "xmlnode.h"
+
+#include "jabber.h"
+
PurpleXfer *jabber_xfer_new(PurpleConnection *gc, const char *who);
void jabber_xfer_send(PurpleConnection *gc, const char *who, const char *file);
xmlnode *jabber_xfer_create_file_element(const PurpleXfer *xfer);
PurpleXfer *jabber_xfer_create_from_xml(PurpleAccount *account, xmlnode *file,
const gchar *who, gpointer data);
-
+
+/* request thumbnail if present in offer, then calls purple_xfer_request
+ otherwise calls purple_xfer_request immediatly */
+void jabber_xfer_request_thumbnail(JabberStream *js, const xmlnode *file,
+ PurpleXfer *xfer);
+
+void jabber_xfer_add_thumbnail(JabberStream *js, const xmlnode *file,
+ PurpleXfer *xfer);
+
#endif /* JABBER_XFER_H */
More information about the Commits
mailing list