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
13 #####################################################################
14 # parse a properties list
15 sub ParseProperties($)
18 foreach my $d (@{$props}) {
19 if (ref($d) ne "HASH") {
22 foreach my $k (keys %{$d}) {
23 $res .= "[$k($d->{$k})] ";
29 #####################################################################
30 # parse a structure element
34 (defined $element->{PROPERTIES}) && ParseProperties($element->{PROPERTIES});
35 ParseType($element->{TYPE});
37 if ($element->{POINTERS}) {
38 for (my($i)=0; $i < $element->{POINTERS}; $i++) {
42 $res .= "$element->{NAME}";
43 (defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]");
46 #####################################################################
52 if (defined $struct->{ELEMENTS}) {
56 $res .= "\t/* Parse scalars */\n\n";
58 foreach my $e (@{$struct->{ELEMENTS}}) {
59 if (defined $e->{POINTERS}) {
60 $res .= "\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, \"$e->{NAME}\");\n";
62 $res .= "\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n";
68 $res .= "\n\t/* Parse buffers */\n\n";
70 foreach my $e (@{$struct->{ELEMENTS}}) {
71 $res .= "\tif (ptr_$e->{NAME})\n\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n\n",
72 if (defined $e->{POINTERS});
78 #####################################################################
79 # parse a union element
80 sub ParseUnionElement($)
84 # $res .= "int dissect_$element->{DATA}->{TYPE}()\n{\n";
88 $res .= "\tcase $element->{DATA}->{NAME}: \n";
89 $res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
91 # $res .= "[case($element->{CASE})] ";
92 # ParseElement($element->{DATA});
96 #####################################################################
102 $res .= "\tswitch (level) {\n";
104 (defined $union->{PROPERTIES}) && ParseProperties($union->{PROPERTIES});
105 foreach my $e (@{$union->{DATA}}) {
106 ParseUnionElement($e);
112 #####################################################################
118 if (ref($data) eq "HASH") {
119 ($data->{TYPE} eq "STRUCT") &&
121 ($data->{TYPE} eq "UNION") &&
128 #####################################################################
132 my($typedef) = shift;
134 $res .= "static int dissect_$typedef->{NAME}(tvbuff_t *tvb, int offset,\
135 \tpacket_info *pinfo, proto_tree *tree)\n{\n";
136 ParseType($typedef->{DATA});
140 #####################################################################
142 sub ParseFunctionArg($$)
145 my($io) = shift; # "in" or "out"
147 if (@{$arg->{PROPERTIES}}[0] =~ /$io/) {
150 # Arg is a policy handle - no pointer
152 foreach my $prop (@{$arg->{PROPERTIES}}) {
153 if ($prop =~ /context_handle/) {
154 $res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree, \"policy_hnd\");\n";
160 if ($arg->{POINTERS}) {
161 $res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
162 $res .= "\tif (ptr_$arg->{NAME})\
163 \t\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n\n";
165 $res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
171 #####################################################################
175 my($function) = shift;
179 $res .= "static int $function->{NAME}_q(tvbuff_t *tvb, int offset,\
180 \tpacket_info *pinfo, proto_tree *tree)\n{\n";
182 foreach my $arg (@{$function->{DATA}}) {
183 ParseFunctionArg($arg, "in");
186 $res .= "\n\treturn 0;\n}\n\n";
190 $res .= "static int $function->{NAME}_r(tvbuff_t *tvb, int offset,\
191 \tpacket_info *pinfo, proto_tree *tree)\n{\n";
193 foreach my $arg (@{$function->{DATA}}) {
194 ParseFunctionArg($arg, "out");
197 $res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree, \"status\");\n";
199 $res .= "\n\treturn 0;\n}\n\n";
203 #####################################################################
204 # parse the interface definitions
205 sub ParseInterface($)
207 my($interface) = shift;
208 my($data) = $interface->{DATA};
209 foreach my $d (@{$data}) {
210 ($d->{TYPE} eq "TYPEDEF") &&
212 ($d->{TYPE} eq "FUNCTION") &&
218 #####################################################################
219 # parse a parsed IDL structure back into an IDL file
223 $res = "/* parser auto-generated by pidl */\n\n";
224 foreach my $x (@{$idl}) {
225 ($x->{TYPE} eq "INTERFACE") &&