2011-11-12 10:51:01 +00:00
|
|
|
/* xmpp-utils.h
|
|
|
|
*
|
|
|
|
* Copyright 2011, Mariusz Okroj <okrojmariusz[]gmail.com>
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-11-12 10:51:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XMPP_UTILS_H
|
|
|
|
#define XMPP_UTILS_H
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
2013-03-29 17:43:14 +00:00
|
|
|
#include "tvbuff.h"
|
|
|
|
#include "dissectors/packet-xml.h"
|
2013-03-01 23:53:11 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
#define xmpp_elem_cdata(elem) \
|
2011-11-12 10:51:01 +00:00
|
|
|
elem->data?elem->data->value:""
|
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_array_t
|
2011-11-12 10:51:01 +00:00
|
|
|
{
|
|
|
|
gpointer data;
|
|
|
|
gint length;
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_array_t;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_attr_t{
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *value;
|
|
|
|
const gchar *name;
|
2011-11-12 10:51:01 +00:00
|
|
|
gint offset;
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
gboolean was_read;
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_attr_t;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_data_t{
|
2011-11-12 10:51:01 +00:00
|
|
|
gchar *value;
|
|
|
|
|
|
|
|
gint offset;
|
|
|
|
gint length;
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_data_t;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_element_t{
|
2011-11-12 10:51:01 +00:00
|
|
|
gchar* name;
|
2011-11-13 23:33:47 +00:00
|
|
|
|
2011-11-12 10:51:01 +00:00
|
|
|
/*abbreviation that apprears before tag name (<nos:x .../>)
|
|
|
|
if abbrev doesn't appear then NULL*/
|
|
|
|
gchar* default_ns_abbrev;
|
|
|
|
/*pair of namespace abbrev and namespace*/
|
|
|
|
GHashTable *namespaces;
|
|
|
|
|
|
|
|
GHashTable *attrs;
|
|
|
|
GList *elements;
|
2011-11-13 23:33:47 +00:00
|
|
|
xmpp_data_t *data;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
gint offset;
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
gboolean was_read;
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_element_t;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*informations about attributes that are displayed in proto tree*/
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_attr_info{
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *name;
|
2011-11-12 10:51:01 +00:00
|
|
|
gint hf;
|
|
|
|
gboolean is_required;
|
|
|
|
gboolean in_short_list;
|
|
|
|
|
|
|
|
/*function validates this attribute
|
|
|
|
it may impose other restrictions (e.g. validating atribut's name, ...)*/
|
2012-12-26 05:57:06 +00:00
|
|
|
void (*val_func)(packet_info *pinfo, proto_item *item, const gchar *name, const gchar *value, gconstpointer data);
|
2011-11-12 10:51:01 +00:00
|
|
|
gpointer data;
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_attr_info;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_attr_info_ext{
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar* ns;
|
2011-11-13 23:33:47 +00:00
|
|
|
xmpp_attr_info info;
|
|
|
|
} xmpp_attr_info_ext;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef enum _xmpp_elem_info_type{
|
2011-11-12 10:51:01 +00:00
|
|
|
NAME,
|
|
|
|
ATTR,
|
|
|
|
NAME_AND_ATTR,
|
|
|
|
NAMES
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_elem_info_type;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef enum _xmpp_elem_info_occurrence
|
2011-11-12 10:51:01 +00:00
|
|
|
{
|
|
|
|
ONE,MANY
|
2011-11-13 23:33:47 +00:00
|
|
|
} xmpp_elem_info_occurrence;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*informations about elements that are displayed in proto tree*/
|
2011-11-13 23:33:47 +00:00
|
|
|
typedef struct _xmpp_elem_info{
|
|
|
|
xmpp_elem_info_type type;
|
2012-12-26 05:57:06 +00:00
|
|
|
gconstpointer data;
|
2011-11-12 10:51:01 +00:00
|
|
|
/*function that displays element in tree*/
|
2011-11-13 23:33:47 +00:00
|
|
|
void (*elem_func)(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo, xmpp_element_t* element);
|
|
|
|
xmpp_elem_info_occurrence occurrence;
|
|
|
|
} xmpp_elem_info;
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
typedef struct _xmpp_conv_info_t {
|
|
|
|
emem_tree_t *req_resp;
|
|
|
|
emem_tree_t *jingle_sessions;
|
|
|
|
emem_tree_t *ibb_sessions;
|
|
|
|
emem_tree_t *gtalk_sessions;
|
2012-07-28 03:09:46 +00:00
|
|
|
guint32 ssl_start;
|
|
|
|
guint32 ssl_proceed;
|
2011-11-12 10:51:01 +00:00
|
|
|
} xmpp_conv_info_t;
|
|
|
|
|
|
|
|
/** Struct conatins frame numbers (request frame(IQ set/get) and
|
|
|
|
* response frame(IQ result/error)).
|
|
|
|
*/
|
|
|
|
typedef struct _xmpp_reqresp_transaction_t {
|
|
|
|
guint32 req_frame;
|
|
|
|
guint32 resp_frame;
|
|
|
|
} xmpp_transaction_t;
|
|
|
|
|
|
|
|
/** Function that is responsibe for request/response tracking in IQ packets.
|
|
|
|
* Each IQ set/get packet should have the response in other IQ result/error packet.
|
|
|
|
* Both packet should have the same id attribute. Function saves in emem_tree pairs of
|
|
|
|
* packet id and struct xmpp_transaction_t.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_iq_reqresp_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function that is responsibe for jingle session tracking in IQ packets.
|
|
|
|
* Function saves in emem_tree pairs of packet's id and Jingle session's id.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_jingle_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function that is responsibe for ibb(in band bytestreams) session tracking in IQ packets.
|
|
|
|
* Function saves in emem_tree pairs of packet's id and In-Band Bytestreams session's id.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_ibb_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function that is responsibe for GTalk session(voice/video) tracking in IQ packets.
|
|
|
|
* Function saves in emem_tree pairs of packet's id and GTalk session's id.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_gtalk_session_track(packet_info *pinfo, xmpp_element_t *packet, xmpp_conv_info_t *xmpp_info);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function detects unrecognized elements and displays them in tree.
|
|
|
|
* It uses ett_unknown to display packets. ett_unknown has const size described by
|
2011-11-13 23:33:47 +00:00
|
|
|
* ETT_UNKNOWN_LEN in packet-xmpp.h
|
2011-11-12 10:51:01 +00:00
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_unknown(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_unknown_attrs(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element, gboolean displ_short_list);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Displays CDATA from element in tree. You can use your own header field hf or
|
|
|
|
* pass -1. If you pass -1 then CDATA will be display as text(proto_tree_add_text):
|
|
|
|
* ELEMENT_NAME: CDATA
|
|
|
|
* ELEMENT_NAME = element->name, if element is empty CDATA = "(empty)"
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_cdata(proto_tree *tree, tvbuff_t *tvb, xmpp_element_t *element, gint hf);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function is similar to xmpp_cdata. But it display items only as a text and it is
|
|
|
|
* compatibile with function display_elems
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_simple_cdata_elem(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, xmpp_element_t *element);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/** Converts xml_frame_t struct to xmpp_element_t. Should be call with parent==NULL.
|
2011-11-12 10:51:01 +00:00
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern xmpp_element_t* xmpp_xml_frame_to_element_t(xml_frame_t *xml_frame, xmpp_element_t *parent, tvbuff_t *tvb);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/** Frees all GLib structs in xmpp_element_t struct. Should be call only for root element.
|
2011-11-12 10:51:01 +00:00
|
|
|
* It works recursively.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_element_t_tree_free(xmpp_element_t *root);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/** Allocs ephemeral memory for xmpp_array_t struct.*/
|
|
|
|
extern xmpp_array_t* xmpp_ep_init_array_t(const gchar** array, gint len);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/*Allocs ephemeral memory for xmpp_attr_t struct*/
|
2012-12-26 05:57:06 +00:00
|
|
|
extern xmpp_attr_t* xmpp_ep_init_attr_t(const gchar *value, gint offset, gint length);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Allocs ephemeral memory for upcased string*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern gchar* xmpp_ep_string_upcase(const gchar* string);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/*Compares 2 xmpp_element_t struct by names. Returns value is similar to the returned by strcmp*/
|
|
|
|
extern gint xmpp_element_t_cmp(gconstpointer a, gconstpointer b);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Searches child element in parent element by name. GList element is returned.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern GList* xmpp_find_element_by_name(xmpp_element_t *packet,const gchar *name);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** steal_*
|
|
|
|
* Functions searches and marks as read found elements.
|
|
|
|
* If element is set as read, it is invisible for these functions.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
|
|
|
|
extern xmpp_element_t* xmpp_steal_element_by_name(xmpp_element_t *packet, const gchar *name);
|
|
|
|
extern xmpp_element_t* xmpp_steal_element_by_names(xmpp_element_t *packet, const gchar **names, gint names_len);
|
|
|
|
extern xmpp_element_t* xmpp_steal_element_by_attr(xmpp_element_t *packet, const gchar *attr_name, const gchar *attr_value);
|
|
|
|
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);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Returns first child in element*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern xmpp_element_t* xmpp_get_first_element(xmpp_element_t *packet);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Converts element to string. Returns memory allocated as ephemeral.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern gchar* xmpp_element_to_string(tvbuff_t *tvb, xmpp_element_t *element);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Converts attribute to string. Returns memory allocated as ephemeral.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern gchar* xmpp_attr_to_string(tvbuff_t *tvb, xmpp_attr_t *attr);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/* Returns attribute by name and set as read. If attrib is set as read, it may be found
|
|
|
|
* one more time, but it is invisible for function xmpp_unknown_attrib*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern xmpp_attr_t* xmpp_get_attr(xmpp_element_t *element, const gchar* attr_name);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Function hides first element in tree.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_proto_tree_hide_first_child(proto_tree *tree);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Function shows first element in tree.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_proto_tree_show_first_child(proto_tree *tree);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Function returns item as text. Memory is allocated as ephemeral.*/
|
|
|
|
extern gchar* proto_item_get_text(proto_item *item);
|
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/*Function returns struct that contains 3 strings. It is used to build xmpp_attr_info struct.*/
|
2012-12-26 05:57:06 +00:00
|
|
|
extern gpointer xmpp_name_attr_struct(const gchar *name, const gchar *attr_name, const gchar *attr_value);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function displays attributes from element in way described in attrs.
|
|
|
|
* Elements that doesn't exist in attrs are displayed as text.
|
2011-11-13 23:33:47 +00:00
|
|
|
* In XMPP_ATTR_INFO struct you can define several things:
|
2011-11-12 10:51:01 +00:00
|
|
|
* - is_in_short_list - attribute should be displayed in short list e.g. ELEMENT_NAME [ATTR1='value' ATTR2='value']
|
|
|
|
* - is_required - attribute is required. If attribute doesn't appear then EXPERT INFO will be displayed
|
|
|
|
* - val_func - validate function
|
|
|
|
* - data - data passes to the val_func
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_display_attrs(proto_tree *tree, xmpp_element_t *element, packet_info *pinfo, tvbuff_t *tvb, xmpp_attr_info *attrs, guint n);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/** Function does the same as shown above. It takes attrs(XMPP_ATTR_INFO_EXT) argument
|
|
|
|
* that contains XMPP_ATTR_INFO struct and string with namespace. It is used when packet
|
2011-11-12 10:51:01 +00:00
|
|
|
* contains several namespaces and each attribute belongs to particular namespace.
|
|
|
|
* E.g.
|
2013-04-30 00:55:03 +00:00
|
|
|
* @code
|
2011-11-12 10:51:01 +00:00
|
|
|
* <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
|
|
|
|
* mechanism='PLAIN'
|
|
|
|
* xmlns:ga='http://www.google.com/talk/protocol/auth'
|
|
|
|
* ga:client-uses-full-bind-result='true'>
|
|
|
|
* </auth>
|
2013-04-30 00:55:03 +00:00
|
|
|
* @endcode
|
2011-11-12 10:51:01 +00:00
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
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);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
2011-11-13 23:33:47 +00:00
|
|
|
/** Displays elements from parent element in a way described in elems(XMPP_ELEM_INFO).
|
|
|
|
* XMPP_ELEM_INFO describes how to find particular element and what action should be done
|
2011-11-12 10:51:01 +00:00
|
|
|
* for this element.
|
|
|
|
* Function calls xmpp_unknown.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_display_elems(proto_tree *tree, xmpp_element_t *parent, packet_info *pinfo, tvbuff_t *tvb, xmpp_elem_info *elems, guint n);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/* Validates attribute value. Takes string array(gchar**) in parameter data.
|
2011-11-13 23:33:47 +00:00
|
|
|
* Is used in XMPP_ATTR_INFO struct.
|
2011-11-12 10:51:01 +00:00
|
|
|
*/
|
2012-12-26 05:57:06 +00:00
|
|
|
extern void xmpp_val_enum_list(packet_info *pinfo, proto_item *item, const gchar *name, const gchar *value, gconstpointer data);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** Function changes element to attribute. It searches element by name in parent element,
|
|
|
|
* next it create attribute using transform_func and inserts it to parent attributes hash table
|
|
|
|
* using attr_name as key.
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
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));
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/** transform_func that creates attribute with element's cdata as value
|
|
|
|
*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern xmpp_attr_t* xmpp_transform_func_cdata(xmpp_element_t *elem);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
/*Copys keys and values from one hash table to another.
|
|
|
|
Hash tables must be initialized.*/
|
2011-11-13 23:33:47 +00:00
|
|
|
extern void xmpp_copy_hash_table(GHashTable *src, GHashTable *dst);
|
2011-11-12 10:51:01 +00:00
|
|
|
|
|
|
|
#endif /* XMPP_UTILS_H */
|