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");
22 #####################################################################
23 # parse a properties list
24 sub ParseProperties($)
27 foreach my $d (@{$props}) {
28 if (ref($d) ne "HASH") {
31 foreach my $k (keys %{$d}) {
32 $res .= "[$k($d->{$k})] ";
38 #####################################################################
39 # parse a structure element
43 (defined $element->{PROPERTIES}) && ParseProperties($element->{PROPERTIES});
44 ParseType($element->{TYPE});
46 if ($element->{POINTERS}) {
47 for (my($i)=0; $i < $element->{POINTERS}; $i++) {
51 $res .= "$element->{NAME}";
52 (defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]");
55 #####################################################################
61 if (defined $struct->{ELEMENTS}) {
65 $res .= "\tif (flags & PARSE_SCALARS) {\n";
67 foreach my $e (@{$struct->{ELEMENTS}}) {
68 if (defined $e->{POINTERS}) {
69 $res .= "\t\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, \"$e->{NAME}\");\n";
71 $res .= "\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n";
79 $res .= "\tif (flags & PARSE_BUFFERS) {\n";
81 foreach my $e (@{$struct->{ELEMENTS}}) {
82 $res .= "\t\tif (ptr_$e->{NAME})\n\t\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n\n",
83 if (defined $e->{POINTERS});
91 #####################################################################
92 # parse a union element
93 sub ParseUnionElement($)
97 # $res .= "int dissect_$element->{DATA}->{TYPE}()\n{\n";
101 $res .= "\tcase $element->{DATA}->{NAME}: \n";
102 $res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
104 # $res .= "[case($element->{CASE})] ";
105 # ParseElement($element->{DATA});
109 #####################################################################
115 $res .= "\tswitch (level) {\n";
117 (defined $union->{PROPERTIES}) && ParseProperties($union->{PROPERTIES});
118 foreach my $e (@{$union->{DATA}}) {
119 ParseUnionElement($e);
125 #####################################################################
131 if (ref($data) eq "HASH") {
132 ($data->{TYPE} eq "STRUCT") &&
134 ($data->{TYPE} eq "UNION") &&
141 #####################################################################
145 my($typedef) = shift;
147 $res .= "static int dissect_$typedef->{NAME}(tvbuff_t *tvb, int offset,\
148 \tpacket_info *pinfo, proto_tree *tree)\n{\n";
149 ParseType($typedef->{DATA});
153 #####################################################################
155 sub ParseFunctionArg($$)
158 my($io) = shift; # "in" or "out"
160 if (@{$arg->{PROPERTIES}}[0] =~ /$io/) {
163 # Arg is a policy handle - no pointer
165 foreach my $prop (@{$arg->{PROPERTIES}}) {
166 if ($prop =~ /context_handle/) {
167 $res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree);\n";
173 if ($arg->{POINTERS}) {
174 $res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
175 $res .= "\tif (ptr_$arg->{NAME})\n\t\toffset = ";
177 if (is_simple_type($arg->{TYPE})) {
178 $res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}}\");\n\n";
180 $res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, PARSE_SCALARS|PARSE_BUFFERS, \"$arg->{NAME}\");\n\n";
183 $res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
189 #####################################################################
193 my($function) = shift;
197 $res .= "static int $function->{NAME}_q(tvbuff_t *tvb, int offset,\
198 \tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
200 foreach my $arg (@{$function->{DATA}}) {
201 ParseFunctionArg($arg, "in");
204 $res .= "\n\treturn 0;\n}\n\n";
208 $res .= "static int $function->{NAME}_r(tvbuff_t *tvb, int offset,\
209 \tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
211 foreach my $arg (@{$function->{DATA}}) {
212 ParseFunctionArg($arg, "out");
215 $res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree);\n";
217 $res .= "\n\treturn 0;\n}\n\n";
221 #####################################################################
222 # parse the interface definitions
223 sub ParseInterface($)
225 my($interface) = shift;
226 my($data) = $interface->{DATA};
227 foreach my $d (@{$data}) {
228 ($d->{TYPE} eq "TYPEDEF") &&
230 ($d->{TYPE} eq "FUNCTION") &&
236 #####################################################################
237 # parse a parsed IDL structure back into an IDL file
241 $res = "/* parser auto-generated by pidl */\n\n";
242 foreach my $x (@{$idl}) {
243 ($x->{TYPE} eq "INTERFACE") &&