r602: Autogenerated packet-dcerpc-samr.c now compiles!
authorTim Potter <tpot@samba.org>
Sun, 9 May 2004 10:03:55 +0000 (10:03 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:51:50 +0000 (12:51 -0500)
(This used to be commit 0c1069b56e7c80e2b428f6a6b550eacd5ac3d762)

source4/build/pidl/eparser.pm
source4/build/pidl/pidl.pl

index f32e1b98424c8605c3ac2bbe18055865e5386d0f..f7d383d29752469e9b742a04da26cf49430c12ce 100644 (file)
@@ -10,6 +10,8 @@ use strict;
 use dump;
 use Data::Dumper;
 
+my($name);
+
 sub ParamSimpleNdrType($)
 {
     my($p) = shift;
@@ -25,7 +27,7 @@ sub ParamPolicyHandle($)
     my($p) = shift;
     my($res);
 
-    $res .= "\toffset = dissect_nt_policy_handle(tvb, offset, pinfo, tree, drep, hf_policy_hnd, NULL, NULL, FALSE, FALSE);\n";
+    $res .= "\toffset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep, hf_policy_hnd, NULL, NULL, FALSE, FALSE);\n";
 
     return $res;
 }
@@ -89,7 +91,7 @@ sub ParseFunction($)
        $res .= ParseParameter($d), if defined($d->{PROPERTIES}{out});
     }
 
-
+    $res .= "\n";
     $res .= "\treturn offset;\n";
     $res .= "}\n\n";
 
@@ -98,7 +100,7 @@ sub ParseFunction($)
 
 #####################################################################
 # parse the interface definitions
-sub ParseInterface($)
+sub Pass2Interface($)
 {
     my($interface) = shift;
     my($data) = $interface->{DATA};
@@ -111,19 +113,157 @@ sub ParseInterface($)
     return $res;
 }
 
+#####################################################################
+# Pass 1: Stuff required before structs and functions
+
+sub Pass1ModuleHeader($)
+{
+    my($d) = shift;
+    my($res) = "";
+
+    $res .= << "EOF";
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "packet-dcerpc.h"
+#include "packet-dcerpc-nt.h"
+
+EOF
+
+    # UUID
+
+    if ($d->{TYPE} eq "MODULEHEADER" and defined($d->{PROPERTIES}->{uuid})) {
+       my $uuid = $d->{PROPERTIES}->{uuid};
+       $res .= "static e_uuid_t uuid_dcerpc_$name = {\n";
+       $res .= "\t0x" . substr($uuid, 0, 8);
+       $res .= ", 0x" . substr($uuid, 9, 4);
+       $res .= ", 0x" . substr($uuid, 14, 4) . ",\n";
+       $res .= "\t{ 0x" . substr($uuid, 19, 2);
+       $res .= ", 0x" . substr($uuid, 21, 2);
+       $res .= ", 0x" . substr($uuid, 24, 2);
+       $res .= ", 0x" . substr($uuid, 26, 2);
+       $res .= ", 0x" . substr($uuid, 28, 2);
+       $res .= ", 0x" . substr($uuid, 30, 2);
+       $res .= ", 0x" . substr($uuid, 32, 2);
+       $res .= ", 0x" . substr($uuid, 34, 2) . " }\n";
+       $res .= "};\n\n";
+       
+       $res .= "static guint16 ver_dcerpc_samr = " . 
+           $d->{PROPERTIES}->{version} . ";\n\n";
+    }
+
+    return $res;
+}
+
+sub Pass1Interface($)
+{
+    my($interface) = shift;
+    my($res) = "";
+
+    $res .= << "EOF";
+static int proto_dcerpc_$name = -1;
+
+static int hf_${name}_opnum = -1;
+static int hf_${name}_rc = -1;
+static int hf_policy_hnd = -1;
+
+static gint ett_dcerpc_$name = -1;
+
+EOF
+
+    my %p = ();
+
+    foreach my $fn (@{$interface->{DATA}}) {
+       next, if $fn->{TYPE} ne "FUNCTION";
+       foreach my $args ($fn->{DATA}) {
+           foreach my $params (@{$args}) {
+               $res .= "static int hf_$params->{NAME} = -1;\n",
+                   if not defined $p{$params->{NAME}};
+               $p{$params->{NAME}} = 1;
+           }
+       }
+    }
+
+    $res .= "\n";
+
+    return $res;
+}
+
+#####################################################################
+# Pass 3: trailing stuff
+
+sub Pass3Interface($)
+{
+    my($interface) = shift;
+    my($res) = "";
+
+    $res .= "static dcerpc_sub_dissector dcerpc_${name}_dissectors[] = {\n";
+
+    my $num = 0;
+
+    foreach my $d (@{$interface->{DATA}}) {
+       if ($d->{TYPE} eq "FUNCTION") {
+           # Strip module name from function name, if present
+           my $n = $d->{NAME};
+           $n = substr($d->{NAME}, length($name) + 1),
+               if $name eq substr($d->{NAME}, 0, length($name));
+
+           $res .= "\t{ $num, \"$n\",\n";
+           $res .= "\t\t$d->{NAME}_rqst,\n";
+           $res .= "\t\t$d->{NAME}_resp },\n";
+           $num++;
+       }
+    }
+
+    $res .= "};\n\n";
+
+    return $res;
+}
 
 #####################################################################
 # parse a parsed IDL structure back into an IDL file
 sub Parse($)
 {
     my($idl) = shift;
-    my($res);
+    my($res) = "/* parser auto-generated by pidl */\n\n";
+    my($d);
+
+    # Pass 0: set module name
+
+    foreach $d (@{$idl}) {
+       $name = $d->{NAME}, if ($d->{TYPE} eq "INTERFACE");
+    }
+
+    # Pass 1: header stuff
+
+    foreach $d (@{$idl}) {
+       $res .= Pass1ModuleHeader($d), if $d->{TYPE} eq "MODULEHEADER";
+       $res .= Pass1Interface($d), if $d->{TYPE} eq "INTERFACE";
+    }
 
-    $res = "/* parser auto-generated by pidl */\n\n";
-    foreach my $d (@{$idl}) {
-       $res .= ParseInterface($d), if $d->{TYPE} eq "INTERFACE";
+    # Pass 2: typedefs and functions
+
+    foreach $d (@{$idl}) {
+       $res .= Pass2Interface($d), if $d->{TYPE} eq "INTERFACE";
+    }
+
+    # Pass 3: trailing stuff
+
+    foreach $d (@{$idl}) {
+       $res .= Pass3Interface($d), if $d->{TYPE} eq "INTERFACE";
     }
 
+    $res .= << "EOF";
+void
+proto_reg_handoff_dcerpc_$name(void)
+{
+        dcerpc_init_uuid(proto_dcerpc_$name, ett_dcerpc_$name, 
+                        &uuid_dcerpc_$name, ver_dcerpc_$name, 
+                        dcerpc_${name}_dissectors, hf_${name}_opnum);
+}
+EOF
+
     return $res;
 }
 
index 46585e2ca573c03d5014c9585ad30aa461b3e931..6004ebb145a9df09209e5fd99f53e7488347d772 100755 (executable)
@@ -144,7 +144,7 @@ sub process_file($)
        }
 
        if ($opt_eparser) {
-               my($parser) = util::ChangeExtension($output, "_ethereal.c");
+               my($parser) = dirname($output) . "/packet-dcerpc-$basename.c";
                util::FileSave($parser, IdlEParser::Parse($pidl));
        }