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