annotate libpurple/protocols/myspace/message.c @ 24764:c044eb54b7ac

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