comparison libpurple/protocols/myspace/message.c @ 18891:7db556e97dd1

Make msim_escape_or_unescape() take a const gchar *, and duplicate it itself so that it is not freed. Makes code clearer.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 11 Aug 2007 04:38:52 +0000
parents 00499df91ffe
children f732d072b118
comparison
equal deleted inserted replaced
18890:00499df91ffe 18891:7db556e97dd1
20 */ 20 */
21 21
22 #include "myspace.h" 22 #include "myspace.h"
23 #include "message.h" 23 #include "message.h"
24 24
25 static gchar *msim_unescape_or_escape(gchar *msg, gboolean escape); 25 static gchar *msim_unescape_or_escape(const gchar *msg, gboolean escape);
26 static void msim_msg_free_element(gpointer data, gpointer user_data); 26 static void msim_msg_free_element(gpointer data, gpointer user_data);
27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data); 27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end); 28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name); 29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
30 static MsimMessage *msim_msg_new_v(va_list argp); 30 static MsimMessage *msim_msg_new_v(va_list argp);
42 }; 42 };
43 43
44 /** 44 /**
45 * Unescape or escape a protocol message. 45 * Unescape or escape a protocol message.
46 * 46 *
47 * @param msg The message to be unescaped or escaped. WILL BE FREED. 47 * @param msg The message to be unescaped or escaped.
48 * @param escape TRUE to escape, FALSE to unescape. 48 * @param escape TRUE to escape, FALSE to unescape.
49 * 49 *
50 * @return The unescaped or escaped message. Caller must g_free(). 50 * @return The unescaped or escaped message. Caller must g_free().
51 */ 51 */
52 static gchar * 52 static gchar *
53 msim_unescape_or_escape(gchar *msg, gboolean escape) 53 msim_unescape_or_escape(const gchar *original_msg, gboolean escape)
54 { 54 {
55 gchar *tmp; 55 gchar *tmp, *msg;
56 guint i; 56 guint i;
57 struct MSIM_ESCAPE_REPLACEMENT* replacement; 57 struct MSIM_ESCAPE_REPLACEMENT* replacement;
58
59 /* Freed in loop below. */
60 msg = g_strdup(original_msg);
58 61
59 /* Replace each code in msim_replacement_code with 62 /* Replace each code in msim_replacement_code with
60 * corresponding entry in msim_replacement_text. */ 63 * corresponding entry in msim_replacement_text. */
61 for (i = 0; (replacement = &msim_escape_replacements[i]); ++i) { 64 for (i = 0; (replacement = &msim_escape_replacements[i]); ++i) {
62 gchar *code, *text; 65 gchar *code, *text;
85 * @return The escaped message. Caller must g_free(). 88 * @return The escaped message. Caller must g_free().
86 */ 89 */
87 gchar * 90 gchar *
88 msim_escape(const gchar *msg) 91 msim_escape(const gchar *msg)
89 { 92 {
90 return msim_unescape_or_escape(g_strdup(msg), TRUE); 93 return msim_unescape_or_escape(msg, TRUE);
91 } 94 }
92 95
93 gchar * 96 gchar *
94 msim_unescape(const gchar *msg) 97 msim_unescape(const gchar *msg)
95 { 98 {
96 return msim_unescape_or_escape(g_strdup(msg), FALSE); 99 return msim_unescape_or_escape(msg, FALSE);
97 } 100 }
98 101
99 /** Create a new MsimMessage. 102 /** Create a new MsimMessage.
100 * 103 *
101 * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow. 104 * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow.