annotate libpurple/protocols/myspace/message.c @ 18909:c32fcdef2809

Only say we are connected after the MsimSession structure is fully setup. (Also change a few debugging statements to help find this bug.) Previously, purple_connection_set_state(..., PURPLE_CONNECTED) was called too early, so that if a client called any msimprpl functions that operated on MsimSession (pretty much all of them) within the signed-on signal handler, the userid etc., would not yet be correct and the call would fail. Now, the call is called at the right time so it works as expected. Closes #2520.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 12 Aug 2007 18:48:03 +0000
parents 6541b0edee26
children 692b128fe74a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1 /** MySpaceIM protocol messages
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
3 * \author Jeff Connelly
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
4 *
17680
d87916bd1d73 Fix email address.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17661
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
6 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
10 * (at your option) any later version.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
11 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
15 * GNU General Public License for more details.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
16 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
26 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
17326
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17318
diff changeset
27 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
28 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
29 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
30
18889
a3a5b2e9079a Change escape code replacement text parallel arrays to an array of structs,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18882
diff changeset
31 /* 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
32 * 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
33 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
34 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
35 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
36 } 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
37 { "/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
38 { "/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
39 /* { "/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
40 { 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
41 };
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
42
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
43 /**
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
44 * Escape a protocol message.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
45 *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
46 * @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
47 */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
48 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
49 msim_escape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
50 {
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
51 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
52 guint i, 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
53
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
54 gs = g_string_new("");
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
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
57 for (i = 0; i < strlen(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
58 struct MSIM_ESCAPE_REPLACEMENT *replacement;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
59 gchar *replace;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
60
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
61 replace = NULL;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
62
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
63 /* Check for characters that need to be escaped, and escape them. */
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
64 for (j = 0; (replacement = &msim_escape_replacements[j]) &&
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
65 replacement->code != NULL; ++j) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
66 if (msg[i] == replacement->text) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
67 replace = replacement->code;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
68 break;
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
69 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
70 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
71
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
72 if (replace) {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
73 g_string_append(gs, replace);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
74 } else {
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
75 g_string_append_c(gs, msg[i]);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
76 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
77 }
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 purple_debug_info("msim", "msim_escape: msg=%s, ret=%s\n", msg, gs->str);
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
80
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
81 return gs->str;
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
82 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
83
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 /**
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
85 * 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
86 *
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
87 * @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
88 */
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
89 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
90 msim_unescape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
91 {
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
92 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
93 guint i, 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
94
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
95 gs = g_string_new("");
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
96
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
97 for (i = 0; i < strlen(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
98 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
99 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
100
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
101 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
102
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
103 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
104 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
105 if (msg[i] == replacement->code[0] &&
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 i + 1 < strlen(msg) &&
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 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
108 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
109 ++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
110 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
111 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
112 }
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
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 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
115 }
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
116
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
117 purple_debug_info("msim", "msim_unescape: msg=%s, ret=%s\n", msg, gs->str);
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 return gs->str;
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
120 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
121
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
122 /** 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
123 *
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
124 * @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
125 * @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
126 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
127 * 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
128 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
129 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
130 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
131 {
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
132 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
133
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
134 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
135 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
136 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
137 } else {
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
138 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
139 }
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
140 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
141
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
142 /** 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
143 *
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 * @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
145 * 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
146 * @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
147 * @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
148 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
149 * 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
150 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
151 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
152 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
153 {
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
154 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
155 MsimMessageType type;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
156 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
157 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
158
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
159 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
160 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
161 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
162
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
163 /* 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
164 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
165
3f95e691bad2 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18897
diff changeset
166 /* 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
167 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
168
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
169 /* 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
170 do {
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
171 if (first)
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
172 {
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 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
174 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
175 } 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
176 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
177 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
178 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
179 }
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 }
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
181
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
182 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
183
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
184 /* 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
185 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
186 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
187 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
188 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
189 break;
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 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
192 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
193
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
194 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
195
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
196 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
197 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
198
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
199 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
200 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
201
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
202 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
203
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
204 /* 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
205 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
206 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
207
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
208 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
209 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
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 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
212
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
213 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
214 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
215
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
216 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
217 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
218
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
219 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
220
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
221 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
222 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
223
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
224 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
225 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
226 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
227 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
228 } 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
229 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
230
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
231 return msg;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
232 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
233
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
234 /** 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
235 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
236 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
237 {
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
238 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
239
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
240 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
241
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
242 /* 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
243 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
244 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
245 }
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 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
248 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
249
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
250 /** Free a GList * of gchar * strings. */
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
251 void
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
252 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
253 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
254
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
255 for (; l != NULL; l = g_list_next(l)) {
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
256 g_free((gchar *)(l->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
257 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
258 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
259 }
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 /** 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
262 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
263 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
264 {
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
265 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
266 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
267 guint i;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
268
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
269 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
270 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
271
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 /* 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
273
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
274 for (i = 0; array[i] != NULL; ++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
275 list = g_list_append(list, g_strdup(array[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
276 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
277
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
278 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
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 return list;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
281 }
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
282
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
283 /** 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
284 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
285 * @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
286 * @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
287 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
288 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
289 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
290 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
291 MsimMessageElement *elem;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
292 MsimMessage **new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
293 gpointer new_data;
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
294
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
295 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
296 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
297
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
298 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
299 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
300
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
301 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
302 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
303 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
304 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
305 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
306
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
307 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
308 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
309 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
310 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
311
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
312 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
313 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
314 break;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
315
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
316 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
317 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
318
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
319 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
320 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
321 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
322 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
323
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
324 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
325 break;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
326
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
327 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
328 purple_debug_info("msim", "msim_msg_clone_element: unknown type %d\n", 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 g_return_if_fail(NULL);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
330 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
331
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
332 /* 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
333 * never needs to be copied nor freed. */
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
334 *new = msim_msg_append(*new, elem->name, elem->type, new_data);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
335 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
336
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
337 /** 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
338 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
339 * @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
340 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
341 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
342 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
343 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
344 MsimMessage *new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
345
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
346 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
347 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
348 }
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
349
17302
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17301
diff changeset
350 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
351
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
352 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
353
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
354 return new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
355 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
356
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
357 /** 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
358 *
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
359 * @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
360 *
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
361 * 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
362 * 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
363 */
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
364 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
365 msim_msg_free_element_data(MsimMessageElement *elem)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
366 {
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
367 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
368 case MSIM_TYPE_BOOLEAN:
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
369 case MSIM_TYPE_INTEGER:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
370 /* Integer value stored in gpointer - no need to free(). */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
371 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
372
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
373 case MSIM_TYPE_RAW:
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
374 case MSIM_TYPE_STRING:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
375 /* Always free strings - caller should have g_strdup()'d if
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
376 * string was static or temporary and not to be freed. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
377 g_free(elem->data);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
378 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
379
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
380 case MSIM_TYPE_BINARY:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
381 /* Free the GString itself and the binary data. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
382 g_string_free((GString *)elem->data, TRUE);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
383 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
384
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
385 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
386 msim_msg_free((MsimMessage *)elem->data);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
387 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
388
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
389 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
390 g_list_free((GList *)elem->data);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
391 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
392
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
393 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
394 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
395 "not freeing unknown type %d\n", elem->type);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
396 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
397 }
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
398 }
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
399
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
400 /** 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
401 *
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
402 * @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
403 * @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
404 *
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
405 * Frees both the element data and the element itself.
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
406 */
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
407 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
408 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
409 {
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
410 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
411
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
412 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
413
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
414 msim_msg_free_element_data(elem);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
415
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
416 g_free(elem);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
417 }
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 /** 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
420 void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
421 msim_msg_free(MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
422 {
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
423 if (!msg) {
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
424 /* already free as can be */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
425 return;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
426 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
427
18909
c32fcdef2809 Only say we are connected after the MsimSession structure is fully setup.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18908
diff changeset
428 #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
429 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
430 #endif
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
431
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
432 g_list_foreach(msg, msim_msg_free_element, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
433 g_list_free(msg);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
434 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
435
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
436 /** 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
437 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
438 msim_msg_send(MsimSession *session, MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
439 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
440 gchar *raw;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
441 gboolean success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
442
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
443 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
444 g_return_val_if_fail(raw != NULL, FALSE);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
445 success = msim_send_raw(session, raw);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
446 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
447
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
448 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
449
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
450 return success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
451 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
452
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
453 /**
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 * 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
456 * variable arguments.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
457 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
458 * @param session
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
459 * @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
460 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
461 * 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
462 * 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
463 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
464 * 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
465 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
466 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
467 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
468 msim_send(MsimSession *session, ...)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
469 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
470 gboolean success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
471 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
472 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
473
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
474 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
475 msg = msim_msg_new_v(NULL, argp);
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 /* Actually send the message. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
478 success = msim_msg_send(session, msg);
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 /* Cleanup. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
481 msim_msg_free(msg);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
482
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
483 return success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
484 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
485
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
486 /** 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
487 *
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
488 * For internal use; users probably want msim_msg_append() or msim_msg_insert_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
489 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
490 static MsimMessageElement *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
491 msim_msg_element_new(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
492 {
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
493 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
494
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
495 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
496
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
497 elem->name = 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
498 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
499 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
500
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
501 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
502 }
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
503
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
504
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
505 /** Append a new element to a message.
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 * @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
508 * @param type An MSIM_TYPE_* code.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
509 * @param data Pointer to data, see below.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
510 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
511 * @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
512 *
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
513 * msg = msim_msg_append(msg, ...)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
514 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
515 * The data parameter depends on the type given:
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 * * MSIM_TYPE_INTEGER: Use GUINT_TO_POINTER(x).
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
518 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
519 * * 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
520 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
521 * * 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
522 *
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
523 * * 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
524 *
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
525 * * 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
526 *
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
527 * * 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
528 *
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
529 * * 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
530 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
531 * */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
532 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
533 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
534 MsimMessageType type, gpointer data)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
535 {
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
536 return g_list_append(msg, msim_msg_element_new(name, type, 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
537 }
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
538
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
539 /** 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
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 * @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
542 * 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
543 *
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
544 * 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
545 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
546 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
547 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
548 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
549 {
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
550 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
551 GList *node_before;
17264
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 new_elem = msim_msg_element_new(name, type, 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
554
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
555 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
556
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
557 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
558 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
559
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
560 /** 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
561 * Used by msim_msg_dump() and msim_msg_pack().
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
562 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
563 gchar *
18879
e0cac5db762b In msim_msg_pack_element_dict(), separate keys and values with '=' for
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17976
diff changeset
564 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
565 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
566 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
567 const gchar *begin, const gchar *end)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
568 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
569 gchar **strings;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
570 gchar **strings_tmp;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
571 gchar *joined;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
572 gchar *final;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
573 int i;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
574
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
575 g_return_val_if_fail(msg != NULL, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
576
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
577 /* Add one for NULL terminator for g_strjoinv(). */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
578 strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
579
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
580 strings_tmp = strings;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
581 g_list_foreach(msg, gf, &strings_tmp);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
582
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
583 joined = g_strjoinv(sep, strings);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
584 final = g_strconcat(begin, joined, end, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
585 g_free(joined);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
586
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
587 /* Clean up. */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
588 for (i = 0; i < g_list_length(msg); ++i) {
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
589 g_free(strings[i]);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
590 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
591
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
592 g_free(strings);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
593
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
594 return final;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
595 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
596 /** Store a human-readable string describing the element.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
597 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
598 * @param data Pointer to an MsimMessageElement.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
599 * @param user_data
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
600 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
601 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
602 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
603 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
604 MsimMessageElement *elem;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
605 gchar *string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
606 GString *gs;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
607 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
608 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
609
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
610 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
611 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
612 guint i;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
613
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
614 elem = (MsimMessageElement *)data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
615 items = user_data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
616
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
617 switch (elem->type) {
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
618 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
619 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
620 GPOINTER_TO_UINT(elem->data));
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
621 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
622
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
623 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
624 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
625 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
626 break;
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
627
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
628 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
629 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
630 elem->data ? (gchar *)elem->data : "(NULL)");
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
631 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
632
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
633 case MSIM_TYPE_BINARY:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
634 gs = (GString *)elem->data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
635 binary = purple_base64_encode((guchar*)gs->str, gs->len);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
636 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
637 g_free(binary);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
638 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
639
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
640 case MSIM_TYPE_BOOLEAN:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
641 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
642 elem->data ? "TRUE" : "FALSE");
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
643 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
644
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
645 case MSIM_TYPE_DICTIONARY:
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
646 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
647 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
648 } 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
649 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
650 }
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
651
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
652 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
653 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
654 }
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
655
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
656 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
657
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
658 g_free(s);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
659 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
660
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
661 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
662 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
663 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
664
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
665 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
666 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
667 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
668 ++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
669 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
670
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
671 string = gs->str;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
672 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
673
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
674 default:
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
675 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
676 elem->name ? elem->name : "(NULL)", elem->type);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
677 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
678 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
679
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
680 **items = string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
681 ++(*items);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
682 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
683
17298
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17294
diff changeset
684 /** 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
685 *
17298
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17294
diff changeset
686 * @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
687 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
688 void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
689 msim_msg_dump(const gchar *fmt_string, MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
690 {
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
691 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
692
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
693 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
694
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
695 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
696
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
697 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
698
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
699 purple_debug_info("msim_msg_dump", "debug_str=%s\n", debug_str);
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
700
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
701
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
702 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
703
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
704 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
705 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
706
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
707 /** 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
708 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
709 * @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
710 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
711 gchar *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
712 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
713 {
17298
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17294
diff changeset
714 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
715
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
716 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
717 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
718 } else {
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17294
diff changeset
719 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
720 "\n", "<MsimMessage: \n", "\n/MsimMessage>");
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
721 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
722
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
723 return debug_str;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
724 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
725
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
726 /** 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
727 *
17326
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17318
diff changeset
728 * @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
729 *
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
730 * 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
731 * 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
732 * 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
733 */
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
734 gchar *
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
735 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
736 {
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
737 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
738 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
739
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
740 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
741
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
742 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
743 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
744 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
745
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
746 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
747 /* 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
748 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
749
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
750 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
751 /* 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
752 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
753 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
754 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
755
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
756 case MSIM_TYPE_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
757 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
758 /* 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
759 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
760
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
761 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
762 /* 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
763 * 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
764 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
765
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
766 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
767 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
768
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
769 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
770 /* 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
771 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
772
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
773 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
774 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
775
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
776 /* 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
777 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
778 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
779 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
780
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
781 return gs->str;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
782
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
783 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
784 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
785 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
786 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
787 return NULL;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
788 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
789 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
790
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
791 /** 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
792 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
793 * 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
794 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
795 static void
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
796 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
797 {
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
798 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
799 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
800
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
801 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
802 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
803
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
804 /* 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
805 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
806 return;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
807 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
808
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
809 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
810
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
811 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
812
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
813 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
814 /* 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
815 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
816 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
817 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
818 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
819 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
820 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
821 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
822 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
823 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
824
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
825 default:
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
826 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
827 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
828 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
829 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
830
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
831 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
832
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
833 **items = string;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
834 ++(*items);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
835 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
836
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
837 /** Pack an element into its protocol representation.
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
838 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
839 * @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
840 * @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
841 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
842 * 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
843 * 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
844 * 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
845 * 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
846 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
847 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
848 msim_msg_pack_element(gpointer data, gpointer user_data)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
849 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
850 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
851 gchar *string, *data_string;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
852 gchar ***items;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
853
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
854 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
855 items = (gchar ***)user_data;
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
856
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
857 /* 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
858 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
859 return;
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
860 }
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
861
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
862 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
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) {
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
865 /* 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
866 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
867 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
868 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
869 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
870 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
871 case MSIM_TYPE_LIST:
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
872 string = g_strconcat(elem->name, "\\", data_string, NULL);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
873 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
874
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
875 /* Boolean is represented by absence or presence of name. */
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
876 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
877 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
878 /* True - leave in, with blank value. */
17318
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
879 string = g_strdup_printf("%s\\", elem->name);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
880 } else {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
881 /* False - leave out. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
882 string = g_strdup("");
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
883 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
884 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
885
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
886 default:
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
887 g_free(data_string);
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
888 g_return_if_fail(FALSE);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
889 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
890 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
891
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
892 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
893
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
894 **items = string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
895 ++(*items);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
896 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
897
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
898
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
899 /** 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
900 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
901 * @return A string. Caller must g_free().
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
902 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
903 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
904 msim_msg_pack(MsimMessage *msg)
17264
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
905 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
906 g_return_val_if_fail(msg != NULL, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
907
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
908 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
909 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
910
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
911 /** 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
912 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
913 * @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
914 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
915 gchar *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
916 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
917 {
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
918 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
919
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
920 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
921 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
922
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
923 /**
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
924 * 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
925 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
926 * @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
927 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
928 * @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
929 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
930 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
931 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
932 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
933 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
934 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
935 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
936 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
937 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
938 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
939
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
940 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
941
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
942 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
943
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
944 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
945
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
946 /* 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
947 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
948 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
949 "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
950 /* 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
951
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
952 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
953 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
954 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
955
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
956 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
957
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
958 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
959 (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
960 i++) {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
961 #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
962 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
963 #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
964 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
965 /* Odd-numbered ordinal is a value. */
17285
4f54e8c41086 Cosmetic improvement to MsimMessage debug output.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17284
diff changeset
966
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
967 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
968
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
969 /* 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
970 * 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
971 * 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
972 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
973 #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
974 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
975 #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
976 } else {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
977 /* 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
978 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
979 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
980 }
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
981 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
982
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
983 /* 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
984 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
985
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
986 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
987 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
988
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
989 /**
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
990 * Parse a \x1c-separated "dictionary" of key=value pairs into a hash table.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
991 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
992 * @param body_str The text of the dictionary to parse. Often the
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 * value for the 'body' field.
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
994 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
995 * @return Hash table of the keys and values. Must g_hash_table_destroy() when done.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
996 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
997 GHashTable *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
998 msim_parse_body(const gchar *body_str)
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
999 {
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
1000 GHashTable *table;
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 gchar *item;
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1002 gchar **items;
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 gchar **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
1004 guint i;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1005
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1006 g_return_val_if_fail(body_str != 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
1007
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
1008 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1009
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
1010 for (items = g_strsplit(body_str, "\x1c", 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
1011 (item = items[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
1012 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
1013 gchar *key, *value;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1014
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1015 elements = g_strsplit(item, "=", 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
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1017 key = elements[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
1018 if (!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
1019 purple_debug_info("msim", "msim_parse_body(%s): null key\n",
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1020 body_str);
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
1021 g_strfreev(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
1022 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
1023 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1024
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
1025 value = elements[1];
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1026 if (!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
1027 purple_debug_info("msim", "msim_parse_body(%s): null value\n",
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1028 body_str);
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 g_strfreev(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
1030 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
1031 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1032
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1033 #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
1034 purple_debug_info("msim", "-- %s: %s\n", key ? key : "(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
1035 value ? value : "(NULL)");
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1036 #endif
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1037
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
1038 /* XXX: This overwrites duplicates. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1039 /* TODO: make the GHashTable values be GList's, and append to the list if
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1040 * there is already a value of the same key name. This is important for
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1041 * the WebChallenge message. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1042 g_hash_table_insert(table, g_strdup(key), g_strdup(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
1043
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1044 g_strfreev(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
1045 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1046
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1047 g_strfreev(items);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1048
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1049 return table;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1050 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1051
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
1052 /** 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
1053 *
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1054 * @param msg Message to search within.
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1055 * @param name Field name to search for.
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1056 *
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1057 * @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
1058 *
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
1059 * 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
1060 * access the MsimMessageElement *, instead of the GList * container.
17318
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1061 *
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 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1063 static GList *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1064 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
1065 {
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 GList *i;
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
1067
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1068 if (!name) {
17318
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1069 return NULL;
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1070 }
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
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 /* Linear search for the given name. O(n) but n is small. */
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1073 for (i = g_list_first(msg); i != NULL; i = g_list_next(i)) {
17301
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1074 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
1075
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1076 elem = i->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
1077 g_return_val_if_fail(elem != NULL, 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
1078
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1079 if (strcmp(elem->name, name) == 0) {
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
1080 return i;
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
1081 }
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
1082 }
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
1083 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
1084 }
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
1085
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1086 /** 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
1087 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1088 * @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
1089 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1090 * @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
1091 *
17274
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1092 * 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
1093 * 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
1094 * 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
1095 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1096 MsimMessageElement *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1097 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
1098 {
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
1099 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
1100
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
1101 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
1102 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
1103 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
1104 } 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
1105 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
1106 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1107 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1108
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1109 /** 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
1110 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1111 * @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
1112 *
18908
6541b0edee26 Fix some assertion failures, that should really not be assertions. Found by using
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18905
diff changeset
1113 * @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
1114 * 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
1115 *
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17302
diff changeset
1116 * 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
1117 * 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
1118 * 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
1119 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1120 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1121 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
1122 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1123 MsimMessageElement *elem;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1124
17274
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1125 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
1126 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
1127 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
1128 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1129
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1130 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
1131 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
1132 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
1133
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1134 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
1135 /* 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
1136 * be escaped. */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1137 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
1138
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1139 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
1140 /* 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
1141 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
1142
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1143 default:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1144 purple_debug_info("msim", "msim_msg_get_string: type %d unknown, name %s\n",
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1145 elem->type, name ? 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
1146 return NULL;
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1147 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1148 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1149
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1150 /** 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
1151 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1152 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
1153 {
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
1154 MsimMessageElement *elem;
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1155
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
1156 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
1157 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
1158 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
1159 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1160
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
1161 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
1162 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
1163 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
1164
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 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
1166 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
1167
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
1168 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
1169 purple_debug_info("msim_msg_get_list", "type %d unknown, name %s\n",
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 elem->type, name ? 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
1171 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
1172 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1173 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1174
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1175 /** Parse a \034-deliminated and =-separated string into a dictionary. TODO */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1176 MsimMessage *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1177 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
1178 {
18895
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1179 /* TODO - get code from msim_parse_body, but parse into MsimMessage */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1180 return NULL;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1181 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1182
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1183 /** 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
1184 MsimMessage *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1185 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
1186 {
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
1187 MsimMessageElement *elem;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1188
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
1189 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
1190 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
1191 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
1192 }
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1193
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
1194 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
1195 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
1196 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
1197
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1198 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
1199 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
1200
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
1201 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
1202 purple_debug_info("msim_msg_get_dictionary", "type %d unknown, name %s\n",
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1203 elem->type, name ? 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
1204 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
1205 }
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1206 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1207
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1208 /** Return the data of an element of a given name, as an integer.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1209 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1210 * @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
1211 *
17327
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17326
diff changeset
1212 * @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
1213 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1214 * 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
1215 * 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
1216 * 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
1217 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1218 guint
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1219 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
1220 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1221 MsimMessageElement *elem;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1222
17274
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17273
diff changeset
1223 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
1224
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1225 if (!elem) {
17327
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17326
diff changeset
1226 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
1227 }
17327
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17326
diff changeset
1228
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1229 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
1230 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
1231 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
1232
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1233 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
1234 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
1235 /* 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
1236 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
1237
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1238 default:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1239 return 0;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1240 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17264
diff changeset
1241 }
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1242
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1243 /** 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
1244 *
17277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1245 * @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
1246 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1247 * @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
1248 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1249 * @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
1250 */
17661
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1251 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17327
diff changeset
1252 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
1253 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
1254 {
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1255 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
1256
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 GString *gs;
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1258
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1259 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
1260 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
1261 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
1262 }
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1263
18890
00499df91ffe Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18889
diff changeset
1264 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
1265 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
1266 /* 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
1267 * 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
1268 * 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
1269 * 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
1270 * 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
1271 */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1272
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1273 /* 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
1274 * 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
1275 * 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
1276 * 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
1277 *
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1278 * 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
1279 * 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
1280 * 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
1281 * 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
1282 * 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
1283 * 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
1284 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1285 */
17281
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17277
diff changeset
1286 *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
1287 return TRUE;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1288
17276
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1289 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
1290 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
1291
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
1292 /* Duplicate data, so caller can g_free() it. */
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1293 *binary_data = g_new0(char, gs->len);
f732d072b118 Change all code to better match the style of libpurple - use 8-space tabs
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18891
diff changeset
1294 memcpy(*binary_data, gs->str, 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
1295
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
1296 *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
1297
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
1298 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
1299
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1300
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1301 /* 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
1302 * 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
1303 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17276
diff changeset
1304 * 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
1305
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1306 default:
17284
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17282
diff changeset
1307 purple_debug_info("msim", "msim_msg_get_binary: unhandled type %d for key %s\n",
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1308 elem->type, name ? 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
1309 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
1310 }
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17274
diff changeset
1311 }