cpw.malu.ft_thumbnails: 9265a75a: Added an "ephemeral" argument when creat...

malu at pidgin.im malu at pidgin.im
Mon Jun 29 16:50:29 EDT 2009


-----------------------------------------------------------------
Revision: 9265a75ad797e6127091cfce270271205dd9fee8
Ancestor: 6dccdae9e51472dd29ee57909dad288a622060fb
Author: malu at pidgin.im
Date: 2009-06-29T20:44:45
Branch: im.pidgin.cpw.malu.ft_thumbnails
URL: http://d.pidgin.im/viewmtn/revision/info/9265a75ad797e6127091cfce270271205dd9fee8

Modified files:
        libpurple/protocols/jabber/data.c
        libpurple/protocols/jabber/data.h
        libpurple/protocols/jabber/message.c

ChangeLog: 

Added an "ephemeral" argument when creating local data objects (given a CID).
This will cause them to be destroyed automatically when receiving a get request
To be use for short-lived "one time" data, such as file transfer thumbnails 

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/data.c	e7c80f39f38254ca96b48f50bcd871306c0aace4
+++ libpurple/protocols/jabber/data.c	4f90165b441ec31f31f80867b78dc8d920948081
@@ -31,7 +31,7 @@ jabber_data_create_from_data(gconstpoint
 
 JabberData *
 jabber_data_create_from_data(gconstpointer rawdata, gsize size, const char *type,
-	JabberStream *js)
+	gboolean ephemeral, JabberStream *js)
 {
 	JabberData *data = g_new0(JabberData, 1);
 	gchar *checksum = purple_util_get_image_checksum(rawdata, size);
@@ -43,6 +43,7 @@ jabber_data_create_from_data(gconstpoint
 	data->cid = g_strdup(cid);
 	data->type = g_strdup(type);
 	data->size = size;
+	data->ephemeral = ephemeral;
 
 	data->data = g_memdup(rawdata, size);
 
@@ -229,6 +230,12 @@ jabber_data_parse(JabberStream *js, cons
 		xmlnode_set_attrib(result->node, "id", id);
 		xmlnode_insert_child(result->node,
 							 jabber_data_get_xml_definition(data));
+		/* if the data object is temporary, destroy it and remove the references
+		 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/data.h	d84c3937f1cd59c08696199f5e7898f4e18c8d80
+++ libpurple/protocols/jabber/data.h	cf683b3c239120ce81c95668c20323030bc97b7c
@@ -29,11 +29,12 @@ typedef struct {
 	char *type;
 	gsize size;
 	gpointer data;
+	gboolean ephemeral;
 } JabberData;
 
 /* creates a JabberData instance from raw data */
 JabberData *jabber_data_create_from_data(gconstpointer data, gsize size,
-										 const char *type, JabberStream *js);
+	const char *type, gboolean ephemeral, JabberStream *js);
 
 /* create a JabberData instance from an XML "data" element (as defined by
   XEP 0231 */
============================================================
--- libpurple/protocols/jabber/message.c	3dad8a124eef4953da0be9f671d8f1dd464ead29
+++ libpurple/protocols/jabber/message.c	5c9dfbd53bf04e9b51a27d5baecd838463714e76
@@ -994,7 +994,7 @@ jabber_message_smileyfy_xhtml(JabberMess
 					JabberData *new_data =
 						jabber_data_create_from_data(purple_imgstore_get_data(image),
 							purple_imgstore_get_size(image),
-							jabber_message_get_mimetype_from_ext(ext), js);
+							jabber_message_get_mimetype_from_ext(ext), FALSE, js);
 					purple_debug_info("jabber",
 						"cache local smiley alt = %s, cid = %s\n",
 						shortcut, jabber_data_get_cid(new_data));


More information about the Commits mailing list