aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-xml.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2006-07-07 00:45:54 +0000
committerGerald Combs <gerald@wireshark.org>2006-07-07 00:45:54 +0000
commit7976c442db7d58ee9be01679597952074f5c5b46 (patch)
tree7510059331b05daa1e1a8109aa7e8f686aef3949 /epan/dissectors/packet-xml.c
parent1f4873db0be82e0e119204532ee40be433cdc805 (diff)
Fix a few format string bugs found by Ilja van Sprundel.
svn path=/trunk/; revision=18677
Diffstat (limited to 'epan/dissectors/packet-xml.c')
-rw-r--r--epan/dissectors/packet-xml.c376
1 files changed, 188 insertions, 188 deletions
diff --git a/epan/dissectors/packet-xml.c b/epan/dissectors/packet-xml.c
index 88e97822c1..ec49b2e3bd 100644
--- a/epan/dissectors/packet-xml.c
+++ b/epan/dissectors/packet-xml.c
@@ -54,33 +54,33 @@
#include <epan/prefs.h>
typedef struct _xml_ns_t {
- /* the name of this namespace */
+ /* the name of this namespace */
gchar* name;
-
- /* its fully qualified name */
+
+ /* its fully qualified name */
gchar* fqn;
/* the contents of the whole element from <> to </> */
int hf_tag;
-
+
/* chunks of cdata from <> to </> excluding sub tags */
int hf_cdata;
-
+
/* the subtree for its sub items */
gint ett;
GHashTable* attributes;
/* key: the attribute name
value: hf_id of what's between quotes */
-
+
/* the namespace's namespaces */
GHashTable* elements;
/* key: the element name
value: the child namespace */
-
+
GPtrArray* element_names;
/* imported directly from the parser and used while building the namespace */
-
+
} xml_ns_t;
typedef struct {
@@ -131,38 +131,38 @@ GArray* hf_arr;
GArray* ett_arr;
static const gchar* default_media_types[] = {
- "text/xml",
- "text/vnd.wap.wml",
- "text/vnd.wap.si",
- "text/vnd.wap.sl",
- "text/vnd.wap.co",
- "text/vnd.wap.emn",
- "application/auth-policy+xml",
+ "text/xml",
+ "text/vnd.wap.wml",
+ "text/vnd.wap.si",
+ "text/vnd.wap.sl",
+ "text/vnd.wap.co",
+ "text/vnd.wap.emn",
+ "application/auth-policy+xml",
"application/cpim-pidf+xml",
"application/cpl+xml",
- "application/mathml+xml",
+ "application/mathml+xml",
"application/pidf+xml",
"application/poc-settings+xml",
- "application/rdf+xml",
+ "application/rdf+xml",
"application/reginfo+xml",
"application/resource-lists+xml",
"application/rlmi+xml",
"application/rls-services+xml",
- "application/smil",
+ "application/smil",
"application/simple-filter+xml",
- "application/soap+xml",
- "application/vnd.wv.csp+xml",
+ "application/soap+xml",
+ "application/vnd.wv.csp+xml",
"application/vnd.wv.csp.xml",
"application/watcherinfo+xml",
- "application/xcap-att+xml",
- "application/xcap-caps+xml",
- "application/xcap-el+xml",
- "application/xcap-error+xml",
- "application/xml",
- "application/xml-dtd",
+ "application/xcap-att+xml",
+ "application/xcap-caps+xml",
+ "application/xcap-el+xml",
+ "application/xcap-error+xml",
+ "application/xml",
+ "application/xml-dtd",
"application/xpidf+xml",
- "application/xslt+xml",
- "image/svg+xml",
+ "application/xslt+xml",
+ "image/svg+xml",
};
static void
@@ -177,10 +177,10 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/XML");
if(!tree) return;
-
+
if (stack != NULL)
g_ptr_array_free(stack,TRUE);
-
+
stack = g_ptr_array_new();
current_frame = ep_alloc(sizeof(xml_frame_t));
g_ptr_array_add(stack,current_frame);
@@ -189,22 +189,22 @@ dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
current_frame->start_offset = 0;
root_ns = NULL;
-
+
if (pinfo->match_string)
root_ns = g_hash_table_lookup(media_types,pinfo->match_string);
-
+
if (! root_ns ) {
root_ns = &xml_ns;
}
-
+
current_frame->ns = root_ns;
-
+
current_frame->item = proto_tree_add_item(tree,current_frame->ns->hf_tag,tvb,0,-1,FALSE);
current_frame->tree = proto_item_add_subtree(current_frame->item,current_frame->ns->ett);
current_frame->last_item = current_frame->item;
-
+
while(( tok = tvbparse_get(tt, want) )) ;
-}
+}
static gboolean dissect_xml_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
if ( pref_heuristic && tvbparse_peek(tvbparse_init(tvb,0,-1,NULL,want_ignore), want_heur)) {
@@ -228,9 +228,9 @@ static void after_token(void* tvbparse_data, const void* wanted_data _U_, tvbpar
} else {
hfid = xml_ns.hf_cdata;
}
-
+
pi = proto_tree_add_item(current_frame->tree, hfid, tok->tvb, tok->offset, tok->len, FALSE);
-
+
proto_item_set_text(pi, "%s",
tvb_format_text(tok->tvb,tok->offset,tok->len));
}
@@ -246,7 +246,7 @@ static void before_xmpli(void* tvbparse_data, const void* wanted_data _U_, tvbpa
int hf_tag;
gint ett;
-
+
g_strdown(name);
if (!ns) {
hf_tag = hf_xmlpi;
@@ -255,13 +255,13 @@ static void before_xmpli(void* tvbparse_data, const void* wanted_data _U_, tvbpa
hf_tag = ns->hf_tag;
ett = ns->ett;
}
-
+
pi = proto_tree_add_item(current_frame->tree,hf_tag,tok->tvb,tok->offset,tok->len,FALSE);
-
- proto_item_set_text(pi,tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
-
+
+ proto_item_set_text(pi, "%s", tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
+
pt = proto_item_add_subtree(pi,ett);
-
+
current_frame = ep_alloc(sizeof(xml_frame_t));
current_frame->item = pi;
current_frame->last_item = pi;
@@ -270,17 +270,17 @@ static void before_xmpli(void* tvbparse_data, const void* wanted_data _U_, tvbpa
current_frame->ns = ns;
g_ptr_array_add(stack,current_frame);
-
+
}
static void after_xmlpi(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
GPtrArray* stack = tvbparse_data;
xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
-
+
proto_tree_add_text(current_frame->tree,
tok->tvb, tok->offset, tok->len,
tvb_format_text(tok->tvb,tok->offset,tok->len));
-
+
if (stack->len > 1) {
g_ptr_array_remove_index_fast(stack,stack->len - 1);
} else {
@@ -303,28 +303,28 @@ static void before_tag(void* tvbparse_data, const void* wanted_data _U_, tvbpars
tvbparse_elem_t* root_tok = name_tok->sub->sub;
tvbparse_elem_t* leaf_tok = name_tok->sub->sub->next->next;
xml_ns_t* nameroot_ns;
-
+
root_name = tvb_get_ephemeral_string(root_tok->tvb,root_tok->offset,root_tok->len);
name = tvb_get_ephemeral_string(leaf_tok->tvb,leaf_tok->offset,leaf_tok->len);
-
+
nameroot_ns = g_hash_table_lookup(xml_ns.elements,root_name);
-
+
if(nameroot_ns) {
ns = g_hash_table_lookup(nameroot_ns->elements,name);
if (!ns) {
- ns = &unknown_ns;
+ ns = &unknown_ns;
}
} else {
ns = &unknown_ns;
}
-
+
} else {
name = tvb_get_ephemeral_string(name_tok->tvb,name_tok->offset,name_tok->len);
g_strdown(name);
if(current_frame->ns) {
ns = g_hash_table_lookup(current_frame->ns->elements,name);
-
+
if (!ns) {
if (! ( ns = g_hash_table_lookup(root_ns->elements,name) ) ) {
ns = &unknown_ns;
@@ -336,10 +336,10 @@ static void before_tag(void* tvbparse_data, const void* wanted_data _U_, tvbpars
}
pi = proto_tree_add_item(current_frame->tree,ns->hf_tag,tok->tvb,tok->offset,tok->len,FALSE);
- proto_item_set_text(pi,tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
-
+ proto_item_set_text(pi, "%s", tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
+
pt = proto_item_add_subtree(pi,ns->ett);
-
+
new_frame = ep_alloc(sizeof(xml_frame_t));
new_frame->item = pi;
new_frame->last_item = pi;
@@ -362,13 +362,13 @@ static void after_closed_tag(void* tvbparse_data, const void* wanted_data _U_, t
GPtrArray* stack = tvbparse_data;
xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
- proto_item_append_text(current_frame->last_item,"/>");
+ proto_item_append_text(current_frame->last_item,"/>");
if (stack->len > 1) {
g_ptr_array_remove_index_fast(stack,stack->len - 1);
} else {
proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Closing an unopened tag ]");
- }
+ }
}
static void after_untag(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok){
@@ -376,7 +376,7 @@ static void after_untag(void* tvbparse_data, const void* wanted_data _U_, tvbpar
xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
proto_item_set_len(current_frame->item, (tok->offset - current_frame->start_offset) + tok->len);
-
+
proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"%s",
tvb_format_text(tok->tvb,tok->offset,tok->len));
@@ -394,7 +394,7 @@ static void before_dtd_doctype(void* tvbparse_data, const void* wanted_data _U_,
tvbparse_elem_t* name_tok = tok->sub->next->next->next->sub->sub;
proto_tree* dtd_item = proto_tree_add_item(current_frame->tree, hf_doctype,
name_tok->tvb, name_tok->offset, name_tok->len, FALSE);
-
+
proto_item_set_text(dtd_item,"%s",tvb_format_text(tok->tvb,tok->offset,tok->len));
current_frame = ep_alloc(sizeof(xml_frame_t));
@@ -416,13 +416,13 @@ static void pop_stack(void* tvbparse_data, const void* wanted_data _U_, tvbparse
} else {
proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,
"[ ERROR: Closing an unopened tag ]");
- }
+ }
}
static void after_dtd_close(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok){
GPtrArray* stack = tvbparse_data;
xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
-
+
proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"%s",
tvb_format_text(tok->tvb,tok->offset,tok->len));
if (stack->len > 1) {
@@ -451,7 +451,7 @@ static void after_attrib(void* tvbparse_data, const void* wanted_data _U_, tvbpa
hfid = hf_unknowwn_attrib;
value = tok;
}
-
+
current_frame->last_item = proto_tree_add_item(current_frame->tree,hfid,value->tvb,value->offset,value->len,FALSE);
proto_item_set_text(current_frame->last_item, "%s", tvb_format_text(tok->tvb,tok->offset,tok->len));
@@ -460,56 +460,56 @@ static void after_attrib(void* tvbparse_data, const void* wanted_data _U_, tvbpa
static void unrecognized_token(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok _U_){
GPtrArray* stack = tvbparse_data;
xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
-
+
proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Unrecognized text ]");
}
-static void init_xml_parser(void) {
+static void init_xml_parser(void) {
tvbparse_wanted_t* want_name = tvbparse_chars(-1,1,0,"abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",NULL,NULL,NULL);
tvbparse_wanted_t* want_attr_name = tvbparse_chars(-1,1,0,"abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:",NULL,NULL,NULL);
-
+
tvbparse_wanted_t* want_scoped_name = tvbparse_set_seq(XML_SCOPED_NAME, NULL, NULL, NULL,
want_name,
tvbparse_char(-1,":",NULL,NULL,NULL),
want_name,
NULL);
-
+
tvbparse_wanted_t* want_tag_name = tvbparse_set_oneof(0, NULL, NULL, NULL,
want_scoped_name,
want_name,
NULL);
-
+
tvbparse_wanted_t* want_attrib_value = tvbparse_set_oneof(0, NULL, NULL, get_attrib_value,
tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb,'\"','\\'),
tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb,'\'','\\'),
tvbparse_chars(-1,1,0,"0123456789",NULL,NULL,NULL),
want_name,
NULL);
-
+
tvbparse_wanted_t* want_attributes = tvbparse_one_or_more(-1, NULL, NULL, NULL,
tvbparse_set_seq(-1, NULL, NULL, after_attrib,
want_attr_name,
tvbparse_char(-1,"=",NULL,NULL,NULL),
want_attrib_value,
NULL));
-
+
tvbparse_wanted_t* want_stoptag = tvbparse_set_oneof(-1,NULL,NULL,NULL,
tvbparse_char(-1, ">", NULL, NULL, after_open_tag),
tvbparse_string(-1, "/>", NULL, NULL, after_closed_tag),
NULL);
-
+
tvbparse_wanted_t* want_stopxmlpi = tvbparse_string(-1,"?>",NULL,NULL,after_xmlpi);
-
+
tvbparse_wanted_t* want_comment = tvbparse_set_seq(hf_comment,NULL,NULL,after_token,
tvbparse_string(-1,"<!--",NULL,NULL,NULL),
tvbparse_until(-1,NULL,NULL,NULL,
tvbparse_string(-1,"-->",NULL,NULL,NULL),
TP_UNTIL_INCLUDE),
NULL);
-
+
tvbparse_wanted_t* want_xmlpi = tvbparse_set_seq(hf_xmlpi,NULL,before_xmpli,NULL,
tvbparse_string(-1,"<?",NULL,NULL,NULL),
want_name,
@@ -521,14 +521,14 @@ static void init_xml_parser(void) {
NULL),
NULL),
NULL);
-
+
tvbparse_wanted_t* want_closing_tag = tvbparse_set_seq(0,NULL,NULL,after_untag,
tvbparse_char(-1, "<", NULL, NULL, NULL),
tvbparse_char(-1, "/", NULL, NULL, NULL),
want_tag_name,
tvbparse_char(-1, ">", NULL, NULL, NULL),
NULL);
-
+
tvbparse_wanted_t* want_doctype_start = tvbparse_set_seq(-1,NULL,before_dtd_doctype,NULL,
tvbparse_char(-1,"<",NULL,NULL,NULL),
tvbparse_char(-1,"!",NULL,NULL,NULL),
@@ -550,7 +550,7 @@ static void init_xml_parser(void) {
NULL),
NULL),
NULL);
-
+
tvbparse_wanted_t* want_dtd_tag = tvbparse_set_seq(hf_dtd_tag,NULL,NULL,after_token,
tvbparse_char(-1,"<",NULL,NULL,NULL),
tvbparse_char(-1,"!",NULL,NULL,NULL),
@@ -558,7 +558,7 @@ static void init_xml_parser(void) {
tvbparse_char(-1, ">", NULL, NULL, NULL),
TP_UNTIL_INCLUDE),
NULL);
-
+
tvbparse_wanted_t* want_tag = tvbparse_set_seq(-1, NULL, before_tag, NULL,
tvbparse_char(-1,"<",NULL,NULL,NULL),
want_tag_name,
@@ -570,15 +570,15 @@ static void init_xml_parser(void) {
want_stoptag,
NULL),
NULL);
-
+
tvbparse_wanted_t* want_dtd_close = tvbparse_set_seq(-1,NULL,NULL,after_dtd_close,
tvbparse_char(-1,"]",NULL,NULL,NULL),
tvbparse_char(-1,">",NULL,NULL,NULL),
NULL);
-
+
want_ignore = tvbparse_chars(-1,1,0," \t\r\n",NULL,NULL,NULL);
-
-
+
+
want = tvbparse_set_oneof(-1, NULL, NULL, NULL,
want_comment,
want_xmlpi,
@@ -590,7 +590,7 @@ static void init_xml_parser(void) {
tvbparse_not_chars(XML_CDATA,1,0,"<",NULL,NULL,after_token),
tvbparse_not_chars(-1,1,0," \t\r\n",NULL,NULL,unrecognized_token),
NULL);
-
+
want_heur = tvbparse_set_oneof(-1, NULL, NULL, NULL,
want_comment,
want_xmlpi,
@@ -598,7 +598,7 @@ static void init_xml_parser(void) {
want_dtd_tag,
want_tag,
NULL);
-
+
}
@@ -606,33 +606,33 @@ static xml_ns_t* xml_new_namespace(GHashTable* hash, gchar* name, ...) {
xml_ns_t* ns = g_malloc(sizeof(xml_ns_t));
va_list ap;
gchar* attr_name;
-
+
ns->name = g_strdup(name);
ns->hf_tag = -1;
ns->hf_cdata = -1;
ns->ett = -1;
ns->attributes = g_hash_table_new(g_str_hash,g_str_equal);
ns->elements = g_hash_table_new(g_str_hash,g_str_equal);
-
+
va_start(ap,name);
-
+
while(( attr_name = va_arg(ap,gchar*) )) {
int* hfp = g_malloc(sizeof(int));
*hfp = -1;
g_hash_table_insert(ns->attributes,g_strdup(attr_name),hfp);
};
-
+
va_end(ap);
-
+
g_hash_table_insert(hash,ns->name,ns);
-
+
return ns;
}
static void add_xml_field(GArray* hfs, int* p_id, gchar* name, gchar* fqn) {
hf_register_info hfri;
-
+
hfri.p_id = p_id;
hfri.hfinfo.name = name;
hfri.hfinfo.abbrev = fqn;
@@ -647,8 +647,8 @@ static void add_xml_field(GArray* hfs, int* p_id, gchar* name, gchar* fqn) {
hfri.hfinfo.bitshift = 0;
hfri.hfinfo.same_name_next = NULL;
hfri.hfinfo.same_name_prev = NULL;
-
- g_array_append_val(hfs,hfri);
+
+ g_array_append_val(hfs,hfri);
}
static void add_xml_attribute_names(gpointer k, gpointer v, gpointer p) {
@@ -667,10 +667,10 @@ static void add_xmlpi_namespace(gpointer k _U_, gpointer v, gpointer p) {
add_xml_field(hf_arr, &(ns->hf_tag), basename, basename);
g_array_append_val(ett_arr,ett_p);
-
+
d.basename = basename;
d.hf = hf_arr;
-
+
g_hash_table_foreach(ns->attributes,add_xml_attribute_names,&d);
}
@@ -681,9 +681,9 @@ static void destroy_dtd_data(dtd_build_data_t* dtd_data) {
if(dtd_data->media_type) g_free(dtd_data->media_type);
if(dtd_data->description) g_free(dtd_data->description);
if(dtd_data->proto_root) g_free(dtd_data->proto_root);
-
+
g_string_free(dtd_data->error,TRUE);
-
+
while(dtd_data->elements->len) {
dtd_named_list_t* nl = g_ptr_array_remove_index_fast(dtd_data->elements,0);
@@ -692,7 +692,7 @@ static void destroy_dtd_data(dtd_build_data_t* dtd_data) {
}
g_ptr_array_free(dtd_data->elements,TRUE);
-
+
while(dtd_data->attributes->len) {
dtd_named_list_t* nl = g_ptr_array_remove_index_fast(dtd_data->elements,0);
g_ptr_array_free(nl->list,TRUE);
@@ -710,24 +710,24 @@ static void copy_attrib_item(gpointer k, gpointer v _U_, gpointer p) {
gchar* key = g_strdup(k);
int* value = g_malloc(sizeof(int));
GHashTable* dst = p;
-
+
*value = -1;
g_hash_table_insert(dst,key,value);
-
+
}
static GHashTable* copy_attributes_hash(GHashTable* src) {
GHashTable* dst = g_hash_table_new(g_str_hash,g_str_equal);
-
+
g_hash_table_foreach(src,copy_attrib_item,dst);
-
+
return dst;
}
static xml_ns_t* duplicate_element(xml_ns_t* orig) {
xml_ns_t* new_item = g_malloc(sizeof(xml_ns_t));
guint i;
-
+
new_item->name = g_strdup(orig->name);
new_item->hf_tag = -1;
new_item->hf_cdata = -1;
@@ -735,12 +735,12 @@ static xml_ns_t* duplicate_element(xml_ns_t* orig) {
new_item->attributes = copy_attributes_hash(orig->attributes);
new_item->elements = g_hash_table_new(g_str_hash,g_str_equal);
new_item->element_names = g_ptr_array_new();
-
+
for(i=0; i < orig->element_names->len; i++) {
g_ptr_array_add(new_item->element_names,
g_ptr_array_index(orig->element_names,i));
}
-
+
return new_item;
}
@@ -748,15 +748,15 @@ static gchar* fully_qualified_name(GPtrArray* hier, gchar* name) {
guint i;
GString* s = g_string_new("");
gchar* str;
-
+
for (i = 0; i < hier->len; i++) {
g_string_sprintfa(s, "%s.",(gchar*)g_ptr_array_index(hier,i));
}
-
+
g_string_append(s,name);
str = s->str;
g_string_free(s,FALSE);
-
+
return str;
}
@@ -784,22 +784,22 @@ static xml_ns_t* make_xml_hier(gchar* elem_name,
g_string_sprintfa(error,"element '%s' is not defined\n", elem_name);
return NULL;
}
-
+
for (i = 0; i < hier->len; i++) {
if( strcmp(elem_name,(gchar*) g_ptr_array_index(hier,i) ) == 0 ) {
recurred = TRUE;
}
}
-
+
if (recurred) {
return NULL;
}
-
+
fqn = fully_qualified_name(hier,elem_name);
-
+
new = duplicate_element(orig);
new->fqn = fqn;
-
+
add_xml_field(hfs, &(new->hf_tag), g_strdup(elem_name), fqn);
add_xml_field(hfs, &(new->hf_cdata), g_strdup(elem_name), fqn);
@@ -808,22 +808,22 @@ static xml_ns_t* make_xml_hier(gchar* elem_name,
d.basename = fqn;
d.hf = hfs;
-
+
g_hash_table_foreach(new->attributes,add_xml_attribute_names,&d);
while(new->element_names->len) {
gchar* child_name = g_ptr_array_remove_index(new->element_names,0);
xml_ns_t* child_element = NULL;
-
+
g_ptr_array_add(hier,elem_name);
child_element = make_xml_hier(child_name, root, elements, hier,error,hfs,etts);
g_ptr_array_remove_index_fast(hier,hier->len - 1);
-
+
if (child_element) {
g_hash_table_insert(new->elements,child_element->name,child_element);
}
}
-
+
g_ptr_array_free(new->element_names,TRUE);
new->element_names = NULL;
return new;
@@ -841,14 +841,14 @@ static gboolean free_elements(gpointer k _U_, gpointer v, gpointer p _U_) {
g_hash_table_foreach_remove(e->attributes,free_both,NULL);
g_hash_table_destroy(e->attributes);
g_hash_table_destroy(e->elements);
-
+
while (e->element_names->len) {
g_free(g_ptr_array_remove_index(e->element_names,0));
}
-
+
g_ptr_array_free(e->element_names,TRUE);
g_free(e);
-
+
return TRUE;
}
@@ -861,16 +861,16 @@ static void register_dtd(dtd_build_data_t* dtd_data, GString* errors) {
GPtrArray* hier;
gchar* curr_name;
GPtrArray* element_names = g_ptr_array_new();
-
+
/* we first populate elements with the those coming from the parser */
while(dtd_data->elements->len) {
dtd_named_list_t* nl = g_ptr_array_remove_index(dtd_data->elements,0);
xml_ns_t* element = g_malloc(sizeof(xml_ns_t));
-
+
/* we will use the first element found as root in case no other one was given. */
if (root_name == NULL)
root_name = g_strdup(nl->name);
-
+
element->name = nl->name;
element->element_names = nl->list;
element->hf_tag = -1;
@@ -878,7 +878,7 @@ static void register_dtd(dtd_build_data_t* dtd_data, GString* errors) {
element->ett = -1;
element->attributes = g_hash_table_new(g_str_hash,g_str_equal);
element->elements = g_hash_table_new(g_str_hash,g_str_equal);
-
+
if( g_hash_table_lookup(elements,element->name) ) {
g_string_sprintfa(errors,"element %s defined more than once\n", element->name);
free_elements(NULL,element,NULL);
@@ -886,7 +886,7 @@ static void register_dtd(dtd_build_data_t* dtd_data, GString* errors) {
g_hash_table_insert(elements,element->name,element);
g_ptr_array_add(element_names,g_strdup(element->name));
}
-
+
g_free(nl);
}
@@ -894,21 +894,21 @@ static void register_dtd(dtd_build_data_t* dtd_data, GString* errors) {
while(dtd_data->attributes->len) {
dtd_named_list_t* nl = g_ptr_array_remove_index(dtd_data->attributes,0);
xml_ns_t* element = g_hash_table_lookup(elements,nl->name);
-
+
if (!element) {
g_string_sprintfa(errors,"element %s is not defined\n", nl->name);
goto next_attribute;
}
-
+
while(nl->list->len) {
gchar* name = g_ptr_array_remove_index(nl->list,0);
int* id_p = g_malloc(sizeof(int));
-
+
*id_p = -1;
g_hash_table_insert(element->attributes,name,id_p);
}
-
+
next_attribute:
g_free(nl->name);
g_ptr_array_free(nl->list,TRUE);
@@ -924,7 +924,7 @@ next_attribute:
/* we use a stack with the names to avoid recurring infinitelly */
hier = g_ptr_array_new();
-
+
/*
* if a proto name was given in the dtd the dtd will be used as a protocol
* or else the dtd will be loaded as a branch of the xml namespace
@@ -932,17 +932,17 @@ next_attribute:
if( ! dtd_data->proto_name ) {
hfs = hf_arr;
etts = ett_arr;
- g_ptr_array_add(hier,g_strdup("xml"));
+ g_ptr_array_add(hier,g_strdup("xml"));
root_element = &xml_ns;
} else {
/*
* if we were given a proto_name the namespace will be registered
* as an indipendent protocol with its own hf and ett arrays.
- */
+ */
hfs = g_array_new(FALSE,FALSE,sizeof(hf_register_info));
etts = g_array_new(FALSE,FALSE,sizeof(gint*));
}
-
+
/* the root element of the dtd's namespace */
root_element = g_malloc(sizeof(xml_ns_t));
root_element->name = g_strdup(root_name);
@@ -952,7 +952,7 @@ next_attribute:
root_element->ett = -1;
root_element->elements = g_hash_table_new(g_str_hash,g_str_equal);
root_element->element_names = element_names;
-
+
/*
* we can either create a namespace as a flat namespace
* in which all the elements are at the root level
@@ -960,17 +960,17 @@ next_attribute:
*/
if (dtd_data->recursion) {
xml_ns_t* orig_root;
-
+
make_xml_hier(root_name, root_element, elements,hier,errors,hfs,etts);
-
+
g_hash_table_insert(root_element->elements,root_element->name,root_element);
-
+
orig_root = g_hash_table_lookup(elements,root_name);
-
+
/* if the root element was defined copy its attrlist to the child */
- if(orig_root) {
+ if(orig_root) {
struct _attr_reg_data d;
-
+
d.basename = root_name;
d.hf = hfs;
@@ -982,29 +982,29 @@ next_attribute:
/* we then create all the sub hierachies to catch the recurred cases */
g_ptr_array_add(hier,root_name);
-
+
while(root_element->element_names->len) {
curr_name = g_ptr_array_remove_index(root_element->element_names,0);
-
+
if( ! g_hash_table_lookup(root_element->elements,curr_name) ) {
xml_ns_t* new = make_xml_hier(curr_name, root_element, elements,hier,errors,hfs,etts);
g_hash_table_insert(root_element->elements,new->name,new);
}
-
+
g_free(curr_name);
}
-
+
} else {
/* a flat namespace */
g_ptr_array_add(hier,root_name);
-
+
root_element->attributes = g_hash_table_new(g_str_hash,g_str_equal);
while(root_element->element_names->len) {
xml_ns_t* new;
gint* ett_p;
struct _attr_reg_data d;
-
+
curr_name = g_ptr_array_remove_index(root_element->element_names,0);
new = duplicate_element(g_hash_table_lookup(elements,curr_name));
new->fqn = fully_qualified_name(hier, curr_name);
@@ -1019,17 +1019,17 @@ next_attribute:
ett_p = &new->ett;
g_array_append_val(etts,ett_p);
-
+
g_ptr_array_free(new->element_names,TRUE);
-
+
g_hash_table_insert(root_element->elements,new->name,new);
}
}
g_ptr_array_free(element_names,TRUE);
-
+
g_ptr_array_free(hier,TRUE);
-
+
/*
* if we were given a proto_name the namespace will be registered
* as an indipendent protocol.
@@ -1040,34 +1040,34 @@ next_attribute:
if ( ! dtd_data->description) {
dtd_data->description = g_strdup(root_name);
}
-
+
ett_p = &root_element->ett;
g_array_append_val(etts,ett_p);
add_xml_field(hfs, &root_element->hf_cdata, root_element->name, root_element->fqn);
-
+
root_element->hf_tag = proto_register_protocol(dtd_data->description, dtd_data->proto_name, root_element->name);
proto_register_field_array(root_element->hf_tag, (hf_register_info*)hfs->data, hfs->len);
proto_register_subtree_array((gint**)etts->data, etts->len);
-
+
if (dtd_data->media_type) {
g_hash_table_insert(media_types,dtd_data->media_type,root_element);
dtd_data->media_type = NULL;
}
-
+
dtd_data->description = NULL;
dtd_data->proto_name = NULL;
g_array_free(hfs,FALSE);
g_array_free(etts,TRUE);
}
-
+
g_hash_table_insert(xml_ns.elements,root_element->name,root_element);
-
+
g_hash_table_foreach_remove(elements,free_elements,NULL);
g_hash_table_destroy(elements);
-
+
destroy_dtd_data(dtd_data);
-
+
if (root_name)
g_free(root_name);
}
@@ -1095,62 +1095,62 @@ static void init_xml_names(void) {
const FILE_T* file;
const gchar* filename;
gchar* dirname;
-
+
#if GLIB_MAJOR_VERSION >= 2
GError** dummy = g_malloc(sizeof(GError *));
*dummy = NULL;
#endif
-
+
xmpli_names = g_hash_table_new(g_str_hash,g_str_equal);
media_types = g_hash_table_new(g_str_hash,g_str_equal);
-
+
unknown_ns.elements = xml_ns.elements = g_hash_table_new(g_str_hash,g_str_equal);
unknown_ns.attributes = xml_ns.attributes = g_hash_table_new(g_str_hash,g_str_equal);
-
+
xmlpi_xml_ns = xml_new_namespace(xmpli_names,"xml","version","encoding","standalone",NULL);
-
+
g_hash_table_destroy(xmlpi_xml_ns->elements);
xmlpi_xml_ns->elements = NULL;
-
+
dirname = get_persconffile_path("dtds", FALSE);
-
+
if (test_for_directory(dirname) != EISDIR) {
/* Although dir isn't a directory it may still use memory */
g_free(dirname);
dirname = get_datafile_path("dtds");
}
-
+
if (test_for_directory(dirname) == EISDIR) {
-
+
if ((dir = OPENDIR_OP(dirname)) != NULL) {
while ((file = DIRGETNEXT_OP(dir)) != NULL) {
guint namelen;
filename = GETFNAME_OP(file);
-
+
namelen = strlen(filename);
if ( namelen > 4 && ( g_strcasecmp(filename+(namelen-4),".dtd") == 0 ) ) {
GString* errors = g_string_new("");
GString* preparsed = dtd_preparse(dirname, filename, errors);
dtd_build_data_t* dtd_data;
-
+
if (errors->len) {
report_failure("Dtd Preparser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
continue;
}
-
+
dtd_data = dtd_parse(preparsed);
-
+
g_string_free(preparsed,TRUE);
-
+
if (dtd_data->error->len) {
report_failure("Dtd Parser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,dtd_data->error->str);
destroy_dtd_data(dtd_data);
continue;
}
-
+
register_dtd(dtd_data,errors);
-
+
if (errors->len) {
report_failure("Dtd Registration in file: %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
g_string_free(errors,TRUE);
@@ -1158,29 +1158,29 @@ static void init_xml_names(void) {
}
}
}
-
+
CLOSEDIR_OP(dir);
}
}
-
+
for(i=0;i<array_length(default_media_types);i++) {
if( ! g_hash_table_lookup(media_types,default_media_types[i]) ) {
g_hash_table_insert(media_types,(gpointer)default_media_types[i],&xml_ns);
}
}
-
+
g_hash_table_foreach(xmpli_names,add_xmlpi_namespace,"xml.xmlpi");
#if GLIB_MAJOR_VERSION >= 2
g_free(dummy);
-#endif
+#endif
}
static void apply_prefs(void) {
if (pref_heuristic) {
heur_dissector_add("http", dissect_xml_heur, xml_ns.hf_tag);
heur_dissector_add("sip", dissect_xml_heur, xml_ns.hf_tag);
- heur_dissector_add("media", dissect_xml_heur, xml_ns.hf_tag);
+ heur_dissector_add("media", dissect_xml_heur, xml_ns.hf_tag);
}
}
@@ -1192,7 +1192,7 @@ proto_register_xml(void) {
&ett_dtd,
&ett_xmpli
};
-
+
static hf_register_info hf_base[] = {
{ &hf_xmlpi, {"XMLPI", "xml.xmlpi", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
{ &hf_comment, {"Comment", "xml.comment", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
@@ -1210,26 +1210,26 @@ proto_register_xml(void) {
g_array_append_vals(hf_arr,hf_base,array_length(hf_base));
g_array_append_vals(ett_arr,ett_base,array_length(ett_base));
-
+
init_xml_names();
xml_ns.hf_tag = proto_register_protocol("eXtensible Markup Language", "XML", xml_ns.name);
proto_register_field_array(xml_ns.hf_tag, (hf_register_info*)hf_arr->data, hf_arr->len);
proto_register_subtree_array((gint**)ett_arr->data, ett_arr->len);
-
+
xml_module = prefs_register_protocol(xml_ns.hf_tag,apply_prefs);
prefs_register_bool_preference(xml_module, "heuristic", "Use Heuristics",
"Try to recognize XML for unknown media types",
&pref_heuristic);
-
+
g_array_free(hf_arr,FALSE);
g_array_free(ett_arr,TRUE);
-
+
register_dissector("xml", dissect_xml, xml_ns.hf_tag);
-
+
init_xml_parser();
-
+
}
static void add_dissector_media(gpointer k, gpointer v _U_, gpointer p _U_) {
@@ -1239,9 +1239,9 @@ static void add_dissector_media(gpointer k, gpointer v _U_, gpointer p _U_) {
void
proto_reg_handoff_xml(void)
{
-
+
xml_handle = find_dissector("xml");
-
+
g_hash_table_foreach(media_types,add_dissector_media,NULL);
-
+
}