4 * XML dissector for wireshark
7 * Copyright 2005, Luis E. Garcia Ontanon <luis@ontanon.org>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
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.
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.
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.
38 #include "dtd_parse.h"
40 static dtd_named_list_t* dtd_named_list_new(gchar* name, GPtrArray* list) {
41 dtd_named_list_t* nl = g_malloc(sizeof(dtd_named_list_t));
49 static GPtrArray* g_ptr_array_join(GPtrArray* a, GPtrArray* b){
52 g_ptr_array_add(a,g_ptr_array_remove_index_fast(b,0));
55 g_ptr_array_free(b,TRUE);
64 %extra_argument { dtd_build_data_t *bd }
68 if ($$->text) g_free($$->text);
69 if ($$->location) g_free($$->location);
76 g_string_append_printf(bd->error,"syntax error at end of file");
78 g_string_append_printf(bd->error,"syntax error in %s at or before '%s': \n", TOKEN->location,TOKEN->text);
82 g_string_append_printf(bd->error,"DTD parsing failure\n");
87 %token_type { dtd_token_data_t* }
92 doctype ::= TAG_START DOCTYPE_KW NAME(Name) OPEN_BRACKET dtd_parts CLOSE_BRACKET TAG_STOP. {
93 dtd_named_list_t* root;
94 GPtrArray* root_elems = g_ptr_array_new();
98 if(! bd->proto_name) {
99 bd->proto_name = Name->text;
103 g_free(bd->proto_root);
105 bd->proto_root = Name->text;
107 name = g_ascii_strdown(bd->proto_name, -1);
108 g_free(bd->proto_name);
109 bd->proto_name = name;
111 for( i = 0; i< bd->elements->len; i++) {
112 dtd_named_list_t* el = g_ptr_array_index(bd->elements,i);
114 g_ptr_array_add(root_elems,g_strdup(el->name));
117 root = dtd_named_list_new(g_strdup(Name->text),root_elems);
119 g_ptr_array_add(bd->elements,root);
121 g_free(Name->location);
126 dtd_parts ::= dtd_parts element(Element). { g_ptr_array_add(bd->elements,Element); }
127 dtd_parts ::= dtd_parts attlist(Attlist). { g_ptr_array_add(bd->attributes,Attlist); }
128 dtd_parts ::= element(Element). { g_ptr_array_add(bd->elements,Element); }
129 dtd_parts ::= attlist(Attlist). { g_ptr_array_add(bd->attributes,Attlist); }
131 %type attlist { dtd_named_list_t* }
132 attlist(A) ::= TAG_START ATTLIST_KW NAME(B) attrib_list(TheList) TAG_STOP. {
133 A = dtd_named_list_new(g_ascii_strdown(B->text, -1),TheList);
139 %type element { dtd_named_list_t* }
140 element(A) ::= TAG_START ELEMENT_KW NAME(B) sub_elements(C) TAG_STOP. {
141 A = dtd_named_list_new(g_ascii_strdown(B->text, -1),C);
147 %type attrib_list { GPtrArray* }
148 attrib_list(A) ::= attrib_list(B) attrib(C). { g_ptr_array_add(B,C); A = B; }
149 attrib_list(A) ::= attrib(B). { A = g_ptr_array_new(); g_ptr_array_add(A,B); }
151 %type attrib { gchar* }
152 attrib(A) ::= NAME(B) att_type att_default. {
153 A = g_ascii_strdown(B->text, -1);
159 att_type ::= ATT_TYPE.
160 att_type ::= enumeration.
162 att_default ::= ATT_DEF.
163 att_default ::= ATT_DEF_WITH_VALUE QUOTED.
164 att_default ::= QUOTED.
165 att_default ::= IMPLIED_KW.
166 att_default ::= REQUIRED_KW.
168 enumeration ::= OPEN_PARENS enum_list CLOSE_PARENS.
170 enum_list ::= enum_list PIPE enum_item.
171 enum_list ::= enum_item.
172 enum_list ::= enumeration.
173 enum_list ::= enum_list PIPE enumeration.
176 enum_item ::= QUOTED.
179 %type sub_elements { GPtrArray* }
180 sub_elements(A) ::= sub_elements(B) STAR. {A=B;}
181 sub_elements(A) ::= sub_elements(B) PLUS. {A=B;}
182 sub_elements(A) ::= sub_elements(B) QUESTION. {A=B;}
183 sub_elements(A) ::= OPEN_PARENS ELEM_DATA CLOSE_PARENS. { A = g_ptr_array_new(); }
184 sub_elements(A) ::= OPEN_PARENS element_list(B) COMMA ELEM_DATA CLOSE_PARENS. { A = B; }
185 sub_elements(A) ::= OPEN_PARENS element_list(B) PIPE ELEM_DATA CLOSE_PARENS. { A = B; }
186 sub_elements(A) ::= OPEN_PARENS element_list(B) CLOSE_PARENS. { A = B; }
187 sub_elements(A) ::= EMPTY_KW. { A = g_ptr_array_new(); }
189 %type element_list { GPtrArray* }
190 element_list(A) ::= element_list(B) COMMA element_child(C). { g_ptr_array_add(B,C); A = B; }
191 element_list(A) ::= element_list(B) PIPE element_child(C). { g_ptr_array_add(B,C); A = B; }
192 element_list(A) ::= element_child(B). { A = g_ptr_array_new(); g_ptr_array_add(A,B); }
193 element_list(A) ::= sub_elements(B). { A = B; }
194 element_list(A) ::= element_list(B) COMMA sub_elements(C). { A = g_ptr_array_join(B,C); }
195 element_list(A) ::= element_list(B) PIPE sub_elements(C). { A = g_ptr_array_join(B,C); }
197 %type element_child { gchar* }
198 element_child(A) ::= NAME(B). {
199 A = g_ascii_strdown(B->text, -1);
205 element_child(A) ::= NAME(B) STAR. {
206 A = g_ascii_strdown(B->text, -1);
212 element_child(A) ::= NAME(B) QUESTION. {
213 A = g_ascii_strdown(B->text, -1);
219 element_child(A) ::= NAME(B) PLUS. {
220 A = g_ascii_strdown(B->text, -1);