Mercurial > pidgin.yaz
annotate libpurple/protocols/myspace/message.c @ 17937:231b87b76da4
In debug messages, don't output unknown elem->type fields as %c too (only as
%d), so that utf-8 errors do not occur.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Thu, 05 Jul 2007 06:10:30 +0000 |
parents | 3aed9c8c6af7 |
children | c109b7f1c739 |
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 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
25 static void msim_msg_free_element(gpointer data, gpointer user_data); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
26 static void msim_msg_debug_string_element(gpointer data, gpointer user_data); |
17383
f057837085b0
Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17375
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 static MsimMessage *msim_msg_new_v(va_list argp); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
31 |
17359
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
32 /** 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
|
33 * |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
34 * @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
|
35 * @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
|
36 * |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
37 * 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
|
38 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
39 MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
40 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
|
41 { |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
42 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
|
43 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
44 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
|
45 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
46 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
|
47 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
|
48 else |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
49 return NULL; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
50 } |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
51 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
52 /** 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
|
53 * |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
54 * @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
|
55 * @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
|
56 * |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
57 * 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
|
58 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
59 static MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
60 msim_msg_new_v(va_list argp) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
61 { |
17359
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
62 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
|
63 MsimMessageType type; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
64 GString *gs; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
65 MsimMessage *msg; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
66 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
67 /* 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
|
68 msg = NULL; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
69 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
70 /* 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
|
71 do |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
72 { |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
73 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
|
74 if (!key) |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
75 { |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
76 break; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
77 } |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
78 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
79 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
|
80 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
81 /* 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
|
82 switch (type) |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
83 { |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 break; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
88 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
89 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
|
90 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
|
91 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
92 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
|
93 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
94 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
|
95 break; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
96 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
97 case MSIM_TYPE_BINARY: |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
98 gs = va_arg(argp, GString *); |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
99 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
100 g_return_val_if_fail(gs != NULL, FALSE); |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
101 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
102 /* msim_msg_free() will free this GString the caller created. */ |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
103 msg = msim_msg_append(msg, key, type, gs); |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
104 break; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
105 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
106 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
|
107 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
|
108 break; |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
109 } |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
110 } while(key); |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
111 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
|
112 |
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
113 return msg; |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
114 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
115 |
17359
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
116 |
17348
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
117 /** 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
|
118 * |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
119 * @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
|
120 * @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
|
121 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
122 static void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
123 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
|
124 { |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
125 MsimMessageElement *elem; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
126 MsimMessage **new; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
127 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
|
128 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
129 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
|
130 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
|
131 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
132 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
|
133 { |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 break; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
138 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 break; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
143 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
144 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
|
145 { |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
146 GString *gs; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
147 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
148 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
|
149 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
150 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
|
151 } |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
152 break; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
153 /* TODO: other types */ |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 } |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
158 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
159 /* 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
|
160 * 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
|
161 *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
|
162 } |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
163 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
164 /** 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
|
165 * |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
166 * @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
|
167 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
168 MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
169 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
|
170 { |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
171 MsimMessage *new; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
172 |
17368
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
173 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
|
174 return NULL; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
175 |
17359
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
176 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
|
177 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
178 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
|
179 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
180 return new; |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
181 } |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
182 |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
183 /** 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
|
184 * |
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
185 * @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
|
186 * @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
|
187 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
188 static void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
189 msim_msg_free_element(gpointer data, gpointer user_data) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
190 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
191 MsimMessageElement *elem; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
192 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
193 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
194 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
195 switch (elem->type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
196 { |
17348
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
197 case MSIM_TYPE_BOOLEAN: |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
198 case MSIM_TYPE_INTEGER: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
199 /* Integer value stored in gpointer - no need to free(). */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
200 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
201 |
17348
d8903e1320a9
Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17342
diff
changeset
|
202 case MSIM_TYPE_RAW: |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
203 case MSIM_TYPE_STRING: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
204 /* Always free strings - caller should have g_strdup()'d if |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
205 * string was static or temporary and not to be freed. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
206 g_free(elem->data); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
207 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
208 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
209 case MSIM_TYPE_BINARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
210 /* Free the GString itself and the binary data. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
211 g_string_free((GString *)elem->data, TRUE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
212 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
213 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
214 case MSIM_TYPE_DICTIONARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
215 /* TODO: free dictionary */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
216 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
217 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
218 case MSIM_TYPE_LIST: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
219 /* TODO: free list */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
220 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
221 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
222 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
|
223 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
|
224 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
225 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
226 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
227 g_free(elem); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
228 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
229 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
230 /** 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
|
231 void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
232 msim_msg_free(MsimMessage *msg) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
233 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
234 if (!msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
235 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
236 /* already free as can be */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
237 return; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
238 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
239 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
240 g_list_foreach(msg, msim_msg_free_element, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
241 g_list_free(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
242 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
243 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
244 /** 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
|
245 gboolean |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
246 msim_msg_send(MsimSession *session, MsimMessage *msg) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
247 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
248 gchar *raw; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
249 gboolean success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
250 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
251 raw = msim_msg_pack(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
252 success = msim_send_raw(session, raw); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
253 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
|
254 |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
255 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
|
256 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
257 return success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
258 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
259 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
260 /** |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
261 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
262 * 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
|
263 * variable arguments. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
264 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
265 * @param session |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
266 * @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
|
267 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
268 * 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
|
269 * 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
|
270 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
271 * 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
|
272 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
273 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
274 gboolean |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
275 msim_send(MsimSession *session, ...) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
276 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
277 gboolean success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
278 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
|
279 va_list argp; |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
280 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
281 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
|
282 msg = msim_msg_new_v(argp); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
283 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
284 /* Actually send the message. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
285 success = msim_msg_send(session, msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
286 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
287 /* Cleanup. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
288 msim_msg_free(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
289 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
290 return success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
291 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
292 |
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
|
293 /** 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
|
294 * |
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
|
295 * 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
|
296 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
297 static MsimMessageElement * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
298 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
|
299 { |
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
|
300 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
|
301 |
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
|
302 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
|
303 |
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
|
304 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
|
305 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
|
306 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
|
307 |
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
|
308 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
|
309 } |
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
|
310 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
311 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
312 /** Append a new element to a message. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
313 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
314 * @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
|
315 * @param type An MSIM_TYPE_* code. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
316 * @param data Pointer to data, see below. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
317 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
318 * @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
|
319 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
320 * msg = msim_msg_append(msg, ...) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
321 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
322 * The data parameter depends on the type given: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
323 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
324 * * MSIM_TYPE_INTEGER: Use GUINT_TO_POINTER(x). |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
325 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
326 * * 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
|
327 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
328 * * 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
|
329 * |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
330 * * 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
|
331 * |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
332 * * 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
|
333 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
334 * * MSIM_TYPE_DICTIONARY: TODO |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
335 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
336 * * MSIM_TYPE_LIST: TODO |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
337 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
338 * */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
339 MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
340 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
|
341 MsimMessageType type, gpointer data) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
342 { |
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
|
343 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
|
344 } |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
345 |
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
|
346 /** 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
|
347 * |
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
|
348 * @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
|
349 * 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
|
350 * |
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
|
351 * 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
|
352 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
353 MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
354 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
|
355 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
|
356 { |
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
|
357 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
|
358 GList *node_before; |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
359 |
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
|
360 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
|
361 |
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
|
362 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
|
363 |
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
|
364 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
|
365 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
366 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
367 /** 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
|
368 * Used by msim_msg_dump() and msim_msg_pack(). |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
369 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
370 gchar * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
371 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
|
372 const gchar *begin, const gchar *end) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
373 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
374 gchar **strings; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
375 gchar **strings_tmp; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
376 gchar *joined; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
377 gchar *final; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
378 int i; |
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 g_return_val_if_fail(msg != NULL, NULL); |
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 /* Add one for NULL terminator for g_strjoinv(). */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
383 strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1); |
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 strings_tmp = strings; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
386 g_list_foreach(msg, gf, &strings_tmp); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
387 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
388 joined = g_strjoinv(sep, strings); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
389 final = g_strconcat(begin, joined, end, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
390 g_free(joined); |
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 /* Clean up. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
393 for (i = 0; i < g_list_length(msg); ++i) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
394 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
395 g_free(strings[i]); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
396 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
397 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
398 g_free(strings); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
399 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
400 return final; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
401 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
402 /** Store a human-readable string describing the element. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
403 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
404 * @param data Pointer to an MsimMessageElement. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
405 * @param user_data |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
406 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
407 static void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
408 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
|
409 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
410 MsimMessageElement *elem; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
411 gchar *string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
412 GString *gs; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
413 gchar *binary; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
414 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
|
415 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
416 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
417 items = user_data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
418 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
419 switch (elem->type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
420 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
421 case MSIM_TYPE_INTEGER: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
422 string = g_strdup_printf("%s(integer): %d", elem->name, GPOINTER_TO_UINT(elem->data)); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
423 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
424 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
425 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
|
426 string = g_strdup_printf("%s(raw): %s", elem->name, (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
|
427 break; |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
428 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
429 case MSIM_TYPE_STRING: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
430 string = g_strdup_printf("%s(string): %s", elem->name, (gchar *)elem->data); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
431 break; |
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 case MSIM_TYPE_BINARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
434 gs = (GString *)elem->data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
435 binary = purple_base64_encode((guchar*)gs->str, gs->len); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
436 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
|
437 g_free(binary); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
438 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
439 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
440 case MSIM_TYPE_BOOLEAN: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
441 string = g_strdup_printf("%s(boolean): %s", elem->name, |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
442 GPOINTER_TO_UINT(elem->data) ? "TRUE" : "FALSE"); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
443 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
444 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
445 case MSIM_TYPE_DICTIONARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
446 /* TODO: provide human-readable output of dictionary. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
447 string = g_strdup_printf("%s(dict): TODO", elem->name); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
448 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
449 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
450 case MSIM_TYPE_LIST: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
451 /* TODO: provide human-readable output of list. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
452 string = g_strdup_printf("%s(list): TODO", elem->name); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
453 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
454 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
455 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
|
456 string = g_strdup_printf("%s(unknown type %d", elem->name, elem->type); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
457 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
458 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
459 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
460 **items = string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
461 ++(*items); |
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 |
17355
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
464 /** 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
|
465 * |
17355
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
466 * @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
|
467 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
468 void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
469 msim_msg_dump(const gchar *fmt_string, MsimMessage *msg) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
470 { |
17355
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
471 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
|
472 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
473 if (!msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
474 { |
17355
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
475 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
|
476 } else { |
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
477 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
|
478 "\n", "<MsimMessage: \n", "\n/MsimMessage>"); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
479 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
480 |
17355
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
481 purple_debug_info("msim", fmt_string, 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
|
482 |
9c5b1dc7404f
Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17351
diff
changeset
|
483 g_free(debug_str); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
484 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
485 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
486 /** 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
|
487 * |
17383
f057837085b0
Change to use const gchar * where appropriate.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17375
diff
changeset
|
488 * @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
|
489 * |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
490 * 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
|
491 * 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
|
492 * 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
|
493 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
494 static gchar * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
495 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
|
496 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
497 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
|
498 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
499 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
|
500 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
|
501 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
502 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
|
503 /* 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
|
504 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
|
505 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
506 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
|
507 /* Strings get escaped. msim_escape() creates a new string. */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
508 return msim_escape((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
|
509 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
510 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
|
511 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
512 GString *gs; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
513 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
514 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
|
515 /* 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
|
516 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
|
517 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
518 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
519 case MSIM_TYPE_BOOLEAN: |
17368
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
520 /* Not used by the wire protocol * -- see msim_msg_pack_element. */ |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
521 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
|
522 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
523 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
|
524 /* TODO: pack using k=v\034k2=v2\034... */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
525 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
526 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
527 case MSIM_TYPE_LIST: |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
528 /* TODO: pack using a|b|c|d|... */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
529 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
530 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
531 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
|
532 purple_debug_info("msim", "field %s, unknown type %d\n", elem->name, 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
|
533 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
534 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
535 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
536 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
537 /** Pack an element into its protocol representation. |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
538 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
539 * @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
|
540 * @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
|
541 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
542 * 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
|
543 * 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
|
544 * 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
|
545 * 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
|
546 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
547 static void |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
548 msim_msg_pack_element(gpointer data, gpointer user_data) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
549 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
550 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
|
551 gchar *string, *data_string; |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
552 gchar ***items; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
553 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
554 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
555 items = user_data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
556 |
17368
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
557 /* 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
|
558 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
|
559 { |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
560 return; |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
561 } |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
562 |
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
563 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
|
564 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
565 switch (elem->type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
566 { |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
567 /* 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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 case MSIM_TYPE_LIST: |
17338
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
574 string = g_strconcat(elem->name, "\\", data_string, NULL); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
575 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
576 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
577 /* Boolean is represented by absence or presence of name. */ |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
578 case MSIM_TYPE_BOOLEAN: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
579 if (GPOINTER_TO_UINT(elem->data)) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
580 { |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
581 /* True - leave in, with blank value. */ |
17375
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
582 string = g_strdup_printf("%s\\", elem->name); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
583 } else { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
584 /* False - leave out. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
585 string = g_strdup(""); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
586 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
587 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
588 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
589 default: |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
590 g_free(data_string); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
591 g_return_if_fail(FALSE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
592 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
593 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
594 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
595 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
|
596 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
597 **items = string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
598 ++(*items); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
599 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
600 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
601 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
602 /** Return a packed string suitable for sending over the wire. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
603 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
604 * @return A string. Caller must g_free(). |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
605 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
606 gchar * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
607 msim_msg_pack(MsimMessage *msg) |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
608 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
609 g_return_val_if_fail(msg != NULL, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
610 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
611 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
|
612 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
613 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
614 /** |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
615 * 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
|
616 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
617 * @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
|
618 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
619 * @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
|
620 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
621 MsimMessage * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
622 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
|
623 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
624 MsimMessage *msg; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
625 gchar *token; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
626 gchar **tokens; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
627 gchar *key; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
628 gchar *value; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
629 int i; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
630 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
631 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
|
632 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
633 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
|
634 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
635 key = NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
636 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
637 /* 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
|
638 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
|
639 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
640 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
|
641 "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
|
642 /* 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
|
643 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
644 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
|
645 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
646 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
647 |
17359
d69bcd74c240
Enhance msim_msg_new() to accept a variadic arguments, like msim_send(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17358
diff
changeset
|
648 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
|
649 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
650 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
|
651 (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
|
652 i++) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
653 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
654 #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
|
655 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
|
656 #endif |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
657 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
|
658 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
659 /* Odd-numbered ordinal is a value. */ |
17342
4f54e8c41086
Cosmetic improvement to MsimMessage debug output.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17341
diff
changeset
|
660 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
661 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
|
662 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
663 /* 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
|
664 * 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
|
665 * 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
|
666 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
|
667 #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
|
668 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
|
669 #endif |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
670 } else { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
671 /* 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
|
672 key = token; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
673 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
674 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
675 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
|
676 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
677 /* 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
|
678 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
|
679 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
680 return msg; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
681 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
682 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
683 /** |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
684 * 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
|
685 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
686 * @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
|
687 * 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
|
688 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
689 * @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
|
690 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
691 GHashTable * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
692 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
|
693 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
694 GHashTable *table; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
695 gchar *item; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
696 gchar **items; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
697 gchar **elements; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
698 guint i; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
699 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
700 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
|
701 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
702 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
|
703 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
704 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
|
705 (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
|
706 i++) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
707 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
708 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
|
709 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
710 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
|
711 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
712 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
|
713 if (!key) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
714 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
715 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
|
716 body_str); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
717 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
|
718 break; |
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 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
721 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
|
722 if (!value) |
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 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
|
725 body_str); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
726 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
|
727 break; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
728 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
729 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
730 #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
|
731 purple_debug_info("msim", "-- %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
|
732 #endif |
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 /* 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
|
735 /* 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
|
736 * 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
|
737 * 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
|
738 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
|
739 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
740 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
|
741 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
742 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
743 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
|
744 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
745 return table; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
746 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
747 |
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
|
748 /** 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
|
749 * |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
750 * @param msg Message to search within. |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
751 * @param name Field name to search for. |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
752 * |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
753 * @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
|
754 * |
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
|
755 * 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
|
756 * access the MsimMessageElement *, instead of the GList * container. |
17375
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
757 * |
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
|
758 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
759 static GList * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
760 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
|
761 { |
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
|
762 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
|
763 |
17375
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
764 if (!name) |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
765 { |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
766 return NULL; |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
767 } |
7abd1eca3d18
Bug fixes in MsimMessage:
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17368
diff
changeset
|
768 |
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
|
769 /* 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
|
770 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
|
771 { |
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
|
772 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
|
773 |
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
|
774 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
|
775 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
|
776 |
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
|
777 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
|
778 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
|
779 } |
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
|
780 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
|
781 } |
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
|
782 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
783 /** 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
|
784 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
785 * @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
|
786 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
787 * @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
|
788 * |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
789 * 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
|
790 * 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
|
791 * 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
|
792 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
793 MsimMessageElement * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
794 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
|
795 { |
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
|
796 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
|
797 |
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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
804 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
805 /** 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
|
806 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
807 * @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
|
808 * |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
809 * @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
|
810 * |
17368
3720176bdac6
Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17359
diff
changeset
|
811 * 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
|
812 * 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
|
813 * 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
|
814 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
815 gchar * |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
816 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
|
817 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
818 MsimMessageElement *elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
819 |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
820 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
|
821 if (!elem) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
822 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
823 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
824 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
|
825 { |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
826 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
|
827 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
|
828 |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
829 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
|
830 /* 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
|
831 * be escaped. */ |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
832 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
|
833 |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
834 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
|
835 /* 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
|
836 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
|
837 |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
838 default: |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
839 purple_debug_info("msim", "msim_msg_get_string: type %d unknown, name %s\n", |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
840 elem->type, name); |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
841 return NULL; |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
842 } |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
843 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
844 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
845 /** 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
|
846 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
847 * @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
|
848 * |
17384
320b0b450c7b
msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17383
diff
changeset
|
849 * @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
|
850 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
851 * 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
|
852 * 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
|
853 * 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
|
854 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
855 guint |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
856 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
|
857 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
858 MsimMessageElement *elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
859 |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
860 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
|
861 |
17384
320b0b450c7b
msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17383
diff
changeset
|
862 if (!elem) |
320b0b450c7b
msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17383
diff
changeset
|
863 return 0; |
320b0b450c7b
msim_msg_get_integer() - if could not find element, return 0.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17383
diff
changeset
|
864 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
865 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
|
866 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
867 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
|
868 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
|
869 |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
870 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
|
871 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
|
872 /* 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
|
873 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
|
874 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
875 default: |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
876 return 0; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
877 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
878 } |
17333
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
879 |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
880 /** 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
|
881 * |
17334
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
882 * @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
|
883 * |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
884 * @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
|
885 * |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
886 * @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
|
887 */ |
17904
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
888 gboolean |
38030f1a2e56
Split return type and function name + arguments on to separate lines, to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17384
diff
changeset
|
889 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
|
890 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
|
891 { |
17338
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
892 MsimMessageElement *elem; |
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
893 |
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
894 elem = msim_msg_get(msg, name); |
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
895 |
17333
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
896 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
|
897 { |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
898 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
|
899 /* 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
|
900 * 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
|
901 * 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
|
902 * 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
|
903 * 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
|
904 */ |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
905 |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
906 /* 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
|
907 * 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
|
908 * 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
|
909 * 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
|
910 * |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
911 * 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
|
912 * 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
|
913 * 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
|
914 * 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
|
915 * 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
|
916 * 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
|
917 * |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
918 */ |
17338
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
919 *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
|
920 return TRUE; |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
921 |
17333
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
922 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
|
923 { |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
924 GString *gs; |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
925 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
926 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
|
927 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
928 /* 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
|
929 *binary_data = g_new0(char, gs->len); |
17338
d8afaaf24f34
Trivial fixes to clean up MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17334
diff
changeset
|
930 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
|
931 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
932 *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
|
933 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
934 return TRUE; |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
935 } |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
936 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
937 |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
938 /* 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
|
939 * 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
|
940 * |
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
941 * 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
|
942 |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
943 default: |
17341
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
944 purple_debug_info("msim", "msim_msg_get_binary: unhandled type %d for key %s\n", |
37499e926a42
Add new MsimMessage element type, MSIM_TYPE_RAW, for fields in incoming
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17339
diff
changeset
|
945 elem->type, name); |
17334
af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17333
diff
changeset
|
946 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
|
947 } |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
948 } |