From Mariusz Okrój and Sebastien Vincent via https://bugs.wireshark.org/bugzilla...
[obnox/wireshark/wip.git] / epan / dissectors / packet-xmpp-conference.c
1 /* xmpp-conference.c
2  * Wireshark's XMPP dissector.
3  *
4  * XEP-0298: Delivering Conference Information to Jingle Participants (Coin)
5  *
6  * Copyright 2011, Mariusz Okroj <okrojmariusz[]gmail.com>
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <stdio.h>
35
36 #include <epan/proto.h>
37 #include <epan/packet.h>
38 #include <epan/packet_info.h>
39 #include <epan/epan.h>
40 #include <epan/expert.h>
41 #include <epan/dissectors/packet-xml.h>
42
43 #include <packet-xmpp.h>
44 #include <packet-xmpp-utils.h>
45 #include <packet-xmpp-conference.h>
46
47
48 static void xmpp_conf_desc(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
49 static void xmpp_conf_state(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
50 static void xmpp_conf_users(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
51 static void xmpp_conf_user(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
52 static void xmpp_conf_endpoint(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
53 static void xmpp_conf_media(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element);
54
55 void
56 xmpp_conferece_info_advert(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
57 {
58     proto_item *cinfo_item;
59     proto_tree *cinfo_tree;
60
61     attr_info attrs_info [] = {
62         {"xmlns", hf_xmpp_xmlns, TRUE, TRUE, NULL, NULL},
63         {"isfocus", -1, TRUE, TRUE, NULL, NULL}
64     };
65
66     cinfo_item = proto_tree_add_item(tree, hf_xmpp_conf_info, tvb, element->offset, element->length, 
67         ENC_BIG_ENDIAN);
68     cinfo_tree = proto_item_add_subtree(cinfo_item, ett_xmpp_conf_info);
69
70     display_attrs(cinfo_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
71     display_elems(cinfo_tree, element, pinfo, tvb, NULL, 0);
72 }
73
74 void
75 xmpp_conference_info(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
76 {
77     proto_item *cinfo_item;
78     proto_tree *cinfo_tree;
79
80     const gchar *state_enums[] = {"full", "partial", "deleted"};
81     array_t *state_array = ep_init_array_t(state_enums, array_length(state_enums));
82
83     attr_info attrs_info [] = {
84         {"xmlns", hf_xmpp_xmlns, TRUE, TRUE, NULL, NULL},
85         {"entity", -1, TRUE, TRUE, NULL, NULL},
86         {"state", -1, FALSE, TRUE, val_enum_list, state_array},
87         {"version", -1, FALSE, TRUE, NULL, NULL},
88         {"sid", hf_xmpp_conf_info_sid, FALSE, TRUE, NULL, NULL}
89     };
90
91     elem_info elems_info [] = {
92         {NAME, "conference-description", xmpp_conf_desc, ONE},
93         {NAME, "conference-state", xmpp_conf_state, ONE},
94         /*{NAME, "host-info", xmpp_conf_host_info, ONE},*/
95         {NAME, "users", xmpp_conf_users, ONE},
96         /*{NAME, "sidebars-by-ref", xmpp_conf_sidebars_by_ref, ONE},*/
97         /*{NAME, "sidebars-by-val", xmpp_conf_sidebars_by_val, ONE},*/
98     };
99
100     col_append_fstr(pinfo->cinfo, COL_INFO, "CONFERENC-INFO ");
101
102     cinfo_item = proto_tree_add_item(tree, hf_xmpp_conf_info, tvb, element->offset, element->length, 
103         ENC_BIG_ENDIAN);
104     cinfo_tree = proto_item_add_subtree(cinfo_item, ett_xmpp_conf_info);
105
106     display_attrs(cinfo_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
107     display_elems(cinfo_tree, element, pinfo, tvb, elems_info, array_length(elems_info));
108 }
109
110 static void
111 xmpp_conf_desc(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
112 {
113     proto_item *desc_item;
114     proto_tree *desc_tree;
115
116     attr_info attrs_info [] = {
117         {"subject", -1, FALSE, TRUE, NULL, NULL},
118         {"display-text", -1, FALSE, FALSE, NULL, NULL},
119         {"free-text", -1, FALSE, FALSE, NULL, NULL},
120         {"max-user-count", -1, FALSE, FALSE, NULL, NULL},
121     };
122
123 /*
124     elem_info elems_info [] = {
125         {NAME, "keywords", xmpp_conf_desc_keywords, ONE},
126         {NAME, "conf-uris", xmpp_conf_desc_conf_uris, ONE},
127         {NAME, "service-uris", xmpp_conf_desc_serv_uris, ONE},
128         {NAME, "available-media", xmpp_conf_desc_avil_media, ONE},
129     };
130 */
131
132     desc_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "CONFERENCE DESCRIPTION");
133     desc_tree = proto_item_add_subtree(desc_item, ett_xmpp_conf_desc);
134
135     change_elem_to_attrib("subject", "subject", element, transform_func_cdata);
136     change_elem_to_attrib("display-text", "display-text", element, transform_func_cdata);
137     change_elem_to_attrib("free-text", "free-text", element, transform_func_cdata);
138     change_elem_to_attrib("maximum-user-count", "max-user-count", element, transform_func_cdata);
139
140     display_attrs(desc_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
141     display_elems(desc_tree, element, pinfo, tvb, NULL,0);
142 }
143
144 static void
145 xmpp_conf_state(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
146 {
147     proto_item *state_item;
148     proto_tree *state_tree;
149
150     attr_info attrs_info [] = {
151         {"user-count", -1, FALSE, TRUE, NULL, NULL},
152         {"active", -1, FALSE, TRUE, NULL, NULL},
153         {"locked", -1, FALSE, TRUE, NULL, NULL}
154     };
155
156     state_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "CONFERENCE STATE");
157     state_tree = proto_item_add_subtree(state_item, ett_xmpp_conf_state);
158
159     change_elem_to_attrib("user-count", "user-count", element, transform_func_cdata);
160     change_elem_to_attrib("active", "active", element, transform_func_cdata);
161     change_elem_to_attrib("locked", "locked", element, transform_func_cdata);
162
163     display_attrs(state_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
164     display_elems(state_tree, element, pinfo, tvb, NULL,0);
165     
166 }
167
168 static void
169 xmpp_conf_users(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
170 {
171     proto_item *users_item;
172     proto_tree *users_tree;
173
174     attr_info attrs_info [] = {
175         {"state", -1, FALSE, TRUE, NULL, NULL}
176     };
177
178     elem_info elems_info [] = {
179         {NAME, "user", xmpp_conf_user, MANY}
180     };
181
182     users_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "USERS");
183     users_tree = proto_item_add_subtree(users_item, ett_xmpp_conf_users);   
184
185     display_attrs(users_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
186     display_elems(users_tree, element, pinfo, tvb, elems_info, array_length(elems_info));
187 }
188 static void
189 xmpp_conf_user(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
190 {
191     proto_item *user_item;
192     proto_tree *user_tree;
193
194     attr_info attrs_info [] = {
195         {"entity", -1, FALSE, TRUE, NULL, NULL},
196         {"state", -1, FALSE, TRUE, NULL, NULL},
197         {"display-text", -1, FALSE, TRUE, NULL, NULL},
198         {"cascaded-focus", -1, FALSE, TRUE, NULL, NULL}
199     };
200
201     elem_info elems_info [] = {
202         /*{NAME, "associated-aors", xmpp_conf_assoc_aors, ONE},*/
203         /*{NAME, "roles", xmpp_conf_roles, ONE},*/
204         /*{NAME, "languages", xmpp_conf_langs, ONE},*/
205         {NAME, "endpoint", xmpp_conf_endpoint, MANY},
206     };
207
208     user_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "USERS");
209     user_tree = proto_item_add_subtree(user_item, ett_xmpp_conf_user);
210
211     change_elem_to_attrib("display-text", "display-text", element, transform_func_cdata);
212     change_elem_to_attrib("cascaded-focus", "cascaded-focus", element, transform_func_cdata);
213
214     display_attrs(user_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
215     display_elems(user_tree, element, pinfo, tvb, elems_info, array_length(elems_info));
216 }
217
218 static void
219 xmpp_conf_endpoint(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
220 {
221     proto_item *endpoint_item;
222     proto_tree *endpoint_tree;
223
224     attr_info attrs_info [] = {
225         {"entity", -1, FALSE, TRUE, NULL, NULL},
226         {"state", -1, FALSE, TRUE, NULL, NULL},
227         {"display-text", -1, FALSE, TRUE, NULL, NULL},
228         {"status", -1, FALSE, TRUE, NULL, NULL},
229         {"joining-method", -1, FALSE, TRUE, NULL, NULL},
230         {"disconnection-method", -1, FALSE, TRUE, NULL, NULL},
231     };
232
233     elem_info elems_info [] = {
234         /*{NAME,"referred",...,ONE},*/
235         /*{NAME,"joining-info",...,ONE},*/
236         /*{NAME,"disconnection-info",...,ONE},*/
237         {NAME,"media", xmpp_conf_media, ONE},
238         /*{NAME,"call-info",...,ONE},*/
239
240     };
241
242     endpoint_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "ENDPOINT");
243     endpoint_tree = proto_item_add_subtree(endpoint_item, ett_xmpp_conf_endpoint);
244
245     change_elem_to_attrib("display-text", "display-text", element, transform_func_cdata);
246     change_elem_to_attrib("status", "status", element, transform_func_cdata);
247     change_elem_to_attrib("joining-method", "joining-method", element, transform_func_cdata);
248     change_elem_to_attrib("disconnection-method", "disconnection-method", element, transform_func_cdata);
249
250
251     display_attrs(endpoint_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
252     display_elems(endpoint_tree, element, pinfo, tvb, elems_info, array_length(elems_info));
253 }
254
255 static void
256 xmpp_conf_media(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, element_t *element)
257 {
258     proto_item *media_item;
259     proto_tree *media_tree;
260
261     attr_info attrs_info[] = {
262         {"id", -1, TRUE, TRUE, NULL, NULL},
263         {"display-text", -1, FALSE, TRUE, NULL, NULL},
264         {"type", -1, FALSE, TRUE, NULL, NULL},
265         {"label", -1, FALSE, TRUE, NULL, NULL},
266         {"src-id", -1, FALSE, TRUE, NULL, NULL},
267         {"status", -1, FALSE, TRUE, NULL, NULL},
268     };
269
270     media_item = proto_tree_add_text(tree, tvb, element->offset, element->length, "MEDIA");
271     media_tree = proto_item_add_subtree(media_item, ett_xmpp_conf_media);
272
273     change_elem_to_attrib("display-text", "display-text", element, transform_func_cdata);
274     change_elem_to_attrib("type", "type", element, transform_func_cdata);
275     change_elem_to_attrib("label", "label", element, transform_func_cdata);
276     change_elem_to_attrib("src-id", "src-id", element, transform_func_cdata);
277     change_elem_to_attrib("status", "status", element, transform_func_cdata);
278
279     display_attrs(media_tree, element, pinfo, tvb, attrs_info, array_length(attrs_info));
280     display_elems(media_tree, element, pinfo, tvb, NULL, 0);
281 }
282 /*
283 * Editor modelines - http://www.wireshark.org/tools/modelines.html
284 *
285 * Local variables:
286 * c-basic-offset: 4
287 * tab-width: 8
288 * indent-tabs-mode: nil
289 * End:
290 *
291 * ex: set shiftwidth=4 tabstop=8 expandtab:
292 * :indentSize=4:tabSize=8:noTabs=true:
293 */