annotate libpurple/protocols/myspace/message.c @ 17976:b2d81d13f015

Be more careful about null strings in %s format specifier in debug messages.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 05 Aug 2007 03:02:17 +0000
parents acff371d7908
children e0cac5db762b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1 /** MySpaceIM protocol messages
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
3 * \author Jeff Connelly
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
4 *
17923
d87916bd1d73 Fix email address.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17904
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
6 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
10 * (at your option) any later version.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
11 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
15 * GNU General Public License for more details.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
16 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
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
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
25 static gchar *msim_unescape_or_escape(gchar *msg, gboolean escape);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
26 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
27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
17383
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17375
diff changeset
28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
17368
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
29 static gchar *msim_msg_pack_element_data(MsimMessageElement *elem);
17383
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17375
diff changeset
30 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
31 static MsimMessage *msim_msg_new_v(va_list argp);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
32
17968
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
33 /* Replacement codes to be replaced with associated replacement text,
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
34 * used for protocol message escaping / unescaping. */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
35 static gchar* msim_replacement_code[] = { "/1", "/2", /* "/3", */ NULL };
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
36 static gchar* msim_replacement_text[] = { "/", "\\", /* "|", */ NULL };
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
37
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
38 /**
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
39 * Unescape or escape a protocol message.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
40 *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
41 * @param msg The message to be unescaped or escaped. WILL BE FREED.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
42 * @param escape TRUE to escape, FALSE to unescape.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
43 *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
44 * @return The unescaped or escaped message. Caller must g_free().
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
45 */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
46 static gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
47 msim_unescape_or_escape(gchar *msg, gboolean escape)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
48 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
49 gchar *tmp, *code, *text;
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
50 guint i;
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
51
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
52 /* Replace each code in msim_replacement_code with
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
53 * corresponding entry in msim_replacement_text. */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
54 for (i = 0; (code = msim_replacement_code[i])
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
55 && (text = msim_replacement_text[i]); ++i)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
56 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
57 if (escape)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
58 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
59 tmp = str_replace(msg, text, code);
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
60 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
61 else
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
62 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
63 tmp = str_replace(msg, code, text);
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
64 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
65 g_free(msg);
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
66 msg = tmp;
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
67 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
68
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
69 return msg;
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
70 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
71
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
72 /**
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
73 * Escape a protocol message.
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
74 *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
75 * @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
76 */
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
77 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
78 msim_escape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
79 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
80 return msim_unescape_or_escape(g_strdup(msg), TRUE);
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
81 }
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 gchar *
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
84 msim_unescape(const gchar *msg)
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
85 {
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
86 return msim_unescape_or_escape(g_strdup(msg), FALSE);
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
87 }
a2298513db8b Move msim_escape() and msim_unescape() to message.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17964
diff changeset
88
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
89 /** Create a new MsimMessage.
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
90 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
91 * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow.
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
92 * @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: 17358
diff changeset
93 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
94 * 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: 17358
diff changeset
95 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
96 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
97 msim_msg_new(gboolean not_empty, ...)
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
98 {
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
99 va_list argp;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
100
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
101 va_start(argp, not_empty);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
102
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
103 if (not_empty)
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
104 return msim_msg_new_v(argp);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
105 else
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
106 return NULL;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
107 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
108
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
109 /** 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: 17358
diff changeset
110 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
111 * @param argp A va_list of variadic arguments, already started with va_start(). Will be va_end()'d.
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
112 * @return New MsimMessage *, must be freed with msim_msg_free().
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
113 *
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
114 * For internal use - users probably want msim_msg_new() or msim_send().
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
115 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
116 static MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
117 msim_msg_new_v(va_list argp)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
118 {
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
119 gchar *key, *value;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
120 MsimMessageType type;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
121 MsimMessage *msg;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
122
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
123 /* Begin with an empty message. */
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
124 msg = NULL;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
125
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
126 /* Read key, type, value triplets until NULL. */
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
127 do
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
128 {
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
129 key = va_arg(argp, gchar *);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
130 if (!key)
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
131 {
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
132 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
133 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
134
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
135 type = va_arg(argp, int);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
136
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
137 /* Interpret variadic arguments. */
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
138 switch (type)
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
139 {
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
140 case MSIM_TYPE_INTEGER:
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
141 case MSIM_TYPE_BOOLEAN:
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
142 msg = msim_msg_append(msg, key, type, GUINT_TO_POINTER(va_arg(argp, int)));
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
143 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
144
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
145 case MSIM_TYPE_STRING:
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
146 value = va_arg(argp, char *);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
147
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
148 g_return_val_if_fail(value != NULL, FALSE);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
149
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
150 msg = msim_msg_append(msg, key, type, value);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
151 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
152
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
153 case MSIM_TYPE_BINARY:
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
154 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
155 GString *gs;
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
156
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
157 gs = va_arg(argp, GString *);
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
158
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
159 g_return_val_if_fail(gs != NULL, FALSE);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
160
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
161 /* msim_msg_free() will free this GString the caller created. */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
162 msg = msim_msg_append(msg, key, type, gs);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
163 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
164 }
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
165
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
166 case MSIM_TYPE_LIST:
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
167 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
168 GList *gl;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
169
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
170 gl = va_arg(argp, GList *);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
171
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
172 g_return_val_if_fail(gl != NULL, FALSE);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
173
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
174 msg = msim_msg_append(msg, key, type, gl);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
175 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
176 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
177
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
178 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
179 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
180 MsimMessage *dict;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
181
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
182 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
183
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
184 g_return_val_if_fail(dict != NULL, FALSE);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
185
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
186 msg = msim_msg_append(msg, key, type, dict);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
187 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
188 }
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
189
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
190 default:
17937
231b87b76da4 In debug messages, don't output unknown elem->type fields as %c too (only as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17935
diff changeset
191 purple_debug_info("msim", "msim_send: unknown type %d\n", type);
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
192 break;
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
193 }
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
194 } while(key);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
195 va_end(argp);
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
196
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
197 return msg;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
198 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
199
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
200 /** 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
201 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
202 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
203 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
204 GList *new_list;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
205
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
206 new_list = NULL;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
207
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
208 /* Deep copy (g_list_copy is shallow). Copy each string. */
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
209 for (; old != NULL; old = g_list_next(old))
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
210 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
211 new_list = g_list_append(new_list, g_strdup(old->data));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
212 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
213
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
214 return new_list;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
215 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
216
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
217 /** 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
218 void
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
219 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
220 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
221
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
222 for (; l != NULL; l = g_list_next(l))
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
223 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
224 g_free((gchar *)(l->data));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
225 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
226 g_list_free(l);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
227 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
228
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
229 /** 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
230 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
231 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
232 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
233 gchar **array;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
234 GList *list;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
235 guint i;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
236
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
237 array = g_strsplit(raw, "|", 0);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
238 list = NULL;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
239
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
240 for (i = 0; array[i] != NULL; ++i)
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
241 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
242 list = g_list_append(list, g_strdup(array[i]));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
243 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
244
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
245 g_strfreev(array);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
246
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
247 return list;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
248 }
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
249
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
250 /** Clone an individual element.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
251 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
252 * @param data MsimMessageElement * to clone.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
253 * @param user_data Pointer to MsimMessage * to add cloned element to.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
254 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
255 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
256 msim_msg_clone_element(gpointer data, gpointer user_data)
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
257 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
258 MsimMessageElement *elem;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
259 MsimMessage **new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
260 gpointer new_data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
261
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
262 elem = (MsimMessageElement *)data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
263 new = (MsimMessage **)user_data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
264
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
265 switch (elem->type)
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
266 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
267 case MSIM_TYPE_BOOLEAN:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
268 case MSIM_TYPE_INTEGER:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
269 new_data = elem->data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
270 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
271
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
272 case MSIM_TYPE_RAW:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
273 case MSIM_TYPE_STRING:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
274 new_data = g_strdup((gchar *)elem->data);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
275 break;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
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 case MSIM_TYPE_LIST:
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
278 new_data = (gpointer)msim_msg_list_copy((GList *)(elem->data));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
279 break;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
280
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
281 case MSIM_TYPE_BINARY:
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
282 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
283 GString *gs;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
284
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
285 gs = (GString *)elem->data;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
286
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
287 new_data = g_string_new_len(gs->str, gs->len);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
288 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
289 break;
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
290 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
291 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
292 MsimMessage *dict;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
293
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
294 dict = (MsimMessage *)elem->data;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
295
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
296 new_data = msim_msg_clone(dict);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
297 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
298 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
299
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
300 default:
17937
231b87b76da4 In debug messages, don't output unknown elem->type fields as %c too (only as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17935
diff changeset
301 purple_debug_info("msim", "msim_msg_clone_element: unknown type %d\n", elem->type);
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
302 g_return_if_fail(NULL);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
303 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
304
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
305 /* Append cloned data. Note that the 'name' field is a static string, so it
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
306 * 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: 17342
diff changeset
307 *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: 17342
diff changeset
308 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
309
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
310 /** Clone an existing MsimMessage.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
311 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
312 * @return Cloned message; caller should free with msim_msg_free().
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
313 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
314 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
315 msim_msg_clone(MsimMessage *old)
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
316 {
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
317 MsimMessage *new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
318
17368
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
319 if (old == NULL)
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
320 return NULL;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
321
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
322 new = msim_msg_new(FALSE);
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
323
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
324 g_list_foreach(old, msim_msg_clone_element, &new);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
325
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
326 return new;
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
327 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
328
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
329 /** Free an individual message element.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
330 *
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
331 * @param data MsimMessageElement * to free.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
332 * @param user_data Not used; required to match g_list_foreach() callback prototype.
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
333 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
334 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
335 msim_msg_free_element(gpointer data, gpointer user_data)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
336 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
337 MsimMessageElement *elem;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
338
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
339 elem = (MsimMessageElement *)data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
340
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
341 switch (elem->type)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
342 {
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
343 case MSIM_TYPE_BOOLEAN:
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
344 case MSIM_TYPE_INTEGER:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
345 /* Integer value stored in gpointer - no need to free(). */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
346 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
347
17348
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17342
diff changeset
348 case MSIM_TYPE_RAW:
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
349 case MSIM_TYPE_STRING:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
350 /* Always free strings - caller should have g_strdup()'d if
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
351 * string was static or temporary and not to be freed. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
352 g_free(elem->data);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
353 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
354
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
355 case MSIM_TYPE_BINARY:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
356 /* Free the GString itself and the binary data. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
357 g_string_free((GString *)elem->data, TRUE);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
358 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
359
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
360 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
361 msim_msg_free((MsimMessage *)elem->data);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
362 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
363
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
364 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
365 g_list_free((GList *)elem->data);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
366 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
367
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
368 default:
17937
231b87b76da4 In debug messages, don't output unknown elem->type fields as %c too (only as
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17935
diff changeset
369 purple_debug_info("msim", "msim_msg_free_element: not freeing unknown type %d\n", elem->type);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
370 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
371 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
372
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
373 g_free(elem);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
374 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
375
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
376 /** Free a complete message. */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
377 void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
378 msim_msg_free(MsimMessage *msg)
17321
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 if (!msg)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
381 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
382 /* already free as can be */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
383 return;
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
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
386 msim_msg_dump("msim_msg_free: freeing %s", msg);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
387
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
388 g_list_foreach(msg, msim_msg_free_element, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
389 g_list_free(msg);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
390 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
391
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
392 /** Send an existing MsimMessage. */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
393 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
394 msim_msg_send(MsimSession *session, MsimMessage *msg)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
395 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
396 gchar *raw;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
397 gboolean success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
398
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
399 raw = msim_msg_pack(msg);
17944
c109b7f1c739 Allow setting status string messages. Known bug: custom status messages always
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17937
diff changeset
400 g_return_val_if_fail(raw != NULL, FALSE);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
401 success = msim_send_raw(session, raw);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
402 g_free(raw);
17368
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
403
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
404 msim_msg_dump("msim_msg_send()ing %s\n", msg);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
405
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
406 return success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
407 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
408
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
409 /**
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
410 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
411 * 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
412 * variable arguments.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
413 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
414 * @param session
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
415 * @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
416 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
417 * 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
418 * 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
419 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
420 * 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
421 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
422 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
423 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
424 msim_send(MsimSession *session, ...)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
425 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
426 gboolean success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
427 MsimMessage *msg;
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
428 va_list argp;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
429
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
430 va_start(argp, session);
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
431 msg = msim_msg_new_v(argp);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
432
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
433 /* Actually send the message. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
434 success = msim_msg_send(session, msg);
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 /* Cleanup. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
437 msim_msg_free(msg);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
438
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
439 return success;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
440 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
441
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
442 /** 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: 17355
diff changeset
443 *
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
444 * 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: 17355
diff changeset
445 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
446 static MsimMessageElement *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
447 msim_msg_element_new(const gchar *name, MsimMessageType type, gpointer data)
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
448 {
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
449 MsimMessageElement *elem;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
450
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
451 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: 17355
diff changeset
452
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
453 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: 17355
diff changeset
454 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: 17355
diff changeset
455 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: 17355
diff changeset
456
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
457 return elem;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
458 }
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
459
17321
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 /** Append a new element to a message.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
462 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
463 * @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
464 * @param type An MSIM_TYPE_* code.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
465 * @param data Pointer to data, see below.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
466 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
467 * @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
468 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
469 * msg = msim_msg_append(msg, ...)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
470 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
471 * The data parameter depends on the type given:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
472 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
473 * * MSIM_TYPE_INTEGER: Use GUINT_TO_POINTER(x).
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
474 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
475 * * 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
476 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
477 * * 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
478 *
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
479 * * 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: 17339
diff changeset
480 *
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
481 * * MSIM_TYPE_BINARY: g_string_new_len(data, length). The data AND GString will be freed.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
482 *
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
483 * * MSIM_TYPE_DICTIONARY: An MsimMessage *. Freed when message is destroyed.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
484 *
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
485 * * MSIM_TYPE_LIST: GList * of gchar *. Again, everything will be freed.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
486 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
487 * */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
488 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
489 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: 17384
diff changeset
490 MsimMessageType type, gpointer data)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
491 {
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
492 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: 17355
diff changeset
493 }
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
494
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
495 /** 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: 17355
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: 17355
diff changeset
497 * @param name_before Name of the element to insert the new element before. If
17375
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
498 * could not be found or NULL, new element will be inserted at end.
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
499 *
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
500 * 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: 17355
diff changeset
501 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
502 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
503 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: 17384
diff changeset
504 const gchar *name, MsimMessageType type, gpointer data)
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
505 {
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
506 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: 17355
diff changeset
507 GList *node_before;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
508
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
509 new_elem = 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: 17355
diff changeset
510
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
511 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: 17355
diff changeset
512
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
513 return g_list_insert_before(msg, node_before, new_elem);
17321
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
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
516 /** Pack a string using the given GFunc and seperator.
17355
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
517 * Used by msim_msg_dump() and msim_msg_pack().
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
518 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
519 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
520 msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep,
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
521 const gchar *begin, const gchar *end)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
522 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
523 gchar **strings;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
524 gchar **strings_tmp;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
525 gchar *joined;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
526 gchar *final;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
527 int i;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
528
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
529 g_return_val_if_fail(msg != NULL, NULL);
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 /* Add one for NULL terminator for g_strjoinv(). */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
532 strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
533
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
534 strings_tmp = strings;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
535 g_list_foreach(msg, gf, &strings_tmp);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
536
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
537 joined = g_strjoinv(sep, strings);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
538 final = g_strconcat(begin, joined, end, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
539 g_free(joined);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
540
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
541 /* Clean up. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
542 for (i = 0; i < g_list_length(msg); ++i)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
543 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
544 g_free(strings[i]);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
545 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
546
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
547 g_free(strings);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
548
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
549 return final;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
550 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
551 /** Store a human-readable string describing the element.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
552 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
553 * @param data Pointer to an MsimMessageElement.
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
554 * @param user_data
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
555 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
556 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
557 msim_msg_debug_string_element(gpointer data, gpointer user_data)
17321
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 MsimMessageElement *elem;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
560 gchar *string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
561 GString *gs;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
562 gchar *binary;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
563 gchar ***items; /* wow, a pointer to a pointer to a pointer */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
564
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
565 elem = (MsimMessageElement *)data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
566 items = user_data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
567
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
568 switch (elem->type)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
569 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
570 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
571 string = g_strdup_printf("%s(integer): %d", elem->name,
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
572 GPOINTER_TO_UINT(elem->data));
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
573 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
574
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
575 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
576 string = g_strdup_printf("%s(raw): %s", elem->name,
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
577 elem->data ? (gchar *)elem->data : "(NULL)");
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
578 break;
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
579
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
580 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
581 string = g_strdup_printf("%s(string): %s", elem->name,
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
582 elem->data ? (gchar *)elem->data : "(NULL)");
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
583 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
584
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
585 case MSIM_TYPE_BINARY:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
586 gs = (GString *)elem->data;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
587 binary = purple_base64_encode((guchar*)gs->str, gs->len);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
588 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
589 g_free(binary);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
590 break;
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 case MSIM_TYPE_BOOLEAN:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
593 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
594 elem->data ? "TRUE" : "FALSE");
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
595 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
596
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
597 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
598 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
599 gchar *s;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
600
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
601 if (!elem->data)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
602 s = g_strdup("(NULL)");
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
603 else
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
604 s = msim_msg_dump_to_str((MsimMessage *)elem->data);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
605
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
606 if (!s)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
607 s = g_strdup("(NULL, couldn't msim_msg_dump_to_str)");
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
608
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
609 string = g_strdup_printf("%s(dict): %s", elem->name, s);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
610
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
611 g_free(s);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
612 }
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
613 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
614
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
615 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
616 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
617 GString *gs;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
618 GList *gl;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
619 guint i;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
620
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
621 gs = g_string_new("");
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
622 g_string_append_printf(gs, "%s(list): \n", elem->name);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
623
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
624 i = 0;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
625 for (gl = (GList *)elem->data; gl != NULL; gl = g_list_next(gl))
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
626 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
627 g_string_append_printf(gs, " %d. %s\n", i, (gchar *)(gl->data));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
628 ++i;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
629 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
630
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
631 string = gs->str;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
632 }
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
633 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
634
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
635 default:
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
636 string = g_strdup_printf("%s(unknown type %d",
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
637 elem->name ? elem->name : "(NULL)", elem->type);
17321
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
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
641 **items = string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
642 ++(*items);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
643 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
644
17355
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
645 /** Print a human-readable string of the message to Purple's debug log.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
646 *
17355
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
647 * @param fmt_string A static string, in which '%s' will be replaced.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
648 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
649 void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
650 msim_msg_dump(const gchar *fmt_string, MsimMessage *msg)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
651 {
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
652 gchar *debug_str;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
653
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
654 g_return_if_fail(fmt_string != NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
655
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
656 debug_str = msim_msg_dump_to_str(msg);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
657
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
658 g_return_if_fail(debug_str != NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
659
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
660 purple_debug_info("msim_msg_dump", "debug_str=%s\n", debug_str);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
661
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
662
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
663 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
664
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
665 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
666 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
667
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
668 /** 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
669 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
670 * @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
671 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
672 gchar *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
673 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
674 {
17355
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
675 gchar *debug_str;
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
676
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
677 if (!msg)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
678 {
17355
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
679 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: 17351
diff changeset
680 } else {
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17351
diff changeset
681 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: 17351
diff changeset
682 "\n", "<MsimMessage: \n", "\n/MsimMessage>");
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
683 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
684
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
685 return debug_str;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
686 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
687
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
688 /** Return a message element data as a new string for a raw protocol message, converting from other types (integer, etc.) if necessary.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
689 *
17383
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17375
diff changeset
690 * @return const gchar * The data as a string, or NULL. Caller must g_free().
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
691 *
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
692 * 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: 17339
diff changeset
693 * 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: 17339
diff changeset
694 * msim_msg_get_string() if you want a string, which in some cases is same as this.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
695 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
696 static gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
697 msim_msg_pack_element_data(MsimMessageElement *elem)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
698 {
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
699 g_return_val_if_fail(elem != NULL, NULL);
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
700
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
701 switch (elem->type)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
702 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
703 case MSIM_TYPE_INTEGER:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
704 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: 17321
diff changeset
705
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
706 case MSIM_TYPE_RAW:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
707 /* Not un-escaped - this is a raw element, already escaped if necessary. */
17383
f057837085b0 Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17375
diff changeset
708 return (gchar *)g_strdup((gchar *)elem->data);
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
709
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
710 case MSIM_TYPE_STRING:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
711 /* Strings get escaped. msim_escape() creates a new string. */
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
712 g_return_val_if_fail(elem->data != NULL, NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
713 return elem->data ? msim_escape((gchar *)elem->data) :
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
714 g_strdup("(NULL)");
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
715
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
716 case MSIM_TYPE_BINARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
717 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
718 GString *gs;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
719
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
720 gs = (GString *)elem->data;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
721 /* Do not escape! */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
722 return purple_base64_encode((guchar *)gs->str, gs->len);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
723 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
724
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
725 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
726 /* Not used by messages in the wire protocol * -- 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
727 * Only used by dictionaries, see msim_msg_pack_element_dict. */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
728 return elem->data ? g_strdup("On") : g_strdup("Off");
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
729
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
730 case MSIM_TYPE_DICTIONARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
731 /* TODO: pack using k=v\034k2=v2\034... */
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
732 return msim_msg_pack_dict((MsimMessage *)elem->data);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
733
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
734 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
735 /* Pack using a|b|c|d|... */
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
736 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
737 GString *gs;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
738 GList *gl;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
739
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
740 gs = g_string_new("");
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
741
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
742 for (gl = (GList *)elem->data; gl != NULL; gl = g_list_next(gl))
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
743 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
744 g_string_append_printf(gs, "%s|", (gchar*)(gl->data));
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
745 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
746
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
747 return gs->str;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
748 }
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
749
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
750 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
751 purple_debug_info("msim", "field %s, unknown type %d\n",
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
752 elem->name ? elem->name : "(NULL)",
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
753 elem->type);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
754 return NULL;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
755 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
756 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
757
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
758 /** 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
759 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
760 * 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
761 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
762 static void
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
763 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
764 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
765 MsimMessageElement *elem;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
766 gchar *string, *data_string, ***items;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
767
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
768 elem = (MsimMessageElement *)data;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
769 items = (gchar ***)user_data;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
770
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
771 /* Exclude elements beginning with '_' from packed protocol messages. */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
772 if (elem->name[0] == '_')
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
773 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
774 return;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
775 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
776
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
777 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
778
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
779 g_return_if_fail(data_string != NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
780
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
781 switch (elem->type)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
782 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
783 /* 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
784 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
785 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
786 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
787 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
788 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
789 case MSIM_TYPE_LIST:
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
790 case MSIM_TYPE_BOOLEAN: /* Boolean is On or Off */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
791 string = g_strconcat(elem->name, "\\", data_string, NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
792 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
793
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
794 default:
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
795 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
796 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
797 break;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
798 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
799
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
800 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
801
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
802 **items = string;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
803 ++(*items);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
804 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
805
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
806 /** Pack an element into its protocol representation.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
807 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
808 * @param data Pointer to an MsimMessageElement.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
809 * @param user_data Pointer to a gchar ** array of string items.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
810 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
811 * Called by msim_msg_pack(). Will pack the MsimMessageElement into
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
812 * a part of the protocol string and append it to the array. Caller
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
813 * is responsible for creating array to correct dimensions, and
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
814 * freeing each string element of the array added by this function.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
815 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
816 static void
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
817 msim_msg_pack_element(gpointer data, gpointer user_data)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
818 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
819 MsimMessageElement *elem;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
820 gchar *string, *data_string;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
821 gchar ***items;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
822
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
823 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
824 items = (gchar ***)user_data;
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
825
17368
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
826 /* Exclude elements beginning with '_' from packed protocol messages. */
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
827 if (elem->name[0] == '_')
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
828 {
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
829 return;
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
830 }
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
831
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
832 data_string = msim_msg_pack_element_data(elem);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
833
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
834 switch (elem->type)
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
835 {
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
836 /* These types are represented by key name/value pairs (converted above). */
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
837 case MSIM_TYPE_INTEGER:
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
838 case MSIM_TYPE_RAW:
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
839 case MSIM_TYPE_STRING:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
840 case MSIM_TYPE_BINARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
841 case MSIM_TYPE_DICTIONARY:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
842 case MSIM_TYPE_LIST:
17338
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
843 string = g_strconcat(elem->name, "\\", data_string, NULL);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
844 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
845
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
846 /* Boolean is represented by absence or presence of name. */
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
847 case MSIM_TYPE_BOOLEAN:
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
848 if (GPOINTER_TO_UINT(elem->data))
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
849 {
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
850 /* True - leave in, with blank value. */
17375
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
851 string = g_strdup_printf("%s\\", elem->name);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
852 } else {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
853 /* False - leave out. */
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
854 string = g_strdup("");
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
855 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
856 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
857
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
858 default:
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
859 g_free(data_string);
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
860 g_return_if_fail(FALSE);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
861 break;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
862 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
863
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
864 g_free(data_string);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
865
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
866 **items = string;
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
867 ++(*items);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
868 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
869
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
870
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
871 /** Return a packed string of a message suitable for sending over the wire.
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
872 *
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
873 * @return A string. Caller must g_free().
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
874 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
875 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
876 msim_msg_pack(MsimMessage *msg)
17321
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
877 {
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
878 g_return_val_if_fail(msg != NULL, NULL);
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
879
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
880 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
881 }
ddcf9ef2ccec Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
882
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
883 /** 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
884 *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
885 * @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
886 */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
887 gchar *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
888 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
889 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
890 g_return_val_if_fail(msg != NULL, NULL);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
891
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
892 return msim_msg_pack_using(msg, msim_msg_pack_element_dict, "\034", "", "");
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
893 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
894
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
895 /**
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
896 * Parse a raw protocol message string into a MsimMessage *.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
897 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
898 * @param raw The raw message string to parse, will be g_free()'d.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
899 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
900 * @return MsimMessage *. Caller should msim_msg_free() when done.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
901 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
902 MsimMessage *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
903 msim_parse(gchar *raw)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
904 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
905 MsimMessage *msg;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
906 gchar *token;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
907 gchar **tokens;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
908 gchar *key;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
909 gchar *value;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
910 int i;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
911
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
912 g_return_val_if_fail(raw != NULL, NULL);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
913
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
914 purple_debug_info("msim", "msim_parse: got <%s>\n", raw);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
915
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
916 key = NULL;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
917
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
918 /* All messages begin with a \. */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
919 if (raw[0] != '\\' || raw[1] == 0)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
920 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
921 purple_debug_info("msim", "msim_parse: incomplete/bad string, "
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
922 "missing initial backslash: <%s>\n", raw);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
923 /* XXX: Should we try to recover, and read to first backslash? */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
924
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
925 g_free(raw);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
926 return NULL;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
927 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
928
17359
d69bcd74c240 Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17358
diff changeset
929 msg = msim_msg_new(FALSE);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
930
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
931 for (tokens = g_strsplit(raw + 1, "\\", 0), i = 0;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
932 (token = tokens[i]);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
933 i++)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
934 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
935 #ifdef MSIM_DEBUG_PARSE
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
936 purple_debug_info("msim", "tok=<%s>, i%2=%d\n", token, i % 2);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
937 #endif
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
938 if (i % 2)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
939 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
940 /* Odd-numbered ordinal is a value. */
17342
4f54e8c41086 Cosmetic improvement to MsimMessage debug output.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17341
diff changeset
941
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
942 value = token;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
943
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
944 /* Incoming protocol messages get tagged as MSIM_TYPE_RAW, which
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
945 * represents an untyped piece of data. msim_msg_get_* will
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
946 * convert to appropriate types for caller, and handle unescaping if needed. */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
947 msg = msim_msg_append(msg, g_strdup(key), MSIM_TYPE_RAW, g_strdup(value));
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
948 #ifdef MSIM_DEBUG_PARSE
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
949 purple_debug_info("msim", "insert string: |%s|=|%s|\n", key, value);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
950 #endif
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
951 } else {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
952 /* Even numbered indexes are key names. */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
953 key = token;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
954 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
955 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
956 g_strfreev(tokens);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
957
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
958 /* Can free now since all data was copied to hash key/values */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
959 g_free(raw);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
960
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
961 return msg;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
962 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
963
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
964 /**
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
965 * 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: 17321
diff changeset
966 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
967 * @param body_str The text of the dictionary to parse. Often the
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
968 * value for the 'body' field.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
969 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
970 * @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: 17321
diff changeset
971 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
972 GHashTable *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
973 msim_parse_body(const gchar *body_str)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
974 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
975 GHashTable *table;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
976 gchar *item;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
977 gchar **items;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
978 gchar **elements;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
979 guint i;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
980
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
981 g_return_val_if_fail(body_str != NULL, NULL);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
982
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
983 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
984
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
985 for (items = g_strsplit(body_str, "\x1c", 0), i = 0;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
986 (item = items[i]);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
987 i++)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
988 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
989 gchar *key, *value;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
990
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
991 elements = g_strsplit(item, "=", 2);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
992
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
993 key = elements[0];
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
994 if (!key)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
995 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
996 purple_debug_info("msim", "msim_parse_body(%s): null key\n",
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
997 body_str);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
998 g_strfreev(elements);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
999 break;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1000 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1001
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1002 value = elements[1];
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1003 if (!value)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1004 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1005 purple_debug_info("msim", "msim_parse_body(%s): null value\n",
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1006 body_str);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1007 g_strfreev(elements);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1008 break;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1009 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1010
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1011 #ifdef MSIM_DEBUG_PARSE
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1012 purple_debug_info("msim", "-- %s: %s\n", key ? key : "(NULL)",
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1013 value ? value : "(NULL)");
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1014 #endif
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1015
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1016 /* XXX: This overwrites duplicates. */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1017 /* TODO: make the GHashTable values be GList's, and append to the list if
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1018 * there is already a value of the same key name. This is important for
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1019 * the WebChallenge message. */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1020 g_hash_table_insert(table, g_strdup(key), g_strdup(value));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1021
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1022 g_strfreev(elements);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1023 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1024
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1025 g_strfreev(items);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1026
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1027 return table;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1028 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1029
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1030 /** Search for and return the node in msg, matching name, or NULL.
17375
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1031 *
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1032 * @param msg Message to search within.
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1033 * @param name Field name to search for.
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1034 *
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1035 * @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: 17368
diff changeset
1036 *
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1037 * 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: 17355
diff changeset
1038 * access the MsimMessageElement *, instead of the GList * container.
17375
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1039 *
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1040 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1041 static GList *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1042 msim_msg_get_node(MsimMessage *msg, const gchar *name)
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1043 {
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1044 GList *i;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1045
17375
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1046 if (!name)
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1047 {
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1048 return NULL;
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1049 }
7abd1eca3d18 Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17368
diff changeset
1050
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1051 /* Linear search for the given name. O(n) but n is small. */
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1052 for (i = g_list_first(msg); i != NULL; i = g_list_next(i))
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1053 {
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1054 MsimMessageElement *elem;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1055
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1056 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: 17355
diff changeset
1057 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: 17355
diff changeset
1058
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1059 if (strcmp(elem->name, name) == 0)
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1060 return i;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1061 }
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1062 return NULL;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1063 }
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1064
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1065 /** 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: 17321
diff changeset
1066 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1067 * @param name Name to search for.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1068 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1069 * @return MsimMessageElement * matching name, or NULL.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1070 *
17331
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17330
diff changeset
1071 * Note: useful fields of MsimMessageElement are 'data' and 'type', which
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17330
diff changeset
1072 * you can access directly. But it is often more convenient to use
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17330
diff changeset
1073 * another msim_msg_get_* that converts the data to what type you want.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1074 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1075 MsimMessageElement *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1076 msim_msg_get(MsimMessage *msg, const gchar *name)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1077 {
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1078 GList *node;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1079
17358
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1080 node = msim_msg_get_node(msg, name);
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1081 if (node)
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1082 return (MsimMessageElement *)node->data;
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1083 else
641c96277fa6 Add msim_msg_insert_before(), needed since some elements must be in a certain order.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17355
diff changeset
1084 return NULL;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1085 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1086
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1087 /** 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: 17321
diff changeset
1088 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1089 * @param name Name of element.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1090 *
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1091 * @return gchar * The data as a string. Caller must g_free().
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1092 *
17368
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17359
diff changeset
1093 * Note that msim_msg_pack_element_data() is similar, but returns a string
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1094 * 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: 17339
diff changeset
1095 * This function unescapes the string for you, if needed.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1096 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1097 gchar *
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1098 msim_msg_get_string(MsimMessage *msg, const gchar *name)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1099 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1100 MsimMessageElement *elem;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1101
17331
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17330
diff changeset
1102 elem = msim_msg_get(msg, name);
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1103 g_return_val_if_fail(elem != NULL , NULL);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1104
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1105 switch (elem->type)
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1106 {
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1107 case MSIM_TYPE_INTEGER:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1108 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data));
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1109
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1110 case MSIM_TYPE_RAW:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1111 /* Raw element from incoming message - if its a string, it'll
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1112 * be escaped. */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1113 return msim_unescape((gchar *)elem->data);
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1114
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1115 case MSIM_TYPE_STRING:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1116 /* Already unescaped. */
17935
3aed9c8c6af7 Fix bug where string returned from msim_msg_get_string() is not a new
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17923
diff changeset
1117 return g_strdup((gchar *)elem->data);
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1118
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1119 default:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1120 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
1121 elem->type, name ? name : "(NULL)");
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1122 return NULL;
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1123 }
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1124 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1125
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1126 /** 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
1127 GList *
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1128 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
1129 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1130 MsimMessageElement *elem;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1131
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1132 elem = msim_msg_get(msg, name);
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1133 if (!elem)
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1134 return NULL;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1135
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1136 switch (elem->type)
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1137 {
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1138 case MSIM_TYPE_LIST:
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1139 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
1140
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1141 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
1142 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
1143
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1144 default:
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1145 purple_debug_info("msim_msg_get_list", "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
1146 elem->type, name ? name : "(NULL)");
17964
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1147 return NULL;
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1148 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1149 }
6d1d86ab6a59 In MsimMessage, add support for MSIM_TYPE_LIST - pipe-separated lists.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17944
diff changeset
1150
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1151 /** 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
1152 MsimMessage *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1153 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
1154 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1155 /* TODO - get code from msim_parse_body, but parse into MsimMessage */
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1156 return NULL;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1157 }
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1158
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1159 /** 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
1160 MsimMessage *
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1161 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
1162 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1163 MsimMessageElement *elem;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1164
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1165 elem = msim_msg_get(msg, name);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1166 if (!elem)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1167 return NULL;
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1168
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1169 switch (elem->type)
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1170 {
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1171 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
1172 return msim_msg_clone((MsimMessage *)elem->data);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1173
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1174 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
1175 return msim_msg_dictionary_parse((gchar *)elem->data);
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1176
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1177 default:
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1178 purple_debug_info("msim_msg_get_dictionary", "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
1179 elem->type, name ? name : "(NULL)");
17973
acff371d7908 Fix crash when deleting buddies on Windows. This was done by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17968
diff changeset
1180 return NULL;
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
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1184 /** 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: 17321
diff changeset
1185 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1186 * @param name Name of element.
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1187 *
17384
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17383
diff changeset
1188 * @return guint Numeric representation of data, or 0 if could not be converted / not found.
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1189 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1190 * 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: 17321
diff changeset
1191 * 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: 17321
diff changeset
1192 * 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: 17321
diff changeset
1193 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1194 guint
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1195 msim_msg_get_integer(MsimMessage *msg, const gchar *name)
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1196 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1197 MsimMessageElement *elem;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1198
17331
9accf6d6cd61 Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17330
diff changeset
1199 elem = msim_msg_get(msg, name);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1200
17384
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17383
diff changeset
1201 if (!elem)
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17383
diff changeset
1202 return 0;
320b0b450c7b msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17383
diff changeset
1203
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1204 switch (elem->type)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1205 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1206 case MSIM_TYPE_INTEGER:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1207 return GPOINTER_TO_UINT(elem->data);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1208
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1209 case MSIM_TYPE_RAW:
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1210 case MSIM_TYPE_STRING:
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1211 /* TODO: find out if we need larger integers */
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1212 return (guint)atoi((gchar *)elem->data);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1213
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1214 default:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1215 return 0;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1216 }
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17321
diff changeset
1217 }
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1218
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1219 /** 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: 17331
diff changeset
1220 *
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1221 * @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: 17333
diff changeset
1222 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1223 * @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: 17333
diff changeset
1224 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1225 * @return TRUE if successful, FALSE if not.
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1226 */
17904
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1227 gboolean
38030f1a2e56 Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17384
diff changeset
1228 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: 17384
diff changeset
1229 gchar **binary_data, gsize *binary_length)
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1230 {
17338
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1231 MsimMessageElement *elem;
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1232
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1233 elem = msim_msg_get(msg, name);
17976
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1234 if (!elem)
b2d81d13f015 Be more careful about null strings in %s format specifier in debug messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17973
diff changeset
1235 return FALSE;
17338
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1236
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1237 switch (elem->type)
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1238 {
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1239 case MSIM_TYPE_RAW:
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1240 /* Incoming messages are tagged with MSIM_TYPE_RAW, and
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1241 * converted appropriately. They can still be "strings", just they won't
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1242 * be tagged as MSIM_TYPE_STRING (as MSIM_TYPE_STRING is intended to be used
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1243 * by msimprpl code for things like instant messages - stuff that should be
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1244 * escaped if needed). DWIM.
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1245 */
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1246
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1247 /* Previously, incoming messages were stored as MSIM_TYPE_STRING.
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1248 * This was fine for integers and strings, since they can easily be
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1249 * converted in msim_get_*, as desirable. However, it does not work
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1250 * well for binary strings. Consider:
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1251 *
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1252 * If incoming base64'd elements were tagged as MSIM_TYPE_STRING.
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1253 * msim_msg_get_binary() sees MSIM_TYPE_STRING, base64 decodes, returns.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1254 * everything is fine.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1255 * But then, msim_send() is called on the incoming message, which has
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1256 * a base64'd MSIM_TYPE_STRING that really is encoded binary. The values
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1257 * will be escaped since strings are escaped, and / becomes /2; no good.
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1258 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1259 */
17338
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1260 *binary_data = (gchar *)purple_base64_decode((const gchar *)elem->data, binary_length);
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1261 return TRUE;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1262
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1263 case MSIM_TYPE_BINARY:
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1264 {
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1265 GString *gs;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1266
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1267 gs = (GString *)elem->data;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1268
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1269 /* Duplicate data, so caller can g_free() it. */
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1270 *binary_data = g_new0(char, gs->len);
17338
d8afaaf24f34 Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17334
diff changeset
1271 memcpy(*binary_data, gs->str, gs->len);
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1272
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1273 *binary_length = gs->len;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1274
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1275 return TRUE;
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1276 }
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1277
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1278
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1279 /* 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: 17333
diff changeset
1280 * 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: 17333
diff changeset
1281 *
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1282 * return (GString *)elem->data; */
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1283
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1284 default:
17341
37499e926a42 Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17339
diff changeset
1285 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
1286 elem->type, name ? name : "(NULL)");
17334
af7083a8ada7 Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17333
diff changeset
1287 return FALSE;
17333
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1288 }
b9c0a8bb94b9 Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17331
diff changeset
1289 }