changeset 17968:a2298513db8b

Move msim_escape() and msim_unescape() to message.c.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 22 Jul 2007 07:00:10 +0000
parents c9acdf96e74e
children 8983b8340fdc
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 4 files changed, 61 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Sun Jul 22 06:53:48 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Sun Jul 22 07:00:10 2007 +0000
@@ -22,6 +22,7 @@
 #include "myspace.h"
 #include "message.h"
 
+static gchar *msim_unescape_or_escape(gchar *msg, gboolean escape);
 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);
@@ -29,6 +30,62 @@
 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
 static MsimMessage *msim_msg_new_v(va_list argp);
 
+/* Replacement codes to be replaced with associated replacement text,
+ * used for protocol message escaping / unescaping. */
+static gchar* msim_replacement_code[] = { "/1", "/2", /* "/3", */ NULL };
+static gchar* msim_replacement_text[] = { "/", "\\", /* "|", */ NULL };
+
+/**
+ * Unescape or escape a protocol message.
+ *
+ * @param msg The message to be unescaped or escaped. WILL BE FREED.
+ * @param escape TRUE to escape, FALSE to unescape.
+ *
+ * @return The unescaped or escaped message. Caller must g_free().
+ */
+static gchar *
+msim_unescape_or_escape(gchar *msg, gboolean escape)
+{
+	gchar *tmp, *code, *text;
+	guint i;
+
+	/* Replace each code in msim_replacement_code with
+	 * corresponding entry in msim_replacement_text. */
+	for (i = 0; (code = msim_replacement_code[i])
+		   	&& (text = msim_replacement_text[i]); ++i)
+	{
+		if (escape)
+		{
+			tmp = str_replace(msg, text, code);
+		}
+		else
+		{
+			tmp = str_replace(msg, code, text);
+		}
+		g_free(msg);
+		msg = tmp;
+	}
+	
+	return msg;
+}
+
+/**
+ * Escape a protocol message.
+ *
+ * @return The escaped message. Caller must g_free().
+ */
+gchar *
+msim_escape(const gchar *msg)
+{
+	return msim_unescape_or_escape(g_strdup(msg), TRUE);
+}
+
+gchar *
+msim_unescape(const gchar *msg)
+{
+	return msim_unescape_or_escape(g_strdup(msg), FALSE);
+}
+
 /** Create a new MsimMessage. 
  * 
  * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow.
--- a/libpurple/protocols/myspace/message.h	Sun Jul 22 06:53:48 2007 +0000
+++ b/libpurple/protocols/myspace/message.h	Sun Jul 22 07:00:10 2007 +0000
@@ -44,6 +44,9 @@
 #define MSIM_TYPE_DICTIONARY	'd'
 #define MSIM_TYPE_LIST			'l'
 
+gchar *msim_escape(const gchar *msg);
+gchar *msim_unescape(const gchar *msg);
+
 MsimMessage *msim_msg_new(gboolean not_empty, ...);
 /* No sentinel attribute, because can leave off varargs if not_empty is FALSE. */
 
--- a/libpurple/protocols/myspace/myspace.c	Sun Jul 22 06:53:48 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sun Jul 22 07:00:10 2007 +0000
@@ -249,61 +249,7 @@
     return "myspace";
 }
 
-/* Replacement codes to be replaced with associated replacement text,
- * used for protocol message escaping / unescaping. */
-static gchar* msim_replacement_code[] = { "/1", "/2", /* "/3", */ NULL };
-static gchar* msim_replacement_text[] = { "/", "\\", /* "|", */ NULL };
-
-/**
- * Unescape or escape a protocol message.
- *
- * @param msg The message to be unescaped or escaped. WILL BE FREED.
- * @param escape TRUE to escape, FALSE to unescape.
- *
- * @return The unescaped or escaped message. Caller must g_free().
- */
-gchar *
-msim_unescape_or_escape(gchar *msg, gboolean escape)
-{
-	gchar *tmp, *code, *text;
-	guint i;
-
-	/* Replace each code in msim_replacement_code with
-	 * corresponding entry in msim_replacement_text. */
-	for (i = 0; (code = msim_replacement_code[i])
-		   	&& (text = msim_replacement_text[i]); ++i)
-	{
-		if (escape)
-		{
-			tmp = str_replace(msg, text, code);
-		}
-		else
-		{
-			tmp = str_replace(msg, code, text);
-		}
-		g_free(msg);
-		msg = tmp;
-	}
-	
-	return msg;
-}
-
-/**
- * Escape a protocol message.
- *
- * @return The escaped message. Caller must g_free().
- */
-gchar *
-msim_escape(const gchar *msg)
-{
-	return msim_unescape_or_escape(g_strdup(msg), TRUE);
-}
-
-gchar *
-msim_unescape(const gchar *msg)
-{
-	return msim_unescape_or_escape(g_strdup(msg), FALSE);
-}
+
 
 /**
  * Replace 'old' with 'new' in 'str'.
--- a/libpurple/protocols/myspace/myspace.h	Sun Jul 22 06:53:48 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Sun Jul 22 07:00:10 2007 +0000
@@ -214,10 +214,6 @@
 
 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy);
 
-/* TODO: move these three functions to message.c/h */
-gchar *msim_unescape_or_escape(gchar *msg, gboolean escape);
-gchar *msim_unescape(const gchar *msg);
-gchar *msim_escape(const gchar *msg);
 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new);
 
 void print_hash_item(gpointer key, gpointer value, gpointer user_data);