annotate libpurple/protocols/myspace/message.c @ 30248:9bd9ef37354f

Add sound-support for got-attention event.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 05 Jul 2010 16:57:47 +0000
parents df7705d4b19a
children 943fce8ef142
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1 /** MySpaceIM protocol messages
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
3 * \author Jeff Connelly
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
4 *
17680
d87916bd1d73 Fix email address.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17661
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
6 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
10 * (at your option) any later version.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
11 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
15 * GNU General Public License for more details.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
16 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19431
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
20 */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
21
27343
df7705d4b19a Including internal.h here fixed a Windows build ages ago but struck me as odd
Etan Reisner <pidgin@unreliablesource.net>
parents: 24805
diff changeset
22 #include "myspace.h"
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
23 #include "message.h"
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
24
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
25 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
26
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
27 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
28 * Escape codes and associated replacement text, used for protocol message
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
29 * escaping and unescaping.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
30 */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
31 static struct MSIM_ESCAPE_REPLACEMENT {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
32 gchar *code;
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
33 gchar text;
18889
a3a5b2e9079a Change escape code replacement text parallel arrays to an array of structs,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18882
diff changeset
34 } msim_escape_replacements[] = {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
35 { "/1", '/' },
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
36 { "/2", '\\' },
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
37 /* { "/3", "|" }, */ /* Not used here -- only for within arrays */
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
38 { NULL, 0 }
18889
a3a5b2e9079a Change escape code replacement text parallel arrays to an array of structs,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18882
diff changeset
39 };
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
40
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
41 /**
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
42 * Escape a protocol message.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
43 *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
44 * @return The escaped message. Caller must g_free().
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
45 */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
46 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
47 msim_escape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
48 {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
49 GString *gs;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
50 guint i, j;
22269
0e68dab2a362 Patch from oliver:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 20336
diff changeset
51 guint msg_len;
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
52
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
53 gs = g_string_new("");
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
54 msg_len = strlen(msg);
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
55
22269
0e68dab2a362 Patch from oliver:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 20336
diff changeset
56 for (i = 0; i < msg_len; ++i) {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
57 struct MSIM_ESCAPE_REPLACEMENT *replacement;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
58 gchar *replace;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
59
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
60 replace = NULL;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
61
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
62 /* Check for characters that need to be escaped, and escape them. */
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
63 for (j = 0; (replacement = &msim_escape_replacements[j]) &&
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
64 replacement->code != NULL; ++j) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
65 if (msg[i] == replacement->text) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
66 replace = replacement->code;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
67 break;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
68 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
69 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
70
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
71 if (replace) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
72 g_string_append(gs, replace);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
73 } else {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
74 g_string_append_c(gs, msg[i]);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
75 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
76 }
18911
692b128fe74a Conditionally-compile out debugging statements of escaping.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18909
diff changeset
77
692b128fe74a Conditionally-compile out debugging statements of escaping.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18909
diff changeset
78 #ifdef MSIM_DEBUG_ESCAPE
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
79 purple_debug_info("msim", "msim_escape: msg=%s, ret=%s\n", msg, gs->str);
18911
692b128fe74a Conditionally-compile out debugging statements of escaping.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18909
diff changeset
80 #endif
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
81
20243
5440eed4ec7e applied changes from efedefa70ee1d6f7f4dd39afe5db10c7e5bfe64c
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
82 return g_string_free(gs, FALSE);
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
83 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
84
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
85 /**
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
86 * Unescape a protocol message.
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
87 *
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
88 * @return The unescaped message, caller must g_free().
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
89 */
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
90 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
91 msim_unescape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
92 {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
93 GString *gs;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
94 guint i, j;
22269
0e68dab2a362 Patch from oliver:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 20336
diff changeset
95 guint msg_len;
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
96
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
97 gs = g_string_new("");
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
98 msg_len = strlen(msg);
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
99
22269
0e68dab2a362 Patch from oliver:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 20336
diff changeset
100 for (i = 0; i < msg_len; ++i) {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
101 struct MSIM_ESCAPE_REPLACEMENT *replacement;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
102 gchar replace;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
103
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
104 replace = msg[i];
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
105
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
106 for (j = 0; (replacement = &msim_escape_replacements[j]) &&
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
107 replacement->code != NULL; ++j) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
108 if (msg[i] == replacement->code[0] &&
22269
0e68dab2a362 Patch from oliver:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 20336
diff changeset
109 i + 1 < msg_len &&
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
110 msg[i + 1] == replacement->code[1]) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
111 replace = replacement->text;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
112 ++i;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
113 break;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
114 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
115 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
116
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
117 g_string_append_c(gs, replace);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
118 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
119
18911
692b128fe74a Conditionally-compile out debugging statements of escaping.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18909
diff changeset
120 #ifdef MSIM_DEBUG_ESCAPE
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
121 purple_debug_info("msim", "msim_unescape: msg=%s, ret=%s\n", msg, gs->str);
18911
692b128fe74a Conditionally-compile out debugging statements of escaping.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18909
diff changeset
122 #endif
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
123
20243
5440eed4ec7e applied changes from efedefa70ee1d6f7f4dd39afe5db10c7e5bfe64c
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
124 return g_string_free(gs, FALSE);
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
125 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
126
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
127 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
128 * Create a new message from va_list and its first argument.
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
129 *
18897
d0be4366e876 Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18895
diff changeset
130 * @param first_key The first argument (a key), or NULL to take all arguments
d0be4366e876 Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18895
diff changeset
131 * from argp.
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
132 * @param argp A va_list of variadic arguments, already started with va_start(). Will be va_end()'d.
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
133 * @return New MsimMessage *, must be freed with msim_msg_free().
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
134 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
135 * For internal use - users probably want msim_msg_new() or msim_send().
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
136 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
137 static MsimMessage *
18897
d0be4366e876 Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18895
diff changeset
138 msim_msg_new_v(gchar *first_key, va_list argp)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
139 {
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
140 gchar *key, *value;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
141 MsimMessageType type;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
142 MsimMessage *msg;
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
143 gboolean first;
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
144
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
145 GString *gs;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
146 GList *gl;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
147 MsimMessage *dict;
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
148
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
149 /* Begin with an empty message. */
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
150 msg = NULL;
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
151
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
152 /* First parameter can be given explicitly. */
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
153 first = first_key != NULL;
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
154
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
155 /* Read key, type, value triplets until NULL. */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
156 do {
19252
cfbd89a98431 Remove msim_parse_body(), obsoleted by msim_msg_get_dictionary().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19248
diff changeset
157 if (first) {
18905
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
158 key = first_key;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
159 first = FALSE;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
160 } else {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
161 key = va_arg(argp, gchar *);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
162 if (!key) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
163 break;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
164 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
165 }
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
166
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
167 type = va_arg(argp, int);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
168
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
169 /* Interpret variadic arguments. */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
170 switch (type) {
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
171 case MSIM_TYPE_INTEGER:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
172 case MSIM_TYPE_BOOLEAN:
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
173 msg = msim_msg_append(msg, key, type, GUINT_TO_POINTER(va_arg(argp, int)));
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
174 break;
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
175
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
176 case MSIM_TYPE_STRING:
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
177 value = va_arg(argp, char *);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
178
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
179 g_return_val_if_fail(value != NULL, FALSE);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
180
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
181 msg = msim_msg_append(msg, key, type, value);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
182 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
183
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
184 case MSIM_TYPE_BINARY:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
185 gs = va_arg(argp, GString *);
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
186
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
187 g_return_val_if_fail(gs != NULL, FALSE);
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
188
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
189 /* msim_msg_free() will free this GString the caller created. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
190 msg = msim_msg_append(msg, key, type, gs);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
191 break;
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
192
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
193 case MSIM_TYPE_LIST:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
194 gl = va_arg(argp, GList *);
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
195
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
196 g_return_val_if_fail(gl != NULL, FALSE);
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
197
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
198 msg = msim_msg_append(msg, key, type, gl);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
199 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
200
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
201 case MSIM_TYPE_DICTIONARY:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
202 dict = va_arg(argp, MsimMessage *);
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
203
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
204 g_return_val_if_fail(dict != NULL, FALSE);
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
205
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
206 msg = msim_msg_append(msg, key, type, dict);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
207 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
208
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
209 default:
17694
231b87b76da4 In debug messages, don't output unknown elem->type fields as %c too (only as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17692
diff changeset
210 purple_debug_info("msim", "msim_send: unknown type %d\n", type);
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
211 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
212 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
213 } while(key);
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
214 va_end(argp);
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
215
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
216 return msg;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
217 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
218
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
219 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
220 * Create a new MsimMessage.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
221 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
222 * @param first_key The first key in the sequence, or NULL for an empty message.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
223 * @param ... A sequence of gchar* key/type/value triplets, terminated with NULL.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
224 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
225 * See msim_msg_append() documentation for details on types.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
226 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
227 MsimMessage *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
228 msim_msg_new(gchar *first_key, ...)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
229 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
230 va_list argp;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
231
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
232 if (first_key) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
233 va_start(argp, first_key);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
234 return msim_msg_new_v(first_key, argp);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
235 } else {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
236 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
237 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
238 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
239
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
240 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
241 * Pack a string using the given GFunc and seperator.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
242 * Used by msim_msg_dump() and msim_msg_pack().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
243 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
244 static gchar *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
245 msim_msg_pack_using(MsimMessage *msg,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
246 GFunc gf,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
247 const gchar *sep,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
248 const gchar *begin, const gchar *end)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
249 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
250 int num_items;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
251 gchar **strings;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
252 gchar **strings_tmp;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
253 gchar *joined;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
254 gchar *final;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
255 int i;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
256
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
257 g_return_val_if_fail(msg != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
258
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
259 num_items = g_list_length(msg);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
260
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
261 /* Add one for NULL terminator for g_strjoinv(). */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
262 strings = (gchar **)g_new0(gchar *, num_items + 1);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
263
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
264 strings_tmp = strings;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
265 g_list_foreach(msg, gf, &strings_tmp);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
266
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
267 joined = g_strjoinv(sep, strings);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
268 final = g_strconcat(begin, joined, end, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
269 g_free(joined);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
270
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
271 /* Clean up. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
272 for (i = 0; i < num_items; ++i) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
273 g_free(strings[i]);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
274 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
275
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
276 g_free(strings);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
277
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
278 return final;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
279 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
280
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
281 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
282 * Return a human-readable string of the message.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
283 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
284 * @return A new gchar *, must be g_free()'d.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
285 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
286 static gchar *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
287 msim_msg_dump_to_str(MsimMessage *msg)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
288 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
289 gchar *debug_str;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
290
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
291 if (!msg) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
292 debug_str = g_strdup("<MsimMessage: empty>");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
293 } else {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
294 debug_str = msim_msg_pack_using(msg, msim_msg_debug_string_element,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
295 "\n", "<MsimMessage: \n", "\n/MsimMessage>");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
296 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
297
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
298 return debug_str;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
299 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
300
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
301 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
302 * Store a human-readable string describing the element.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
303 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
304 * @param data Pointer to an MsimMessageElement.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
305 * @param user_data
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
306 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
307 static void
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
308 msim_msg_debug_string_element(gpointer data, gpointer user_data)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
309 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
310 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
311 gchar *string;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
312 GString *gs;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
313 gchar *binary;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
314 gchar ***items; /* wow, a pointer to a pointer to a pointer */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
315
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
316 gchar *s;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
317 GList *gl;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
318 guint i;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
319
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
320 elem = (MsimMessageElement *)data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
321 items = user_data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
322
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
323 switch (elem->type) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
324 case MSIM_TYPE_INTEGER:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
325 string = g_strdup_printf("%s(integer): %d", elem->name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
326 GPOINTER_TO_UINT(elem->data));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
327 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
328
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
329 case MSIM_TYPE_RAW:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
330 string = g_strdup_printf("%s(raw): %s", elem->name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
331 elem->data ? (gchar *)elem->data : "(NULL)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
332 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
333
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
334 case MSIM_TYPE_STRING:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
335 string = g_strdup_printf("%s(string): %s", elem->name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
336 elem->data ? (gchar *)elem->data : "(NULL)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
337 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
338
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
339 case MSIM_TYPE_BINARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
340 gs = (GString *)elem->data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
341 binary = purple_base64_encode((guchar*)gs->str, gs->len);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
342 string = g_strdup_printf("%s(binary, %d bytes): %s", elem->name, (int)gs->len, binary);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
343 g_free(binary);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
344 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
345
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
346 case MSIM_TYPE_BOOLEAN:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
347 string = g_strdup_printf("%s(boolean): %s", elem->name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
348 elem->data ? "TRUE" : "FALSE");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
349 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
350
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
351 case MSIM_TYPE_DICTIONARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
352 if (!elem->data) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
353 s = g_strdup("(NULL)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
354 } else {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
355 s = msim_msg_dump_to_str((MsimMessage *)elem->data);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
356 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
357
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
358 if (!s) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
359 s = g_strdup("(NULL, couldn't msim_msg_dump_to_str)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
360 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
361
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
362 string = g_strdup_printf("%s(dict): %s", elem->name, s);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
363
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
364 g_free(s);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
365 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
366
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
367 case MSIM_TYPE_LIST:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
368 gs = g_string_new("");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
369 g_string_append_printf(gs, "%s(list): \n", elem->name);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
370
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
371 i = 0;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
372 for (gl = (GList *)elem->data; gl != NULL; gl = g_list_next(gl)) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
373 g_string_append_printf(gs, " %d. %s\n", i, (gchar *)(gl->data));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
374 ++i;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
375 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
376
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
377 string = g_string_free(gs, FALSE);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
378 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
379
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
380 default:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
381 string = g_strdup_printf("%s(unknown type %d",
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
382 elem->name ? elem->name : "(NULL)", elem->type);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
383 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
384 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
385
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
386 **items = string;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
387 ++(*items);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
388 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
389
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
390 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
391 * Search for and return the node in msg, matching name, or NULL.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
392 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
393 * @param msg Message to search within.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
394 * @param name Field name to search for.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
395 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
396 * @return The GList * node for the MsimMessageElement with the given name, or NULL if not found or name is NULL.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
397 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
398 * For internal use - users probably want to use msim_msg_get() to
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
399 * access the MsimMessageElement *, instead of the GList * container.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
400 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
401 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
402 static GList *
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
403 msim_msg_get_node(const MsimMessage *msg, const gchar *name)
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
404 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
405 GList *node;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
406
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
407 if (!name || !msg) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
408 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
409 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
410
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
411 /* Linear search for the given name. O(n) but n is small. */
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
412 for (node = (GList*)msg; node != NULL; node = g_list_next(node)) {
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
413 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
414
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
415 elem = (MsimMessageElement *)node->data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
416
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
417 g_return_val_if_fail(elem != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
418 g_return_val_if_fail(elem->name != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
419
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
420 if (strcmp(elem->name, name) == 0) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
421 return node;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
422 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
423 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
424 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
425 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
426
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
427 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
428 * Create a new MsimMessageElement * - must be g_free()'d.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
429 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
430 * For internal use; users probably want msim_msg_append() or msim_msg_insert_before().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
431 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
432 * @param dynamic_name Whether 'name' should be freed when the message is destroyed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
433 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
434 static MsimMessageElement *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
435 msim_msg_element_new(const gchar *name, MsimMessageType type, gpointer data, gboolean dynamic_name)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
436 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
437 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
438
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
439 elem = g_new0(MsimMessageElement, 1);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
440
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
441 elem->name = name;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
442 elem->dynamic_name = dynamic_name;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
443 elem->type = type;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
444 elem->data = data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
445
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
446 return elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
447 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
448
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
449 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
450 * Append a new element to a message.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
451 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
452 * @param name Textual name of element (static string, neither copied nor freed).
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
453 * @param type An MSIM_TYPE_* code.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
454 * @param data Pointer to data, see below.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
455 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
456 * @return The new message - must be assigned to as with GList*. For example:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
457 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
458 * msg = msim_msg_append(msg, ...)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
459 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
460 * The data parameter depends on the type given:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
461 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
462 * * MSIM_TYPE_INTEGER: Use GUINT_TO_POINTER(x).
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
463 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
464 * * MSIM_TYPE_BINARY: Same as integer, non-zero is TRUE and zero is FALSE.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
465 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
466 * * MSIM_TYPE_STRING: gchar *. The data WILL BE FREED - use g_strdup() if needed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
467 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
468 * * MSIM_TYPE_RAW: gchar *. The data WILL BE FREED - use g_strdup() if needed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
469 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
470 * * MSIM_TYPE_BINARY: g_string_new_len(data, length). The data AND GString will be freed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
471 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
472 * * MSIM_TYPE_DICTIONARY: An MsimMessage *. Freed when message is destroyed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
473 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
474 * * MSIM_TYPE_LIST: GList * of gchar *. Again, everything will be freed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
475 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
476 * */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
477 MsimMessage *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
478 msim_msg_append(MsimMessage *msg, const gchar *name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
479 MsimMessageType type, gpointer data)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
480 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
481 return g_list_append(msg, msim_msg_element_new(name, type, data, FALSE));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
482 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
483
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
484 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
485 * Append a new element, but with a dynamically-allocated name.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
486 * Exactly the same as msim_msg_append(), except 'name' will be freed when
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
487 * the message is destroyed. Normally, it isn't, because a static string is given.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
488 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
489 static MsimMessage *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
490 msim_msg_append_dynamic_name(MsimMessage *msg, gchar *name,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
491 MsimMessageType type, gpointer data)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
492 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
493 return g_list_append(msg, msim_msg_element_new(name, type, data, TRUE));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
494 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
495
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
496 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
497 * Insert a new element into a message, before the given element name.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
498 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
499 * @param name_before Name of the element to insert the new element before. If
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
500 * could not be found or NULL, new element will be inserted at end.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
501 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
502 * See msim_msg_append() for usage of other parameters, and an important note about return value.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
503 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
504 MsimMessage *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
505 msim_msg_insert_before(MsimMessage *msg, const gchar *name_before,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
506 const gchar *name, MsimMessageType type, gpointer data)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
507 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
508 MsimMessageElement *new_elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
509 GList *node_before;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
510
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
511 new_elem = msim_msg_element_new(name, type, data, FALSE);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
512
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
513 node_before = msim_msg_get_node(msg, name_before);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
514
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
515 return g_list_insert_before(msg, node_before, new_elem);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
516 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
517
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
518 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
519 * Perform a deep copy on a GList * of gchar * strings. Free with msim_msg_list_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
520 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
521 static GList *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
522 msim_msg_list_copy(const GList *old)
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
523 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
524 GList *new_list;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
525
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
526 new_list = NULL;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
527
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
528 /* Deep copy (g_list_copy is shallow). Copy each string. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
529 for (; old != NULL; old = g_list_next(old)) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
530 new_list = g_list_append(new_list, g_strdup(old->data));
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
531 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
532
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
533 return new_list;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
534 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
535
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
536 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
537 * Clone an individual element.
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
538 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
539 * @param data MsimMessageElement * to clone.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
540 * @param user_data Pointer to MsimMessage * to add cloned element to.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
541 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
542 static void
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
543 msim_msg_clone_element(gpointer data, gpointer user_data)
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
544 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
545 MsimMessageElement *elem;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
546 MsimMessage **new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
547 gpointer new_data;
20336
b93e7be3847b applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents: 20243
diff changeset
548
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
549 GString *gs;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
550 MsimMessage *dict;
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
551
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
552 elem = (MsimMessageElement *)data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
553 new = (MsimMessage **)user_data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
554
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
555 switch (elem->type) {
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
556 case MSIM_TYPE_BOOLEAN:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
557 case MSIM_TYPE_INTEGER:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
558 new_data = elem->data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
559 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
560
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
561 case MSIM_TYPE_RAW:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
562 case MSIM_TYPE_STRING:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
563 new_data = g_strdup((gchar *)elem->data);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
564 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
565
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
566 case MSIM_TYPE_LIST:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
567 new_data = (gpointer)msim_msg_list_copy((GList *)(elem->data));
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
568 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
569
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
570 case MSIM_TYPE_BINARY:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
571 gs = (GString *)elem->data;
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
572
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
573 new_data = g_string_new_len(gs->str, gs->len);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
574 break;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
575 case MSIM_TYPE_DICTIONARY:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
576 dict = (MsimMessage *)elem->data;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
577
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
578 new_data = msim_msg_clone(dict);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
579 break;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
580
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
581 default:
17694
231b87b76da4 In debug messages, don't output unknown elem->type fields as %c too (only as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17692
diff changeset
582 purple_debug_info("msim", "msim_msg_clone_element: unknown type %d\n", elem->type);
20336
b93e7be3847b applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents: 20243
diff changeset
583 g_return_if_reached();
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
584 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
585
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
586 /* Append cloned data. Note that the 'name' field is a static string, so it
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
587 * never needs to be copied nor freed. */
24745
0e8d91cdd63a Change the msim_msg_clone_element() function to respect the "dynamic_name"
Mark Doliner <mark@kingant.net>
parents: 24552
diff changeset
588 if (elem->dynamic_name)
0e8d91cdd63a Change the msim_msg_clone_element() function to respect the "dynamic_name"
Mark Doliner <mark@kingant.net>
parents: 24552
diff changeset
589 *new = msim_msg_append_dynamic_name(*new, g_strdup(elem->name), elem->type, new_data);
0e8d91cdd63a Change the msim_msg_clone_element() function to respect the "dynamic_name"
Mark Doliner <mark@kingant.net>
parents: 24552
diff changeset
590 else
0e8d91cdd63a Change the msim_msg_clone_element() function to respect the "dynamic_name"
Mark Doliner <mark@kingant.net>
parents: 24552
diff changeset
591 *new = msim_msg_append(*new, elem->name, elem->type, new_data);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
592 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
593
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
594 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
595 * Clone an existing MsimMessage.
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
596 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
597 * @return Cloned message; caller should free with msim_msg_free().
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
598 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
599 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
600 msim_msg_clone(MsimMessage *old)
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
601 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
602 MsimMessage *new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
603
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
604 if (old == NULL) {
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
605 return NULL;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
606 }
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
607
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
608 new = msim_msg_new(FALSE);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
609
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
610 g_list_foreach(old, msim_msg_clone_element, &new);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
611
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
612 return new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
613 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
614
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
615 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
616 * Free the data of a message element.
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
617 *
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
618 * @param elem The MsimMessageElement *
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
619 *
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
620 * Note this only frees the element data; you may also want to free the
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
621 * element itself with g_free() (see msim_msg_free_element()).
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
622 */
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
623 void
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
624 msim_msg_free_element_data(MsimMessageElement *elem)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
625 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
626 switch (elem->type) {
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
627 case MSIM_TYPE_BOOLEAN:
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
628 case MSIM_TYPE_INTEGER:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
629 /* Integer value stored in gpointer - no need to free(). */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
630 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
631
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
632 case MSIM_TYPE_RAW:
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
633 case MSIM_TYPE_STRING:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
634 /* Always free strings - caller should have g_strdup()'d if
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
635 * string was static or temporary and not to be freed. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
636 g_free(elem->data);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
637 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
638
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
639 case MSIM_TYPE_BINARY:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
640 /* Free the GString itself and the binary data. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
641 g_string_free((GString *)elem->data, TRUE);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
642 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
643
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
644 case MSIM_TYPE_DICTIONARY:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
645 msim_msg_free((MsimMessage *)elem->data);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
646 break;
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
647
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
648 case MSIM_TYPE_LIST:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
649 g_list_free((GList *)elem->data);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
650 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
651
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
652 default:
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
653 purple_debug_info("msim", "msim_msg_free_element_data: "
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
654 "not freeing unknown type %d\n", elem->type);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
655 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
656 }
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
657 }
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
658
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
659 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
660 * Free a GList * of MsimMessageElement *'s.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
661 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
662 void
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
663 msim_msg_list_free(GList *l)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
664 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
665
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
666 for (; l != NULL; l = g_list_next(l)) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
667 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
668
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
669 elem = (MsimMessageElement *)l->data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
670
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
671 /* Note that name is almost never dynamically allocated elsewhere;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
672 * it is usually a static string, but not in lists. So cast it. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
673 g_free((gchar *)elem->name);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
674 g_free(elem->data);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
675 g_free(elem);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
676 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
677 g_list_free(l);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
678 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
679
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
680 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
681 * Free an individual message element.
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
682 *
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
683 * @param data MsimMessageElement * to free.
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
684 * @param user_data Not used; required to match g_list_foreach() callback prototype.
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
685 *
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
686 * Frees both the element data and the element itself.
22334
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
687 * Also frees the name if dynamic_name is TRUE.
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
688 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
689 static void
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
690 msim_msg_free_element(gpointer data, gpointer user_data)
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
691 {
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
692 MsimMessageElement *elem;
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
693
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
694 elem = (MsimMessageElement *)data;
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.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18879
diff changeset
695
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
696 msim_msg_free_element_data(elem);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
697
22334
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
698 if (elem->dynamic_name)
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
699 /* Need to cast to remove const-ness, because
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
700 * elem->name is almost always a constant, static
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
701 * string, but not in this case. */
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
702 g_free((gchar *)elem->name);
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
703
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
704 g_free(elem);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
705 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
706
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
707 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
708 * Free a complete message.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
709 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
710 void
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
711 msim_msg_free(MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
712 {
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
713 if (!msg) {
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
714 /* already free as can be */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
715 return;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
716 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
717
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
718 g_list_foreach(msg, msim_msg_free_element, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
719 g_list_free(msg);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
720 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
721
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
722 /**
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
723 * Pack an element into its protocol representation.
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
724 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
725 * @param data Pointer to an MsimMessageElement.
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
726 * @param user_data Pointer to a gchar ** array of string items.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
727 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
728 * Called by msim_msg_pack(). Will pack the MsimMessageElement into
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
729 * a part of the protocol string and append it to the array. Caller
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
730 * is responsible for creating array to correct dimensions, and
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
731 * freeing each string element of the array added by this function.
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
732 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
733 static void
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
734 msim_msg_pack_element(gpointer data, gpointer user_data)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
735 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
736 MsimMessageElement *elem;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
737 gchar *string, *data_string;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
738 gchar ***items;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
739
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
740 elem = (MsimMessageElement *)data;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
741 items = (gchar ***)user_data;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
742
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
743 /* Exclude elements beginning with '_' from packed protocol messages. */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
744 if (elem->name[0] == '_') {
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
745 return;
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
746 }
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
747
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
748 data_string = msim_msg_pack_element_data(elem);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
749
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
750 switch (elem->type) {
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
751 /* These types are represented by key name/value pairs (converted above). */
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
752 case MSIM_TYPE_INTEGER:
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
753 case MSIM_TYPE_RAW:
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
754 case MSIM_TYPE_STRING:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
755 case MSIM_TYPE_BINARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
756 case MSIM_TYPE_DICTIONARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
757 case MSIM_TYPE_LIST:
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
758 string = g_strconcat(elem->name, "\\", data_string, NULL);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
759 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
760
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
761 /* Boolean is represented by absence or presence of name. */
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
762 case MSIM_TYPE_BOOLEAN:
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
763 if (GPOINTER_TO_UINT(elem->data)) {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
764 /* True - leave in, with blank value. */
17318
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
765 string = g_strdup_printf("%s\\", elem->name);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
766 } else {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
767 /* False - leave out. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
768 string = g_strdup("");
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
769 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
770 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
771
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
772 default:
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
773 g_free(data_string);
20336
b93e7be3847b applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents: 20243
diff changeset
774 g_return_if_reached();
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
775 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
776 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
777
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
778 g_free(data_string);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
779
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
780 **items = string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
781 ++(*items);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
782 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
783
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
784 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
785 * Pack an element into its protcol representation inside a dictionary.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
786 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
787 * See msim_msg_pack_element().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
788 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
789 static void
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
790 msim_msg_pack_element_dict(gpointer data, gpointer user_data)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
791 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
792 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
793 gchar *string, *data_string, ***items;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
794
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
795 elem = (MsimMessageElement *)data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
796 items = (gchar ***)user_data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
797
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
798 /* Exclude elements beginning with '_' from packed protocol messages. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
799 if (elem->name[0] == '_') {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
800 return;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
801 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
802
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
803 data_string = msim_msg_pack_element_data(elem);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
804
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
805 g_return_if_fail(data_string != NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
806
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
807 switch (elem->type) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
808 /* These types are represented by key name/value pairs (converted above). */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
809 case MSIM_TYPE_INTEGER:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
810 case MSIM_TYPE_RAW:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
811 case MSIM_TYPE_STRING:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
812 case MSIM_TYPE_BINARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
813 case MSIM_TYPE_DICTIONARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
814 case MSIM_TYPE_LIST:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
815 case MSIM_TYPE_BOOLEAN: /* Boolean is On or Off */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
816 string = g_strconcat(elem->name, "=", data_string, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
817 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
818
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
819 default:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
820 g_free(data_string);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
821 g_return_if_fail(FALSE);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
822 break;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
823 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
824
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
825 g_free(data_string);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
826
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
827 **items = string;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
828 ++(*items);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
829 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
830
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
831 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
832 * Return a packed string of a message suitable for sending over the wire.
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
833 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
834 * @return A string. Caller must g_free().
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
835 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
836 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
837 msim_msg_pack(MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
838 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
839 g_return_val_if_fail(msg != NULL, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
840
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
841 return msim_msg_pack_using(msg, msim_msg_pack_element, "\\", "\\", "\\final\\");
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
842 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
843
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
844 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
845 * Return a packed string of a dictionary, suitable for embedding in MSIM_TYPE_DICTIONARY.
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
846 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
847 * @return A string; caller must g_free().
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
848 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
849 static gchar *
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
850 msim_msg_pack_dict(MsimMessage *msg)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
851 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
852 g_return_val_if_fail(msg != NULL, NULL);
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
853
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
854 return msim_msg_pack_using(msg, msim_msg_pack_element_dict, "\034", "", "");
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
855 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
856
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
857 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
858 * Send an existing MsimMessage.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
859 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
860 gboolean
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
861 msim_msg_send(MsimSession *session, MsimMessage *msg)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
862 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
863 gchar *raw;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
864 gboolean success;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
865
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
866 raw = msim_msg_pack(msg);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
867 g_return_val_if_fail(raw != NULL, FALSE);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
868 success = msim_send_raw(session, raw);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
869 g_free(raw);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
870
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
871 return success;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
872 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
873
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
874 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
875 * Return a message element data as a new string for a raw protocol message,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
876 * converting from other types (integer, etc.) if necessary.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
877 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
878 * @return const gchar * The data as a string, or NULL. Caller must g_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
879 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
880 * Returns a string suitable for inclusion in a raw protocol message, not necessarily
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
881 * optimal for human consumption. For example, strings are escaped. Use
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
882 * msim_msg_get_string() if you want a string, which in some cases is same as this.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
883 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
884 gchar *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
885 msim_msg_pack_element_data(MsimMessageElement *elem)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
886 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
887 GString *gs;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
888 GList *gl;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
889
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
890 g_return_val_if_fail(elem != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
891
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
892 switch (elem->type) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
893 case MSIM_TYPE_INTEGER:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
894 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
895
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
896 case MSIM_TYPE_RAW:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
897 /* Not un-escaped - this is a raw element, already escaped if necessary. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
898 return (gchar *)g_strdup((gchar *)elem->data);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
899
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
900 case MSIM_TYPE_STRING:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
901 /* Strings get escaped. msim_escape() creates a new string. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
902 g_return_val_if_fail(elem->data != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
903 return elem->data ? msim_escape((gchar *)elem->data) :
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
904 g_strdup("(NULL)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
905
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
906 case MSIM_TYPE_BINARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
907 gs = (GString *)elem->data;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
908 /* Do not escape! */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
909 return purple_base64_encode((guchar *)gs->str, gs->len);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
910
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
911 case MSIM_TYPE_BOOLEAN:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
912 /* Not used by messages in the wire protocol * -- see msim_msg_pack_element.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
913 * Only used by dictionaries, see msim_msg_pack_element_dict. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
914 return elem->data ? g_strdup("On") : g_strdup("Off");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
915
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
916 case MSIM_TYPE_DICTIONARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
917 return msim_msg_pack_dict((MsimMessage *)elem->data);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
918
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
919 case MSIM_TYPE_LIST:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
920 /* Pack using a|b|c|d|... */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
921 gs = g_string_new("");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
922
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
923 for (gl = (GList *)elem->data; gl != NULL; gl = g_list_next(gl)) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
924 g_string_append_printf(gs, "%s", (gchar*)(gl->data));
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
925
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
926 /* All but last element is separated by a bar. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
927 if (g_list_next(gl))
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
928 g_string_append(gs, "|");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
929 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
930
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
931 return g_string_free(gs, FALSE);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
932
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
933 default:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
934 purple_debug_info("msim", "field %s, unknown type %d\n",
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
935 elem->name ? elem->name : "(NULL)",
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
936 elem->type);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
937 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
938 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
939 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
940
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
941 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
942 * Send a message to the server, whose contents is specified using
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
943 * variable arguments.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
944 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
945 * @param session
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
946 * @param ... A sequence of gchar* key/type/value triplets, terminated with NULL.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
947 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
948 * This function exists for coding convenience: it allows a message to be created
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
949 * and sent in one line of code. Internally it calls msim_msg_send().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
950 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
951 * IMPORTANT: See msim_msg_append() documentation for details on element types.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
952 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
953 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
954 gboolean
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
955 msim_send(MsimSession *session, ...)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
956 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
957 gboolean success;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
958 MsimMessage *msg;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
959 va_list argp;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
960
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
961 va_start(argp, session);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
962 msg = msim_msg_new_v(NULL, argp);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
963
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
964 /* Actually send the message. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
965 success = msim_msg_send(session, msg);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
966
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
967 /* Cleanup. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
968 msim_msg_free(msg);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
969
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
970 return success;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
971 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
972
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
973 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
974 * Print a human-readable string of the message to Purple's debug log.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
975 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
976 * @param fmt_string A static string, in which '%s' will be replaced.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
977 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
978 void
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
979 msim_msg_dump(const gchar *fmt_string, MsimMessage *msg)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
980 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
981 gchar *debug_str;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
982
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
983 g_return_if_fail(fmt_string != NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
984
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
985 debug_str = msim_msg_dump_to_str(msg);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
986
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
987 g_return_if_fail(debug_str != NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
988
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
989 purple_debug_info("msim", fmt_string, debug_str);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
990
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
991 g_free(debug_str);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
992 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
993
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
994 /**
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
995 * Parse a raw protocol message string into a MsimMessage *.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
996 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
997 * @param raw The raw message string to parse, will be g_free()'d.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
998 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
999 * @return MsimMessage *. Caller should msim_msg_free() when done.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1000 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1001 MsimMessage *
24764
c1c464583f8c Mark some parameters as const char * instead of char * and don't
Mark Doliner <mark@kingant.net>
parents: 24757
diff changeset
1002 msim_parse(const gchar *raw)
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1003 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1004 MsimMessage *msg;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1005 gchar *token;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1006 gchar **tokens;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1007 gchar *key;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1008 gchar *value;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1009 int i;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1010
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1011 g_return_val_if_fail(raw != NULL, NULL);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1012
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1013 purple_debug_info("msim", "msim_parse: got <%s>\n", raw);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1014
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1015 key = NULL;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1016
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1017 /* All messages begin with a \. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1018 if (raw[0] != '\\' || raw[1] == 0) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1019 purple_debug_info("msim", "msim_parse: incomplete/bad string, "
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1020 "missing initial backslash: <%s>\n", raw);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1021 /* XXX: Should we try to recover, and read to first backslash? */
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1022
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1023 return NULL;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1024 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1025
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1026 msg = msim_msg_new(FALSE);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1027
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1028 for (tokens = g_strsplit(raw + 1, "\\", 0), i = 0;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1029 (token = tokens[i]);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1030 i++) {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1031 #ifdef MSIM_DEBUG_PARSE
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1032 purple_debug_info("msim", "tok=<%s>, i%2=%d\n", token, i % 2);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1033 #endif
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1034 if (i % 2) {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1035 /* Odd-numbered ordinal is a value. */
17285
4f54e8c41086 Cosmetic improvement to MsimMessage debug output.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17284
diff changeset
1036
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1037 value = token;
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1038
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1039 /* Incoming protocol messages get tagged as MSIM_TYPE_RAW, which
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1040 * represents an untyped piece of data. msim_msg_get_* will
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1041 * convert to appropriate types for caller, and handle unescaping if needed. */
24805
22fd7467f0cc Fix a few small memleaks
Mark Doliner <mark@kingant.net>
parents: 24799
diff changeset
1042 msg = msim_msg_append_dynamic_name(msg, g_strdup(key), MSIM_TYPE_RAW, g_strdup(value));
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1043 #ifdef MSIM_DEBUG_PARSE
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1044 purple_debug_info("msim", "insert string: |%s|=|%s|\n", key, value);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1045 #endif
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1046 } else {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1047 /* Even numbered indexes are key names. */
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1048 key = token;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1049 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1050 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1051 g_strfreev(tokens);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1052
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1053 return msg;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1054 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1055
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1056 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1057 * Return the first MsimMessageElement * with given name in the MsimMessage *.
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1058 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1059 * @param name Name to search for.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1060 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1061 * @return MsimMessageElement * matching name, or NULL.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1062 *
17274
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1063 * Note: useful fields of MsimMessageElement are 'data' and 'type', which
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1064 * you can access directly. But it is often more convenient to use
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1065 * another msim_msg_get_* that converts the data to what type you want.
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1066 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1067 MsimMessageElement *
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1068 msim_msg_get(const MsimMessage *msg, const gchar *name)
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1069 {
17301
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1070 GList *node;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1071
17301
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1072 node = msim_msg_get_node(msg, name);
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1073 if (node) {
17301
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1074 return (MsimMessageElement *)node->data;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1075 } else {
17301
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1076 return NULL;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1077 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1078 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1079
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1080 gchar *
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1081 msim_msg_get_string_from_element(MsimMessageElement *elem)
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1082 {
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1083 g_return_val_if_fail(elem != NULL, NULL);
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1084 switch (elem->type) {
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1085 case MSIM_TYPE_INTEGER:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1086 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data));
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1087
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1088 case MSIM_TYPE_RAW:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1089 /* Raw element from incoming message - if its a string, it'll
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1090 * be escaped. */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1091 return msim_unescape((gchar *)elem->data);
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1092
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1093 case MSIM_TYPE_STRING:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1094 /* Already unescaped. */
17692
3aed9c8c6af7 Fix bug where string returned from msim_msg_get_string() is not a new
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17680
diff changeset
1095 return g_strdup((gchar *)elem->data);
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1096
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1097 default:
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1098 purple_debug_info("msim", "msim_msg_get_string_element: type %d unknown, name %s\n",
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1099 elem->type, elem->name ? elem->name : "(NULL)");
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1100 return NULL;
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1101 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1102 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1103
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1104 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1105 * Return the data of an element of a given name, as a string.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1106 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1107 * @param name Name of element.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1108 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1109 * @return gchar * The data as a string, or NULL if not found.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1110 * Caller must g_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1111 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1112 * Note that msim_msg_pack_element_data() is similar, but returns a string
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1113 * for inclusion into a raw protocol string (escaped and everything).
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1114 * This function unescapes the string for you, if needed.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1115 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1116 gchar *
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1117 msim_msg_get_string(const MsimMessage *msg, const gchar *name)
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1118 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1119 MsimMessageElement *elem;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1120
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1121 elem = msim_msg_get(msg, name);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1122 if (!elem) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1123 return NULL;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1124 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1125
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1126 return msim_msg_get_string_from_element(elem);
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1127 }
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1128
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1129 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1130 * Parse a |-separated string into a new GList. Free with msim_msg_list_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1131 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1132 static GList *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1133 msim_msg_list_parse(const gchar *raw)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1134 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1135 gchar **array;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1136 GList *list;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1137 guint i;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1138
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1139 array = g_strsplit(raw, "|", 0);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1140 list = NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1141
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1142 /* TODO: escape/unescape /3 <-> | within list elements */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1143
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1144 for (i = 0; array[i] != NULL; ++i) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1145 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1146
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1147 /* Freed in msim_msg_list_free() */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1148 elem = g_new0(MsimMessageElement, 1);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1149
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1150 /* Give the element a name for debugging purposes.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1151 * Not supposed to be looked up by this name; instead,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1152 * lookup the elements by indexing the array. */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1153 elem->name = g_strdup_printf("(list item #%d)", i);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1154 elem->type = MSIM_TYPE_RAW;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1155 elem->data = g_strdup(array[i]);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1156
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1157 list = g_list_append(list, elem);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1158 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1159
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1160 g_strfreev(array);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1161
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1162 return list;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1163 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1164
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1165 static GList *
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1166 msim_msg_get_list_from_element(MsimMessageElement *elem)
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1167 {
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1168 g_return_val_if_fail(elem != NULL, NULL);
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1169 switch (elem->type) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1170 case MSIM_TYPE_LIST:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1171 return msim_msg_list_copy((GList *)elem->data);
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1172
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1173 case MSIM_TYPE_RAW:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1174 return msim_msg_list_parse((gchar *)elem->data);
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1175
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1176 default:
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1177 purple_debug_info("msim_msg_get_list", "type %d unknown, name %s\n",
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1178 elem->type, elem->name ? elem->name : "(NULL)");
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1179 return NULL;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1180 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1181 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1182
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1183 /**
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1184 * Return an element as a new list. Caller frees with msim_msg_list_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1185 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1186 GList *
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1187 msim_msg_get_list(const MsimMessage *msg, const gchar *name)
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1188 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1189 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1190
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1191 elem = msim_msg_get(msg, name);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1192 if (!elem) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1193 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1194 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1195
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1196 return msim_msg_get_list_from_element(elem);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1197 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1198
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1199 /**
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1200 * Parse a \x1c-separated "dictionary" of key=value pairs into a hash table.
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1201 *
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1202 * @param raw The text of the dictionary to parse. Often the
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1203 * value for the 'body' field.
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1204 *
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1205 * @return A new MsimMessage *. Must msim_msg_free() when done.
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1206 */
24764
c1c464583f8c Mark some parameters as const char * instead of char * and don't
Mark Doliner <mark@kingant.net>
parents: 24757
diff changeset
1207 static MsimMessage *
c1c464583f8c Mark some parameters as const char * instead of char * and don't
Mark Doliner <mark@kingant.net>
parents: 24757
diff changeset
1208 msim_msg_dictionary_parse(const gchar *raw)
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1209 {
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1210 MsimMessage *dict;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1211 gchar *item;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1212 gchar **items;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1213 gchar **elements;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1214 guint i;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1215
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1216 g_return_val_if_fail(raw != NULL, NULL);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1217
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1218 dict = msim_msg_new(NULL);
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1219
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1220 for (items = g_strsplit(raw, "\x1c", 0), i = 0;
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1221 (item = items[i]);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1222 i++) {
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1223 gchar *key, *value;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1224
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1225 elements = g_strsplit(item, "=", 2);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1226
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1227 key = elements[0];
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1228 if (!key) {
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1229 purple_debug_info("msim", "msim_msg_dictionary_parse(%s): null key\n",
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1230 raw);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1231 g_strfreev(elements);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1232 break;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1233 }
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1234
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1235 value = elements[1];
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1236 if (!value) {
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1237 purple_debug_info("msim", "msim_msg_dictionary_prase(%s): null value\n",
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1238 raw);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1239 g_strfreev(elements);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1240 break;
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1241 }
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1242
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1243 #ifdef MSIM_DEBUG_PARSE
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1244 purple_debug_info("msim_msg_dictionary_parse","-- %s: %s\n", key ? key : "(NULL)",
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1245 value ? value : "(NULL)");
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1246 #endif
22334
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
1247 /* Append with _dynamic_name since g_strdup(key) is dynamic, and
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
1248 * needs to be freed when the message is destroyed. It isn't static as usual. */
9479cf89a97d In msimprpl, support dynamically-allocated strings in message element names,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 22269
diff changeset
1249 dict = msim_msg_append_dynamic_name(dict, g_strdup(key), MSIM_TYPE_RAW, g_strdup(value));
19248
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1250
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1251 g_strfreev(elements);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1252 }
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1253
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1254 g_strfreev(items);
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1255
d34e49d8fac7 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18911
diff changeset
1256 return dict;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1257 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1258
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1259 static MsimMessage *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1260 msim_msg_get_dictionary_from_element(MsimMessageElement *elem)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1261 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1262 g_return_val_if_fail(elem != NULL, NULL);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1263 switch (elem->type) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1264 case MSIM_TYPE_DICTIONARY:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1265 return msim_msg_clone((MsimMessage *)elem->data);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1266
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1267 case MSIM_TYPE_RAW:
24764
c1c464583f8c Mark some parameters as const char * instead of char * and don't
Mark Doliner <mark@kingant.net>
parents: 24757
diff changeset
1268 return msim_msg_dictionary_parse(elem->data);
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1269
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1270 default:
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1271 purple_debug_info("msim_msg_get_dictionary", "type %d unknown, name %s\n",
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1272 elem->type, elem->name ? elem->name : "(NULL)");
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1273 return NULL;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1274 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1275 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1276
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1277 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1278 * Return an element as a new dictionary. Caller frees with msim_msg_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1279 */
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1280 MsimMessage *
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1281 msim_msg_get_dictionary(const MsimMessage *msg, const gchar *name)
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1282 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1283 MsimMessageElement *elem;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1284
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1285 elem = msim_msg_get(msg, name);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1286 if (!elem) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1287 return NULL;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1288 }
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1289
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1290 return msim_msg_get_dictionary_from_element(elem);
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1291 }
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1292
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1293 guint
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1294 msim_msg_get_integer_from_element(MsimMessageElement *elem)
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1295 {
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1296 g_return_val_if_fail(elem != NULL, 0);
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1297 switch (elem->type) {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1298 case MSIM_TYPE_INTEGER:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1299 return GPOINTER_TO_UINT(elem->data);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1300
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1301 case MSIM_TYPE_RAW:
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1302 case MSIM_TYPE_STRING:
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1303 /* TODO: find out if we need larger integers */
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1304 return (guint)atoi((gchar *)elem->data);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1305
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1306 default:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1307 return 0;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1308 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1309 }
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1310
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1311 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1312 * Return the data of an element of a given name, as an unsigned integer.
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1313 *
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1314 * @param name Name of element.
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1315 *
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1316 * @return guint Numeric representation of data, or 0 if could not be converted / not found.
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1317 *
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1318 * Useful to obtain an element's data if you know it should be an integer,
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1319 * even if it is not stored as an MSIM_TYPE_INTEGER. MSIM_TYPE_STRING will
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1320 * be converted handled correctly, for example.
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1321 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1322 guint
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1323 msim_msg_get_integer(const MsimMessage *msg, const gchar *name)
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1324 {
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1325 MsimMessageElement *elem;
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1326
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1327 elem = msim_msg_get(msg, name);
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1328
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1329 if (!elem) {
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1330 return 0;
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1331 }
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1332
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1333 return msim_msg_get_integer_from_element(elem);
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1334 }
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1335
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1336 static gboolean
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1337 msim_msg_get_binary_from_element(MsimMessageElement *elem, gchar **binary_data, gsize *binary_length)
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1338 {
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1339 GString *gs;
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1340
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1341 g_return_val_if_fail(elem != NULL, FALSE);
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1342
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1343 switch (elem->type) {
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1344 case MSIM_TYPE_RAW:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1345 /* Incoming messages are tagged with MSIM_TYPE_RAW, and
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1346 * converted appropriately. They can still be "strings", just they won't
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1347 * be tagged as MSIM_TYPE_STRING (as MSIM_TYPE_STRING is intended to be used
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1348 * by msimprpl code for things like instant messages - stuff that should be
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1349 * escaped if needed). DWIM.
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1350 */
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1351
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1352 /* Previously, incoming messages were stored as MSIM_TYPE_STRING.
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1353 * This was fine for integers and strings, since they can easily be
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1354 * converted in msim_get_*, as desirable. However, it does not work
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1355 * well for binary strings. Consider:
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1356 *
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1357 * If incoming base64'd elements were tagged as MSIM_TYPE_STRING.
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1358 * msim_msg_get_binary() sees MSIM_TYPE_STRING, base64 decodes, returns.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1359 * everything is fine.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1360 * But then, msim_send() is called on the incoming message, which has
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1361 * a base64'd MSIM_TYPE_STRING that really is encoded binary. The values
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1362 * will be escaped since strings are escaped, and / becomes /2; no good.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1363 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1364 */
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1365 *binary_data = (gchar *)purple_base64_decode((const gchar *)elem->data, binary_length);
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1366 return TRUE;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1367
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1368 case MSIM_TYPE_BINARY:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1369 gs = (GString *)elem->data;
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1370
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1371 /* Duplicate data, so caller can g_free() it. */
20243
5440eed4ec7e applied changes from efedefa70ee1d6f7f4dd39afe5db10c7e5bfe64c
Richard Laager <rlaager@wiktel.com>
parents: 19681
diff changeset
1372 *binary_data = g_memdup(gs->str, gs->len);
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1373 *binary_length = gs->len;
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1374
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1375 return TRUE;
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1376
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1377
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1378 /* Rejected because if it isn't already a GString, have to g_new0 it and
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1379 * then caller has to ALSO free the GString!
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1380 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1381 * return (GString *)elem->data; */
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1382
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1383 default:
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1384 purple_debug_info("msim", "msim_msg_get_binary: unhandled type %d for key %s\n",
19253
b66c5991c011 For each msim_msg_get_*() function that takes an element name, add
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19252
diff changeset
1385 elem->type, elem->name ? elem->name : "(NULL)");
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1386 return FALSE;
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1387 }
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1388 }
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1389
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1390 /**
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1391 * Return the data of an element of a given name, as a binary GString.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1392 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1393 * @param binary_data A pointer to a new pointer, which will be filled in with the binary data. CALLER MUST g_free().
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1394 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1395 * @param binary_length A pointer to an integer, which will be set to the binary data length.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1396 *
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1397 * @return TRUE if successful, FALSE if not.
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1398 */
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1399 gboolean
24799
c044eb54b7ac Fix a leak in myspace prpl.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24784
diff changeset
1400 msim_msg_get_binary(const MsimMessage *msg, const gchar *name,
24757
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1401 gchar **binary_data, gsize *binary_length)
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1402 {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1403 MsimMessageElement *elem;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1404
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1405 elem = msim_msg_get(msg, name);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1406 if (!elem) {
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1407 return FALSE;
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1408 }
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1409
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1410 return msim_msg_get_binary_from_element(elem, binary_data, binary_length);
68cc1a8a0d21 Shuffling things around, remove stray whitespace, remove some forward
Mark Doliner <mark@kingant.net>
parents: 24745
diff changeset
1411 }