Mercurial > pidgin.yaz
annotate libpurple/protocols/myspace/message.c @ 17333:b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Fri, 01 Jun 2007 05:28:46 +0000 |
parents | 9accf6d6cd61 |
children | af7083a8ada7 |
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 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
5 * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im> |
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); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
27 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, gchar *sep, gchar *begin, gchar *end); |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
28 static gchar *msim_msg_element_as_string(MsimMessageElement *elem); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
29 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
30 MsimMessage *msim_msg_new(void) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
31 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
32 /* Just an empty list. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
33 return NULL; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
34 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
35 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
36 /** Free an individual message element. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
37 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
|
38 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
39 MsimMessageElement *elem; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
40 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
41 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
42 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
43 switch (elem->type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
44 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
45 case MSIM_TYPE_BOOLEAN: /* Fall through */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
46 case MSIM_TYPE_INTEGER: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
47 /* Integer value stored in gpointer - no need to free(). */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
48 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
49 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
50 case MSIM_TYPE_STRING: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
51 /* Always free strings - caller should have g_strdup()'d if |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
52 * string was static or temporary and not to be freed. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
53 g_free(elem->data); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
54 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
55 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
56 case MSIM_TYPE_BINARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
57 /* Free the GString itself and the binary data. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
58 g_string_free((GString *)elem->data, TRUE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
59 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
60 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
61 case MSIM_TYPE_DICTIONARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
62 /* TODO: free dictionary */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
63 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
64 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
65 case MSIM_TYPE_LIST: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
66 /* TODO: free list */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
67 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
68 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
69 default: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
70 purple_debug_info("msim", "msim_msg_free_element: not freeing unknown type %d\n", |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
71 elem->type); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
72 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
73 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
74 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
75 g_free(elem); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
76 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
77 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
78 /** Free a complete message. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
79 void msim_msg_free(MsimMessage *msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
80 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
81 if (!msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
82 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
83 /* already free as can be */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
84 return; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
85 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
86 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
87 g_list_foreach(msg, msim_msg_free_element, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
88 g_list_free(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
89 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
90 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
91 /** Send an existing MsimMessage. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
92 gboolean msim_msg_send(MsimSession *session, MsimMessage *msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
93 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
94 gchar *raw; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
95 gboolean success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
96 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
97 raw = msim_msg_pack(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
98 success = msim_send_raw(session, raw); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
99 g_free(raw); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
100 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
101 return success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
102 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
103 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
104 /** |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
105 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
106 * 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
|
107 * variable arguments. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
108 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
109 * @param session |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
110 * @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
|
111 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
112 * 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
|
113 * 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
|
114 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
115 * 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
|
116 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
117 */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
118 gboolean msim_send(MsimSession *session, ...) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
119 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
120 va_list argp; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
121 gchar *key, *value; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
122 MsimMessageType type; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
123 gboolean success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
124 MsimMessage *msg; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
125 GString *gs; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
126 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
127 msg = msim_msg_new(); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
128 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
129 /* Read key, type, value triplets until NULL. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
130 va_start(argp, session); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
131 do |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
132 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
133 key = va_arg(argp, gchar *); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
134 if (!key) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
135 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
136 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
137 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
138 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
139 type = va_arg(argp, int); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
140 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
141 /* Interpret variadic arguments. */ |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
142 switch (type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
143 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
144 case MSIM_TYPE_INTEGER: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
145 msg = msim_msg_append(msg, key, type, GUINT_TO_POINTER(va_arg(argp, int))); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
146 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
147 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
148 case MSIM_TYPE_STRING: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
149 value = va_arg(argp, char *); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
150 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
151 g_return_val_if_fail(value != NULL, FALSE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
152 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
153 msg = msim_msg_append(msg, key, type, value); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
154 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
155 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
156 case MSIM_TYPE_BINARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
157 gs = va_arg(argp, GString *); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
158 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
159 g_return_val_if_fail(gs != NULL, FALSE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
160 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
161 /* msim_msg_free() will free this GString the caller created. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
162 msg = msim_msg_append(msg, key, type, gs); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
163 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
164 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
165 default: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
166 purple_debug_info("msim", "msim_send: unknown type %d\n", type); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
167 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
168 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
169 } while(key); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
170 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
171 /* Actually send the message. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
172 success = msim_msg_send(session, msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
173 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
174 /* Cleanup. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
175 va_end(argp); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
176 msim_msg_free(msg); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
177 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
178 return success; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
179 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
180 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
181 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
182 /** Append a new element to a message. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
183 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
184 * @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
|
185 * @param type An MSIM_TYPE_* code. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
186 * @param data Pointer to data, see below. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
187 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
188 * @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
|
189 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
190 * msg = msim_msg_append(msg, ...) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
191 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
192 * The data parameter depends on the type given: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
193 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
194 * * MSIM_TYPE_INTEGER: Use GUINT_TO_POINTER(x). |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
195 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
196 * * 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
|
197 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
198 * * 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
|
199 * |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
200 * * 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
|
201 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
202 * * MSIM_TYPE_DICTIONARY: TODO |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
203 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
204 * * MSIM_TYPE_LIST: TODO |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
205 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
206 * */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
207 MsimMessage *msim_msg_append(MsimMessage *msg, gchar *name, MsimMessageType type, gpointer data) |
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 MsimMessageElement *elem; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
210 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
211 elem = g_new0(MsimMessageElement, 1); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
212 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
213 elem->name = name; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
214 elem->type = type; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
215 elem->data = data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
216 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
217 return g_list_append(msg, elem); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
218 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
219 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
220 /** Pack a string using the given GFunc and seperator. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
221 * Used by msim_msg_debug_string() and msim_msg_pack(). |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
222 */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
223 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, gchar *sep, gchar *begin, gchar *end) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
224 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
225 gchar **strings; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
226 gchar **strings_tmp; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
227 gchar *joined; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
228 gchar *final; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
229 int i; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
230 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
231 g_return_val_if_fail(msg != NULL, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
232 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
233 /* Add one for NULL terminator for g_strjoinv(). */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
234 strings = (gchar **)g_new0(gchar *, g_list_length(msg) + 1); |
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 strings_tmp = strings; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
237 g_list_foreach(msg, gf, &strings_tmp); |
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 joined = g_strjoinv(sep, strings); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
240 final = g_strconcat(begin, joined, end, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
241 g_free(joined); |
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 /* Clean up. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
244 for (i = 0; i < g_list_length(msg); ++i) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
245 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
246 g_free(strings[i]); |
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 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
249 g_free(strings); |
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 return final; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
252 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
253 /** Store a human-readable string describing the element. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
254 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
255 * @param data Pointer to an MsimMessageElement. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
256 * @param user_data |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
257 */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
258 static void msim_msg_debug_string_element(gpointer data, gpointer user_data) |
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 MsimMessageElement *elem; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
261 gchar *string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
262 GString *gs; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
263 gchar *binary; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
264 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
|
265 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
266 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
267 items = user_data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
268 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
269 switch (elem->type) |
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 case MSIM_TYPE_INTEGER: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
272 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
|
273 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
274 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
275 case MSIM_TYPE_STRING: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
276 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
|
277 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
278 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
279 case MSIM_TYPE_BINARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
280 gs = (GString *)elem->data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
281 binary = purple_base64_encode((guchar*)gs->str, gs->len); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
282 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
|
283 g_free(binary); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
284 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
285 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
286 case MSIM_TYPE_BOOLEAN: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
287 string = g_strdup_printf("%s(boolean): %s", elem->name, |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
288 GPOINTER_TO_UINT(elem->data) ? "TRUE" : "FALSE"); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
289 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
290 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
291 case MSIM_TYPE_DICTIONARY: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
292 /* TODO: provide human-readable output of dictionary. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
293 string = g_strdup_printf("%s(dict): TODO", elem->name); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
294 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
295 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
296 case MSIM_TYPE_LIST: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
297 /* TODO: provide human-readable output of list. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
298 string = g_strdup_printf("%s(list): TODO", elem->name); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
299 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
300 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
301 default: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
302 string = g_strdup_printf("%s(unknown type %d)", elem->name, elem->type); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
303 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
304 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
305 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
306 **items = string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
307 ++(*items); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
308 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
309 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
310 /** Return a human-readable string of the message. |
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 * @return A string. Caller must g_free(). |
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 gchar *msim_msg_debug_string(MsimMessage *msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
315 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
316 if (!msg) |
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 g_strdup("<MsimMessage: empty>"); |
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 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
321 return msim_msg_pack_using(msg, msim_msg_debug_string_element, "\n", "<MsimMessage: \n", ">"); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
322 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
323 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
324 /** Return a message element data as a new string, converting from other types (integer, etc.) if necessary. |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
325 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
326 * @return gchar * The data as a string, or NULL. Caller must g_free(). |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
327 */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
328 static gchar *msim_msg_element_as_string(MsimMessageElement *elem) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
329 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
330 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
|
331 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
332 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
|
333 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
|
334 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
335 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
|
336 /* 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
|
337 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
|
338 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
339 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
|
340 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
341 GString *gs; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
342 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
343 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
|
344 /* 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
|
345 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
|
346 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
347 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
348 case MSIM_TYPE_BOOLEAN: |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
349 /* These strings are not actually used by the wire protocol |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
350 * -- see msim_msg_pack_element. */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
351 return g_strdup(GPOINTER_TO_UINT(elem->data) ? "True" : "False"); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
352 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
353 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
|
354 /* 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
|
355 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
356 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
357 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
|
358 /* 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
|
359 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
360 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
361 default: |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
362 purple_debug_info("msim", "field %s, unknown type %d\n", elem->name, elem->type); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
363 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
364 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
365 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
366 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
367 /** Pack an element into its protocol representation. |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
368 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
369 * @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
|
370 * @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
|
371 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
372 * 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
|
373 * 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
|
374 * 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
|
375 * 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
|
376 */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
377 static void msim_msg_pack_element(gpointer data, gpointer user_data) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
378 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
379 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
|
380 gchar *string, *data_string; |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
381 gchar ***items; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
382 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
383 elem = (MsimMessageElement *)data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
384 items = user_data; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
385 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
386 data_string = msim_msg_element_as_string(elem); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
387 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
388 switch (elem->type) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
389 { |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
390 /* These types are represented by key name/value pairs. */ |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
391 case MSIM_TYPE_INTEGER: |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 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
|
396 string = g_strconcat("%s", "\\", data_string, NULL); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
397 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
398 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
399 /* Boolean is represented by absence or presence of name. */ |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
400 case MSIM_TYPE_BOOLEAN: |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
401 if (GPOINTER_TO_UINT(elem->data)) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
402 { |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
403 /* True - leave in, with blank value. */ |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
404 string = g_strdup_printf("%s\\\\", elem->name); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
405 } else { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
406 /* False - leave out. */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
407 string = g_strdup(""); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
408 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
409 break; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
410 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
411 default: |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
412 g_free(data_string); |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
413 g_return_if_fail(FALSE); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
414 break; |
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 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
417 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
|
418 |
17321
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
419 **items = string; |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
420 ++(*items); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
421 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
422 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
423 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
424 /** Return a packed string suitable for sending over the wire. |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
425 * |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
426 * @return A string. Caller must g_free(). |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
427 */ |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
428 gchar *msim_msg_pack(MsimMessage *msg) |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
429 { |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
430 g_return_val_if_fail(msg != NULL, NULL); |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
431 |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
432 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
|
433 } |
ddcf9ef2ccec
Add MsimMessage implementation (sending only).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff
changeset
|
434 |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
435 /** |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
436 * 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
|
437 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
438 * @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
|
439 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
440 * @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
|
441 */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
442 MsimMessage *msim_parse(gchar *raw) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
443 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
444 MsimMessage *msg; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
445 gchar *token; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
446 gchar **tokens; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
447 gchar *key; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
448 gchar *value; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
449 int i; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
450 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
451 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
|
452 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
453 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
|
454 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
455 key = NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
456 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
457 /* 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
|
458 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
|
459 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
460 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
|
461 "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
|
462 /* 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
|
463 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
464 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
|
465 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
466 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
467 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
468 msg = msim_msg_new(); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
469 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
470 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
|
471 (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
|
472 i++) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
473 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
474 #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
|
475 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
|
476 #endif |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
477 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
|
478 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
479 /* Odd-numbered ordinal is a value. */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
480 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
481 /* Note: returns 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
|
482 value = msim_unescape(token); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
483 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
484 /* Always append strings, since protocol has no incoming |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
485 * type information for each field. */ |
17330
dc7ed2ecf0cb
Fix msim_parse() to correctly parse into an MsimMessage *.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17323
diff
changeset
|
486 msg = msim_msg_append(msg, g_strdup(key), MSIM_TYPE_STRING, value); |
17323
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
487 #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
|
488 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
|
489 #endif |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
490 } else { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
491 /* 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
|
492 key = token; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
493 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
494 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
495 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
|
496 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
497 /* 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
|
498 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
|
499 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
500 return msg; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
501 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
502 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
503 /** |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
504 * 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
|
505 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
506 * @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
|
507 * 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
|
508 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
509 * @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
|
510 */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
511 GHashTable *msim_parse_body(const gchar *body_str) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
512 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
513 GHashTable *table; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
514 gchar *item; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
515 gchar **items; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
516 gchar **elements; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
517 guint i; |
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 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
|
520 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
521 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
|
522 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
523 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
|
524 (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
|
525 i++) |
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 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
|
528 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
529 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
|
530 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
531 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
|
532 if (!key) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
533 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
534 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
|
535 body_str); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
536 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
|
537 break; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
538 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
539 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
540 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
|
541 if (!value) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
542 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
543 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
|
544 body_str); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
545 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
|
546 break; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
547 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
548 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
549 #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
|
550 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
|
551 #endif |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
552 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
553 /* 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
|
554 /* 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
|
555 * 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
|
556 * 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
|
557 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
|
558 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
559 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
|
560 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
561 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
562 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
|
563 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
564 return table; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
565 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
566 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
567 /** 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
|
568 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
569 * @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
|
570 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
571 * @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
|
572 * |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
573 * 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
|
574 * 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
|
575 * 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
|
576 */ |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
577 MsimMessageElement *msim_msg_get(MsimMessage *msg, 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
|
578 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
579 GList *i; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
580 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
581 /* Linear search for the given name. O(n) but n is small. */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
582 for (i = g_list_first(msg); i != NULL; i = g_list_next(msg)) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
583 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
584 MsimMessageElement *elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
585 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
586 elem = i->data; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
587 g_return_val_if_fail(elem != NULL, NULL); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
588 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
589 if (strcmp(elem->name, name) == 0) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
590 return elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
591 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
592 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
593 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
594 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
595 /** 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
|
596 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
597 * @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
|
598 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
599 * @return gchar * The message string. Caller must g_free(). |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
600 */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
601 gchar *msim_msg_get_string(MsimMessage *msg, gchar *name) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
602 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
603 MsimMessageElement *elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
604 |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
605 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
|
606 if (!elem) |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
607 return NULL; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
608 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
609 return msim_msg_element_as_string(elem); |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
610 } |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
611 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
612 /** 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
|
613 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
614 * @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
|
615 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
616 * @return guint Numeric representation of data, or 0 if could not be converted. |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
617 * |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
618 * 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
|
619 * 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
|
620 * 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
|
621 */ |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
622 guint msim_msg_get_integer(MsimMessage *msg, gchar *name) |
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 MsimMessageElement *elem; |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
625 |
17331
9accf6d6cd61
Change msim_msg_get_element to msim_msg_get.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17330
diff
changeset
|
626 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
|
627 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
628 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
|
629 { |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
630 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
|
631 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
|
632 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
633 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
|
634 /* 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
|
635 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
|
636 |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
637 default: |
793301c04e3a
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17321
diff
changeset
|
638 return 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 } |
17333
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
641 |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
642 /** 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
|
643 * |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
644 * @return GString * of binary data, or NULL. |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
645 */ |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
646 GString *msim_msg_get_binary(MsimMessage *msg, gchar *name) |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
647 { |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
648 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
|
649 { |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
650 case MSIM_TYPE_BINARY: |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
651 return (GString *)elem->data; |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
652 |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
653 default: |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
654 return NULL; |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
655 } |
b9c0a8bb94b9
Add msim_msg_get_binary() - retrieves binary data values from an MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
17331
diff
changeset
|
656 } |