3 * Copyright 2011, Mariusz Okroj <okrojmariusz[]gmail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "ws_symbol_export.h"
31 #include "dissectors/packet-xml.h"
33 #define xmpp_elem_cdata(elem) \
34 elem->data?elem->data->value:""
36 typedef struct _xmpp_array_t
42 typedef struct _xmpp_attr_t{
51 typedef struct _xmpp_data_t{
58 typedef struct _xmpp_element_t{
61 /*abbreviation that apprears before tag name (<nos:x .../>)
62 if abbrev doesn't appear then NULL*/
63 gchar* default_ns_abbrev;
64 /*pair of namespace abbrev and namespace*/
65 GHashTable *namespaces;
77 /*informations about attributes that are displayed in proto tree*/
78 typedef struct _xmpp_attr_info{
82 gboolean in_short_list;
84 /*function validates this attribute
85 it may impose other restrictions (e.g. validating atribut's name, ...)*/
86 void (*val_func)(packet_info *pinfo, proto_item *item, const gchar *name, const gchar *value, gconstpointer data);
90 typedef struct _xmpp_attr_info_ext{
95 typedef enum _xmpp_elem_info_type{
100 } xmpp_elem_info_type;
102 typedef enum _xmpp_elem_info_occurrence
105 } xmpp_elem_info_occurrence;
107 /*informations about elements that are displayed in proto tree*/
108 typedef struct _xmpp_elem_info{
109 xmpp_elem_info_type type;
111 /*function that displays element in tree*/
112 void (*elem_func)(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo, xmpp_element_t* element);
113 xmpp_elem_info_occurrence occurrence;
116 typedef struct _xmpp_conv_info_t {
117 emem_tree_t *req_resp;
118 emem_tree_t *jingle_sessions;
119 emem_tree_t *ibb_sessions;
120 emem_tree_t *gtalk_sessions;
125 /** Struct conatins frame numbers (request frame(IQ set/get) and
126 * response frame(IQ result/error)).
128 typedef struct _xmpp_reqresp_transaction_t {
131 } xmpp_transaction_t;
133 /** Function that is responsibe for request/response tracking in IQ packets.
134 * Each IQ set/get packet should have the response in other IQ result/error packet.
135 * Both packet should have the same id attribute. Function saves in emem_tree pairs of
136 * packet id and struct xmpp_transaction_t.
138 extern void xmpp_iq_reqresp_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
140 /** Function that is responsibe for jingle session tracking in IQ packets.
141 * Function saves in emem_tree pairs of packet's id and Jingle session's id.
143 extern void xmpp_jingle_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
145 /** Function that is responsibe for ibb(in band bytestreams) session tracking in IQ packets.
146 * Function saves in emem_tree pairs of packet's id and In-Band Bytestreams session's id.
148 extern void xmpp_ibb_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
150 /** Function that is responsibe for GTalk session(voice/video) tracking in IQ packets.
151 * Function saves in emem_tree pairs of packet's id and GTalk session's id.
153 extern void xmpp_gtalk_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
155 /** Function detects unrecognized elements and displays them in tree.
156 * It uses ett_unknown to display packets. ett_unknown has const size described by
157 * ETT_UNKNOWN_LEN in packet-xmpp.h
159 extern void xmpp_unknown(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element);
161 extern void xmpp_unknown_attrs(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element, gboolean displ_short_list);
163 /** Displays CDATA from element in tree. You can use your own header field hf or
164 * pass -1. If you pass -1 then CDATA will be display as text(proto_tree_add_text):
165 * ELEMENT_NAME: CDATA
166 * ELEMENT_NAME = element->name, if element is empty CDATA = "(empty)"
168 extern void xmpp_cdata(proto_tree *tree, tvbuff_t *tvb, xmpp_element_t *element, gint hf);
170 /** Function is similar to xmpp_cdata. But it display items only as a text and it is
171 * compatibile with function display_elems
173 extern void xmpp_simple_cdata_elem(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element);
175 /** Converts xml_frame_t struct to xmpp_element_t. Should be call with parent==NULL.
177 extern xmpp_element_t* xmpp_xml_frame_to_element_t(xml_frame_t *xml_frame, xmpp_element_t *parent, tvbuff_t *tvb);
179 /** Frees all GLib structs in xmpp_element_t struct. Should be call only for root element.
180 * It works recursively.
182 extern void xmpp_element_t_tree_free(xmpp_element_t *root);
184 /** Allocs ephemeral memory for xmpp_array_t struct.*/
185 extern xmpp_array_t* xmpp_ep_init_array_t(const gchar** array, gint len);
187 /*Allocs ephemeral memory for xmpp_attr_t struct*/
188 extern xmpp_attr_t* xmpp_ep_init_attr_t(const gchar *value, gint offset, gint length);
190 /*Allocs ephemeral memory for upcased string*/
191 extern gchar* xmpp_ep_string_upcase(const gchar* string);
193 /*Compares 2 xmpp_element_t struct by names. Returns value is similar to the returned by strcmp*/
194 extern gint xmpp_element_t_cmp(gconstpointer a, gconstpointer b);
196 /*Searches child element in parent element by name. GList element is returned.*/
197 extern GList* xmpp_find_element_by_name(xmpp_element_t *packet,const gchar *name);
200 * Functions searches and marks as read found elements.
201 * If element is set as read, it is invisible for these functions.*/
203 extern xmpp_element_t* xmpp_steal_element_by_name(xmpp_element_t *packet, const gchar *name);
204 extern xmpp_element_t* xmpp_steal_element_by_names(xmpp_element_t *packet, const gchar **names, gint names_len);
205 extern xmpp_element_t* xmpp_steal_element_by_attr(xmpp_element_t *packet, const gchar *attr_name, const gchar *attr_value);
206 extern xmpp_element_t* xmpp_steal_element_by_name_and_attr(xmpp_element_t *packet, const gchar *name, const gchar *attr_name, const gchar *attr_value);
208 /*Returns first child in element*/
209 extern xmpp_element_t* xmpp_get_first_element(xmpp_element_t *packet);
211 /*Converts element to string. Returns memory allocated as ephemeral.*/
212 extern gchar* xmpp_element_to_string(tvbuff_t *tvb, xmpp_element_t *element);
214 /*Converts attribute to string. Returns memory allocated as ephemeral.*/
215 extern gchar* xmpp_attr_to_string(tvbuff_t *tvb, xmpp_attr_t *attr);
217 /* Returns attribute by name and set as read. If attrib is set as read, it may be found
218 * one more time, but it is invisible for function xmpp_unknown_attrib*/
219 extern xmpp_attr_t* xmpp_get_attr(xmpp_element_t *element, const gchar* attr_name);
221 /*Function hides first element in tree.*/
222 extern void xmpp_proto_tree_hide_first_child(proto_tree *tree);
224 /*Function shows first element in tree.*/
225 extern void xmpp_proto_tree_show_first_child(proto_tree *tree);
227 /*Function returns item as text. Memory is allocated as ephemeral.*/
228 extern gchar* proto_item_get_text(proto_item *item);
230 /*Function returns struct that contains 3 strings. It is used to build xmpp_attr_info struct.*/
231 extern gpointer xmpp_name_attr_struct(const gchar *name, const gchar *attr_name, const gchar *attr_value);
233 /** Function displays attributes from element in way described in attrs.
234 * Elements that doesn't exist in attrs are displayed as text.
235 * In XMPP_ATTR_INFO struct you can define several things:
236 * - is_in_short_list - attribute should be displayed in short list e.g. ELEMENT_NAME [ATTR1='value' ATTR2='value']
237 * - is_required - attribute is required. If attribute doesn't appear then EXPERT INFO will be displayed
238 * - val_func - validate function
239 * - data - data passes to the val_func
241 extern void xmpp_display_attrs(proto_tree *tree, xmpp_element_t *element, packet_info *pinfo, tvbuff_t *tvb, xmpp_attr_info *attrs, guint n);
243 /** Function does the same as shown above. It takes attrs(XMPP_ATTR_INFO_EXT) argument
244 * that contains XMPP_ATTR_INFO struct and string with namespace. It is used when packet
245 * contains several namespaces and each attribute belongs to particular namespace.
248 * <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
250 * xmlns:ga='http://www.google.com/talk/protocol/auth'
251 * ga:client-uses-full-bind-result='true'>
255 extern void xmpp_display_attrs_ext(proto_tree *tree, xmpp_element_t *element, packet_info *pinfo, tvbuff_t *tvb, xmpp_attr_info_ext *attrs, guint n);
257 /** Displays elements from parent element in a way described in elems(XMPP_ELEM_INFO).
258 * XMPP_ELEM_INFO describes how to find particular element and what action should be done
260 * Function calls xmpp_unknown.
262 extern void xmpp_display_elems(proto_tree *tree, xmpp_element_t *parent, packet_info *pinfo, tvbuff_t *tvb, xmpp_elem_info *elems, guint n);
264 /* Validates attribute value. Takes string array(gchar**) in parameter data.
265 * Is used in XMPP_ATTR_INFO struct.
267 extern void xmpp_val_enum_list(packet_info *pinfo, proto_item *item, const gchar *name, const gchar *value, gconstpointer data);
269 /** Function changes element to attribute. It searches element by name in parent element,
270 * next it create attribute using transform_func and inserts it to parent attributes hash table
271 * using attr_name as key.
273 extern void xmpp_change_elem_to_attrib(const gchar *elem_name, const gchar *attr_name, xmpp_element_t *parent, xmpp_attr_t* (*transform_func)(xmpp_element_t *element));
275 /** transform_func that creates attribute with element's cdata as value
277 extern xmpp_attr_t* xmpp_transform_func_cdata(xmpp_element_t *elem);
279 /*Copys keys and values from one hash table to another.
280 Hash tables must be initialized.*/
281 extern void xmpp_copy_hash_table(GHashTable *src, GHashTable *dst);
283 #endif /* XMPP_UTILS_H */