1 ###################################################
2 # parser generator for IDL structures
3 # Copyright tpot@samba.org 2001
4 # Copyright tridge@samba.org 2000
5 # released under the GNU GPL
15 sub ParamSimpleNdrType($)
20 $res .= "\toffset = dissect_ndr_$p->{TYPE}(tvb, offset, pinfo, tree, drep, hf_$p->{NAME}, NULL);\n";
25 sub ParamPolicyHandle($)
30 $res .= "\toffset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep, hf_policy_hnd, NULL, NULL, FALSE, FALSE);\n";
35 my %param_handlers = (
36 'uint16' => \&ParamSimpleNdrType,
37 'uint32' => \&ParamSimpleNdrType,
38 'policy_handle' => \&ParamPolicyHandle,
41 #####################################################################
48 if (defined($param_handlers{$p->{TYPE}})) {
49 $res .= &{$param_handlers{$p->{TYPE}}}($p);
53 $res .= "\t/* Unhandled IDL type '$p->{TYPE}' in $p->{PARENT}->{NAME} */\n";
59 #####################################################################
67 $res .= IdlDump::DumpFunction($f);
72 $res .= "static int\n";
73 $res .= "$f->{NAME}_rqst(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n";
77 foreach $d (@{$f->{DATA}}) {
78 $res .= ParseParameter($d), if defined($d->{PROPERTIES}{in});
81 $res .= "\treturn offset;\n";
86 $res .= "static int\n";
87 $res .= "$f->{NAME}_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n";
90 foreach $d (@{$f->{DATA}}) {
91 $res .= ParseParameter($d), if defined($d->{PROPERTIES}{out});
95 $res .= "\treturn offset;\n";
101 #####################################################################
102 # parse the interface definitions
103 sub Pass2Interface($)
105 my($interface) = shift;
106 my($data) = $interface->{DATA};
109 foreach my $d (@{$data}) {
110 $res .= ParseFunction($d), if $d->{TYPE} eq "FUNCTION";
116 #####################################################################
117 # Pass 1: Stuff required before structs and functions
119 sub Pass1ModuleHeader($)
129 #include "packet-dcerpc.h"
130 #include "packet-dcerpc-nt.h"
136 if ($d->{TYPE} eq "MODULEHEADER" and defined($d->{PROPERTIES}->{uuid})) {
137 my $uuid = $d->{PROPERTIES}->{uuid};
138 $res .= "static e_uuid_t uuid_dcerpc_$name = {\n";
139 $res .= "\t0x" . substr($uuid, 0, 8);
140 $res .= ", 0x" . substr($uuid, 9, 4);
141 $res .= ", 0x" . substr($uuid, 14, 4) . ",\n";
142 $res .= "\t{ 0x" . substr($uuid, 19, 2);
143 $res .= ", 0x" . substr($uuid, 21, 2);
144 $res .= ", 0x" . substr($uuid, 24, 2);
145 $res .= ", 0x" . substr($uuid, 26, 2);
146 $res .= ", 0x" . substr($uuid, 28, 2);
147 $res .= ", 0x" . substr($uuid, 30, 2);
148 $res .= ", 0x" . substr($uuid, 32, 2);
149 $res .= ", 0x" . substr($uuid, 34, 2) . " }\n";
152 $res .= "static guint16 ver_dcerpc_samr = " .
153 $d->{PROPERTIES}->{version} . ";\n\n";
159 sub Pass1Interface($)
161 my($interface) = shift;
165 static int proto_dcerpc_$name = -1;
167 static int hf_${name}_opnum = -1;
168 static int hf_${name}_rc = -1;
169 static int hf_policy_hnd = -1;
171 static gint ett_dcerpc_$name = -1;
177 foreach my $fn (@{$interface->{DATA}}) {
178 next, if $fn->{TYPE} ne "FUNCTION";
179 foreach my $args ($fn->{DATA}) {
180 foreach my $params (@{$args}) {
181 $res .= "static int hf_$params->{NAME} = -1;\n",
182 if not defined $p{$params->{NAME}};
183 $p{$params->{NAME}} = 1;
193 #####################################################################
194 # Pass 3: trailing stuff
196 sub Pass3Interface($)
198 my($interface) = shift;
201 $res .= "static dcerpc_sub_dissector dcerpc_${name}_dissectors[] = {\n";
205 foreach my $d (@{$interface->{DATA}}) {
206 if ($d->{TYPE} eq "FUNCTION") {
207 # Strip module name from function name, if present
209 $n = substr($d->{NAME}, length($name) + 1),
210 if $name eq substr($d->{NAME}, 0, length($name));
212 $res .= "\t{ $num, \"$n\",\n";
213 $res .= "\t\t$d->{NAME}_rqst,\n";
214 $res .= "\t\t$d->{NAME}_resp },\n";
224 #####################################################################
225 # parse a parsed IDL structure back into an IDL file
229 my($res) = "/* parser auto-generated by pidl */\n\n";
232 # Pass 0: set module name
234 foreach $d (@{$idl}) {
235 $name = $d->{NAME}, if ($d->{TYPE} eq "INTERFACE");
238 # Pass 1: header stuff
240 foreach $d (@{$idl}) {
241 $res .= Pass1ModuleHeader($d), if $d->{TYPE} eq "MODULEHEADER";
242 $res .= Pass1Interface($d), if $d->{TYPE} eq "INTERFACE";
245 # Pass 2: typedefs and functions
247 foreach $d (@{$idl}) {
248 $res .= Pass2Interface($d), if $d->{TYPE} eq "INTERFACE";
251 # Pass 3: trailing stuff
253 foreach $d (@{$idl}) {
254 $res .= Pass3Interface($d), if $d->{TYPE} eq "INTERFACE";
259 proto_reg_handoff_dcerpc_$name(void)
261 dcerpc_init_uuid(proto_dcerpc_$name, ett_dcerpc_$name,
262 &uuid_dcerpc_$name, ver_dcerpc_$name,
263 dcerpc_${name}_dissectors, hf_${name}_opnum);