do not free the element name, as its been passed to the hf array.
[obnox/wireshark/wip.git] / epan / dissectors / packet-xml.c
1 /* packet-xml.c
2  * ethereal's xml dissector .
3  *
4  * (C) 2005, Luis E. Garcia Ontanon.
5  *
6  * $Id$
7  *
8  * Refer to the AUTHORS file or the AUTHORS section in the man page
9  * for contacting the author(s) of this file.
10  *
11  * Ethereal - Network traffic analyzer
12  * By Gerald Combs <gerald@ethereal.com>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #ifdef HAVE_DIRENT_H
35 #include <dirent.h>
36 #endif
37
38 #include <ctype.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <stdarg.h>
42 #include <errno.h>
43
44 #include <stdio.h>
45
46 #include <glib.h>
47 #include <epan/emem.h>
48 #include <epan/packet.h>
49 #include <epan/strutil.h>
50 #include <epan/tvbparse.h>
51 #include <epan/dtd.h>
52 #include <epan/report_err.h>
53 #include <epan/filesystem.h>
54
55 typedef struct _xml_ns_t {
56     /* the name of this namespace */ 
57         gchar* name;
58     
59     /* its fully qualified name */ 
60         gchar* fqn;
61
62         /* the contents of the whole element from <> to </> */
63         int hf_tag;
64     
65         /* chunks of cdata from <> to </> excluding sub tags */
66         int hf_cdata;
67     
68     /* the subtree for its sub items  */
69         gint ett;
70
71         GHashTable* attributes;
72     /*  key:   the attribute name
73         value: hf_id of what's between quotes */
74         
75     /* the namespace's namespaces */
76     GHashTable* elements;
77     /*  key:   the element name
78         value: the child namespace */
79         
80         GPtrArray* element_names;
81     /* imported directly from the parser and used while building the namespace */
82     
83 } xml_ns_t;
84
85 typedef struct {
86         proto_tree* tree;
87         proto_item* item;
88         proto_item* last_item;
89         xml_ns_t* ns;
90         int start_offset;
91 } xml_frame_t;
92
93 struct _attr_reg_data {
94         GArray* hf;
95         gchar* basename;
96 };
97
98
99 static gint ett_dtd = -1;
100 static gint ett_xmpli = -1;
101
102 static int hf_unknowwn_attrib = -1;
103 static int hf_comment = -1;
104 static int hf_xmlpi = -1;
105 static int hf_dtd_tag = -1;
106 static int hf_doctype = -1;
107
108 /* dissector handles */
109 static dissector_handle_t xml_handle;
110
111 /* parser definitions */
112 static tvbparse_wanted_t* want;
113 static tvbparse_wanted_t* want_ignore;
114
115 static GHashTable* xmpli_names;
116 static GHashTable* media_types;
117
118 static xml_ns_t xml_ns = {"xml","/",-1,-1,-1,NULL,NULL,NULL};
119 static xml_ns_t unknown_ns = {"unknown","?",-1,-1,-1,NULL,NULL,NULL};
120 static xml_ns_t* root_ns;
121
122 #define XML_CDATA -1000
123 #define XML_SCOPED_NAME -1001
124
125
126 GArray* hf_arr;
127 GArray* ett_arr;
128
129 static const gchar* default_media_types[] = {
130         "text/xml", 
131         "application/xml", 
132         "application/soap+xml", 
133         "application/xml-dtd", 
134         "text/vnd.wap.wml", 
135         "text/vnd.wap.si", 
136         "text/vnd.wap.sl", 
137         "text/vnd.wap.co", 
138         "text/vnd.wap.emn", 
139         "application/vnd.wv.csp+xml", 
140         "application/xcap-el+xml", 
141         "application/xcap-att+xml", 
142         "application/xcap-error+xml", 
143         "application/xcap-caps+xml", 
144         "application/auth-policy+xml", 
145         "application/smil", 
146         "application/cpim-pidf+xml", 
147         "application/rdf+xml", 
148         "application/xslt+xml", 
149         "application/mathml+xml", 
150         "image/svg+xml", 
151         "application/vnd.wv.csp.xml",
152 };
153
154
155 static void
156 dissect_xml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
157 {
158         tvbparse_t* tt;
159         tvbparse_elem_t* tok = NULL;
160         static GPtrArray* stack = NULL;
161         xml_frame_t* current_frame;
162         
163         if(!tree) return;
164         
165         if (stack != NULL)
166                 g_ptr_array_free(stack,TRUE);
167         
168         stack = g_ptr_array_new();
169         current_frame = ep_alloc(sizeof(xml_frame_t));
170         g_ptr_array_add(stack,current_frame);
171
172         tt = tvbparse_init(tvb,0,-1,stack,want_ignore);
173         current_frame->start_offset = 0;
174
175         root_ns = NULL;
176         
177         if (pinfo->match_string)
178                 root_ns = g_hash_table_lookup(media_types,pinfo->match_string);
179         
180         if (! root_ns ) {
181                 root_ns = &xml_ns;
182         }
183         
184         current_frame->ns = root_ns;
185         
186         current_frame->item = proto_tree_add_item(tree,current_frame->ns->hf_tag,tvb,0,-1,FALSE);
187         current_frame->tree = proto_item_add_subtree(current_frame->item,current_frame->ns->ett);
188         current_frame->last_item = current_frame->item;
189         
190         while(( tok = tvbparse_get(tt, want) )) ;
191
192
193
194 static void after_token(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
195         GPtrArray* stack = tvbparse_data;
196         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
197         int hfid;
198         proto_item* pi;
199
200         if (tok->id == XML_CDATA) {
201                 hfid = current_frame->ns ? current_frame->ns->hf_cdata : xml_ns.hf_cdata;
202         } else if ( tok->id > 0) {
203                 hfid = tok->id;
204         } else {
205                 hfid = xml_ns.hf_cdata;
206         }
207         
208         pi = proto_tree_add_item(current_frame->tree, hfid, tok->tvb, tok->offset, tok->len, FALSE);
209         
210         proto_item_set_text(pi, "%s",
211                                                 tvb_format_text(tok->tvb,tok->offset,tok->len));
212 }
213
214 static void before_xmpli(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
215         GPtrArray* stack = tvbparse_data;
216         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
217         proto_item* pi;
218         proto_tree* pt;
219         tvbparse_elem_t* name_tok = tok->sub->next;
220         gchar* name = tvb_get_ephemeral_string(name_tok->tvb,name_tok->offset,name_tok->len);
221         xml_ns_t* ns = g_hash_table_lookup(xmpli_names,name);
222
223         int hf_tag;
224         gint ett;
225         
226         g_strdown(name);
227         if (!ns) {
228                 hf_tag = hf_xmlpi;
229                 ett = ett_xmpli;
230         } else {
231                 hf_tag = ns->hf_tag;
232                 ett = ns->ett;
233         }
234         
235         pi = proto_tree_add_item(current_frame->tree,hf_tag,tok->tvb,tok->offset,tok->len,FALSE);
236         
237         proto_item_set_text(pi,tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
238         
239         pt = proto_item_add_subtree(pi,ett);
240         
241         current_frame = ep_alloc(sizeof(xml_frame_t));
242         current_frame->item = pi;
243         current_frame->last_item = pi;
244         current_frame->tree = pt;
245         current_frame->start_offset = tok->offset;
246         current_frame->ns = ns;
247
248         g_ptr_array_add(stack,current_frame);
249         
250 }
251
252 static void after_xmlpi(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
253         GPtrArray* stack = tvbparse_data;
254         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
255                 
256         proto_tree_add_text(current_frame->tree,
257                                                    tok->tvb, tok->offset, tok->len,
258                                                    tvb_format_text(tok->tvb,tok->offset,tok->len));
259         
260         if (stack->len > 1) {
261                 g_ptr_array_remove_index_fast(stack,stack->len - 1);
262         } else {
263                 proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Closing an unopened xmpli tag ]");
264         }
265 }
266
267 static void before_tag(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
268         GPtrArray* stack = tvbparse_data;
269         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
270         tvbparse_elem_t* name_tok = tok->sub->next;
271     gchar* root_name;
272         gchar* name;
273         xml_ns_t* ns;
274         xml_frame_t* new_frame;
275         proto_item* pi;
276         proto_tree* pt;
277
278         if (name_tok->sub->id == XML_SCOPED_NAME) {
279         tvbparse_elem_t* root_tok = name_tok->sub->sub;
280         tvbparse_elem_t* leaf_tok = name_tok->sub->sub->next->next;
281         xml_ns_t* nameroot_ns;
282         
283         root_name = tvb_get_ephemeral_string(root_tok->tvb,root_tok->offset,root_tok->len);
284         name = tvb_get_ephemeral_string(leaf_tok->tvb,leaf_tok->offset,leaf_tok->len);
285         
286         nameroot_ns = g_hash_table_lookup(xml_ns.elements,root_name);
287         
288         if(nameroot_ns) {
289             ns = g_hash_table_lookup(nameroot_ns->elements,name);
290             if (!ns) {
291                 ns = &unknown_ns;                
292             }
293         } else {
294             ns = &unknown_ns;
295         }
296         
297     } else {
298         name = tvb_get_ephemeral_string(name_tok->tvb,name_tok->offset,name_tok->len);
299         g_strdown(name);
300
301         if(current_frame->ns) {
302                         ns = g_hash_table_lookup(current_frame->ns->elements,name);
303         
304                         if (!ns) {
305                                 if (! ( ns = g_hash_table_lookup(root_ns->elements,name) ) ) {
306                                         ns = &unknown_ns;
307                                 }
308                         }
309                 } else {
310                         ns = &unknown_ns;
311                 }
312     }
313
314     pi = proto_tree_add_item(current_frame->tree,ns->hf_tag,tok->tvb,tok->offset,tok->len,FALSE);
315         proto_item_set_text(pi,tvb_format_text(tok->tvb,tok->offset,(name_tok->offset - tok->offset) + name_tok->len));
316         
317         pt = proto_item_add_subtree(pi,ns->ett);
318         
319         new_frame = ep_alloc(sizeof(xml_frame_t));
320         new_frame->item = pi;
321         new_frame->last_item = pi;
322         new_frame->tree = pt;
323         new_frame->start_offset = tok->offset;
324         new_frame->ns = ns;
325
326         g_ptr_array_add(stack,new_frame);
327
328 }
329
330 static void after_open_tag(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok _U_) {
331         GPtrArray* stack = tvbparse_data;
332         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
333
334         proto_item_append_text(current_frame->last_item,">");
335 }
336
337 static void after_closed_tag(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
338         GPtrArray* stack = tvbparse_data;
339         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
340
341         proto_item_append_text(current_frame->last_item,"/>");                                  
342
343         if (stack->len > 1) {
344                 g_ptr_array_remove_index_fast(stack,stack->len - 1);
345         } else {
346                 proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Closing an unopened tag ]");
347         }       
348 }
349
350 void after_untag(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok){
351         GPtrArray* stack = tvbparse_data;
352         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
353
354         proto_item_set_len(current_frame->item, (tok->offset - current_frame->start_offset) + tok->len);
355         
356         proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"%s",
357                                                 tvb_format_text(tok->tvb,tok->offset,tok->len));
358
359         if (stack->len > 1) {
360                 g_ptr_array_remove_index_fast(stack,stack->len - 1);
361         } else {
362                 proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,
363                                                         "[ ERROR: Closing an unopened tag ]");
364         }
365 }
366
367 static void before_dtd_doctype(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok){
368         GPtrArray* stack = tvbparse_data;
369         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
370         tvbparse_elem_t* name_tok = tok->sub->next->next->next->sub->sub;
371         proto_tree* dtd_item = proto_tree_add_item(current_frame->tree, hf_doctype,
372                                                                                            name_tok->tvb, name_tok->offset, name_tok->len, FALSE);
373                                                                                            
374         proto_item_set_text(dtd_item,"%s",tvb_format_text(tok->tvb,tok->offset,tok->len));
375
376         current_frame = ep_alloc(sizeof(xml_frame_t));
377         current_frame->item = dtd_item;
378         current_frame->last_item = dtd_item;
379         current_frame->tree = proto_item_add_subtree(dtd_item,ett_dtd);
380         current_frame->start_offset = tok->offset;
381         current_frame->ns = NULL;
382
383         g_ptr_array_add(stack,current_frame);
384 }
385
386 static void pop_stack(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok _U_) {
387         GPtrArray* stack = tvbparse_data;
388         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
389
390         if (stack->len > 1) {
391                 g_ptr_array_remove_index_fast(stack,stack->len - 1);
392         } else {
393                 proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,
394                                                         "[ ERROR: Closing an unopened tag ]");
395         }       
396 }
397
398 static void after_dtd_close(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok){
399         GPtrArray* stack = tvbparse_data;
400         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
401         
402         proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"%s",
403                                                 tvb_format_text(tok->tvb,tok->offset,tok->len));
404         if (stack->len > 1) {
405                 g_ptr_array_remove_index_fast(stack,stack->len - 1);
406         } else {
407                 proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Closing an unopened tag ]");
408         }
409 }
410
411 static void get_attrib_value(void* tvbparse_data _U_, const void* wanted_data _U_, tvbparse_elem_t* tok) {
412         tok->data = tok->sub;
413 }
414
415 static void after_attrib(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok) {
416         GPtrArray* stack = tvbparse_data;
417         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
418         gchar* name = tvb_get_ephemeral_string(tok->sub->tvb,tok->sub->offset,tok->sub->len);
419         tvbparse_elem_t* value = tok->sub->next->next->data;
420         int* hfidp;
421         int hfid;
422
423         g_strdown(name);
424         if(current_frame->ns && (hfidp = g_hash_table_lookup(current_frame->ns->attributes,name) )) {
425                 hfid = *hfidp;
426         } else {
427                 hfid = hf_unknowwn_attrib;
428                 value = tok;
429         }
430         
431         current_frame->last_item = proto_tree_add_item(current_frame->tree,hfid,value->tvb,value->offset,value->len,FALSE);
432         proto_item_set_text(current_frame->last_item, "%s", tvb_format_text(tok->tvb,tok->offset,tok->len));
433
434 }
435
436 static void unrecognized_token(void* tvbparse_data, const void* wanted_data _U_, tvbparse_elem_t* tok _U_){
437         GPtrArray* stack = tvbparse_data;
438         xml_frame_t* current_frame = g_ptr_array_index(stack,stack->len - 1);
439         
440         proto_tree_add_text(current_frame->tree,tok->tvb,tok->offset,tok->len,"[ ERROR: Unrecognized text ]");
441
442 }
443
444
445
446 void init_xml_parser(void) {    
447         tvbparse_wanted_t* want_name = tvbparse_chars(-1,1,0,"abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ",NULL,NULL,NULL);
448         tvbparse_wanted_t* want_attr_name = tvbparse_chars(-1,1,0,"abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ:",NULL,NULL,NULL);
449     
450     tvbparse_wanted_t* want_scoped_name = tvbparse_set_seq(XML_SCOPED_NAME, NULL, NULL, NULL,
451                                                            want_name,
452                                                            tvbparse_char(-1,":",NULL,NULL,NULL),
453                                                            want_name,
454                                                            NULL);
455     
456     tvbparse_wanted_t* want_tag_name = tvbparse_set_oneof(0, NULL, NULL, NULL,
457                                                           want_scoped_name,
458                                                           want_name,
459                                                           NULL);
460     
461     tvbparse_wanted_t* want_attrib_value = tvbparse_set_oneof(0, NULL, NULL, get_attrib_value,
462                                                               tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb,'\"','\\'),
463                                                               tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb,'\'','\\'),
464                                                               tvbparse_chars(-1,1,0,"0123456789",NULL,NULL,NULL),
465                                                               want_name,
466                                                               NULL);
467     
468         tvbparse_wanted_t* want_attributes = tvbparse_one_or_more(-1, NULL, NULL, NULL,
469                                                                                                                           tvbparse_set_seq(-1, NULL, NULL, after_attrib,
470                                                                                want_attr_name,
471                                                                                                                                                            tvbparse_char(-1,"=",NULL,NULL,NULL),
472                                                                                                                                                            want_attrib_value,
473                                                                                                                                                            NULL));
474         
475         tvbparse_wanted_t* want_stoptag = tvbparse_set_oneof(-1,NULL,NULL,NULL,
476                                                                                                                  tvbparse_char(-1, ">", NULL, NULL, after_open_tag),
477                                                                                                                  tvbparse_string(-1, "/>", NULL, NULL, after_closed_tag),
478                                                                                                                  NULL);
479         
480         tvbparse_wanted_t* want_stopxmlpi = tvbparse_string(-1,"?>",NULL,NULL,after_xmlpi);
481         
482     tvbparse_wanted_t* want_comment = tvbparse_set_seq(hf_comment,NULL,NULL,after_token,
483                                                        tvbparse_string(-1,"<!--",NULL,NULL,NULL),
484                                                        tvbparse_until(-1,NULL,NULL,NULL,
485                                                                       tvbparse_string(-1,"-->",NULL,NULL,NULL),
486                                                                       TP_UNTIL_INCLUDE),
487                                                        NULL);
488     
489     tvbparse_wanted_t* want_xmlpi = tvbparse_set_seq(hf_xmlpi,NULL,before_xmpli,NULL,
490                                                      tvbparse_string(-1,"<?",NULL,NULL,NULL),
491                                                      want_name,
492                                                      tvbparse_set_oneof(-1,NULL,NULL,NULL,
493                                                                         want_stopxmlpi,
494                                                                         tvbparse_set_seq(-1,NULL,NULL,NULL,
495                                                                                          want_attributes,
496                                                                                          want_stopxmlpi,
497                                                                                          NULL),
498                                                                         NULL),
499                                                      NULL);
500     
501     tvbparse_wanted_t* want_closing_tag = tvbparse_set_seq(0,NULL,NULL,after_untag,
502                                                            tvbparse_char(-1, "<", NULL, NULL, NULL),
503                                                            tvbparse_char(-1, "/", NULL, NULL, NULL),
504                                                            want_tag_name,
505                                                            tvbparse_char(-1, ">", NULL, NULL, NULL),
506                                                            NULL);
507     
508     tvbparse_wanted_t* want_doctype_start = tvbparse_set_seq(-1,NULL,before_dtd_doctype,NULL,
509                                                              tvbparse_char(-1,"<",NULL,NULL,NULL),
510                                                              tvbparse_char(-1,"!",NULL,NULL,NULL),
511                                                              tvbparse_casestring(-1,"DOCTYPE",NULL,NULL,NULL),
512                                                              tvbparse_set_oneof(-1,NULL,NULL,NULL,
513                                                                                 tvbparse_set_seq(-1,NULL,NULL,NULL,
514                                                                                                  want_name,
515                                                                                                  tvbparse_char(-1,"[",NULL,NULL,NULL),
516                                                                                                  NULL),
517                                                                                 tvbparse_set_seq(-1,NULL,NULL,pop_stack,
518                                                                                                  want_name,
519                                                                                                  tvbparse_set_oneof(-1,NULL,NULL,NULL,
520                                                                                                                     tvbparse_casestring(-1,"PUBLIC",NULL,NULL,NULL),
521                                                                                                                     tvbparse_casestring(-1,"SYSTEM",NULL,NULL,NULL),
522                                                                                                                     NULL),
523                                                                                                  tvbparse_until(-1,NULL,NULL,NULL,
524                                                                                                                 tvbparse_char(-1,">",NULL,NULL,NULL),
525                                                                                                                 TP_UNTIL_INCLUDE),
526                                                                                                  NULL),
527                                                                                 NULL),
528                                                              NULL);
529     
530     tvbparse_wanted_t* want_dtd_tag = tvbparse_set_seq(hf_dtd_tag,NULL,NULL,after_token,
531                                                        tvbparse_char(-1,"<",NULL,NULL,NULL),
532                                                        tvbparse_char(-1,"!",NULL,NULL,NULL),
533                                                        tvbparse_until(-1,NULL,NULL,NULL,
534                                                                       tvbparse_char(-1, ">", NULL, NULL, NULL),
535                                                                       TP_UNTIL_INCLUDE),
536                                                        NULL);
537     
538     tvbparse_wanted_t* want_tag = tvbparse_set_seq(-1, NULL, before_tag, NULL,
539                                                    tvbparse_char(-1,"<",NULL,NULL,NULL),
540                                                    want_tag_name,
541                                                    tvbparse_set_oneof(-1,NULL,NULL,NULL,
542                                                                       tvbparse_set_seq(-1,NULL,NULL,NULL,
543                                                                                        want_attributes,
544                                                                                        want_stoptag,
545                                                                                        NULL),
546                                                                       want_stoptag,
547                                                                       NULL),
548                                                    NULL);
549     
550     tvbparse_wanted_t* want_dtd_close = tvbparse_set_seq(-1,NULL,NULL,after_dtd_close,
551                                                          tvbparse_char(-1,"]",NULL,NULL,NULL),
552                                                          tvbparse_char(-1,">",NULL,NULL,NULL),
553                                                          NULL);
554     
555     want_ignore = tvbparse_chars(-1,1,0," \t\r\n",NULL,NULL,NULL);
556         
557     
558         want = tvbparse_set_oneof(-1, NULL, NULL, NULL,
559                                                           want_comment,
560                                                           want_xmlpi,
561                                                           want_closing_tag,
562                                                           want_doctype_start,
563                                                           want_dtd_close,
564                                                           want_dtd_tag,
565                                                           want_tag,
566                                                           tvbparse_not_chars(XML_CDATA,1,0,"<",NULL,NULL,after_token),
567                                                           tvbparse_not_chars(-1,1,0," \t\r\n",NULL,NULL,unrecognized_token),
568                                                           NULL);
569         
570         
571 }
572
573
574 xml_ns_t* xml_new_namespace(GHashTable* hash, gchar* name, ...) {
575         xml_ns_t* ns = g_malloc(sizeof(xml_ns_t));
576         va_list ap;
577         gchar* attr_name;
578         
579         ns->name = g_strdup(name);
580         ns->hf_tag = -1;
581         ns->hf_cdata = -1;
582         ns->ett = -1;
583         ns->attributes = g_hash_table_new(g_str_hash,g_str_equal);
584         ns->elements = g_hash_table_new(g_str_hash,g_str_equal);
585         
586         va_start(ap,name);
587         
588         while(( attr_name = va_arg(ap,gchar*) )) {
589                 int* hfp = g_malloc(sizeof(int));
590                 *hfp = -1;
591                 g_hash_table_insert(ns->attributes,g_strdup(attr_name),hfp);
592         };
593         
594         va_end(ap);
595         
596         g_hash_table_insert(hash,ns->name,ns);
597         
598         return ns;
599 }
600
601
602 void add_xml_field(GArray* hfs, int* p_id, gchar* name, gchar* fqn) {
603         hf_register_info hfri;
604         
605         hfri.p_id = p_id;
606         hfri.hfinfo.name = name;
607         hfri.hfinfo.abbrev = fqn;
608         hfri.hfinfo.type = FT_STRING;
609         hfri.hfinfo.display = BASE_NONE;
610         hfri.hfinfo.strings = NULL;
611         hfri.hfinfo.bitmask = 0x0;
612         hfri.hfinfo.blurb = "";
613         hfri.hfinfo.id = 0;
614         hfri.hfinfo.parent = 0;
615         hfri.hfinfo.ref_count = 0;
616         hfri.hfinfo.bitshift = 0;
617         hfri.hfinfo.same_name_next = NULL;
618         hfri.hfinfo.same_name_prev = NULL;
619         
620         g_array_append_val(hfs,hfri);   
621 }
622
623 void add_xml_attribute_names(gpointer k, gpointer v, gpointer p) {
624         struct _attr_reg_data* d = p;
625         gchar* basename = g_strdup_printf("%s.%s",d->basename,(gchar*)k);
626         add_xml_field(d->hf, (int*) v, (gchar*)k, basename);
627 }
628
629
630 void add_xmlpi_namespace(gpointer k _U_, gpointer v, gpointer p) {
631         xml_ns_t* ns = v;
632         gchar* basename = g_strdup_printf("%s.%s",(gchar*)p,ns->name);
633         gint* ett_p = &(ns->ett);
634         struct _attr_reg_data d;
635
636         add_xml_field(hf_arr, &(ns->hf_tag), basename, basename);
637
638         g_array_append_val(ett_arr,ett_p);
639         
640         d.basename = basename;
641         d.hf = hf_arr;
642         
643         g_hash_table_foreach(ns->attributes,add_xml_attribute_names,&d);
644
645 }
646
647 static void destroy_dtd_data(dtd_build_data_t* dtd_data) {
648
649         if(dtd_data->proto_name) g_free(dtd_data->proto_name);
650         if(dtd_data->media_type) g_free(dtd_data->media_type);
651         if(dtd_data->description) g_free(dtd_data->description);
652         if(dtd_data->proto_root) g_free(dtd_data->proto_root);
653     
654     g_string_free(dtd_data->error,TRUE);
655         
656
657         while(dtd_data->elements->len) {
658                 dtd_named_list_t* nl = g_ptr_array_remove_index_fast(dtd_data->elements,0);
659                 g_ptr_array_free(nl->list,TRUE);
660                 g_free(nl);
661         }
662
663         g_ptr_array_free(dtd_data->elements,TRUE);
664         
665         while(dtd_data->attributes->len) {
666                 dtd_named_list_t* nl = g_ptr_array_remove_index_fast(dtd_data->elements,0);
667                 g_ptr_array_free(nl->list,TRUE);
668                 g_free(nl);
669         }
670
671         g_ptr_array_free(dtd_data->attributes,TRUE);
672
673         g_free(dtd_data);
674
675 }
676
677
678 static void copy_attrib_item(gpointer k, gpointer v _U_, gpointer p) {
679         gchar* key = g_strdup(k);
680         int* value = g_malloc(sizeof(int));
681         GHashTable* dst = p;
682         
683         *value = -1;
684         g_hash_table_insert(dst,key,value);
685         
686 }
687
688 static GHashTable* copy_attributes_hash(GHashTable* src) {
689         GHashTable* dst = g_hash_table_new(g_str_hash,g_str_equal);
690         
691         g_hash_table_foreach(src,copy_attrib_item,dst);
692         
693         return dst;
694 }
695
696 static xml_ns_t* duplicate_element(xml_ns_t* orig) {
697         xml_ns_t* new_item  = g_malloc(sizeof(xml_ns_t));
698         guint i;
699         
700         new_item->name = g_strdup(orig->name);
701         new_item->hf_tag = -1;
702         new_item->hf_cdata = -1;
703         new_item->ett = -1;
704         new_item->attributes = copy_attributes_hash(orig->attributes);
705         new_item->elements =  g_hash_table_new(g_str_hash,g_str_equal);
706         new_item->element_names = g_ptr_array_new();
707         
708         for(i=0; i < orig->element_names->len; i++) {
709                 g_ptr_array_add(new_item->element_names,
710                                                    g_ptr_array_index(orig->element_names,i));
711         }
712         
713         return new_item;
714 }
715
716 static gchar* fully_qualified_name(GPtrArray* hier, gchar* name) {
717         guint i;
718         GString* s = g_string_new("");
719         gchar* str;
720         
721         for (i = 0; i < hier->len; i++) {
722                 g_string_sprintfa(s, "%s.",(gchar*)g_ptr_array_index(hier,i));
723         }
724         
725         g_string_append(s,name);
726         str = s->str;
727         g_string_free(s,FALSE);
728         
729         return str;
730 }
731
732
733 static xml_ns_t* make_xml_hier(gchar* elem_name,
734                                                                   xml_ns_t* root,
735                                                                   GHashTable* elements,
736                                                                   GPtrArray* hier,
737                                                                   GString* error,
738                                                                   GArray* hfs,
739                                                                   GArray* etts) {
740         xml_ns_t* new;
741         xml_ns_t* orig;
742         gchar* fqn;
743         gint* ett_p;
744         struct _attr_reg_data d;
745     gboolean recurred = FALSE;
746     guint i;
747
748     if ( g_str_equal(elem_name,root->name) ) {
749         return NULL;
750     }
751
752         if (! ( orig = g_hash_table_lookup(elements,elem_name) )) {
753                 g_string_sprintfa(error,"element '%s' is not defined\n", elem_name);
754                 return NULL;
755         }
756     
757     for (i = 0; i < hier->len; i++) {
758         if( strcmp(elem_name,(gchar*) g_ptr_array_index(hier,i) ) == 0 ) {
759             recurred = TRUE;
760         }
761     }
762     
763     if (recurred) {
764         return NULL;
765     }
766     
767         fqn = fully_qualified_name(hier,elem_name);
768     
769         new = duplicate_element(orig);
770         new->fqn = fqn;
771     
772     add_xml_field(hfs, &(new->hf_tag), g_strdup(elem_name), fqn);
773         add_xml_field(hfs, &(new->hf_cdata), g_strdup(elem_name), fqn);
774
775         ett_p = &new->ett;
776         g_array_append_val(etts,ett_p);
777
778         d.basename = fqn;
779         d.hf = hfs;
780         
781         g_hash_table_foreach(new->attributes,add_xml_attribute_names,&d);
782
783         while(new->element_names->len) {
784                 gchar* child_name = g_ptr_array_remove_index(new->element_names,0);
785                 xml_ns_t* child_element = NULL;
786                 
787         g_ptr_array_add(hier,elem_name);
788         child_element = make_xml_hier(child_name, root, elements, hier,error,hfs,etts);
789         g_ptr_array_remove_index_fast(hier,hier->len - 1);
790                 
791                 if (child_element) {
792                         g_hash_table_insert(new->elements,child_element->name,child_element);
793                 }
794     }
795         
796         g_ptr_array_free(new->element_names,TRUE);
797         new->element_names = NULL;
798         return new;
799 }
800
801 static gboolean free_both(gpointer k, gpointer v, gpointer p _U_) {
802     g_free(k);
803     g_free(v);
804     return TRUE;
805 }
806
807 static gboolean free_elements(gpointer k _U_, gpointer v, gpointer p _U_) {
808     xml_ns_t* e = v;
809     g_free(e->name);
810     g_hash_table_foreach_remove(e->attributes,free_both,NULL);
811     g_hash_table_destroy(e->attributes);
812     g_hash_table_destroy(e->elements);
813     
814     while (e->element_names->len) {
815         g_free(g_ptr_array_remove_index(e->element_names,0));
816     }
817     
818     g_ptr_array_free(e->element_names,TRUE);
819     g_free(e);
820     
821     return TRUE;
822 }
823
824 static void register_dtd(dtd_build_data_t* dtd_data, GString* errors) {
825         GHashTable* elements = g_hash_table_new(g_str_hash,g_str_equal);
826         gchar* root_name = NULL;
827         xml_ns_t* root_element = NULL;
828         GArray* hfs;
829         GArray* etts;
830         GPtrArray* hier;
831         gchar* curr_name;
832     GPtrArray* element_names = g_ptr_array_new();
833     
834     /* we first populate elements with the those coming from the parser */
835         while(dtd_data->elements->len) {
836                 dtd_named_list_t* nl = g_ptr_array_remove_index(dtd_data->elements,0);
837                 xml_ns_t* element = g_malloc(sizeof(xml_ns_t));
838                 
839                 /* we will use the first element found as root in case no other one was given. */
840                 if (root_name == NULL)
841             root_name = g_strdup(nl->name);
842                 
843                 element->name = nl->name;
844                 element->element_names = nl->list;
845                 element->hf_tag = -1;
846                 element->hf_cdata = -1;
847                 element->ett = -1;
848                 element->attributes = g_hash_table_new(g_str_hash,g_str_equal);
849                 element->elements = g_hash_table_new(g_str_hash,g_str_equal);
850                 
851         if( g_hash_table_lookup(elements,element->name) ) {
852             g_string_sprintfa(errors,"element %s defined more than once\n", element->name);
853             free_elements(NULL,element,NULL);
854         } else {
855             g_hash_table_insert(elements,element->name,element);
856             g_ptr_array_add(element_names,g_strdup(element->name));
857                 }
858         
859                 g_free(nl);
860         }
861
862         /* then we add the attributes to its relative elements */
863         while(dtd_data->attributes->len) {
864                 dtd_named_list_t* nl = g_ptr_array_remove_index(dtd_data->attributes,0);
865                 xml_ns_t* element = g_hash_table_lookup(elements,nl->name);
866                 
867                 if (!element) {
868                         g_string_sprintfa(errors,"element %s is not defined\n", nl->name);
869
870             goto next_attribute;
871                 }
872                 
873                 while(nl->list->len) {
874                         gchar* name = g_ptr_array_remove_index(nl->list,0);
875                         int* id_p = g_malloc(sizeof(int));
876             
877                         *id_p = -1;
878                         g_hash_table_insert(element->attributes,name,id_p);
879                 }
880         
881 next_attribute:
882                 g_free(nl->name);
883                 g_ptr_array_free(nl->list,TRUE);
884                 g_free(nl);
885         }
886
887     /* if a proto_root is defined in the dtd we'll use that as root */
888         if( dtd_data->proto_root ) {
889         if(root_name)
890             g_free(root_name);
891         root_name = g_strdup(dtd_data->proto_root);
892         }
893
894     /* we use a stack with the names to avoid recurring infinitelly */
895         hier = g_ptr_array_new();
896     
897     /*
898      * if a proto name was given in the dtd the dtd will be used as a protocol
899      * or else the dtd will be loaded as a branch of the xml namespace
900      */
901         if( ! dtd_data->proto_name ) {
902                 hfs = hf_arr;
903                 etts = ett_arr;
904                 g_ptr_array_add(hier,g_strdup("xml")); 
905                 root_element = &xml_ns;
906         } else {
907         /*
908          * if we were given a proto_name the namespace will be registered
909          * as an indipendent protocol with its own hf and ett arrays.
910          */        
911             hfs = g_array_new(FALSE,FALSE,sizeof(hf_register_info));
912             etts = g_array_new(FALSE,FALSE,sizeof(gint*));
913         }
914     
915     /* the root element of the dtd's namespace */
916         root_element = g_malloc(sizeof(xml_ns_t));
917     root_element->name = g_strdup(root_name);
918     root_element->fqn = root_element->name;
919     root_element->hf_tag = -1;
920     root_element->hf_cdata = -1;
921     root_element->ett = -1;
922     root_element->elements = g_hash_table_new(g_str_hash,g_str_equal);
923     root_element->element_names = element_names;
924     
925     /*
926      * we can either create a namespace as a flat namespace
927      * in which all the elements are at the root level
928      * or we can create a recursive namespace
929      */
930     if (dtd_data->recursion) {
931         xml_ns_t* orig_root;
932         
933         make_xml_hier(root_name, root_element, elements,hier,errors,hfs,etts);
934         
935         g_hash_table_insert(root_element->elements,root_element->name,root_element);
936         
937         orig_root = g_hash_table_lookup(elements,root_name);
938         
939         /* if the root element was defined copy its attrlist to the child */
940         if(orig_root) { 
941             struct _attr_reg_data d;
942             
943             d.basename = root_name;
944             d.hf = hfs;
945
946             root_element->attributes = copy_attributes_hash(orig_root->attributes);
947             g_hash_table_foreach(root_element->attributes,add_xml_attribute_names,&d);
948         } else {
949             root_element->attributes = g_hash_table_new(g_str_hash,g_str_equal);
950         }
951
952         /* we then create all the sub hierachies to catch the recurred cases */
953         g_ptr_array_add(hier,root_name);
954         
955         while(root_element->element_names->len) {
956             curr_name = g_ptr_array_remove_index(root_element->element_names,0);
957             
958             if( ! g_hash_table_lookup(root_element->elements,curr_name) ) {
959                 xml_ns_t* new = make_xml_hier(curr_name, root_element, elements,hier,errors,hfs,etts);
960                 g_hash_table_insert(root_element->elements,new->name,new);
961             }
962             
963             g_free(curr_name);
964         }
965         
966     } else {
967         /* a flat namespace */
968         g_ptr_array_add(hier,root_name);
969         
970         root_element->attributes = g_hash_table_new(g_str_hash,g_str_equal);
971
972         while(root_element->element_names->len) {
973             xml_ns_t* new;
974             gint* ett_p;
975             struct _attr_reg_data d;
976             
977             curr_name = g_ptr_array_remove_index(root_element->element_names,0);
978             new = duplicate_element(g_hash_table_lookup(elements,curr_name));
979             new->fqn = fully_qualified_name(hier, curr_name);
980
981             add_xml_field(hfs, &(new->hf_tag), curr_name, new->fqn);
982             add_xml_field(hfs, &(new->hf_cdata), curr_name, new->fqn);
983
984             d.basename = new->fqn;
985             d.hf = hfs;
986
987             g_hash_table_foreach(new->attributes,add_xml_attribute_names,&d);
988
989             ett_p = &new->ett;
990             g_array_append_val(etts,ett_p);
991             
992             g_ptr_array_free(new->element_names,TRUE);
993             
994             g_hash_table_insert(root_element->elements,new->name,new);
995         }
996     }
997
998     g_ptr_array_free(element_names,TRUE);
999     
1000         g_ptr_array_free(hier,TRUE);
1001         
1002     /*
1003      * if we were given a proto_name the namespace will be registered
1004      * as an indipendent protocol.
1005      */
1006         if( dtd_data->proto_name ) {
1007         gint* ett_p;
1008
1009                 if ( ! dtd_data->description) {
1010                         dtd_data->description = g_strdup(root_name);
1011                 }
1012                 
1013         ett_p = &root_element->ett;
1014         g_array_append_val(etts,ett_p);
1015
1016         add_xml_field(hfs, &root_element->hf_cdata, root_element->name, root_element->fqn);
1017             
1018                 root_element->hf_tag = proto_register_protocol(dtd_data->description, dtd_data->proto_name, root_element->name);
1019                 proto_register_field_array(root_element->hf_tag, (hf_register_info*)hfs->data, hfs->len);
1020                 proto_register_subtree_array((gint**)etts->data, etts->len);
1021                 
1022                 if (dtd_data->media_type) {
1023                         g_hash_table_insert(media_types,dtd_data->media_type,root_element);
1024                         dtd_data->media_type = NULL;
1025                 }
1026         
1027                 dtd_data->description = NULL;
1028                 dtd_data->proto_name = NULL;
1029                 g_array_free(hfs,FALSE);
1030                 g_array_free(etts,TRUE);
1031         }
1032     
1033     g_hash_table_insert(xml_ns.elements,root_element->name,root_element);
1034     
1035     g_hash_table_foreach_remove(elements,free_elements,NULL);
1036     g_hash_table_destroy(elements);
1037     
1038         destroy_dtd_data(dtd_data);
1039     
1040     if (root_name)
1041         g_free(root_name);
1042 }
1043
1044 #if GLIB_MAJOR_VERSION < 2
1045 #  define DIRECTORY_T DIR
1046 #  define FILE_T struct dirent
1047 #  define OPENDIR_OP(name) opendir(name)
1048 #  define DIRGETNEXT_OP(dir) readdir(dir)
1049 #  define GETFNAME_OP(file) (gchar *)file->d_name
1050 #  define CLOSEDIR_OP(dir) closedir(dir)
1051 #else /* GLIB 2 */
1052 #  define DIRECTORY_T GDir
1053 #  define FILE_T gchar
1054 #  define OPENDIR_OP(name) g_dir_open(name, 0, dummy)
1055 #  define DIRGETNEXT_OP(dir) g_dir_read_name(dir)
1056 #  define GETFNAME_OP(file) (file);
1057 #  define CLOSEDIR_OP(dir) g_dir_close(dir)
1058 #endif
1059
1060 void init_xml_names(void) {
1061         xml_ns_t* xmlpi_xml_ns;
1062         guint i;
1063     DIRECTORY_T* dir;
1064     const FILE_T* file;
1065     const gchar* filename;
1066     gchar* dirname;
1067     
1068 #if GLIB_MAJOR_VERSION >= 2
1069     GError** dummy = g_malloc(sizeof(GError *));
1070     *dummy = NULL;
1071 #endif
1072     
1073         xmpli_names = g_hash_table_new(g_str_hash,g_str_equal);
1074         media_types = g_hash_table_new(g_str_hash,g_str_equal);
1075         
1076         unknown_ns.elements = xml_ns.elements = g_hash_table_new(g_str_hash,g_str_equal);
1077         unknown_ns.attributes = xml_ns.attributes = g_hash_table_new(g_str_hash,g_str_equal);
1078         
1079         xmlpi_xml_ns = xml_new_namespace(xmpli_names,"xml","version","encoding","standalone",NULL);
1080         
1081         g_hash_table_destroy(xmlpi_xml_ns->elements);
1082         xmlpi_xml_ns->elements = NULL;
1083
1084     
1085     dirname = get_persconffile_path("dtds", FALSE);
1086         
1087         if (test_for_directory(dirname) != EISDIR) {
1088                 dirname = get_datafile_path("dtds");
1089     }
1090     
1091         if (test_for_directory(dirname) == EISDIR) {
1092         
1093         if ((dir = OPENDIR_OP(dirname)) != NULL) {
1094             while ((file = DIRGETNEXT_OP(dir)) != NULL) {
1095                 guint namelen;
1096                 filename = GETFNAME_OP(file);
1097                 
1098                 namelen = strlen(filename);
1099                 if ( namelen > 4 && ( g_strcasecmp(filename+(namelen-4),".dtd")  == 0 ) ) {
1100                     GString* errors = g_string_new("");
1101                     GString* preparsed = dtd_preparse(dirname, filename, errors);
1102                     dtd_build_data_t* dtd_data;
1103                     
1104                     if (errors->len) {
1105                         report_failure("Dtd Preparser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
1106                         continue;
1107                     }
1108                     
1109                     dtd_data = dtd_parse(preparsed);
1110                     
1111                     g_string_free(preparsed,TRUE);
1112                     
1113                     if (dtd_data->error->len) {
1114                         report_failure("Dtd Parser in file %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,dtd_data->error->str);
1115                         destroy_dtd_data(dtd_data);
1116                         continue;
1117                     }
1118                     
1119                     register_dtd(dtd_data,errors);
1120                     
1121                     if (errors->len) {
1122                         report_failure("Dtd Registration in file: %s%c%s: %s",dirname,G_DIR_SEPARATOR,filename,errors->str);
1123                         g_string_free(errors,TRUE);
1124                         continue;
1125                     }
1126                 }
1127             }
1128             
1129             CLOSEDIR_OP(dir);
1130         }
1131     }
1132     
1133         for(i=0;i<array_length(default_media_types);i++) {
1134                 if( ! g_hash_table_lookup(media_types,default_media_types[i]) ) {
1135                         g_hash_table_insert(media_types,(gpointer)default_media_types[i],&xml_ns);
1136                 }
1137         }
1138         
1139         g_hash_table_foreach(xmpli_names,add_xmlpi_namespace,"xml.xmlpi");
1140
1141 #if GLIB_MAJOR_VERSION >= 2
1142     g_free(dummy);
1143 #endif    
1144 }
1145
1146 void
1147 proto_register_xml(void) {
1148         
1149         static gint *ett_base[] = {
1150                 &unknown_ns.ett,
1151                 &xml_ns.ett,
1152                 &ett_dtd,
1153                 &ett_xmpli
1154         };
1155         
1156         static hf_register_info hf_base[] = {
1157                 { &hf_xmlpi, {"XMLPI", "xml.xmlpi", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1158                 { &hf_comment, {"Comment", "xml.comment", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1159                 { &hf_unknowwn_attrib, {"Attribute", "xml.attribute", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1160                 { &hf_doctype, {"Doctype", "xml.doctype", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1161                 { &hf_dtd_tag, {"DTD Tag", "xml.dtdtag", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1162                 { &unknown_ns.hf_cdata, {"CDATA", "xml.cdata", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1163                 { &unknown_ns.hf_tag, {"Tag", "xml.tag", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
1164                 { &xml_ns.hf_cdata, {"Unknown", "xml.unknown", FT_STRING, BASE_NONE, NULL, 0, "", HFILL }}
1165         };
1166
1167         hf_arr = g_array_new(FALSE,FALSE,sizeof(hf_register_info));
1168         ett_arr = g_array_new(FALSE,FALSE,sizeof(gint*));
1169
1170         g_array_append_vals(hf_arr,hf_base,array_length(hf_base));
1171         g_array_append_vals(ett_arr,ett_base,array_length(ett_base));
1172         
1173         init_xml_names();
1174
1175         xml_ns.hf_tag = proto_register_protocol("eXtensible Markup Language", "XML", xml_ns.name);
1176
1177         proto_register_field_array(xml_ns.hf_tag, (hf_register_info*)hf_arr->data, hf_arr->len);
1178         proto_register_subtree_array((gint**)ett_arr->data, ett_arr->len);
1179         
1180     g_array_free(hf_arr,FALSE);
1181     g_array_free(ett_arr,TRUE);
1182     
1183         register_dissector("xml", dissect_xml, xml_ns.hf_tag);
1184         
1185         init_xml_parser();
1186     
1187 }
1188
1189 void add_dissector_media(gpointer k, gpointer v _U_, gpointer p _U_) {
1190         dissector_add_string("media_type", (gchar*)k, xml_handle);
1191 }
1192
1193 void
1194 proto_reg_handoff_xml(void)
1195 {
1196         
1197         xml_handle = find_dissector("xml");
1198         
1199         g_hash_table_foreach(media_types,add_dissector_media,NULL);
1200         
1201 }