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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include "dtd_parse.h"
38 static dtd_named_list_t* dtd_named_list_new(gchar* name, GPtrArray* list) {
39 dtd_named_list_t* nl = g_new(dtd_named_list_t,1);
47 static GPtrArray* g_ptr_array_join(GPtrArray* a, GPtrArray* b){
50 g_ptr_array_add(a,g_ptr_array_remove_index_fast(b,0));
53 g_ptr_array_free(b,TRUE);
62 %extra_argument { dtd_build_data_t *bd }
66 if ($$->text) g_free($$->text);
67 if ($$->location) g_free($$->location);
74 g_string_append_printf(bd->error,"syntax error at end of file");
76 g_string_append_printf(bd->error,"syntax error in %s at or before '%s': \n", TOKEN->location,TOKEN->text);
80 g_string_append_printf(bd->error,"DTD parsing failure\n");
85 %token_type { dtd_token_data_t* }
90 doctype ::= TAG_START DOCTYPE_KW NAME(Name) OPEN_BRACKET dtd_parts CLOSE_BRACKET TAG_STOP. {
91 dtd_named_list_t* root;
92 GPtrArray* root_elems = g_ptr_array_new();
96 if(! bd->proto_name) {
97 bd->proto_name = Name->text;
101 g_free(bd->proto_root);
103 bd->proto_root = Name->text;
105 name = g_ascii_strdown(bd->proto_name, -1);
106 g_free(bd->proto_name);
107 bd->proto_name = name;
109 for( i = 0; i< bd->elements->len; i++) {
110 dtd_named_list_t* el = (dtd_named_list_t*)g_ptr_array_index(bd->elements,i);
112 g_ptr_array_add(root_elems,g_strdup(el->name));
115 root = dtd_named_list_new(g_strdup(Name->text),root_elems);
117 g_ptr_array_add(bd->elements,root);
119 g_free(Name->location);
124 dtd_parts ::= dtd_parts element(Element). { g_ptr_array_add(bd->elements,Element); }
125 dtd_parts ::= dtd_parts attlist(Attlist). { g_ptr_array_add(bd->attributes,Attlist); }
126 dtd_parts ::= element(Element). { g_ptr_array_add(bd->elements,Element); }
127 dtd_parts ::= attlist(Attlist). { g_ptr_array_add(bd->attributes,Attlist); }
129 %type attlist { dtd_named_list_t* }
130 attlist(A) ::= TAG_START ATTLIST_KW NAME(B) attrib_list(TheList) TAG_STOP. {
131 A = dtd_named_list_new(g_ascii_strdown(B->text, -1),TheList);
137 %type element { dtd_named_list_t* }
138 element(A) ::= TAG_START ELEMENT_KW NAME(B) sub_elements(C) TAG_STOP. {
139 A = dtd_named_list_new(g_ascii_strdown(B->text, -1),C);
145 %type attrib_list { GPtrArray* }
146 attrib_list(A) ::= attrib_list(B) attrib(C). { g_ptr_array_add(B,C); A = B; }
147 attrib_list(A) ::= attrib(B). { A = g_ptr_array_new(); g_ptr_array_add(A,B); }
149 %type attrib { gchar* }
150 attrib(A) ::= NAME(B) att_type att_default. {
151 A = g_ascii_strdown(B->text, -1);
157 att_type ::= ATT_TYPE.
158 att_type ::= enumeration.
160 att_default ::= ATT_DEF.
161 att_default ::= ATT_DEF_WITH_VALUE QUOTED.
162 att_default ::= QUOTED.
163 att_default ::= IMPLIED_KW.
164 att_default ::= REQUIRED_KW.
166 enumeration ::= OPEN_PARENS enum_list CLOSE_PARENS.
168 enum_list ::= enum_list PIPE enum_item.
169 enum_list ::= enum_item.
170 enum_list ::= enumeration.
171 enum_list ::= enum_list PIPE enumeration.
174 enum_item ::= QUOTED.
177 %type sub_elements { GPtrArray* }
178 sub_elements(A) ::= sub_elements(B) STAR. {A=B;}
179 sub_elements(A) ::= sub_elements(B) PLUS. {A=B;}
180 sub_elements(A) ::= sub_elements(B) QUESTION. {A=B;}
181 sub_elements(A) ::= OPEN_PARENS ELEM_DATA CLOSE_PARENS. { A = g_ptr_array_new(); }
182 sub_elements(A) ::= OPEN_PARENS element_list(B) COMMA ELEM_DATA CLOSE_PARENS. { A = B; }
183 sub_elements(A) ::= OPEN_PARENS element_list(B) PIPE ELEM_DATA CLOSE_PARENS. { A = B; }
184 sub_elements(A) ::= OPEN_PARENS element_list(B) CLOSE_PARENS. { A = B; }
185 sub_elements(A) ::= EMPTY_KW. { A = g_ptr_array_new(); }
187 %type element_list { GPtrArray* }
188 element_list(A) ::= element_list(B) COMMA element_child(C). { g_ptr_array_add(B,C); A = B; }
189 element_list(A) ::= element_list(B) PIPE element_child(C). { g_ptr_array_add(B,C); A = B; }
190 element_list(A) ::= element_child(B). { A = g_ptr_array_new(); g_ptr_array_add(A,B); }
191 element_list(A) ::= sub_elements(B). { A = B; }
192 element_list(A) ::= element_list(B) COMMA sub_elements(C). { A = g_ptr_array_join(B,C); }
193 element_list(A) ::= element_list(B) PIPE sub_elements(C). { A = g_ptr_array_join(B,C); }
195 %type element_child { gchar* }
196 element_child(A) ::= NAME(B). {
197 A = g_ascii_strdown(B->text, -1);
203 element_child(A) ::= NAME(B) STAR. {
204 A = g_ascii_strdown(B->text, -1);
210 element_child(A) ::= NAME(B) QUESTION. {
211 A = g_ascii_strdown(B->text, -1);
217 element_child(A) ::= NAME(B) PLUS. {
218 A = g_ascii_strdown(B->text, -1);