changeset 30201:b6dda7d483a2

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
author Marcus Lundblad <ml@update.uu.se>
date Mon, 29 Jun 2009 20:44:45 +0000
parents 51bc0be83108
children 7d8b074feda2
files libpurple/protocols/jabber/data.c libpurple/protocols/jabber/data.h libpurple/protocols/jabber/message.c
diffstat 3 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c	Thu Jun 25 22:25:23 2009 +0000
+++ b/libpurple/protocols/jabber/data.c	Mon Jun 29 20:44:45 2009 +0000
@@ -31,7 +31,7 @@
 
 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 @@
 	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 @@
 		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);
 }
--- a/libpurple/protocols/jabber/data.h	Thu Jun 25 22:25:23 2009 +0000
+++ b/libpurple/protocols/jabber/data.h	Mon Jun 29 20:44:45 2009 +0000
@@ -29,11 +29,12 @@
 	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 */
--- a/libpurple/protocols/jabber/message.c	Thu Jun 25 22:25:23 2009 +0000
+++ b/libpurple/protocols/jabber/message.c	Mon Jun 29 20:44:45 2009 +0000
@@ -994,7 +994,7 @@
 					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));