changeset 18880:f41db253c1af

Add a new public function msim_msg_free_element_data(), that frees element data (but the MsimMessageElement * still must be g_free()'d). Internally, msim_msg_free_element() is still used, as a callback to g_list_foreach() to free every element in an MsimMessage. Expose msim_msg_pack_element_data(), which returns the wire protocol representation of the given element. Similar to msim_msg_get_string(), except that msim_msg_pack_element_data() will be escaped, ready to be sent over the wire. msim_msg_get_string() will probably be used in most places instead, as it returns the string suitable for usage elsewhere. Both these functions will be used by an upcoming change in msim_postprocess_outgoing() in myspace.c.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 07 Aug 2007 02:50:34 +0000
parents e0cac5db762b
children 3ec39ff6b407
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h
diffstat 2 files changed, 30 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Tue Aug 07 02:11:15 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Tue Aug 07 02:50:34 2007 +0000
@@ -26,7 +26,6 @@
 static void msim_msg_free_element(gpointer data, gpointer user_data);
 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
-static gchar *msim_msg_pack_element_data(MsimMessageElement *elem);
 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
 static MsimMessage *msim_msg_new_v(va_list argp);
 
@@ -326,19 +325,17 @@
 	return new;
 }
 
-/** Free an individual message element. 
+/** Free the data of a message element.
  *
- * @param data MsimMessageElement * to free.
- * @param user_data Not used; required to match g_list_foreach() callback prototype.
+ * @param elem The MsimMessageElement *
+ *
+ * Note this only frees the element data; you may also want to free the
+ * element itself with g_free() (see msim_msg_free_element()).
  */
-static void 
-msim_msg_free_element(gpointer data, gpointer user_data)
+void
+msim_msg_free_element_data(MsimMessageElement *elem)
 {
-	MsimMessageElement *elem;
-
-	elem = (MsimMessageElement *)data;
-
-	switch (elem->type)
+    switch (elem->type)
 	{
 		case MSIM_TYPE_BOOLEAN:
 		case MSIM_TYPE_INTEGER:
@@ -366,9 +363,27 @@
 			break;
 
 		default:
-			purple_debug_info("msim", "msim_msg_free_element: not freeing unknown type %d\n", elem->type);
+			purple_debug_info("msim", "msim_msg_free_element_data: "
+                    "not freeing unknown type %d\n", elem->type);
 			break;
 	}
+}
+
+/** Free an individual message element.
+ *
+ * @param data MsimMessageElement * to free.
+ * @param user_data Not used; required to match g_list_foreach() callback prototype.
+ *
+ * Frees both the element data and the element itself.
+ */
+static void 
+msim_msg_free_element(gpointer data, gpointer user_data)
+{
+	MsimMessageElement *elem;
+
+	elem = (MsimMessageElement *)data;
+
+    msim_msg_free_element_data(elem);
 
 	g_free(elem);
 }
@@ -695,7 +710,7 @@
  * optimal for human consumption. For example, strings are escaped. Use 
  * msim_msg_get_string() if you want a string, which in some cases is same as this.
  */
-static gchar *
+gchar *
 msim_msg_pack_element_data(MsimMessageElement *elem)
 {
     g_return_val_if_fail(elem != NULL, NULL);
--- a/libpurple/protocols/myspace/message.h	Tue Aug 07 02:11:15 2007 +0000
+++ b/libpurple/protocols/myspace/message.h	Tue Aug 07 02:50:34 2007 +0000
@@ -51,10 +51,12 @@
 /* No sentinel attribute, because can leave off varargs if not_empty is FALSE. */
 
 MsimMessage *msim_msg_clone(MsimMessage *old);
+void msim_msg_free_element_data(MsimMessageElement *elem);
 void msim_msg_free(MsimMessage *msg);
 MsimMessage *msim_msg_append(MsimMessage *msg, const gchar *name, MsimMessageType type, gpointer data);
 MsimMessage *msim_msg_insert_before(MsimMessage *msg, const gchar *name_before, const gchar *name, MsimMessageType type, gpointer data);
 gchar *msim_msg_dump_to_str(MsimMessage *msg);
+gchar *msim_msg_pack_element_data(MsimMessageElement *elem);
 void msim_msg_dump(const char *fmt_string, MsimMessage *msg);
 gchar *msim_msg_pack(MsimMessage *msg);
 gchar *msim_msg_pack_dict(MsimMessage *msg);