1 ###################################################
2 # Ethereal parser generator for IDL structures
3 # Copyright tpot@samba.org 2001
4 # Copyright tridge@samba.org 2000
5 # released under the GNU GPL
17 return 1, if ($type eq "uint32");
18 return 1, if ($type eq "long");
19 return 1, if ($type eq "short");
20 return 1, if ($type eq "char");
21 return 1, if ($type eq "uint16");
22 return 1, if ($type eq "hyper");
27 #####################################################################
28 # parse a properties list
29 sub ParseProperties($)
32 foreach my $d (@{$props}) {
33 if (ref($d) ne "HASH") {
36 foreach my $k (keys %{$d}) {
37 $res .= "[$k($d->{$k})] ";
43 #####################################################################
44 # parse a structure element
50 # (defined $elt->{PROPERTIES}) && ParseProperties($elt->{PROPERTIES});
51 # ParseType($elt->{TYPE});
54 # if ($elt->{POINTERS}) {
55 # for (my($i)=0; $i < $elt->{POINTERS}; $i++) {
59 # $res .= "$elt->{NAME}";
60 # (defined $elt->{ARRAY_LEN}) && ($res .= "[$elt->{ARRAY_LEN}]");
64 # Arg is a policy handle
66 foreach my $prop (@{$elt->{PROPERTIES}}) {
67 if ($prop =~ /context_handle/) {
68 $res .= "\toffset = prs_policy_hnd(tvb, offset, pinfo, tree);\n";
75 if ($flags =~ /scalars/) {
77 # Pointers are scalars
79 if ($elt->{POINTERS}) {
80 $res .= "\t\tptr_$elt->{NAME} = prs_ptr(tvb, offset, pinfo, tree, \"$elt->{NAME}\");\n";
83 # Simple type are scalars too
85 if (is_scalar_type($elt->{TYPE})) {
86 $res .= "\t\tprs_$elt->{TYPE}(tvb, offset, pinfo, tree, \"$elt->{NAME}}\");\n\n";
92 # Scalars are not buffers
94 if (!is_scalar_type($elt->{TYPE})) {
96 # If we have a pointer, check it
98 if ($elt->{POINTERS}) {
99 $res .= "\t\tif (ptr_$elt->{NAME}) {\n\t";
102 $res .= "\t\tprs_$elt->{TYPE}(tvb, offset, pinfo, tree, flags, \"$elt->{NAME}\");\n\n";
104 if ($elt->{POINTERS}) {
112 # if (is_simple_type($elt->{TYPE})) {
113 # if ($flags =~ /scalars/ && !$elt->{POINTERS}) {
114 # $res .= "\t\tprs_$elt->{TYPE}(tvb, offset, pinfo, tree, \"$elt->{NAME}}\");\n\n",
117 # if ($flags =~ /buffers/) {
118 # if ($elt->{POINTERS}) {
119 # $res .= "\t\tif (ptr_$elt->{NAME}) {\n\t";
121 # $res .= "\t\tprs_$elt->{TYPE}(tvb, offset, pinfo, tree, flags, \"$elt->{NAME}\");\n\n";
122 # if ($elt->{POINTERS}) {
123 # $res .= "\t\t}\n\n";
129 #####################################################################
135 if (defined $struct->{ELEMENTS}) {
139 $res .= "\tif (flags & PARSE_SCALARS) {\n";
141 foreach my $e (@{$struct->{ELEMENTS}}) {
142 ParseElement($e, "scalars");
144 # if (defined $e->{POINTERS}) {
145 # $res .= "\t\toffset = prs_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, \"$e->{NAME}\");\n";
147 # $res .= "\t\toffset = prs_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n";
155 $res .= "\tif (flags & PARSE_BUFFERS) {\n";
157 foreach my $e (@{$struct->{ELEMENTS}}) {
158 ParseElement($e, "buffers");
159 # $res .= "\t\tif (ptr_$e->{NAME})\n\t\t\toffset = prs_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n\n",
160 # if (defined $e->{POINTERS});
168 #####################################################################
169 # parse a union element
170 sub ParseUnionElement($)
172 my($element) = shift;
174 # $res .= "int prs_$element->{DATA}->{TYPE}()\n{\n";
178 $res .= "\tcase $element->{DATA}->{NAME}: \n";
179 $res .= "\t\toffset = prs_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
181 # $res .= "[case($element->{CASE})] ";
182 # ParseElement($element->{DATA});
186 #####################################################################
192 $res .= "\tswitch (level) {\n";
194 (defined $union->{PROPERTIES}) && ParseProperties($union->{PROPERTIES});
195 foreach my $e (@{$union->{DATA}}) {
196 ParseUnionElement($e);
202 #####################################################################
208 if (ref($data) eq "HASH") {
209 ($data->{TYPE} eq "STRUCT") &&
211 ($data->{TYPE} eq "UNION") &&
218 #####################################################################
222 my($typedef) = shift;
224 $res .= "static int prs_$typedef->{NAME}(tvbuff_t *tvb, int offset,\
225 \tpacket_info *pinfo, proto_tree *tree)\n{\n";
226 ParseType($typedef->{DATA});
230 #####################################################################
232 sub ParseFunctionArg($$)
235 my($io) = shift; # "in" or "out"
237 if (@{$arg->{PROPERTIES}}[0] =~ /$io/) {
240 ParseElement($arg, "scalars");
244 #####################################################################
248 my($function) = shift;
252 $res .= "static int $function->{NAME}_q(tvbuff_t *tvb, int offset,\
253 \tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
255 foreach my $arg (@{$function->{DATA}}) {
256 ParseFunctionArg($arg, "in");
259 $res .= "\n\treturn 0;\n}\n\n";
263 $res .= "static int $function->{NAME}_r(tvbuff_t *tvb, int offset,\
264 \tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
266 foreach my $arg (@{$function->{DATA}}) {
267 ParseFunctionArg($arg, "out");
270 $res .= "\n\toffset = prs_ntstatus(tvb, offset, pinfo, tree);\n";
272 $res .= "\n\treturn 0;\n}\n\n";
276 #####################################################################
277 # parse the interface definitions
278 sub ParseInterface($)
280 my($interface) = shift;
281 my($data) = $interface->{DATA};
282 foreach my $d (@{$data}) {
283 ($d->{TYPE} eq "TYPEDEF") &&
285 ($d->{TYPE} eq "FUNCTION") &&
291 #####################################################################
292 # parse a parsed IDL structure back into an IDL file
296 $res = "/* parser auto-generated by pidl */\n\n";
297 foreach my $x (@{$idl}) {
298 ($x->{TYPE} eq "INTERFACE") &&