diff options
author | Jörg Mayer <jmayer@loplof.de> | 2006-03-30 07:44:03 +0000 |
---|---|---|
committer | Jörg Mayer <jmayer@loplof.de> | 2006-03-30 07:44:03 +0000 |
commit | 9ba859bacf860117c12778e75bcde2f4634c1133 (patch) | |
tree | 2574eae5508ad72fb7c18837d97d43d64b51280a /tools/pidl | |
parent | e4f01d2051b83f3114cf993ccb33c1f8164b04b2 (diff) |
Update from samba tree revision 13374 to 14805
============================ Samba log start ============
svn: When specifying working copy paths, only one target may be given
============================ Samba log end ==============
svn path=/trunk/; revision=17767
Diffstat (limited to 'tools/pidl')
21 files changed, 370 insertions, 252 deletions
diff --git a/tools/pidl/TODO b/tools/pidl/TODO index a99a4f3f5f..3098a44a8f 100644 --- a/tools/pidl/TODO +++ b/tools/pidl/TODO @@ -11,6 +11,10 @@ - auto-alloc [ref] pointers for Samba4 during pull if they were NULL -- replace subcontext() with represent_as() +- improve represent_as() - --explain-ndr option that dumps out parse tree ? + +- seperate tables for NDR and DCE/RPC + +- allow data structures outside of interfaces diff --git a/tools/pidl/lib/Parse/Pidl/Compat.pm b/tools/pidl/lib/Parse/Pidl/Compat.pm index f0b8cc7b0b..944193ac1b 100644 --- a/tools/pidl/lib/Parse/Pidl/Compat.pm +++ b/tools/pidl/lib/Parse/Pidl/Compat.pm @@ -124,10 +124,6 @@ sub CheckElement($) warning($e, "compression() property not supported"); } - if (has_property($e, "obfuscation")) { - warning($e, "obfuscation() property not supported"); - } - if (has_property($e, "sptr")) { warning($e, "sptr() pointer property not supported"); } diff --git a/tools/pidl/lib/Parse/Pidl/NDR.pm b/tools/pidl/lib/Parse/Pidl/NDR.pm index 179d2ecb12..1efd0694e5 100644 --- a/tools/pidl/lib/Parse/Pidl/NDR.pm +++ b/tools/pidl/lib/Parse/Pidl/NDR.pm @@ -2,7 +2,7 @@ # Samba4 NDR info tree generator # Copyright tridge@samba.org 2000-2003 # Copyright tpot@samba.org 2001 -# Copyright jelmer@samba.org 2004-2005 +# Copyright jelmer@samba.org 2004-2006 # released under the GNU GPL =pod @@ -51,6 +51,7 @@ my $scalar_alignment = { 'int32' => 4, 'uint32' => 4, 'hyper' => 8, + 'pointer' => 8, 'dlong' => 4, 'udlong' => 4, 'udlongr' => 4, @@ -231,7 +232,6 @@ sub GetElementLevelTable($) SUBCONTEXT_SIZE => $subsize, IS_DEFERRED => $is_deferred, COMPRESSION => has_property($e, "compression"), - OBFUSCATION => has_property($e, "obfuscation") }); } @@ -257,6 +257,8 @@ sub GetElementLevelTable($) push (@$order, { TYPE => "DATA", + CONVERT_TO => has_property($e, ""), + CONVERT_FROM => has_property($e, ""), DATA_TYPE => $e->{TYPE}, IS_DEFERRED => $is_deferred, CONTAINS_DEFERRED => can_contain_deferred($e), @@ -316,8 +318,10 @@ sub find_largest_alignment($) if ($e->{POINTERS}) { $a = 4; - } elsif (has_property($e, "subcontext")){ + } elsif (has_property($e, "subcontext")) { $a = 1; + } elsif (has_property($e, "transmit_as")) { + $a = align_type($e->{PROPERTIES}->{transmit_as}); } else { $a = align_type($e->{TYPE}); } @@ -365,6 +369,7 @@ sub ParseElement($) TYPE => $e->{TYPE}, PROPERTIES => $e->{PROPERTIES}, LEVELS => GetElementLevelTable($e), + REPRESENTATION_TYPE => $e->{PROPERTIES}->{represent_as}, ALIGN => align_type($e->{TYPE}), ORIGINAL => $e }; @@ -749,6 +754,7 @@ my %property_list = ( "pointer_default" => ["INTERFACE"], "pointer_default_top" => ["INTERFACE"], "depends" => ["INTERFACE"], + "helper" => ["INTERFACE"], "authservice" => ["INTERFACE"], # dcom @@ -791,11 +797,13 @@ my %property_list = ( "case" => ["ELEMENT"], "default" => ["ELEMENT"], + "represent_as" => ["ELEMENT"], + "transmit_as" => ["ELEMENT"], + # subcontext "subcontext" => ["ELEMENT"], "subcontext_size" => ["ELEMENT"], "compression" => ["ELEMENT"], - "obfuscation" => ["ELEMENT"], # enum "enum8bit" => ["TYPEDEF"], @@ -894,6 +902,23 @@ sub ValidElement($) } } + + if (has_property($e, "subcontext") and has_property($e, "represent_as")) { + fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element"); + } + + if (has_property($e, "subcontext") and has_property($e, "transmit_as")) { + fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element"); + } + + if (has_property($e, "represent_as") and has_property($e, "transmit_as")) { + fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element"); + } + + if (has_property($e, "represent_as") and has_property($e, "value")) { + fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element"); + } + if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) { fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element"); } @@ -902,10 +927,6 @@ sub ValidElement($) fatal($e, el_name($e) . " : compression() on non-subcontext element"); } - if (defined (has_property($e, "obfuscation")) and not defined(has_property($e, "subcontext"))) { - fatal($e, el_name($e) . " : obfuscation() on non-subcontext element"); - } - if (!$e->{POINTERS} && ( has_property($e, "ptr") or has_property($e, "sptr") or diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm index ceeb81c3d7..59f0341d02 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -19,8 +19,8 @@ my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{FILE}:$e->{LINE}: $s\n"); } +sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } +sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } sub CopyLevel($$$$) { diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm index fb02120a42..c479b14afa 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -19,8 +19,8 @@ my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{FILE}:$e->{LINE}: $s\n"); } +sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } +sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } sub ParseElement($) { @@ -32,7 +32,8 @@ sub ParseElement($) pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; } elsif ($l->{TYPE} eq "SWITCH") { } elsif ($l->{TYPE} eq "DATA") { - pidl "\t" . DeclShort($e) . ";"; + my $n = DeclShort($e); + pidl "\t$n;" if ($n); } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { my ($t,$f) = StringType($e,$l); pidl "\t" . uc($t) . " $e->{NAME};"; diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm index c12f7554e9..a6b4b38cdf 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -22,7 +22,7 @@ my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } +sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } #TODO: # - Add some security checks (array sizes, memory alloc == NULL, etc) diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm index 072aa07850..47d565dce6 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/Template.pm @@ -45,16 +45,32 @@ sub Parse($$) $res = ""; - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * template auto-generated by pidl. Modify to your needs"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl ""; - pidl "#undef DBGC_CLASS"; - pidl "#define DBGC_CLASS DBGC_MSRPC"; - pidl ""; + pidl "/* + * Unix SMB/CIFS implementation. + **** template auto-generated by pidl. Modify to your needs **** + * RPC Pipe client / server routines + * Copyright (C) YOUR NAME 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\" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_MSRPC +"; foreach (@$ndr) { ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); diff --git a/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm b/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm index d1f1032714..666d23e669 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -18,7 +18,7 @@ $VERSION = '0.01'; # TODO: Find external types somehow? -sub warning($$) { my ($e,$s) = @_; print STDERR "$e->{FILE}:$e->{LINE}: $s\n"; } +sub warning($$) { my ($e,$s) = @_; print STDERR "$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"; } sub init_scalar($$$$) { @@ -144,6 +144,12 @@ my $known_types = INIT => \&init_scalar, DISSECT_P => \&dissect_scalar, }, + int32 => + { + DECL => "int32", + INIT => \&init_scalar, + DISSECT_P => \&dissect_scalar, + }, string => { DECL => \&decl_string, @@ -199,6 +205,15 @@ my $known_types = return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; } }, + security_descriptor => + { + DECL => "SEC_DESC", + INIT => "", + DISSECT_P => sub { + my ($e,$l,$n,$w,$a) = @_; + return "sec_io_desc(\"$e->{NAME}\", &n, ps, depth)"; + } + }, hyper => { DECL => "uint64", @@ -228,7 +243,7 @@ sub DeclShort($) my $t = $known_types->{$e->{TYPE}}; if (not $t) { - warning($e, "Can't declare unknown type $e->{TYPE}"); + warning($e, "Can't declare unknown type `$e->{TYPE}'"); return undef; } @@ -262,7 +277,7 @@ sub DeclLong($) my $t = $known_types->{$e->{TYPE}}; if (not $t) { - warning($e, "Can't declare unknown type $e->{TYPE}"); + warning($e, "Can't declare unknown type `$e->{TYPE}'"); return undef; } diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/COM/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba4/COM/Header.pm index 83df9afe88..85dab37246 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/COM/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/COM/Header.pm @@ -117,19 +117,22 @@ sub ParseCoClass($) return $res; } -sub Parse($) +sub Parse($$) { - my $idl = shift; + my ($idl,$ndr_header) = @_; my $res = ""; - foreach my $x (@{$idl}) + $res .= "#include \"librpc/gen_ndr/orpc.h\"\n" . + "#include \"$ndr_header\"\n\n"; + + foreach (@{$idl}) { - if ($x->{TYPE} eq "INTERFACE" && has_property($x, "object")) { - $res.=ParseInterface($x); + if ($_->{TYPE} eq "INTERFACE" && has_property($_, "object")) { + $res.=ParseInterface($_); } - if ($x->{TYPE} eq "COCLASS") { - $res.=ParseCoClass($x); + if ($_->{TYPE} eq "COCLASS") { + $res.=ParseCoClass($_); } } diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm b/tools/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm index c0d460fe09..e6366f0f3d 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/COM/Proxy.pm @@ -196,17 +196,21 @@ sub RegistrationFunction($$) return $res; } -sub Parse($) +sub Parse($$) { - my $pidl = shift; + my ($pidl,$comh_filename) = @_; my $res = ""; - foreach my $x (@{$pidl}) { - next if ($x->{TYPE} ne "INTERFACE"); - next if has_property($x, "local"); - next unless has_property($x, "object"); + $res .= "#include \"includes.h\"\n" . + "#include \"lib/com/dcom/dcom.h\"\n" . + "#include \"$comh_filename\"\n"; - $res .= ParseInterface($x); + foreach (@{$pidl}) { + next if ($_->{TYPE} ne "INTERFACE"); + next if has_property($_, "local"); + next unless has_property($_, "object"); + + $res .= ParseInterface($_); } return $res; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm index d5e1405c30..41ea1e8eaa 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -124,7 +124,7 @@ sub fn_declare($$) if (has_property($fn, "public")) { pidl_hdr "$decl;\n"; - pidl "$decl"; + pidl "_PUBLIC_ $decl"; } else { pidl "static $decl"; } @@ -797,6 +797,7 @@ sub Parse($$) pidl " /* EJS wrapper functions auto-generated by pidl */ #include \"includes.h\" +#include \"librpc/rpc/dcerpc.h\" #include \"lib/appweb/ejs/ejs.h\" #include \"scripting/ejs/ejsrpc.h\" #include \"scripting/ejs/smbcalls.h\" diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm index 46caba731a..6fb3ee2eec 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -10,6 +10,7 @@ use strict; use Parse::Pidl::Typelist qw(mapType); use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel GetPrevLevel); +use Parse::Pidl::Samba4 qw(is_intree); use vars qw($VERSION); $VERSION = '0.01'; @@ -54,19 +55,23 @@ sub HeaderElement($) my($element) = shift; pidl tabs(); - HeaderType($element, $element->{TYPE}, ""); - pidl " "; - my $numstar = $element->{POINTERS}; - if ($numstar >= 1) { - $numstar-- if Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE}); - } - foreach (@{$element->{ARRAY_LEN}}) - { - next if is_constant($_) and - not has_property($element, "charset"); - $numstar++; + if (has_property($element, "represent_as")) { + pidl mapType($element->{PROPERTIES}->{represent_as})." "; + } else { + HeaderType($element, $element->{TYPE}, ""); + pidl " "; + my $numstar = $element->{POINTERS}; + if ($numstar >= 1) { + $numstar-- if Parse::Pidl::Typelist::scalar_is_reference($element->{TYPE}); + } + foreach (@{$element->{ARRAY_LEN}}) + { + next if is_constant($_) and + not has_property($element, "charset"); + $numstar++; + } + pidl "*" foreach (1..$numstar); } - pidl "*" foreach (1..$numstar); pidl $element->{NAME}; foreach (@{$element->{ARRAY_LEN}}) { next unless (is_constant($_) and @@ -90,8 +95,8 @@ sub HeaderStruct($$) $tab_depth++; my $el_count=0; if (defined $struct->{ELEMENTS}) { - foreach my $e (@{$struct->{ELEMENTS}}) { - HeaderElement($e); + foreach (@{$struct->{ELEMENTS}}) { + HeaderElement($_); $el_count++; } } @@ -236,10 +241,8 @@ sub HeaderFunctionInOut($$) { my($fn,$prop) = @_; - foreach my $e (@{$fn->{ELEMENTS}}) { - if (has_property($e, $prop)) { - HeaderElement($e); - } + foreach (@{$fn->{ELEMENTS}}) { + HeaderElement($_) if (has_property($_, $prop)); } } @@ -349,6 +352,10 @@ sub Parse($) $res = ""; %headerstructs = (); pidl "/* header auto-generated by pidl */\n\n"; + if (!is_intree()) { + pidl "#include <core.h>\n\n"; + } + foreach (@{$idl}) { ($_->{TYPE} eq "INTERFACE") && HeaderInterface($_); } diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm index 83f9034c7c..ace1e79672 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm @@ -1,16 +1,19 @@ ################################################### # client calls generator # Copyright tridge@samba.org 2003 +# Copyright jelmer@samba.org 2005-2006 # released under the GNU GPL package Parse::Pidl::Samba4::NDR::Client; +use Parse::Pidl::Samba4 qw(choose_header is_intree); + use vars qw($VERSION); $VERSION = '0.01'; use strict; -my($res); +my($res,$res_hdr); ##################################################################### # parse a function @@ -20,6 +23,10 @@ sub ParseFunction($$) my $name = $fn->{NAME}; my $uname = uc $name; + $res_hdr .= "\nstruct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r); +NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r); +"; + $res .= " struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r) { @@ -40,7 +47,7 @@ NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name * status = dcerpc_ndr_request_recv(req); - if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) { + if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) { NDR_PRINT_OUT_DEBUG($name, r); } "; @@ -62,6 +69,14 @@ my %done; sub ParseInterface($) { my($interface) = shift; + + $res_hdr .= "#ifndef _HEADER_RPC_$interface->{NAME}\n"; + $res_hdr .= "#define _HEADER_RPC_$interface->{NAME}\n\n"; + + if (defined $interface->{PROPERTIES}->{uuid}) { + $res_hdr .= "extern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};\n"; + } + $res .= "/* $interface->{NAME} - client functions generated by pidl */\n\n"; foreach my $fn (@{$interface->{FUNCTIONS}}) { @@ -71,32 +86,42 @@ sub ParseInterface($) $done{$fn->{NAME}} = 1; } + $res_hdr .= "#endif /* _HEADER_RPC_$interface->{NAME} */\n"; + return $res; } -sub Parse($$) +sub Parse($$$$) { - my($ndr) = shift; - my($filename) = shift; + my($ndr,$header,$ndr_header,$client_header) = @_; - my $h_filename = $filename; $res = ""; - - if ($h_filename =~ /(.*)\.c/) { - $h_filename = "$1.h"; - } + $res_hdr = ""; $res .= "/* client functions auto-generated by pidl */\n"; $res .= "\n"; - $res .= "#include \"includes.h\"\n"; - $res .= "#include \"$h_filename\"\n"; + if (is_intree()) { + $res .= "#include \"includes.h\"\n"; + } else { + $res .= "#define _GNU_SOURCE\n"; + $res .= "#include <stdio.h>\n"; + $res .= "#include <stdlib.h>\n"; + $res .= "#include <stdint.h>\n"; + $res .= "#include <stdarg.h>\n"; + $res .= "#include <core/nterr.h>\n"; + } + $res .= "#include \"$ndr_header\"\n"; + $res .= "#include \"$client_header\"\n"; $res .= "\n"; + $res_hdr .= choose_header("librpc/rpc/dcerpc.h", "dcerpc.h")."\n"; + $res_hdr .= "#include \"$header\"\n"; + foreach my $x (@{$ndr}) { ($x->{TYPE} eq "INTERFACE") && ParseInterface($x); } - return $res; + return ($res,$res_hdr); } 1; diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 5d01531eb7..07128568bd 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2,7 +2,7 @@ # Samba4 NDR parser generator for IDL structures # Copyright tridge@samba.org 2000-2003 # Copyright tpot@samba.org 2001 -# Copyright jelmer@samba.org 2004-2005 +# Copyright jelmer@samba.org 2004-2006 # released under the GNU GPL package Parse::Pidl::Samba4::NDR::Parser; @@ -11,6 +11,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); use Parse::Pidl::Util qw(has_property ParseExpr print_uuid); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba4 qw(is_intree choose_header); use vars qw($VERSION); $VERSION = '0.01'; @@ -199,7 +200,7 @@ sub fn_declare($$) if (has_property($fn, "public")) { pidl_hdr "$decl;"; - pidl "$decl"; + pidl "_PUBLIC_ $decl"; } else { pidl "static $decl"; } @@ -463,42 +464,6 @@ sub ParseCompressionPullEnd($$$$) pidl "}"; } -sub ParseObfuscationPushStart($$) -{ - my ($e,$ndr) = @_; - my $obfuscation = has_property($e, "obfuscation"); - - pidl "NDR_CHECK(ndr_push_obfuscation_start($ndr, $obfuscation));"; - - return $ndr; -} - -sub ParseObfuscationPushEnd($$) -{ - my ($e,$ndr) = @_; - my $obfuscation = has_property($e, "obfuscation"); - - pidl "NDR_CHECK(ndr_push_obfuscation_end($ndr, $obfuscation));"; -} - -sub ParseObfuscationPullStart($$) -{ - my ($e,$ndr) = @_; - my $obfuscation = has_property($e, "obfuscation"); - - pidl "NDR_CHECK(ndr_pull_obfuscation_start($ndr, $obfuscation));"; - - return $ndr; -} - -sub ParseObfuscationPullEnd($$) -{ - my ($e,$ndr) = @_; - my $obfuscation = has_property($e, "obfuscation"); - - pidl "NDR_CHECK(ndr_pull_obfuscation_end($ndr, $obfuscation));"; -} - sub ParseSubcontextPushStart($$$$) { my ($e,$l,$ndr,$env) = @_; @@ -514,10 +479,6 @@ sub ParseSubcontextPushStart($$$$) $subndr = ParseCompressionPushStart($e, $l, $subndr, $env); } - if (defined $l->{OBFUSCATION}) { - $subndr = ParseObfuscationPushStart($e, $subndr); - } - return $subndr; } @@ -531,10 +492,6 @@ sub ParseSubcontextPushEnd($$$$) ParseCompressionPushEnd($e, $l, $subndr, $env); } - if (defined $l->{OBFUSCATION}) { - ParseObfuscationPushEnd($e, $subndr); - } - pidl "NDR_CHECK(ndr_push_subcontext_end($ndr, $subndr, $l->{HEADER_SIZE}, $subcontext_size));"; deindent; pidl "}"; @@ -555,10 +512,6 @@ sub ParseSubcontextPullStart($$$$) $subndr = ParseCompressionPullStart($e, $l, $subndr, $env); } - if (defined $l->{OBFUSCATION}) { - $subndr = ParseObfuscationPullStart($e, $subndr); - } - return $subndr; } @@ -572,10 +525,6 @@ sub ParseSubcontextPullEnd($$$$) ParseCompressionPullEnd($e, $l, $subndr, $env); } - if (defined $l->{OBFUSCATION}) { - ParseObfuscationPullEnd($e, $subndr); - } - pidl "NDR_CHECK(ndr_pull_subcontext_end($ndr, $subndr, $l->{HEADER_SIZE}, $subcontext_size));"; deindent; pidl "}"; @@ -669,10 +618,20 @@ sub ParseElementPush($$$$$$) my $var_name = $var_prefix.$e->{NAME}; - $var_name = append_prefix($e, $var_name); - return unless $primitives or ($deferred and ContainsDeferred($e, $e->{LEVELS}[0])); + # Representation type is different from transmit_as + if ($e->{REPRESENTATION_TYPE}) { + pidl "{"; + indent; + my $transmit_name = "_transmit_$e->{NAME}"; + pidl mapType($e->{TYPE}) ." $transmit_name;"; + pidl "NDR_CHECK(ndr_$e->{REPRESENTATION_TYPE}_to_$e->{TYPE}($var_name, " . get_pointer_to($transmit_name) . "));"; + $var_name = $transmit_name; + } + + $var_name = append_prefix($e, $var_name); + start_flags($e); if (my $value = has_property($e, "value")) { @@ -682,6 +641,11 @@ sub ParseElementPush($$$$$$) ParseElementPushLevel($e, $e->{LEVELS}[0], $ndr, $var_name, $env, $primitives, $deferred); end_flags($e); + + if ($e->{REPRESENTATION_TYPE}) { + deindent; + pidl "}"; + } } ##################################################################### @@ -713,9 +677,15 @@ sub ParseElementPrint($$$) { my($e,$var_name,$env) = @_; - $var_name = append_prefix($e, $var_name); return if (has_property($e, "noprint")); + if ($e->{REPRESENTATION_TYPE}) { + pidl "ndr_print_$e->{REPRESENTATION_TYPE}(ndr, \"$e->{NAME}\", $var_name);"; + return; + } + + $var_name = append_prefix($e, $var_name); + if (my $value = has_property($e, "value")) { $var_name = "(ndr->flags & LIBNDR_PRINT_SET_VALUES)?" . ParseExpr($value,$env) . ":$var_name"; } @@ -1056,16 +1026,34 @@ sub ParseElementPull($$$$$$) my($e,$ndr,$var_prefix,$env,$primitives,$deferred) = @_; my $var_name = $var_prefix.$e->{NAME}; - - $var_name = append_prefix($e, $var_name); + my $represent_name; + my $transmit_name; return unless $primitives or ($deferred and ContainsDeferred($e, $e->{LEVELS}[0])); + if ($e->{REPRESENTATION_TYPE}) { + pidl "{"; + indent; + $represent_name = $var_name; + $transmit_name = "_transmit_$e->{NAME}"; + $var_name = $transmit_name; + pidl mapType($e->{TYPE})." $var_name;"; + } + + $var_name = append_prefix($e, $var_name); + start_flags($e); ParseElementPullLevel($e,$e->{LEVELS}[0],$ndr,$var_name,$env,$primitives,$deferred); end_flags($e); + + # Representation type is different from transmit_as + if ($e->{REPRESENTATION_TYPE}) { + pidl "NDR_CHECK(ndr_$e->{TYPE}_to_$e->{REPRESENTATION_TYPE}($transmit_name, ".get_pointer_to($represent_name)."));"; + deindent; + pidl "}"; + } } ##################################################################### @@ -1377,18 +1365,15 @@ sub ParseStructPrint($$) EnvSubstituteValue($env, $struct); - foreach my $e (@{$struct->{ELEMENTS}}) { - DeclareArrayVariables($e); - } + DeclareArrayVariables($_) foreach (@{$struct->{ELEMENTS}}); pidl "ndr_print_struct(ndr, name, \"$name\");"; start_flags($struct); pidl "ndr->depth++;"; - foreach my $e (@{$struct->{ELEMENTS}}) { - ParseElementPrint($e, "r->$e->{NAME}", $env); - } + + ParseElementPrint($_, "r->$_->{NAME}", $env) foreach (@{$struct->{ELEMENTS}}); pidl "ndr->depth--;"; end_flags($struct); @@ -1867,7 +1852,7 @@ sub ParseTypedefPrint($) my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"print"); - pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)"; + pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)"; pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);"; pidl "{"; indent; @@ -1904,7 +1889,7 @@ sub ParseFunctionPrint($) return if 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 "_PUBLIC_ void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r)"; pidl_hdr "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r);"; pidl "{"; indent; @@ -2215,8 +2200,10 @@ sub FunctionTable($) pidl "\nconst struct dcerpc_interface_table dcerpc_table_$interface->{NAME} = {"; pidl "\t.name\t\t= \"$interface->{NAME}\","; - pidl "\t.uuid\t\t= ". print_uuid($interface->{UUID}) .","; - pidl "\t.if_version\t= DCERPC_$uname\_VERSION,"; + pidl "\t.syntax_id\t= {"; + pidl "\t\t" . print_uuid($interface->{UUID}) .","; + pidl "\t\tDCERPC_$uname\_VERSION"; + pidl "\t},"; pidl "\t.helpstring\t= DCERPC_$uname\_HELPSTRING,"; pidl "\t.num_calls\t= $count,"; pidl "\t.calls\t\t= $interface->{NAME}\_calls,"; @@ -2237,15 +2224,22 @@ sub HeaderInterface($) my $count = 0; - pidl_hdr "#ifndef _HEADER_RPC_$interface->{NAME}"; - pidl_hdr "#define _HEADER_RPC_$interface->{NAME}"; + pidl_hdr choose_header("librpc/ndr/libndr.h", "ndr.h"); - pidl_hdr ""; + if (has_property($interface, "object")) { + pidl choose_header("librpc/gen_ndr/ndr_orpc.h", "ndr/orpc.h"); + } if (defined $interface->{PROPERTIES}->{depends}) { my @d = split / /, $interface->{PROPERTIES}->{depends}; foreach my $i (@d) { - pidl_hdr "#include \"librpc/gen_ndr/ndr_$i\.h\""; + pidl choose_header("librpc/gen_ndr/ndr_$i\.h", "gen_ndr/ndr_$i.h"); + } + } + + if (defined $interface->{PROPERTIES}->{helper}) { + foreach (split / /, $interface->{PROPERTIES}->{helper}) { + pidl_hdr "#include $_"; } } @@ -2278,9 +2272,6 @@ sub HeaderInterface($) pidl_hdr "#define DCERPC_$u_name ($val)"; - pidl_hdr "NTSTATUS dcerpc_$_->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $_->{NAME} *r);"; - pidl_hdr "struct rpc_request *dcerpc_$_->{NAME}\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $_->{NAME} *r);"; - pidl_hdr ""; $count++; } @@ -2293,7 +2284,6 @@ sub HeaderInterface($) pidl_hdr "#define DCERPC_" . uc $interface->{NAME} . "_CALL_COUNT ($val)"; - pidl_hdr "#endif /* _HEADER_RPC_$interface->{NAME} */"; } ##################################################################### @@ -2302,6 +2292,15 @@ sub ParseInterface($$) { my($interface,$needed) = @_; + pidl_hdr "#ifndef _HEADER_NDR_$interface->{NAME}"; + pidl_hdr "#define _HEADER_NDR_$interface->{NAME}"; + + pidl_hdr ""; + + if ($needed->{"compression"}) { + pidl choose_header("librpc/ndr/ndr_compression.h", "ndr/compression.h"); + } + HeaderInterface($interface); # Typedefs @@ -2329,23 +2328,43 @@ sub ParseInterface($$) } FunctionTable($interface); + + pidl_hdr "#endif /* _HEADER_NDR_$interface->{NAME} */"; } ##################################################################### # parse a parsed IDL structure back into an IDL file -sub Parse($$) +sub Parse($$$) { - my($ndr,$basename) = @_; + my($ndr,$gen_header,$ndr_header) = @_; $tabs = ""; $res = ""; $res_hdr = ""; - pidl_hdr "/* header auto-generated by pidl */"; + pidl_hdr "/* header auto-generated by pidl */"; + pidl_hdr ""; + pidl_hdr "#include \"$gen_header\"" if ($gen_header); pidl_hdr ""; pidl "/* parser auto-generated by pidl */"; pidl ""; + if (is_intree()) { + pidl "#include \"includes.h\""; + } else { + pidl "#define _GNU_SOURCE"; + pidl "#include <stdint.h>"; + pidl "#include <stdlib.h>"; + pidl "#include <stdio.h>"; + pidl "#include <stdarg.h>"; + pidl "#include <string.h>"; + } + pidl choose_header("libcli/util/nterr.h", "core/nterr.h"); + pidl choose_header("librpc/gen_ndr/ndr_misc.h", "gen_ndr/ndr_misc.h"); + pidl choose_header("librpc/gen_ndr/ndr_dcerpc.h", "gen_ndr/ndr_dcerpc.h"); + pidl "#include \"$ndr_header\"" if ($ndr_header); + pidl choose_header("librpc/rpc/dcerpc.h", "dcerpc.h"); #FIXME: This shouldn't be here! + pidl ""; my %needed = (); @@ -2396,6 +2415,9 @@ sub NeededTypedef($$) for my $e (@{$t->{DATA}->{ELEMENTS}}) { $e->{PARENT} = $t->{DATA}; + if (has_property($e, "compression")) { + $needed->{"compression"} = 1; + } if ($needed->{"pull_$t->{NAME}"} and not defined($needed->{"pull_$e->{TYPE}"})) { $needed->{"pull_$e->{TYPE}"} = 1; @@ -2422,4 +2444,3 @@ sub NeededInterface($$) } 1; - diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm index 8710f08cc7..c35310785a 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm @@ -188,8 +188,7 @@ static NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_C static const struct dcesrv_interface $name\_interface = { .name = \"$name\", - .uuid = ".print_uuid($uuid).", - .if_version = $if_version, + .syntax_id = {".print_uuid($uuid).",$if_version}, .bind = $name\__op_bind, .unbind = $name\__op_unbind, .ndr_pull = $name\__op_ndr_pull, @@ -230,8 +229,8 @@ static NTSTATUS $name\__op_init_server(struct dcesrv_context *dce_ctx, const str static BOOL $name\__op_interface_by_uuid(struct dcesrv_interface *iface, const struct GUID *uuid, uint32_t if_version) { - if ($name\_interface.if_version == if_version && - GUID_equal(\&$name\_interface.uuid, uuid)) { + if ($name\_interface.syntax_id.if_version == if_version && + GUID_equal(\&$name\_interface.syntax_id.uuid, uuid)) { memcpy(iface,&$name\_interface, sizeof(*iface)); return True; } @@ -309,11 +308,11 @@ sub ParseInterface($) sub Parse($$) { - my($ndr) = shift; - my($filename) = shift; + my($ndr,$header) = @_; $res = ""; $res .= "/* server functions auto-generated by pidl */\n"; + $res .= "#include \"$header\"\n"; $res .= "\n"; foreach my $x (@{$ndr}) { diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/TDR.pm b/tools/pidl/lib/Parse/Pidl/Samba4/TDR.pm index 3bdb701526..7e597dfb34 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/TDR.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/TDR.pm @@ -5,6 +5,7 @@ package Parse::Pidl::Samba4::TDR; use Parse::Pidl::Util qw(has_property ParseExpr is_constant); +use Parse::Pidl::Samba4 qw(is_intree choose_header); use vars qw($VERSION); $VERSION = '0.01'; @@ -237,12 +238,21 @@ sub Parser($$$) my ($idl,$hdrname,$baseheader) = @_; $ret = ""; $ret_hdr = ""; pidl "/* autogenerated by pidl */"; - pidl "#include \"includes.h\""; + if (is_intree()) { + pidl "#include \"includes.h\""; + } else { + pidl "#include <stdio.h>"; + pidl "#include <stdlib.h>"; + pidl "#include <stdint.h>"; + pidl "#include <stdarg.h>"; + pidl "#include <string.h>"; + pidl "#include <core/nterr.h>"; + } pidl "#include \"$hdrname\""; pidl ""; pidl_hdr "/* autogenerated by pidl */"; pidl_hdr "#include \"$baseheader\""; - pidl_hdr "#include \"tdr/tdr.h\""; + pidl_hdr choose_header("tdr/tdr.h", "tdr.h"); pidl_hdr ""; foreach (@$idl) { ParserInterface($_) if ($_->{TYPE} eq "INTERFACE"); } diff --git a/tools/pidl/lib/Parse/Pidl/Typelist.pm b/tools/pidl/lib/Parse/Pidl/Typelist.pm index 67e348c5fe..b54badaeb6 100644 --- a/tools/pidl/lib/Parse/Pidl/Typelist.pm +++ b/tools/pidl/lib/Parse/Pidl/Typelist.pm @@ -73,6 +73,11 @@ my $scalars = { C_TYPE => "uint64_t", IS_REFERENCE => 0, }, + # assume its a 8 byte type, but cope with either + "pointer" => { + C_TYPE => "void*", + IS_REFERENCE => 0, + }, # DATA_BLOB types "DATA_BLOB" => { diff --git a/tools/pidl/pidl b/tools/pidl/pidl index dcf5850774..314ab7c60b 100755 --- a/tools/pidl/pidl +++ b/tools/pidl/pidl @@ -279,7 +279,8 @@ Datagram support (ncadg_*) in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, -call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as. +call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, +transmit_as. =head2 PIDL Specific properties @@ -357,7 +358,7 @@ helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib, import, include, includelib, last_is, lcid, licensed, max_is, module, ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl, oleautomation, optional, pragma, propget, propputref, propput, readonly, -requestedit, restricted, retval, source, transmit_as, uidefault, +requestedit, restricted, retval, source, uidefault, usesgetlasterror, vararg, vi_progid, wire_marshal. =head1 EXAMPLES @@ -613,27 +614,22 @@ sub process_file($) unlink($tempfile); } + + my $comh_filename = ($opt_com_header or "$outputdir/com_$basename.h"); if (defined($opt_com_header)) { require Parse::Pidl::Samba4::COM::Header; - my $res = Parse::Pidl::Samba4::COM::Header::Parse($pidl); + my $res = Parse::Pidl::Samba4::COM::Header::Parse($pidl,"$outputdir/ndr_$basename.h"); if ($res) { - my $comh_filename = ($opt_com_header or "$outputdir/com_$basename.h"); - FileSave($comh_filename, - "#include \"librpc/gen_ndr/ndr_orpc.h\"\n" . - "#include \"$outputdir/ndr_$basename.h\"\n" . - $res); + FileSave($comh_filename, $res); } } if (defined($opt_dcom_proxy)) { require Parse::Pidl::Samba4::COM::Proxy; - my $res = Parse::Pidl::Samba4::COM::Proxy::Parse($pidl); + my $res = Parse::Pidl::Samba4::COM::Proxy::Parse($pidl,$comh_filename); if ($res) { my ($client) = ($opt_dcom_proxy or "$outputdir/$basename\_p.c"); - FileSave($client, - "#include \"includes.h\"\n" . - "#include \"$outputdir/com_$basename.h\"\n" . - "#include \"lib/com/dcom/dcom.h\"\n" .$res); + FileSave($client, $res); } } @@ -648,7 +644,7 @@ sub process_file($) defined($opt_client) or defined($opt_server) or defined($opt_ndr_parser) or defined($opt_ejs) or defined($opt_dump_ndr_tree) or defined($opt_samba3_header) or - defined($opt_samba3_header) or defined($opt_samba3_server) or + defined($opt_samba3_parser) or defined($opt_samba3_server) or defined($opt_samba3_template) or defined($opt_samba3_client)) { require Parse::Pidl::NDR; $ndr = Parse::Pidl::NDR::Parse($pidl); @@ -668,9 +664,15 @@ sub process_file($) my $h_filename = "$outputdir/ndr_$basename.h"; if (defined($opt_client)) { require Parse::Pidl::Samba4::NDR::Client; - my ($client) = ($opt_client or "$outputdir/ndr_$basename\_c.c"); + my ($c_client) = ($opt_client or "$outputdir/ndr_$basename\_c.c"); + my ($c_header) = $c_client; + $c_header =~ s/\.c$/.h/; + + my ($srcd,$hdrd) = Parse::Pidl::Samba4::NDR::Client::Parse( + $ndr,$gen_header,$h_filename,$c_header); - FileSave($client, Parse::Pidl::Samba4::NDR::Client::Parse($ndr,$h_filename)); + FileSave($c_client, $srcd); + FileSave($c_header, $hdrd); } if (defined($opt_ejs)) { @@ -684,12 +686,12 @@ sub process_file($) require Parse::Pidl::Samba4::NDR::Server; my $dcom = ""; - foreach my $x (@{$pidl}) { - next if ($x->{TYPE} ne "INTERFACE"); + foreach (@{$pidl}) { + next if ($_->{TYPE} ne "INTERFACE"); - if (Parse::Pidl::Util::has_property($x, "object")) { + if (Parse::Pidl::Util::has_property($_, "object")) { require Parse::Pidl::Samba4::COM::Stub; - $dcom .= Parse::Pidl::Samba4::COM::Stub::ParseInterface($x); + $dcom .= Parse::Pidl::Samba4::COM::Stub::ParseInterface($_); } } @@ -711,25 +713,16 @@ $dcom if (defined($opt_ndr_parser)) { my $parser_fname = ($opt_ndr_parser or "$outputdir/ndr_$basename.c"); require Parse::Pidl::Samba4::NDR::Parser; - my $header_fname = $parser_fname; - $header_fname =~ s/\.c$/\.h/; - my ($header,$parser) = Parse::Pidl::Samba4::NDR::Parser::Parse($ndr, $basename); - - my $baseheader = $h_filename; $baseheader =~ s/\/ndr_/\//; - $header = "#include \"$baseheader\"\n$header"; + my ($header,$parser) = Parse::Pidl::Samba4::NDR::Parser::Parse($ndr, $gen_header, $h_filename); - $parser = "#include \"includes.h\"\n" - . "#include \"librpc/gen_ndr/ndr_misc.h\"\n" - . "#include \"librpc/gen_ndr/ndr_dcerpc.h\"\n" - . "#include \"$header_fname\"\n\n$parser"; FileSave($parser_fname, $parser); - FileSave($header_fname, $header); + FileSave($h_filename, $header); if (defined($opt_swig)) { require Parse::Pidl::Samba4::SWIG; my($filename) = ($opt_swig or "$outputdir/$basename.i"); - Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $header_fname, $filename); + Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $h_filename, $filename); } } diff --git a/tools/pidl/tests/Util.pm b/tools/pidl/tests/Util.pm index cd2ba2a37e..fde92c2a77 100644 --- a/tools/pidl/tests/Util.pm +++ b/tools/pidl/tests/Util.pm @@ -1,5 +1,5 @@ # Some simple utility functions for pidl tests -# Copyright (C) 2005 Jelmer Vernooij +# Copyright (C) 2005-2006 Jelmer Vernooij # Published under the GNU General Public License package Util; @@ -16,13 +16,11 @@ use Parse::Pidl::NDR; use Parse::Pidl::Samba4::NDR::Parser; use Parse::Pidl::Samba4::Header; -my $sanecc = 0; - # Generate a Samba4 parser for an IDL fragment and run it with a specified # piece of code to check whether the parser works as expected -sub test_samba4_ndr($$$) +sub test_samba4_ndr { - my ($name,$idl,$c) = @_; + my ($name,$idl,$c,$extra) = @_; my $pidl = Parse::Pidl::IDL::parse_string("interface echo { $idl }; ", "<$name>"); ok(defined($pidl), "($name) parse idl"); @@ -30,20 +28,14 @@ sub test_samba4_ndr($$$) ok(defined($header), "($name) generate generic header"); my $pndr = Parse::Pidl::NDR::Parse($pidl); ok(defined($pndr), "($name) generate NDR tree"); - my ($ndrheader,$ndrparser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, "foo"); + my ($ndrheader,$ndrparser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, undef, undef); ok(defined($ndrparser), "($name) generate NDR parser"); ok(defined($ndrheader), "($name) generate NDR header"); SKIP: { - my $insamba = -f "include/includes.h"; - my $link = $insamba && 0; # FIXME - skip "no samba environment available, skipping compilation", 3 - if not $insamba; - - skip "no sane C compiler, skipping compilation", 3 - if not $sanecc; + if (system("pkg-config --exists dcerpc ndr") != 0); my $test_data_prefix = $ENV{TEST_DATA_PREFIX}; @@ -54,17 +46,18 @@ SKIP: { $outfile = "test-$name"; } - #my $cflags = $ENV{CFLAGS}; - my $cflags = "-Iinclude -Ilib -I."; + my $cflags = `pkg-config --libs --cflags dcerpc ndr`; - if ($insamba and $link) { - open CC, "|cc -x c -o $outfile $cflags -"; - } elsif ($insamba) { - open CC, "|cc -x c -c -o $outfile $cflags -"; - } - print CC "#include \"includes.h\"\n"; + open CC, "|cc -x c - -o $outfile $cflags"; + print CC "#define uint_t unsigned int\n"; + print CC "#define _GNU_SOURCE\n"; + print CC "#include <stdint.h>\n"; + print CC "#include <stdlib.h>\n"; + print CC "#include <stdio.h>\n"; + print CC "#include <stdarg.h>\n"; print CC $header; print CC $ndrheader; + print CC $extra if ($extra); print CC $ndrparser; print CC "int main(int argc, const char **argv) { @@ -79,23 +72,14 @@ SKIP: { ok(-f $outfile, "($name) compile"); - unless ($link) { - skip "no shared libraries of Samba available yet, can't run test", 2; - unlink($outfile); - } + my $ret = system("./$outfile", ()) >> 8; + print "# return code: $ret\n" if ($ret != 0); - ok(system($outfile), "($name) run"); + ok($ret == 0, "($name) run"); ok(unlink($outfile), "($name) remove"); } } -my $outfile = "test"; # FIXME: Somewhat more unique name - -# Test whether CC is sane. The real 'fix' here would be using the -# Samba build system, but unfortunately, we have no way of hooking into that -# yet so we're running CC directly for now -$sanecc = 1 if system('echo "main() {}"'." | cc -I. -x c -c - -o $outfile") == 0; - 1; diff --git a/tools/pidl/tests/ndr_align.pl b/tools/pidl/tests/ndr_align.pl index 7ca180cf20..c05f6383ed 100755 --- a/tools/pidl/tests/ndr_align.pl +++ b/tools/pidl/tests/ndr_align.pl @@ -118,17 +118,19 @@ test_samba4_ndr('align-blob-align2', typedef [public] struct { uint8 x; [flag(LIBNDR_FLAG_ALIGN2)] DATA_BLOB data; + uint8 y; } bla; ', ' struct ndr_push *ndr = ndr_push_init(); struct bla r; uint8_t data[] = { 0x01, 0x02 }; - uint8_t expected[] = { 0x0D, 0x00, 0x01, 0x02 }; - DATA_BLOB expected_blob = { expected, 4 }; + uint8_t expected[] = { 0x0D, 0x00, 0x0E }; + DATA_BLOB expected_blob = { expected, 3 }; DATA_BLOB result_blob; r.x = 13; + r.y = 14; r.data.data = data; r.data.length = 2; diff --git a/tools/pidl/tests/ndr_refptr.pl b/tools/pidl/tests/ndr_refptr.pl index 0fd573d51e..6940586f01 100755 --- a/tools/pidl/tests/ndr_refptr.pl +++ b/tools/pidl/tests/ndr_refptr.pl @@ -5,7 +5,7 @@ # Published under the GNU General Public License. use strict; -use Test::More tests => 21 * 8; +use Test::More tests => 22 * 8; use FindBin qw($RealBin); use lib "$RealBin/../lib"; use lib "$RealBin"; @@ -402,6 +402,9 @@ test_samba4_ndr("ptr-top-push-double", return 4; '); +SKIP: { + skip "ptr-top-push-double-sndnull is known to fail", 8; + test_samba4_ndr("ptr-top-push-double-sndnull", ' [public] void echo_TestRef([in] uint16 **foo); @@ -421,6 +424,7 @@ test_samba4_ndr("ptr-top-push-double-sndnull", ndr->data[2] != 0 || ndr->data[3] != 0) return 3; '); +} test_samba4_ndr("ptr-top-push-double-fstnull", ' @@ -462,6 +466,10 @@ test_samba4_ndr("refptr-top-push-double", return 4; '); +SKIP: { + + skip "refptr-top-push-double-sndnull is known to fail", 8; + test_samba4_ndr("refptr-top-push-double-sndnull", ' [public] void echo_TestRef([in,ref] uint16 **foo); @@ -481,6 +489,7 @@ test_samba4_ndr("refptr-top-push-double-sndnull", ndr->data[2] != 0 || ndr->data[3] != 0) return 3; '); +} test_samba4_ndr("refptr-top-push-double-fstnull", ' @@ -497,20 +506,22 @@ test_samba4_ndr("refptr-top-push-double-fstnull", '); -#FIXME: Not supported yet -#test_samba4_ndr("ignore-ptr", -#' -# [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar); -#', -#' struct ndr_push *ndr = ndr_push_init(); -# struct echo_TestRef r; -# uint16_t v = 10; -# r.in.foo = &v; -# r.in.bar = &v; -# -# if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r))) -# return 1; -# -# if (ndr->offset != 4) -# return 2; -#'); +SKIP: { + skip "ignore-ptrs are not supported yet", 8; +test_samba4_ndr("ignore-ptr", +' + [public] void echo_TestRef([in,ignore] uint16 *foo, [in] uint16 *bar); +', +' struct ndr_push *ndr = ndr_push_init(); + struct echo_TestRef r; + uint16_t v = 10; + r.in.foo = &v; + r.in.bar = &v; + + if (NT_STATUS_IS_OK(ndr_push_echo_TestRef(ndr, NDR_IN, &r))) + return 1; + + if (ndr->offset != 4) + return 2; +'); +} |