summaryrefslogtreecommitdiff
path: root/source4/pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-12-25 01:33:35 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:47:42 -0500
commit620d375320e143abcf6775a392f9bde3146f2baa (patch)
tree9d477da925be390502d8a49eb53cdd98c4ae5dec /source4/pidl
parent68ef82aac72c351f6e166b92bbb4573e8bcdbc86 (diff)
downloadsamba-620d375320e143abcf6775a392f9bde3146f2baa.tar.gz
samba-620d375320e143abcf6775a392f9bde3146f2baa.tar.bz2
samba-620d375320e143abcf6775a392f9bde3146f2baa.zip
r12465: Merge Parse::Pidl::Samba4::NDR::Header into Parse::Pidl::Samba4::NDR::Parser.
Small optimization to avoid including NDR headers multiple times (This used to be commit 6967b9884970b6f1d7617196ab024d401628a13c)
Diffstat (limited to 'source4/pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm157
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm146
-rwxr-xr-xsource4/pidl/pidl49
-rwxr-xr-xsource4/pidl/tests/ndr_simple.pl70
4 files changed, 179 insertions, 243 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
deleted file mode 100644
index 1480b42971..0000000000
--- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Header.pm
+++ /dev/null
@@ -1,157 +0,0 @@
-###################################################
-# 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::Samba4::NDR::Header;
-
-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::NDR::Parser;
-
-use vars qw($VERSION);
-$VERSION = '0.01';
-
-my($res);
-
-sub pidl ($) { $res .= shift; }
-
-#####################################################################
-# prototype a typedef
-sub HeaderTypedefProto($)
-{
- my($d) = shift;
-
- my $tf = Parse::Pidl::Samba4::NDR::Parser::get_typefamily($d->{DATA}{TYPE});
-
- if (has_property($d, "gensize")) {
- my $size_args = $tf->{SIZE_FN_ARGS}->($d);
- pidl "size_t ndr_size_$d->{NAME}($size_args);\n";
- }
-
- return unless has_property($d, "public");
-
- unless (has_property($d, "nopush")) {
- pidl "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *ndr, int ndr_flags, " . $tf->{DECL}->($d, "push") . ");\n";
- }
- unless (has_property($d, "nopull")) {
- pidl "NTSTATUS ndr_pull_$d->{NAME}(struct ndr_pull *ndr, int ndr_flags, " . $tf->{DECL}->($d, "pull") . ");\n";
- }
- unless (has_property($d, "noprint")) {
- pidl "void ndr_print_$d->{NAME}(struct ndr_print *ndr, const char *name, " . $tf->{DECL}->($d, "print") . ");\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";
-
- unless (has_property($fn, "noopnum")) {
- 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 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;
-
- if (defined $interface->{PROPERTIES}->{depends}) {
- my @d = split / /, $interface->{PROPERTIES}->{depends};
- foreach my $i (@d) {
- pidl "#include \"librpc/gen_ndr/ndr_$i\.h\"\n";
- }
- }
-
- my $count = 0;
-
- pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
- pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
-
- if (defined $interface->{PROPERTIES}->{uuid}) {
- my $name = uc $interface->{NAME};
- pidl "#define DCERPC_$name\_UUID " .
- Parse::Pidl::Util::make_str(lc($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->{DATA}}) {
- next if $d->{TYPE} ne "FUNCTION";
- next if has_property($d, "noopnum");
- next if grep(/$d->{NAME}/,@{$interface->{INHERITED_FUNCTIONS}});
- my $u_name = uc $d->{NAME};
- pidl "#define DCERPC_$u_name (";
-
- if (defined($interface->{BASE})) {
- pidl "DCERPC_" . uc $interface->{BASE} . "_CALL_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->{DATA}}) {
- next if ($d->{TYPE} ne "TYPEDEF");
- HeaderTypedefProto($d);
- }
-
- foreach my $d (@{$interface->{DATA}}) {
- next if ($d->{TYPE} ne "FUNCTION");
- HeaderFnProto($interface, $d);
- }
-
- pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
-}
-
-#####################################################################
-# parse a parsed IDL into a C header
-sub Parse($$)
-{
- my($idl,$basename) = @_;
-
- $res = "";
- pidl "/* header auto-generated by pidl */\n";
- pidl "#include \"librpc/gen_ndr/$basename\.h\"\n\n";
-
- foreach my $x (@{$idl}) {
- ($x->{TYPE} eq "INTERFACE") && HeaderInterface($x);
- }
- return $res;
-}
-
-1;
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index a7ea60b2e4..2242323747 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -101,7 +101,7 @@ sub get_value_of($)
}
}
-my $res = "";
+my $res;
my $deferred = "";
my $tabs = "";
@@ -117,6 +117,10 @@ sub pidl($)
$res .="\n";
}
+my $res_hdr;
+
+sub pidl_hdr ($) { my $d = shift; $res_hdr .= "$d\n"; }
+
####################################
# defer() is like pidl(), but adds to
# a deferred buffer which is then added to the
@@ -188,13 +192,17 @@ sub check_null_pointer_void($)
}
#####################################################################
-# work out is a parse function should be declared static or not
-sub fn_prefix($)
+# declare a function public or static, depending on its attributes
+sub fn_declare($$)
{
- my $fn = shift;
+ my ($fn,$decl) = @_;
- return "" if (has_property($fn, "public"));
- return "static ";
+ if (has_property($fn, "public")) {
+ pidl_hdr "$decl;";
+ pidl "$decl";
+ } else {
+ pidl "static $decl";
+ }
}
###################################################################
@@ -1821,7 +1829,7 @@ sub ParseTypedefPush($)
my($e) = shift;
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"push");
- pidl fn_prefix($e) . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)";
+ fn_declare($e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)");
pidl "{";
indent;
@@ -1840,7 +1848,7 @@ sub ParseTypedefPull($)
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"pull");
- pidl fn_prefix($e) . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)";
+ fn_declare($e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)");
pidl "{";
indent;
@@ -1860,6 +1868,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_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
pidl "{";
indent;
$typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $e->{NAME});
@@ -1877,7 +1886,8 @@ sub ParseTypedefNdrSize($)
my $tf = $typefamily{$t->{DATA}->{TYPE}};
my $args = $tf->{SIZE_FN_ARGS}->($t);
- pidl "size_t ndr_size_$t->{NAME}($args)";
+ fn_declare($t, "size_t ndr_size_$t->{NAME}($args)");
+
pidl "{";
indent;
$typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t);
@@ -1895,6 +1905,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_hdr "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, const struct $fn->{NAME} *r);";
pidl "{";
indent;
@@ -1958,7 +1969,8 @@ sub ParseFunctionPush($)
return if has_property($fn, "nopush");
- pidl fn_prefix($fn) . "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, const struct $fn->{NAME} *r)";
+ fn_declare($fn, "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, const struct $fn->{NAME} *r)");
+
pidl "{";
indent;
@@ -2038,7 +2050,7 @@ sub ParseFunctionPull($)
return if 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)";
+ fn_declare($fn, "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)");
pidl "{";
indent;
@@ -2149,6 +2161,7 @@ sub FunctionTable($)
$count = $#{$interface->{FUNCTIONS}}+1;
return if ($count == 0);
+ return unless defined ($interface->{PROPERTIES}->{uuid});
pidl "static const struct dcerpc_interface_call $interface->{NAME}\_calls[] = {";
$count = 0;
@@ -2223,11 +2236,82 @@ sub FunctionTable($)
}
#####################################################################
+# generate prototypes and defines for the interface definitions
+# FIXME: these prototypes are for the DCE/RPC client functions, not the
+# NDR parser and so do not belong here, technically speaking
+sub HeaderInterface($)
+{
+ my($interface) = shift;
+
+ my $count = 0;
+
+ pidl_hdr "#ifndef _HEADER_RPC_$interface->{NAME}";
+ pidl_hdr "#define _HEADER_RPC_$interface->{NAME}";
+
+ pidl_hdr "";
+
+ if (defined $interface->{PROPERTIES}->{depends}) {
+ my @d = split / /, $interface->{PROPERTIES}->{depends};
+ foreach my $i (@d) {
+ pidl_hdr "#include \"librpc/gen_ndr/ndr_$i\.h\"";
+ }
+ }
+
+ if (defined $interface->{PROPERTIES}->{uuid}) {
+ my $name = uc $interface->{NAME};
+ pidl_hdr "#define DCERPC_$name\_UUID " .
+ Parse::Pidl::Util::make_str(lc($interface->{PROPERTIES}->{uuid}));
+
+ if(!defined $interface->{PROPERTIES}->{version}) { $interface->{PROPERTIES}->{version} = "0.0"; }
+ pidl_hdr "#define DCERPC_$name\_VERSION $interface->{PROPERTIES}->{version}";
+
+ pidl_hdr "#define DCERPC_$name\_NAME \"$interface->{NAME}\"";
+
+ if(!defined $interface->{PROPERTIES}->{helpstring}) { $interface->{PROPERTIES}->{helpstring} = "NULL"; }
+ pidl_hdr "#define DCERPC_$name\_HELPSTRING $interface->{PROPERTIES}->{helpstring}";
+
+ pidl_hdr "extern const struct dcerpc_interface_table dcerpc_table_$interface->{NAME};";
+ pidl_hdr "NTSTATUS dcerpc_server_$interface->{NAME}_init(void);";
+ }
+
+ foreach (@{$interface->{FUNCTIONS}}) {
+ next if has_property($_, "noopnum");
+ next if grep(/$_->{NAME}/,@{$interface->{INHERITED_FUNCTIONS}});
+ my $u_name = uc $_->{NAME};
+
+ my $val = sprintf("0x%02x", $count);
+ if (defined($interface->{BASE})) {
+ $val .= " + DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT";
+ }
+
+ 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++;
+ }
+
+ my $val = $count;
+
+ if (defined($interface->{BASE})) {
+ $val .= " + DCERPC_" . uc $interface->{BASE} . "_CALL_COUNT";
+ }
+
+ pidl_hdr "#define DCERPC_" . uc $interface->{NAME} . "_CALL_COUNT ($val)";
+
+ pidl_hdr "#endif /* _HEADER_RPC_$interface->{NAME} */";
+}
+
+#####################################################################
# parse the interface definitions
sub ParseInterface($$)
{
my($interface,$needed) = @_;
+ HeaderInterface($interface);
+
# Typedefs
foreach my $d (@{$interface->{TYPEDEFS}}) {
($needed->{"push_$d->{NAME}"}) && ParseTypedefPush($d);
@@ -2257,10 +2341,8 @@ sub ParseInterface($$)
sub RegistrationFunction($$)
{
- my ($idl,$filename) = @_;
+ my ($idl,$basename) = @_;
- $filename =~ /.*\/ndr_(.*).c/;
- my $basename = $1;
pidl "NTSTATUS dcerpc_$basename\_init(void)";
pidl "{";
indent;
@@ -2271,6 +2353,7 @@ sub RegistrationFunction($$)
my $count = ($#{$interface->{FUNCTIONS}}+1);
next if ($count == 0);
+ next unless defined ($interface->{PROPERTIES}->{uuid});
pidl "status = dcerpc_ndr_$interface->{NAME}_init();";
pidl "if (NT_STATUS_IS_ERR(status)) {";
@@ -2288,37 +2371,31 @@ sub RegistrationFunction($$)
# parse a parsed IDL structure back into an IDL file
sub Parse($$)
{
- my($ndr,$filename) = @_;
+ my($ndr,$basename) = @_;
$tabs = "";
- my $h_filename = $filename;
$res = "";
- if ($h_filename =~ /(.*)\.c/) {
- $h_filename = "$1.h";
- }
+ $res_hdr = "";
+ pidl_hdr "/* header auto-generated by pidl */";
+ pidl_hdr "";
pidl "/* parser auto-generated by pidl */";
pidl "";
- pidl "#include \"includes.h\"";
- pidl "#include \"librpc/gen_ndr/ndr_misc.h\"";
- pidl "#include \"librpc/gen_ndr/ndr_dcerpc.h\"";
- pidl "#include \"$h_filename\"";
- pidl "";
my %needed = ();
- foreach my $x (@{$ndr}) {
- ($x->{TYPE} eq "INTERFACE") && NeededInterface($x, \%needed);
+ foreach (@{$ndr}) {
+ ($_->{TYPE} eq "INTERFACE") && NeededInterface($_, \%needed);
}
- foreach my $x (@{$ndr}) {
- ($x->{TYPE} eq "INTERFACE") && ParseInterface($x, \%needed);
+ foreach (@{$ndr}) {
+ ($_->{TYPE} eq "INTERFACE") && ParseInterface($_, \%needed);
}
- RegistrationFunction($ndr, $filename);
+ RegistrationFunction($ndr, $basename);
- return $res;
+ return ($res_hdr, $res);
}
sub NeededFunction($$)
@@ -2378,12 +2455,9 @@ sub NeededTypedef($$)
sub NeededInterface($$)
{
my ($interface,$needed) = @_;
- foreach my $d (@{$interface->{FUNCTIONS}}) {
- NeededFunction($d, $needed);
- }
- foreach my $d (reverse @{$interface->{TYPEDEFS}}) {
- NeededTypedef($d, $needed);
- }
+ NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
+ NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPEDEFS}});
}
1;
+
diff --git a/source4/pidl/pidl b/source4/pidl/pidl
index 4a68424b97..1bfe6e396c 100755
--- a/source4/pidl/pidl
+++ b/source4/pidl/pidl
@@ -17,7 +17,7 @@ pidl - An IDL compiler written in Perl
pidl --help
-pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--ndr-header[=OUTPUT]] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--eth-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-header=[OUTPUT]] [--tdr-parser[=OUTPUT]] [--samba3-header[=OUTPUT]] [--samba3-parser=[OUTPUT]] [--samba3-server=[OUTPUT]] [--samba3-template[=OUTPUT]] [--samba3-client[=OUTPUT]] [<idlfile>.idl]...
+pidl [--outputdir[=OUTNAME]] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--swig[=OUTPUT]] [--uint-enums] [--ndr-parser[=OUTPUT]] [--client] [--server] [--dcom-proxy] [--com-header] [--warn-compat] [--quiet] [--verbose] [--template] [--eth-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-header=[OUTPUT]] [--tdr-parser[=OUTPUT]] [--samba3-header[=OUTPUT]] [--samba3-parser=[OUTPUT]] [--samba3-server=[OUTPUT]] [--samba3-template[=OUTPUT]] [--samba3-client[=OUTPUT]] [<idlfile>.idl]...
=head1 DESCRIPTION
@@ -71,13 +71,11 @@ Generate a new IDL file. File will be named OUTNAME.idl.
Generate a C header file for the specified interface. Filename defaults to OUTNAME.h.
-=item I<--ndr-header>
-
-Generate a C header file with the prototypes for the NDR parsers. Filename defaults to ndr_OUTNAME.h.
-
=item I<--ndr-parser>
-Generate a C file containing NDR parsers. Filename defaults to ndr_OUTNAME.c.
+Generate a C file and C header containing NDR parsers. The filename for
+the parser defaults to ndr_OUTNAME.c. The header filename will be the
+parser filename with the extension changed from .c to .h.
=item I<--server>
@@ -455,7 +453,6 @@ my($opt_dump_idl) = 0;
my($opt_uint_enums) = 0;
my($opt_diff) = 0;
my($opt_header);
-my($opt_ndr_header);
my($opt_samba3_header);
my($opt_samba3_parser);
my($opt_samba3_server);
@@ -504,7 +501,6 @@ Debugging:
Samba 4 output:
--header[=OUTFILE] create generic header file [BASENAME.h]
--uint-enums don't use C enums, instead use uint* types
- --ndr-header[=OUTFILE] create a C NDR-specific header file [ndr_BASENAME.h]
--ndr-parser[=OUTFILE] create a C NDR parser [ndr_BASENAME.c]
--client[=OUTFILE] create a C NDR client [ndr_BASENAME_c.c]
--tdr-header[=OUTFILE] create a C TDR header file [tdr_BASENAME.h]
@@ -538,7 +534,6 @@ my $result = GetOptions (
'parse-idl-tree' => \$opt_parse_idl_tree,
'dump-ndr-tree:s' => \$opt_dump_ndr_tree,
'uint-enums' => \$opt_uint_enums,
- 'ndr-header:s' => \$opt_ndr_header,
'samba3-header:s' => \$opt_samba3_header,
'samba3-parser:s' => \$opt_samba3_parser,
'samba3-server:s' => \$opt_samba3_server,
@@ -646,7 +641,7 @@ sub process_file($)
$pidl = Parse::Pidl::ODL::ODL2IDL($pidl);
- if (defined($opt_ndr_header) or defined($opt_eth_parser) or
+ if (defined($opt_eth_parser) or
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
@@ -668,17 +663,6 @@ sub process_file($)
FileSave($header, Parse::Pidl::Samba4::Header::Parse($pidl));
}
- if (defined($opt_ndr_header)) {
- my $header = ($opt_ndr_header or "$outputdir/ndr_$basename.h");
- require Parse::Pidl::Samba4::NDR::Header;
- FileSave($header, Parse::Pidl::Samba4::NDR::Header::Parse($pidl, $basename));
- if (defined($opt_swig)) {
- require Parse::Pidl::Samba4::SWIG;
- my($filename) = ($opt_swig or "$outputdir/$basename.i");
- Parse::Pidl::Samba4::SWIG::RewriteHeader($pidl, $header, $filename);
- }
- }
-
my $h_filename = "$outputdir/ndr_$basename.h";
if (defined($opt_client)) {
require Parse::Pidl::Samba4::NDR::Client;
@@ -724,9 +708,28 @@ $dcom
}
if (defined($opt_ndr_parser)) {
- my $parser = ($opt_ndr_parser or "$outputdir/ndr_$basename.c");
+ my $parser_fname = ($opt_ndr_parser or "$outputdir/ndr_$basename.c");
require Parse::Pidl::Samba4::NDR::Parser;
- FileSave($parser, Parse::Pidl::Samba4::NDR::Parser::Parse($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";
+
+ $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);
+
+ 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);
+ }
}
if (defined($opt_eth_parser)) {
diff --git a/source4/pidl/tests/ndr_simple.pl b/source4/pidl/tests/ndr_simple.pl
index 96e213ede9..5bdd02b763 100755
--- a/source4/pidl/tests/ndr_simple.pl
+++ b/source4/pidl/tests/ndr_simple.pl
@@ -4,45 +4,61 @@
# Published under the GNU General Public License
use strict;
-use Test::Simple tests => 4;
+use Test::Simple tests => 6;
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use Parse::Pidl::IDL;
use Parse::Pidl::NDR;
use Parse::Pidl::Samba4::NDR::Parser;
+use Parse::Pidl::Samba4::Header;
my $pidl = Parse::Pidl::IDL::parse_string(
"interface test { void Test(); }; ", "<test>");
ok (defined($pidl));
my $pndr = Parse::Pidl::NDR::Parse($pidl);
ok(defined($pndr));
-my ($header,$parser) = Parse::Pidl::Samba4::NDR::Parser($pndr);
+my $header = Parse::Pidl::Samba4::Header::Parse($pidl);
ok(defined($header));
+my ($ndrheader,$parser) = Parse::Pidl::Samba4::NDR::Parser::Parse($pndr, "foo");
ok(defined($parser));
+ok(defined($ndrheader));
+my $outfile = "test";
-#Parse::Pidl::Test::test_idl(
-# # Name
-# 'UInt8',
-#
-# # Settings
-# \%settings,
-#
-#
-# # C Test
-# '
-# uint8_t data[] = { 0x02 };
-# uint8_t result;
-# DATA_BLOB b;
-# struct ndr_pull *ndr;
-#
-# b.data = data;
-# b.length = 1;
-# ndr = ndr_pull_init_blob(&b, mem_ctx);
-#
-# if (NT_STATUS_IS_ERR(ndr_pull_uint8(ndr, NDR_SCALARS, &result)))
-# return 1;
-#
-# if (result != 0x02)
-# return 2;
-#');
+#my $cflags = $ENV{CFLAGS};
+my $cflags = "-Iinclude -I.";
+
+open CC, "|cc -x c -o $outfile $cflags -";
+#open CC, ">foo";
+print CC "#include \"includes.h\"";
+print CC $header;
+print CC $ndrheader;
+print CC $parser;
+print CC
+ '
+int main(int argc, const char **argv)
+{
+ uint8_t data[] = { 0x02 };
+ uint8_t result;
+ DATA_BLOB b;
+ struct ndr_pull *ndr;
+ TALLOC_CTX *mem_ctx = talloc_init(NULL);
+
+ b.data = data;
+ b.length = 1;
+ ndr = ndr_pull_init_blob(&b, mem_ctx);
+
+ if (NT_STATUS_IS_ERR(ndr_pull_uint8(ndr, NDR_SCALARS, &result)))
+ return 1;
+
+ if (result != 0x02)
+ return 2;
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+';
+close CC;
+
+ok(-f $outfile);