summaryrefslogtreecommitdiff
path: root/source4/build/pidl/Parse
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-07-09 15:32:08 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:27 -0500
commitfa1445f4bc962efb3e639d3a4e345b1db14155b7 (patch)
tree8799d04bc9ec022569fedd636e899bcc29a57935 /source4/build/pidl/Parse
parentc222331d6d3785075bb0c961315aae9380101e47 (diff)
downloadsamba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.tar.gz
samba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.tar.bz2
samba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.zip
r8264: - Use standard perl package structure for pidl.
- Only "use" pidl modules in the main executable when necessary Try 'make install' in build/pidl to install the package (should work stand-alone). (This used to be commit c620095692122a65ae1c5d85ca20468d4de93c54)
Diffstat (limited to 'source4/build/pidl/Parse')
-rw-r--r--source4/build/pidl/Parse/Pidl.pm16
-rw-r--r--source4/build/pidl/Parse/Pidl/Compat.pm55
-rw-r--r--source4/build/pidl/Parse/Pidl/Dump.pm241
-rw-r--r--source4/build/pidl/Parse/Pidl/Ethereal/NDR/Header.pm101
-rw-r--r--source4/build/pidl/Parse/Pidl/Ethereal/NDR/Parser.pm1323
-rw-r--r--source4/build/pidl/Parse/Pidl/IDL.pm2485
-rw-r--r--source4/build/pidl/Parse/Pidl/NDR.pm597
-rw-r--r--source4/build/pidl/Parse/Pidl/ODL.pm89
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/COM/Header.pm138
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/COM/Proxy.pm211
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/COM/Stub.pm323
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/EJS.pm734
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/EJSHeader.pm75
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/NDR/Client.pm99
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/NDR/Header.pm472
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/NDR/Parser.pm2230
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/NDR/Server.pm322
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/SWIG.pm76
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/Template.pm88
-rw-r--r--source4/build/pidl/Parse/Pidl/Test.pm169
-rw-r--r--source4/build/pidl/Parse/Pidl/Typelist.pm326
-rw-r--r--source4/build/pidl/Parse/Pidl/Util.pm219
-rw-r--r--source4/build/pidl/Parse/Pidl/Validator.pm369
23 files changed, 10758 insertions, 0 deletions
diff --git a/source4/build/pidl/Parse/Pidl.pm b/source4/build/pidl/Parse/Pidl.pm
new file mode 100644
index 0000000000..465f3409ad
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl.pm
@@ -0,0 +1,16 @@
+###################################################
+# package to parse IDL files and generate code for
+# rpc functions in Samba
+# Copyright tridge@samba.org 2000-2003
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl;
+
+use strict;
+
+use vars qw ( $VERSION );
+
+$VERSION = '0.01';
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Compat.pm b/source4/build/pidl/Parse/Pidl/Compat.pm
new file mode 100644
index 0000000000..f81d73f36a
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Compat.pm
@@ -0,0 +1,55 @@
+###################################################
+# IDL Compatibility checker
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Compat;
+
+use strict;
+
+my($res);
+
+sub warning($$)
+{
+ my $l = shift;
+ my $m = shift;
+
+ print "$l->{FILE}:$l->{LINE}:$m\n";
+}
+
+sub CheckInterface($)
+{
+ my $if = shift;
+ if (util::has_property($if, "pointer_default_top")) {
+ warning($if, "pointer_default_top() is pidl-specific");
+ }
+
+ foreach my $x (@{$if->{DATA}}) {
+ if ($x->{TYPE} eq "DECLARE") {
+ warning($if, "the declare keyword is pidl-specific");
+ next;
+ }
+
+ if ($x->{TYPE} eq "TYPEDEF") {
+ if ($x->{DATA}->{TYPE} eq "UNION") {
+ if (util::has_property($x, "nodiscriminant")) {
+ warning($x, "nodiscriminant property is pidl-specific");
+ }
+ }
+ }
+ }
+}
+
+sub Check($)
+{
+ my $pidl = shift;
+ my $res = "";
+
+ foreach my $x (@{$pidl}) {
+ CheckInterface($x) if ($x->{TYPE} eq "INTERFACE");
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Dump.pm b/source4/build/pidl/Parse/Pidl/Dump.pm
new file mode 100644
index 0000000000..7a18cf5173
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Dump.pm
@@ -0,0 +1,241 @@
+###################################################
+# dump function for IDL structures
+# Copyright tridge@samba.org 2000
+# released under the GNU GPL
+
+package Parse::Pidl::Dump;
+
+use strict;
+
+my($res);
+
+#####################################################################
+# dump a properties list
+sub DumpProperties($)
+{
+ my($props) = shift;
+ my($res);
+
+ foreach my $d ($props) {
+ foreach my $k (keys %{$d}) {
+ if ($k eq "in") {
+ $res .= "[in] ";
+ next;
+ }
+ if ($k eq "out") {
+ $res .= "[out] ";
+ next;
+ }
+ if ($k eq "ref") {
+ $res .= "[ref] ";
+ next;
+ }
+ $res .= "[$k($d->{$k})] ";
+ }
+ }
+ return $res;
+}
+
+#####################################################################
+# dump a structure element
+sub DumpElement($)
+{
+ my($element) = shift;
+ my($res);
+
+ (defined $element->{PROPERTIES}) &&
+ ($res .= DumpProperties($element->{PROPERTIES}));
+ $res .= DumpType($element->{TYPE});
+ $res .= " ";
+ for my $i (1..$element->{POINTERS}) {
+ $res .= "*";
+ }
+ $res .= "$element->{NAME}";
+ foreach (@{$element->{ARRAY_LEN}}) {
+ $res .= "[$_]";
+ }
+
+ return $res;
+}
+
+#####################################################################
+# dump a struct
+sub DumpStruct($)
+{
+ my($struct) = shift;
+ my($res);
+
+ $res .= "struct {\n";
+ if (defined $struct->{ELEMENTS}) {
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ $res .= DumpElement($e);
+ $res .= ";\n";
+ }
+ }
+ $res .= "}";
+
+ return $res;
+}
+
+
+#####################################################################
+# dump a struct
+sub DumpEnum($)
+{
+ my($enum) = shift;
+ my($res);
+
+ $res .= "enum";
+
+ return $res;
+}
+
+
+#####################################################################
+# dump a union element
+sub DumpUnionElement($)
+{
+ my($element) = shift;
+ my($res);
+
+ if (util::has_property($element, "default")) {
+ $res .= "[default] ;\n";
+ } else {
+ $res .= "[case($element->{PROPERTIES}->{case})] ";
+ $res .= DumpElement($element), if defined($element);
+ $res .= ";\n";
+ }
+
+ return $res;
+}
+
+#####################################################################
+# dump a union
+sub DumpUnion($)
+{
+ my($union) = shift;
+ my($res);
+
+ (defined $union->{PROPERTIES}) &&
+ ($res .= DumpProperties($union->{PROPERTIES}));
+ $res .= "union {\n";
+ foreach my $e (@{$union->{ELEMENTS}}) {
+ $res .= DumpUnionElement($e);
+ }
+ $res .= "}";
+
+ return $res;
+}
+
+#####################################################################
+# dump a type
+sub DumpType($)
+{
+ my($data) = shift;
+ my($res);
+
+ if (ref($data) eq "HASH") {
+ ($data->{TYPE} eq "STRUCT") &&
+ ($res .= DumpStruct($data));
+ ($data->{TYPE} eq "UNION") &&
+ ($res .= DumpUnion($data));
+ ($data->{TYPE} eq "ENUM") &&
+ ($res .= DumpEnum($data));
+ } else {
+ $res .= "$data";
+ }
+
+ return $res;
+}
+
+#####################################################################
+# dump a typedef
+sub DumpTypedef($)
+{
+ my($typedef) = shift;
+ my($res);
+
+ $res .= "typedef ";
+ $res .= DumpType($typedef->{DATA});
+ $res .= " $typedef->{NAME};\n\n";
+
+ return $res;
+}
+
+#####################################################################
+# dump a typedef
+sub DumpFunction($)
+{
+ my($function) = shift;
+ my($first) = 1;
+ my($res);
+
+ $res .= DumpType($function->{RETURN_TYPE});
+ $res .= " $function->{NAME}(\n";
+ for my $d (@{$function->{DATA}}) {
+ $first || ($res .= ",\n"); $first = 0;
+ $res .= DumpElement($d);
+ }
+ $res .= "\n);\n\n";
+
+ return $res;
+}
+
+#####################################################################
+# dump a module header
+sub DumpInterfaceProperties($)
+{
+ my($header) = shift;
+ my($data) = $header->{DATA};
+ my($first) = 1;
+ my($res);
+
+ $res .= "[\n";
+ foreach my $k (keys %{$data}) {
+ $first || ($res .= ",\n"); $first = 0;
+ $res .= "$k($data->{$k})";
+ }
+ $res .= "\n]\n";
+
+ return $res;
+}
+
+#####################################################################
+# dump the interface definitions
+sub DumpInterface($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ my($res);
+
+ $res .= DumpInterfaceProperties($interface->{PROPERTIES});
+
+ $res .= "interface $interface->{NAME}\n{\n";
+ foreach my $d (@{$data}) {
+ ($d->{TYPE} eq "TYPEDEF") &&
+ ($res .= DumpTypedef($d));
+ ($d->{TYPE} eq "FUNCTION") &&
+ ($res .= DumpFunction($d));
+ }
+ $res .= "}\n";
+
+ return $res;
+}
+
+
+#####################################################################
+# dump a parsed IDL structure back into an IDL file
+sub Dump($)
+{
+ my($idl) = shift;
+ my($res);
+
+ $res = "/* Dumped by pidl */\n\n";
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") &&
+ ($res .= DumpInterface($x));
+ }
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Header.pm b/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Header.pm
new file mode 100644
index 0000000000..c4d983e793
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Header.pm
@@ -0,0 +1,101 @@
+###################################################
+# create C header files for an IDL structure
+# Copyright tridge@samba.org 2000
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Ethereal::NDR::Header;
+
+use strict;
+
+my($res);
+my($tab_depth);
+
+sub pidl ($)
+{
+ $res .= shift;
+}
+
+sub tabs()
+{
+ for (my($i)=0; $i < $tab_depth; $i++) {
+ pidl "\t";
+ }
+}
+
+#####################################################################
+# prototype a typedef
+sub HeaderTypedefProto($)
+{
+ my($d) = shift;
+
+ my $tf = EthParser::get_typefamily($d->{DATA}{TYPE});
+
+ return unless util::has_property($d, "public");
+
+ unless (util::has_property($d, "nopull")) {
+ pidl "dcerpc_dissect_fnct_t $d->{NAME};\n";
+ }
+}
+
+#####################################################################
+# parse a const
+sub HeaderConst($)
+{
+ my($const) = shift;
+ if (!defined($const->{ARRAY_LEN}[0])) {
+ pidl "#define $const->{NAME}\t( $const->{VALUE} )\n";
+ } else {
+ pidl "#define $const->{NAME}\t $const->{VALUE}\n";
+ }
+}
+
+my %headerstructs = ();
+
+#####################################################################
+# parse the interface definitions
+sub HeaderInterface($)
+{
+ my($interface) = shift;
+
+ my $count = 0;
+
+ pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
+ pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
+
+ if (defined $interface->{PROPERTIES}->{depends}) {
+ my @d = split / /, $interface->{PROPERTIES}->{depends};
+ foreach my $i (@d) {
+ pidl "#include \"packet-dcerpc-$i\.h\"\n";
+ }
+ }
+
+ foreach my $d (@{$interface->{CONSTS}}) {
+ HeaderConst($d);
+ }
+
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ HeaderTypedefProto($d);
+ }
+
+ pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Parse($)
+{
+ my($idl) = shift;
+ $tab_depth = 0;
+
+ $res = "";
+ pidl "/* header auto-generated by pidl */\n\n";
+ foreach my $x (@{$idl}) {
+ if ($x->{TYPE} eq "INTERFACE") {
+ HeaderInterface($x);
+ }
+ }
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Parser.pm b/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Parser.pm
new file mode 100644
index 0000000000..96eafc0b57
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Ethereal/NDR/Parser.pm
@@ -0,0 +1,1323 @@
+##################################################
+# Samba4 NDR parser generator for IDL structures
+# Copyright tridge@samba.org 2000-2003
+# Copyright tpot@samba.org 2001
+# Copyright jelmer@samba.org 2004-2005
+# released under the GNU GPL
+
+package Parse::Pidl::Ethereal::NDR::Parser;
+
+use strict;
+use Parse::Pidl::Typelist;
+use Parse::Pidl::NDR;
+
+# the list of needed functions
+
+# list of known types
+my %typefamily;
+
+
+sub NeededFunction($$)
+{
+ my $fn = shift;
+ my $needed = shift;
+ $needed->{"pull_$fn->{NAME}"} = 1;
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ $e->{PARENT} = $fn;
+ unless(defined($needed->{"pull_$e->{TYPE}"})) {
+ $needed->{"pull_$e->{TYPE}"} = 1;
+ }
+
+ # for Ethereal
+ $needed->{"hf_$fn->{NAME}_$e->{NAME}"} = {
+ 'name' => field2name($e->{NAME}),
+ 'type' => $e->{TYPE},
+ 'ft' => type2ft($e->{TYPE}),
+ 'base' => elementbase($e)
+ };
+ $needed->{"hf_$e->{TYPE}"} = {
+ 'name' => field2name($e->{NAME}),
+ 'type' => $e->{TYPE},
+ 'ft' => type2ft($e->{TYPE}),
+ 'base' => elementbase($e)
+ };
+ $needed->{"ett_$e->{TYPE}"} = 1;
+ }
+
+ # Add entry for return value
+ if (defined($fn->{RETURN_TYPE})) {
+ $needed->{"hf_$fn->{NAME}_result"} = {
+ 'name' => field2name('result'),
+ 'type' => $fn->{RETURN_TYPE},
+ 'ft' => type2ft($fn->{RETURN_TYPE}),
+ 'base' => elementbase($fn)
+ };
+ }
+}
+
+sub NeededTypedef($$)
+{
+ my $t = shift;
+ my $needed = shift;
+
+ if (util::has_property($t, "public")) {
+ $needed->{"pull_$t->{NAME}"} = not util::has_property($t, "nopull");
+ $needed->{"decl_$t->{NAME}"} = not util::has_property($t, "nopull");
+ }
+
+ if ($t->{DATA}->{TYPE} eq "STRUCT" or $t->{DATA}->{TYPE} eq "UNION") {
+
+ for my $e (@{$t->{DATA}->{ELEMENTS}}) {
+ $e->{PARENT} = $t->{DATA};
+ if ($needed->{"pull_$t->{NAME}"} and
+ not defined($needed->{"pull_$e->{TYPE}"})) {
+ $needed->{"decl_$e->{TYPE}"} = $needed->{"pull_$e->{TYPE}"} = 1;
+ }
+
+ $needed->{"hf_$t->{NAME}_$e->{NAME}"} = {
+ 'name' => field2name($e->{NAME}),
+ 'type' => $e->{TYPE},
+ 'ft' => type2ft($e->{TYPE}),
+ 'base' => elementbase($e)
+ };
+ $needed->{"ett_$e->{TYPE}"} = 1;
+ }
+ }
+
+ if ($t->{DATA}->{TYPE} eq "ENUM") {
+
+ $needed->{"hf_$t->{NAME}"} = {
+ 'name' => field2name($t->{NAME}),
+ 'ft' => 'FT_UINT16',
+ 'base' => 'BASE_DEC',
+ 'strings' => "VALS($t->{NAME}_vals)"
+ };
+ $needed->{"ett_$t->{NAME}"} = 1;
+ }
+
+ if ($t->{DATA}->{TYPE} eq "BITMAP") {
+ $needed->{BITMAPS}->{$t->{NAME}} = $t;
+
+ foreach my $e (@{$t->{DATA}{ELEMENTS}}) {
+ $e =~ /^(.*?) \( (.*?) \)$/;
+ $needed->{"hf_$t->{NAME}_$1"} = {
+ 'name' => "$1",
+ 'ft' => "FT_BOOLEAN",
+ 'base' => bitmapbase($t),
+ 'bitmask' => "$2"
+ };
+ }
+ $needed->{"ett_$t->{NAME}"} = 1;
+ }
+}
+
+#####################################################################
+# work out what parse functions are needed
+sub NeededInterface($)
+{
+ my($interface) = shift;
+ my %needed = ();
+
+ $needed{"hf_$interface->{NAME}_opnum"} = {
+ 'name' => "Operation",
+ 'ft' => "FT_UINT16",
+ 'base' => "BASE_DEC"
+ };
+
+ $needed{"ett_dcerpc_$interface->{NAME}"} = 1;
+
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ NeededFunction($d, \%needed);
+ }
+ foreach my $d (reverse @{$interface->{TYPEDEFS}}) {
+ NeededTypedef($d, \%needed);
+ }
+
+ return \%needed;
+}
+
+sub type2ft($)
+{
+ my($t) = shift;
+
+ return "FT_UINT$1" if $t =~ /uint(8|16|32|64)/;
+ return "FT_INT$1" if $t =~ /int(8|16|32|64)/;
+ return "FT_UINT64", if $t eq "HYPER_T" or $t eq "NTTIME"
+ or $t eq "NTTIME_1sec" or $t eq "NTTIME_hyper" or $t eq "hyper";
+
+ # Type is an enum
+
+ return "FT_UINT16";
+}
+
+# Determine the display base for an element
+
+sub elementbase($)
+{
+ my($e) = shift;
+
+ if (my $base = util::has_property($e, "display")) {
+ return "BASE_" . uc($base);
+ }
+
+ return "BASE_DEC", if $e->{TYPE} eq "ENUM";
+ return "BASE_DEC", if $e->{TYPE} =~ /u?int(8|16|32|64)/;
+ return "BASE_DEC", if $e->{TYPE} eq "NTTIME" or $e->{TYPE} eq "HYPER_T";
+
+ # Probably an enum
+
+ return "BASE_DEC";
+}
+
+# Convert a IDL structure field name (e.g access_mask) to a prettier
+# string like 'Access Mask'.
+
+sub field2name($)
+{
+ my($field) = shift;
+
+ $field =~ s/_/ /g; # Replace underscores with spaces
+ $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word
+
+ return $field;
+}
+
+sub bitmapbase($)
+{
+ my $e = shift;
+
+ return "16", if util::has_property($e->{DATA}, "bitmap16bit");
+ return "8", if util::has_property($e->{DATA}, "bitmap8bit");
+
+ return "32";
+}
+
+sub get_typefamily($)
+{
+ my $n = shift;
+ return $typefamily{$n};
+}
+
+sub append_prefix($$)
+{
+ my $e = shift;
+ my $var_name = shift;
+ my $pointers = 0;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER") {
+ $pointers++;
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ if (($pointers == 0) and
+ (not $l->{IS_FIXED}) and
+ (not $l->{IS_INLINE})) {
+ return get_value_of($var_name)
+ }
+ } elsif ($l->{TYPE} eq "DATA") {
+ if (typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ return get_value_of($var_name) unless ($pointers);
+ }
+ }
+ }
+
+ return $var_name;
+}
+
+# see if a variable needs to be allocated by the NDR subsystem on pull
+sub need_alloc($)
+{
+ my $e = shift;
+
+ return 0;
+}
+
+sub get_pointer_to($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\*(.*)$/) {
+ return $1;
+ } elsif ($var_name =~ /^\&(.*)$/) {
+ return $var_name;
+# return "&($var_name)";
+ } else {
+ return "&$var_name";
+ }
+}
+
+sub get_value_of($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\&(.*)$/) {
+ return $1;
+ } else {
+ return "*$var_name";
+ }
+}
+
+my $res;
+my $tabs = "";
+sub pidl($)
+{
+ my $d = shift;
+ if ($d) {
+ $res .= $tabs;
+ $res .= $d;
+ }
+ $res .="\n";
+}
+
+sub indent()
+{
+ $tabs .= "\t";
+}
+
+sub deindent()
+{
+ $tabs = substr($tabs, 0, -1);
+}
+
+#####################################################################
+# check that a variable we get from ParseExpr isn't a null pointer
+sub check_null_pointer($)
+{
+ my $size = shift;
+ if ($size =~ /^\*/) {
+ my $size2 = substr($size, 1);
+ pidl "if ($size2 == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;";
+ }
+}
+
+#####################################################################
+# check that a variable we get from ParseExpr isn't a null pointer
+# void return varient
+sub check_null_pointer_void($)
+{
+ my $size = shift;
+ if ($size =~ /^\*/) {
+ my $size2 = substr($size, 1);
+ pidl "if ($size2 == NULL) return;";
+ }
+}
+
+#####################################################################
+# work out is a parse function should be declared static or not
+sub fn_prefix($)
+{
+ my $fn = shift;
+
+ return "" if (util::has_property($fn, "public"));
+ return "static ";
+}
+
+###################################################################
+# setup any special flags for an element or structure
+sub start_flags($)
+{
+ my $e = shift;
+ my $flags = util::has_property($e, "flag");
+ if (defined $flags) {
+ pidl "{ uint32_t _flags_save_$e->{TYPE} = ndr->flags;";
+ pidl "ndr_set_flags(&ndr->flags, $flags);";
+ indent;
+ }
+}
+
+###################################################################
+# end any special flags for an element or structure
+sub end_flags($)
+{
+ my $e = shift;
+ my $flags = util::has_property($e, "flag");
+ if (defined $flags) {
+ pidl "ndr->flags = _flags_save_$e->{TYPE};\n\t}";
+ deindent;
+ }
+}
+
+sub GenerateStructEnv($)
+{
+ my $x = shift;
+ my %env;
+
+ foreach my $e (@{$x->{ELEMENTS}}) {
+ $env{$e->{NAME}} = "r->$e->{NAME}";
+ }
+
+ $env{"this"} = "r";
+
+ return \%env;
+}
+
+sub GenerateFunctionEnv($)
+{
+ my $fn = shift;
+ my %env;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep (/out/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->out.$e->{NAME}";
+ }
+ if (grep (/in/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->in.$e->{NAME}";
+ }
+ }
+
+ return \%env;
+}
+
+#####################################################################
+sub ParseArrayPreceding($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $var_name = shift;
+
+ return if ($l->{NO_METADATA});
+
+ # non fixed arrays encode the size just before the array
+ pidl "ndr_pull_array_size(ndr, tree, " . get_pointer_to($var_name) . ");";
+}
+
+sub compression_alg($$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return $alg;
+}
+
+sub compression_clen($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $env = shift;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return util::ParseExpr($clen, $env);
+}
+
+sub compression_dlen($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $env = shift;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return util::ParseExpr($dlen, $env);
+}
+
+sub ParseCompressionStart($$$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $subndr = shift;
+ my $env = shift;
+ my $comndr = $subndr."_compressed";
+ my $alg = compression_alg($e, $l);
+ my $dlen = compression_dlen($e, $l, $env);
+
+ pidl "{";
+ indent;
+ pidl "struct pidl_pull *$comndr;";
+ pidl "NDR_ALLOC($subndr, $comndr);";
+ pidl "ndr_pull_compression($subndr, $comndr, $alg, $dlen);";
+
+ return $comndr;
+}
+
+sub ParseCompressionEnd($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $subndr = shift;
+ my $comndr = $subndr."_compressed";
+
+ deindent;
+ pidl "}";
+}
+
+sub ParseObfuscationStart($$)
+{
+ my $e = shift;
+ my $ndr = shift;
+ my $obfuscation = util::has_property($e, "obfuscation");
+
+ pidl "ndr_pull_obfuscation($ndr, $obfuscation);";
+
+ return $ndr;
+}
+
+sub ParseObfuscationEnd($$)
+{
+ my $e = shift;
+ my $ndr = shift;
+
+ # nothing to do here
+}
+
+sub ParseSubcontextStart($$$$$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my $var_name = shift;
+ my $ndr_flags = shift;
+ my $env = shift;
+ my $retndr = "_ndr_$e->{NAME}";
+
+ pidl "/* NDR_FLAGS $ndr_flags */";
+ pidl "if ((ndr_flags) & NDR_SCALARS) {";
+ indent;
+ pidl "struct pidl_pull *$retndr;";
+ pidl "NDR_ALLOC(ndr, $retndr);";
+ pidl "ndr_pull_subcontext_header($ndr, $l->{HEADER_SIZE}, $l->{SUBCONTEXT_SIZE}, $retndr);";
+
+ if (defined $l->{COMPRESSION}) {
+ $retndr = ParseCompressionStart($e, $l, $retndr, $env);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ $retndr = ParseObfuscationStart($e, $retndr);
+ }
+
+ return ($retndr,$var_name);
+}
+
+sub ParseSubcontextEnd($$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $ndr = "_ndr_$e->{NAME}";
+
+ if (defined $l->{COMPRESSION}) {
+ ParseCompressionEnd($e, $l, $ndr);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ ParseObfuscationEnd($e, $ndr);
+ }
+
+ my $advance;
+ if (defined($l->{SUBCONTEXT_SIZE}) and ($l->{SUBCONTEXT_SIZE} ne "-1")) {
+ $advance = $l->{SUBCONTEXT_SIZE};
+ } elsif ($l->{HEADER_SIZE}) {
+ $advance = "$ndr->data_size";
+ } else {
+ $advance = "$ndr->offset";
+ }
+ pidl "ndr_pull_advance(ndr, $advance);";
+ deindent;
+ pidl "}";
+}
+
+#####################################################################
+# parse scalars in a structure element - pull size
+sub ParseSwitch($$$$$$)
+{
+ my($e) = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my($var_name) = shift;
+ my($ndr_flags) = shift;
+ my $env = shift;
+ my $switch_var = util::ParseExpr($l->{SWITCH_IS}, $env);
+
+ check_null_pointer($switch_var);
+
+ $var_name = get_pointer_to($var_name);
+ pidl "ndr_pull_set_switch_value($ndr, $var_name, $switch_var);";
+
+}
+
+sub ParseData($$$$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my $var_name = shift;
+ my $ndr_flags = shift;
+
+ #
+ # ALAND! for packet-dcerpc-lsa.c, uncommenting this code
+ # produces constructs like &(&r->string), to pass to another
+ # function, which gives compiler errors.
+ #
+ if (typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ $var_name = get_pointer_to($var_name);
+
+ pidl "offset += dissect_$l->{DATA_TYPE}(tvb, offset, pinfo, tree, drep, hf_FIXME, NULL);";
+
+ if (my $range = util::has_property($e, "range")) {
+ $var_name = get_value_of($var_name);
+ my ($low, $high) = split(/ /, $range, 2);
+ if (($l->{DATA_TYPE} =~ /^uint/) and ($low eq "0")) {
+ pidl "if ($var_name > $high) {";
+ } else {
+ pidl "if ($var_name < $low || $var_name > $high) {";
+ }
+ pidl "\treturn NT_STATUS_OK;";
+ pidl "}";
+ }
+}
+
+sub CalcNdrFlags($$$)
+{
+ my $l = shift;
+ my $primitives = shift;
+ my $deferred = shift;
+
+ my $scalars = 0;
+ my $buffers = 0;
+
+ # Add NDR_SCALARS if this one is deferred
+ # and deferreds may be pushed
+ $scalars = 1 if ($l->{IS_DEFERRED} and $deferred);
+
+ # Add NDR_SCALARS if this one is not deferred and
+ # primitives may be pushed
+ $scalars = 1 if (!$l->{IS_DEFERRED} and $primitives);
+
+ # Add NDR_BUFFERS if this one contains deferred stuff
+ # and deferreds may be pushed
+ $buffers = 1 if ($l->{CONTAINS_DEFERRED} and $deferred);
+
+ return "NDR_SCALARS|NDR_BUFFERS" if ($scalars and $buffers);
+ return "NDR_SCALARS" if ($scalars);
+ return "NDR_BUFFERS" if ($buffers);
+ return undef;
+}
+
+
+sub ParseElementLevel
+{
+ my($e) = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my($var_name) = shift;
+ my $env = shift;
+ my $primitives = shift;
+ my $deferred = shift;
+
+ my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred);
+
+ # Only pull something if there's actually something to be pulled
+ if (defined($ndr_flags)) {
+ if ($l->{TYPE} eq "SUBCONTEXT") {
+ ($ndr,$var_name) = ParseSubcontextStart($e, $l, $ndr, $var_name, $ndr_flags, $env);
+ ParseElementLevel($e,Ndr::GetNextLevel($e,$l), $ndr, $var_name, $env, $primitives, $deferred);
+ ParseSubcontextEnd($e, $l);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $length = ParseArrayHeader($e, $l, $ndr, $var_name, $env);
+ } elsif ($l->{TYPE} eq "POINTER") {
+ ParsePtr($e, $l, $ndr, $var_name);
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseSwitch($e, $l, $ndr, $var_name, $ndr_flags, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ ParseData($e, $l, $ndr, $var_name, $ndr_flags);
+ }
+ }
+
+ # add additional constructions
+ if ($l->{TYPE} eq "POINTER" and $deferred) {
+ if ($l->{POINTER_TYPE} ne "ref") {
+ pidl "if ($var_name) {";
+ indent;
+
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "struct ndr_pull_save _relative_save;";
+ pidl "ndr_pull_save(ndr, &_relative_save);";
+ pidl "NDR_CHECK(ndr_pull_relative_ptr2(ndr, $var_name));";
+ }
+ }
+
+ $var_name = get_value_of($var_name);
+ ParseElementLevel($e,Ndr::GetNextLevel($e,$l), $ndr, $var_name, $env, $primitives, $deferred);
+
+ if ($l->{POINTER_TYPE} ne "ref") {
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "ndr_pull_restore(ndr, &_relative_save);";
+ }
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $length = util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
+
+ $var_name = $var_name . "[$counter]";
+ unless ($l->{NO_METADATA}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ if (($primitives and not $l->{IS_DEFERRED}) or ($deferred and $l->{IS_DEFERRED})) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementLevel($e,Ndr::GetNextLevel($e,$l), $ndr, $var_name, $env, 1, 0);
+ deindent;
+ pidl "}";
+ }
+
+ if ($deferred and Ndr::ContainsDeferred($e, $l)) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementLevel($e,Ndr::GetNextLevel($e,$l), $ndr, $var_name, $env, 0, 1);
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseElementLevel($e,Ndr::GetNextLevel($e,$l), $ndr, $var_name, $env, $primitives, $deferred);
+ }
+}
+
+#####################################################################
+# parse scalars in a structure element - pull size
+sub ParseElement($$$$$$)
+{
+ my($e) = shift;
+ my $ndr = shift;
+ my($var_prefix) = shift;
+ my $env = shift;
+ my $primitives = shift;
+ my $deferred = shift;
+
+ my $var_name = $var_prefix.$e->{NAME};
+
+ $var_name = append_prefix($e, $var_name);
+
+ return unless $primitives or ($deferred and Ndr::ContainsDeferred($e, $e->{LEVELS}[0]));
+
+ start_flags($e);
+
+ ParseElementLevel($e,$e->{LEVELS}[0],$ndr,$var_name,$env,$primitives,$deferred);
+
+ end_flags($e);
+}
+
+#####################################################################
+# parse a pointer in a struct element or function
+sub ParsePtr($$$$)
+{
+ my($e) = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my($var_name) = shift;
+
+ my $nl = Ndr::GetNextLevel($e, $l);
+ my $next_is_array = ($nl->{TYPE} eq "ARRAY");
+
+ if ($l->{LEVEL} eq "EMBEDDED") {
+ pidl "dissect_ndr_embedded_pointer(FIXME);";
+ } elsif ($l->{POINTER_TYPE} ne "ref") {
+ pidl "dissect_ndr_toplevel_pointer(FIXME);";
+ }
+
+ #pidl "memset($var_name, 0, sizeof($var_name));";
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "ndr_pull_relative_ptr1($ndr, $var_name, _ptr_$e->{NAME});";
+ }
+}
+
+$typefamily{ENUM} = {
+ DECL => \&DeclEnum,
+};
+
+#####################################################################
+# generate a pull function for an bitmap
+sub ParseBitmap($$)
+{
+ my($bitmap) = shift;
+ my $name = shift;
+ my $type_fn = $bitmap->{BASE_TYPE};
+ my($type_decl) = typelist::mapType($bitmap->{BASE_TYPE});
+
+ pidl "$type_decl v_bitmap;";
+ start_flags($bitmap);
+ pidl "dissect_$type_fn(ndr, tree, hf, &v_bitmap);";
+
+ pidl "{\n\tproto_tree *subtree = NULL;";
+ pidl "";
+ pidl "\tif (tree->proto_tree)\n\t\tsubtree = proto_item_add_subtree(tree->proto_tree->last_child, ett_$name);";
+ pidl "";
+ foreach my $e (@{$bitmap->{DATA}{ELEMENTS}}) {
+ $e =~ /^(.*?) \( (.*?) \)$/;
+ pidl "\tproto_tree_add_boolean(subtree, hf_${name}_$1, ndr->tvb, ndr->offset - sizeof(v_bitmap), sizeof(v_bitmap), v_bitmap);";
+ }
+ pidl "}";
+
+ pidl "*r = v_bitmap;";
+
+ end_flags($bitmap);
+}
+
+$typefamily{BITMAP} = {
+ FN_BODY => \&ParseBitmap,
+};
+
+#####################################################################
+# parse a struct - pull side
+sub ParseStruct($$)
+{
+ my($struct) = shift;
+ my $name = shift;
+ my $conform_e;
+
+ return unless defined $struct->{ELEMENTS};
+
+ my $env = GenerateStructEnv($struct);
+
+ # see if the structure contains a conformant array. If it
+ # does, then it must be the last element of the structure, and
+ # we need to pull the conformant length early, as it fits on
+ # the wire before the structure (and even before the structure
+ # alignment)
+ $conform_e = $struct->{SURROUNDING_ELEMENT};
+
+ # declare any internal pointers we need
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER" and not ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP")) {
+ pidl "uint32_t _ptr_$e->{NAME};";
+ last;
+ }
+ }
+ }
+
+ start_flags($struct);
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ if (defined $conform_e) {
+ ParseArrayPreceding($conform_e, $conform_e->{LEVELS}[0], "r->$conform_e->{NAME}");
+ }
+
+ pidl "ndr_pull_align(ndr, $struct->{ALIGN});";
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElement($e, "ndr", "r->", $env, 1, 0);
+ }
+ deindent;
+ pidl "}";
+
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElement($e, "ndr", "r->", $env, 0, 0);
+ }
+
+ pidl "proto_item_set_end(tree->proto_tree, ndr->tvb, ndr->offset);";
+ deindent;
+ pidl "}";
+
+ end_flags($struct);
+}
+
+$typefamily{STRUCT} = {
+ FN_BODY => \&ParseStruct,
+};
+
+#####################################################################
+# parse a union - pull side
+sub ParseUnion($$$)
+{
+ my $e = shift;
+ my $name = shift;
+ my $have_default = 0;
+ my $switch_type = $e->{SWITCH_TYPE};
+
+ pidl "int level;";
+ if (defined($switch_type)) {
+ if (typelist::typeIs($switch_type, "ENUM")) {
+ $switch_type = typelist::enum_type_fn(typelist::getType($switch_type));
+ }
+ pidl typelist::mapType($switch_type) . " _level;";
+ }
+
+ start_flags($e);
+
+ pidl "level = ndr_pull_get_switch_value(ndr, r);";
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ if (defined($switch_type)) {
+ pidl "ndr_pull_$switch_type(ndr, tree, hf_${name}, &_level);";
+ pidl "if (_level != level) {";
+ pidl "\treturn NT_STATUS_OK;";
+ pidl "}";
+ }
+
+# my $align = union_alignment($e);
+# pidl "\tndr_pull_align(ndr, $align);\n";
+
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ if ($el->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$el->{CASE}: {";
+
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ foreach my $l (@{$el->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER" and not ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP")) {
+ pidl "uint32_t _ptr_$el->{NAME};";
+ last;
+ }
+ }
+ ParseElement($el, "ndr", "r->", {}, 1, 0);
+ deindent;
+ }
+ pidl "break; }";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn NT_STATUS_OK;";
+ }
+ deindent;
+ pidl "}";
+ deindent;
+ pidl "}";
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ pidl "$el->{CASE}:";
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ ParseElement($el, "ndr", "r->", {}, 0, 1);
+ deindent;
+ }
+ pidl "break;";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn NT_STATUS_OK;";
+ }
+ deindent;
+ pidl "}";
+ pidl "proto_item_set_end(tree->proto_tree, ndr->tvb, ndr->offset);";
+ deindent;
+ pidl "}";
+ end_flags($e);
+}
+
+$typefamily{UNION} = {
+ FN_BODY => \&ParseUnion,
+};
+
+#####################################################################
+# parse an array
+sub ParseArrayHeader($$$$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $ndr = shift;
+ my $var_name = shift;
+ my $env = shift;
+
+ unless ($l->{NO_METADATA}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ # $var_name contains the name of the first argument here
+
+ my $length = util::ParseExpr($l->{SIZE_IS}, $env);
+ my $size = $length;
+
+ if ($l->{IS_CONFORMANT}) {
+ $length = $size = "ndr_get_array_size($ndr, " . get_pointer_to($var_name) . ")";
+ }
+
+ # if this is a conformant array then we use that size to allocate, and make sure
+ # we allocate enough to pull the elements
+ if (!$l->{IS_SURROUNDING}) {
+ ParseArrayPreceding($e, $l, $var_name);
+ }
+
+
+ if ($l->{IS_VARYING}) {
+ pidl "NDR_CHECK(ndr_pull_array_length($ndr, " . get_pointer_to($var_name) . "));";
+ $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
+ }
+
+ check_null_pointer($length);
+
+ if ($length ne $size) {
+ pidl "if ($length > $size) {";
+ indent;
+ pidl "return ndr_pull_error($ndr, NDR_ERR_ARRAY_SIZE, \"Bad array size %u should exceed array length %u\", $size, $length);";
+ deindent;
+ pidl "}";
+ }
+
+ if ($l->{IS_CONFORMANT}) {
+ my $size = util::ParseExpr($l->{SIZE_IS}, $env);
+ check_null_pointer($size);
+ pidl "NDR_CHECK(ndr_check_array_size(ndr, (void*)" . get_pointer_to($var_name) . ", $size));";
+ }
+
+ if ($l->{IS_VARYING}) {
+ my $length = util::ParseExpr($l->{LENGTH_IS}, $env);
+ check_null_pointer($length);
+ pidl "NDR_CHECK(ndr_check_array_length(ndr, (void*)" . get_pointer_to($var_name) . ", $length));";
+ }
+
+ return $length;
+}
+
+#####################################################################
+# parse a typedef - pull side
+sub ParseTypedef($)
+{
+ my($e) = shift;
+
+ return unless (defined ($typefamily{$e->{DATA}->{TYPE}}));
+
+ pidl fn_prefix($e) . "int dissect_$e->{NAME}(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int hf_index, guint32 param)";
+
+ pidl "{";
+ indent;
+ $typefamily{$e->{DATA}->{TYPE}}->{FN_BODY}->($e->{DATA}, $e->{NAME});
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse a function
+sub ParseFunctionRqst($)
+{
+ my($fn) = shift;
+
+ my $env = GenerateFunctionEnv($fn);
+
+ # request function
+ pidl "static int dissect_$fn->{NAME}_rqst(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)";
+ pidl "{";
+ indent;
+
+ pidl "struct pidl_pull *ndr = pidl_pull_init(tvb, offset, pinfo, drep);";
+
+ # declare any internal pointers we need
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep (/in/, @{$e->{DIRECTIONS}}));
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER" and
+ not ($l->{POINTER_TYPE} eq "ref" and
+ $l->{LEVEL} eq "TOP")) {
+ pidl "uint32_t _ptr_$e->{NAME};";
+ last;
+ }
+ }
+ }
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep(/in/, @{$e->{DIRECTION}}));
+ ParseElement($e, "ndr", "r->in.", $env, 1, 1);
+ }
+
+ pidl "return offset;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+sub ParseFunctionResp($)
+{
+ my($fn) = shift;
+
+ my $env = GenerateFunctionEnv($fn);
+
+ # response function
+ pidl "static int dissect_$fn->{NAME}_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)";
+ pidl "{";
+ indent;
+
+ pidl "struct pidl_pull *ndr = pidl_pull_init(tvb, offset, pinfo, drep);";
+
+ # declare any internal pointers we need
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep (/out/, @{$e->{DIRECTIONS}}));
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER" and
+ not ($l->{POINTER_TYPE} eq "ref" and
+ $l->{LEVEL} eq "TOP")) {
+ pidl "uint32_t _ptr_$e->{NAME};";
+ last;
+ }
+ }
+ }
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless grep(/out/, @{$e->{DIRECTION}});
+ ParseElement($e, "ndr", "r->out.", $env, 1, 1);
+ }
+
+ if ($fn->{RETURN_TYPE}) {
+ pidl "dissect_$fn->{RETURN_TYPE}(ndr, tree, hf_$fn->{NAME}_result, drep);";
+ }
+
+ pidl "return offset;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# produce a function call table
+sub FunctionTable($)
+{
+ my($interface) = shift;
+
+ pidl "static dcerpc_sub_dissector dcerpc_dissectors[] = {";
+ my $num = 0;
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ # Strip interface name from function name, if present
+ my($n) = $d->{NAME};
+ $n = substr($d->{NAME}, length($interface->{NAME}) + 1),
+ if $interface->{NAME} eq substr($d->{NAME}, 0, length($interface->{NAME}));
+ pidl "\t{ $num, \"$n\",";
+ pidl "\t\tdissect_$d->{NAME}_rqst,";
+ pidl "\t\tdissect_$d->{NAME}_resp },";
+ $num++;
+ }
+ pidl "};\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub ParseInterface($$)
+{
+ my($interface) = shift;
+ my $needed = shift;
+
+ # Typedefs
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ ($needed->{"pull_$d->{NAME}"}) && ParseTypedef($d);
+ # Make sure we don't generate a function twice...
+ $needed->{"pull_$d->{NAME}"} = 0;
+ }
+
+ # Functions
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ if ($needed->{"pull_$d->{NAME}"}) {
+ ParseFunctionRqst($d);
+ ParseFunctionResp($d);
+ }
+
+ # Make sure we don't generate a function twice...
+ $needed->{"pull_$d->{NAME}"} = 0;
+ }
+}
+
+#####################################################################
+# generate code to parse an enum
+sub DeclEnum($$)
+{
+ my ($e) = shift;
+ my $n = shift;
+
+ pidl "static const value_string $n\_vals[] =";
+ pidl "{";
+
+ foreach my $x (@{$e->{ELEMENTS}}) {
+ $x =~ /([^=]*)=(.*)/;
+ pidl "\t{ $1, \"$1\" },";
+ }
+
+ pidl "};\n";
+}
+
+sub DeclInterface($$)
+{
+ my($interface) = shift;
+ my $needed = shift;
+
+ # Typedefs
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ ($needed->{"decl_$d->{NAME}"}) && DeclTypedef($d, $needed);
+ }
+}
+
+sub DeclTypedef($$)
+{
+ my $e = shift;
+ my $needed = shift;
+
+ if (defined($typefamily{$e->{DATA}->{TYPE}}->{DECL})) {
+ $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e->{DATA}, $e->{NAME});
+
+ # Make sure we don't generate a function twice...
+ $needed->{"decl_$e->{NAME}"} = 0;
+ }
+}
+
+sub RegisterInterface($$)
+{
+ my $x = shift;
+ my $needed = shift;
+
+ pidl "void proto_register_dcerpc_pidl_$x->{NAME}(void)";
+ pidl "{";
+ indent;
+
+ pidl "static hf_register_info hf[] = {";
+ pidl "{ &hf_ptr, { \"Pointer\", \"$x->{NAME}.ptr\", FT_UINT32, BASE_HEX, NULL, 0x0, \"Pointer\", HFILL }},";
+
+ foreach my $x (sort keys(%{$needed})) {
+ next, if !($x =~ /^hf_/);
+ pidl "{ &$x,";
+ $needed->{$x}->{strings} = "NULL", if !defined($needed->{$x}->{strings});
+ $needed->{$x}->{bitmask} = "0", if !defined($needed->{$x}->{bitmask});
+ pidl " { \"$needed->{$x}->{name}\", \"$x\", $needed->{$x}->{ft}, $needed->{$x}->{base}, $needed->{$x}->{strings}, $needed->{$x}->{bitmask}, \"$x\", HFILL }},";
+ }
+
+ pidl "};\n";
+
+ pidl "static gint *ett[] = {";
+ indent;
+ foreach my $x (sort keys(%{$needed})) {
+ pidl "&$x,", if $x =~ /^ett_/;
+ }
+ deindent;
+
+ pidl "};\n";
+
+ if (defined($x->{UUID})) {
+ # These can be changed to non-pidl names if the old dissectors
+ # in epan/dissctors are deleted.
+
+ my $name = "\"" . uc($x->{NAME}) . " (pidl)\"";
+ if (util::has_property($x, "helpstring")) {
+ $name = $x->{PROPERTIES}->{helpstring};
+ }
+ my $short_name = "pidl_$x->{NAME}";
+ my $filter_name = "pidl_$x->{NAME}";
+
+ pidl "proto_dcerpc_pidl_$x->{NAME} = proto_register_protocol($name, \"$short_name\", \"$filter_name\");";
+
+ pidl "proto_register_field_array(proto_dcerpc_pidl_$x->{NAME}, hf, array_length (hf));";
+ pidl "proto_register_subtree_array(ett, array_length(ett));";
+ } else {
+ pidl "int proto_dcerpc;";
+ pidl "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");";
+ pidl "proto_register_field_array(proto_dcerpc, hf, array_length(hf));";
+ pidl "proto_register_subtree_array(ett, array_length(ett));";
+ }
+
+ deindent;
+ pidl "}\n";
+}
+
+sub RegisterInterfaceHandoff($)
+{
+ my $x = shift;
+ pidl "void proto_reg_handoff_dcerpc_pidl_$x->{NAME}(void)";
+ pidl "{";
+ indent;
+ pidl "dcerpc_init_uuid(proto_dcerpc_pidl_$x->{NAME}, ett_dcerpc_$x->{NAME},";
+ pidl "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},";
+ pidl "\tdcerpc_dissectors, hf_$x->{NAME}_opnum);";
+ deindent;
+ pidl "}";
+}
+
+sub ProcessInterface($)
+{
+ my $x = shift;
+ my $needed = NeededInterface($x);
+
+ # Required global declarations
+ DeclInterface($x, $needed);
+
+ foreach my $y (sort keys(%{$needed})) {
+ pidl "static int $y = -1;", if $y =~ /^hf_/;
+ }
+ pidl "";
+
+ foreach my $y (sort keys(%{$needed})) {
+ pidl "static gint $y = -1;", if $y =~ /^ett_/;
+ }
+ pidl "";
+
+ pidl "int proto_dcerpc_pidl_$x->{NAME} = -1;\n";
+
+ if (defined($x->{UUID})) {
+ my $if_uuid = $x->{UUID};
+
+ pidl "static e_uuid_t uuid_dcerpc_$x->{NAME} = {";
+ pidl "\t0x" . substr($if_uuid, 1, 8)
+ . ", 0x" . substr($if_uuid, 10, 4)
+ . ", 0x" . substr($if_uuid, 15, 4) . ",";
+ pidl "\t{ 0x" . substr($if_uuid, 20, 2)
+ . ", 0x" . substr($if_uuid, 22, 2)
+ . ", 0x" . substr($if_uuid, 25, 2)
+ . ", 0x" . substr($if_uuid, 27, 2)
+ . ", 0x" . substr($if_uuid, 29, 2)
+ . ", 0x" . substr($if_uuid, 31, 2)
+ . ", 0x" . substr($if_uuid, 33, 2)
+ . ", 0x" . substr($if_uuid, 35, 2) . " }";
+ pidl "};\n";
+
+ pidl "static guint16 ver_dcerpc_$x->{NAME} = $x->{VERSION};";
+ }
+
+ # dissect_* functions
+ ParseInterface($x, $needed);
+
+ # Function call tables
+ FunctionTable($x);
+
+ RegisterInterface($x, $needed);
+ RegisterInterfaceHandoff($x);
+}
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($$$)
+{
+ my($ndr) = shift;
+ my $module = shift;
+ my($filename) = shift;
+
+ $tabs = "";
+ my $h_filename = $filename;
+ $res = "";
+
+ if ($h_filename =~ /(.*)\.c/) {
+ $h_filename = "$1.h";
+ }
+
+ pidl "/* parser auto-generated by pidl */";
+ pidl "#include \"packet-dcerpc.h\"";
+ pidl "#include \"$h_filename\"";
+ pidl "";
+ pidl "static int hf_ptr = -1;";
+ pidl "static int hf_array_size = -1;";
+ pidl "";
+
+# print keys %{$needed->{hf_atsvc_JobGetInfo_result}}, "\n";
+
+ # Ethereal protocol registration
+
+ ProcessInterface($_) foreach (@$ndr);
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/IDL.pm b/source4/build/pidl/Parse/Pidl/IDL.pm
new file mode 100644
index 0000000000..4e851d36ba
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/IDL.pm
@@ -0,0 +1,2485 @@
+####################################################################
+#
+# This file was generated using Parse::Yapp version 1.05.
+#
+# Don't edit this file, use source file instead.
+#
+# ANY CHANGE MADE HERE WILL BE LOST !
+#
+####################################################################
+package Parse::Pidl::IDL;
+use vars qw ( @ISA );
+use strict;
+
+@ISA= qw ( Parse::Yapp::Driver );
+#Included Parse/Yapp/Driver.pm file----------------------------------------
+{
+#
+# Module Parse::Yapp::Driver
+#
+# This module is part of the Parse::Yapp package available on your
+# nearest CPAN
+#
+# Any use of this module in a standalone parser make the included
+# text under the same copyright as the Parse::Yapp module itself.
+#
+# This notice should remain unchanged.
+#
+# (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved.
+# (see the pod text in Parse::Yapp module for use and distribution rights)
+#
+
+package Parse::Yapp::Driver;
+
+require 5.004;
+
+use strict;
+
+use vars qw ( $VERSION $COMPATIBLE $FILENAME );
+
+$VERSION = '1.05';
+$COMPATIBLE = '0.07';
+$FILENAME=__FILE__;
+
+use Carp;
+
+#Known parameters, all starting with YY (leading YY will be discarded)
+my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
+ YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
+#Mandatory parameters
+my(@params)=('LEX','RULES','STATES');
+
+sub new {
+ my($class)=shift;
+ my($errst,$nberr,$token,$value,$check,$dotpos);
+ my($self)={ ERROR => \&_Error,
+ ERRST => \$errst,
+ NBERR => \$nberr,
+ TOKEN => \$token,
+ VALUE => \$value,
+ DOTPOS => \$dotpos,
+ STACK => [],
+ DEBUG => 0,
+ CHECK => \$check };
+
+ _CheckParams( [], \%params, \@_, $self );
+
+ exists($$self{VERSION})
+ and $$self{VERSION} < $COMPATIBLE
+ and croak "Yapp driver version $VERSION ".
+ "incompatible with version $$self{VERSION}:\n".
+ "Please recompile parser module.";
+
+ ref($class)
+ and $class=ref($class);
+
+ bless($self,$class);
+}
+
+sub YYParse {
+ my($self)=shift;
+ my($retval);
+
+ _CheckParams( \@params, \%params, \@_, $self );
+
+ if($$self{DEBUG}) {
+ _DBLoad();
+ $retval = eval '$self->_DBParse()';#Do not create stab entry on compile
+ $@ and die $@;
+ }
+ else {
+ $retval = $self->_Parse();
+ }
+ $retval
+}
+
+sub YYData {
+ my($self)=shift;
+
+ exists($$self{USER})
+ or $$self{USER}={};
+
+ $$self{USER};
+
+}
+
+sub YYErrok {
+ my($self)=shift;
+
+ ${$$self{ERRST}}=0;
+ undef;
+}
+
+sub YYNberr {
+ my($self)=shift;
+
+ ${$$self{NBERR}};
+}
+
+sub YYRecovering {
+ my($self)=shift;
+
+ ${$$self{ERRST}} != 0;
+}
+
+sub YYAbort {
+ my($self)=shift;
+
+ ${$$self{CHECK}}='ABORT';
+ undef;
+}
+
+sub YYAccept {
+ my($self)=shift;
+
+ ${$$self{CHECK}}='ACCEPT';
+ undef;
+}
+
+sub YYError {
+ my($self)=shift;
+
+ ${$$self{CHECK}}='ERROR';
+ undef;
+}
+
+sub YYSemval {
+ my($self)=shift;
+ my($index)= $_[0] - ${$$self{DOTPOS}} - 1;
+
+ $index < 0
+ and -$index <= @{$$self{STACK}}
+ and return $$self{STACK}[$index][1];
+
+ undef; #Invalid index
+}
+
+sub YYCurtok {
+ my($self)=shift;
+
+ @_
+ and ${$$self{TOKEN}}=$_[0];
+ ${$$self{TOKEN}};
+}
+
+sub YYCurval {
+ my($self)=shift;
+
+ @_
+ and ${$$self{VALUE}}=$_[0];
+ ${$$self{VALUE}};
+}
+
+sub YYExpect {
+ my($self)=shift;
+
+ keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
+}
+
+sub YYLexer {
+ my($self)=shift;
+
+ $$self{LEX};
+}
+
+
+#################
+# Private stuff #
+#################
+
+
+sub _CheckParams {
+ my($mandatory,$checklist,$inarray,$outhash)=@_;
+ my($prm,$value);
+ my($prmlst)={};
+
+ while(($prm,$value)=splice(@$inarray,0,2)) {
+ $prm=uc($prm);
+ exists($$checklist{$prm})
+ or croak("Unknow parameter '$prm'");
+ ref($value) eq $$checklist{$prm}
+ or croak("Invalid value for parameter '$prm'");
+ $prm=unpack('@2A*',$prm);
+ $$outhash{$prm}=$value;
+ }
+ for (@$mandatory) {
+ exists($$outhash{$_})
+ or croak("Missing mandatory parameter '".lc($_)."'");
+ }
+}
+
+sub _Error {
+ print "Parse error.\n";
+}
+
+sub _DBLoad {
+ {
+ no strict 'refs';
+
+ exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
+ and return;
+ }
+ my($fname)=__FILE__;
+ my(@drv);
+ open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
+ while(<DRV>) {
+ /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
+ and do {
+ s/^#DBG>//;
+ push(@drv,$_);
+ }
+ }
+ close(DRV);
+
+ $drv[0]=~s/_P/_DBP/;
+ eval join('',@drv);
+}
+
+#Note that for loading debugging version of the driver,
+#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
+#So, DO NOT remove comment at end of sub !!!
+sub _Parse {
+ my($self)=shift;
+
+ my($rules,$states,$lex,$error)
+ = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
+ my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
+ = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
+
+#DBG> my($debug)=$$self{DEBUG};
+#DBG> my($dbgerror)=0;
+
+#DBG> my($ShowCurToken) = sub {
+#DBG> my($tok)='>';
+#DBG> for (split('',$$token)) {
+#DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
+#DBG> ? sprintf('<%02X>',ord($_))
+#DBG> : $_;
+#DBG> }
+#DBG> $tok.='<';
+#DBG> };
+
+ $$errstatus=0;
+ $$nberror=0;
+ ($$token,$$value)=(undef,undef);
+ @$stack=( [ 0, undef ] );
+ $$check='';
+
+ while(1) {
+ my($actions,$act,$stateno);
+
+ $stateno=$$stack[-1][0];
+ $actions=$$states[$stateno];
+
+#DBG> print STDERR ('-' x 40),"\n";
+#DBG> $debug & 0x2
+#DBG> and print STDERR "In state $stateno:\n";
+#DBG> $debug & 0x08
+#DBG> and print STDERR "Stack:[".
+#DBG> join(',',map { $$_[0] } @$stack).
+#DBG> "]\n";
+
+
+ if (exists($$actions{ACTIONS})) {
+
+ defined($$token)
+ or do {
+ ($$token,$$value)=&$lex($self);
+#DBG> $debug & 0x01
+#DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n";
+ };
+
+ $act= exists($$actions{ACTIONS}{$$token})
+ ? $$actions{ACTIONS}{$$token}
+ : exists($$actions{DEFAULT})
+ ? $$actions{DEFAULT}
+ : undef;
+ }
+ else {
+ $act=$$actions{DEFAULT};
+#DBG> $debug & 0x01
+#DBG> and print STDERR "Don't need token.\n";
+ }
+
+ defined($act)
+ and do {
+
+ $act > 0
+ and do { #shift
+
+#DBG> $debug & 0x04
+#DBG> and print STDERR "Shift and go to state $act.\n";
+
+ $$errstatus
+ and do {
+ --$$errstatus;
+
+#DBG> $debug & 0x10
+#DBG> and $dbgerror
+#DBG> and $$errstatus == 0
+#DBG> and do {
+#DBG> print STDERR "**End of Error recovery.\n";
+#DBG> $dbgerror=0;
+#DBG> };
+ };
+
+
+ push(@$stack,[ $act, $$value ]);
+
+ $$token ne '' #Don't eat the eof
+ and $$token=$$value=undef;
+ next;
+ };
+
+ #reduce
+ my($lhs,$len,$code,@sempar,$semval);
+ ($lhs,$len,$code)=@{$$rules[-$act]};
+
+#DBG> $debug & 0x04
+#DBG> and $act
+#DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";
+
+ $act
+ or $self->YYAccept();
+
+ $$dotpos=$len;
+
+ unpack('A1',$lhs) eq '@' #In line rule
+ and do {
+ $lhs =~ /^\@[0-9]+\-([0-9]+)$/
+ or die "In line rule name '$lhs' ill formed: ".
+ "report it as a BUG.\n";
+ $$dotpos = $1;
+ };
+
+ @sempar = $$dotpos
+ ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
+ : ();
+
+ $semval = $code ? &$code( $self, @sempar )
+ : @sempar ? $sempar[0] : undef;
+
+ splice(@$stack,-$len,$len);
+
+ $$check eq 'ACCEPT'
+ and do {
+
+#DBG> $debug & 0x04
+#DBG> and print STDERR "Accept.\n";
+
+ return($semval);
+ };
+
+ $$check eq 'ABORT'
+ and do {
+
+#DBG> $debug & 0x04
+#DBG> and print STDERR "Abort.\n";
+
+ return(undef);
+
+ };
+
+#DBG> $debug & 0x04
+#DBG> and print STDERR "Back to state $$stack[-1][0], then ";
+
+ $$check eq 'ERROR'
+ or do {
+#DBG> $debug & 0x04
+#DBG> and print STDERR
+#DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";
+
+#DBG> $debug & 0x10
+#DBG> and $dbgerror
+#DBG> and $$errstatus == 0
+#DBG> and do {
+#DBG> print STDERR "**End of Error recovery.\n";
+#DBG> $dbgerror=0;
+#DBG> };
+
+ push(@$stack,
+ [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
+ $$check='';
+ next;
+ };
+
+#DBG> $debug & 0x04
+#DBG> and print STDERR "Forced Error recovery.\n";
+
+ $$check='';
+
+ };
+
+ #Error
+ $$errstatus
+ or do {
+
+ $$errstatus = 1;
+ &$error($self);
+ $$errstatus # if 0, then YYErrok has been called
+ or next; # so continue parsing
+
+#DBG> $debug & 0x10
+#DBG> and do {
+#DBG> print STDERR "**Entering Error recovery.\n";
+#DBG> ++$dbgerror;
+#DBG> };
+
+ ++$$nberror;
+
+ };
+
+ $$errstatus == 3 #The next token is not valid: discard it
+ and do {
+ $$token eq '' # End of input: no hope
+ and do {
+#DBG> $debug & 0x10
+#DBG> and print STDERR "**At eof: aborting.\n";
+ return(undef);
+ };
+
+#DBG> $debug & 0x10
+#DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";
+
+ $$token=$$value=undef;
+ };
+
+ $$errstatus=3;
+
+ while( @$stack
+ and ( not exists($$states[$$stack[-1][0]]{ACTIONS})
+ or not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
+ or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {
+
+#DBG> $debug & 0x10
+#DBG> and print STDERR "**Pop state $$stack[-1][0].\n";
+
+ pop(@$stack);
+ }
+
+ @$stack
+ or do {
+
+#DBG> $debug & 0x10
+#DBG> and print STDERR "**No state left on stack: aborting.\n";
+
+ return(undef);
+ };
+
+ #shift the error token
+
+#DBG> $debug & 0x10
+#DBG> and print STDERR "**Shift \$error token and go to state ".
+#DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}.
+#DBG> ".\n";
+
+ push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);
+
+ }
+
+ #never reached
+ croak("Error in driver logic. Please, report it as a BUG");
+
+}#_Parse
+#DO NOT remove comment
+
+1;
+
+}
+#End of include--------------------------------------------------
+
+
+
+
+sub new {
+ my($class)=shift;
+ ref($class)
+ and $class=ref($class);
+
+ my($self)=$class->SUPER::new( yyversion => '1.05',
+ yystates =>
+[
+ {#State 0
+ DEFAULT => -1,
+ GOTOS => {
+ 'idl' => 1
+ }
+ },
+ {#State 1
+ ACTIONS => {
+ '' => 2
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'interface' => 3,
+ 'coclass' => 4,
+ 'property_list' => 5
+ }
+ },
+ {#State 2
+ DEFAULT => 0
+ },
+ {#State 3
+ DEFAULT => -2
+ },
+ {#State 4
+ DEFAULT => -3
+ },
+ {#State 5
+ ACTIONS => {
+ "coclass" => 6,
+ "interface" => 8,
+ "[" => 7
+ }
+ },
+ {#State 6
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 10
+ }
+ },
+ {#State 7
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 11,
+ 'properties' => 13,
+ 'property' => 12
+ }
+ },
+ {#State 8
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 14
+ }
+ },
+ {#State 9
+ DEFAULT => -86
+ },
+ {#State 10
+ ACTIONS => {
+ "{" => 15
+ }
+ },
+ {#State 11
+ ACTIONS => {
+ "(" => 16
+ },
+ DEFAULT => -64
+ },
+ {#State 12
+ DEFAULT => -62
+ },
+ {#State 13
+ ACTIONS => {
+ "," => 17,
+ "]" => 18
+ }
+ },
+ {#State 14
+ ACTIONS => {
+ ":" => 19
+ },
+ DEFAULT => -8,
+ GOTOS => {
+ 'base_interface' => 20
+ }
+ },
+ {#State 15
+ DEFAULT => -5,
+ GOTOS => {
+ 'interface_names' => 21
+ }
+ },
+ {#State 16
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'listtext' => 26,
+ 'anytext' => 25,
+ 'text' => 24,
+ 'constant' => 27
+ }
+ },
+ {#State 17
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 11,
+ 'property' => 29
+ }
+ },
+ {#State 18
+ DEFAULT => -61
+ },
+ {#State 19
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 30
+ }
+ },
+ {#State 20
+ ACTIONS => {
+ "{" => 31
+ }
+ },
+ {#State 21
+ ACTIONS => {
+ "}" => 32,
+ "interface" => 33
+ }
+ },
+ {#State 22
+ DEFAULT => -88
+ },
+ {#State 23
+ DEFAULT => -71
+ },
+ {#State 24
+ DEFAULT => -73
+ },
+ {#State 25
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -66
+ },
+ {#State 26
+ ACTIONS => {
+ "," => 46,
+ ")" => 47
+ }
+ },
+ {#State 27
+ DEFAULT => -72
+ },
+ {#State 28
+ DEFAULT => -87
+ },
+ {#State 29
+ DEFAULT => -63
+ },
+ {#State 30
+ DEFAULT => -9
+ },
+ {#State 31
+ ACTIONS => {
+ "typedef" => 48,
+ "declare" => 53,
+ "const" => 56
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'const' => 55,
+ 'declare' => 54,
+ 'function' => 49,
+ 'typedef' => 57,
+ 'definitions' => 50,
+ 'definition' => 52,
+ 'property_list' => 51
+ }
+ },
+ {#State 32
+ ACTIONS => {
+ ";" => 59
+ },
+ DEFAULT => -89,
+ GOTOS => {
+ 'optional_semicolon' => 58
+ }
+ },
+ {#State 33
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 60
+ }
+ },
+ {#State 34
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 61,
+ 'constant' => 27
+ }
+ },
+ {#State 35
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 62,
+ 'constant' => 27
+ }
+ },
+ {#State 36
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 63,
+ 'constant' => 27
+ }
+ },
+ {#State 37
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 64,
+ 'constant' => 27
+ }
+ },
+ {#State 38
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 65,
+ 'constant' => 27,
+ 'commalisttext' => 66
+ }
+ },
+ {#State 39
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 67,
+ 'constant' => 27
+ }
+ },
+ {#State 40
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 68,
+ 'constant' => 27
+ }
+ },
+ {#State 41
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 65,
+ 'constant' => 27,
+ 'commalisttext' => 69
+ }
+ },
+ {#State 42
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 70,
+ 'constant' => 27
+ }
+ },
+ {#State 43
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 71,
+ 'constant' => 27
+ }
+ },
+ {#State 44
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 72,
+ 'constant' => 27
+ }
+ },
+ {#State 45
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 73,
+ 'constant' => 27
+ }
+ },
+ {#State 46
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 74,
+ 'constant' => 27
+ }
+ },
+ {#State 47
+ DEFAULT => -65
+ },
+ {#State 48
+ DEFAULT => -60,
+ GOTOS => {
+ 'property_list' => 75
+ }
+ },
+ {#State 49
+ DEFAULT => -12
+ },
+ {#State 50
+ ACTIONS => {
+ "}" => 76,
+ "typedef" => 48,
+ "declare" => 53,
+ "const" => 56
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'const' => 55,
+ 'declare' => 54,
+ 'function' => 49,
+ 'typedef' => 57,
+ 'definition' => 77,
+ 'property_list' => 51
+ }
+ },
+ {#State 51
+ ACTIONS => {
+ 'IDENTIFIER' => 9,
+ "union" => 78,
+ "enum" => 79,
+ "[" => 7,
+ 'void' => 81,
+ "bitmap" => 80,
+ "struct" => 88
+ },
+ GOTOS => {
+ 'identifier' => 83,
+ 'struct' => 84,
+ 'enum' => 85,
+ 'type' => 86,
+ 'union' => 87,
+ 'bitmap' => 82
+ }
+ },
+ {#State 52
+ DEFAULT => -10
+ },
+ {#State 53
+ DEFAULT => -60,
+ GOTOS => {
+ 'property_list' => 89
+ }
+ },
+ {#State 54
+ DEFAULT => -15
+ },
+ {#State 55
+ DEFAULT => -13
+ },
+ {#State 56
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 90
+ }
+ },
+ {#State 57
+ DEFAULT => -14
+ },
+ {#State 58
+ DEFAULT => -4
+ },
+ {#State 59
+ DEFAULT => -90
+ },
+ {#State 60
+ ACTIONS => {
+ ";" => 91
+ }
+ },
+ {#State 61
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -74
+ },
+ {#State 62
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "*" => 43,
+ "{" => 38,
+ "&" => 39,
+ "/" => 40,
+ "|" => 42,
+ "(" => 41,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -78
+ },
+ {#State 63
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "*" => 43,
+ "{" => 38,
+ "&" => 39,
+ "/" => 40,
+ "|" => 42,
+ "(" => 41,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -83
+ },
+ {#State 64
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -82
+ },
+ {#State 65
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "*" => 43,
+ "{" => 38,
+ "&" => 39,
+ "/" => 40,
+ "|" => 42,
+ "(" => 41,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -68
+ },
+ {#State 66
+ ACTIONS => {
+ "}" => 92,
+ "," => 93
+ }
+ },
+ {#State 67
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -80
+ },
+ {#State 68
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -81
+ },
+ {#State 69
+ ACTIONS => {
+ "," => 93,
+ ")" => 94
+ }
+ },
+ {#State 70
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -79
+ },
+ {#State 71
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -76
+ },
+ {#State 72
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -75
+ },
+ {#State 73
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -77
+ },
+ {#State 74
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -67
+ },
+ {#State 75
+ ACTIONS => {
+ 'IDENTIFIER' => 9,
+ "union" => 78,
+ "enum" => 79,
+ "[" => 7,
+ 'void' => 81,
+ "bitmap" => 80,
+ "struct" => 88
+ },
+ GOTOS => {
+ 'identifier' => 83,
+ 'struct' => 84,
+ 'enum' => 85,
+ 'type' => 95,
+ 'union' => 87,
+ 'bitmap' => 82
+ }
+ },
+ {#State 76
+ ACTIONS => {
+ ";" => 59
+ },
+ DEFAULT => -89,
+ GOTOS => {
+ 'optional_semicolon' => 96
+ }
+ },
+ {#State 77
+ DEFAULT => -11
+ },
+ {#State 78
+ ACTIONS => {
+ "{" => 97
+ }
+ },
+ {#State 79
+ ACTIONS => {
+ "{" => 98
+ }
+ },
+ {#State 80
+ ACTIONS => {
+ "{" => 99
+ }
+ },
+ {#State 81
+ DEFAULT => -30
+ },
+ {#State 82
+ DEFAULT => -28
+ },
+ {#State 83
+ DEFAULT => -29
+ },
+ {#State 84
+ DEFAULT => -25
+ },
+ {#State 85
+ DEFAULT => -27
+ },
+ {#State 86
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 100
+ }
+ },
+ {#State 87
+ DEFAULT => -26
+ },
+ {#State 88
+ ACTIONS => {
+ "{" => 101
+ }
+ },
+ {#State 89
+ ACTIONS => {
+ "enum" => 102,
+ "[" => 7,
+ "bitmap" => 103
+ },
+ GOTOS => {
+ 'decl_enum' => 104,
+ 'decl_bitmap' => 105,
+ 'decl_type' => 106
+ }
+ },
+ {#State 90
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 107
+ }
+ },
+ {#State 91
+ DEFAULT => -6
+ },
+ {#State 92
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 108,
+ 'constant' => 27
+ }
+ },
+ {#State 93
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 109,
+ 'constant' => 27
+ }
+ },
+ {#State 94
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 110,
+ 'constant' => 27
+ }
+ },
+ {#State 95
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 111
+ }
+ },
+ {#State 96
+ DEFAULT => -7
+ },
+ {#State 97
+ DEFAULT => -45,
+ GOTOS => {
+ 'union_elements' => 112
+ }
+ },
+ {#State 98
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 113,
+ 'enum_element' => 114,
+ 'enum_elements' => 115
+ }
+ },
+ {#State 99
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 118,
+ 'bitmap_elements' => 117,
+ 'bitmap_element' => 116
+ }
+ },
+ {#State 100
+ ACTIONS => {
+ "(" => 119
+ }
+ },
+ {#State 101
+ DEFAULT => -51,
+ GOTOS => {
+ 'element_list1' => 120
+ }
+ },
+ {#State 102
+ DEFAULT => -22
+ },
+ {#State 103
+ DEFAULT => -23
+ },
+ {#State 104
+ DEFAULT => -20
+ },
+ {#State 105
+ DEFAULT => -21
+ },
+ {#State 106
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 121
+ }
+ },
+ {#State 107
+ ACTIONS => {
+ "[" => 124,
+ "=" => 123
+ },
+ GOTOS => {
+ 'array_len' => 122
+ }
+ },
+ {#State 108
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "*" => 43,
+ "{" => 38,
+ "&" => 39,
+ "/" => 40,
+ "|" => 42,
+ "(" => 41,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -85
+ },
+ {#State 109
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "*" => 43,
+ "{" => 38,
+ "&" => 39,
+ "/" => 40,
+ "|" => 42,
+ "(" => 41,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -69
+ },
+ {#State 110
+ ACTIONS => {
+ "<" => 35,
+ "~" => 36,
+ "{" => 38
+ },
+ DEFAULT => -84
+ },
+ {#State 111
+ ACTIONS => {
+ "[" => 124
+ },
+ DEFAULT => -57,
+ GOTOS => {
+ 'array_len' => 125
+ }
+ },
+ {#State 112
+ ACTIONS => {
+ "}" => 126
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'optional_base_element' => 128,
+ 'property_list' => 127
+ }
+ },
+ {#State 113
+ ACTIONS => {
+ "=" => 129
+ },
+ DEFAULT => -34
+ },
+ {#State 114
+ DEFAULT => -32
+ },
+ {#State 115
+ ACTIONS => {
+ "}" => 130,
+ "," => 131
+ }
+ },
+ {#State 116
+ DEFAULT => -37
+ },
+ {#State 117
+ ACTIONS => {
+ "}" => 132,
+ "," => 133
+ }
+ },
+ {#State 118
+ ACTIONS => {
+ "=" => 134
+ }
+ },
+ {#State 119
+ ACTIONS => {
+ "," => -53,
+ "void" => 137,
+ ")" => -53
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'base_element' => 135,
+ 'element_list2' => 138,
+ 'property_list' => 136
+ }
+ },
+ {#State 120
+ ACTIONS => {
+ "}" => 139
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'base_element' => 140,
+ 'property_list' => 136
+ }
+ },
+ {#State 121
+ ACTIONS => {
+ ";" => 141
+ }
+ },
+ {#State 122
+ ACTIONS => {
+ "=" => 142
+ }
+ },
+ {#State 123
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 143,
+ 'constant' => 27
+ }
+ },
+ {#State 124
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ "]" => 145,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 144,
+ 'constant' => 27
+ }
+ },
+ {#State 125
+ ACTIONS => {
+ ";" => 146
+ }
+ },
+ {#State 126
+ DEFAULT => -47
+ },
+ {#State 127
+ ACTIONS => {
+ "[" => 7
+ },
+ DEFAULT => -60,
+ GOTOS => {
+ 'base_or_empty' => 147,
+ 'base_element' => 148,
+ 'empty_element' => 149,
+ 'property_list' => 150
+ }
+ },
+ {#State 128
+ DEFAULT => -46
+ },
+ {#State 129
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 151,
+ 'constant' => 27
+ }
+ },
+ {#State 130
+ DEFAULT => -31
+ },
+ {#State 131
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 113,
+ 'enum_element' => 152
+ }
+ },
+ {#State 132
+ DEFAULT => -36
+ },
+ {#State 133
+ ACTIONS => {
+ 'IDENTIFIER' => 9
+ },
+ GOTOS => {
+ 'identifier' => 118,
+ 'bitmap_element' => 153
+ }
+ },
+ {#State 134
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 154,
+ 'constant' => 27
+ }
+ },
+ {#State 135
+ DEFAULT => -55
+ },
+ {#State 136
+ ACTIONS => {
+ 'IDENTIFIER' => 9,
+ "union" => 78,
+ "enum" => 79,
+ "[" => 7,
+ 'void' => 81,
+ "bitmap" => 80,
+ "struct" => 88
+ },
+ GOTOS => {
+ 'identifier' => 83,
+ 'struct' => 84,
+ 'enum' => 85,
+ 'type' => 155,
+ 'union' => 87,
+ 'bitmap' => 82
+ }
+ },
+ {#State 137
+ DEFAULT => -54
+ },
+ {#State 138
+ ACTIONS => {
+ "," => 156,
+ ")" => 157
+ }
+ },
+ {#State 139
+ DEFAULT => -40
+ },
+ {#State 140
+ ACTIONS => {
+ ";" => 158
+ }
+ },
+ {#State 141
+ DEFAULT => -19
+ },
+ {#State 142
+ ACTIONS => {
+ 'CONSTANT' => 28,
+ 'TEXT' => 22,
+ 'IDENTIFIER' => 9
+ },
+ DEFAULT => -70,
+ GOTOS => {
+ 'identifier' => 23,
+ 'text' => 24,
+ 'anytext' => 159,
+ 'constant' => 27
+ }
+ },
+ {#State 143
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ ";" => 160,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ }
+ },
+ {#State 144
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "]" => 161,
+ "." => 44,
+ ">" => 45
+ }
+ },
+ {#State 145
+ ACTIONS => {
+ "[" => 124
+ },
+ DEFAULT => -57,
+ GOTOS => {
+ 'array_len' => 162
+ }
+ },
+ {#State 146
+ DEFAULT => -24
+ },
+ {#State 147
+ DEFAULT => -44
+ },
+ {#State 148
+ ACTIONS => {
+ ";" => 163
+ }
+ },
+ {#State 149
+ DEFAULT => -43
+ },
+ {#State 150
+ ACTIONS => {
+ 'IDENTIFIER' => 9,
+ "union" => 78,
+ ";" => 164,
+ "enum" => 79,
+ "[" => 7,
+ 'void' => 81,
+ "bitmap" => 80,
+ "struct" => 88
+ },
+ GOTOS => {
+ 'identifier' => 83,
+ 'struct' => 84,
+ 'enum' => 85,
+ 'type' => 155,
+ 'union' => 87,
+ 'bitmap' => 82
+ }
+ },
+ {#State 151
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -35
+ },
+ {#State 152
+ DEFAULT => -33
+ },
+ {#State 153
+ DEFAULT => -38
+ },
+ {#State 154
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ },
+ DEFAULT => -39
+ },
+ {#State 155
+ DEFAULT => -49,
+ GOTOS => {
+ 'pointers' => 165
+ }
+ },
+ {#State 156
+ DEFAULT => -60,
+ GOTOS => {
+ 'base_element' => 166,
+ 'property_list' => 136
+ }
+ },
+ {#State 157
+ ACTIONS => {
+ ";" => 167
+ }
+ },
+ {#State 158
+ DEFAULT => -52
+ },
+ {#State 159
+ ACTIONS => {
+ "-" => 34,
+ "<" => 35,
+ ";" => 168,
+ "+" => 37,
+ "~" => 36,
+ "&" => 39,
+ "{" => 38,
+ "/" => 40,
+ "(" => 41,
+ "|" => 42,
+ "*" => 43,
+ "." => 44,
+ ">" => 45
+ }
+ },
+ {#State 160
+ DEFAULT => -16
+ },
+ {#State 161
+ ACTIONS => {
+ "[" => 124
+ },
+ DEFAULT => -57,
+ GOTOS => {
+ 'array_len' => 169
+ }
+ },
+ {#State 162
+ DEFAULT => -58
+ },
+ {#State 163
+ DEFAULT => -42
+ },
+ {#State 164
+ DEFAULT => -41
+ },
+ {#State 165
+ ACTIONS => {
+ 'IDENTIFIER' => 9,
+ "*" => 171
+ },
+ GOTOS => {
+ 'identifier' => 170
+ }
+ },
+ {#State 166
+ DEFAULT => -56
+ },
+ {#State 167
+ DEFAULT => -18
+ },
+ {#State 168
+ DEFAULT => -17
+ },
+ {#State 169
+ DEFAULT => -59
+ },
+ {#State 170
+ ACTIONS => {
+ "[" => 124
+ },
+ DEFAULT => -57,
+ GOTOS => {
+ 'array_len' => 172
+ }
+ },
+ {#State 171
+ DEFAULT => -50
+ },
+ {#State 172
+ DEFAULT => -48
+ }
+],
+ yyrules =>
+[
+ [#Rule 0
+ '$start', 2, undef
+ ],
+ [#Rule 1
+ 'idl', 0, undef
+ ],
+ [#Rule 2
+ 'idl', 2,
+sub
+#line 19 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 3
+ 'idl', 2,
+sub
+#line 20 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 4
+ 'coclass', 7,
+sub
+#line 24 "build/pidl/idl.yp"
+{$_[3] => {
+ "TYPE" => "COCLASS",
+ "PROPERTIES" => $_[1],
+ "NAME" => $_[3],
+ "DATA" => $_[5],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 5
+ 'interface_names', 0, undef
+ ],
+ [#Rule 6
+ 'interface_names', 4,
+sub
+#line 36 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 7
+ 'interface', 8,
+sub
+#line 40 "build/pidl/idl.yp"
+{$_[3] => {
+ "TYPE" => "INTERFACE",
+ "PROPERTIES" => $_[1],
+ "NAME" => $_[3],
+ "BASE" => $_[4],
+ "DATA" => $_[6],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 8
+ 'base_interface', 0, undef
+ ],
+ [#Rule 9
+ 'base_interface', 2,
+sub
+#line 53 "build/pidl/idl.yp"
+{ $_[2] }
+ ],
+ [#Rule 10
+ 'definitions', 1,
+sub
+#line 57 "build/pidl/idl.yp"
+{ [ $_[1] ] }
+ ],
+ [#Rule 11
+ 'definitions', 2,
+sub
+#line 58 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 12
+ 'definition', 1, undef
+ ],
+ [#Rule 13
+ 'definition', 1, undef
+ ],
+ [#Rule 14
+ 'definition', 1, undef
+ ],
+ [#Rule 15
+ 'definition', 1, undef
+ ],
+ [#Rule 16
+ 'const', 6,
+sub
+#line 66 "build/pidl/idl.yp"
+{{
+ "TYPE" => "CONST",
+ "DTYPE" => $_[2],
+ "NAME" => $_[3],
+ "VALUE" => $_[5],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 17
+ 'const', 7,
+sub
+#line 75 "build/pidl/idl.yp"
+{{
+ "TYPE" => "CONST",
+ "DTYPE" => $_[2],
+ "NAME" => $_[3],
+ "ARRAY_LEN" => $_[4],
+ "VALUE" => $_[6],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 18
+ 'function', 7,
+sub
+#line 88 "build/pidl/idl.yp"
+{{
+ "TYPE" => "FUNCTION",
+ "NAME" => $_[3],
+ "RETURN_TYPE" => $_[2],
+ "PROPERTIES" => $_[1],
+ "ELEMENTS" => $_[5],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 19
+ 'declare', 5,
+sub
+#line 100 "build/pidl/idl.yp"
+{{
+ "TYPE" => "DECLARE",
+ "PROPERTIES" => $_[2],
+ "NAME" => $_[4],
+ "DATA" => $_[3],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 20
+ 'decl_type', 1, undef
+ ],
+ [#Rule 21
+ 'decl_type', 1, undef
+ ],
+ [#Rule 22
+ 'decl_enum', 1,
+sub
+#line 114 "build/pidl/idl.yp"
+{{
+ "TYPE" => "ENUM"
+ }}
+ ],
+ [#Rule 23
+ 'decl_bitmap', 1,
+sub
+#line 120 "build/pidl/idl.yp"
+{{
+ "TYPE" => "BITMAP"
+ }}
+ ],
+ [#Rule 24
+ 'typedef', 6,
+sub
+#line 126 "build/pidl/idl.yp"
+{{
+ "TYPE" => "TYPEDEF",
+ "PROPERTIES" => $_[2],
+ "NAME" => $_[4],
+ "DATA" => $_[3],
+ "ARRAY_LEN" => $_[5],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 25
+ 'type', 1, undef
+ ],
+ [#Rule 26
+ 'type', 1, undef
+ ],
+ [#Rule 27
+ 'type', 1, undef
+ ],
+ [#Rule 28
+ 'type', 1, undef
+ ],
+ [#Rule 29
+ 'type', 1, undef
+ ],
+ [#Rule 30
+ 'type', 1,
+sub
+#line 138 "build/pidl/idl.yp"
+{ "void" }
+ ],
+ [#Rule 31
+ 'enum', 4,
+sub
+#line 143 "build/pidl/idl.yp"
+{{
+ "TYPE" => "ENUM",
+ "ELEMENTS" => $_[3]
+ }}
+ ],
+ [#Rule 32
+ 'enum_elements', 1,
+sub
+#line 150 "build/pidl/idl.yp"
+{ [ $_[1] ] }
+ ],
+ [#Rule 33
+ 'enum_elements', 3,
+sub
+#line 151 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[3]); $_[1] }
+ ],
+ [#Rule 34
+ 'enum_element', 1, undef
+ ],
+ [#Rule 35
+ 'enum_element', 3,
+sub
+#line 155 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 36
+ 'bitmap', 4,
+sub
+#line 159 "build/pidl/idl.yp"
+{{
+ "TYPE" => "BITMAP",
+ "ELEMENTS" => $_[3]
+ }}
+ ],
+ [#Rule 37
+ 'bitmap_elements', 1,
+sub
+#line 166 "build/pidl/idl.yp"
+{ [ $_[1] ] }
+ ],
+ [#Rule 38
+ 'bitmap_elements', 3,
+sub
+#line 167 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[3]); $_[1] }
+ ],
+ [#Rule 39
+ 'bitmap_element', 3,
+sub
+#line 170 "build/pidl/idl.yp"
+{ "$_[1] ( $_[3] )" }
+ ],
+ [#Rule 40
+ 'struct', 4,
+sub
+#line 174 "build/pidl/idl.yp"
+{{
+ "TYPE" => "STRUCT",
+ "ELEMENTS" => $_[3]
+ }}
+ ],
+ [#Rule 41
+ 'empty_element', 2,
+sub
+#line 181 "build/pidl/idl.yp"
+{{
+ "NAME" => "",
+ "TYPE" => "EMPTY",
+ "PROPERTIES" => $_[1],
+ "POINTERS" => 0,
+ "ARRAY_LEN" => [],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 42
+ 'base_or_empty', 2, undef
+ ],
+ [#Rule 43
+ 'base_or_empty', 1, undef
+ ],
+ [#Rule 44
+ 'optional_base_element', 2,
+sub
+#line 195 "build/pidl/idl.yp"
+{ $_[2]->{PROPERTIES} = Parse::Pidl::Util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
+ ],
+ [#Rule 45
+ 'union_elements', 0, undef
+ ],
+ [#Rule 46
+ 'union_elements', 2,
+sub
+#line 200 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 47
+ 'union', 4,
+sub
+#line 204 "build/pidl/idl.yp"
+{{
+ "TYPE" => "UNION",
+ "ELEMENTS" => $_[3]
+ }}
+ ],
+ [#Rule 48
+ 'base_element', 5,
+sub
+#line 211 "build/pidl/idl.yp"
+{{
+ "NAME" => $_[4],
+ "TYPE" => $_[2],
+ "PROPERTIES" => $_[1],
+ "POINTERS" => $_[3],
+ "ARRAY_LEN" => $_[5],
+ "FILE" => $_[0]->YYData->{INPUT_FILENAME},
+ "LINE" => $_[0]->YYData->{LINE},
+ }}
+ ],
+ [#Rule 49
+ 'pointers', 0,
+sub
+#line 225 "build/pidl/idl.yp"
+{ 0 }
+ ],
+ [#Rule 50
+ 'pointers', 2,
+sub
+#line 226 "build/pidl/idl.yp"
+{ $_[1]+1 }
+ ],
+ [#Rule 51
+ 'element_list1', 0, undef
+ ],
+ [#Rule 52
+ 'element_list1', 3,
+sub
+#line 231 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[2]); $_[1] }
+ ],
+ [#Rule 53
+ 'element_list2', 0, undef
+ ],
+ [#Rule 54
+ 'element_list2', 1, undef
+ ],
+ [#Rule 55
+ 'element_list2', 1,
+sub
+#line 237 "build/pidl/idl.yp"
+{ [ $_[1] ] }
+ ],
+ [#Rule 56
+ 'element_list2', 3,
+sub
+#line 238 "build/pidl/idl.yp"
+{ push(@{$_[1]}, $_[3]); $_[1] }
+ ],
+ [#Rule 57
+ 'array_len', 0, undef
+ ],
+ [#Rule 58
+ 'array_len', 3,
+sub
+#line 243 "build/pidl/idl.yp"
+{ push(@{$_[3]}, "*"); $_[3] }
+ ],
+ [#Rule 59
+ 'array_len', 4,
+sub
+#line 244 "build/pidl/idl.yp"
+{ push(@{$_[4]}, "$_[2]"); $_[4] }
+ ],
+ [#Rule 60
+ 'property_list', 0, undef
+ ],
+ [#Rule 61
+ 'property_list', 4,
+sub
+#line 250 "build/pidl/idl.yp"
+{ Parse::Pidl::Util::FlattenHash([$_[1],$_[3]]); }
+ ],
+ [#Rule 62
+ 'properties', 1,
+sub
+#line 253 "build/pidl/idl.yp"
+{ $_[1] }
+ ],
+ [#Rule 63
+ 'properties', 3,
+sub
+#line 254 "build/pidl/idl.yp"
+{ Parse::Pidl::Util::FlattenHash([$_[1], $_[3]]); }
+ ],
+ [#Rule 64
+ 'property', 1,
+sub
+#line 257 "build/pidl/idl.yp"
+{{ "$_[1]" => "1" }}
+ ],
+ [#Rule 65
+ 'property', 4,
+sub
+#line 258 "build/pidl/idl.yp"
+{{ "$_[1]" => "$_[3]" }}
+ ],
+ [#Rule 66
+ 'listtext', 1, undef
+ ],
+ [#Rule 67
+ 'listtext', 3,
+sub
+#line 263 "build/pidl/idl.yp"
+{ "$_[1] $_[3]" }
+ ],
+ [#Rule 68
+ 'commalisttext', 1, undef
+ ],
+ [#Rule 69
+ 'commalisttext', 3,
+sub
+#line 268 "build/pidl/idl.yp"
+{ "$_[1],$_[3]" }
+ ],
+ [#Rule 70
+ 'anytext', 0,
+sub
+#line 272 "build/pidl/idl.yp"
+{ "" }
+ ],
+ [#Rule 71
+ 'anytext', 1, undef
+ ],
+ [#Rule 72
+ 'anytext', 1, undef
+ ],
+ [#Rule 73
+ 'anytext', 1, undef
+ ],
+ [#Rule 74
+ 'anytext', 3,
+sub
+#line 274 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 75
+ 'anytext', 3,
+sub
+#line 275 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 76
+ 'anytext', 3,
+sub
+#line 276 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 77
+ 'anytext', 3,
+sub
+#line 277 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 78
+ 'anytext', 3,
+sub
+#line 278 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 79
+ 'anytext', 3,
+sub
+#line 279 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 80
+ 'anytext', 3,
+sub
+#line 280 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 81
+ 'anytext', 3,
+sub
+#line 281 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 82
+ 'anytext', 3,
+sub
+#line 282 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 83
+ 'anytext', 3,
+sub
+#line 283 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]" }
+ ],
+ [#Rule 84
+ 'anytext', 5,
+sub
+#line 284 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]$_[4]$_[5]" }
+ ],
+ [#Rule 85
+ 'anytext', 5,
+sub
+#line 285 "build/pidl/idl.yp"
+{ "$_[1]$_[2]$_[3]$_[4]$_[5]" }
+ ],
+ [#Rule 86
+ 'identifier', 1, undef
+ ],
+ [#Rule 87
+ 'constant', 1, undef
+ ],
+ [#Rule 88
+ 'text', 1,
+sub
+#line 294 "build/pidl/idl.yp"
+{ "\"$_[1]\"" }
+ ],
+ [#Rule 89
+ 'optional_semicolon', 0, undef
+ ],
+ [#Rule 90
+ 'optional_semicolon', 1, undef
+ ]
+],
+ @_);
+ bless($self,$class);
+}
+
+#line 305 "build/pidl/idl.yp"
+
+
+use Parse::Pidl::Util;
+
+sub _Error {
+ if (exists $_[0]->YYData->{ERRMSG}) {
+ print $_[0]->YYData->{ERRMSG};
+ delete $_[0]->YYData->{ERRMSG};
+ return;
+ };
+ my $line = $_[0]->YYData->{LINE};
+ my $last_token = $_[0]->YYData->{LAST_TOKEN};
+ my $file = $_[0]->YYData->{INPUT_FILENAME};
+
+ print "$file:$line: Syntax error near '$last_token'\n";
+}
+
+sub _Lexer($)
+{
+ my($parser)=shift;
+
+ $parser->YYData->{INPUT}
+ or return('',undef);
+
+again:
+ $parser->YYData->{INPUT} =~ s/^[ \t]*//;
+
+ for ($parser->YYData->{INPUT}) {
+ if (/^\#/) {
+ if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
+ $parser->YYData->{LINE} = $1-1;
+ $parser->YYData->{INPUT_FILENAME} = $2;
+ goto again;
+ }
+ if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) {
+ $parser->YYData->{LINE} = $1-1;
+ $parser->YYData->{INPUT_FILENAME} = $2;
+ goto again;
+ }
+ if (s/^(\#.*)$//m) {
+ goto again;
+ }
+ }
+ if (s/^(\n)//) {
+ $parser->YYData->{LINE}++;
+ goto again;
+ }
+ if (s/^\"(.*?)\"//) {
+ $parser->YYData->{LAST_TOKEN} = $1;
+ return('TEXT',$1);
+ }
+ if (s/^(\d+)(\W|$)/$2/) {
+ $parser->YYData->{LAST_TOKEN} = $1;
+ return('CONSTANT',$1);
+ }
+ if (s/^([\w_]+)//) {
+ $parser->YYData->{LAST_TOKEN} = $1;
+ if ($1 =~
+ /^(coclass|interface|const|typedef|declare|union
+ |struct|enum|bitmap|void)$/x) {
+ return $1;
+ }
+ return('IDENTIFIER',$1);
+ }
+ if (s/^(.)//s) {
+ $parser->YYData->{LAST_TOKEN} = $1;
+ return($1,$1);
+ }
+ }
+}
+
+sub parse_idl($$)
+{
+ my $self = shift;
+ my $filename = shift;
+
+ my $saved_delim = $/;
+ undef $/;
+ my $cpp = $ENV{CPP};
+ if (! defined $cpp) {
+ $cpp = "cpp"
+ }
+ my $data = `$cpp -D__PIDL__ -xc $filename`;
+ $/ = $saved_delim;
+
+ $self->YYData->{INPUT} = $data;
+ $self->YYData->{LINE} = 0;
+ $self->YYData->{LAST_TOKEN} = "NONE";
+
+ my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
+
+ return Parse::Pidl::Util::CleanData($idl);
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/NDR.pm b/source4/build/pidl/Parse/Pidl/NDR.pm
new file mode 100644
index 0000000000..f07b5e60ea
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/NDR.pm
@@ -0,0 +1,597 @@
+###################################################
+# Samba4 NDR info tree generator
+# Copyright tridge@samba.org 2000-2003
+# Copyright tpot@samba.org 2001
+# Copyright jelmer@samba.org 2004-2005
+# released under the GNU GPL
+
+package Parse::Pidl::NDR;
+
+use strict;
+use Parse::Pidl::Typelist;
+
+sub nonfatal($$)
+{
+ my ($e,$s) = @_;
+ warn ("$e->{FILE}:$e->{LINE}: Warning: $s\n");
+}
+
+#####################################################################
+# return a table describing the order in which the parts of an element
+# should be parsed
+# Possible level types:
+# - POINTER
+# - ARRAY
+# - SUBCONTEXT
+# - SWITCH
+# - DATA
+sub GetElementLevelTable($)
+{
+ my $e = shift;
+
+ my $order = [];
+ my $is_deferred = 0;
+ my @bracket_array = ();
+ my @length_is = ();
+ my @size_is = ();
+
+ if (Parse::Pidl::Util::has_property($e, "size_is")) {
+ @size_is = split /,/, Parse::Pidl::Util::has_property($e, "size_is");
+ }
+
+ if (Parse::Pidl::Util::has_property($e, "length_is")) {
+ @length_is = split /,/, Parse::Pidl::Util::has_property($e, "length_is");
+ }
+
+ if (defined($e->{ARRAY_LEN})) {
+ @bracket_array = @{$e->{ARRAY_LEN}};
+ }
+
+ # Parse the [][][][] style array stuff
+ foreach my $d (@bracket_array) {
+ my $size = $d;
+ my $length = $d;
+ my $is_surrounding = 0;
+ my $is_varying = 0;
+ my $is_conformant = 0;
+ my $is_string = 0;
+
+ if ($d eq "*") {
+ $is_conformant = 1;
+ if ($size = shift @size_is) {
+ } elsif ((scalar(@size_is) == 0) and Parse::Pidl::Util::has_property($e, "string")) {
+ $is_string = 1;
+ delete($e->{PROPERTIES}->{string});
+ } else {
+ print "$e->{FILE}:$e->{LINE}: Must specify size_is() for conformant array!\n";
+ exit 1;
+ }
+
+ if (($length = shift @length_is) or $is_string) {
+ $is_varying = 1;
+ } else {
+ $length = $size;
+ }
+
+ if ($e == $e->{PARENT}->{ELEMENTS}[-1]
+ and $e->{PARENT}->{TYPE} ne "FUNCTION") {
+ $is_surrounding = 1;
+ }
+ }
+
+ push (@$order, {
+ TYPE => "ARRAY",
+ SIZE_IS => $size,
+ LENGTH_IS => $length,
+ IS_DEFERRED => "$is_deferred",
+ IS_SURROUNDING => "$is_surrounding",
+ IS_ZERO_TERMINATED => "$is_string",
+ IS_VARYING => "$is_varying",
+ IS_CONFORMANT => "$is_conformant",
+ IS_FIXED => (not $is_conformant and Parse::Pidl::Util::is_constant($size)),
+ IS_INLINE => (not $is_conformant and not Parse::Pidl::Util::is_constant($size))
+ });
+ }
+
+ # Next, all the pointers
+ foreach my $i (1..$e->{POINTERS}) {
+ my $pt = pointer_type($e);
+
+ my $level = "EMBEDDED";
+ # Top level "ref" pointers do not have a referrent identifier
+ $level = "TOP" if ( defined($pt)
+ and $i == 1
+ and $e->{PARENT}->{TYPE} eq "FUNCTION");
+
+ push (@$order, {
+ TYPE => "POINTER",
+ # for now, there can only be one pointer type per element
+ POINTER_TYPE => pointer_type($e),
+ IS_DEFERRED => "$is_deferred",
+ LEVEL => $level
+ });
+
+ # everything that follows will be deferred
+ $is_deferred = 1 if ($e->{PARENT}->{TYPE} ne "FUNCTION");
+
+ my $array_size = shift @size_is;
+ my $array_length;
+ my $is_varying;
+ my $is_conformant;
+ my $is_string = 0;
+ if ($array_size) {
+ $is_conformant = 1;
+ if ($array_length = shift @length_is) {
+ $is_varying = 1;
+ } else {
+ $array_length = $array_size;
+ $is_varying =0;
+ }
+ }
+
+ if (scalar(@size_is) == 0 and Parse::Pidl::Util::has_property($e, "string")) {
+ $is_string = 1;
+ $is_varying = $is_conformant = Parse::Pidl::Util::has_property($e, "noheader")?0:1;
+ delete($e->{PROPERTIES}->{string});
+ }
+
+ if ($array_size or $is_string) {
+ push (@$order, {
+ TYPE => "ARRAY",
+ IS_ZERO_TERMINATED => "$is_string",
+ SIZE_IS => $array_size,
+ LENGTH_IS => $array_length,
+ IS_DEFERRED => "$is_deferred",
+ IS_SURROUNDING => 0,
+ IS_VARYING => "$is_varying",
+ IS_CONFORMANT => "$is_conformant",
+ IS_FIXED => 0,
+ IS_INLINE => 0,
+ });
+
+ $is_deferred = 0;
+ }
+ }
+
+ if (defined(Parse::Pidl::Util::has_property($e, "subcontext"))) {
+ my $hdr_size = Parse::Pidl::Util::has_property($e, "subcontext");
+ my $subsize = Parse::Pidl::Util::has_property($e, "subcontext_size");
+ if (not defined($subsize)) {
+ $subsize = -1;
+ }
+
+ push (@$order, {
+ TYPE => "SUBCONTEXT",
+ HEADER_SIZE => $hdr_size,
+ SUBCONTEXT_SIZE => $subsize,
+ IS_DEFERRED => $is_deferred,
+ COMPRESSION => Parse::Pidl::Util::has_property($e, "compression"),
+ OBFUSCATION => Parse::Pidl::Util::has_property($e, "obfuscation")
+ });
+ }
+
+ if (my $switch = Parse::Pidl::Util::has_property($e, "switch_is")) {
+ push (@$order, {
+ TYPE => "SWITCH",
+ SWITCH_IS => $switch,
+ IS_DEFERRED => $is_deferred
+ });
+ }
+
+ if (scalar(@size_is) > 0) {
+ nonfatal($e, "size_is() on non-array element");
+ }
+
+ if (scalar(@length_is) > 0) {
+ nonfatal($e, "length_is() on non-array element");
+ }
+
+ if (Parse::Pidl::Util::has_property($e, "string")) {
+ nonfatal($e, "string() attribute on non-array element");
+ }
+
+
+ push (@$order, {
+ TYPE => "DATA",
+ DATA_TYPE => $e->{TYPE},
+ IS_DEFERRED => $is_deferred,
+ CONTAINS_DEFERRED => can_contain_deferred($e),
+ IS_SURROUNDING => 0 #FIXME
+ });
+
+ my $i = 0;
+ foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
+
+ return $order;
+}
+
+#####################################################################
+# see if a type contains any deferred data
+sub can_contain_deferred
+{
+ my $e = shift;
+
+ return 1 if ($e->{POINTERS});
+ return 0 if (Parse::Pidl::Typelist::is_scalar($e->{TYPE}));
+ return 1 unless (Parse::Pidl::Typelist::hasType($e->{TYPE})); # assume the worst
+
+ my $type = Parse::Pidl::Typelist::getType($e->{TYPE});
+
+ foreach my $x (@{$type->{DATA}->{ELEMENTS}}) {
+ return 1 if (can_contain_deferred ($x));
+ }
+
+ return 0;
+}
+
+sub pointer_type($)
+{
+ my $e = shift;
+
+ return undef unless $e->{POINTERS};
+
+ return "ref" if (Parse::Pidl::Util::has_property($e, "ref"));
+ return "ptr" if (Parse::Pidl::Util::has_property($e, "ptr"));
+ return "sptr" if (Parse::Pidl::Util::has_property($e, "sptr"));
+ return "unique" if (Parse::Pidl::Util::has_property($e, "unique"));
+ return "relative" if (Parse::Pidl::Util::has_property($e, "relative"));
+ return "ignore" if (Parse::Pidl::Util::has_property($e, "ignore"));
+
+ return undef;
+}
+
+#####################################################################
+# work out the correct alignment for a structure or union
+sub find_largest_alignment($)
+{
+ my $s = shift;
+
+ my $align = 1;
+ for my $e (@{$s->{ELEMENTS}}) {
+ my $a = 1;
+
+ if ($e->{POINTERS}) {
+ $a = 4;
+ } else {
+ $a = align_type($e->{TYPE});
+ }
+
+ $align = $a if ($align < $a);
+ }
+
+ return $align;
+}
+
+#####################################################################
+# align a type
+sub align_type
+{
+ my $e = shift;
+
+ unless (Parse::Pidl::Typelist::hasType($e)) {
+ # it must be an external type - all we can do is guess
+ # print "Warning: assuming alignment of unknown type '$e' is 4\n";
+ return 4;
+ }
+
+ my $dt = Parse::Pidl::Typelist::getType($e)->{DATA};
+
+ if ($dt->{TYPE} eq "ENUM") {
+ return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
+ } elsif ($dt->{TYPE} eq "BITMAP") {
+ return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
+ } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
+ return find_largest_alignment($dt);
+ } elsif ($dt->{TYPE} eq "SCALAR") {
+ return Parse::Pidl::Typelist::getScalarAlignment($dt->{NAME});
+ }
+
+ die("Unknown data type type $dt->{TYPE}");
+}
+
+sub ParseElement($)
+{
+ my $e = shift;
+
+ return {
+ NAME => $e->{NAME},
+ TYPE => $e->{TYPE},
+ PROPERTIES => $e->{PROPERTIES},
+ LEVELS => GetElementLevelTable($e),
+ ALIGN => align_type($e->{TYPE})
+ };
+}
+
+sub ParseStruct($)
+{
+ my $struct = shift;
+ my @elements = ();
+ my $surrounding = undef;
+
+ foreach my $x (@{$struct->{ELEMENTS}})
+ {
+ push @elements, ParseElement($x);
+ }
+
+ my $e = $elements[-1];
+ if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
+ $e->{LEVELS}[0]->{IS_SURROUNDING}) {
+ $surrounding = $e;
+ }
+
+ if (defined $e->{TYPE} && $e->{TYPE} eq "string"
+ && Parse::Pidl::Util::property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
+ $surrounding = $struct->{ELEMENTS}[-1];
+ }
+
+ return {
+ TYPE => "STRUCT",
+ SURROUNDING_ELEMENT => $surrounding,
+ ELEMENTS => \@elements,
+ PROPERTIES => $struct->{PROPERTIES}
+ };
+}
+
+sub ParseUnion($)
+{
+ my $e = shift;
+ my @elements = ();
+ my $switch_type = Parse::Pidl::Util::has_property($e, "switch_type");
+ unless (defined($switch_type)) { $switch_type = "uint32"; }
+
+ if (Parse::Pidl::Util::has_property($e, "nodiscriminant")) { $switch_type = undef; }
+
+ foreach my $x (@{$e->{ELEMENTS}})
+ {
+ my $t;
+ if ($x->{TYPE} eq "EMPTY") {
+ $t = { TYPE => "EMPTY" };
+ } else {
+ $t = ParseElement($x);
+ }
+ if (Parse::Pidl::Util::has_property($x, "default")) {
+ $t->{CASE} = "default";
+ } elsif (defined($x->{PROPERTIES}->{case})) {
+ $t->{CASE} = "case $x->{PROPERTIES}->{case}";
+ } else {
+ die("Union element $x->{NAME} has neither default nor case property");
+ }
+ push @elements, $t;
+ }
+
+ return {
+ TYPE => "UNION",
+ SWITCH_TYPE => $switch_type,
+ ELEMENTS => \@elements,
+ PROPERTIES => $e->{PROPERTIES}
+ };
+}
+
+sub ParseEnum($)
+{
+ my $e = shift;
+
+ return {
+ TYPE => "ENUM",
+ BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
+ ELEMENTS => $e->{ELEMENTS},
+ PROPERTIES => $e->{PROPERTIES}
+ };
+}
+
+sub ParseBitmap($)
+{
+ my $e = shift;
+
+ return {
+ TYPE => "BITMAP",
+ BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
+ ELEMENTS => $e->{ELEMENTS},
+ PROPERTIES => $e->{PROPERTIES}
+ };
+}
+
+sub ParseTypedef($$)
+{
+ my ($ndr,$d) = @_;
+ my $data;
+
+ if ($d->{DATA}->{TYPE} eq "STRUCT" or $d->{DATA}->{TYPE} eq "UNION") {
+ CheckPointerTypes($d->{DATA}, $ndr->{PROPERTIES}->{pointer_default});
+ }
+
+ if (defined($d->{PROPERTIES}) && !defined($d->{DATA}->{PROPERTIES})) {
+ $d->{DATA}->{PROPERTIES} = $d->{PROPERTIES};
+ }
+
+ $data = {
+ STRUCT => \&ParseStruct,
+ UNION => \&ParseUnion,
+ ENUM => \&ParseEnum,
+ BITMAP => \&ParseBitmap
+ }->{$d->{DATA}->{TYPE}}->($d->{DATA});
+
+ $data->{ALIGN} = align_type($d->{NAME});
+
+ return {
+ NAME => $d->{NAME},
+ TYPE => $d->{TYPE},
+ PROPERTIES => $d->{PROPERTIES},
+ DATA => $data
+ };
+}
+
+sub ParseConst($$)
+{
+ my ($ndr,$d) = @_;
+
+ return $d;
+}
+
+sub ParseFunction($$$)
+{
+ my ($ndr,$d,$opnum) = @_;
+ my @elements = ();
+ my $rettype = undef;
+ my $thisopnum = undef;
+
+ CheckPointerTypes($d, $ndr->{PROPERTIES}->{pointer_default_top});
+
+ if (not defined($d->{PROPERTIES}{noopnum})) {
+ $thisopnum = ${$opnum};
+ ${$opnum}++;
+ }
+
+ foreach my $x (@{$d->{ELEMENTS}}) {
+ my $e = ParseElement($x);
+ push (@{$e->{DIRECTION}}, "in") if (Parse::Pidl::Util::has_property($x, "in"));
+ push (@{$e->{DIRECTION}}, "out") if (Parse::Pidl::Util::has_property($x, "out"));
+ push (@elements, $e);
+ }
+
+ if ($d->{RETURN_TYPE} ne "void") {
+ $rettype = $d->{RETURN_TYPE};
+ }
+
+ return {
+ NAME => $d->{NAME},
+ TYPE => "FUNCTION",
+ OPNUM => $thisopnum,
+ RETURN_TYPE => $rettype,
+ PROPERTIES => $d->{PROPERTIES},
+ ELEMENTS => \@elements
+ };
+}
+
+sub CheckPointerTypes($$)
+{
+ my $s = shift;
+ my $default = shift;
+
+ foreach my $e (@{$s->{ELEMENTS}}) {
+ if ($e->{POINTERS} and not defined(pointer_type($e))) {
+ $e->{PROPERTIES}->{$default} = 1;
+ }
+ }
+}
+
+sub ParseInterface($)
+{
+ my $idl = shift;
+ my @typedefs = ();
+ my @consts = ();
+ my @functions = ();
+ my @endpoints;
+ my @declares = ();
+ my $opnum = 0;
+ my $version;
+
+ if (not Parse::Pidl::Util::has_property($idl, "pointer_default")) {
+ # MIDL defaults to "ptr" in DCE compatible mode (/osf)
+ # and "unique" in Microsoft Extensions mode (default)
+ $idl->{PROPERTIES}->{pointer_default} = "unique";
+ }
+
+ if (not Parse::Pidl::Util::has_property($idl, "pointer_default_top")) {
+ $idl->{PROPERTIES}->{pointer_default_top} = "ref";
+ }
+
+ foreach my $d (@{$idl->{DATA}}) {
+ if ($d->{TYPE} eq "TYPEDEF") {
+ push (@typedefs, ParseTypedef($idl, $d));
+ }
+
+ if ($d->{TYPE} eq "DECLARE") {
+ push (@declares, $d);
+ }
+
+ if ($d->{TYPE} eq "FUNCTION") {
+ push (@functions, ParseFunction($idl, $d, \$opnum));
+ }
+
+ if ($d->{TYPE} eq "CONST") {
+ push (@consts, ParseConst($idl, $d));
+ }
+ }
+
+ $version = "0.0";
+
+ if(defined $idl->{PROPERTIES}->{version}) {
+ $version = $idl->{PROPERTIES}->{version};
+ }
+
+ # If no endpoint is set, default to the interface name as a named pipe
+ if (!defined $idl->{PROPERTIES}->{endpoint}) {
+ push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
+ } else {
+ @endpoints = split / /, $idl->{PROPERTIES}->{endpoint};
+ }
+
+ return {
+ NAME => $idl->{NAME},
+ UUID => Parse::Pidl::Util::has_property($idl, "uuid"),
+ VERSION => $version,
+ TYPE => "INTERFACE",
+ PROPERTIES => $idl->{PROPERTIES},
+ FUNCTIONS => \@functions,
+ CONSTS => \@consts,
+ TYPEDEFS => \@typedefs,
+ DECLARES => \@declares,
+ ENDPOINTS => \@endpoints
+ };
+}
+
+# Convert a IDL tree to a NDR tree
+# Gives a result tree describing all that's necessary for easily generating
+# NDR parsers / generators
+sub Parse($)
+{
+ my $idl = shift;
+ my @ndr = ();
+
+ push(@ndr, ParseInterface($_)) foreach (@{$idl});
+
+ return \@ndr;
+}
+
+sub GetNextLevel($$)
+{
+ my $e = shift;
+ my $fl = shift;
+
+ my $seen = 0;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ return $l if ($seen);
+ ($seen = 1) if ($l == $fl);
+ }
+
+ return undef;
+}
+
+sub GetPrevLevel($$)
+{
+ my ($e,$fl) = @_;
+ my $prev = undef;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ (return $prev) if ($l == $fl);
+ $prev = $l;
+ }
+
+ return undef;
+}
+
+sub ContainsDeferred($$)
+{
+ my ($e,$l) = @_;
+
+ do {
+ return 1 if ($l->{IS_DEFERRED});
+ return 1 if ($l->{CONTAINS_DEFERRED});
+ } while ($l = GetNextLevel($e,$l));
+
+ return 0;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/ODL.pm b/source4/build/pidl/Parse/Pidl/ODL.pm
new file mode 100644
index 0000000000..eddf7e417c
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/ODL.pm
@@ -0,0 +1,89 @@
+##########################################
+# Converts ODL stuctures to IDL structures
+# (C) 2004-2005 Jelmer Vernooij <jelmer@samba.org>
+
+package Parse::Pidl::ODL;
+
+use strict;
+
+#####################################################################
+# find an interface in an array of interfaces
+sub get_interface($$)
+{
+ my($if) = shift;
+ my($n) = shift;
+
+ foreach(@{$if}) {
+ if($_->{NAME} eq $n) { return $_; }
+ }
+
+ return 0;
+}
+
+sub FunctionAddObjArgs($)
+{
+ my $e = shift;
+
+ unshift(@{$e->{ELEMENTS}}, {
+ 'NAME' => 'ORPCthis',
+ 'POINTERS' => 0,
+ 'PROPERTIES' => { 'in' => '1' },
+ 'TYPE' => 'ORPCTHIS'
+ });
+ unshift(@{$e->{ELEMENTS}}, {
+ 'NAME' => 'ORPCthat',
+ 'POINTERS' => 0,
+ 'PROPERTIES' => { 'out' => '1' },
+ 'TYPE' => 'ORPCTHAT'
+ });
+}
+
+sub ReplaceInterfacePointers($)
+{
+ my $e = shift;
+
+ foreach my $x (@{$e->{ELEMENTS}}) {
+ next unless (Parse::Pidl::Typelist::hasType($x->{TYPE}));
+ next unless Parse::Pidl::Typelist::getType($x->{TYPE})->{DATA}->{TYPE} eq "INTERFACE";
+
+ $x->{TYPE} = "MInterfacePointer";
+ }
+}
+
+# Add ORPC specific bits to an interface.
+sub ODL2IDL($)
+{
+ my $odl = shift;
+
+ foreach my $x (@{$odl}) {
+ # Add [in] ORPCTHIS *this, [out] ORPCTHAT *that
+ # and replace interfacepointers with MInterfacePointer
+ # for 'object' interfaces
+ if (Parse::Pidl::Util::has_property($x, "object")) {
+ foreach my $e (@{$x->{DATA}}) {
+ ($e->{TYPE} eq "FUNCTION") && FunctionAddObjArgs($e);
+ ReplaceInterfacePointers($e);
+ }
+ # Object interfaces use ORPC
+ my @depends = ();
+ if(Parse::Pidl::Util::has_property($x, "depends")) {
+ @depends = split /,/, $x->{PROPERTIES}->{depends};
+ }
+ push @depends, "orpc";
+ $x->{PROPERTIES}->{depends} = join(',',@depends);
+ }
+
+ if ($x->{BASE}) {
+ my $base = get_interface($odl, $x->{BASE});
+
+ foreach my $fn (reverse @{$base->{DATA}}) {
+ next unless ($fn->{TYPE} eq "FUNCTION");
+ unshift (@{$x->{DATA}}, $fn);
+ }
+ }
+ }
+
+ return $odl;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/COM/Header.pm b/source4/build/pidl/Parse/Pidl/Samba/COM/Header.pm
new file mode 100644
index 0000000000..4f5e0d68ad
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/COM/Header.pm
@@ -0,0 +1,138 @@
+# COM Header generation
+# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+
+package Parse::Pidl::Samba::COM::Header;
+
+use Parse::Pidl::Typelist;
+
+use strict;
+
+sub GetArgumentProtoList($)
+{
+ my $f = shift;
+ my $res = "";
+
+ foreach my $a (@{$f->{ELEMENTS}}) {
+
+ $res .= ", " . Parse::Pidl::Typelist::mapType($a->{TYPE}) . " ";
+
+ my $l = $a->{POINTERS};
+ $l-- if (Parse::Pidl::Typelist::scalar_is_reference($a->{TYPE}));
+ foreach my $i (1..$l) {
+ $res .= "*";
+ }
+
+ if (defined $a->{ARRAY_LEN}[0] &&
+ !Parse::Pidl::Util::is_constant($a->{ARRAY_LEN}[0]) &&
+ !$a->{POINTERS}) {
+ $res .= "*";
+ }
+ $res .= $a->{NAME};
+ if (defined $a->{ARRAY_LEN}[0] && Parse::Pidl::Util::is_constant($a->{ARRAY_LEN}[0])) {
+ $res .= "[$a->{ARRAY_LEN}[0]]";
+ }
+ }
+
+ return $res;
+}
+
+sub GetArgumentList($)
+{
+ my $f = shift;
+ my $res = "";
+
+ foreach my $a (@{$f->{ELEMENTS}}) {
+ $res .= ", $a->{NAME}";
+ }
+
+ return $res;
+}
+
+#####################################################################
+# generate vtable structure for COM interface
+sub HeaderVTable($)
+{
+ my $interface = shift;
+ my $res;
+ $res .= "#define " . uc($interface->{NAME}) . "_METHODS \\\n";
+ if (defined($interface->{BASE})) {
+ $res .= "\t" . uc($interface->{BASE} . "_METHODS") . "\\\n";
+ }
+
+ my $data = $interface->{DATA};
+ foreach my $d (@{$data}) {
+ $res .= "\t" . Parse::Pidl::Typelist::mapType($d->{RETURN_TYPE}) . " (*$d->{NAME}) (struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . GetArgumentProtoList($d) . ");\\\n" if ($d->{TYPE} eq "FUNCTION");
+ }
+ $res .= "\n";
+ $res .= "struct $interface->{NAME}_vtable {\n";
+ $res .= "\tstruct GUID iid;\n";
+ $res .= "\t" . uc($interface->{NAME}) . "_METHODS\n";
+ $res .= "};\n\n";
+
+ return $res;
+}
+
+sub ParseInterface($)
+{
+ my $if = shift;
+ my $res;
+
+ $res .="\n\n/* $if->{NAME} */\n";
+
+ $res .="#define COM_" . uc($if->{NAME}) . "_UUID $if->{PROPERTIES}->{uuid}\n\n";
+
+ $res .="struct $if->{NAME}_vtable;\n\n";
+
+ $res .="struct $if->{NAME} {
+ struct com_context *ctx;
+ struct $if->{NAME}_vtable *vtable;
+ void *object_data;
+};\n\n";
+
+ $res.=HeaderVTable($if);
+
+ foreach my $d (@{$if->{DATA}}) {
+ next if ($d->{TYPE} ne "FUNCTION");
+
+ $res .= "#define $if->{NAME}_$d->{NAME}(interface, mem_ctx" . GetArgumentList($d) . ") ";
+
+ $res .= "((interface)->vtable->$d->{NAME}(interface, mem_ctx" . GetArgumentList($d) . "))";
+
+ $res .="\n";
+ }
+
+ return $res;
+}
+
+sub ParseCoClass($)
+{
+ my $c = shift;
+ my $res = "";
+ $res .= "#define CLSID_" . uc($c->{NAME}) . " $c->{PROPERTIES}->{uuid}\n";
+ if (Parse::Pidl::Util::has_property($c, "progid")) {
+ $res .= "#define PROGID_" . uc($c->{NAME}) . " $c->{PROPERTIES}->{progid}\n";
+ }
+ $res .= "\n";
+ return $res;
+}
+
+sub Parse($)
+{
+ my $idl = shift;
+ my $res = "";
+
+ foreach my $x (@{$idl})
+ {
+ if ($x->{TYPE} eq "INTERFACE" && Parse::Pidl::Util::has_property($x, "object")) {
+ $res.=ParseInterface($x);
+ }
+
+ if ($x->{TYPE} eq "COCLASS") {
+ $res.=ParseCoClass($x);
+ }
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/COM/Proxy.pm b/source4/build/pidl/Parse/Pidl/Samba/COM/Proxy.pm
new file mode 100644
index 0000000000..f4c23e1d9b
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/COM/Proxy.pm
@@ -0,0 +1,211 @@
+###################################################
+# DCOM parser for Samba
+# Basically the glue between COM and DCE/RPC with NDR
+# Copyright jelmer@samba.org 2003-2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::COM::Proxy;
+
+use Parse::Pidl::Samba::COM::Header;
+
+use strict;
+
+my($res);
+
+sub ParseVTable($$)
+{
+ my $interface = shift;
+ my $name = shift;
+
+ # Generate the vtable
+ $res .="\tstruct $interface->{NAME}_vtable $name = {";
+
+ if (defined($interface->{BASE})) {
+ $res .= "\n\t\t{},";
+ }
+
+ my $data = $interface->{DATA};
+
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") {
+ $res .= "\n\t\tdcom_proxy_$interface->{NAME}_$d->{NAME}";
+ $res .= ",";
+ }
+ }
+
+ $res .= "\n\t};\n\n";
+}
+
+sub ParseRegFunc($)
+{
+ my $interface = shift;
+
+ $res .= "static NTSTATUS dcom_proxy_$interface->{NAME}_init(void)
+{
+ struct GUID base_iid;
+ struct $interface->{NAME}_vtable *proxy_vtable = talloc(talloc_autofree_context(), struct $interface->{NAME}_vtable);
+";
+
+ if (defined($interface->{BASE})) {
+ $res.= "
+ const void *base_vtable;
+
+ GUID_from_string(DCERPC_" . (uc $interface->{BASE}) . "_UUID, &base_iid);
+
+ base_vtable = dcom_proxy_vtable_by_iid(&base_iid);
+ if (base_vtable == NULL) {
+ DEBUG(0, (\"No proxy registered for base interface '$interface->{BASE}'\\n\"));
+ return NT_STATUS_FOOBAR;
+ }
+
+ memcpy(&proxy_vtable, base_vtable, sizeof(struct $interface->{BASE}_vtable));
+
+";
+ }
+ foreach my $x (@{$interface->{DATA}}) {
+ next unless ($x->{TYPE} eq "FUNCTION");
+
+ $res .= "\tproxy_vtable.$x->{NAME} = dcom_proxy_$interface->{NAME}_$x->{NAME};\n";
+ }
+
+ $res.= "
+ GUID_from_string(DCERPC_" . (uc $interface->{NAME}) . "_UUID, &proxy_vtable.iid);
+
+ return dcom_register_proxy(&proxy_vtable);
+}\n\n";
+}
+
+#####################################################################
+# parse a function
+sub ParseFunction($$)
+{
+ my $interface = shift;
+ my $fn = shift;
+ my $name = $fn->{NAME};
+ my $uname = uc $name;
+
+ $res.="
+static $fn->{RETURN_TYPE} dcom_proxy_$interface->{NAME}_$name(struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . Parse::Pidl::Samba::COM::Header::GetArgumentProtoList($fn) . ")
+{
+ struct dcerpc_pipe *p;
+ NTSTATUS status = dcom_get_pipe(d, &p);
+ struct $name r;
+ struct rpc_request *req;
+
+ if (NT_STATUS_IS_ERR(status)) {
+ return status;
+ }
+
+ ZERO_STRUCT(r.in.ORPCthis);
+ r.in.ORPCthis.version.MajorVersion = COM_MAJOR_VERSION;
+ r.in.ORPCthis.version.MinorVersion = COM_MINOR_VERSION;
+";
+
+ # Put arguments into r
+ foreach my $a (@{$fn->{ELEMENTS}}) {
+ next unless (Parse::Pidl::Util::has_property($a, "in"));
+ if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) {
+ $res .="\tNDR_CHECK(dcom_OBJREF_from_IUnknown(&r.in.$a->{NAME}.obj, $a->{NAME}));\n";
+ } else {
+ $res .= "\tr.in.$a->{NAME} = $a->{NAME};\n";
+ }
+ }
+
+ $res .="
+ if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
+ NDR_PRINT_IN_DEBUG($name, &r);
+ }
+
+ status = dcerpc_ndr_request(p, &d->ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, &r);
+
+ if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
+ NDR_PRINT_OUT_DEBUG($name, r);
+ }
+
+";
+
+ # Put r info back into arguments
+ foreach my $a (@{$fn->{ELEMENTS}}) {
+ next unless (Parse::Pidl::Util::has_property($a, "out"));
+
+ if (Parse::Pidl::Typelist::typeIs($a->{TYPE}, "INTERFACE")) {
+ $res .="\tNDR_CHECK(dcom_IUnknown_from_OBJREF(d->ctx, &$a->{NAME}, r.out.$a->{NAME}.obj));\n";
+ } else {
+ $res .= "\t*$a->{NAME} = r.out.$a->{NAME};\n";
+ }
+
+ }
+
+ if ($fn->{RETURN_TYPE} eq "NTSTATUS") {
+ $res .= "\tif (NT_STATUS_IS_OK(status)) status = r.out.result;\n";
+ }
+
+ $res .=
+ "
+ return r.out.result;
+}\n\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub ParseInterface($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ $res = "/* DCOM proxy for $interface->{NAME} generated by pidl */\n\n";
+ foreach my $d (@{$data}) {
+ ($d->{TYPE} eq "FUNCTION") &&
+ ParseFunction($interface, $d);
+ }
+
+ ParseRegFunc($interface);
+}
+
+sub RegistrationFunction($$)
+{
+ my $idl = shift;
+ my $basename = shift;
+
+ my $res = "\n\nNTSTATUS dcom_$basename\_init(void)\n";
+ $res .= "{\n";
+ $res .="\tNTSTATUS status = NT_STATUS_OK;\n";
+ foreach my $interface (@{$idl}) {
+ next if $interface->{TYPE} ne "INTERFACE";
+ next if not Parse::Pidl::Util::has_property($interface, "object");
+
+ my $data = $interface->{DATA};
+ my $count = 0;
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") { $count++; }
+ }
+
+ next if ($count == 0);
+
+ $res .= "\tstatus = dcom_$interface->{NAME}_init();\n";
+ $res .= "\tif (NT_STATUS_IS_ERR(status)) {\n";
+ $res .= "\t\treturn status;\n";
+ $res .= "\t}\n\n";
+ }
+ $res .= "\treturn status;\n";
+ $res .= "}\n\n";
+
+ return $res;
+}
+
+sub Parse($)
+{
+ my $pidl = shift;
+ my $res = "";
+
+ foreach my $x (@{$pidl}) {
+ next if ($x->{TYPE} ne "INTERFACE");
+ next if Parse::Pidl::Util::has_property($x, "local");
+ next unless Parse::Pidl::Util::has_property($x, "object");
+
+ $res .= ParseInterface($x);
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/COM/Stub.pm b/source4/build/pidl/Parse/Pidl/Samba/COM/Stub.pm
new file mode 100644
index 0000000000..a06671e76d
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/COM/Stub.pm
@@ -0,0 +1,323 @@
+###################################################
+# DCOM stub boilerplate generator
+# Copyright jelmer@samba.org 2004-2005
+# Copyright tridge@samba.org 2003
+# Copyright metze@samba.org 2004
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::COM::Stub;
+
+use strict;
+
+my($res);
+
+sub pidl($)
+{
+ $res .= shift;
+}
+
+#####################################################
+# generate the switch statement for function dispatch
+sub gen_dispatch_switch($)
+{
+ my $data = shift;
+
+ my $count = 0;
+ foreach my $d (@{$data}) {
+ next if ($d->{TYPE} ne "FUNCTION");
+
+ pidl "\tcase $count: {\n";
+ if ($d->{RETURN_TYPE} && $d->{RETURN_TYPE} ne "void") {
+ pidl "\t\tNTSTATUS result;\n";
+ }
+ pidl "\t\tstruct $d->{NAME} *r2 = r;\n";
+ pidl "\t\tif (DEBUGLEVEL > 10) {\n";
+ pidl "\t\t\tNDR_PRINT_FUNCTION_DEBUG($d->{NAME}, NDR_IN, r2);\n";
+ pidl "\t\t}\n";
+ if ($d->{RETURN_TYPE} && $d->{RETURN_TYPE} ne "void") {
+ pidl "\t\tresult = vtable->$d->{NAME}(iface, mem_ctx, r2);\n";
+ } else {
+ pidl "\t\tvtable->$d->{NAME}(iface, mem_ctx, r2);\n";
+ }
+ pidl "\t\tif (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {\n";
+ pidl "\t\t\tDEBUG(5,(\"function $d->{NAME} will reply async\\n\"));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tbreak;\n\t}\n";
+ $count++;
+ }
+}
+
+#####################################################
+# generate the switch statement for function reply
+sub gen_reply_switch($)
+{
+ my $data = shift;
+
+ my $count = 0;
+ foreach my $d (@{$data}) {
+ next if ($d->{TYPE} ne "FUNCTION");
+
+ pidl "\tcase $count: {\n";
+ pidl "\t\tstruct $d->{NAME} *r2 = r;\n";
+ pidl "\t\tif (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {\n";
+ pidl "\t\t\tDEBUG(5,(\"function $d->{NAME} replied async\\n\"));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tif (DEBUGLEVEL > 10 && dce_call->fault_code == 0) {\n";
+ pidl "\t\t\tNDR_PRINT_FUNCTION_DEBUG($d->{NAME}, NDR_OUT | NDR_SET_VALUES, r2);\n";
+ pidl "\t\t}\n";
+ pidl "\t\tif (dce_call->fault_code != 0) {\n";
+ pidl "\t\t\tDEBUG(2,(\"dcerpc_fault %s in $d->{NAME}\\n\", dcerpc_errstr(mem_ctx, dce_call->fault_code)));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tbreak;\n\t}\n";
+ $count++;
+ }
+}
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Boilerplate_Iface($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ my $name = $interface->{NAME};
+ my $uname = uc $name;
+ my $uuid = Parse::Pidl::Util::make_str($interface->{PROPERTIES}->{uuid});
+ my $if_version = $interface->{PROPERTIES}->{version};
+
+ pidl "
+static NTSTATUS $name\__op_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
+{
+#ifdef DCESRV_INTERFACE_$uname\_BIND
+ return DCESRV_INTERFACE_$uname\_BIND(dce_call,iface);
+#else
+ return NT_STATUS_OK;
+#endif
+}
+
+static void $name\__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
+{
+#ifdef DCESRV_INTERFACE_$uname\_UNBIND
+ DCESRV_INTERFACE_$uname\_UNBIND(context, iface);
+#else
+ return;
+#endif
+}
+
+static NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
+{
+ NTSTATUS status;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ dce_call->fault_code = 0;
+
+ if (opnum >= dcerpc_table_$name.num_calls) {
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ *r = talloc_size(mem_ctx, dcerpc_table_$name.calls[opnum].struct_size);
+ NT_STATUS_HAVE_NO_MEMORY(*r);
+
+ /* unravel the NDR for the packet */
+ status = dcerpc_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
+{
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+ struct GUID ipid = dce_call->pkt.u.request.object.object;
+ struct dcom_interface_p *iface = dcom_get_local_iface_p(&ipid);
+ const struct dcom_$name\_vtable *vtable = iface->vtable;
+
+ switch (opnum) {
+";
+ gen_dispatch_switch($data);
+
+pidl "
+ default:
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ break;
+ }
+
+ if (dce_call->fault_code != 0) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
+{
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ switch (opnum) {
+";
+ gen_reply_switch($data);
+
+pidl "
+ default:
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ break;
+ }
+
+ if (dce_call->fault_code != 0) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)
+{
+ NTSTATUS status;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ status = dcerpc_table_$name.calls[opnum].ndr_push(push, NDR_OUT, r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static const struct dcesrv_interface $name\_interface = {
+ .name = \"$name\",
+ .uuid = $uuid,
+ .if_version = $if_version,
+ .bind = $name\__op_bind,
+ .unbind = $name\__op_unbind,
+ .ndr_pull = $name\__op_ndr_pull,
+ .dispatch = $name\__op_dispatch,
+ .reply = $name\__op_reply,
+ .ndr_push = $name\__op_ndr_push
+};
+
+";
+}
+
+#####################################################################
+# produce boilerplate code for an endpoint server
+sub Boilerplate_Ep_Server($)
+{
+ my($interface) = shift;
+ my $name = $interface->{NAME};
+ my $uname = uc $name;
+
+ pidl "
+static NTSTATUS $name\__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
+{
+ int i;
+
+ for (i=0;i<dcerpc_table_$name.endpoints->count;i++) {
+ NTSTATUS ret;
+ const char *name = dcerpc_table_$name.endpoints->names[i];
+
+ ret = dcesrv_interface_register(dce_ctx, name, &$name\_interface, NULL);
+ if (!NT_STATUS_IS_OK(ret)) {
+ DEBUG(1,(\"$name\_op_init_server: failed to register endpoint \'%s\'\\n\",name));
+ return ret;
+ }
+ }
+
+ return NT_STATUS_OK;
+}
+
+static BOOL $name\__op_interface_by_uuid(struct dcesrv_interface *iface, const char *uuid, uint32_t if_version)
+{
+ if (dcerpc_table_$name.if_version == if_version &&
+ strcmp(dcerpc_table_$name.uuid, uuid)==0) {
+ memcpy(iface,&dcerpc_table_$name, sizeof(*iface));
+ return True;
+ }
+
+ return False;
+}
+
+static BOOL $name\__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
+{
+ if (strcmp(dcerpc_table_$name.name, name)==0) {
+ memcpy(iface,&dcerpc_table_$name, sizeof(*iface));
+ return True;
+ }
+
+ return False;
+}
+
+NTSTATUS dcerpc_server_$name\_init(void)
+{
+ NTSTATUS ret;
+ struct dcesrv_endpoint_server ep_server;
+
+ /* fill in our name */
+ ep_server.name = \"$name\";
+
+ /* fill in all the operations */
+ ep_server.init_server = $name\__op_init_server;
+
+ ep_server.interface_by_uuid = $name\__op_interface_by_uuid;
+ ep_server.interface_by_name = $name\__op_interface_by_name;
+
+ /* register ourselves with the DCERPC subsystem. */
+ ret = dcerpc_register_ep_server(&ep_server);
+
+ if (!NT_STATUS_IS_OK(ret)) {
+ DEBUG(0,(\"Failed to register \'$name\' endpoint server!\\n\"));
+ return ret;
+ }
+
+ return ret;
+}
+
+";
+}
+
+#####################################################################
+# dcom interface stub from a parsed IDL structure
+sub ParseInterface($)
+{
+ my($interface) = shift;
+
+ return "" if Parse::Pidl::Util::has_property($interface, "local");
+
+ my($data) = $interface->{DATA};
+ my $count = 0;
+
+ $res = "";
+
+ if (!defined $interface->{PROPERTIES}->{uuid}) {
+ return $res;
+ }
+
+ if (!defined $interface->{PROPERTIES}->{version}) {
+ $interface->{PROPERTIES}->{version} = "0.0";
+ }
+
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") { $count++; }
+ }
+
+ if ($count == 0) {
+ return $res;
+ }
+
+ $res = "/* dcom interface stub generated by pidl */\n\n";
+ Boilerplate_Iface($interface);
+ Boilerplate_Ep_Server($interface);
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/EJS.pm b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm
new file mode 100644
index 0000000000..72f280add0
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm
@@ -0,0 +1,734 @@
+###################################################
+# EJS function wrapper generator
+# Copyright jelmer@samba.org 2005
+# Copyright Andrew Tridgell 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::EJS;
+
+use strict;
+use Parse::Pidl::Typelist;
+
+my($res);
+my %constants;
+
+my $tabs = "";
+sub pidl($)
+{
+ my $d = shift;
+ if ($d) {
+ $res .= $tabs;
+ $res .= $d;
+ }
+ $res .= "\n";
+}
+
+sub indent()
+{
+ $tabs .= "\t";
+}
+
+sub deindent()
+{
+ $tabs = substr($tabs, 0, -1);
+}
+
+# this should probably be in ndr.pm
+sub GenerateStructEnv($)
+{
+ my $x = shift;
+ my %env;
+
+ foreach my $e (@{$x->{ELEMENTS}}) {
+ if ($e->{NAME}) {
+ $env{$e->{NAME}} = "r->$e->{NAME}";
+ }
+ }
+
+ $env{"this"} = "r";
+
+ return \%env;
+}
+
+sub GenerateFunctionInEnv($)
+{
+ my $fn = shift;
+ my %env;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep (/in/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->in.$e->{NAME}";
+ }
+ }
+
+ return \%env;
+}
+
+sub GenerateFunctionOutEnv($)
+{
+ my $fn = shift;
+ my %env;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep (/out/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->out.$e->{NAME}";
+ } elsif (grep (/in/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->in.$e->{NAME}";
+ }
+ }
+
+ return \%env;
+}
+
+sub get_pointer_to($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\*(.*)$/) {
+ return $1;
+ } elsif ($var_name =~ /^\&(.*)$/) {
+ return "&($var_name)";
+ } else {
+ return "&$var_name";
+ }
+}
+
+sub get_value_of($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\&(.*)$/) {
+ return $1;
+ } else {
+ return "*$var_name";
+ }
+}
+
+#####################################################################
+# work out is a parse function should be declared static or not
+sub fn_prefix($)
+{
+ my $fn = shift;
+
+ return "" if (Parse::Pidl::Util::has_property($fn, "public"));
+ return "static ";
+}
+
+###########################
+# pull a scalar element
+sub EjsPullScalar($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+
+ return if (Parse::Pidl::Util::has_property($e, "value"));
+
+ $var = get_pointer_to($var);
+ # have to handle strings specially :(
+ if ($e->{TYPE} eq "string") {
+ $var = get_pointer_to($var);
+ }
+ pidl "NDR_CHECK(ejs_pull_$e->{TYPE}(ejs, v, $name, $var));";
+}
+
+###########################
+# pull a pointer element
+sub EjsPullPointer($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ pidl "if (ejs_pull_null(ejs, v, $name)) {";
+ indent;
+ pidl "$var = NULL;";
+ deindent;
+ pidl "} else {";
+ indent;
+ pidl "EJS_ALLOC(ejs, $var);";
+ $var = get_value_of($var);
+ EjsPullElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
+ deindent;
+ pidl "}";
+}
+
+###########################
+# pull a string element
+sub EjsPullString($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ $var = get_pointer_to($var);
+ pidl "NDR_CHECK(ejs_pull_string(ejs, v, $name, $var));";
+}
+
+
+###########################
+# pull an array element
+sub EjsPullArray($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l);
+ if ($pl && $pl->{TYPE} eq "POINTER") {
+ $var = get_pointer_to($var);
+ }
+ my $avar = $var . "[i]";
+ pidl "{";
+ indent;
+ pidl "uint32_t i;";
+ if (!$l->{IS_FIXED}) {
+ pidl "EJS_ALLOC_N(ejs, $var, $length);";
+ }
+ pidl "for (i=0;i<$length;i++) {";
+ indent;
+ pidl "char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);";
+ EjsPullElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $avar, "id", $env);
+ pidl "talloc_free(id);";
+ deindent;
+ pidl "}";
+ pidl "ejs_push_uint32(ejs, v, $name \".length\", &i);";
+ deindent;
+ pidl "}";
+}
+
+###########################
+# pull a switch element
+sub EjsPullSwitch($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+ pidl "ejs_set_switch(ejs, $switch_var);";
+ EjsPullElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
+}
+
+###########################
+# pull a structure element
+sub EjsPullElement($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ EjsPullString($e, $l, $var, $name, $env);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ EjsPullArray($e, $l, $var, $name, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ EjsPullScalar($e, $l, $var, $name, $env);
+ } elsif (($l->{TYPE} eq "POINTER")) {
+ EjsPullPointer($e, $l, $var, $name, $env);
+ } elsif (($l->{TYPE} eq "SWITCH")) {
+ EjsPullSwitch($e, $l, $var, $name, $env);
+ } else {
+ pidl "return ejs_panic(ejs, \"unhandled pull type $l->{TYPE}\");";
+ }
+}
+
+#############################################
+# pull a structure/union element at top level
+sub EjsPullElementTop($$)
+{
+ my $e = shift;
+ my $env = shift;
+ my $l = $e->{LEVELS}[0];
+ my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env);
+ my $name = "\"$e->{NAME}\"";
+ EjsPullElement($e, $l, $var, $name, $env);
+}
+
+###########################
+# pull a struct
+sub EjsStructPull($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $env = GenerateStructEnv($d);
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)\n{";
+ indent;
+ pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));";
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ EjsPullElementTop($e, $env);
+ }
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+###########################
+# pull a union
+sub EjsUnionPull($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $have_default = 0;
+ my $env = GenerateStructEnv($d);
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, union $name *r)\n{";
+ indent;
+ pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));";
+ pidl "switch (ejs->switch_var) {";
+ indent;
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ if ($e->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$e->{CASE}:";
+ indent;
+ if ($e->{TYPE} ne "EMPTY") {
+ EjsPullElementTop($e, $env);
+ }
+ pidl "break;";
+ deindent;
+ }
+ if (! $have_default) {
+ pidl "default:";
+ indent;
+ pidl "return ejs_panic(ejs, \"Bad switch value\");";
+ deindent;
+ }
+ deindent;
+ pidl "}";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+}
+
+###########################
+# pull a enum
+sub EjsEnumPull($$)
+{
+ my $name = shift;
+ my $d = shift;
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, enum $name *r)\n{";
+ indent;
+ pidl "unsigned e;";
+ pidl "NDR_CHECK(ejs_pull_enum(ejs, v, name, &e));";
+ pidl "*r = e;";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+###########################
+# pull a bitmap
+sub EjsBitmapPull($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $type_fn = $d->{BASE_TYPE};
+ my($type_decl) = Parse::Pidl::Typelist::mapType($d->{BASE_TYPE});
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $type_decl *r)\n{";
+ indent;
+ pidl "return ejs_pull_$type_fn(ejs, v, name, r);";
+ deindent;
+ pidl "}";
+}
+
+
+###########################
+# generate a structure pull
+sub EjsTypedefPull($)
+{
+ my $d = shift;
+ return if (Parse::Pidl::Util::has_property($d, "noejs"));
+ if ($d->{DATA}->{TYPE} eq 'STRUCT') {
+ EjsStructPull($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'UNION') {
+ EjsUnionPull($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'ENUM') {
+ EjsEnumPull($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'BITMAP') {
+ EjsBitmapPull($d->{NAME}, $d->{DATA});
+ } else {
+ warn "Unhandled pull typedef $d->{NAME} of type $d->{DATA}->{TYPE}";
+ }
+}
+
+#####################
+# generate a function
+sub EjsPullFunction($)
+{
+ my $d = shift;
+ my $env = GenerateFunctionInEnv($d);
+ my $name = $d->{NAME};
+
+ pidl "\nstatic NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, struct $name *r)";
+ pidl "{";
+ indent;
+ pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, \"input\"));";
+
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ next unless (grep(/in/, @{$e->{DIRECTION}}));
+ EjsPullElementTop($e, $env);
+ }
+
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+
+###########################
+# push a scalar element
+sub EjsPushScalar($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ $var = get_pointer_to($var);
+ pidl "NDR_CHECK(ejs_push_$e->{TYPE}(ejs, v, $name, $var));";
+}
+
+###########################
+# push a string element
+sub EjsPushString($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ pidl "NDR_CHECK(ejs_push_string(ejs, v, $name, $var));";
+}
+
+###########################
+# push a pointer element
+sub EjsPushPointer($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ pidl "if (NULL == $var) {";
+ indent;
+ pidl "NDR_CHECK(ejs_push_null(ejs, v, $name));";
+ deindent;
+ pidl "} else {";
+ indent;
+ $var = get_value_of($var);
+ EjsPushElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
+ deindent;
+ pidl "}";
+}
+
+###########################
+# push a switch element
+sub EjsPushSwitch($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+ pidl "ejs_set_switch(ejs, $switch_var);";
+ EjsPushElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
+}
+
+
+###########################
+# push an array element
+sub EjsPushArray($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l);
+ if ($pl && $pl->{TYPE} eq "POINTER") {
+ $var = get_pointer_to($var);
+ }
+ my $avar = $var . "[i]";
+ pidl "{";
+ indent;
+ pidl "uint32_t i;";
+ pidl "for (i=0;i<$length;i++) {";
+ indent;
+ pidl "const char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);";
+ EjsPushElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $avar, "id", $env);
+ deindent;
+ pidl "}";
+ pidl "ejs_push_uint32(ejs, v, $name \".length\", &i);";
+ deindent;
+ pidl "}";
+}
+
+################################
+# push a structure/union element
+sub EjsPushElement($$$$$)
+{
+ my ($e, $l, $var, $name, $env) = @_;
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ EjsPushString($e, $l, $var, $name, $env);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ EjsPushArray($e, $l, $var, $name, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ EjsPushScalar($e, $l, $var, $name, $env);
+ } elsif (($l->{TYPE} eq "POINTER")) {
+ EjsPushPointer($e, $l, $var, $name, $env);
+ } elsif (($l->{TYPE} eq "SWITCH")) {
+ EjsPushSwitch($e, $l, $var, $name, $env);
+ } else {
+ pidl "return ejs_panic(ejs, \"unhandled push type $l->{TYPE}\");";
+ }
+}
+
+#############################################
+# push a structure/union element at top level
+sub EjsPushElementTop($$)
+{
+ my $e = shift;
+ my $env = shift;
+ my $l = $e->{LEVELS}[0];
+ my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env);
+ my $name = "\"$e->{NAME}\"";
+ EjsPushElement($e, $l, $var, $name, $env);
+}
+
+###########################
+# push a struct
+sub EjsStructPush($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $env = GenerateStructEnv($d);
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)\n{";
+ indent;
+ pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, name));";
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ EjsPushElementTop($e, $env);
+ }
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+###########################
+# push a union
+sub EjsUnionPush($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $have_default = 0;
+ my $env = GenerateStructEnv($d);
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const union $name *r)\n{";
+ indent;
+ pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, name));";
+ pidl "switch (ejs->switch_var) {";
+ indent;
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ if ($e->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$e->{CASE}:";
+ indent;
+ if ($e->{TYPE} ne "EMPTY") {
+ EjsPushElementTop($e, $env);
+ }
+ pidl "break;";
+ deindent;
+ }
+ if (! $have_default) {
+ pidl "default:";
+ indent;
+ pidl "return ejs_panic(ejs, \"Bad switch value\");";
+ deindent;
+ }
+ deindent;
+ pidl "}";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+}
+
+###########################
+# push a enum
+sub EjsEnumPush($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $v = 0;
+ # put the enum elements in the constants array
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ my $el = $e;
+ chomp $el;
+ if ($el =~ /^(.*)=\s*(.*)\s*$/) {
+ $el = $1;
+ $v = $2;
+ }
+ $constants{$el} = $v;
+ $v++;
+ }
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const enum $name *r)\n{";
+ indent;
+ pidl "unsigned e = *r;";
+ pidl "NDR_CHECK(ejs_push_enum(ejs, v, name, &e));";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+###########################
+# push a bitmap
+sub EjsBitmapPush($$)
+{
+ my $name = shift;
+ my $d = shift;
+ my $type_fn = $d->{BASE_TYPE};
+ my($type_decl) = Parse::Pidl::Typelist::mapType($d->{BASE_TYPE});
+ # put the bitmap elements in the constants array
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ if ($e =~ /^(\w*)\s*(.*)\s*$/) {
+ my $bname = $1;
+ my $v = $2;
+ $constants{$bname} = $v;
+ }
+ }
+ pidl fn_prefix($d);
+ pidl "NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const $type_decl *r)\n{";
+ indent;
+ pidl "return ejs_push_$type_fn(ejs, v, name, r);";
+ deindent;
+ pidl "}";
+}
+
+
+###########################
+# generate a structure push
+sub EjsTypedefPush($)
+{
+ my $d = shift;
+ return if (Parse::Pidl::Util::has_property($d, "noejs"));
+ if ($d->{DATA}->{TYPE} eq 'STRUCT') {
+ EjsStructPush($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'UNION') {
+ EjsUnionPush($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'ENUM') {
+ EjsEnumPush($d->{NAME}, $d->{DATA});
+ } elsif ($d->{DATA}->{TYPE} eq 'BITMAP') {
+ EjsBitmapPush($d->{NAME}, $d->{DATA});
+ } else {
+ warn "Unhandled push typedef $d->{NAME} of type $d->{DATA}->{TYPE}";
+ }
+}
+
+
+#####################
+# generate a function
+sub EjsPushFunction($)
+{
+ my $d = shift;
+ my $env = GenerateFunctionOutEnv($d);
+
+ pidl "\nstatic NTSTATUS ejs_push_$d->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const struct $d->{NAME} *r)";
+ pidl "{";
+ indent;
+ pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, \"output\"));";
+
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ next unless (grep(/out/, @{$e->{DIRECTION}}));
+ EjsPushElementTop($e, $env);
+ }
+
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}\n";
+}
+
+
+#################################
+# generate a ejs mapping function
+sub EjsFunction($)
+{
+ my $d = shift;
+ my $name = $d->{NAME};
+
+ pidl "static int ejs_$name(int eid, int argc, struct MprVar **argv)";
+ pidl "{";
+ indent;
+ pidl "return ejs_rpc_call(eid, argc, argv, \"$name\", (ejs_pull_function_t)ejs_pull_$name, (ejs_push_function_t)ejs_push_$name);";
+ deindent;
+ pidl "}\n";
+}
+
+###################
+# handle a constant
+sub EjsConst($)
+{
+ my $const = shift;
+ $constants{$const->{NAME}} = $const->{VALUE};
+}
+
+#####################################################################
+# parse the interface definitions
+sub EjsInterface($)
+{
+ my($interface) = shift;
+ my @fns = ();
+ my $name = $interface->{NAME};
+
+ %constants = ();
+
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ EjsTypedefPush($d);
+ EjsTypedefPull($d);
+ }
+
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ next if not defined($d->{OPNUM});
+
+ EjsPullFunction($d);
+ EjsPushFunction($d);
+ EjsFunction($d);
+
+ push (@fns, $d->{NAME});
+ }
+
+ foreach my $d (@{$interface->{CONSTS}}) {
+ EjsConst($d);
+ }
+
+ pidl "void setup_ejs_$name(void)";
+ pidl "{";
+ indent;
+ foreach (@fns) {
+ pidl "ejsDefineCFunction(-1, \"dcerpc_$_\", ejs_$_, NULL, MPR_VAR_SCRIPT_HANDLE);";
+ }
+ deindent;
+ pidl "}\n";
+
+ pidl "void setup_ejs_constants_$name(int eid)";
+ pidl "{";
+ indent;
+ foreach my $v (keys %constants) {
+ my $value = $constants{$v};
+ if (substr($value, 0, 1) eq "\"") {
+ pidl "ejs_set_constant_string(eid, \"$v\", $value);";
+ } else {
+ pidl "ejs_set_constant_int(eid, \"$v\", $value);";
+ }
+ }
+ deindent;
+ pidl "}\n";
+
+ pidl "NTSTATUS ejs_init_$name(void)";
+ pidl "{";
+ indent;
+ pidl "return smbcalls_register_ejs(\"$name\", setup_ejs_$name, setup_ejs_constants_$name);";
+ deindent;
+ pidl "}";
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Parse($$)
+{
+ my($ndr,$hdr) = @_;
+
+ my $ejs_hdr = $hdr;
+ $ejs_hdr =~ s/.h$/_ejs.h/;
+ $res = "";
+ pidl "
+/* EJS wrapper functions auto-generated by pidl */
+#include \"includes.h\"
+#include \"lib/ejs/ejs.h\"
+#include \"scripting/ejs/ejsrpc.h\"
+#include \"librpc/gen_ndr/ndr_misc_ejs.h\"
+#include \"$hdr\"
+#include \"$ejs_hdr\"
+
+";
+ foreach my $x (@{$ndr}) {
+ if ($x->{TYPE} eq "INTERFACE") {
+ ($x->{TYPE} eq "INTERFACE") && EjsInterface($x);
+ }
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/EJSHeader.pm b/source4/build/pidl/Parse/Pidl/Samba/EJSHeader.pm
new file mode 100644
index 0000000000..e2472545ef
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/EJSHeader.pm
@@ -0,0 +1,75 @@
+###################################################
+# create C header files for an EJS mapping functions
+# Copyright tridge@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::EJSHeader;
+
+use strict;
+use Parse::Pidl::Typelist;
+
+my($res);
+
+sub pidl ($)
+{
+ $res .= shift;
+}
+
+#####################################################################
+# prototype a typedef
+sub HeaderTypedefProto($)
+{
+ my $d = shift;
+ my $name = $d->{NAME};
+
+ return unless Parse::Pidl::Util::has_property($d, "public");
+
+ my $type_decl = Parse::Pidl::Typelist::mapType($name);
+
+ pidl "NTSTATUS ejs_push_$d->{NAME}(struct ejs_rpc *, struct MprVar *, const char *, const $type_decl *);\n";
+ pidl "NTSTATUS ejs_pull_$d->{NAME}(struct ejs_rpc *, struct MprVar *, const char *, $type_decl *);\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub HeaderInterface($)
+{
+ my($interface) = shift;
+
+ my $count = 0;
+
+ pidl "#ifndef _HEADER_EJS_$interface->{NAME}\n";
+ pidl "#define _HEADER_EJS_$interface->{NAME}\n\n";
+
+ if (defined $interface->{PROPERTIES}->{depends}) {
+ my @d = split / /, $interface->{PROPERTIES}->{depends};
+ foreach my $i (@d) {
+ pidl "#include \"librpc/gen_ndr/ndr_$i\_ejs\.h\"\n";
+ }
+ }
+
+ pidl "\n";
+
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ HeaderTypedefProto($d);
+ }
+
+ pidl "\n";
+ pidl "#endif /* _HEADER_EJS_$interface->{NAME} */\n";
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Parse($)
+{
+ my($idl) = shift;
+
+ $res = "";
+ pidl "/* header auto-generated by pidl */\n\n";
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") && HeaderInterface($x);
+ }
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/NDR/Client.pm b/source4/build/pidl/Parse/Pidl/Samba/NDR/Client.pm
new file mode 100644
index 0000000000..126dbc3ba9
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/NDR/Client.pm
@@ -0,0 +1,99 @@
+###################################################
+# client calls generator
+# Copyright tridge@samba.org 2003
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::NDR::Client;
+
+use strict;
+
+my($res);
+
+#####################################################################
+# parse a function
+sub ParseFunction($$)
+{
+ my ($interface, $fn) = @_;
+ my $name = $fn->{NAME};
+ my $uname = uc $name;
+
+ $res .= "
+struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
+{
+ if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
+ NDR_PRINT_IN_DEBUG($name, r);
+ }
+
+ return dcerpc_ndr_request_send(p, NULL, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
+}
+
+NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
+{
+ struct rpc_request *req;
+ NTSTATUS status;
+
+ req = dcerpc_$name\_send(p, mem_ctx, r);
+ if (req == NULL) return NT_STATUS_NO_MEMORY;
+
+ status = dcerpc_ndr_request_recv(req);
+
+ if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
+ NDR_PRINT_OUT_DEBUG($name, r);
+ }
+";
+
+ if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") {
+ $res .= "\tif (NT_STATUS_IS_OK(status)) status = r->out.result;\n";
+ }
+ $res .=
+"
+ return status;
+}
+";
+}
+
+my %done;
+
+#####################################################################
+# parse the interface definitions
+sub ParseInterface($)
+{
+ my($interface) = shift;
+ $res .= "/* $interface->{NAME} - client functions generated by pidl */\n\n";
+
+ foreach my $fn (@{$interface->{FUNCTIONS}}) {
+ next if not defined($fn->{OPNUM});
+ next if defined($done{$fn->{NAME}});
+ ParseFunction($interface, $fn);
+ $done{$fn->{NAME}} = 1;
+ }
+
+ return $res;
+}
+
+sub Parse($$)
+{
+ my($ndr) = shift;
+ my($filename) = shift;
+
+ my $h_filename = $filename;
+ $res = "";
+
+ if ($h_filename =~ /(.*)\.c/) {
+ $h_filename = "$1.h";
+ }
+
+ $res .= "/* client functions auto-generated by pidl */\n";
+ $res .= "\n";
+ $res .= "#include \"includes.h\"\n";
+ $res .= "#include \"$h_filename\"\n";
+ $res .= "\n";
+
+ foreach my $x (@{$ndr}) {
+ ($x->{TYPE} eq "INTERFACE") && ParseInterface($x);
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/NDR/Header.pm b/source4/build/pidl/Parse/Pidl/Samba/NDR/Header.pm
new file mode 100644
index 0000000000..d15e9bfbcb
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/NDR/Header.pm
@@ -0,0 +1,472 @@
+###################################################
+# create C header files for an IDL structure
+# Copyright tridge@samba.org 2000
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::NDR::Header;
+
+use strict;
+use Parse::Pidl::Typelist;
+use Parse::Pidl::Samba::NDR::Parser;
+
+my($res);
+my($tab_depth);
+
+sub pidl ($)
+{
+ $res .= shift;
+}
+
+sub tabs()
+{
+ for (my($i)=0; $i < $tab_depth; $i++) {
+ pidl "\t";
+ }
+}
+
+#####################################################################
+# parse a properties list
+sub HeaderProperties($$)
+{
+ my($props,$ignores) = @_;
+ my $ret = "";
+
+ foreach my $d (keys %{$props}) {
+ next if (grep(/^$d$/, @$ignores));
+ if($props->{$d} ne "1") {
+ $ret.= "$d($props->{$d}),";
+ } else {
+ $ret.="$d,";
+ }
+ }
+
+ if ($ret) {
+ pidl "/* [" . substr($ret, 0, -1) . "] */";
+ }
+}
+
+#####################################################################
+# parse a structure element
+sub HeaderElement($)
+{
+ my($element) = shift;
+
+ pidl tabs();
+ HeaderType($element, $element->{TYPE}, "");
+ pidl " ";
+ my $prefix = "";
+ my $postfix = "";
+ foreach my $l (@{$element->{LEVELS}})
+ {
+ if (($l->{TYPE} eq "POINTER")) {
+ my $nl = Parse::Pidl::NDR::GetNextLevel($element, $l);
+ $nl = Parse::Pidl::NDR::GetNextLevel($element, $nl) if ($nl->{TYPE} eq "SUBCONTEXT");
+ next if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}));
+ $prefix .= "*";
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $pl = Parse::Pidl::NDR::GetPrevLevel($element, $l);
+ next if ($pl and $pl->{TYPE} eq "POINTER");
+
+ if ($l->{IS_FIXED}) {
+ $postfix .= "[$l->{SIZE_IS}]";
+ } else {
+ $prefix .= "*";
+ }
+ } elsif ($l->{TYPE} eq "DATA") {
+ pidl "$prefix$element->{NAME}$postfix";
+ }
+ }
+
+ if (defined $element->{ARRAY_LEN}[0] && Parse::Pidl::Util::is_constant($element->{ARRAY_LEN}[0])) {
+ pidl "[$element->{ARRAY_LEN}[0]]";
+ }
+ pidl ";";
+ if (defined $element->{PROPERTIES}) {
+ HeaderProperties($element->{PROPERTIES}, ["in", "out"]);
+ }
+ pidl "\n";
+}
+
+#####################################################################
+# parse a struct
+sub HeaderStruct($$)
+{
+ my($struct,$name) = @_;
+ pidl "\nstruct $name {\n";
+ $tab_depth++;
+ my $el_count=0;
+ if (defined $struct->{ELEMENTS}) {
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ HeaderElement($e);
+ $el_count++;
+ }
+ }
+ if ($el_count == 0) {
+ # some compilers can't handle empty structures
+ pidl "\tchar _empty_;\n";
+ }
+ $tab_depth--;
+ pidl "}";
+ if (defined $struct->{PROPERTIES}) {
+ HeaderProperties($struct->{PROPERTIES}, []);
+ }
+}
+
+#####################################################################
+# parse a enum
+sub HeaderEnum($$)
+{
+ my($enum,$name) = @_;
+ my $first = 1;
+
+ if (not Parse::Pidl::Util::useUintEnums()) {
+ pidl "\nenum $name {\n";
+ $tab_depth++;
+ foreach my $e (@{$enum->{ELEMENTS}}) {
+ unless ($first) { pidl ",\n"; }
+ $first = 0;
+ tabs();
+ pidl $e;
+ }
+ pidl "\n";
+ $tab_depth--;
+ pidl "}";
+ } else {
+ my $count = 0;
+ pidl "\nenum $name { __donnot_use_enum_$name=0x7FFFFFFF};\n";
+ my $with_val = 0;
+ my $without_val = 0;
+ foreach my $e (@{$enum->{ELEMENTS}}) {
+ my $t = "$e";
+ my $name;
+ my $value;
+ if ($t =~ /(.*)=(.*)/) {
+ $name = $1;
+ $value = $2;
+ $with_val = 1;
+ die ("you can't mix enum member with values and without values when using --uint-enums!")
+ unless ($without_val == 0);
+ } else {
+ $name = $t;
+ $value = $count++;
+ $without_val = 1;
+ die ("you can't mix enum member with values and without values when using --uint-enums!")
+ unless ($with_val == 0);
+ }
+ pidl "#define $name ( $value )\n";
+ }
+ pidl "\n";
+ }
+}
+
+#####################################################################
+# parse a bitmap
+sub HeaderBitmap($$)
+{
+ my($bitmap,$name) = @_;
+
+ pidl "\n/* bitmap $name */\n";
+
+ foreach my $e (@{$bitmap->{ELEMENTS}})
+ {
+ pidl "#define $e\n";
+ }
+
+ pidl "\n";
+}
+
+#####################################################################
+# parse a union
+sub HeaderUnion($$)
+{
+ my($union,$name) = @_;
+ my %done = ();
+
+ pidl "\nunion $name {\n";
+ $tab_depth++;
+ foreach my $e (@{$union->{ELEMENTS}}) {
+ if ($e->{TYPE} ne "EMPTY") {
+ if (! defined $done{$e->{NAME}}) {
+ HeaderElement($e);
+ }
+ $done{$e->{NAME}} = 1;
+ }
+ }
+ $tab_depth--;
+ pidl "}";
+
+ if (defined $union->{PROPERTIES}) {
+ HeaderProperties($union->{PROPERTIES}, []);
+ }
+}
+
+#####################################################################
+# parse a type
+sub HeaderType($$$)
+{
+ my($e,$data,$name) = @_;
+ if (ref($data) eq "HASH") {
+ ($data->{TYPE} eq "ENUM") && HeaderEnum($data, $name);
+ ($data->{TYPE} eq "BITMAP") && HeaderBitmap($data, $name);
+ ($data->{TYPE} eq "STRUCT") && HeaderStruct($data, $name);
+ ($data->{TYPE} eq "UNION") && HeaderUnion($data, $name);
+ return;
+ }
+
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ pidl "const char";
+ } else {
+ pidl Parse::Pidl::Typelist::mapType($e->{TYPE});
+ }
+}
+
+#####################################################################
+# parse a typedef
+sub HeaderTypedef($)
+{
+ my($typedef) = shift;
+ HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME});
+ pidl ";\n" unless ($typedef->{DATA}->{TYPE} eq "BITMAP");
+}
+
+#####################################################################
+# prototype a typedef
+sub HeaderTypedefProto($)
+{
+ my($d) = shift;
+
+ my $tf = Parse::Pidl::Samba::NDR::Parser::get_typefamily($d->{DATA}{TYPE});
+
+ if (Parse::Pidl::Util::has_property($d, "gensize")) {
+ my $size_args = $tf->{SIZE_FN_ARGS}->($d);
+ pidl "size_t ndr_size_$d->{NAME}($size_args);\n";
+ }
+
+ return unless Parse::Pidl::Util::has_property($d, "public");
+
+ my $pull_args = $tf->{PULL_FN_ARGS}->($d);
+ my $push_args = $tf->{PUSH_FN_ARGS}->($d);
+ my $print_args = $tf->{PRINT_FN_ARGS}->($d);
+ unless (Parse::Pidl::Util::has_property($d, "nopush")) {
+ pidl "NTSTATUS ndr_push_$d->{NAME}($push_args);\n";
+ }
+ unless (Parse::Pidl::Util::has_property($d, "nopull")) {
+ pidl "NTSTATUS ndr_pull_$d->{NAME}($pull_args);\n";
+ }
+ unless (Parse::Pidl::Util::has_property($d, "noprint")) {
+ pidl "void ndr_print_$d->{NAME}($print_args);\n";
+ }
+}
+
+#####################################################################
+# parse a const
+sub HeaderConst($)
+{
+ my($const) = shift;
+ if (!defined($const->{ARRAY_LEN}[0])) {
+ pidl "#define $const->{NAME}\t( $const->{VALUE} )\n";
+ } else {
+ pidl "#define $const->{NAME}\t $const->{VALUE}\n";
+ }
+}
+
+#####################################################################
+# parse a function
+sub HeaderFunctionInOut($$)
+{
+ my($fn,$prop) = @_;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (Parse::Pidl::Util::has_property($e, $prop)) {
+ HeaderElement($e);
+ }
+ }
+}
+
+#####################################################################
+# determine if we need an "in" or "out" section
+sub HeaderFunctionInOut_needed($$)
+{
+ my($fn,$prop) = @_;
+
+ if ($prop eq "out" && $fn->{RETURN_TYPE}) {
+ return 1;
+ }
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (Parse::Pidl::Util::has_property($e, $prop)) {
+ return 1;
+ }
+ }
+
+ return undef;
+}
+
+my %headerstructs = ();
+
+#####################################################################
+# parse a function
+sub HeaderFunction($)
+{
+ my($fn) = shift;
+
+ return if ($headerstructs{$fn->{NAME}});
+
+ $headerstructs{$fn->{NAME}} = 1;
+
+ pidl "\nstruct $fn->{NAME} {\n";
+ $tab_depth++;
+ my $needed = 0;
+
+ if (HeaderFunctionInOut_needed($fn, "in")) {
+ tabs();
+ pidl "struct {\n";
+ $tab_depth++;
+ HeaderFunctionInOut($fn, "in");
+ $tab_depth--;
+ tabs();
+ pidl "} in;\n\n";
+ $needed++;
+ }
+
+ if (HeaderFunctionInOut_needed($fn, "out")) {
+ tabs();
+ pidl "struct {\n";
+ $tab_depth++;
+ HeaderFunctionInOut($fn, "out");
+ if ($fn->{RETURN_TYPE}) {
+ tabs();
+ pidl Parse::Pidl::Typelist::mapType($fn->{RETURN_TYPE}) . " result;\n";
+ }
+ $tab_depth--;
+ tabs();
+ pidl "} out;\n\n";
+ $needed++;
+ }
+
+ if (! $needed) {
+ # sigh - some compilers don't like empty structures
+ tabs();
+ pidl "int _dummy_element;\n";
+ }
+
+ $tab_depth--;
+ pidl "};\n\n";
+}
+
+#####################################################################
+# output prototypes for a IDL function
+sub HeaderFnProto($$)
+{
+ my ($interface,$fn) = @_;
+ my $name = $fn->{NAME};
+
+ pidl "void ndr_print_$name(struct ndr_print *ndr, const char *name, int flags, const struct $name *r);\n";
+
+ if (defined($fn->{OPNUM})) {
+ pidl "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
+ pidl "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r);\n";
+ }
+
+ return unless Parse::Pidl::Util::has_property($fn, "public");
+
+ pidl "NTSTATUS ndr_push_$name(struct ndr_push *ndr, int flags, const struct $name *r);\n";
+ pidl "NTSTATUS ndr_pull_$name(struct ndr_pull *ndr, int flags, struct $name *r);\n";
+
+ pidl "\n";
+}
+
+#####################################################################
+# parse the interface definitions
+sub HeaderInterface($)
+{
+ my($interface) = shift;
+
+ my $count = 0;
+
+ pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
+ pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
+
+ if (defined $interface->{PROPERTIES}->{depends}) {
+ my @d = split / /, $interface->{PROPERTIES}->{depends};
+ foreach my $i (@d) {
+ pidl "#include \"librpc/gen_ndr/ndr_$i\.h\"\n";
+ }
+ }
+
+ if (defined $interface->{PROPERTIES}->{uuid}) {
+ my $name = uc $interface->{NAME};
+ pidl "#define DCERPC_$name\_UUID " .
+ Parse::Pidl::Util::make_str($interface->{PROPERTIES}->{uuid}) . "\n";
+
+ if(!defined $interface->{PROPERTIES}->{version}) { $interface->{PROPERTIES}->{version} = "0.0"; }
+ pidl "#define DCERPC_$name\_VERSION $interface->{PROPERTIES}->{version}\n";
+
+ pidl "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n";
+
+ if(!defined $interface->{PROPERTIES}->{helpstring}) { $interface->{PROPERTIES}->{helpstring} = "NULL"; }
+ pidl "#define DCERPC_$name\_HELPSTRING $interface->{PROPERTIES}->{helpstring}\n";
+
+ pidl "\nextern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n";
+ pidl "NTSTATUS dcerpc_server_$interface->{NAME}_init(void);\n\n";
+ }
+
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ next if not defined($d->{OPNUM});
+ my $u_name = uc $d->{NAME};
+ pidl "#define DCERPC_$u_name (";
+
+ if (defined($interface->{BASE})) {
+ pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
+ }
+
+ if ($d->{OPNUM} != $count) {
+ die ("Function ".$d->{NAME}." has: wrong opnum [".$d->{OPNUM}."] should be [".$count."]");
+ }
+
+ pidl sprintf("0x%02x", $count) . ")\n";
+ $count++;
+ }
+
+ pidl "\n#define DCERPC_" . uc $interface->{NAME} . "_CALL_COUNT (";
+
+ if (defined($interface->{BASE})) {
+ pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT + ";
+ }
+
+ pidl "$count)\n\n";
+
+ foreach my $d (@{$interface->{CONSTS}}) {
+ HeaderConst($d);
+ }
+
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ HeaderTypedef($d);
+ HeaderTypedefProto($d);
+ }
+
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ HeaderFunction($d);
+ HeaderFnProto($interface, $d);
+ }
+
+ pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Parse($)
+{
+ my($idl) = shift;
+ $tab_depth = 0;
+
+ $res = "";
+ pidl "/* header auto-generated by pidl */\n\n";
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") && HeaderInterface($x);
+ }
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/NDR/Parser.pm b/source4/build/pidl/Parse/Pidl/Samba/NDR/Parser.pm
new file mode 100644
index 0000000000..21e1449067
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/NDR/Parser.pm
@@ -0,0 +1,2230 @@
+###################################################
+# Samba4 NDR parser generator for IDL structures
+# Copyright tridge@samba.org 2000-2003
+# Copyright tpot@samba.org 2001
+# Copyright jelmer@samba.org 2004-2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::NDR::Parser;
+
+use strict;
+use Parse::Pidl::Typelist;
+use Parse::Pidl::NDR;
+
+# list of known types
+my %typefamily;
+
+sub get_typefamily($)
+{
+ my $n = shift;
+ return $typefamily{$n};
+}
+
+sub append_prefix($$)
+{
+ my ($e, $var_name) = @_;
+ my $pointers = 0;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER") {
+ $pointers++;
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ if (($pointers == 0) and
+ (not $l->{IS_FIXED}) and
+ (not $l->{IS_INLINE})) {
+ return get_value_of($var_name);
+ }
+ } elsif ($l->{TYPE} eq "DATA") {
+ if (Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ return get_value_of($var_name) unless ($pointers);
+ }
+ }
+ }
+
+ return $var_name;
+}
+
+sub is_scalar_array($$)
+{
+ my ($e,$l) = @_;
+
+ return 0 if ($l->{TYPE} ne "ARRAY");
+
+ my $nl = Parse::Pidl::NDR::GetNextLevel($e,$l);
+ return (($nl->{TYPE} eq "DATA") and
+ (Parse::Pidl::Typelist::is_scalar($nl->{DATA_TYPE})));
+}
+
+sub get_pointer_to($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\*(.*)$/) {
+ return $1;
+ } elsif ($var_name =~ /^\&(.*)$/) {
+ return "&($var_name)";
+ } else {
+ return "&$var_name";
+ }
+}
+
+sub get_value_of($)
+{
+ my $var_name = shift;
+
+ if ($var_name =~ /^\&(.*)$/) {
+ return $1;
+ } else {
+ return "*$var_name";
+ }
+}
+
+my $res = "";
+my $tabs = "";
+sub pidl($)
+{
+ my $d = shift;
+ if ($d) {
+ $res .= $tabs;
+ $res .= $d;
+ }
+ $res .="\n";
+}
+
+sub indent()
+{
+ $tabs .= "\t";
+}
+
+sub deindent()
+{
+ $tabs = substr($tabs, 0, -1);
+}
+
+#####################################################################
+# check that a variable we get from ParseExpr isn't a null pointer
+sub check_null_pointer($)
+{
+ my $size = shift;
+ if ($size =~ /^\*/) {
+ my $size2 = substr($size, 1);
+ pidl "if ($size2 == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;";
+ }
+}
+
+#####################################################################
+# check that a variable we get from ParseExpr isn't a null pointer
+# void return varient
+sub check_null_pointer_void($)
+{
+ my $size = shift;
+ if ($size =~ /^\*/) {
+ my $size2 = substr($size, 1);
+ pidl "if ($size2 == NULL) return;";
+ }
+}
+
+#####################################################################
+# work out is a parse function should be declared static or not
+sub fn_prefix($)
+{
+ my $fn = shift;
+
+ return "" if (Parse::Pidl::Util::has_property($fn, "public"));
+ return "static ";
+}
+
+###################################################################
+# setup any special flags for an element or structure
+sub start_flags($)
+{
+ my $e = shift;
+ my $flags = Parse::Pidl::Util::has_property($e, "flag");
+ if (defined $flags) {
+ pidl "{";
+ indent;
+ pidl "uint32_t _flags_save_$e->{TYPE} = ndr->flags;";
+ pidl "ndr_set_flags(&ndr->flags, $flags);";
+ }
+}
+
+###################################################################
+# end any special flags for an element or structure
+sub end_flags($)
+{
+ my $e = shift;
+ my $flags = Parse::Pidl::Util::has_property($e, "flag");
+ if (defined $flags) {
+ pidl "ndr->flags = _flags_save_$e->{TYPE};";
+ deindent;
+ pidl "}";
+ }
+}
+
+sub GenerateStructEnv($)
+{
+ my $x = shift;
+ my %env;
+
+ foreach my $e (@{$x->{ELEMENTS}}) {
+ $env{$e->{NAME}} = "r->$e->{NAME}";
+ }
+
+ $env{"this"} = "r";
+
+ return \%env;
+}
+
+sub GenerateFunctionInEnv($)
+{
+ my $fn = shift;
+ my %env;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep (/in/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->in.$e->{NAME}";
+ }
+ }
+
+ return \%env;
+}
+
+sub GenerateFunctionOutEnv($)
+{
+ my $fn = shift;
+ my %env;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep (/out/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->out.$e->{NAME}";
+ } elsif (grep (/in/, @{$e->{DIRECTION}})) {
+ $env{$e->{NAME}} = "r->in.$e->{NAME}";
+ }
+ }
+
+ return \%env;
+}
+
+#####################################################################
+# parse the data of an array - push side
+sub ParseArrayPushHeader($$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$env) = @_;
+
+ if ($l->{IS_CONFORMANT} or $l->{IS_VARYING}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ my $size;
+ my $length;
+
+ if ($l->{IS_ZERO_TERMINATED}) {
+ $size = $length = "ndr_string_length($var_name, sizeof(*$var_name))";
+ } else {
+ $size = Parse::Pidl::Util::ParseExpr($l->{SIZE_IS}, $env);
+ $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ }
+
+ if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
+ pidl "NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $size));";
+ }
+
+ if ($l->{IS_VARYING}) {
+ pidl "NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, 0));";
+ pidl "NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $length));";
+ }
+
+ return $length;
+}
+
+#####################################################################
+# parse an array - pull side
+sub ParseArrayPullHeader($$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$env) = @_;
+
+ if ($l->{IS_CONFORMANT} or $l->{IS_VARYING}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ my $length;
+ my $size;
+
+ if ($l->{IS_CONFORMANT}) {
+ $length = $size = "ndr_get_array_size($ndr, " . get_pointer_to($var_name) . ")";
+ } elsif ($l->{IS_ZERO_TERMINATED}) { # Noheader arrays
+ $length = $size = "ndr_get_string_size($ndr, sizeof(*$var_name))";
+ } else {
+ $length = $size = Parse::Pidl::Util::ParseExpr($l->{SIZE_IS}, $env);
+ }
+
+ if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
+ pidl "NDR_CHECK(ndr_pull_array_size(ndr, " . get_pointer_to($var_name) . "));";
+ }
+
+
+ if ($l->{IS_VARYING}) {
+ pidl "NDR_CHECK(ndr_pull_array_length($ndr, " . get_pointer_to($var_name) . "));";
+ $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
+ }
+
+ check_null_pointer($length);
+
+ if ($length ne $size) {
+ pidl "if ($length > $size) {";
+ indent;
+ pidl "return ndr_pull_error($ndr, NDR_ERR_ARRAY_SIZE, \"Bad array size %u should exceed array length %u\", $size, $length);";
+ deindent;
+ pidl "}";
+ }
+
+ if ($l->{IS_CONFORMANT} and not $l->{IS_ZERO_TERMINATED}) {
+ my $size = Parse::Pidl::Util::ParseExpr($l->{SIZE_IS}, $env);
+ check_null_pointer($size);
+ pidl "NDR_CHECK(ndr_check_array_size(ndr, (void*)" . get_pointer_to($var_name) . ", $size));";
+ }
+
+ if ($l->{IS_VARYING} and not $l->{IS_ZERO_TERMINATED}) {
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ check_null_pointer($length);
+ pidl "NDR_CHECK(ndr_check_array_length(ndr, (void*)" . get_pointer_to($var_name) . ", $length));";
+ }
+
+ if (!$l->{IS_FIXED}) {
+ AllocateArrayLevel($e,$l,$ndr,$env,$size);
+ }
+
+ return $length;
+}
+
+sub compression_alg($$)
+{
+ my ($e,$l) = @_;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return $alg;
+}
+
+sub compression_clen($$$)
+{
+ my ($e,$l,$env) = @_;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return Parse::Pidl::Util::ParseExpr($clen, $env);
+}
+
+sub compression_dlen($$$)
+{
+ my ($e,$l,$env) = @_;
+ my $compression = $l->{COMPRESSION};
+ my ($alg, $clen, $dlen) = split(/ /, $compression);
+
+ return Parse::Pidl::Util::ParseExpr($dlen, $env);
+}
+
+sub ParseCompressionPushStart($$$)
+{
+ my ($e,$l,$ndr) = @_;
+ my $comndr = "$ndr\_compressed";
+
+ pidl "{";
+ indent;
+ pidl "struct ndr_push *$comndr;";
+ pidl "";
+ pidl "$comndr = ndr_push_init_ctx($ndr);";
+ pidl "if (!$comndr) return NT_STATUS_NO_MEMORY;";
+ pidl "$comndr->flags = $ndr->flags;";
+ pidl "";
+
+ return $comndr;
+}
+
+sub ParseCompressionPushEnd($$$)
+{
+ my ($e,$l,$ndr) = @_;
+ my $comndr = "$ndr\_compressed";
+ my $alg = compression_alg($e, $l);
+
+ pidl "NDR_CHECK(ndr_push_compression($ndr, $comndr, $alg));";
+ deindent;
+ pidl "}";
+}
+
+sub ParseCompressionPullStart($$$$)
+{
+ my ($e,$l,$ndr,$env) = @_;
+ my $comndr = "$ndr\_compressed";
+ my $alg = compression_alg($e, $l);
+ my $dlen = compression_dlen($e, $l, $env);
+
+ pidl "{";
+ indent;
+ pidl "struct ndr_pull *$comndr;";
+ pidl "NDR_ALLOC($ndr, $comndr);";
+ pidl "NDR_CHECK(ndr_pull_compression($ndr, $comndr, $alg, $dlen));";
+
+ return $comndr;
+}
+
+sub ParseCompressionPullEnd($$$)
+{
+ my ($e,$l,$ndr) = @_;
+ my $comndr = "$ndr\_compressed";
+
+ deindent;
+ pidl "}";
+}
+
+sub ParseObfuscationPushStart($$)
+{
+ my ($e,$ndr) = @_;
+
+ # nothing to do here
+
+ return $ndr;
+}
+
+sub ParseObfuscationPushEnd($$)
+{
+ my ($e,$ndr) = @_;
+ my $obfuscation = Parse::Pidl::Util::has_property($e, "obfuscation");
+
+ pidl "NDR_CHECK(ndr_push_obfuscation($ndr, $obfuscation));";
+}
+
+sub ParseObfuscationPullStart($$)
+{
+ my ($e,$ndr) = @_;
+ my $obfuscation = Parse::Pidl::Util::has_property($e, "obfuscation");
+
+ pidl "NDR_CHECK(ndr_pull_obfuscation($ndr, $obfuscation));";
+
+ return $ndr;
+}
+
+sub ParseObfuscationPullEnd($$)
+{
+ my ($e,$ndr) = @_;
+
+ # nothing to do here
+}
+
+sub ParseSubcontextPushStart($$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$ndr_flags) = @_;
+ my $retndr = "_ndr_$e->{NAME}";
+
+ pidl "{";
+ indent;
+ pidl "struct ndr_push *$retndr;";
+ pidl "";
+ pidl "$retndr = ndr_push_init_ctx($ndr);";
+ pidl "if (!$retndr) return NT_STATUS_NO_MEMORY;";
+ pidl "$retndr->flags = $ndr->flags;";
+ pidl "";
+
+ if (defined $l->{COMPRESSION}) {
+ $retndr = ParseCompressionPushStart($e, $l, $retndr);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ $retndr = ParseObfuscationPushStart($e, $retndr);
+ }
+
+ return $retndr;
+}
+
+sub ParseSubcontextPushEnd($$$$)
+{
+ my ($e,$l,$ndr_flags,$env) = @_;
+ my $ndr = "_ndr_$e->{NAME}";
+ my $subcontext_size = Parse::Pidl::Util::ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+
+ if (defined $l->{COMPRESSION}) {
+ ParseCompressionPushEnd($e, $l, $ndr);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ ParseObfuscationPushEnd($e, $ndr);
+ }
+
+ pidl "NDR_CHECK(ndr_push_subcontext_header(ndr, $l->{HEADER_SIZE}, $subcontext_size, $ndr));";
+ pidl "NDR_CHECK(ndr_push_bytes(ndr, $ndr->data, $ndr->offset));";
+ deindent;
+ pidl "}";
+}
+
+sub ParseSubcontextPullStart($$$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$ndr_flags,$env) = @_;
+ my $retndr = "_ndr_$e->{NAME}";
+ my $subcontext_size = Parse::Pidl::Util::ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+
+ pidl "{";
+ indent;
+ pidl "struct ndr_pull *$retndr;";
+ pidl "NDR_ALLOC(ndr, $retndr);";
+ pidl "NDR_CHECK(ndr_pull_subcontext_header($ndr, $l->{HEADER_SIZE}, $subcontext_size, $retndr));";
+
+ if (defined $l->{COMPRESSION}) {
+ $retndr = ParseCompressionPullStart($e, $l, $retndr, $env);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ $retndr = ParseObfuscationPullStart($e, $retndr);
+ }
+
+ return ($retndr,$var_name);
+}
+
+sub ParseSubcontextPullEnd($$$)
+{
+ my ($e,$l,$env) = @_;
+ my $ndr = "_ndr_$e->{NAME}";
+
+ if (defined $l->{COMPRESSION}) {
+ ParseCompressionPullEnd($e, $l, $ndr);
+ }
+
+ if (defined $l->{OBFUSCATION}) {
+ ParseObfuscationPullEnd($e, $ndr);
+ }
+
+ my $advance;
+ if (defined($l->{SUBCONTEXT_SIZE}) and ($l->{SUBCONTEXT_SIZE} ne "-1")) {
+ $advance = Parse::Pidl::Util::ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+ } elsif ($l->{HEADER_SIZE}) {
+ $advance = "$ndr->data_size";
+ } else {
+ $advance = "$ndr->offset";
+ }
+ pidl "NDR_CHECK(ndr_pull_advance(ndr, $advance));";
+ deindent;
+ pidl "}";
+}
+
+sub ParseElementPushLevel
+{
+ my ($e,$l,$ndr,$var_name,$env,$primitives,$deferred) = @_;
+
+ my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred);
+
+ if (defined($ndr_flags)) {
+ if ($l->{TYPE} eq "SUBCONTEXT") {
+ $ndr = ParseSubcontextPushStart($e, $l, $ndr, $var_name, $ndr_flags);
+ ParseElementPushLevel($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $ndr, $var_name, $env, 1, 1);
+ ParseSubcontextPushEnd($e, $l, $ndr_flags, $env);
+ } elsif ($l->{TYPE} eq "POINTER") {
+ ParsePtrPush($e, $l, $var_name);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $length = ParseArrayPushHeader($e, $l, $ndr, $var_name, $env);
+ # Allow speedups for arrays of scalar types
+ if (is_scalar_array($e,$l)) {
+ if ($l->{IS_CONFORMANT} or $l->{IS_VARYING}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
+
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ pidl "NDR_CHECK(ndr_push_charset($ndr, $ndr_flags, $var_name, $length, sizeof(" . Parse::Pidl::Typelist::mapType($nl->{DATA_TYPE}) . "), CH_$e->{PROPERTIES}->{charset}));";
+ } else {
+ pidl "NDR_CHECK(ndr_push_array_$nl->{DATA_TYPE}($ndr, $ndr_flags, $var_name, $length));";
+ }
+ return;
+ }
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseSwitchPush($e, $l, $ndr, $var_name, $ndr_flags, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ ParseDataPush($e, $l, $ndr, $var_name, $ndr_flags);
+ }
+ }
+
+ if ($l->{TYPE} eq "POINTER" and $deferred) {
+ if ($l->{POINTER_TYPE} ne "ref") {
+ pidl "if ($var_name) {";
+ indent;
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "NDR_CHECK(ndr_push_relative_ptr2(ndr, $var_name));";
+ }
+ }
+ $var_name = get_value_of($var_name);
+ ParseElementPushLevel($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $ndr, $var_name, $env, $primitives, $deferred);
+
+ if ($l->{POINTER_TYPE} ne "ref") {
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "ARRAY" and not is_scalar_array($e,$l)) {
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
+
+ $var_name = $var_name . "[$counter]";
+
+ if ($l->{IS_VARYING} or $l->{IS_CONFORMANT}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ if (($primitives and not $l->{IS_DEFERRED}) or ($deferred and $l->{IS_DEFERRED})) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementPushLevel($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $ndr, $var_name, $env, 1, 0);
+ deindent;
+ pidl "}";
+ }
+
+ if ($deferred and Parse::Pidl::NDR::ContainsDeferred($e, $l)) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementPushLevel($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $ndr, $var_name, $env, 0, 1);
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseElementPushLevel($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $ndr, $var_name, $env, $primitives, $deferred);
+ }
+}
+
+#####################################################################
+# parse scalars in a structure element
+sub ParseElementPush($$$$$$)
+{
+ my ($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+ my $subndr = undef;
+
+ my $var_name = $var_prefix.$e->{NAME};
+
+ $var_name = append_prefix($e, $var_name);
+
+ return unless $primitives or ($deferred and Parse::Pidl::NDR::ContainsDeferred($e, $e->{LEVELS}[0]));
+
+ start_flags($e);
+
+ if (my $value = Parse::Pidl::Util::has_property($e, "value")) {
+ $var_name = Parse::Pidl::Util::ParseExpr($value, $env);
+ }
+
+ ParseElementPushLevel($e, $e->{LEVELS}[0], $ndr, $var_name, $env, $primitives, $deferred);
+
+ end_flags($e);
+}
+
+#####################################################################
+# parse a pointer in a struct element or function
+sub ParsePtrPush($$$)
+{
+ my ($e,$l,$var_name) = @_;
+
+ if ($l->{POINTER_TYPE} eq "ref") {
+ if ($l->{LEVEL} eq "EMBEDDED") {
+ pidl "NDR_CHECK(ndr_push_ref_ptr(ndr, $var_name));";
+ } else {
+ check_null_pointer(get_value_of($var_name));
+ }
+ } elsif ($l->{POINTER_TYPE} eq "relative") {
+ pidl "NDR_CHECK(ndr_push_relative_ptr1(ndr, $var_name));";
+ } elsif ($l->{POINTER_TYPE} eq "unique") {
+ pidl "NDR_CHECK(ndr_push_unique_ptr(ndr, $var_name));";
+ } elsif ($l->{POINTER_TYPE} eq "sptr") {
+ pidl "NDR_CHECK(ndr_push_sptr_ptr(ndr, $var_name));";
+ } else {
+ die("Unhandled pointer type $l->{POINTER_TYPE}");
+ }
+}
+
+#####################################################################
+# print scalars in a structure element
+sub ParseElementPrint($$$)
+{
+ my($e,$var_name,$env) = @_;
+
+ $var_name = append_prefix($e, $var_name);
+ return if (Parse::Pidl::Util::has_property($e, "noprint"));
+
+ if (my $value = Parse::Pidl::Util::has_property($e, "value")) {
+ $var_name = "(ndr->flags & LIBNDR_PRINT_SET_VALUES)?" . Parse::Pidl::Util::ParseExpr($value,$env) . ":$var_name";
+ }
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER") {
+ pidl "ndr_print_ptr(ndr, \"$e->{NAME}\", $var_name);";
+ pidl "ndr->depth++;";
+ if ($l->{POINTER_TYPE} ne "ref") {
+ pidl "if ($var_name) {";
+ indent;
+ }
+ $var_name = get_value_of($var_name);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $length;
+
+ if (is_scalar_array($e, $l) and ($l->{IS_CONFORMANT} or $l->{IS_VARYING})){
+ $var_name = get_pointer_to($var_name);
+ }
+
+ if ($l->{IS_ZERO_TERMINATED}) {
+ $length = "ndr_string_length($var_name, sizeof(*$var_name))";
+ } else {
+ $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ }
+
+ if (is_scalar_array($e, $l)) {
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ pidl "ndr_print_string(ndr, \"$e->{NAME}\", $var_name);";
+ } else {
+ my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
+ pidl "ndr_print_array_$nl->{DATA_TYPE}(ndr, \"$e->{NAME}\", $var_name, $length);";
+ }
+ last;
+ }
+
+ my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
+
+ pidl "ndr->print(ndr, \"\%s: ARRAY(\%d)\", \"$e->{NAME}\", $length);";
+ pidl 'ndr->depth++;';
+ pidl "for ($counter=0;$counter<$length;$counter++) {";
+ indent;
+ pidl "char *idx_$l->{LEVEL_INDEX}=NULL;";
+ pidl "asprintf(&idx_$l->{LEVEL_INDEX}, \"[\%d]\", $counter);";
+ pidl "if (idx_$l->{LEVEL_INDEX}) {";
+ indent;
+
+ $var_name = $var_name . "[$counter]";
+
+ if ($l->{IS_VARYING} or $l->{IS_CONFORMANT}){ $var_name = get_pointer_to($var_name); }
+
+ } elsif ($l->{TYPE} eq "DATA") {
+ if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ $var_name = get_pointer_to($var_name);
+ }
+ pidl "ndr_print_$l->{DATA_TYPE}(ndr, \"$e->{NAME}\", $var_name);";
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+ check_null_pointer_void($switch_var);
+ pidl "ndr_print_set_switch_value(ndr, " . get_pointer_to($var_name) . ", $switch_var);";
+ }
+ }
+
+ foreach my $l (reverse @{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER") {
+ if ($l->{POINTER_TYPE} ne "ref") {
+ deindent;
+ pidl "}";
+ }
+ pidl "ndr->depth--;";
+ } elsif ($l->{TYPE} eq "ARRAY" and not is_scalar_array($e, $l)) {
+ pidl "free(idx_$l->{LEVEL_INDEX});";
+ deindent;
+ pidl "}";
+ deindent;
+ pidl "}";
+ pidl "ndr->depth--;";
+ }
+ }
+}
+
+#####################################################################
+# parse scalars in a structure element - pull size
+sub ParseSwitchPull($$$$$$)
+{
+ my($e,$l,$ndr,$var_name,$ndr_flags,$env) = @_;
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+
+ check_null_pointer($switch_var);
+
+ $var_name = get_pointer_to($var_name);
+ pidl "NDR_CHECK(ndr_pull_set_switch_value($ndr, $var_name, $switch_var));";
+}
+
+#####################################################################
+# push switch element
+sub ParseSwitchPush($$$$$$)
+{
+ my($e,$l,$ndr,$var_name,$ndr_flags,$env) = @_;
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+
+ check_null_pointer($switch_var);
+ $var_name = get_pointer_to($var_name);
+ pidl "NDR_CHECK(ndr_push_set_switch_value($ndr, $var_name, $switch_var));";
+}
+
+sub ParseDataPull($$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$ndr_flags) = @_;
+
+ if (Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ $var_name = get_pointer_to($var_name);
+
+ pidl "NDR_CHECK(ndr_pull_$l->{DATA_TYPE}($ndr, $ndr_flags, $var_name));";
+
+ if (my $range = Parse::Pidl::Util::has_property($e, "range")) {
+ $var_name = get_value_of($var_name);
+ my ($low, $high) = split(/ /, $range, 2);
+ pidl "if ($var_name < $low || $var_name > $high) {";
+ pidl "\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");";
+ pidl "}";
+ }
+}
+
+sub ParseDataPush($$$$$)
+{
+ my ($e,$l,$ndr,$var_name,$ndr_flags) = @_;
+
+ # strings are passed by value rather then reference
+ if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE}) or Parse::Pidl::Typelist::scalar_is_reference($l->{DATA_TYPE})) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ pidl "NDR_CHECK(ndr_push_$l->{DATA_TYPE}($ndr, $ndr_flags, $var_name));";
+}
+
+sub CalcNdrFlags($$$)
+{
+ my ($l,$primitives,$deferred) = @_;
+
+ my $scalars = 0;
+ my $buffers = 0;
+
+ # Add NDR_SCALARS if this one is deferred
+ # and deferreds may be pushed
+ $scalars = 1 if ($l->{IS_DEFERRED} and $deferred);
+
+ # Add NDR_SCALARS if this one is not deferred and
+ # primitives may be pushed
+ $scalars = 1 if (!$l->{IS_DEFERRED} and $primitives);
+
+ # Add NDR_BUFFERS if this one contains deferred stuff
+ # and deferreds may be pushed
+ $buffers = 1 if ($l->{CONTAINS_DEFERRED} and $deferred);
+
+ return "NDR_SCALARS|NDR_BUFFERS" if ($scalars and $buffers);
+ return "NDR_SCALARS" if ($scalars);
+ return "NDR_BUFFERS" if ($buffers);
+ return undef;
+}
+
+sub ParseElementPullLevel
+{
+ my($e,$l,$ndr,$var_name,$env,$primitives,$deferred) = @_;
+
+ my $ndr_flags = CalcNdrFlags($l, $primitives, $deferred);
+
+ # Only pull something if there's actually something to be pulled
+ if (defined($ndr_flags)) {
+ if ($l->{TYPE} eq "SUBCONTEXT") {
+ ($ndr,$var_name) = ParseSubcontextPullStart($e, $l, $ndr, $var_name, $ndr_flags, $env);
+ ParseElementPullLevel($e,Parse::Pidl::NDR::GetNextLevel($e,$l), $ndr, $var_name, $env, 1, 1);
+ ParseSubcontextPullEnd($e, $l, $env);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ my $length = ParseArrayPullHeader($e, $l, $ndr, $var_name, $env);
+
+ # Speed things up a little - special array pull functions
+ # for scalars
+ if (is_scalar_array($e, $l)) {
+ if ($l->{IS_VARYING} or $l->{IS_CONFORMANT}) {
+ $var_name = get_pointer_to($var_name);
+ }
+ my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
+
+ if (Parse::Pidl::Util::has_property($e, "charset")) {
+ pidl "NDR_CHECK(ndr_pull_charset($ndr, $ndr_flags, ".get_pointer_to($var_name).", $length, sizeof(" . Parse::Pidl::Typelist::mapType($nl->{DATA_TYPE}) . "), CH_$e->{PROPERTIES}->{charset}));";
+ } else {
+ pidl "NDR_CHECK(ndr_pull_array_$nl->{DATA_TYPE}($ndr, $ndr_flags, $var_name, $length));";
+ if ($l->{IS_ZERO_TERMINATED}) {
+ # Make sure last element is zero!
+ pidl "NDR_CHECK(ndr_check_string_terminator($ndr, $var_name, $length, sizeof(*$var_name)));";
+ }
+ }
+ return;
+ }
+ } elsif ($l->{TYPE} eq "POINTER") {
+ ParsePtrPull($e, $l, $ndr, $var_name);
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseSwitchPull($e, $l, $ndr, $var_name, $ndr_flags, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ ParseDataPull($e, $l, $ndr, $var_name, $ndr_flags);
+ }
+ }
+
+ # add additional constructions
+ if ($l->{TYPE} eq "POINTER" and $deferred) {
+ if ($l->{POINTER_TYPE} ne "ref") {
+ pidl "if ($var_name) {";
+ indent;
+
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "struct ndr_pull_save _relative_save;";
+ pidl "ndr_pull_save(ndr, &_relative_save);";
+ pidl "NDR_CHECK(ndr_pull_relative_ptr2(ndr, $var_name));";
+ }
+ }
+
+ $var_name = get_value_of($var_name);
+ ParseElementPullLevel($e,Parse::Pidl::NDR::GetNextLevel($e,$l), $ndr, $var_name, $env, $primitives, $deferred);
+
+ if ($l->{POINTER_TYPE} ne "ref") {
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "ndr_pull_restore(ndr, &_relative_save);";
+ }
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "ARRAY" and not is_scalar_array($e,$l)) {
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
+
+ $var_name = $var_name . "[$counter]";
+ if ($l->{IS_VARYING} or $l->{IS_CONFORMANT}) {
+ $var_name = get_pointer_to($var_name);
+ }
+
+ if (($primitives and not $l->{IS_DEFERRED}) or ($deferred and $l->{IS_DEFERRED})) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementPullLevel($e,Parse::Pidl::NDR::GetNextLevel($e,$l), $ndr, $var_name, $env, 1, 0);
+ deindent;
+ pidl "}";
+
+ if ($l->{IS_ZERO_TERMINATED}) {
+ # Make sure last element is zero!
+ pidl "NDR_CHECK(ndr_check_string_terminator($ndr, $var_name, $length, sizeof(*$var_name)));";
+ }
+ }
+
+ if ($deferred and Parse::Pidl::NDR::ContainsDeferred($e, $l)) {
+ pidl "for ($counter = 0; $counter < $length; $counter++) {";
+ indent;
+ ParseElementPullLevel($e,Parse::Pidl::NDR::GetNextLevel($e,$l), $ndr, $var_name, $env, 0, 1);
+ deindent;
+ pidl "}";
+ }
+ } elsif ($l->{TYPE} eq "SWITCH") {
+ ParseElementPullLevel($e,Parse::Pidl::NDR::GetNextLevel($e,$l), $ndr, $var_name, $env, $primitives, $deferred);
+ }
+}
+
+#####################################################################
+# parse scalars in a structure element - pull size
+sub ParseElementPull($$$$$$)
+{
+ my($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_;
+
+ my $var_name = $var_prefix.$e->{NAME};
+
+ $var_name = append_prefix($e, $var_name);
+
+ return unless $primitives or ($deferred and Parse::Pidl::NDR::ContainsDeferred($e, $e->{LEVELS}[0]));
+
+ start_flags($e);
+
+ ParseElementPullLevel($e,$e->{LEVELS}[0],$ndr,$var_name,$env,$primitives,$deferred);
+
+ end_flags($e);
+}
+
+#####################################################################
+# parse a pointer in a struct element or function
+sub ParsePtrPull($$$$)
+{
+ my($e,$l,$ndr,$var_name) = @_;
+
+ my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
+ my $next_is_array = ($nl->{TYPE} eq "ARRAY");
+ my $next_is_string = (($nl->{TYPE} eq "DATA") and
+ ($nl->{DATA_TYPE} eq "string"));
+
+ if ($l->{POINTER_TYPE} eq "ref") {
+ unless ($l->{LEVEL} eq "TOP") {
+ pidl "NDR_CHECK(ndr_pull_ref_ptr($ndr, &_ptr_$e->{NAME}));";
+ }
+
+ unless ($next_is_array or $next_is_string) {
+ pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {";
+ pidl "\tNDR_ALLOC($ndr, $var_name);";
+ pidl "}";
+ }
+
+ return;
+ } elsif (($l->{POINTER_TYPE} eq "unique") or
+ ($l->{POINTER_TYPE} eq "relative") or
+ ($l->{POINTER_TYPE} eq "sptr")) {
+ pidl "NDR_CHECK(ndr_pull_generic_ptr($ndr, &_ptr_$e->{NAME}));";
+ pidl "if (_ptr_$e->{NAME}) {";
+ indent;
+ } else {
+ die("Unhandled pointer type $l->{POINTER_TYPE}");
+ }
+
+ # Don't do this for arrays, they're allocated at the actual level
+ # of the array
+ unless ($next_is_array or $next_is_string) {
+ pidl "NDR_ALLOC($ndr, $var_name);";
+ } else {
+ pidl "NDR_ALLOC_SIZE($ndr, $var_name, 1);"; # FIXME: Yes, this is nasty. We allocate an array twice - once just to indicate that it's there, then the real allocation...
+ }
+
+ #pidl "memset($var_name, 0, sizeof($var_name));";
+ if ($l->{POINTER_TYPE} eq "relative") {
+ pidl "NDR_CHECK(ndr_pull_relative_ptr1($ndr, $var_name, _ptr_$e->{NAME}));";
+ }
+ deindent;
+ pidl "} else {";
+ pidl "\t$var_name = NULL;";
+ pidl "}";
+}
+
+#####################################################################
+# parse a struct
+sub ParseStructPush($$)
+{
+ my($struct,$name) = @_;
+
+ return unless defined($struct->{ELEMENTS});
+
+ my $env = GenerateStructEnv($struct);
+
+ # save the old relative_base_offset
+ pidl "uint32_t _save_relative_base_offset = ndr_push_get_relative_base_offset(ndr);" if defined($struct->{PROPERTIES}{relative_base});
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ DeclareArrayVariables($e);
+ }
+
+ start_flags($struct);
+
+ # see if the structure contains a conformant array. If it
+ # does, then it must be the last element of the structure, and
+ # we need to push the conformant length early, as it fits on
+ # the wire before the structure (and even before the structure
+ # alignment)
+ my $e = $struct->{ELEMENTS}[-1];
+ if (defined($struct->{SURROUNDING_ELEMENT})) {
+ my $e = $struct->{SURROUNDING_ELEMENT};
+
+ if (defined($e->{LEVELS}[0]) and
+ $e->{LEVELS}[0]->{TYPE} eq "ARRAY") {
+ my $size = Parse::Pidl::Util::ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env);
+
+ pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, $size));";
+ } else {
+ pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_string_array_size(ndr, r->$e->{NAME})));";
+ }
+ }
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ pidl "NDR_CHECK(ndr_push_align(ndr, $struct->{ALIGN}));";
+
+ if (defined($struct->{PROPERTIES}{relative_base})) {
+ # set the current offset as base for relative pointers
+ # and store it based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
+ }
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPush($e, "ndr", "r->", $env, 1, 0);
+ }
+
+ deindent;
+ pidl "}";
+
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ if (defined($struct->{PROPERTIES}{relative_base})) {
+ # retrieve the current offset as base for relative pointers
+ # based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_push_setup_relative_base_offset2(ndr, r));";
+ }
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPush($e, "ndr", "r->", $env, 0, 1);
+ }
+
+ deindent;
+ pidl "}";
+
+ end_flags($struct);
+ # restore the old relative_base_offset
+ pidl "ndr_push_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($struct->{PROPERTIES}{relative_base});
+}
+
+#####################################################################
+# generate a push function for an enum
+sub ParseEnumPush($$)
+{
+ my($enum,$name) = @_;
+ my($type_fn) = $enum->{BASE_TYPE};
+
+ start_flags($enum);
+ pidl "NDR_CHECK(ndr_push_$type_fn(ndr, NDR_SCALARS, r));";
+ end_flags($enum);
+}
+
+#####################################################################
+# generate a pull function for an enum
+sub ParseEnumPull($$)
+{
+ my($enum,$name) = @_;
+ my($type_fn) = $enum->{BASE_TYPE};
+ my($type_v_decl) = Parse::Pidl::Typelist::mapType($type_fn);
+
+ pidl "$type_v_decl v;";
+ start_flags($enum);
+ pidl "NDR_CHECK(ndr_pull_$type_fn(ndr, NDR_SCALARS, &v));";
+ pidl "*r = v;";
+
+ end_flags($enum);
+}
+
+#####################################################################
+# generate a print function for an enum
+sub ParseEnumPrint($$)
+{
+ my($enum,$name) = @_;
+
+ pidl "const char *val = NULL;";
+ pidl "";
+
+ start_flags($enum);
+
+ pidl "switch (r) {";
+ indent;
+ my $els = \@{$enum->{ELEMENTS}};
+ foreach my $i (0 .. $#{$els}) {
+ my $e = ${$els}[$i];
+ chomp $e;
+ if ($e =~ /^(.*)=/) {
+ $e = $1;
+ }
+ pidl "case $e: val = \"$e\"; break;";
+ }
+
+ deindent;
+ pidl "}";
+
+ pidl "ndr_print_enum(ndr, name, \"$enum->{TYPE}\", val, r);";
+
+ end_flags($enum);
+}
+
+sub ArgsEnumPush($)
+{
+ my $e = shift;
+ return "struct ndr_push *ndr, int ndr_flags, enum $e->{NAME} r";
+}
+
+sub ArgsEnumPrint($)
+{
+ my $e = shift;
+ return "struct ndr_print *ndr, const char *name, enum $e->{NAME} r";
+}
+
+sub ArgsEnumPull($)
+{
+ my $e = shift;
+ return "struct ndr_pull *ndr, int ndr_flags, enum $e->{NAME} *r";
+}
+
+$typefamily{ENUM} = {
+ PUSH_FN_BODY => \&ParseEnumPush,
+ PUSH_FN_ARGS => \&ArgsEnumPush,
+ PULL_FN_BODY => \&ParseEnumPull,
+ PULL_FN_ARGS => \&ArgsEnumPull,
+ PRINT_FN_BODY => \&ParseEnumPrint,
+ PRINT_FN_ARGS => \&ArgsEnumPrint,
+};
+
+#####################################################################
+# generate a push function for a bitmap
+sub ParseBitmapPush($$)
+{
+ my($bitmap,$name) = @_;
+ my($type_fn) = $bitmap->{BASE_TYPE};
+
+ start_flags($bitmap);
+
+ pidl "NDR_CHECK(ndr_push_$type_fn(ndr, NDR_SCALARS, r));";
+
+ end_flags($bitmap);
+}
+
+#####################################################################
+# generate a pull function for an bitmap
+sub ParseBitmapPull($$)
+{
+ my($bitmap,$name) = @_;
+ my $type_fn = $bitmap->{BASE_TYPE};
+ my($type_decl) = Parse::Pidl::Typelist::mapType($bitmap->{BASE_TYPE});
+
+ pidl "$type_decl v;";
+ start_flags($bitmap);
+ pidl "NDR_CHECK(ndr_pull_$type_fn(ndr, NDR_SCALARS, &v));";
+ pidl "*r = v;";
+
+ end_flags($bitmap);
+}
+
+#####################################################################
+# generate a print function for an bitmap
+sub ParseBitmapPrintElement($$$)
+{
+ my($e,$bitmap,$name) = @_;
+ my($type_decl) = Parse::Pidl::Typelist::mapType($bitmap->{BASE_TYPE});
+ my($type_fn) = $bitmap->{BASE_TYPE};
+ my($flag);
+
+ if ($e =~ /^(\w+) .*$/) {
+ $flag = "$1";
+ } else {
+ die "Bitmap: \"$name\" invalid Flag: \"$e\"";
+ }
+
+ pidl "ndr_print_bitmap_flag(ndr, sizeof($type_decl), \"$flag\", $flag, r);";
+}
+
+#####################################################################
+# generate a print function for an bitmap
+sub ParseBitmapPrint($$)
+{
+ my($bitmap,$name) = @_;
+ my($type_decl) = Parse::Pidl::Typelist::mapType($bitmap->{TYPE});
+ my($type_fn) = $bitmap->{BASE_TYPE};
+
+ start_flags($bitmap);
+
+ pidl "ndr_print_$type_fn(ndr, name, r);";
+
+ pidl "ndr->depth++;";
+ foreach my $e (@{$bitmap->{ELEMENTS}}) {
+ ParseBitmapPrintElement($e, $bitmap, $name);
+ }
+ pidl "ndr->depth--;";
+
+ end_flags($bitmap);
+}
+
+sub ArgsBitmapPush($)
+{
+ my $e = shift;
+ my $type_decl = Parse::Pidl::Typelist::mapType($e->{DATA}->{BASE_TYPE});
+ return "struct ndr_push *ndr, int ndr_flags, $type_decl r";
+}
+
+sub ArgsBitmapPrint($)
+{
+ my $e = shift;
+ my $type_decl = Parse::Pidl::Typelist::mapType($e->{DATA}->{BASE_TYPE});
+ return "struct ndr_print *ndr, const char *name, $type_decl r";
+}
+
+sub ArgsBitmapPull($)
+{
+ my $e = shift;
+ my $type_decl = Parse::Pidl::Typelist::mapType($e->{DATA}->{BASE_TYPE});
+ return "struct ndr_pull *ndr, int ndr_flags, $type_decl *r";
+}
+
+$typefamily{BITMAP} = {
+ PUSH_FN_BODY => \&ParseBitmapPush,
+ PUSH_FN_ARGS => \&ArgsBitmapPush,
+ PULL_FN_BODY => \&ParseBitmapPull,
+ PULL_FN_ARGS => \&ArgsBitmapPull,
+ PRINT_FN_BODY => \&ParseBitmapPrint,
+ PRINT_FN_ARGS => \&ArgsBitmapPrint,
+};
+
+#####################################################################
+# generate a struct print function
+sub ParseStructPrint($$)
+{
+ my($struct,$name) = @_;
+
+ return unless defined $struct->{ELEMENTS};
+
+ my $env = GenerateStructEnv($struct);
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ DeclareArrayVariables($e);
+ }
+
+ pidl "ndr_print_struct(ndr, name, \"$name\");";
+
+ start_flags($struct);
+
+ pidl "ndr->depth++;";
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPrint($e, "r->$e->{NAME}", $env);
+ }
+ pidl "ndr->depth--;";
+
+ end_flags($struct);
+}
+
+sub DeclarePtrVariables($)
+{
+ my $e = shift;
+ foreach my $l (@{$e->{LEVELS}}) {
+ if ($l->{TYPE} eq "POINTER" and
+ not ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP")) {
+ pidl "uint32_t _ptr_$e->{NAME};";
+ last;
+ }
+ }
+}
+
+sub DeclareArrayVariables($)
+{
+ my $e = shift;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ next if (is_scalar_array($e,$l));
+ if ($l->{TYPE} eq "ARRAY") {
+ pidl "uint32_t cntr_$e->{NAME}_$l->{LEVEL_INDEX};";
+ }
+ }
+}
+
+#####################################################################
+# parse a struct - pull side
+sub ParseStructPull($$)
+{
+ my($struct,$name) = @_;
+
+ return unless defined $struct->{ELEMENTS};
+
+ my $env = GenerateStructEnv($struct);
+
+ # declare any internal pointers we need
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ DeclarePtrVariables($e);
+ DeclareArrayVariables($e);
+ }
+
+ # save the old relative_base_offset
+ pidl "uint32_t _save_relative_base_offset = ndr_pull_get_relative_base_offset(ndr);" if defined($struct->{PROPERTIES}{relative_base});
+
+ start_flags($struct);
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ if (defined $struct->{SURROUNDING_ELEMENT}) {
+ pidl "NDR_CHECK(ndr_pull_array_size(ndr, &r->$struct->{SURROUNDING_ELEMENT}->{NAME}));";
+ }
+
+ pidl "NDR_CHECK(ndr_pull_align(ndr, $struct->{ALIGN}));";
+
+ if (defined($struct->{PROPERTIES}{relative_base})) {
+ # set the current offset as base for relative pointers
+ # and store it based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
+ }
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPull($e, "ndr", "r->", $env, 1, 0);
+ }
+
+ deindent;
+ pidl "}";
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ if (defined($struct->{PROPERTIES}{relative_base})) {
+ # retrieve the current offset as base for relative pointers
+ # based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset2(ndr, r));";
+ }
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPull($e, "ndr", "r->", $env, 0, 1);
+ }
+
+ deindent;
+ pidl "}";
+
+ end_flags($struct);
+ # restore the old relative_base_offset
+ pidl "ndr_pull_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($struct->{PROPERTIES}{relative_base});
+}
+
+#####################################################################
+# calculate size of ndr struct
+sub ParseStructNdrSize($)
+{
+ my $t = shift;
+ my $sizevar;
+
+ if (my $flags = Parse::Pidl::Util::has_property($t, "flag")) {
+ pidl "flags |= $flags;";
+ }
+ pidl "return ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});";
+}
+
+sub ArgsStructPush($)
+{
+ my $e = shift;
+ return "struct ndr_push *ndr, int ndr_flags, const struct $e->{NAME} *r";
+}
+
+sub ArgsStructPrint($)
+{
+ my $e = shift;
+ return "struct ndr_print *ndr, const char *name, const struct $e->{NAME} *r";
+}
+
+sub ArgsStructPull($)
+{
+ my $e = shift;
+ return "struct ndr_pull *ndr, int ndr_flags, struct $e->{NAME} *r";
+}
+
+sub ArgsStructNdrSize($)
+{
+ my $d = shift;
+ return "const struct $d->{NAME} *r, int flags";
+}
+
+$typefamily{STRUCT} = {
+ PUSH_FN_BODY => \&ParseStructPush,
+ PUSH_FN_ARGS => \&ArgsStructPush,
+ PULL_FN_BODY => \&ParseStructPull,
+ PULL_FN_ARGS => \&ArgsStructPull,
+ PRINT_FN_BODY => \&ParseStructPrint,
+ PRINT_FN_ARGS => \&ArgsStructPrint,
+ SIZE_FN_BODY => \&ParseStructNdrSize,
+ SIZE_FN_ARGS => \&ArgsStructNdrSize,
+};
+
+#####################################################################
+# calculate size of ndr struct
+sub ParseUnionNdrSize($)
+{
+ my $t = shift;
+ my $sizevar;
+
+ if (my $flags = Parse::Pidl::Util::has_property($t, "flag")) {
+ pidl "flags |= $flags;";
+ }
+
+ pidl "return ndr_size_union(r, flags, level, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});";
+}
+
+#####################################################################
+# parse a union - push side
+sub ParseUnionPush($$)
+{
+ my ($e,$name) = @_;
+ my $have_default = 0;
+
+ # save the old relative_base_offset
+ pidl "uint32_t _save_relative_base_offset = ndr_push_get_relative_base_offset(ndr);" if defined($e->{PROPERTIES}{relative_base});
+ pidl "int level;";
+
+ start_flags($e);
+
+ pidl "level = ndr_push_get_switch_value(ndr, r);";
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ if (defined($e->{SWITCH_TYPE})) {
+ pidl "NDR_CHECK(ndr_push_$e->{SWITCH_TYPE}(ndr, NDR_SCALARS, level));";
+ }
+
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ if ($el->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$el->{CASE}:";
+
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ if (defined($e->{PROPERTIES}{relative_base})) {
+ pidl "NDR_CHECK(ndr_push_align(ndr, $el->{ALIGN}));";
+ # set the current offset as base for relative pointers
+ # and store it based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
+ }
+ DeclareArrayVariables($el);
+ ParseElementPush($el, "ndr", "r->", {}, 1, 0);
+ deindent;
+ }
+ pidl "break;";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);";
+ }
+ deindent;
+ pidl "}";
+ deindent;
+ pidl "}";
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ if (defined($e->{PROPERTIES}{relative_base})) {
+ # retrieve the current offset as base for relative pointers
+ # based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_push_setup_relative_base_offset2(ndr, r));";
+ }
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ pidl "$el->{CASE}:";
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ ParseElementPush($el, "ndr", "r->", {}, 0, 1);
+ deindent;
+ }
+ pidl "break;";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);";
+ }
+ deindent;
+ pidl "}";
+
+ deindent;
+ pidl "}";
+ end_flags($e);
+ # restore the old relative_base_offset
+ pidl "ndr_push_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($e->{PROPERTIES}{relative_base});
+}
+
+#####################################################################
+# print a union
+sub ParseUnionPrint($$)
+{
+ my ($e,$name) = @_;
+ my $have_default = 0;
+
+ pidl "int level = ndr_print_get_switch_value(ndr, r);";
+
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ DeclareArrayVariables($el);
+ }
+
+ pidl "ndr_print_union(ndr, name, level, \"$name\");";
+ start_flags($e);
+
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ if ($el->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$el->{CASE}:";
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ ParseElementPrint($el, "r->$el->{NAME}", {});
+ deindent;
+ }
+ pidl "break;";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\tndr_print_bad_level(ndr, name, level);";
+ }
+ deindent;
+ pidl "}";
+
+ end_flags($e);
+}
+
+#####################################################################
+# parse a union - pull side
+sub ParseUnionPull($$)
+{
+ my ($e,$name) = @_;
+ my $have_default = 0;
+ my $switch_type = $e->{SWITCH_TYPE};
+
+ # save the old relative_base_offset
+ pidl "uint32_t _save_relative_base_offset = ndr_pull_get_relative_base_offset(ndr);" if defined($e->{PROPERTIES}{relative_base});
+ pidl "int level;";
+ if (defined($switch_type)) {
+ if (Parse::Pidl::Typelist::typeIs($switch_type, "ENUM")) {
+ $switch_type = Parse::Pidl::Typelist::enum_type_fn(Parse::Pidl::Typelist::getType($switch_type));
+ }
+ pidl Parse::Pidl::Typelist::mapType($switch_type) . " _level;";
+ }
+
+ start_flags($e);
+
+ pidl "level = ndr_pull_get_switch_value(ndr, r);";
+
+ pidl "if (ndr_flags & NDR_SCALARS) {";
+ indent;
+
+ if (defined($switch_type)) {
+ pidl "NDR_CHECK(ndr_pull_$switch_type(ndr, NDR_SCALARS, &_level));";
+ pidl "if (_level != level) {";
+ pidl "\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $name\", _level);";
+ pidl "}";
+ }
+
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ if ($el->{CASE} eq "default") {
+ $have_default = 1;
+ }
+ pidl "$el->{CASE}: {";
+
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ DeclarePtrVariables($el);
+ DeclareArrayVariables($el);
+ if (defined($e->{PROPERTIES}{relative_base})) {
+ pidl "NDR_CHECK(ndr_pull_align(ndr, $el->{ALIGN}));";
+ # set the current offset as base for relative pointers
+ # and store it based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
+ }
+ ParseElementPull($el, "ndr", "r->", {}, 1, 0);
+ deindent;
+ }
+ pidl "break; }";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);";
+ }
+ deindent;
+ pidl "}";
+ deindent;
+ pidl "}";
+ pidl "if (ndr_flags & NDR_BUFFERS) {";
+ indent;
+ if (defined($e->{PROPERTIES}{relative_base})) {
+ # retrieve the current offset as base for relative pointers
+ # based on the toplevel struct/union
+ pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset2(ndr, r));";
+ }
+ pidl "switch (level) {";
+ indent;
+ foreach my $el (@{$e->{ELEMENTS}}) {
+ pidl "$el->{CASE}:";
+ if ($el->{TYPE} ne "EMPTY") {
+ indent;
+ ParseElementPull($el, "ndr", "r->", {}, 0, 1);
+ deindent;
+ }
+ pidl "break;";
+ pidl "";
+ }
+ if (! $have_default) {
+ pidl "default:";
+ pidl "\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);";
+ }
+ deindent;
+ pidl "}";
+
+ deindent;
+ pidl "}";
+ end_flags($e);
+ # restore the old relative_base_offset
+ pidl "ndr_pull_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($e->{PROPERTIES}{relative_base});
+}
+
+sub ArgsUnionPush($)
+{
+ my $e = shift;
+ return "struct ndr_push *ndr, int ndr_flags, const union $e->{NAME} *r";
+}
+
+sub ArgsUnionPrint($)
+{
+ my $e = shift;
+ return "struct ndr_print *ndr, const char *name, const union $e->{NAME} *r";
+}
+
+sub ArgsUnionPull($)
+{
+ my $e = shift;
+ return "struct ndr_pull *ndr, int ndr_flags, union $e->{NAME} *r";
+}
+
+sub ArgsUnionNdrSize($)
+{
+ my $d = shift;
+ return "const union $d->{NAME} *r, uint32_t level, int flags";
+}
+
+$typefamily{UNION} = {
+ PUSH_FN_BODY => \&ParseUnionPush,
+ PUSH_FN_ARGS => \&ArgsUnionPush,
+ PULL_FN_BODY => \&ParseUnionPull,
+ PULL_FN_ARGS => \&ArgsUnionPull,
+ PRINT_FN_BODY => \&ParseUnionPrint,
+ PRINT_FN_ARGS => \&ArgsUnionPrint,
+ SIZE_FN_ARGS => \&ArgsUnionNdrSize,
+ SIZE_FN_BODY => \&ParseUnionNdrSize,
+};
+
+#####################################################################
+# parse a typedef - push side
+sub ParseTypedefPush($)
+{
+ my($e) = shift;
+
+ my $args = $typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_ARGS}->($e);
+ pidl fn_prefix($e) . "NTSTATUS ndr_push_$e->{NAME}($args)";
+
+ pidl "{";
+ indent;
+ $typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}->($e->{DATA}, $e->{NAME});
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";;
+}
+
+#####################################################################
+# parse a typedef - pull side
+sub ParseTypedefPull($)
+{
+ my($e) = shift;
+
+ my $args = $typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_ARGS}->($e);
+
+ pidl fn_prefix($e) . "NTSTATUS ndr_pull_$e->{NAME}($args)";
+
+ pidl "{";
+ indent;
+ $typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}->($e->{DATA}, $e->{NAME});
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse a typedef - print side
+sub ParseTypedefPrint($)
+{
+ my($e) = shift;
+
+ my $args = $typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_ARGS}->($e);
+
+ pidl "void ndr_print_$e->{NAME}($args)";
+ pidl "{";
+ indent;
+ $typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $e->{NAME});
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+## calculate the size of a structure
+sub ParseTypedefNdrSize($)
+{
+ my($t) = shift;
+
+ my $tf = $typefamily{$t->{DATA}->{TYPE}};
+ my $args = $tf->{SIZE_FN_ARGS}->($t);
+
+ pidl "size_t ndr_size_$t->{NAME}($args)";
+ pidl "{";
+ indent;
+ $typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t);
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse a function - print side
+sub ParseFunctionPrint($)
+{
+ my($fn) = shift;
+
+ return if Parse::Pidl::Util::has_property($fn, "noprint");
+
+ pidl "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r)";
+ pidl "{";
+ indent;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ DeclareArrayVariables($e);
+ }
+
+ pidl "ndr_print_struct(ndr, name, \"$fn->{NAME}\");";
+ pidl "ndr->depth++;";
+
+ pidl "if (flags & NDR_SET_VALUES) {";
+ pidl "\tndr->flags |= LIBNDR_PRINT_SET_VALUES;";
+ pidl "}";
+
+ pidl "if (flags & NDR_IN) {";
+ indent;
+ pidl "ndr_print_struct(ndr, \"in\", \"$fn->{NAME}\");";
+ pidl "ndr->depth++;";
+
+ my $env = GenerateFunctionInEnv($fn);
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep(/in/,@{$e->{DIRECTION}})) {
+ ParseElementPrint($e, "r->in.$e->{NAME}", $env);
+ }
+ }
+ pidl "ndr->depth--;";
+ deindent;
+ pidl "}";
+
+ pidl "if (flags & NDR_OUT) {";
+ indent;
+ pidl "ndr_print_struct(ndr, \"out\", \"$fn->{NAME}\");";
+ pidl "ndr->depth++;";
+
+ $env = GenerateFunctionOutEnv($fn);
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep(/out/,@{$e->{DIRECTION}})) {
+ ParseElementPrint($e, "r->out.$e->{NAME}", $env);
+ }
+ }
+ if ($fn->{RETURN_TYPE}) {
+ pidl "ndr_print_$fn->{RETURN_TYPE}(ndr, \"result\", r->out.result);";
+ }
+ pidl "ndr->depth--;";
+ deindent;
+ pidl "}";
+
+ pidl "ndr->depth--;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse a function
+sub ParseFunctionPush($)
+{
+ my($fn) = shift;
+
+ return if Parse::Pidl::Util::has_property($fn, "nopush");
+
+ pidl fn_prefix($fn) . "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, const struct $fn->{NAME} *r)";
+ pidl "{";
+ indent;
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ DeclareArrayVariables($e);
+ }
+
+ pidl "if (flags & NDR_IN) {";
+ indent;
+
+ my $env = GenerateFunctionInEnv($fn);
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep(/in/,@{$e->{DIRECTION}})) {
+ ParseElementPush($e, "ndr", "r->in.", $env, 1, 1);
+ }
+ }
+
+ deindent;
+ pidl "}";
+
+ pidl "if (flags & NDR_OUT) {";
+ indent;
+
+ $env = GenerateFunctionOutEnv($fn);
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ if (grep(/out/,@{$e->{DIRECTION}})) {
+ ParseElementPush($e, "ndr", "r->out.", $env, 1, 1);
+ }
+ }
+
+ if ($fn->{RETURN_TYPE}) {
+ pidl "NDR_CHECK(ndr_push_$fn->{RETURN_TYPE}(ndr, NDR_SCALARS, r->out.result));";
+ }
+
+ deindent;
+ pidl "}";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+sub AllocateArrayLevel($$$$$)
+{
+ my ($e,$l,$ndr,$env,$size) = @_;
+
+ return if (Parse::Pidl::Util::has_property($e, "charset"));
+
+ my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env);
+
+ check_null_pointer($size);
+ my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l);
+ if (defined($pl) and
+ $pl->{TYPE} eq "POINTER" and
+ $pl->{POINTER_TYPE} eq "ref"
+ and not $l->{IS_ZERO_TERMINATED}) {
+ pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {";
+ pidl "\tNDR_ALLOC_N($ndr, $var, $size);";
+ pidl "}";
+ } else {
+ pidl "NDR_ALLOC_N($ndr, $var, $size);";
+ }
+
+ if (grep(/in/,@{$e->{DIRECTION}}) and
+ grep(/out/,@{$e->{DIRECTION}})) {
+ pidl "memcpy(r->out.$e->{NAME},r->in.$e->{NAME},$size * sizeof(*r->in.$e->{NAME}));";
+ }
+}
+
+#####################################################################
+# parse a function
+sub ParseFunctionPull($)
+{
+ my($fn) = shift;
+
+ return if Parse::Pidl::Util::has_property($fn, "nopull");
+
+ # pull function args
+ pidl fn_prefix($fn) . "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)";
+ pidl "{";
+ indent;
+
+ # declare any internal pointers we need
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ DeclarePtrVariables($e);
+ DeclareArrayVariables($e);
+ }
+
+ pidl "if (flags & NDR_IN) {";
+ indent;
+
+ # auto-init the out section of a structure. I originally argued that
+ # this was a bad idea as it hides bugs, but coping correctly
+ # with initialisation and not wiping ref vars is turning
+ # out to be too tricky (tridge)
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless grep(/out/, @{$e->{DIRECTION}});
+ pidl "ZERO_STRUCT(r->out);";
+ pidl "";
+ last;
+ }
+
+ my $env = GenerateFunctionInEnv($fn);
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep(/in/, @{$e->{DIRECTION}}));
+ ParseElementPull($e, "ndr", "r->in.", $env, 1, 1);
+ }
+
+ # allocate the "simple" out ref variables. FIXME: Shouldn't this have it's
+ # own flag rather then be in NDR_IN ?
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless (grep(/out/, @{$e->{DIRECTION}}));
+ next unless ($e->{LEVELS}[0]->{TYPE} eq "POINTER" and
+ $e->{LEVELS}[0]->{POINTER_TYPE} eq "ref");
+ next if (($e->{LEVELS}[1]->{TYPE} eq "DATA") and
+ ($e->{LEVELS}[1]->{DATA_TYPE} eq "string"));
+ next if (($e->{LEVELS}[1]->{TYPE} eq "ARRAY")
+ and $e->{LEVELS}[1]->{IS_ZERO_TERMINATED});
+
+ if ($e->{LEVELS}[1]->{TYPE} eq "ARRAY") {
+ my $size = Parse::Pidl::Util::ParseExpr($e->{LEVELS}[1]->{SIZE_IS}, $env);
+ check_null_pointer($size);
+
+ pidl "NDR_ALLOC_N(ndr, r->out.$e->{NAME}, $size);";
+
+ if (grep(/in/, @{$e->{DIRECTION}})) {
+ pidl "memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, $size * sizeof(*r->in.$e->{NAME}));";
+ } else {
+ pidl "memset(r->out.$e->{NAME}, 0, $size * sizeof(*r->out.$e->{NAME}));";
+ }
+ } else {
+ pidl "NDR_ALLOC(ndr, r->out.$e->{NAME});";
+
+ if (grep(/in/, @{$e->{DIRECTION}})) {
+ pidl "*r->out.$e->{NAME} = *r->in.$e->{NAME};";
+ } else {
+ pidl "ZERO_STRUCTP(r->out.$e->{NAME});";
+ }
+ }
+ }
+
+ deindent;
+ pidl "}";
+
+ pidl "if (flags & NDR_OUT) {";
+ indent;
+
+ $env = GenerateFunctionOutEnv($fn);
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ next unless grep(/out/, @{$e->{DIRECTION}});
+ ParseElementPull($e, "ndr", "r->out.", $env, 1, 1);
+ }
+
+ if ($fn->{RETURN_TYPE}) {
+ pidl "NDR_CHECK(ndr_pull_$fn->{RETURN_TYPE}(ndr, NDR_SCALARS, &r->out.result));";
+ }
+
+ deindent;
+ pidl "}";
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# produce a function call table
+sub FunctionTable($)
+{
+ my($interface) = shift;
+ my $count = 0;
+ my $uname = uc $interface->{NAME};
+
+ $count = $#{$interface->{FUNCTIONS}}+1;
+
+ return if ($count == 0);
+
+ pidl "static const struct dcerpc_interface_call $interface->{NAME}\_calls[] = {";
+ $count = 0;
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ next if not defined($d->{OPNUM});
+ pidl "\t{";
+ pidl "\t\t\"$d->{NAME}\",";
+ pidl "\t\tsizeof(struct $d->{NAME}),";
+ pidl "\t\t(ndr_push_flags_fn_t) ndr_push_$d->{NAME},";
+ pidl "\t\t(ndr_pull_flags_fn_t) ndr_pull_$d->{NAME},";
+ pidl "\t\t(ndr_print_function_t) ndr_print_$d->{NAME}";
+ pidl "\t},";
+ $count++;
+ }
+ pidl "\t{ NULL, 0, NULL, NULL, NULL }";
+ pidl "};";
+ pidl "";
+
+ pidl "static const char * const $interface->{NAME}\_endpoint_strings[] = {";
+ foreach my $ep (@{$interface->{ENDPOINTS}}) {
+ pidl "\t$ep, ";
+ }
+ my $endpoint_count = $#{$interface->{ENDPOINTS}}+1;
+
+ pidl "};";
+ pidl "";
+
+ pidl "static const struct dcerpc_endpoint_list $interface->{NAME}\_endpoints = {";
+ pidl "\t.count\t= $endpoint_count,";
+ pidl "\t.names\t= $interface->{NAME}\_endpoint_strings";
+ pidl "};";
+ pidl "";
+
+ if (! defined $interface->{PROPERTIES}->{authservice}) {
+ $interface->{PROPERTIES}->{authservice} = "\"host\"";
+ }
+
+ my @a = split / /, $interface->{PROPERTIES}->{authservice};
+ my $authservice_count = $#a + 1;
+
+ pidl "static const char * const $interface->{NAME}\_authservice_strings[] = {";
+ foreach my $ap (@a) {
+ pidl "\t$ap, ";
+ }
+ pidl "};";
+ pidl "";
+
+ pidl "static const struct dcerpc_authservice_list $interface->{NAME}\_authservices = {";
+ pidl "\t.count\t= $endpoint_count,";
+ pidl "\t.names\t= $interface->{NAME}\_authservice_strings";
+ pidl "};";
+ pidl "";
+
+ pidl "\nconst struct dcerpc_interface_table dcerpc_table_$interface->{NAME} = {";
+ pidl "\t.name\t\t= \"$interface->{NAME}\",";
+ pidl "\t.uuid\t\t= DCERPC_$uname\_UUID,";
+ pidl "\t.if_version\t= DCERPC_$uname\_VERSION,";
+ pidl "\t.helpstring\t= DCERPC_$uname\_HELPSTRING,";
+ pidl "\t.num_calls\t= $count,";
+ pidl "\t.calls\t\t= $interface->{NAME}\_calls,";
+ pidl "\t.endpoints\t= &$interface->{NAME}\_endpoints,";
+ pidl "\t.authservices\t= &$interface->{NAME}\_authservices";
+ pidl "};";
+ pidl "";
+
+ pidl "static NTSTATUS dcerpc_ndr_$interface->{NAME}_init(void)";
+ pidl "{";
+ pidl "\treturn librpc_register_interface(&dcerpc_table_$interface->{NAME});";
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse the interface definitions
+sub ParseInterface($$)
+{
+ my($interface,$needed) = @_;
+
+ # Typedefs
+ foreach my $d (@{$interface->{TYPEDEFS}}) {
+ ($needed->{"push_$d->{NAME}"}) && ParseTypedefPush($d);
+ ($needed->{"pull_$d->{NAME}"}) && ParseTypedefPull($d);
+ ($needed->{"print_$d->{NAME}"}) && ParseTypedefPrint($d);
+
+ # Make sure we don't generate a function twice...
+ $needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
+ $needed->{"print_$d->{NAME}"} = 0;
+
+ ($needed->{"ndr_size_$d->{NAME}"}) && ParseTypedefNdrSize($d);
+ }
+
+ # Functions
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ ($needed->{"push_$d->{NAME}"}) && ParseFunctionPush($d);
+ ($needed->{"pull_$d->{NAME}"}) && ParseFunctionPull($d);
+ ($needed->{"print_$d->{NAME}"}) && ParseFunctionPrint($d);
+
+ # Make sure we don't generate a function twice...
+ $needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
+ $needed->{"print_$d->{NAME}"} = 0;
+ }
+
+ FunctionTable($interface);
+}
+
+sub RegistrationFunction($$)
+{
+ my ($idl,$filename) = @_;
+
+ $filename =~ /.*\/ndr_(.*).c/;
+ my $basename = $1;
+ pidl "NTSTATUS dcerpc_$basename\_init(void)";
+ pidl "{";
+ indent;
+ pidl "NTSTATUS status = NT_STATUS_OK;";
+ foreach my $interface (@{$idl}) {
+ next if $interface->{TYPE} ne "INTERFACE";
+
+ my $count = ($#{$interface->{FUNCTIONS}}+1);
+
+ next if ($count == 0);
+
+ pidl "status = dcerpc_ndr_$interface->{NAME}_init();";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\treturn status;";
+ pidl "}";
+ pidl "";
+ }
+ pidl "return status;";
+ deindent;
+ pidl "}";
+ pidl "";
+}
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($$)
+{
+ my($ndr,$filename) = @_;
+
+ $tabs = "";
+ my $h_filename = $filename;
+ $res = "";
+
+ if ($h_filename =~ /(.*)\.c/) {
+ $h_filename = "$1.h";
+ }
+
+ pidl "/* parser auto-generated by pidl */";
+ pidl "";
+ pidl "#include \"includes.h\"";
+ pidl "#include \"$h_filename\"";
+ pidl "";
+
+ my %needed = ();
+
+ foreach my $x (@{$ndr}) {
+ ($x->{TYPE} eq "INTERFACE") && NeededInterface($x, \%needed);
+ }
+
+ foreach my $x (@{$ndr}) {
+ ($x->{TYPE} eq "INTERFACE") && ParseInterface($x, \%needed);
+ }
+
+ RegistrationFunction($ndr, $filename);
+
+ return $res;
+}
+
+sub NeededFunction($$)
+{
+ my ($fn,$needed) = @_;
+ $needed->{"pull_$fn->{NAME}"} = 1;
+ $needed->{"push_$fn->{NAME}"} = 1;
+ $needed->{"print_$fn->{NAME}"} = 1;
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ $e->{PARENT} = $fn;
+ unless(defined($needed->{"pull_$e->{TYPE}"})) {
+ $needed->{"pull_$e->{TYPE}"} = 1;
+ }
+ unless(defined($needed->{"push_$e->{TYPE}"})) {
+ $needed->{"push_$e->{TYPE}"} = 1;
+ }
+ unless(defined($needed->{"print_$e->{TYPE}"})) {
+ $needed->{"print_$e->{TYPE}"} = 1;
+ }
+ }
+}
+
+sub NeededTypedef($$)
+{
+ my ($t,$needed) = @_;
+ if (Parse::Pidl::Util::has_property($t, "public")) {
+ $needed->{"pull_$t->{NAME}"} = not Parse::Pidl::Util::has_property($t, "nopull");
+ $needed->{"push_$t->{NAME}"} = not Parse::Pidl::Util::has_property($t, "nopush");
+ $needed->{"print_$t->{NAME}"} = not Parse::Pidl::Util::has_property($t, "noprint");
+ }
+
+ if ($t->{DATA}->{TYPE} eq "STRUCT" or $t->{DATA}->{TYPE} eq "UNION") {
+ if (Parse::Pidl::Util::has_property($t, "gensize")) {
+ $needed->{"ndr_size_$t->{NAME}"} = 1;
+ }
+
+ for my $e (@{$t->{DATA}->{ELEMENTS}}) {
+ $e->{PARENT} = $t->{DATA};
+ if ($needed->{"pull_$t->{NAME}"} and
+ not defined($needed->{"pull_$e->{TYPE}"})) {
+ $needed->{"pull_$e->{TYPE}"} = 1;
+ }
+ if ($needed->{"push_$t->{NAME}"} and
+ not defined($needed->{"push_$e->{TYPE}"})) {
+ $needed->{"push_$e->{TYPE}"} = 1;
+ }
+ if ($needed->{"print_$t->{NAME}"} and
+ not defined($needed->{"print_$e->{TYPE}"})) {
+ $needed->{"print_$e->{TYPE}"} = 1;
+ }
+ }
+ }
+}
+
+#####################################################################
+# work out what parse functions are needed
+sub NeededInterface($$)
+{
+ my ($interface,$needed) = @_;
+ foreach my $d (@{$interface->{FUNCTIONS}}) {
+ NeededFunction($d, $needed);
+ }
+ foreach my $d (reverse @{$interface->{TYPEDEFS}}) {
+ NeededTypedef($d, $needed);
+ }
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/NDR/Server.pm b/source4/build/pidl/Parse/Pidl/Samba/NDR/Server.pm
new file mode 100644
index 0000000000..1d63ea0cd1
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/NDR/Server.pm
@@ -0,0 +1,322 @@
+###################################################
+# server boilerplate generator
+# Copyright tridge@samba.org 2003
+# Copyright metze@samba.org 2004
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::NDR::Server;
+
+use strict;
+
+my($res);
+
+sub pidl($)
+{
+ $res .= shift;
+}
+
+
+#####################################################
+# generate the switch statement for function dispatch
+sub gen_dispatch_switch($)
+{
+ my $interface = shift;
+
+ foreach my $fn (@{$interface->{FUNCTIONS}}) {
+ next if not defined($fn->{OPNUM});
+
+ pidl "\tcase $fn->{OPNUM}: {\n";
+ pidl "\t\tstruct $fn->{NAME} *r2 = r;\n";
+ pidl "\t\tif (DEBUGLEVEL > 10) {\n";
+ pidl "\t\t\tNDR_PRINT_FUNCTION_DEBUG($fn->{NAME}, NDR_IN, r2);\n";
+ pidl "\t\t}\n";
+ if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
+ pidl "\t\tr2->out.result = $fn->{NAME}(dce_call, mem_ctx, r2);\n";
+ } else {
+ pidl "\t\t$fn->{NAME}(dce_call, mem_ctx, r2);\n";
+ }
+ pidl "\t\tif (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {\n";
+ pidl "\t\t\tDEBUG(5,(\"function $fn->{NAME} will reply async\\n\"));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tbreak;\n\t}\n";
+ }
+}
+
+#####################################################
+# generate the switch statement for function reply
+sub gen_reply_switch($)
+{
+ my $interface = shift;
+
+ foreach my $fn (@{$interface->{FUNCTIONS}}) {
+ next if not defined($fn->{OPNUM});
+
+ pidl "\tcase $fn->{OPNUM}: {\n";
+ pidl "\t\tstruct $fn->{NAME} *r2 = r;\n";
+ pidl "\t\tif (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {\n";
+ pidl "\t\t\tDEBUG(5,(\"function $fn->{NAME} replied async\\n\"));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tif (DEBUGLEVEL > 10 && dce_call->fault_code == 0) {\n";
+ pidl "\t\t\tNDR_PRINT_FUNCTION_DEBUG($fn->{NAME}, NDR_OUT | NDR_SET_VALUES, r2);\n";
+ pidl "\t\t}\n";
+ pidl "\t\tif (dce_call->fault_code != 0) {\n";
+ pidl "\t\t\tDEBUG(2,(\"dcerpc_fault %s in $fn->{NAME}\\n\", dcerpc_errstr(mem_ctx, dce_call->fault_code)));\n";
+ pidl "\t\t}\n";
+ pidl "\t\tbreak;\n\t}\n";
+ }
+}
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Boilerplate_Iface($)
+{
+ my($interface) = shift;
+ my $name = $interface->{NAME};
+ my $uname = uc $name;
+ my $uuid = Parse::Pidl::Util::make_str($interface->{PROPERTIES}->{uuid});
+ my $if_version = $interface->{PROPERTIES}->{version};
+
+ pidl "
+static NTSTATUS $name\__op_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
+{
+#ifdef DCESRV_INTERFACE_$uname\_BIND
+ return DCESRV_INTERFACE_$uname\_BIND(dce_call,iface);
+#else
+ return NT_STATUS_OK;
+#endif
+}
+
+static void $name\__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
+{
+#ifdef DCESRV_INTERFACE_$uname\_UNBIND
+ DCESRV_INTERFACE_$uname\_UNBIND(context, iface);
+#else
+ return;
+#endif
+}
+
+static NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
+{
+ NTSTATUS status;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ dce_call->fault_code = 0;
+
+ if (opnum >= dcerpc_table_$name.num_calls) {
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ *r = talloc_size(mem_ctx, dcerpc_table_$name.calls[opnum].struct_size);
+ NT_STATUS_HAVE_NO_MEMORY(*r);
+
+ /* unravel the NDR for the packet */
+ status = dcerpc_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
+{
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ switch (opnum) {
+";
+ gen_dispatch_switch($interface);
+
+pidl "
+ default:
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ break;
+ }
+
+ if (dce_call->fault_code != 0) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
+{
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ switch (opnum) {
+";
+ gen_reply_switch($interface);
+
+pidl "
+ default:
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ break;
+ }
+
+ if (dce_call->fault_code != 0) {
+ dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)
+{
+ NTSTATUS status;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ status = dcerpc_table_$name.calls[opnum].ndr_push(push, NDR_OUT, r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static const struct dcesrv_interface $name\_interface = {
+ .name = \"$name\",
+ .uuid = $uuid,
+ .if_version = $if_version,
+ .bind = $name\__op_bind,
+ .unbind = $name\__op_unbind,
+ .ndr_pull = $name\__op_ndr_pull,
+ .dispatch = $name\__op_dispatch,
+ .reply = $name\__op_reply,
+ .ndr_push = $name\__op_ndr_push
+};
+
+";
+}
+
+#####################################################################
+# produce boilerplate code for an endpoint server
+sub Boilerplate_Ep_Server($)
+{
+ my($interface) = shift;
+ my $name = $interface->{NAME};
+ my $uname = uc $name;
+
+ pidl "
+static NTSTATUS $name\__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
+{
+ int i;
+
+ for (i=0;i<dcerpc_table_$name.endpoints->count;i++) {
+ NTSTATUS ret;
+ const char *name = dcerpc_table_$name.endpoints->names[i];
+
+ ret = dcesrv_interface_register(dce_ctx, name, &$name\_interface, NULL);
+ if (!NT_STATUS_IS_OK(ret)) {
+ DEBUG(1,(\"$name\_op_init_server: failed to register endpoint \'%s\'\\n\",name));
+ return ret;
+ }
+ }
+
+ return NT_STATUS_OK;
+}
+
+static BOOL $name\__op_interface_by_uuid(struct dcesrv_interface *iface, const char *uuid, uint32_t if_version)
+{
+ if ($name\_interface.if_version == if_version &&
+ strcmp($name\_interface.uuid, uuid)==0) {
+ memcpy(iface,&$name\_interface, sizeof(*iface));
+ return True;
+ }
+
+ return False;
+}
+
+static BOOL $name\__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
+{
+ if (strcmp($name\_interface.name, name)==0) {
+ memcpy(iface,&$name\_interface, sizeof(*iface));
+ return True;
+ }
+
+ return False;
+}
+
+NTSTATUS dcerpc_server_$name\_init(void)
+{
+ NTSTATUS ret;
+ struct dcesrv_endpoint_server ep_server;
+
+ /* fill in our name */
+ ep_server.name = \"$name\";
+
+ /* fill in all the operations */
+ ep_server.init_server = $name\__op_init_server;
+
+ ep_server.interface_by_uuid = $name\__op_interface_by_uuid;
+ ep_server.interface_by_name = $name\__op_interface_by_name;
+
+ /* register ourselves with the DCERPC subsystem. */
+ ret = dcerpc_register_ep_server(&ep_server);
+
+ if (!NT_STATUS_IS_OK(ret)) {
+ DEBUG(0,(\"Failed to register \'$name\' endpoint server!\\n\"));
+ return ret;
+ }
+
+ return ret;
+}
+
+";
+}
+
+#####################################################################
+# dcerpc server boilerplate from a parsed IDL structure
+sub ParseInterface($)
+{
+ my($interface) = shift;
+ my $count = 0;
+
+ if (!defined $interface->{PROPERTIES}->{uuid}) {
+ return $res;
+ }
+
+ if (!defined $interface->{PROPERTIES}->{version}) {
+ $interface->{PROPERTIES}->{version} = "0.0";
+ }
+
+ foreach my $fn (@{$interface->{FUNCTIONS}}) {
+ if (defined($fn->{OPNUM})) { $count++; }
+ }
+
+ if ($count == 0) {
+ return $res;
+ }
+
+ $res .= "/* $interface->{NAME} - dcerpc server boilerplate generated by pidl */\n\n";
+ Boilerplate_Iface($interface);
+ Boilerplate_Ep_Server($interface);
+
+ return $res;
+}
+
+sub Parse($$)
+{
+ my($ndr) = shift;
+ my($filename) = shift;
+
+ $res = "";
+ $res .= "/* server functions auto-generated by pidl */\n";
+ $res .= "\n";
+
+ foreach my $x (@{$ndr}) {
+ ParseInterface($x) if ($x->{TYPE} eq "INTERFACE" and not defined($x->{PROPERTIES}{object}));
+ }
+
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/SWIG.pm b/source4/build/pidl/Parse/Pidl/Samba/SWIG.pm
new file mode 100644
index 0000000000..409095804f
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/SWIG.pm
@@ -0,0 +1,76 @@
+###################################################
+# Samba4 parser generator for swig wrappers
+# Copyright tpot@samba.org 2004,2005
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::SWIG;
+
+use strict;
+
+sub pidl($)
+{
+ print OUT shift;
+}
+
+#####################################################################
+# rewrite autogenerated header file
+sub RewriteHeader($$$)
+{
+ my($idl) = shift;
+ my($input) = shift;
+ my($output) = shift;
+
+ open(IN, "<$input") || die "can't open $input for reading";
+ open(OUT, ">$output") || die "can't open $output for writing";
+
+ pidl "%{\n";
+ pidl "#define data_in in\n";
+ pidl "#define data_out out\n";
+ pidl "%}\n\n";
+
+ while(<IN>) {
+
+ # Rename dom_sid2 to dom_sid as we don't care about the difference
+ # for the swig wrappers.
+
+ s/dom_sid2/dom_sid/g;
+
+ # Copy structure and union definitions
+
+ if (/^(struct|union) .*? {$/ .. /^\};$/) {
+ s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
+ pidl $_;
+ next;
+ }
+
+ # Copy dcerpc functions
+
+ pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
+
+ # Copy interface definitions
+
+ pidl $_
+ if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
+ }
+
+ close(OUT);
+}
+
+#####################################################################
+# rewrite autogenerated header file
+sub RewriteC($$$)
+{
+ my($idl) = shift;
+ my($input) = shift;
+ my($output) = shift;
+
+ open(IN, "<$input") || die "can't open $input for reading";
+ open(OUT, ">>$output") || die "can't open $output for writing";
+
+ while(<IN>) {
+ }
+
+ close(OUT);
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Samba/Template.pm b/source4/build/pidl/Parse/Pidl/Samba/Template.pm
new file mode 100644
index 0000000000..eb71b6d707
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Samba/Template.pm
@@ -0,0 +1,88 @@
+###################################################
+# server template function generator
+# Copyright tridge@samba.org 2003
+# released under the GNU GPL
+
+package Parse::Pidl::Samba::Template;
+
+use strict;
+
+my($res);
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Template($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+ my $name = $interface->{NAME};
+
+ $res .=
+"/*
+ Unix SMB/CIFS implementation.
+
+ endpoint server for the $name pipe
+
+ Copyright (C) YOUR NAME HERE YEAR
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include \"includes.h\"
+#include \"rpc_server/dcerpc_server.h\"
+#include \"librpc/gen_ndr/ndr_$name.h\"
+
+";
+
+ foreach my $d (@{$data}) {
+ if ($d->{TYPE} eq "FUNCTION") {
+ my $fname = $d->{NAME};
+ $res .=
+"
+/*
+ $fname
+*/
+static $d->{RETURN_TYPE} $fname(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
+ struct $fname *r)
+{
+ DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
+}
+
+";
+ }
+ }
+
+ $res .=
+"
+/* include the generated boilerplate */
+#include \"librpc/gen_ndr/ndr_$name\_s.c\"
+"
+}
+
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($)
+{
+ my($idl) = shift;
+ $res = "";
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") &&
+ Template($x);
+ }
+ return $res;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Test.pm b/source4/build/pidl/Parse/Pidl/Test.pm
new file mode 100644
index 0000000000..88403f31d4
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Test.pm
@@ -0,0 +1,169 @@
+# Simple system for running tests against pidl
+# (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU General Public License
+
+package Parse::Pidl::Test;
+
+use strict;
+use pidl::util;
+use Getopt::Long;
+
+my $cc = $ENV{CC};
+my @cflags = split / /, $ENV{CFLAGS};
+my @ldflags = split / /, $ENV{LDFLAGS};
+
+$cc = "cc" if ($cc eq "");
+
+sub generate_cfile($$$)
+{
+ my ($filename, $fragment, $incfiles) = @_;
+
+ unless (open (OUT, ">$filename")) {
+ print STDERR "Unable to open $filename\n";
+ return -1;
+ }
+ print OUT '
+/* This file was autogenerated. All changes made will be lost! */
+#include "include/includes.h"
+';
+
+ foreach (@$incfiles) {
+ print OUT "#include \"$_\"\n";
+ }
+
+ print OUT '
+int main(int argc, char **argv)
+{
+ TALLOC_CTX *mem_ctx = talloc_init(NULL);
+ ';
+ print OUT $fragment;
+ print OUT "\treturn 0;\n}\n";
+ close OUT;
+
+ return 0;
+}
+
+sub generate_idlfile($$)
+{
+ my ($filename,$fragment) = @_;
+
+ unless (open(OUT, ">$filename")) {
+ print STDERR "Unable to open $filename\n";
+ return -1;
+ }
+
+ print OUT '
+[uuid("1-2-3-4-5")] interface test_if
+{
+';
+ print OUT $fragment;
+ print OUT "\n}\n";
+ close OUT;
+
+ return 0;
+}
+
+sub compile_idl($$$)
+{
+ my ($filename,$idl_path, $idlargs) = @_;
+
+ my @args = @$idlargs;
+ push (@args, $filename);
+
+ unless (system($idl_path, @args) == 0) {
+ print STDERR "Error compiling IDL file $filename: $!\n";
+ return -1;
+ }
+}
+
+sub compile_cfile($)
+{
+ my ($filename) = @_;
+
+ return system($cc, @cflags, '-I.', '-Iinclude', '-c', $filename);
+}
+
+sub link_files($$)
+{
+ my ($exe_name,$objs) = @_;
+
+ return system($cc, @ldflags, '-Lbin', '-lrpc', '-o', $exe_name, @$objs);
+}
+
+sub test_idl($$$$)
+{
+ my ($name,$settings,$idl,$c) = @_;
+
+ $| = 1;
+
+ print "Running $name... ";
+
+ my $outputdir = $settings->{OutputDir};
+
+ my $c_filename = $outputdir."/".$name."_test.c";
+ my $idl_filename = $outputdir."/".$name."_idl.idl";
+ my $exe_filename = $outputdir."/".$name."_exe";
+
+ return -1 if (generate_cfile($c_filename, $c, $settings->{IncludeFiles}) == -1);
+
+ return -1 if (generate_idlfile($idl_filename, $idl) == -1);
+
+ return -1 if (compile_idl($idl_filename, $settings->{'IDL-Compiler'}, $settings->{'IDL-Arguments'}) == -1);
+
+ my @srcs = ($c_filename);
+ push (@srcs, @{$settings->{'ExtraFiles'}});
+
+ foreach (@srcs) {
+ next unless /\.c$/;
+ return -1 if (compile_cfile($_) == -1);
+ }
+
+ my @objs;
+ foreach (@srcs) {
+ if (/\.c$/) { s/\.c$/\.o/g; }
+ push(@objs, $_);
+ }
+
+ return -1 if (link_files($exe_filename, \@objs) == -1);
+
+ my $ret = system("./$exe_filename");
+ if ($ret != 0) {
+ $ret = $? >> 8;
+ print "failed with return value $ret\n";
+ return $ret;
+ }
+
+ unless ($settings->{Keep}) {
+ unlink(@srcs, @objs, $exe_filename, $idl_filename);
+ }
+
+ print "Ok\n";
+
+ return $ret;
+}
+
+sub GetSettings($)
+{
+ my $settings = {
+ OutputDir => ".",
+ 'IDL-Compiler' => "./build/pidl/pidl.pl"
+ };
+
+ my %opts = ();
+ GetOptions('idl-compiler=s' => \$settings->{'IDL-Compiler'},
+ 'outputdir=s' => \$settings->{OutputDir},
+ 'keep' => \$settings->{Keep},
+ 'help' => sub { ShowHelp(); exit 1; } );
+
+ return %$settings;
+}
+
+sub ShowHelp()
+{
+ print " --idl-compiler=PATH-TO-PIDL Override path to IDL compiler\n";
+ print " --outputdir=OUTPUTDIR Write temporary files to OUTPUTDIR rather then .\n";
+ print " --keep Keep intermediate files after running test";
+ print " --help Show this help message\n";
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Typelist.pm b/source4/build/pidl/Parse/Pidl/Typelist.pm
new file mode 100644
index 0000000000..d134cc6992
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Typelist.pm
@@ -0,0 +1,326 @@
+###################################################
+# Samba4 parser generator for IDL structures
+# Copyright jelmer@samba.org 2005
+# released under the GNU GPL
+
+package Parse::Pidl::Typelist;
+
+use Parse::Pidl::Util;
+use strict;
+
+my %typedefs = ();
+
+# a list of known scalar types
+my $scalars = {
+ # 0 byte types
+ "void" => {
+ C_TYPE => "void",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 0
+ },
+
+ # 1 byte types
+ "char" => {
+ C_TYPE => "char",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 1
+ },
+ "int8" => {
+ C_TYPE => "int8_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 1
+ },
+ "uint8" => {
+ C_TYPE => "uint8_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 1
+ },
+
+ # 2 byte types
+ "int16" => {
+ C_TYPE => "int16_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 2
+ },
+ "uint16" => { C_TYPE => "uint16_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 2
+ },
+
+ # 4 byte types
+ "int32" => {
+ C_TYPE => "int32_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "uint32" => { C_TYPE => "uint32_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+
+ # 8 byte types
+ "hyper" => {
+ C_TYPE => "uint64_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 8
+ },
+ "dlong" => {
+ C_TYPE => "int64_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "udlong" => {
+ C_TYPE => "uint64_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "udlongr" => {
+ C_TYPE => "uint64_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+
+ # DATA_BLOB types
+ "DATA_BLOB" => {
+ C_TYPE => "DATA_BLOB",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+
+ # string types
+ "string" => {
+ C_TYPE => "const char *",
+ IS_REFERENCE => 1,
+ NDR_ALIGN => 4 #???
+ },
+ "string_array" => {
+ C_TYPE => "const char **",
+ IS_REFERENCE => 1,
+ NDR_ALIGN => 4 #???
+ },
+
+ # time types
+ "time_t" => {
+ C_TYPE => "time_t",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "NTTIME" => {
+ C_TYPE => "NTTIME",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "NTTIME_1sec" => {
+ C_TYPE => "NTTIME",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "NTTIME_hyper" => {
+ C_TYPE => "NTTIME",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 8
+ },
+
+
+ # error code types
+ "WERROR" => {
+ C_TYPE => "WERROR",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+ "NTSTATUS" => {
+ C_TYPE => "NTSTATUS",
+ IS_REFERENCE => 0,
+ NDR_ALIGN => 4
+ },
+
+ # special types
+ "nbt_string" => {
+ C_TYPE => "const char *",
+ IS_REFERENCE => 1,
+ NDR_ALIGN => 4 #???
+ },
+ "ipv4address" => {
+ C_TYPE => "const char *",
+ IS_REFERENCE => 1,
+ NDR_ALIGN => 4
+ }
+};
+
+# map from a IDL type to a C header type
+sub mapScalarType($)
+{
+ my $name = shift;
+
+ # it's a bug when a type is not in the list
+ # of known scalars or has no mapping
+ return $typedefs{$name}->{DATA}->{C_TYPE} if defined($typedefs{$name}) and defined($typedefs{$name}->{DATA}->{C_TYPE});
+
+ die("Unknown scalar type $name");
+}
+
+sub getScalarAlignment($)
+{
+ my $name = shift;
+
+ # it's a bug when a type is not in the list
+ # of known scalars or has no mapping
+ return $scalars->{$name}{NDR_ALIGN} if defined($scalars->{$name}) and defined($scalars->{$name}{NDR_ALIGN});
+
+ die("Unknown scalar type $name");
+}
+
+sub addType($)
+{
+ my $t = shift;
+ $typedefs{$t->{NAME}} = $t;
+}
+
+sub getType($)
+{
+ my $t = shift;
+ return undef if not hasType($t);
+ return $typedefs{$t};
+}
+
+sub typeIs($$)
+{
+ my $t = shift;
+ my $tt = shift;
+
+ return 1 if (hasType($t) and getType($t)->{DATA}->{TYPE} eq $tt);
+ return 0;
+}
+
+sub hasType($)
+{
+ my $t = shift;
+ return 1 if defined($typedefs{$t});
+ return 0;
+}
+
+sub is_scalar($)
+{
+ my $type = shift;
+
+ return 0 unless(hasType($type));
+
+ if (my $dt = getType($type)->{DATA}->{TYPE}) {
+ return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
+ }
+
+ return 0;
+}
+
+sub scalar_is_reference($)
+{
+ my $name = shift;
+
+ return $scalars->{$name}{IS_REFERENCE} if defined($scalars->{$name}) and defined($scalars->{$name}{IS_REFERENCE});
+ return 0;
+}
+
+sub RegisterScalars()
+{
+ foreach my $k (keys %{$scalars}) {
+ $typedefs{$k} = {
+ NAME => $k,
+ TYPE => "TYPEDEF",
+ DATA => $scalars->{$k}
+ };
+ $typedefs{$k}->{DATA}->{TYPE} = "SCALAR";
+ $typedefs{$k}->{DATA}->{NAME} = $k;
+ }
+}
+
+my $aliases = {
+ "DWORD" => "uint32",
+ "int" => "int32",
+ "WORD" => "uint16",
+ "char" => "uint8",
+ "long" => "int32",
+ "short" => "int16",
+ "HYPER_T" => "hyper"
+};
+
+sub RegisterAliases()
+{
+ foreach my $k (keys %{$aliases}) {
+ $typedefs{$k} = $typedefs{$aliases->{$k}};
+ }
+}
+
+sub enum_type_fn($)
+{
+ my $enum = shift;
+ if (Parse::Pidl::Util::has_property($enum->{PARENT}, "enum8bit")) {
+ return "uint8";
+ } elsif (Parse::Pidl::Util::has_property($enum->{PARENT}, "v1_enum")) {
+ return "uint32";
+ }
+ return "uint16";
+}
+
+sub bitmap_type_fn($)
+{
+ my $bitmap = shift;
+
+ if (Parse::Pidl::Util::has_property($bitmap, "bitmap8bit")) {
+ return "uint8";
+ } elsif (Parse::Pidl::Util::has_property($bitmap, "bitmap16bit")) {
+ return "uint16";
+ } elsif (Parse::Pidl::Util::has_property($bitmap, "bitmap64bit")) {
+ return "hyper";
+ }
+ return "uint32";
+}
+
+sub mapType($)
+{
+ my $t = shift;
+ die("Undef passed to mapType") unless defined($t);
+ my $dt;
+
+ unless ($dt or ($dt = getType($t))) {
+ # Best guess
+ return "struct $t";
+ }
+ return mapScalarType($t) if ($dt->{DATA}->{TYPE} eq "SCALAR");
+ return "enum $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "ENUM");
+ return "struct $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "STRUCT");
+ return "struct $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "INTERFACE");
+ return "union $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "UNION");
+
+ if ($dt->{DATA}->{TYPE} eq "BITMAP") {
+ return mapScalarType(bitmap_type_fn($dt->{DATA}));
+ }
+
+ die("Unknown type $dt->{DATA}->{TYPE}");
+}
+
+sub LoadIdl($)
+{
+ my $idl = shift;
+
+ foreach my $x (@{$idl}) {
+ next if $x->{TYPE} ne "INTERFACE";
+
+ # DCOM interfaces can be types as well
+ addType({
+ NAME => $x->{NAME},
+ TYPE => "TYPEDEF",
+ DATA => $x
+ }) if (Parse::Pidl::Util::has_property($x, "object"));
+
+ foreach my $y (@{$x->{DATA}}) {
+ addType($y) if (
+ $y->{TYPE} eq "TYPEDEF"
+ or $y->{TYPE} eq "DECLARE");
+ }
+ }
+}
+
+RegisterScalars();
+RegisterAliases();
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Util.pm b/source4/build/pidl/Parse/Pidl/Util.pm
new file mode 100644
index 0000000000..41fde63c25
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Util.pm
@@ -0,0 +1,219 @@
+###################################################
+# utility functions to support pidl
+# Copyright tridge@samba.org 2000
+# released under the GNU GPL
+package Parse::Pidl::Util;
+
+use strict;
+
+#####################################################################
+# flatten an array of arrays into a single array
+sub FlattenArray2($)
+{
+ my $a = shift;
+ my @b;
+ for my $d (@{$a}) {
+ for my $d1 (@{$d}) {
+ push(@b, $d1);
+ }
+ }
+ return \@b;
+}
+
+#####################################################################
+# flatten an array of arrays into a single array
+sub FlattenArray($)
+{
+ my $a = shift;
+ my @b;
+ for my $d (@{$a}) {
+ for my $d1 (@{$d}) {
+ push(@b, $d1);
+ }
+ }
+ return \@b;
+}
+
+#####################################################################
+# flatten an array of hashes into a single hash
+sub FlattenHash($)
+{
+ my $a = shift;
+ my %b;
+ for my $d (@{$a}) {
+ for my $k (keys %{$d}) {
+ $b{$k} = $d->{$k};
+ }
+ }
+ return \%b;
+}
+
+#####################################################################
+# traverse a perl data structure removing any empty arrays or
+# hashes and any hash elements that map to undef
+sub CleanData($)
+{
+ sub CleanData($);
+ my($v) = shift;
+ if (ref($v) eq "ARRAY") {
+ foreach my $i (0 .. $#{$v}) {
+ CleanData($v->[$i]);
+ if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) {
+ $v->[$i] = undef;
+ next;
+ }
+ }
+ # this removes any undefined elements from the array
+ @{$v} = grep { defined $_ } @{$v};
+ } elsif (ref($v) eq "HASH") {
+ foreach my $x (keys %{$v}) {
+ CleanData($v->{$x});
+ if (!defined $v->{$x}) { delete($v->{$x}); next; }
+ if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; }
+ }
+ }
+ return $v;
+}
+
+#####################################################################
+# return the modification time of a file
+sub FileModtime($)
+{
+ my($filename) = shift;
+ return (stat($filename))[9];
+}
+
+#####################################################################
+# read a file into a string
+sub FileLoad($)
+{
+ my($filename) = shift;
+ local(*INPUTFILE);
+ open(INPUTFILE, $filename) || return undef;
+ my($saved_delim) = $/;
+ undef $/;
+ my($data) = <INPUTFILE>;
+ close(INPUTFILE);
+ $/ = $saved_delim;
+ return $data;
+}
+
+#####################################################################
+# write a string into a file
+sub FileSave($$)
+{
+ my($filename) = shift;
+ my($v) = shift;
+ local(*FILE);
+ open(FILE, ">$filename") || die "can't open $filename";
+ print FILE $v;
+ close(FILE);
+}
+
+#####################################################################
+# return a filename with a changed extension
+sub ChangeExtension($$)
+{
+ my($fname) = shift;
+ my($ext) = shift;
+ if ($fname =~ /^(.*)\.(.*?)$/) {
+ return "$1$ext";
+ }
+ return "$fname$ext";
+}
+
+#####################################################################
+# a dumper wrapper to prevent dependence on the Data::Dumper module
+# unless we actually need it
+sub MyDumper($)
+{
+ require Data::Dumper;
+ my $s = shift;
+ return Data::Dumper::Dumper($s);
+}
+
+#####################################################################
+# see if a pidl property list contains a given property
+sub has_property($$)
+{
+ my($e) = shift;
+ my($p) = shift;
+
+ if (!defined $e->{PROPERTIES}) {
+ return undef;
+ }
+
+ return $e->{PROPERTIES}->{$p};
+}
+
+#####################################################################
+# see if a pidl property matches a value
+sub property_matches($$$)
+{
+ my($e) = shift;
+ my($p) = shift;
+ my($v) = shift;
+
+ if (!defined has_property($e, $p)) {
+ return undef;
+ }
+
+ if ($e->{PROPERTIES}->{$p} =~ /$v/) {
+ return 1;
+ }
+
+ return undef;
+}
+
+# return 1 if the string is a C constant
+sub is_constant($)
+{
+ my $s = shift;
+ if (defined $s && $s =~ /^\d/) {
+ return 1;
+ }
+ return 0;
+}
+
+# return a "" quoted string, unless already quoted
+sub make_str($)
+{
+ my $str = shift;
+ if (substr($str, 0, 1) eq "\"") {
+ return $str;
+ }
+ return "\"" . $str . "\"";
+}
+
+# a hack to build on platforms that don't like negative enum values
+my $useUintEnums = 0;
+sub setUseUintEnums($)
+{
+ $useUintEnums = shift;
+}
+sub useUintEnums()
+{
+ return $useUintEnums;
+}
+
+sub ParseExpr($$)
+{
+ my($expr,$varlist) = @_;
+
+ die("Undefined value in ParseExpr") if not defined($expr);
+
+ my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr;
+ my $ret = "";
+
+ foreach my $t (@tokens) {
+ if (defined($varlist->{$t})) {
+ $ret .= $varlist->{$t};
+ } else {
+ $ret .= $t;
+ }
+ }
+
+ return $ret;
+}
+
+1;
diff --git a/source4/build/pidl/Parse/Pidl/Validator.pm b/source4/build/pidl/Parse/Pidl/Validator.pm
new file mode 100644
index 0000000000..53015bc575
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Validator.pm
@@ -0,0 +1,369 @@
+###################################################
+# check that a parsed IDL file is valid
+# Copyright tridge@samba.org 2003
+# released under the GNU GPL
+
+package Parse::Pidl::Validator;
+
+use strict;
+
+#####################################################################
+# signal a fatal validation error
+sub fatal($$)
+{
+ my ($pos,$s) = @_;
+ die("$pos->{FILE}:$pos->{LINE}:$s\n");
+}
+
+sub nonfatal($$)
+{
+ my ($pos,$s) = @_;
+ warn ("$pos->{FILE}:$pos->{LINE}:warning:$s\n");
+}
+
+sub el_name($)
+{
+ my $e = shift;
+
+ if ($e->{PARENT} && $e->{PARENT}->{NAME}) {
+ return "$e->{PARENT}->{NAME}.$e->{NAME}";
+ }
+
+ if ($e->{PARENT} && $e->{PARENT}->{PARENT}->{NAME}) {
+ return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
+ }
+
+ if ($e->{PARENT}) {
+ return "$e->{PARENT}->{NAME}.$e->{NAME}";
+ }
+ return $e->{NAME};
+}
+
+###################################
+# find a sibling var in a structure
+sub find_sibling($$)
+{
+ my($e,$name) = @_;
+ my($fn) = $e->{PARENT};
+
+ if ($name =~ /\*(.*)/) {
+ $name = $1;
+ }
+
+ for my $e2 (@{$fn->{ELEMENTS}}) {
+ return $e2 if ($e2->{NAME} eq $name);
+ }
+
+ return undef;
+}
+
+my %property_list = (
+ # interface
+ "helpstring" => ["INTERFACE", "FUNCTION"],
+ "version" => ["INTERFACE"],
+ "uuid" => ["INTERFACE"],
+ "endpoint" => ["INTERFACE"],
+ "pointer_default" => ["INTERFACE"],
+ "pointer_default_top" => ["INTERFACE"],
+ "depends" => ["INTERFACE"],
+ "authservice" => ["INTERFACE"],
+
+ # dcom
+ "object" => ["INTERFACE"],
+ "local" => ["INTERFACE", "FUNCTION"],
+ "iid_is" => ["ELEMENT"],
+ "call_as" => ["FUNCTION"],
+ "idempotent" => ["FUNCTION"],
+
+ # function
+ "noopnum" => ["FUNCTION"],
+ "in" => ["ELEMENT"],
+ "out" => ["ELEMENT"],
+
+ # pointer
+ "ref" => ["ELEMENT"],
+ "ptr" => ["ELEMENT"],
+ "sptr" => ["ELEMENT"],
+ "unique" => ["ELEMENT"],
+ "ignore" => ["ELEMENT"],
+ "relative" => ["ELEMENT"],
+ "relative_base" => ["TYPEDEF"],
+
+ "gensize" => ["TYPEDEF"],
+ "value" => ["ELEMENT"],
+ "flag" => ["ELEMENT", "TYPEDEF"],
+
+ # generic
+ "public" => ["FUNCTION", "TYPEDEF"],
+ "nopush" => ["FUNCTION", "TYPEDEF"],
+ "nopull" => ["FUNCTION", "TYPEDEF"],
+ "noprint" => ["FUNCTION", "TYPEDEF"],
+ "noejs" => ["FUNCTION", "TYPEDEF"],
+
+ # union
+ "switch_is" => ["ELEMENT"],
+ "switch_type" => ["ELEMENT", "TYPEDEF"],
+ "nodiscriminant" => ["TYPEDEF"],
+ "case" => ["ELEMENT"],
+ "default" => ["ELEMENT"],
+
+ # subcontext
+ "subcontext" => ["ELEMENT"],
+ "subcontext_size" => ["ELEMENT"],
+ "compression" => ["ELEMENT"],
+ "obfuscation" => ["ELEMENT"],
+
+ # enum
+ "enum8bit" => ["TYPEDEF"],
+ "enum16bit" => ["TYPEDEF"],
+ "v1_enum" => ["TYPEDEF"],
+
+ # bitmap
+ "bitmap8bit" => ["TYPEDEF"],
+ "bitmap16bit" => ["TYPEDEF"],
+ "bitmap32bit" => ["TYPEDEF"],
+ "bitmap64bit" => ["TYPEDEF"],
+
+ # array
+ "range" => ["ELEMENT"],
+ "size_is" => ["ELEMENT"],
+ "string" => ["ELEMENT"],
+ "noheader" => ["ELEMENT"],
+ "charset" => ["ELEMENT"],
+ "length_is" => ["ELEMENT"],
+);
+
+#####################################################################
+# check for unknown properties
+sub ValidProperties($$)
+{
+ my ($e,$t) = @_;
+
+ return unless defined $e->{PROPERTIES};
+
+ foreach my $key (keys %{$e->{PROPERTIES}}) {
+ fatal($e, el_name($e) . ": unknown property '$key'\n")
+ unless defined($property_list{$key});
+
+ fatal($e, el_name($e) . ": property '$key' not allowed on '$t'\n")
+ unless grep($t, @{$property_list{$key}});
+ }
+}
+
+sub mapToScalar($)
+{
+ my $t = shift;
+ my $ti = Parse::Pidl::Typelist::getType($t);
+
+ if (not defined ($ti)) {
+ return undef;
+ } elsif ($ti->{DATA}->{TYPE} eq "ENUM") {
+ return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
+ } elsif ($ti->{DATA}->{TYPE} eq "BITMAP") {
+ return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
+ } elsif ($ti->{DATA}->{TYPE} eq "SCALAR") {
+ return $t;
+ }
+
+ return undef;
+}
+
+#####################################################################
+# parse a struct
+sub ValidElement($)
+{
+ my $e = shift;
+
+ ValidProperties($e,"ELEMENT");
+
+ if (Parse::Pidl::Util::has_property($e, "ptr")) {
+ fatal($e, el_name($e) . " : pidl does not support full NDR pointers yet\n");
+ }
+
+ # Check whether switches are used correctly.
+ if (my $switch = Parse::Pidl::Util::has_property($e, "switch_is")) {
+ my $e2 = find_sibling($e, $switch);
+ my $type = Parse::Pidl::Typelist::getType($e->{TYPE});
+
+ if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
+ fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
+ }
+
+ if (!Parse::Pidl::Util::has_property($type, "nodiscriminant") and defined($e2)) {
+ my $discriminator_type = Parse::Pidl::Util::has_property($type, "switch_type");
+ $discriminator_type = "uint32" unless defined ($discriminator_type);
+
+ my $t1 = mapToScalar($discriminator_type);
+
+ if (not defined($t1)) {
+ fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
+ }
+
+ my $t2 = mapToScalar($e2->{TYPE});
+ if (not defined($t2)) {
+ fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
+ }
+
+ if ($t1 ne $t2) {
+ nonfatal($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
+ }
+ }
+ }
+
+ if (defined (Parse::Pidl::Util::has_property($e, "subcontext_size")) and not defined(Parse::Pidl::Util::has_property($e, "subcontext"))) {
+ fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
+ }
+
+ if (defined (Parse::Pidl::Util::has_property($e, "compression")) and not defined(Parse::Pidl::Util::has_property($e, "subcontext"))) {
+ fatal($e, el_name($e) . " : compression() on non-subcontext element");
+ }
+
+ if (defined (Parse::Pidl::Util::has_property($e, "obfuscation")) and not defined(Parse::Pidl::Util::has_property($e, "subcontext"))) {
+ fatal($e, el_name($e) . " : obfuscation() on non-subcontext element");
+ }
+
+ if (!$e->{POINTERS} && (
+ Parse::Pidl::Util::has_property($e, "ptr") or
+ Parse::Pidl::Util::has_property($e, "sptr") or
+ Parse::Pidl::Util::has_property($e, "unique") or
+ Parse::Pidl::Util::has_property($e, "relative") or
+ Parse::Pidl::Util::has_property($e, "ref"))) {
+ fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
+ }
+}
+
+#####################################################################
+# parse a struct
+sub ValidStruct($)
+{
+ my($struct) = shift;
+
+ ValidProperties($struct,"STRUCT");
+
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ $e->{PARENT} = $struct;
+ ValidElement($e);
+ }
+}
+
+#####################################################################
+# parse a union
+sub ValidUnion($)
+{
+ my($union) = shift;
+
+ ValidProperties($union,"UNION");
+
+ if (Parse::Pidl::Util::has_property($union->{PARENT}, "nodiscriminant") and Parse::Pidl::Util::has_property($union->{PARENT}, "switch_type")) {
+ fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type() on union without discriminant");
+ }
+
+ foreach my $e (@{$union->{ELEMENTS}}) {
+ $e->{PARENT} = $union;
+
+ if (defined($e->{PROPERTIES}->{default}) and
+ defined($e->{PROPERTIES}->{case})) {
+ fatal $e, "Union member $e->{NAME} can not have both default and case properties!\n";
+ }
+
+ unless (defined ($e->{PROPERTIES}->{default}) or
+ defined ($e->{PROPERTIES}->{case})) {
+ fatal $e, "Union member $e->{NAME} must have default or case property\n";
+ }
+
+ if (Parse::Pidl::Util::has_property($e, "ref")) {
+ fatal($e, el_name($e) . " : embedded ref pointers are not supported yet\n");
+ }
+
+
+ ValidElement($e);
+ }
+}
+
+#####################################################################
+# parse a typedef
+sub ValidTypedef($)
+{
+ my($typedef) = shift;
+ my $data = $typedef->{DATA};
+
+ ValidProperties($typedef,"TYPEDEF");
+
+ $data->{PARENT} = $typedef;
+
+ if (ref($data) eq "HASH") {
+ if ($data->{TYPE} eq "STRUCT") {
+ ValidStruct($data);
+ }
+
+ if ($data->{TYPE} eq "UNION") {
+ ValidUnion($data);
+ }
+ }
+}
+
+#####################################################################
+# parse a function
+sub ValidFunction($)
+{
+ my($fn) = shift;
+
+ ValidProperties($fn,"FUNCTION");
+
+ foreach my $e (@{$fn->{ELEMENTS}}) {
+ $e->{PARENT} = $fn;
+ if (Parse::Pidl::Util::has_property($e, "ref") && !$e->{POINTERS}) {
+ fatal $e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})\n";
+ }
+ ValidElement($e);
+ }
+}
+
+#####################################################################
+# parse the interface definitions
+sub ValidInterface($)
+{
+ my($interface) = shift;
+ my($data) = $interface->{DATA};
+
+ ValidProperties($interface,"INTERFACE");
+
+ if (Parse::Pidl::Util::has_property($interface, "pointer_default") &&
+ $interface->{PROPERTIES}->{pointer_default} eq "ptr") {
+ fatal $interface, "Full pointers are not supported yet\n";
+ }
+
+ if (Parse::Pidl::Util::has_property($interface, "object")) {
+ if (Parse::Pidl::Util::has_property($interface, "version") &&
+ $interface->{PROPERTIES}->{version} != 0) {
+ fatal $interface, "Object interfaces must have version 0.0 ($interface->{NAME})\n";
+ }
+
+ if (!defined($interface->{BASE}) &&
+ not ($interface->{NAME} eq "IUnknown")) {
+ fatal $interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})\n";
+ }
+ }
+
+ foreach my $d (@{$data}) {
+ ($d->{TYPE} eq "TYPEDEF") &&
+ ValidTypedef($d);
+ ($d->{TYPE} eq "FUNCTION") &&
+ ValidFunction($d);
+ }
+
+}
+
+#####################################################################
+# parse a parsed IDL into a C header
+sub Validate($)
+{
+ my($idl) = shift;
+
+ foreach my $x (@{$idl}) {
+ ($x->{TYPE} eq "INTERFACE") &&
+ ValidInterface($x);
+ }
+}
+
+1;