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