From f9a416743401121e1bc2961402cd6f87de68ca00 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Oct 2005 23:27:33 +0000 Subject: r10694: Add some work I did this afternoon on getting pidl to output Samba3 RPC parsers. Currently the following files can be generated: - include/rpc_BASENAME.h - rpc_server/srv_BASENAME.c - rpc_server/srv_BASENAME_nt.c (template only, user has to fill in functions) - rpc_client/cli_BASENAME.c - rpc_parse/parse_BASENAME.c So far, I have been working on getting DFS working. Currently still to do (all in rpc_parse/parse_BASENAME.c): - Proper handling of declarations - Proper handling of scalar/buffer parts of structs and unions - Subcontexts - Proper handling of arrays - Support for custom (non-scalar) types I hope to have a somewhat more working version later this week. Some files as currently generated are available from: http://samba.org/~jelmer/pidl_samba3/ (This used to be commit 8af8eaeeef6d46f4d25ccb1d25890e1eef063e4f) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 104 ++++++++++ source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 160 +++++++++++++++ source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 269 +++++++++++++++++++++++++ source4/pidl/lib/Parse/Pidl/Samba3/Server.pm | 115 +++++++++++ source4/pidl/lib/Parse/Pidl/Samba3/Template.pm | 66 ++++++ source4/pidl/lib/Parse/Pidl/Samba3/Util.pm | 29 +++ 6 files changed, 743 insertions(+) create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Client.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Header.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Server.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Template.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Util.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm new file mode 100644 index 0000000000..59d048176f --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -0,0 +1,104 @@ +################################################### +# Samba3 NDR client generator for IDL structures +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Client; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba3::Util qw(MapSamba3Type); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res = ""; +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 ParseFunction($$) +{ + my ($if,$fn) = @_; + + my $args = ""; + my $defargs = ""; + foreach (@{$fn->{ELEMENTS}}) { + $defargs .= ", " . MapSamba3Type($_); + $args .= ", $_->{NAME}"; + } + + my $uif = uc($if->{NAME}); + my $ufn = uc($fn->{NAME}); + + pidl "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; + pidl "{"; + indent; + pidl "prs_struct qbuf, rbuf;"; + pidl "$uif\_Q_$ufn q;"; + pidl "$uif\_R_$ufn r;"; + pidl ""; + pidl "ZERO_STRUCT(q);"; + pidl "ZERO_STRUCT(r);"; + pidl ""; + pidl "/* Marshall data and send request */"; + pidl ""; + pidl "init_$if->{NAME}_q_$fn->{NAME}(&q$args);"; + pidl ""; + pidl "CLI_DO_RPC(cli, mem_ctx, PI_$uif, $ufn,"; + pidl "\tq, r,"; + pidl "\tqbuf, rbuf, "; + pidl "\t$if->{NAME}_q_$fn->{NAME},"; + pidl "\t$if->{NAME}_r_$fn->{NAME},"; + pidl "\tNT_STATUS_UNSUCCESSFUL);"; + pidl ""; + pidl "/* Return result */"; + if (not $fn->{RETURN_TYPE}) { + pidl "return NT_STATUS_OK;"; + } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { + pidl "return r.status;"; + } elsif ($fn->{RETURN_TYPE} eq "WERROR") { + pidl "return werror_to_ntstatus(r.status);"; + } else { + pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; + pidl "return NT_STATUS_OK;"; + } + + deindent; + pidl "}"; + pidl ""; +} + +sub ParseInterface($) +{ + my $if = shift; + + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $res = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * client auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return $res; +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm new file mode 100644 index 0000000000..be7f1ca5c4 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -0,0 +1,160 @@ +################################################### +# Samba3 NDR header generator for IDL structures +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Header; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba3::Util qw(MapSamba3Type); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res = ""; +sub pidl($) { my $x = shift; $res .= "$x\n"; } +sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } + +sub CreateStruct($$$$) +{ + my ($if,$fn,$n,$t) = @_; + + pidl "typedef struct $n {"; + foreach my $e (@$t) { + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "POINTER") { + return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); + pidl "\tuint32 ptr_$e->{NAME};"; + } elsif ($l->{TYPE} eq "SWITCH") { + pidl "\tuint32 level_$e->{NAME};"; + } elsif ($l->{TYPE} eq "DATA") { + pidl "\t" . MapSamba3Type($e) . ";"; + } + } + } + + if (not @$t) { + # Some compilers don't like empty structs + pidl "\tuint32 dummy;"; + } + + pidl "} " . uc($n) . ";"; + pidl ""; +} + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + my @in = (); + my @out = (); + + foreach (@{$_->{ELEMENTS}}) { + push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); + push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); + } + + if (defined($fn->{RETURN_TYPE})) { + push (@out, { + NAME => "status", + TYPE => $fn->{RETURN_TYPE}, + LEVELS => [ + { + TYPE => "DATA", + DATA_TYPE => $fn->{RETURN_TYPE} + } + ] + } ); + } + + # define Q + R structures for functions + + CreateStruct($if, $fn, "$if->{NAME}_q_$fn->{NAME}", \@in); + CreateStruct($if, $fn, "$if->{NAME}_r_$fn->{NAME}", \@out); +} + +sub ParseStruct($$$) +{ + my ($if,$s,$n) = @_; + + CreateStruct($if, $s, "$if->{NAME}_$n", $s->{ELEMENTS}); +} + +sub ParseEnum($$$) +{ + my ($if,$s,$n) = @_; + + pidl "typedef enum {"; + + foreach (@{$s->{ELEMENTS}}) { + pidl "$_,"; + } + + pidl "} $n;"; +} + +sub ParseBitmap($$$) +{ + my ($if,$s,$n) = @_; + + pidl "#define $_" foreach (@{$s->{ELEMENTS}}); +} + +sub ParseInterface($) +{ + my $if = shift; + + my $def = "_RPC_" . uc($if->{NAME}) . "_H"; + + pidl ""; + + pidl "\#ifndef $def"; + pidl "\#define $def"; + + pidl ""; + + foreach (@{$if->{FUNCTIONS}}) { + pidl "\#define " . uc($_->{NAME}) . " $_->{OPNUM}" ; + } + + pidl ""; + + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + + foreach (@{$if->{TYPEDEFS}}) { + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); + ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "ENUM"); + ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "BITMAP"); + fatal($_, "Unions not supported for Samba3 yet") if ($_->{TYPE} eq "STRUCT"); + } + + foreach (@{$if->{CONSTS}}) { + pidl "$_->{NAME} ($_->{VALUE})"; + } + + pidl "\#endif /* $def */"; +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $res = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * header auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + + # Loop over interfaces + foreach (@{$ndr}) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + return $res; +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm new file mode 100644 index 0000000000..8518537ddb --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -0,0 +1,269 @@ +################################################### +# Samba3 NDR parser generator for IDL structures +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Parser; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba3::Util qw(MapSamba3Type); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res = ""; +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 ParseElementLevelData($$$$$) +{ + my ($e,$l,$nl,$env,$varname) = @_; + + #FIXME: This only works for scalar types + pidl "if (!prs_$l->{DATA_TYPE}(\"$e->{NAME}\", ps, depth, &$varname))"; + pidl "\treturn False;"; + pidl ""; +} + +sub ParseElementLevelArray($$$$$) +{ + my ($e,$l,$nl,$env,$varname) = @_; + + #FIXME + pidl "for (i=0; i<".ParseExpr("length_$e->{NAME}", $env) .";i++) {"; + indent; + ParseElementLevel($e,$nl,$env,"$varname\[i]"); + deindent; + pidl "}"; +} + +sub ParseElementLevelSwitch($$$$$) +{ + my ($e,$l,$nl,$env,$varname) = @_; + + pidl "if (!prs_uint32(\"level\", ps, depth, " . ParseExpr("level_$e->{NAME}", $env) . ", ps, depth))"; + pidl "\treturn False;"; + pidl ""; + + ParseElementLevel($e,$nl,$env,$varname); +} + +sub ParseElementLevelPtr($$$$$) +{ + my ($e,$l,$nl,$env,$varname) = @_; + + # No top-level ref pointers for Samba 3 + return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP"); + + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\",ps,depth,&" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; + pidl "\treturn False;"; + pidl ""; + + pidl "if (" . ParseExpr("ptr_$e->{NAME}", $env) . ") {"; + indent; + ParseElementLevel($e,$nl,$env,$varname); + deindent; + pidl "}"; +} + +sub ParseElementLevelSubcontext($$$$$) +{ + my ($e,$l,$nl,$env,$varname) = @_; + + fatal($e, "subcontext() not supported for Samba 3"); +} + +sub ParseElementLevel($$$$) +{ + my ($e,$l,$env,$varname) = @_; + + { + DATA => \&ParseElementLevelData, + SUBCONTEXT => \&ParseElementLevelSubcontext, + POINTER => \&ParseElementLevelPtr, + SWITCH => \&ParseElementLevelSwitch, + ARRAY => \&ParseElementLevelArray + }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname); +} + +sub ParseElement($$) +{ + my ($e,$env) = @_; + + ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env)); +} + +sub CreateStruct($$$) +{ + my ($fn,$s,$es) = @_; + + my $args = ""; + foreach my $e (@$es) { + $args .= ", " . MapSamba3Type($_); + } + + pidl "BOOL init_$fn($s *v$args)"; + pidl "{"; + indent; + pidl "DEBUG(5,(\"init_$fn\\n\"));"; + # Call init for all arguments + foreach my $e (@$es) { + foreach my $l (@{$e->{LEVELS}}) { + #FIXME + } + } + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; + + pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; + pidl "{"; + indent; + pidl "if (v == NULL)"; + pidl "\treturn False;"; + pidl ""; + pidl "prs_debug(ps, depth, desc, \"$fn\");"; + pidl "depth++;"; + pidl "if (!prs_align(ps))"; + pidl "\treturn False;"; + pidl ""; + + my $env = {}; + foreach my $e (@$es) { + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "DATA") { + $env->{"$e->{NAME}"} = $e->{"v->$e->{NAME}"}; + } elsif ($l->{TYPE} eq "POINTER") { + $env->{"ptr_$e->{NAME}"} = $e->{"v->ptr_$e->{NAME}"}; + } elsif ($l->{TYPE} eq "SWITCH") { + $env->{"level_$e->{NAME}"} = $e->{"v->level_$e->{NAME}"}; + } + } + } + + ParseElement($_, $env) foreach (@$es); + + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; +} + +sub ParseStruct($$$) +{ + my ($if,$s,$n) = @_; + + my $fn = "$if->{NAME}_io_$n"; + my $sn = uc("$if->{NAME}_$n"); + + CreateStruct($fn, $sn, $s->{ELEMENTS}); +} + +sub ParseUnion($$$) +{ + my ($if,$u,$n) = @_; + + my $fn = "$if->{NAME}_io_$n"; + my $sn = uc("$if->{NAME}_$n"); + + pidl "BOOL $fn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; + pidl "{"; + indent; + pidl "switch (level) {"; + indent; + + foreach (@{$u->{ELEMENTS}}) { + pidl "$_->{CASE}:"; + indent; + pidl "depth++;"; + ParseElement($_, {}); + deindent; + pidl "depth--;"; + pidl "break"; + } + + deindent; + pidl "}"; + pidl ""; + pidl "return True;"; + deindent; + pidl "}"; +} + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + my @in = (); + my @out = (); + + foreach (@{$fn->{ELEMENTS}}) { + push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); + push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); + } + + if (defined($fn->{RETURN_TYPE})) { + push (@out, { + NAME => "status", + TYPE => $fn->{RETURN_TYPE}, + LEVELS => [ + { + TYPE => "DATA", + DATA_TYPE => $fn->{RETURN_TYPE} + } + ] + } ); + } + + CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), \@in); + CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), \@out); +} + +sub ParseInterface($) +{ + my $if = shift; + + # Structures first + pidl "/* $if->{NAME} structures */"; + foreach (@{$if->{TYPEDEFS}}) { + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); + ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "UNION"); + } + + pidl "/* $if->{NAME} functions */"; + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $tabs = ""; + $res = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * parser auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl ""; + pidl "#undef DBGC_CLASS"; + pidl "#define DBGC_CLASS DBGC_RPC_PARSE"; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return $res; +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm new file mode 100644 index 0000000000..0372cf1117 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm @@ -0,0 +1,115 @@ +################################################### +# Samba3 NDR server generator for IDL structures +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Server; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); + +my $res = ""; +my $tabs = ""; + +sub indent() { $tabs.="\t"; } +sub deindent() { $tabs = substr($tabs, 1); } +sub pidl($) { $res .= $tabs.(shift)."\n"; } + +use vars qw($VERSION); +$VERSION = '0.01'; + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + pidl "/******************************************************************"; + pidl " api_$fn->{NAME}"; + pidl " *****************************************************************/"; + pidl ""; + pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; + pidl "{"; + indent; + pidl uc("$if->{NAME}_q_$fn->{NAME}") . " q_u;"; + pidl uc("$if->{NAME}_r_$fn->{NAME}") . " r_u;"; + pidl "prs_struct *data = &p->in_data.data"; + pidl "prs_struct *rdata = &p->out_data.rdata"; + pidl ""; + pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; + pidl "\treturn False;"; + pidl ""; + pidl "r_u.status = _$fn->{NAME}(p, &q_u, &r_u);"; + pidl ""; + pidl "if (!$if->{NAME}_io_r_$fn->{NAME}(\"\", &r_u, rdata, 0))"; + pidl "\treturn False;"; + pidl ""; + pidl "return True;"; + deindent; + pidl "}"; +} + +sub ParseInterface($) +{ + my $if = shift; + + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + + pidl ""; + pidl "/* Tables */"; + pidl "static struct api_struct api_$if->{NAME}_cmds[] = "; + pidl "{"; + indent; + foreach (@{$if->{FUNCTIONS}}) { + pidl "{\"" . uc($_->{NAME}) . "\", " . uc($_->{NAME}) . ", api_$_->{NAME}},"; + } + deindent; + pidl "};"; + + pidl ""; + + pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)"; + pidl "{"; + indent; + pidl "*fns = api_$if->{NAME}_cmds;"; + pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);"; + deindent; + pidl "}"; + + pidl ""; + + pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; + pidl "{"; + indent; + pidl "return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; + deindent; + pidl "}"; +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $tabs = ""; + $res = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * server auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl "#include \"nterr.h\""; + pidl ""; + pidl "#undef DBGC_CLASS"; + pidl "#define DBGC_CLASS DBGC_RPC"; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return $res; +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm new file mode 100644 index 0000000000..072aa07850 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm @@ -0,0 +1,66 @@ +################################################### +# Samba3 NDR client generator for IDL structures +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Template; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res; +sub pidl($) { my $x = shift; $res.="$x\n"; } + +sub ParseInterface($) +{ + my $if = shift; + + foreach (@{$if->{FUNCTIONS}}) { + my $ret = $_->{RETURN_TYPE}; + if (not $ret) { $ret = "void"; } + pidl "$ret _$_->{NAME}(pipes_struct *p, " . uc($if->{NAME}) . "_Q_" . uc($_->{NAME}) . " *q_u, " . uc($if->{NAME}) . "_R_" . uc($_->{NAME}) . " *r_u)"; + pidl "{"; + pidl "\t/* FIXME: Implement your code here */"; + if (not defined($_->{RETURN_TYPE})) { + } elsif ($_->{RETURN_TYPE} eq "WERROR") { + pidl "\treturn WERR_NOT_SUPPORTED;"; + } elsif ($_->{RETURN_TYPE} eq "NTSTATUS") { + pidl "\treturn NT_STATUS_NOT_IMPLEMENTED;"; + } elsif ($_->{RETURN_TYPE} eq "uint32") { + pidl "\treturn 0;"; + } + pidl "}"; + pidl ""; + } +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $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 ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return $res; +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm new file mode 100644 index 0000000000..2d4179df76 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm @@ -0,0 +1,29 @@ +################################################### +# Samba3 common helper functions +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Util; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(MapSamba3Type); + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); + +use vars qw($VERSION); +$VERSION = '0.01'; + +sub MapSamba3Type($) +{ + my $e = shift; + + return "UNISTR2 $e->{NAME}" if ($e->{TYPE} eq "string"); + + return "$e->{TYPE} $e->{NAME}"; +} + +1; -- cgit From 55065d27cede4e2cdc0e1240b1b5952fa5697391 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Oct 2005 13:07:23 +0000 Subject: r10713: Couple more updates to the Samba3 parser generators. Unions and enums have been improved, init functions are now generated properly, some other small improvements. (This used to be commit 8a60e79175eb27ef9fa4b8dea72a518bbaab900f) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 4 +- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 61 ++++++---- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 127 ++++++++++++++------ source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 169 +++++++++++++++++++++++++++ source4/pidl/lib/Parse/Pidl/Samba3/Util.pm | 29 ----- 5 files changed, 300 insertions(+), 90 deletions(-) create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Types.pm delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Util.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index 59d048176f..83762719ea 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Util qw(MapSamba3Type); +use Parse::Pidl::Samba3::Types qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; @@ -28,7 +28,7 @@ sub ParseFunction($$) my $args = ""; my $defargs = ""; foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . MapSamba3Type($_); + $defargs .= ", " . DeclLong($_); $args .= ", $_->{NAME}"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index be7f1ca5c4..13f506a7da 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Util qw(MapSamba3Type); +use Parse::Pidl::Samba3::Types qw(DeclShort); use vars qw($VERSION); $VERSION = '0.01'; @@ -17,24 +17,30 @@ $VERSION = '0.01'; my $res = ""; sub pidl($) { my $x = shift; $res .= "$x\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 ParseElement($) +{ + my $e = shift; + + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "POINTER") { + return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); + pidl "\tuint32 ptr_$e->{NAME};"; + } elsif ($l->{TYPE} eq "SWITCH") { + pidl "\tuint32 level_$e->{NAME};"; + } elsif ($l->{TYPE} eq "DATA") { + pidl "\t" . DeclShort($e) . ";"; + } + } +} sub CreateStruct($$$$) { my ($if,$fn,$n,$t) = @_; pidl "typedef struct $n {"; - foreach my $e (@$t) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "POINTER") { - return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); - pidl "\tuint32 ptr_$e->{NAME};"; - } elsif ($l->{TYPE} eq "SWITCH") { - pidl "\tuint32 level_$e->{NAME};"; - } elsif ($l->{TYPE} eq "DATA") { - pidl "\t" . MapSamba3Type($e) . ";"; - } - } - } + ParseElement($_) foreach (@$t); if (not @$t) { # Some compilers don't like empty structs @@ -83,16 +89,23 @@ sub ParseStruct($$$) CreateStruct($if, $s, "$if->{NAME}_$n", $s->{ELEMENTS}); } +sub ParseUnion($$$) +{ + my ($if,$u,$n) = @_; + + pidl "typedef union {"; + #FIXME: What about elements that require more then one variable? + ParseElement($_) foreach (@{$u->{ELEMENTS}}); + pidl "} $n;"; + pidl ""; +} + sub ParseEnum($$$) { my ($if,$s,$n) = @_; pidl "typedef enum {"; - - foreach (@{$s->{ELEMENTS}}) { - pidl "$_,"; - } - + pidl "$_," foreach (@{$s->{ELEMENTS}}); pidl "} $n;"; } @@ -122,15 +135,15 @@ sub ParseInterface($) pidl ""; - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - foreach (@{$if->{TYPEDEFS}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); - ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "ENUM"); - ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "BITMAP"); - fatal($_, "Unions not supported for Samba3 yet") if ($_->{TYPE} eq "STRUCT"); + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); + ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "ENUM"); + ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "BITMAP"); + ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); } + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + foreach (@{$if->{CONSTS}}) { pidl "$_->{NAME} ($_->{VALUE})"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 8518537ddb..5caab5da0c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Util qw(MapSamba3Type); +use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType); use vars qw($VERSION); $VERSION = '0.01'; @@ -21,24 +21,40 @@ sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } +#TODO: +# - Different scalars / buffers functions for arrays + unions +# - Register own types with Types::AddType() +# - Find external types somehow? + +sub DeclareArrayVariables($) +{ + my $es = shift; + + foreach my $e (@$es) { + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "ARRAY") { + pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; + } + } + } +} + sub ParseElementLevelData($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; - #FIXME: This only works for scalar types - pidl "if (!prs_$l->{DATA_TYPE}(\"$e->{NAME}\", ps, depth, &$varname))"; + pidl "if (!".DissectType($e, $l, $varname).")"; pidl "\treturn False;"; - pidl ""; } sub ParseElementLevelArray($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; - #FIXME - pidl "for (i=0; i<".ParseExpr("length_$e->{NAME}", $env) .";i++) {"; + my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; + pidl "for ($i=0; $i<".ParseExpr("length_$e->{NAME}", $env) .";$i++) {"; indent; - ParseElementLevel($e,$nl,$env,"$varname\[i]"); + ParseElementLevel($e,$nl,$env,$varname."[$i]"); deindent; pidl "}"; } @@ -58,8 +74,9 @@ sub ParseElementLevelPtr($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; - # No top-level ref pointers for Samba 3 - return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP"); + if ($l->{POINTER_TYPE} eq "relative") { + fatal($e, "relative pointers not supported for Samba 3"); + } pidl "if (!prs_uint32(\"ptr_$e->{NAME}\",ps,depth,&" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; pidl "\treturn False;"; @@ -99,24 +116,65 @@ sub ParseElement($$) ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env)); } -sub CreateStruct($$$) +sub InitLevel($$$$); + +sub InitLevel($$$$) +{ + my ($e,$l,$varname,$env) = @_; + + if ($l->{TYPE} eq "POINTER") { + pidl "if ($varname) {"; + indent; + pidl ParseExpr("ptr_$e->{NAME}", $env) . " = 1;"; + InitLevel($e, GetNextLevel($e,$l), $varname, $env); + deindent; + pidl "} else {"; + pidl "\t" . ParseExpr("ptr_$e->{NAME}", $env) . " = 0;"; + pidl "}"; + } elsif ($l->{TYPE} eq "ARRAY") { + pidl "for (i = 0; i < " . ParseExpr("len_$e->{NAME}", $env) . "; i++) {"; + indent; + InitLevel($e, GetNextLevel($e,$l), $varname."[i]", $env); + deindent; + pidl "}"; + } elsif ($l->{TYPE} eq "DATA") { + pidl InitType($e, $l, $varname, $varname); + } elsif ($l->{TYPE} eq "SWITCH") { + InitLevel($e, GetNextLevel($e,$l), $varname, $env); + } +} + +sub CreateStruct($$$$) { - my ($fn,$s,$es) = @_; + my ($fn,$s,$es,$a) = @_; my $args = ""; foreach my $e (@$es) { - $args .= ", " . MapSamba3Type($_); + $args .= ", " . DeclLong($_); + } + + my $env = {}; + foreach my $e (@$es) { + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "DATA") { + $env->{"$e->{NAME}"} = $e->{"v->$e->{NAME}"}; + } elsif ($l->{TYPE} eq "POINTER") { + $env->{"ptr_$e->{NAME}"} = $e->{"v->ptr_$e->{NAME}"}; + } elsif ($l->{TYPE} eq "SWITCH") { + $env->{"level_$e->{NAME}"} = $e->{"v->level_$e->{NAME}"}; + } + } } pidl "BOOL init_$fn($s *v$args)"; pidl "{"; indent; pidl "DEBUG(5,(\"init_$fn\\n\"));"; + pidl ""; # Call init for all arguments - foreach my $e (@$es) { - foreach my $l (@{$e->{LEVELS}}) { - #FIXME - } + foreach (@$es) { + InitLevel($_, $_->{LEVELS}[0], ParseExpr($_->{NAME}, $env), $env); + pidl ""; } pidl "return True;"; deindent; @@ -126,29 +184,22 @@ sub CreateStruct($$$) pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; pidl "{"; indent; + DeclareArrayVariables($es); pidl "if (v == NULL)"; pidl "\treturn False;"; pidl ""; pidl "prs_debug(ps, depth, desc, \"$fn\");"; pidl "depth++;"; - pidl "if (!prs_align(ps))"; - pidl "\treturn False;"; - pidl ""; - - my $env = {}; - foreach my $e (@$es) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{"$e->{NAME}"} = $e->{"v->$e->{NAME}"}; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = $e->{"v->ptr_$e->{NAME}"}; - } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = $e->{"v->level_$e->{NAME}"}; - } - } + if ($a > 0) { + pidl "if (!prs_align(ps, $a))"; + pidl "\treturn False;"; + pidl ""; } - ParseElement($_, $env) foreach (@$es); + foreach (@$es) { + ParseElement($_, $env); + pidl ""; + } pidl "return True;"; deindent; @@ -163,7 +214,7 @@ sub ParseStruct($$$) my $fn = "$if->{NAME}_io_$n"; my $sn = uc("$if->{NAME}_$n"); - CreateStruct($fn, $sn, $s->{ELEMENTS}); + CreateStruct($fn, $sn, $s->{ELEMENTS}, $s->{ALIGN}); } sub ParseUnion($$$) @@ -176,6 +227,11 @@ sub ParseUnion($$$) pidl "BOOL $fn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; pidl "{"; indent; + DeclareArrayVariables($u->{ELEMENTS}); + pidl "if (!prs_align(ps, $u->{ALIGN}))"; + pidl "\treturn False;"; + pidl ""; + pidl "switch (level) {"; indent; @@ -187,6 +243,7 @@ sub ParseUnion($$$) deindent; pidl "depth--;"; pidl "break"; + pidl ""; } deindent; @@ -222,8 +279,8 @@ sub ParseFunction($$) } ); } - CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), \@in); - CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), \@out); + CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), \@in, 0); + CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), \@out, 0); } sub ParseInterface($) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm new file mode 100644 index 0000000000..68bea0d024 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -0,0 +1,169 @@ +################################################### +# Samba3 common helper functions +# Copyright jelmer@samba.org 2005 +# released under the GNU GPL + +package Parse::Pidl::Samba3::Types; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType); + +use strict; +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); + +use vars qw($VERSION); +$VERSION = '0.01'; + +sub init_scalar($$$$) +{ + my ($e,$l,$n,$v) = @_; + + return "$n = $v;"; +} + +sub dissect_scalar($$$) +{ + my ($e,$l,$n) = @_; + + my $t = lc($e->{TYPE}); + + return "prs_$t(\"$e->{NAME}\", ps, depth, &$n)"; +} + +sub decl_string($) +{ + my $e = shift; + + return "UNISTR2"; +} + +sub init_string($$$$) +{ + my ($e,$l,$n,$v) = @_; + + return "init_unistr2(&$n, $v, UNI_FLAGS_NONE);"; +} + +sub dissect_string($$$) +{ + my ($e,$l,$n) = @_; + + return "FIXME"; +} + +my $known_types = { + uint8 => { + DECL => "uint8", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + uint16 => { + DECL => "uint16", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + uint32 => { + DECL => "uint32", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + string => { + DECL => \&decl_string, + INIT => \&init_string, + DISSECT => \&dissect_string, + }, + NTSTATUS => { + DECL => "NTSTATUS", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, + WERROR => { + DECL => "WERROR", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, +}; + +sub AddType($$) +{ + my ($t,$d) = @_; + + warn("Reregistering type $t") if (defined($known_types->{$t})); + + $known_types->{$t} = $d; +} + +sub GetType($) +{ + my $e = shift; + + my $t = $known_types->{$e->{TYPE}}; + + return undef if not $t; + + # DECL can be a function + if (ref($t->{DECL}) eq "CODE") { + return $t->{DECL}->($e); + } else { + return $t->{DECL}; + } +} + +# Return type without special stuff, as used in +# struct declarations +sub DeclShort($) +{ + my $e = shift; + + my $t = GetType($e); + return undef if not $t; + + return "$t $e->{NAME}"; +} + +sub DeclLong($) +{ + my $e = shift; + + my $t = GetType($e); + + return undef if not $t; + + return "$t $e->{NAME}"; +} + +sub InitType($$$$) +{ + my ($e, $l, $varname, $value) = @_; + + my $t = $known_types->{$l->{DATA_TYPE}}; + + return undef if not $t; + + # INIT can be a function + if (ref($t->{INIT}) eq "CODE") { + return $t->{INIT}->($e, $l, $varname, $value); + } else { + return $t->{INIT}; + } +} + +sub DissectType($$$) +{ + my ($e, $l, $varname) = @_; + + my $t = $known_types->{$l->{DATA_TYPE}}; + + return undef if not $t; + + # DISSECT can be a function + if (ref($t->{DISSECT}) eq "CODE") { + return $t->{DISSECT}->($e, $l, $varname); + } else { + return $t->{DISSECT}; + } +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm deleted file mode 100644 index 2d4179df76..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Util.pm +++ /dev/null @@ -1,29 +0,0 @@ -################################################### -# Samba3 common helper functions -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Util; - -require Exporter; -@ISA = qw(Exporter); -@EXPORT_OK = qw(MapSamba3Type); - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); - -use vars qw($VERSION); -$VERSION = '0.01'; - -sub MapSamba3Type($) -{ - my $e = shift; - - return "UNISTR2 $e->{NAME}" if ($e->{TYPE} eq "string"); - - return "$e->{TYPE} $e->{NAME}"; -} - -1; -- cgit From 81c306472a9c6bf6238e916e49076525d4920ed8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Oct 2005 17:21:31 +0000 Subject: r10715: More Samba3 parser generator improvements: - Actually generate parsers for unions and structs. - Support some more builtin types. - Some more work on supporting arrays. - Several other small fixes. I've updated the example output at http://samba.org/~jelmer/ (This used to be commit b229c033ebc7ec972b32f1b75b60a9c68a36db97) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 37 ++++++----- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 97 ++++++++++++++++++++++++---- 2 files changed, 104 insertions(+), 30 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 5caab5da0c..57ee1543ff 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -23,8 +23,7 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Different scalars / buffers functions for arrays + unions -# - Register own types with Types::AddType() -# - Find external types somehow? +# - Memory allocation for arrays? sub DeclareArrayVariables($) { @@ -78,7 +77,7 @@ sub ParseElementLevelPtr($$$$$) fatal($e, "relative pointers not supported for Samba 3"); } - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\",ps,depth,&" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; pidl "\treturn False;"; pidl ""; @@ -138,7 +137,7 @@ sub InitLevel($$$$) deindent; pidl "}"; } elsif ($l->{TYPE} eq "DATA") { - pidl InitType($e, $l, $varname, $varname); + pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); } elsif ($l->{TYPE} eq "SWITCH") { InitLevel($e, GetNextLevel($e,$l), $varname, $env); } @@ -149,20 +148,22 @@ sub CreateStruct($$$$) my ($fn,$s,$es,$a) = @_; my $args = ""; - foreach my $e (@$es) { + foreach (@$es) { $args .= ", " . DeclLong($_); } - my $env = {}; + my $env = { "this" => "v" }; foreach my $e (@$es) { foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "DATA") { - $env->{"$e->{NAME}"} = $e->{"v->$e->{NAME}"}; + $env->{$e->{NAME}} = "v->$e->{NAME}"; } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = $e->{"v->ptr_$e->{NAME}"}; + $env->{"ptr_$e->{NAME}"} = "v->ptr_$e->{NAME}"; } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = $e->{"v->level_$e->{NAME}"}; - } + $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; + } elsif ($l->{TYPE} eq "ARRAY") { + $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; + } } } @@ -173,7 +174,7 @@ sub CreateStruct($$$$) pidl ""; # Call init for all arguments foreach (@$es) { - InitLevel($_, $_->{LEVELS}[0], ParseExpr($_->{NAME}, $env), $env); + InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); pidl ""; } pidl "return True;"; @@ -238,11 +239,13 @@ sub ParseUnion($$$) foreach (@{$u->{ELEMENTS}}) { pidl "$_->{CASE}:"; indent; - pidl "depth++;"; - ParseElement($_, {}); + if ($_->{TYPE} ne "EMPTY") { + pidl "depth++;"; + ParseElement($_, {}); + pidl "depth--;"; + } + pidl "break;"; deindent; - pidl "depth--;"; - pidl "break"; pidl ""; } @@ -290,8 +293,8 @@ sub ParseInterface($) # Structures first pidl "/* $if->{NAME} structures */"; foreach (@{$if->{TYPEDEFS}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "UNION"); + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); + ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); } pidl "/* $if->{NAME} functions */"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 68bea0d024..b9d969216c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -1,5 +1,5 @@ ################################################### -# Samba3 common helper functions +# Samba3 type-specific declarations / initialization / marshalling # Copyright jelmer@samba.org 2005 # released under the GNU GPL @@ -16,6 +16,10 @@ use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use vars qw($VERSION); $VERSION = '0.01'; +# TODO: Find external types somehow? + +sub warning($$) { my ($e,$s) = @_; print STDERR "$e->{FILE}:$e->{LINE}: $s\n"; } + sub init_scalar($$$$) { my ($e,$l,$n,$v) = @_; @@ -36,6 +40,8 @@ sub decl_string($) { my $e = shift; + # FIXME: More intelligent code here - select between UNISTR2 and other + # variants return "UNISTR2"; } @@ -50,40 +56,67 @@ sub dissect_string($$$) { my ($e,$l,$n) = @_; - return "FIXME"; + return "prs_unistr2(True, \"$e->{NAME}\", ps, depth, &n)"; +} + +sub init_uuid($$$$) +{ + my ($e,$l,$n,$v) = @_; + + return ""; +} + +sub dissect_uuid($$$) +{ + my ($e,$l,$n) = @_; + + return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; } -my $known_types = { - uint8 => { +my $known_types = +{ + uint8 => + { DECL => "uint8", INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, - uint16 => { + uint16 => + { DECL => "uint16", INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, - uint32 => { + uint32 => + { DECL => "uint32", INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, - string => { + string => + { DECL => \&decl_string, INIT => \&init_string, DISSECT => \&dissect_string, }, - NTSTATUS => { + NTSTATUS => + { DECL => "NTSTATUS", INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, - WERROR => { + WERROR => + { DECL => "WERROR", INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, + GUID => + { + DECL => "struct uuid", + INIT => \&init_uuid, + DISSECT => \&dissect_uuid, + } }; sub AddType($$) @@ -101,7 +134,10 @@ sub GetType($) my $t = $known_types->{$e->{TYPE}}; - return undef if not $t; + if (not $t) { + warning($e, "Can't declare unknown type $e->{TYPE}"); + return undef; + } # DECL can be a function if (ref($t->{DECL}) eq "CODE") { @@ -131,7 +167,13 @@ sub DeclLong($) return undef if not $t; - return "$t $e->{NAME}"; + my $ptrs = ""; + + foreach my $l (@{$e->{LEVELS}}) { + ($ptrs.="*") if ($l->{TYPE} eq "POINTER"); + } + + return "$t $ptrs$e->{NAME}"; } sub InitType($$$$) @@ -140,7 +182,10 @@ sub InitType($$$$) my $t = $known_types->{$l->{DATA_TYPE}}; - return undef if not $t; + if (not $t) { + warning($e, "Don't know how to initialize type $l->{DATA_TYPE}"); + return undef; + } # INIT can be a function if (ref($t->{INIT}) eq "CODE") { @@ -156,7 +201,10 @@ sub DissectType($$$) my $t = $known_types->{$l->{DATA_TYPE}}; - return undef if not $t; + if (not $t) { + warning($e, "Don't know how to dissect type $l->{DATA_TYPE}"); + return undef; + } # DISSECT can be a function if (ref($t->{DISSECT}) eq "CODE") { @@ -166,4 +214,27 @@ sub DissectType($$$) } } +sub LoadTypes($) +{ + my $ndr = shift; + foreach my $if (@{$ndr}) { + next unless ($if->{TYPE} eq "INTERFACE"); + + foreach my $td (@{$if->{TYPEDEFS}}) { + AddType($td->{NAME}, { + DECL => uc("$if->{NAME}_$td->{NAME}"), + INIT => sub { + my ($e,$l,$n,$v) = @_; + return "init_$td->{NAME}(&$n/*FIXME:OTHER ARGS*/);"; + }, + DISSECT => sub { + my ($e,$l,$n) = @_; + + return "$if->{NAME}_io_$td->{NAME}(\"$e->{NAME}\", &$n, ps, depth)"; + } + }); + } + } +} + 1; -- cgit From eea74cde05c1532d59b9f8ecc4f88c191a4b200f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Oct 2005 18:24:21 +0000 Subject: r10716: Use correct Samba3 data types for strings. Also use Samba3 types for a couple of other types (policy handles, SIDs, times) (This used to be commit c2527217b4b4c120d82044e65b979dd3b7d2609e) --- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 87 +++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 22 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index b9d969216c..f93e90fe1f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -10,7 +10,7 @@ require Exporter; @EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType); use strict; -use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::Util qw(has_property ParseExpr property_matches); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use vars qw($VERSION); @@ -40,37 +40,44 @@ sub decl_string($) { my $e = shift; - # FIXME: More intelligent code here - select between UNISTR2 and other - # variants - return "UNISTR2"; -} + my $is_conformant = property_matches($e, "flag", ".*STR_SIZE4.*"); + my $is_varying = property_matches($e, "flag", ".*STR_LEN4.*"); + my $is_ascii = property_matches($e, "flag", ".*STR_ASCII.*"); -sub init_string($$$$) -{ - my ($e,$l,$n,$v) = @_; - - return "init_unistr2(&$n, $v, UNI_FLAGS_NONE);"; -} + return "STRING2" if ($is_conformant and $is_varying and $is_ascii); -sub dissect_string($$$) -{ - my ($e,$l,$n) = @_; + return "UNISTR2" if ($is_conformant and $is_varying); + return "UNISTR3" if ($is_varying); + # We don't do UNISTR4, as we have lsa_String for that in Samba4's IDL - return "prs_unistr2(True, \"$e->{NAME}\", ps, depth, &n)"; + die("Don't know what string type to use"); } -sub init_uuid($$$$) +sub init_string($$$$) { my ($e,$l,$n,$v) = @_; - return ""; + my $t = lc(decl_string($e)); + + my $flags; + if (property_matches($e, "flag", ".*STR_NULLTERM.*")) { + $flags = "UNI_STR_TERMINATE"; + } elsif (property_matches($e, "flag", ".*STR_NOTERM.*")) { + $flags = "UNI_STR_NOTERM"; + } else { + $flags = "UNI_FLAGS_NONE"; + } + + return "init_$t(&$n, $v, $flags);"; } -sub dissect_uuid($$$) +sub dissect_string($$$) { my ($e,$l,$n) = @_; - return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; + my $t = lc(decl_string($e)); + + return "prs_$t(True, \"$e->{NAME}\", ps, depth, &n)"; } my $known_types = @@ -93,6 +100,12 @@ my $known_types = INIT => \&init_scalar, DISSECT => \&dissect_scalar, }, + uint64 => + { + DECL => "uint64", + INIT => \&init_scalar, + DISSECT => \&dissect_scalar, + }, string => { DECL => \&decl_string, @@ -114,9 +127,39 @@ my $known_types = GUID => { DECL => "struct uuid", - INIT => \&init_uuid, - DISSECT => \&dissect_uuid, - } + INIT => "", + DISSECT => sub { + my ($e,$l,$n) = @_; + return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; + } + }, + NTTIME => + { + DECL => "NTTIME", + INIT => "", + DISSECT => sub { + my ($e,$l,$n) = @_; + return "smb_io_nttime(\"$e->{NAME}\", &n, ps, depth)"; + } + }, + dom_sid => + { + DECL => "DOM_SID", + INIT => "", + DISSECT => sub { + my ($e,$l,$n) = @_; + return "smb_io_dom_sid(\"$e->{NAME}\", &n, ps, depth)"; + } + }, + policy_handle => + { + DECL => "POLICY_HND", + INIT => "", + DISSECT => sub { + my ($e,$l,$n) = @_; + return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; + } + }, }; sub AddType($$) -- cgit From 9879bc6aa6c7997220079b3501b9a4fb3682c813 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Oct 2005 19:38:35 +0000 Subject: r10717: Another bunch of small updates. All generated files except parse_dfs.c compile now when generated from Samba4's dfs.idl. (This used to be commit 2b315b1942e77640eca8e0a3347b2a9ed1920f6a) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 12 +++++++----- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 6 +++--- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 20 +++++++++++++------- source4/pidl/lib/Parse/Pidl/Samba3/Server.pm | 10 +++++++--- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 2 +- 5 files changed, 31 insertions(+), 19 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index 83762719ea..d79aede138 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -25,11 +25,13 @@ sub ParseFunction($$) { my ($if,$fn) = @_; - my $args = ""; + my $inargs = ""; my $defargs = ""; foreach (@{$fn->{ELEMENTS}}) { $defargs .= ", " . DeclLong($_); - $args .= ", $_->{NAME}"; + if (grep(/in/, @{$_->{DIRECTION}})) { + $inargs .= ", $_->{NAME}"; + } } my $uif = uc($if->{NAME}); @@ -47,13 +49,13 @@ sub ParseFunction($$) pidl ""; pidl "/* Marshall data and send request */"; pidl ""; - pidl "init_$if->{NAME}_q_$fn->{NAME}(&q$args);"; + pidl "init_$if->{NAME}_q_$fn->{NAME}(&q$inargs);"; pidl ""; pidl "CLI_DO_RPC(cli, mem_ctx, PI_$uif, $ufn,"; pidl "\tq, r,"; pidl "\tqbuf, rbuf, "; - pidl "\t$if->{NAME}_q_$fn->{NAME},"; - pidl "\t$if->{NAME}_r_$fn->{NAME},"; + pidl "\t$if->{NAME}_io_q_$fn->{NAME},"; + pidl "\t$if->{NAME}_io_r_$fn->{NAME},"; pidl "\tNT_STATUS_UNSUCCESSFUL);"; pidl ""; pidl "/* Return result */"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 13f506a7da..1e0e2c7270 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -58,7 +58,7 @@ sub ParseFunction($$) my @in = (); my @out = (); - foreach (@{$_->{ELEMENTS}}) { + foreach (@{$fn->{ELEMENTS}}) { push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); } @@ -93,10 +93,10 @@ sub ParseUnion($$$) { my ($if,$u,$n) = @_; - pidl "typedef union {"; + pidl "typedef union $if->{NAME}_$n {"; #FIXME: What about elements that require more then one variable? ParseElement($_) foreach (@{$u->{ELEMENTS}}); - pidl "} $n;"; + pidl "} ".uc($if->{NAME}."_".$n) .";"; pidl ""; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 57ee1543ff..9a7c7d2578 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -143,9 +143,9 @@ sub InitLevel($$$$) } } -sub CreateStruct($$$$) +sub CreateStruct($$$$$) { - my ($fn,$s,$es,$a) = @_; + my ($fn,$ifn, $s,$es,$a) = @_; my $args = ""; foreach (@$es) { @@ -167,10 +167,10 @@ sub CreateStruct($$$$) } } - pidl "BOOL init_$fn($s *v$args)"; + pidl "BOOL $ifn($s *v$args)"; pidl "{"; indent; - pidl "DEBUG(5,(\"init_$fn\\n\"));"; + pidl "DEBUG(5,(\"$ifn\\n\"));"; pidl ""; # Call init for all arguments foreach (@$es) { @@ -215,7 +215,7 @@ sub ParseStruct($$$) my $fn = "$if->{NAME}_io_$n"; my $sn = uc("$if->{NAME}_$n"); - CreateStruct($fn, $sn, $s->{ELEMENTS}, $s->{ALIGN}); + CreateStruct($fn, "init_$if->{NAME}_$n", $sn, $s->{ELEMENTS}, $s->{ALIGN}); } sub ParseUnion($$$) @@ -282,8 +282,14 @@ sub ParseFunction($$) } ); } - CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), \@in, 0); - CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), \@out, 0); + CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", + "init_$if->{NAME}_q_$fn->{NAME}", + uc("$if->{NAME}_q_$fn->{NAME}"), + \@in, 0); + CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", + "init_$if->{NAME}_r_$fn->{NAME}", + uc("$if->{NAME}_r_$fn->{NAME}"), + \@out, 0); } sub ParseInterface($) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm index 0372cf1117..3f1f4645a1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm @@ -33,13 +33,17 @@ sub ParseFunction($$) indent; pidl uc("$if->{NAME}_q_$fn->{NAME}") . " q_u;"; pidl uc("$if->{NAME}_r_$fn->{NAME}") . " r_u;"; - pidl "prs_struct *data = &p->in_data.data"; - pidl "prs_struct *rdata = &p->out_data.rdata"; + pidl "prs_struct *data = &p->in_data.data;"; + pidl "prs_struct *rdata = &p->out_data.rdata;"; pidl ""; pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; pidl "\treturn False;"; pidl ""; - pidl "r_u.status = _$fn->{NAME}(p, &q_u, &r_u);"; + if ($fn->{RETURN_TYPE}) { + pidl "r_u.status = _$fn->{NAME}(p, &q_u, &r_u);"; + } else { + pidl "_$fn->{NAME}(p, &q_u, &r_u);"; + } pidl ""; pidl "if (!$if->{NAME}_io_r_$fn->{NAME}(\"\", &r_u, rdata, 0))"; pidl "\treturn False;"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index f93e90fe1f..c09246e5a9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -268,7 +268,7 @@ sub LoadTypes($) DECL => uc("$if->{NAME}_$td->{NAME}"), INIT => sub { my ($e,$l,$n,$v) = @_; - return "init_$td->{NAME}(&$n/*FIXME:OTHER ARGS*/);"; + return "$n = $v;"; }, DISSECT => sub { my ($e,$l,$n) = @_; -- cgit From 3d6279402caa862db4a7bc4697c667fbd1faa83d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Oct 2005 21:25:18 +0000 Subject: r10718: Another large set of small improvements. All generated files compile without warnings now. The only things left to do that are required for DFS: - add allocation of arrays in marshalling phase - handling primitive and deferred data in embedded structures / unions. Example output is again available from http://samba.org/~jelmer/pidl_samba3/ (This used to be commit 9fe724f6fb026d95306587f696c065f348aaf219) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 8 ++ source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 7 ++ source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 73 +++++++++------ source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 128 +++++++++++++++++++++------ 4 files changed, 160 insertions(+), 56 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index d79aede138..b48a1b519f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -58,6 +58,14 @@ sub ParseFunction($$) pidl "\t$if->{NAME}_io_r_$fn->{NAME},"; pidl "\tNT_STATUS_UNSUCCESSFUL);"; pidl ""; + pidl "/* Return variables */"; + foreach (@{$fn->{ELEMENTS}}) { + next unless (grep(/out/, @{$_->{DIRECTION}})); + + pidl "*$_->{NAME} = r.$_->{NAME};"; + } + + pidl""; pidl "/* Return result */"; if (not $fn->{RETURN_TYPE}) { pidl "return NT_STATUS_OK;"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 1e0e2c7270..21a56e4c2d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -31,6 +31,13 @@ sub ParseElement($) pidl "\tuint32 level_$e->{NAME};"; } elsif ($l->{TYPE} eq "DATA") { pidl "\t" . DeclShort($e) . ";"; + } elsif ($l->{TYPE} eq "ARRAY") { + if ($l->{IS_CONFORMANT}) { + pidl "\tuint32 size_$e->{NAME};"; + } + if ($l->{IS_VARYING}) { + pidl "\tuint32 length_$e->{NAME};"; + } } } } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 9a7c7d2578..166d98bfb1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -23,26 +23,38 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Different scalars / buffers functions for arrays + unions -# - Memory allocation for arrays? +# - Memory allocation for arrays sub DeclareArrayVariables($) { my $es = shift; + my $output = 0; + foreach my $e (@$es) { foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "ARRAY") { pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; + $output = 1; } } } + pidl "" if $output; } sub ParseElementLevelData($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; - pidl "if (!".DissectType($e, $l, $varname).")"; + my @args = ($e,$l,$varname); + + # See if we need to add a level argument because we're parsing a union + foreach (@{$e->{LEVELS}}) { + push (@args, ParseExpr("level_$e->{NAME}", $env)) + if ($_->{TYPE} eq "SWITCH"); + } + + pidl "if (!".DissectType(@args).")"; pidl "\treturn False;"; } @@ -50,8 +62,10 @@ sub ParseElementLevelArray($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; + my $len = ParseExpr($l->{LENGTH_IS}, $env); + my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; - pidl "for ($i=0; $i<".ParseExpr("length_$e->{NAME}", $env) .";$i++) {"; + pidl "for ($i=0; $i<$len;$i++) {"; indent; ParseElementLevel($e,$nl,$env,$varname."[$i]"); deindent; @@ -62,7 +76,7 @@ sub ParseElementLevelSwitch($$$$$) { my ($e,$l,$nl,$env,$varname) = @_; - pidl "if (!prs_uint32(\"level\", ps, depth, " . ParseExpr("level_$e->{NAME}", $env) . ", ps, depth))"; + pidl "if (!prs_uint32(\"level\", ps, depth, &" . ParseExpr("level_$e->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; @@ -77,7 +91,7 @@ sub ParseElementLevelPtr($$$$$) fatal($e, "relative pointers not supported for Samba 3"); } - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; @@ -115,27 +129,22 @@ sub ParseElement($$) ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env)); } -sub InitLevel($$$$); - sub InitLevel($$$$) { + sub InitLevel($$$$); my ($e,$l,$varname,$env) = @_; if ($l->{TYPE} eq "POINTER") { pidl "if ($varname) {"; indent; pidl ParseExpr("ptr_$e->{NAME}", $env) . " = 1;"; - InitLevel($e, GetNextLevel($e,$l), $varname, $env); + InitLevel($e, GetNextLevel($e,$l), "*$varname", $env); deindent; pidl "} else {"; pidl "\t" . ParseExpr("ptr_$e->{NAME}", $env) . " = 0;"; pidl "}"; } elsif ($l->{TYPE} eq "ARRAY") { - pidl "for (i = 0; i < " . ParseExpr("len_$e->{NAME}", $env) . "; i++) {"; - indent; - InitLevel($e, GetNextLevel($e,$l), $varname."[i]", $env); - deindent; - pidl "}"; + pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; } elsif ($l->{TYPE} eq "DATA") { pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); } elsif ($l->{TYPE} eq "SWITCH") { @@ -143,6 +152,22 @@ sub InitLevel($$$$) } } +sub GenerateEnvElement($$) +{ + my ($e,$env) = @_; + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "DATA") { + $env->{$e->{NAME}} = "v->$e->{NAME}"; + } elsif ($l->{TYPE} eq "POINTER") { + $env->{"ptr_$e->{NAME}"} = "v->ptr_$e->{NAME}"; + } elsif ($l->{TYPE} eq "SWITCH") { + $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; + } elsif ($l->{TYPE} eq "ARRAY") { + $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; + } + } +} + sub CreateStruct($$$$$) { my ($fn,$ifn, $s,$es,$a) = @_; @@ -153,19 +178,7 @@ sub CreateStruct($$$$$) } my $env = { "this" => "v" }; - foreach my $e (@$es) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{$e->{NAME}} = "v->$e->{NAME}"; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = "v->ptr_$e->{NAME}"; - } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; - } elsif ($l->{TYPE} eq "ARRAY") { - $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; - } - } - } + GenerateEnvElement($_, $env) foreach (@$es); pidl "BOOL $ifn($s *v$args)"; pidl "{"; @@ -192,7 +205,7 @@ sub CreateStruct($$$$$) pidl "prs_debug(ps, depth, desc, \"$fn\");"; pidl "depth++;"; if ($a > 0) { - pidl "if (!prs_align(ps, $a))"; + pidl "if (!prs_align_custom(ps, $a))"; pidl "\treturn False;"; pidl ""; } @@ -229,7 +242,7 @@ sub ParseUnion($$$) pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); - pidl "if (!prs_align(ps, $u->{ALIGN}))"; + pidl "if (!prs_align_custom(ps, $u->{ALIGN}))"; pidl "\treturn False;"; pidl ""; @@ -241,7 +254,9 @@ sub ParseUnion($$$) indent; if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; - ParseElement($_, {}); + my $env = {}; + GenerateEnvElement($_, $env); + ParseElement($_, $env); pidl "depth--;"; } pidl "break;"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index c09246e5a9..a3bf91d54f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -53,6 +53,26 @@ sub decl_string($) die("Don't know what string type to use"); } +sub contains_pointer($) +{ + my $e = shift; + + foreach my $l (@{$e->{LEVELS}}) { + return 1 if ($l->{TYPE} eq "POINTER"); + } + + return 0; +} + +sub ext_decl_string($) +{ + my $e = shift; + + # One pointer is sufficient.. + return "const char" if (contains_pointer($e)); + return "const char *"; +} + sub init_string($$$$) { my ($e,$l,$n,$v) = @_; @@ -67,6 +87,9 @@ sub init_string($$$$) } else { $flags = "UNI_FLAGS_NONE"; } + + # One pointer is sufficient + if (substr($v, 0, 1) eq "*") { $v = substr($v, 1); } return "init_$t(&$n, $v, $flags);"; } @@ -77,7 +100,7 @@ sub dissect_string($$$) my $t = lc(decl_string($e)); - return "prs_$t(True, \"$e->{NAME}\", ps, depth, &n)"; + return "prs_$t(True, \"$e->{NAME}\", ps, depth, &$n)"; } my $known_types = @@ -109,6 +132,7 @@ my $known_types = string => { DECL => \&decl_string, + EXT_DECL => \&ext_decl_string, INIT => \&init_string, DISSECT => \&dissect_string, }, @@ -172,6 +196,14 @@ sub AddType($$) } sub GetType($) +{ + my $e = shift; + +} + +# Return type without special stuff, as used in +# declarations for internal structs +sub DeclShort($) { my $e = shift; @@ -182,41 +214,66 @@ sub GetType($) return undef; } + my $p; + # DECL can be a function if (ref($t->{DECL}) eq "CODE") { - return $t->{DECL}->($e); + $p = $t->{DECL}->($e); } else { - return $t->{DECL}; + $p = $t->{DECL}; } -} -# Return type without special stuff, as used in -# struct declarations -sub DeclShort($) -{ - my $e = shift; - - my $t = GetType($e); - return undef if not $t; + my $prefixes = ""; + my $suffixes = ""; + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { + $prefixes = "*$prefixes"; + } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { + $suffixes.="[$l->{SIZE_IS}]"; + } + } - return "$t $e->{NAME}"; + return "$p $prefixes$e->{NAME}$suffixes"; } +# Return type including special stuff (pointers, etc). sub DeclLong($) { my $e = shift; - my $t = GetType($e); + my $t = $known_types->{$e->{TYPE}}; + + if (not $t) { + warning($e, "Can't declare unknown type $e->{TYPE}"); + return undef; + } + + my $p; - return undef if not $t; + if (defined($t->{EXT_DECL})) { + $p = $t->{EXT_DECL} + } else { + $p = $t->{DECL}; + } - my $ptrs = ""; + if (ref($p) eq "CODE") { + $p = $p->($e); + } + + my $prefixes = ""; + my $suffixes = ""; foreach my $l (@{$e->{LEVELS}}) { - ($ptrs.="*") if ($l->{TYPE} eq "POINTER"); + if ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { + $prefixes = "*$prefixes"; + } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { + $suffixes.="[$l->{SIZE_IS}]"; + } elsif ($l->{TYPE} eq "POINTER") { + $prefixes = "*$prefixes"; + } } - return "$t $ptrs$e->{NAME}"; + return "$p $prefixes$e->{NAME}$suffixes"; } sub InitType($$$$) @@ -238,9 +295,12 @@ sub InitType($$$$) } } -sub DissectType($$$) +sub DissectType { - my ($e, $l, $varname) = @_; + my @args = @_; + my $e = shift @_; + my $l = shift @_; + my $varname = shift @_; my $t = $known_types->{$l->{DATA_TYPE}}; @@ -251,7 +311,7 @@ sub DissectType($$$) # DISSECT can be a function if (ref($t->{DISSECT}) eq "CODE") { - return $t->{DISSECT}->($e, $l, $varname); + return $t->{DISSECT}->(@args); } else { return $t->{DISSECT}; } @@ -264,17 +324,31 @@ sub LoadTypes($) next unless ($if->{TYPE} eq "INTERFACE"); foreach my $td (@{$if->{TYPEDEFS}}) { - AddType($td->{NAME}, { - DECL => uc("$if->{NAME}_$td->{NAME}"), - INIT => sub { + my $decl = uc("$if->{NAME}_$td->{NAME}"); + my $init = sub { my ($e,$l,$n,$v) = @_; return "$n = $v;"; - }, - DISSECT => sub { + }; + + my $dissect; + if ($td->{DATA}->{TYPE} eq "UNION") { + $dissect = sub { + my ($e,$l,$n,$s) = @_; + + return "$if->{NAME}_io_$td->{NAME}(\"$e->{NAME}\", &$n, $s, ps, depth)"; + }; + } else { + $dissect = sub { my ($e,$l,$n) = @_; return "$if->{NAME}_io_$td->{NAME}(\"$e->{NAME}\", &$n, ps, depth)"; - } + }; + } + + AddType($td->{NAME}, { + DECL => $decl, + INIT => $init, + DISSECT => $dissect }); } } -- cgit From d220237b19f361a2c3c09b292e11f54c8d522fdf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 00:29:47 +0000 Subject: r10721: Handle allocations and primitive / deferred data correctly. In theory, the generated output for DFS should work now (it compiles cleanly, but I haven't tested it yet). Not supported: - subcontexts() - relative pointers - unions of pointers - DATA_BLOB - several other things Also still need to do: - Remove some spurious spaces in the output - Do range() checking Example output is still available at http://samba.org/~jelmer/pidl_samba3/ (This used to be commit e2d7e382bb645f1bddd2047669bed10f121b59d2) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 1 + source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 286 +++++++++++++++++++++------ source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 69 ++++--- 3 files changed, 273 insertions(+), 83 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 21a56e4c2d..5b7fddc14f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -37,6 +37,7 @@ sub ParseElement($) } if ($l->{IS_VARYING}) { pidl "\tuint32 length_$e->{NAME};"; + pidl "\tuint32 offset_$e->{NAME};"; } } } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 166d98bfb1..702835c378 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -14,6 +14,9 @@ use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType); use vars qw($VERSION); $VERSION = '0.01'; +use constant PRIMITIVES => 1; +use constant DEFERRED => 2; + my $res = ""; my $tabs = ""; sub indent() { $tabs.="\t"; } @@ -22,17 +25,22 @@ sub pidl($) { $res .= $tabs.(shift)."\n"; } sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: -# - Different scalars / buffers functions for arrays + unions -# - Memory allocation for arrays +# - Add some security checks (array sizes, memory alloc == NULL, etc) +# - Don't add seperate _p and _d functions if there is no deferred data -sub DeclareArrayVariables($) +sub DeclareArrayVariables { my $es = shift; + my $what = shift; my $output = 0; foreach my $e (@$es) { foreach my $l (@{$e->{LEVELS}}) { + if ($what) { + next if ($l->{IS_DEFERRED} and $what == PRIMITIVES); + next if (not $l->{IS_DEFERRED} and $what == DEFERRED); + } if ($l->{TYPE} eq "ARRAY") { pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; $output = 1; @@ -42,11 +50,11 @@ sub DeclareArrayVariables($) pidl "" if $output; } -sub ParseElementLevelData($$$$$) +sub ParseElementLevelData($$$$$$) { - my ($e,$l,$nl,$env,$varname) = @_; + my ($e,$l,$nl,$env,$varname,$what) = @_; - my @args = ($e,$l,$varname); + my @args = ($e,$l,$varname,$what); # See if we need to add a level argument because we're parsing a union foreach (@{$e->{LEVELS}}) { @@ -54,64 +62,107 @@ sub ParseElementLevelData($$$$$) if ($_->{TYPE} eq "SWITCH"); } - pidl "if (!".DissectType(@args).")"; + my $c = DissectType(@args); + return if not $c; + + pidl "if (!$c)"; pidl "\treturn False;"; } -sub ParseElementLevelArray($$$$$) +sub ParseElementLevelArray($$$$$$) { - my ($e,$l,$nl,$env,$varname) = @_; + my ($e,$l,$nl,$env,$varname,$what) = @_; my $len = ParseExpr($l->{LENGTH_IS}, $env); + my $size = ParseExpr($l->{SIZE_IS}, $env); + + if ($what == PRIMITIVES) { + # Fetch headers + if ($l->{IS_CONFORMANT} and not $l->{IS_SURROUNDING}) { + pidl "if (!prs_uint32(\"size_$e->{NAME}\", ps, depth, &" . ParseExpr("size_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + } + + if ($l->{IS_VARYING}) { + pidl "if (!prs_uint32(\"offset_$e->{NAME}\", ps, depth, &" . ParseExpr("offset_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + + pidl "if (!prs_uint32(\"length_$e->{NAME}\", ps, depth, &" . ParseExpr("length_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + } + } + + # Everything but fixed arrays have to be allocated + if (!$l->{IS_FIXED} and $what == PRIMITIVES) { + pidl "if (UNMARSHALLING(ps)) {"; + indent; + pidl "$varname = (void *)PRS_ALLOC_MEM_VOID(ps,sizeof(*$varname)*$size);"; + deindent; + pidl "}"; + } + + return if ($what == DEFERRED and not ContainsDeferred($e,$l)); my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; pidl "for ($i=0; $i<$len;$i++) {"; indent; - ParseElementLevel($e,$nl,$env,$varname."[$i]"); + ParseElementLevel($e,$nl,$env,$varname."[$i]",$what); deindent; pidl "}"; } -sub ParseElementLevelSwitch($$$$$) +sub ParseElementLevelSwitch($$$$$$) { - my ($e,$l,$nl,$env,$varname) = @_; + my ($e,$l,$nl,$env,$varname,$what) = @_; - pidl "if (!prs_uint32(\"level\", ps, depth, &" . ParseExpr("level_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; + if ($what == PRIMITIVES) { + pidl "if (!prs_uint32(\"level\", ps, depth, &" . ParseExpr("level_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + } - ParseElementLevel($e,$nl,$env,$varname); + ParseElementLevel($e,$nl,$env,$varname,$what); } -sub ParseElementLevelPtr($$$$$) +sub ParseElementLevelPtr($$$$$$) { - my ($e,$l,$nl,$env,$varname) = @_; + my ($e,$l,$nl,$env,$varname,$what) = @_; + + if ($what == PRIMITIVES) { + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + } if ($l->{POINTER_TYPE} eq "relative") { fatal($e, "relative pointers not supported for Samba 3"); + #FIXME } - - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - pidl "if (" . ParseExpr("ptr_$e->{NAME}", $env) . ") {"; - indent; - ParseElementLevel($e,$nl,$env,$varname); - deindent; - pidl "}"; + if ($what == DEFERRED) { + pidl "if (" . ParseExpr("ptr_$e->{NAME}", $env) . ") {"; + indent; + ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES); + ParseElementLevel($e,$nl,$env,$varname,DEFERRED); + deindent; + pidl "}"; + } } -sub ParseElementLevelSubcontext($$$$$) +sub ParseElementLevelSubcontext($$$$$$) { - my ($e,$l,$nl,$env,$varname) = @_; + my ($e,$l,$nl,$env,$varname,$what) = @_; fatal($e, "subcontext() not supported for Samba 3"); + #FIXME } -sub ParseElementLevel($$$$) +sub ParseElementLevel($$$$$) { - my ($e,$l,$env,$varname) = @_; + my ($e,$l,$env,$varname,$what) = @_; { DATA => \&ParseElementLevelData, @@ -119,14 +170,14 @@ sub ParseElementLevel($$$$) POINTER => \&ParseElementLevelPtr, SWITCH => \&ParseElementLevelSwitch, ARRAY => \&ParseElementLevelArray - }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname); + }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname,$what); } -sub ParseElement($$) +sub ParseElement($$$) { - my ($e,$env) = @_; + my ($e,$env,$what) = @_; - ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env)); + ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env), $what); } sub InitLevel($$$$) @@ -164,29 +215,35 @@ sub GenerateEnvElement($$) $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; } elsif ($l->{TYPE} eq "ARRAY") { $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; + $env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}"; + $env->{"offset_$e->{NAME}"} = "v->offset_$e->{NAME}"; } } } -sub CreateStruct($$$$$) +sub ParseStruct($$$) { - my ($fn,$ifn, $s,$es,$a) = @_; + my ($if,$s,$n) = @_; + + my $fn = "$if->{NAME}_io_$n"; + my $sn = uc("$if->{NAME}_$n"); + my $ifn = "init_$if->{NAME}_$n"; my $args = ""; - foreach (@$es) { + foreach (@{$s->{ELEMENTS}}) { $args .= ", " . DeclLong($_); } my $env = { "this" => "v" }; - GenerateEnvElement($_, $env) foreach (@$es); + GenerateEnvElement($_, $env) foreach (@{$s->{ELEMENTS}}); - pidl "BOOL $ifn($s *v$args)"; + pidl "BOOL $ifn($sn *v$args)"; pidl "{"; indent; pidl "DEBUG(5,(\"$ifn\\n\"));"; pidl ""; # Call init for all arguments - foreach (@$es) { + foreach (@{$s->{ELEMENTS}}) { InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); pidl ""; } @@ -194,24 +251,31 @@ sub CreateStruct($$$$$) deindent; pidl "}"; pidl ""; + + my $pfn = "$fn\_p"; + my $dfn = "$fn\_d"; - pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; + pidl "BOOL $pfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; pidl "{"; indent; - DeclareArrayVariables($es); + DeclareArrayVariables($s->{ELEMENTS}, PRIMITIVES); pidl "if (v == NULL)"; pidl "\treturn False;"; pidl ""; - pidl "prs_debug(ps, depth, desc, \"$fn\");"; + pidl "prs_debug(ps, depth, desc, \"$pfn\");"; pidl "depth++;"; - if ($a > 0) { - pidl "if (!prs_align_custom(ps, $a))"; + pidl "if (!prs_align_custom(ps, $s->{ALIGN}))"; + pidl "\treturn False;"; + pidl ""; + + if ($s->{SURROUNDING_ELEMENT}) { + pidl "if (!prs_uint32(\"size_$s->{SURROUNDING_ELEMENT}->{NAME}\", ps, depth, &" . ParseExpr("size_$s->{SURROUNDING_ELEMENT}->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; } - foreach (@$es) { - ParseElement($_, $env); + foreach (@{$s->{ELEMENTS}}) { + ParseElement($_, $env, PRIMITIVES); pidl ""; } @@ -219,16 +283,29 @@ sub CreateStruct($$$$$) deindent; pidl "}"; pidl ""; -} -sub ParseStruct($$$) -{ - my ($if,$s,$n) = @_; + pidl "BOOL $dfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; + pidl "{"; + indent; + DeclareArrayVariables($s->{ELEMENTS}, DEFERRED); + pidl "if (v == NULL)"; + pidl "\treturn False;"; + pidl ""; + pidl "prs_debug(ps, depth, desc, \"$dfn\");"; + pidl "depth++;"; + pidl "if (!prs_align_custom(ps, $s->{ALIGN}))"; + pidl "\treturn False;"; + pidl ""; - my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n"); + foreach (@{$s->{ELEMENTS}}) { + ParseElement($_, $env, DEFERRED); + pidl ""; + } - CreateStruct($fn, "init_$if->{NAME}_$n", $sn, $s->{ELEMENTS}, $s->{ALIGN}); + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; } sub ParseUnion($$$) @@ -238,7 +315,44 @@ sub ParseUnion($$$) my $fn = "$if->{NAME}_io_$n"; my $sn = uc("$if->{NAME}_$n"); - pidl "BOOL $fn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; + my $pfn = "$fn\_p"; + my $dfn = "$fn\_d"; + + pidl "BOOL $pfn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; + pidl "{"; + indent; + DeclareArrayVariables($u->{ELEMENTS}); + pidl "if (!prs_align_custom(ps, $u->{ALIGN}))"; + pidl "\treturn False;"; + pidl ""; + + pidl "switch (level) {"; + indent; + + foreach (@{$u->{ELEMENTS}}) { + pidl "$_->{CASE}:"; + indent; + if ($_->{TYPE} ne "EMPTY") { + pidl "depth++;"; + my $env = {}; + GenerateEnvElement($_, $env); + ParseElement($_, $env, PRIMITIVES); + ParseElement($_, $env, DEFERRED); + pidl "depth--;"; + } + pidl "break;"; + deindent; + pidl ""; + } + + deindent; + pidl "}"; + pidl ""; + pidl "return True;"; + deindent; + pidl "}"; + + pidl "BOOL $dfn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); @@ -256,7 +370,7 @@ sub ParseUnion($$$) pidl "depth++;"; my $env = {}; GenerateEnvElement($_, $env); - ParseElement($_, $env); + ParseElement($_, $env, DEFERRED); pidl "depth--;"; } pidl "break;"; @@ -270,6 +384,56 @@ sub ParseUnion($$$) pidl "return True;"; deindent; pidl "}"; + +} + +sub CreateFnDirection($$$$) +{ + my ($fn,$ifn, $s,$es) = @_; + + my $args = ""; + foreach (@$es) { + $args .= ", " . DeclLong($_); + } + + my $env = { "this" => "v" }; + GenerateEnvElement($_, $env) foreach (@$es); + + pidl "BOOL $ifn($s *v$args)"; + pidl "{"; + indent; + pidl "DEBUG(5,(\"$ifn\\n\"));"; + pidl ""; + # Call init for all arguments + foreach (@$es) { + InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); + pidl ""; + } + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; + + pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; + pidl "{"; + indent; + DeclareArrayVariables($es); + pidl "if (v == NULL)"; + pidl "\treturn False;"; + pidl ""; + pidl "prs_debug(ps, depth, desc, \"$fn\");"; + pidl "depth++;"; + + foreach (@$es) { + ParseElement($_, $env, PRIMITIVES); + ParseElement($_, $env, DEFERRED); + pidl ""; + } + + pidl "return True;"; + deindent; + pidl "}"; + pidl ""; } sub ParseFunction($$) @@ -297,14 +461,14 @@ sub ParseFunction($$) } ); } - CreateStruct("$if->{NAME}_io_q_$fn->{NAME}", + CreateFnDirection("$if->{NAME}_io_q_$fn->{NAME}", "init_$if->{NAME}_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), - \@in, 0); - CreateStruct("$if->{NAME}_io_r_$fn->{NAME}", + \@in); + CreateFnDirection("$if->{NAME}_io_r_$fn->{NAME}", "init_$if->{NAME}_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), - \@out, 0); + \@out); } sub ParseInterface($) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index a3bf91d54f..9a7a31a6bb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -109,50 +109,50 @@ my $known_types = { DECL => "uint8", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, uint16 => { DECL => "uint16", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, uint32 => { DECL => "uint32", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, uint64 => { DECL => "uint64", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, string => { DECL => \&decl_string, EXT_DECL => \&ext_decl_string, INIT => \&init_string, - DISSECT => \&dissect_string, + DISSECT_P => \&dissect_string, }, NTSTATUS => { DECL => "NTSTATUS", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, WERROR => { DECL => "WERROR", INIT => \&init_scalar, - DISSECT => \&dissect_scalar, + DISSECT_P => \&dissect_scalar, }, GUID => { DECL => "struct uuid", INIT => "", - DISSECT => sub { + DISSECT_P => sub { my ($e,$l,$n) = @_; return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; } @@ -161,7 +161,7 @@ my $known_types = { DECL => "NTTIME", INIT => "", - DISSECT => sub { + DISSECT_P => sub { my ($e,$l,$n) = @_; return "smb_io_nttime(\"$e->{NAME}\", &n, ps, depth)"; } @@ -170,7 +170,7 @@ my $known_types = { DECL => "DOM_SID", INIT => "", - DISSECT => sub { + DISSECT_P => sub { my ($e,$l,$n) = @_; return "smb_io_dom_sid(\"$e->{NAME}\", &n, ps, depth)"; } @@ -179,7 +179,7 @@ my $known_types = { DECL => "POLICY_HND", INIT => "", - DISSECT => sub { + DISSECT_P => sub { my ($e,$l,$n) = @_; return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; } @@ -301,6 +301,7 @@ sub DissectType my $e = shift @_; my $l = shift @_; my $varname = shift @_; + my $what = shift @_; my $t = $known_types->{$l->{DATA_TYPE}}; @@ -309,11 +310,20 @@ sub DissectType return undef; } + my $dissect; + if ($what == 1) { #primitives + $dissect = $t->{DISSECT_P}; + } elsif ($what == 2) { + $dissect = $t->{DISSECT_D}; + } + + return "" if not defined($dissect); + # DISSECT can be a function - if (ref($t->{DISSECT}) eq "CODE") { - return $t->{DISSECT}->(@args); + if (ref($dissect) eq "CODE") { + return $dissect->(@args); } else { - return $t->{DISSECT}; + return $dissect; } } @@ -330,25 +340,40 @@ sub LoadTypes($) return "$n = $v;"; }; - my $dissect; + my $dissect_d; + my $dissect_p; if ($td->{DATA}->{TYPE} eq "UNION") { - $dissect = sub { - my ($e,$l,$n,$s) = @_; + $dissect_p = sub { + my ($e,$l,$n,$w,$s) = @_; + + return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, $s, ps, depth)"; + }; - return "$if->{NAME}_io_$td->{NAME}(\"$e->{NAME}\", &$n, $s, ps, depth)"; + $dissect_d = sub { + my ($e,$l,$n,$w,$s) = @_; + + return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, $s, ps, depth)"; }; + } else { - $dissect = sub { - my ($e,$l,$n) = @_; + $dissect_p = sub { + my ($e,$l,$n,$w) = @_; - return "$if->{NAME}_io_$td->{NAME}(\"$e->{NAME}\", &$n, ps, depth)"; + return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; }; + $dissect_d = sub { + my ($e,$l,$n,$w) = @_; + + return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; + }; + } AddType($td->{NAME}, { DECL => $decl, INIT => $init, - DISSECT => $dissect + DISSECT_D => $dissect_d, + DISSECT_P => $dissect_p }); } } -- cgit From 5df3b426ee691adaaaa65424aa2cee22dcc10607 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 14:52:35 +0000 Subject: r10732: Generate _ctr structures for unions (This used to be commit bd8fcb05003ad75f521783ad9603c923eacafc1a) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 27 ++++++++++++++++++--- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 35 ++++++++++++++++++++++++---- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 11 +++++++++ 3 files changed, 65 insertions(+), 8 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 5b7fddc14f..6254abaa2d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -101,10 +101,31 @@ sub ParseUnion($$$) { my ($if,$u,$n) = @_; - pidl "typedef union $if->{NAME}_$n {"; - #FIXME: What about elements that require more then one variable? + my $extra = {"switch_value" => 1}; + + foreach my $e (@{$u->{ELEMENTS}}) { + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "ARRAY") { + if ($l->{IS_CONFORMANT}) { + $extra->{"size"} = 1; + } + if ($l->{IS_VARYING}) { + $extra->{"length"} = $extra->{"offset"} = 1; + } + } elsif ($l->{TYPE} eq "POINTER") { + $extra->{"ptr"} = 1; + } elsif ($l->{TYPE} eq "SWITCH") { + $extra->{"level"} = 1; + } + } + } + + pidl "typedef struct $if->{NAME}_$n\_ctr {"; + pidl "\tuint32 $_;" foreach (keys %$extra); + pidl "\tunion {"; ParseElement($_) foreach (@{$u->{ELEMENTS}}); - pidl "} ".uc($if->{NAME}."_".$n) .";"; + pidl "\t} u;"; + pidl "} ".uc("$if->{NAME}_$n\_ctr") .";"; pidl ""; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 702835c378..49c7cf5e81 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -73,6 +73,11 @@ sub ParseElementLevelArray($$$$$$) { my ($e,$l,$nl,$env,$varname,$what) = @_; + if ($l->{IS_ZERO_TERMINATED}) { + fatal($e, "[string] attribute not supported for Samba3 yet"); + #FIXME + } + my $len = ParseExpr($l->{LENGTH_IS}, $env); my $size = ParseExpr($l->{SIZE_IS}, $env); @@ -308,12 +313,34 @@ sub ParseStruct($$$) pidl ""; } +sub UnionGenerateEnvElement($) +{ + my $e = shift; + my $env = {}; + + foreach my $l (@{$e->{LEVELS}}) { + if ($l->{TYPE} eq "DATA") { + $env->{$e->{NAME}} = "v->u.$e->{NAME}"; + } elsif ($l->{TYPE} eq "POINTER") { + $env->{"ptr_$e->{NAME}"} = "v->ptr"; + } elsif ($l->{TYPE} eq "SWITCH") { + $env->{"level_$e->{NAME}"} = "v->level"; + } elsif ($l->{TYPE} eq "ARRAY") { + $env->{"length_$e->{NAME}"} = "v->length"; + $env->{"size_$e->{NAME}"} = "v->size"; + $env->{"offset_$e->{NAME}"} = "v->offset"; + } + } + + return $env; +} + sub ParseUnion($$$) { my ($if,$u,$n) = @_; my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n"); + my $sn = uc("$if->{NAME}_$n\_ctr"); my $pfn = "$fn\_p"; my $dfn = "$fn\_d"; @@ -334,8 +361,7 @@ sub ParseUnion($$$) indent; if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; - my $env = {}; - GenerateEnvElement($_, $env); + my $env = UnionGenerateEnvElement($_); ParseElement($_, $env, PRIMITIVES); ParseElement($_, $env, DEFERRED); pidl "depth--;"; @@ -368,8 +394,7 @@ sub ParseUnion($$$) indent; if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; - my $env = {}; - GenerateEnvElement($_, $env); + my $env = UnionGenerateEnvElement($_); ParseElement($_, $env, DEFERRED); pidl "depth--;"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 9a7a31a6bb..38e740189b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -184,6 +184,15 @@ my $known_types = return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; } }, + hyper => + { + DECL => "uint64", + INIT => "", + DISSECT_P => sub { + my ($e,$l,$n) = @_; + return "prs_uint64(\"$e->{NAME}\", ps, depth, &$n)"; + } + }, }; sub AddType($$) @@ -335,6 +344,7 @@ sub LoadTypes($) foreach my $td (@{$if->{TYPEDEFS}}) { my $decl = uc("$if->{NAME}_$td->{NAME}"); + my $init = sub { my ($e,$l,$n,$v) = @_; return "$n = $v;"; @@ -343,6 +353,7 @@ sub LoadTypes($) my $dissect_d; my $dissect_p; if ($td->{DATA}->{TYPE} eq "UNION") { + $decl.="_CTR"; $dissect_p = sub { my ($e,$l,$n,$w,$s) = @_; -- cgit From 4bbb584ff0dcc172bbaeeff9e8f6dff6d2b94e66 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 17:13:29 +0000 Subject: r10734: Generate ptr, size, offset, and length elements in unions just once. (This used to be commit 12bfa5d01bcb4cb9dad5167e1a3721fd68f06275) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 27 +++++++++++++++++++++------ source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 15 +++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 6254abaa2d..4579ae2ec0 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -15,7 +15,10 @@ use vars qw($VERSION); $VERSION = '0.01'; my $res = ""; -sub pidl($) { my $x = shift; $res .= "$x\n"; } +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"); } @@ -101,7 +104,11 @@ sub ParseUnion($$$) { my ($if,$u,$n) = @_; - my $extra = {"switch_value" => 1}; + my $extra = {}; + + unless (has_property($u, "nodiscriminant")) { + $extra->{switch_value} = 1; + } foreach my $e (@{$u->{ELEMENTS}}) { foreach my $l (@{$e->{LEVELS}}) { @@ -121,10 +128,17 @@ sub ParseUnion($$$) } pidl "typedef struct $if->{NAME}_$n\_ctr {"; - pidl "\tuint32 $_;" foreach (keys %$extra); - pidl "\tunion {"; - ParseElement($_) foreach (@{$u->{ELEMENTS}}); - pidl "\t} u;"; + indent; + pidl "uint32 $_;" foreach (keys %$extra); + pidl "union {"; + indent; + foreach (@{$u->{ELEMENTS}}) { + next if ($_->{TYPE} eq "EMPTY"); + pidl "\t" . DeclShort($_) . ";"; + } + deindent; + pidl "} u;"; + deindent; pidl "} ".uc("$if->{NAME}_$n\_ctr") .";"; pidl ""; } @@ -185,6 +199,7 @@ sub Parse($$) my($ndr,$filename) = @_; $res = ""; + $tabs = ""; pidl "/*"; pidl " * Unix SMB/CIFS implementation."; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 49c7cf5e81..d1188e7011 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -75,6 +75,7 @@ sub ParseElementLevelArray($$$$$$) if ($l->{IS_ZERO_TERMINATED}) { fatal($e, "[string] attribute not supported for Samba3 yet"); + #FIXME } @@ -123,12 +124,6 @@ sub ParseElementLevelSwitch($$$$$$) { my ($e,$l,$nl,$env,$varname,$what) = @_; - if ($what == PRIMITIVES) { - pidl "if (!prs_uint32(\"level\", ps, depth, &" . ParseExpr("level_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - ParseElementLevel($e,$nl,$env,$varname,$what); } @@ -353,6 +348,14 @@ sub ParseUnion($$$) pidl "\treturn False;"; pidl ""; + if (has_property($u, "nodiscriminant")) { + pidl "if (!prs_uint32(\"switch_value\", ps, depth, &v->switch_value))"; + pidl "\treturn False;"; + pidl ""; + } + + # Maybe check here that level and v->switch_value are equal? + pidl "switch (level) {"; indent; -- cgit From f72dee9e3908fb5c4ea3428e3cba703509a7e16f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 19:41:53 +0000 Subject: r10737: Fix some alignment issues (This used to be commit 2b4270a2e965eb5c6fe0b25d22d2977e60bb7d43) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 111 +++++++++++++++++---------- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 2 +- 2 files changed, 70 insertions(+), 43 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index d1188e7011..b65ece5a12 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -27,6 +27,23 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Add some security checks (array sizes, memory alloc == NULL, etc) # - Don't add seperate _p and _d functions if there is no deferred data +# - [string] +# - subcontext() +# - DATA_BLOB + +sub Align($$) +{ + my ($a,$b) = @_; + + # Only align if previous element was smaller then current one + if ($$a < $b) { + pidl "if (!prs_align_custom(ps, $b))"; + pidl "\treturn False;"; + pidl ""; + } + + $$a = $b; +} sub DeclareArrayVariables { @@ -50,12 +67,19 @@ sub DeclareArrayVariables pidl "" if $output; } -sub ParseElementLevelData($$$$$$) +sub ParseElementLevelData($$$$$$$) { - my ($e,$l,$nl,$env,$varname,$what) = @_; + my ($e,$l,$nl,$env,$varname,$what,$align) = @_; my @args = ($e,$l,$varname,$what); + if (defined($e->{ALIGN})) { + Align($align, $e->{ALIGN}); + } else { + # Default to 4 + Align($align, 4); + } + # See if we need to add a level argument because we're parsing a union foreach (@{$e->{LEVELS}}) { push (@args, ParseExpr("level_$e->{NAME}", $env)) @@ -69,9 +93,9 @@ sub ParseElementLevelData($$$$$$) pidl "\treturn False;"; } -sub ParseElementLevelArray($$$$$$) +sub ParseElementLevelArray($$$$$$$) { - my ($e,$l,$nl,$env,$varname,$what) = @_; + my ($e,$l,$nl,$env,$varname,$what,$align) = @_; if ($l->{IS_ZERO_TERMINATED}) { fatal($e, "[string] attribute not supported for Samba3 yet"); @@ -85,12 +109,14 @@ sub ParseElementLevelArray($$$$$$) if ($what == PRIMITIVES) { # Fetch headers if ($l->{IS_CONFORMANT} and not $l->{IS_SURROUNDING}) { + Align($align, 4); pidl "if (!prs_uint32(\"size_$e->{NAME}\", ps, depth, &" . ParseExpr("size_$e->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; } if ($l->{IS_VARYING}) { + Align($align, 4); pidl "if (!prs_uint32(\"offset_$e->{NAME}\", ps, depth, &" . ParseExpr("offset_$e->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; @@ -115,26 +141,34 @@ sub ParseElementLevelArray($$$$$$) my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; pidl "for ($i=0; $i<$len;$i++) {"; indent; - ParseElementLevel($e,$nl,$env,$varname."[$i]",$what); + ParseElementLevel($e,$nl,$env,$varname."[$i]",$what,$align); deindent; pidl "}"; } -sub ParseElementLevelSwitch($$$$$$) +sub ParseElementLevelSwitch($$$$$$$) { - my ($e,$l,$nl,$env,$varname,$what) = @_; + my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - ParseElementLevel($e,$nl,$env,$varname,$what); + ParseElementLevel($e,$nl,$env,$varname,$what,$align); } -sub ParseElementLevelPtr($$$$$$) +sub ParseElementLevelPtr($$$$$$$) { - my ($e,$l,$nl,$env,$varname,$what) = @_; + my ($e,$l,$nl,$env,$varname,$what,$align) = @_; if ($what == PRIMITIVES) { - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; + if ($l->{POINTER_TYPE} eq "ref" and + $l->{LEVEL} eq "TOP") { + pidl "if (!" . ParseExpr("ptr_$e->{NAME}", $env) . ")"; + pidl "\treturn False;"; + pidl ""; + } else { + Align($align, 4); + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; + pidl "\treturn False;"; + pidl ""; + } } if ($l->{POINTER_TYPE} eq "relative") { @@ -145,24 +179,25 @@ sub ParseElementLevelPtr($$$$$$) if ($what == DEFERRED) { pidl "if (" . ParseExpr("ptr_$e->{NAME}", $env) . ") {"; indent; - ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES); - ParseElementLevel($e,$nl,$env,$varname,DEFERRED); + ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES,$align); + ParseElementLevel($e,$nl,$env,$varname,DEFERRED,$align); deindent; pidl "}"; + $$align = 0; } } -sub ParseElementLevelSubcontext($$$$$$) +sub ParseElementLevelSubcontext($$$$$$$) { - my ($e,$l,$nl,$env,$varname,$what) = @_; + my ($e,$l,$nl,$env,$varname,$what,$align) = @_; fatal($e, "subcontext() not supported for Samba 3"); #FIXME } -sub ParseElementLevel($$$$$) +sub ParseElementLevel($$$$$$) { - my ($e,$l,$env,$varname,$what) = @_; + my ($e,$l,$env,$varname,$what,$align) = @_; { DATA => \&ParseElementLevelData, @@ -170,14 +205,14 @@ sub ParseElementLevel($$$$$) POINTER => \&ParseElementLevelPtr, SWITCH => \&ParseElementLevelSwitch, ARRAY => \&ParseElementLevelArray - }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname,$what); + }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname,$what,$align); } -sub ParseElement($$$) +sub ParseElement($$$$) { - my ($e,$env,$what) = @_; + my ($e,$env,$what,$align) = @_; - ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env), $what); + ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env), $what, $align); } sub InitLevel($$$$) @@ -264,9 +299,6 @@ sub ParseStruct($$$) pidl ""; pidl "prs_debug(ps, depth, desc, \"$pfn\");"; pidl "depth++;"; - pidl "if (!prs_align_custom(ps, $s->{ALIGN}))"; - pidl "\treturn False;"; - pidl ""; if ($s->{SURROUNDING_ELEMENT}) { pidl "if (!prs_uint32(\"size_$s->{SURROUNDING_ELEMENT}->{NAME}\", ps, depth, &" . ParseExpr("size_$s->{SURROUNDING_ELEMENT}->{NAME}", $env) . "))"; @@ -274,8 +306,9 @@ sub ParseStruct($$$) pidl ""; } + my $align = 0; foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, PRIMITIVES); + ParseElement($_, $env, PRIMITIVES, \$align); pidl ""; } @@ -293,12 +326,10 @@ sub ParseStruct($$$) pidl ""; pidl "prs_debug(ps, depth, desc, \"$dfn\");"; pidl "depth++;"; - pidl "if (!prs_align_custom(ps, $s->{ALIGN}))"; - pidl "\treturn False;"; - pidl ""; + $align = 0; foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, DEFERRED); + ParseElement($_, $env, DEFERRED, \$align); pidl ""; } @@ -344,9 +375,6 @@ sub ParseUnion($$$) pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); - pidl "if (!prs_align_custom(ps, $u->{ALIGN}))"; - pidl "\treturn False;"; - pidl ""; if (has_property($u, "nodiscriminant")) { pidl "if (!prs_uint32(\"switch_value\", ps, depth, &v->switch_value))"; @@ -365,8 +393,8 @@ sub ParseUnion($$$) if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; my $env = UnionGenerateEnvElement($_); - ParseElement($_, $env, PRIMITIVES); - ParseElement($_, $env, DEFERRED); + my $align = 0; + ParseElement($_, $env, PRIMITIVES, \$align); pidl "depth--;"; } pidl "break;"; @@ -385,9 +413,6 @@ sub ParseUnion($$$) pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); - pidl "if (!prs_align_custom(ps, $u->{ALIGN}))"; - pidl "\treturn False;"; - pidl ""; pidl "switch (level) {"; indent; @@ -398,7 +423,8 @@ sub ParseUnion($$$) if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; my $env = UnionGenerateEnvElement($_); - ParseElement($_, $env, DEFERRED); + my $align = 0; + ParseElement($_, $env, DEFERRED, \$align); pidl "depth--;"; } pidl "break;"; @@ -452,9 +478,10 @@ sub CreateFnDirection($$$$) pidl "prs_debug(ps, depth, desc, \"$fn\");"; pidl "depth++;"; + my $align = 0; foreach (@$es) { - ParseElement($_, $env, PRIMITIVES); - ParseElement($_, $env, DEFERRED); + ParseElement($_, $env, PRIMITIVES, \$align); + ParseElement($_, $env, DEFERRED, \$align); pidl ""; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 38e740189b..0c66d2c6ad 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -100,7 +100,7 @@ sub dissect_string($$$) my $t = lc(decl_string($e)); - return "prs_$t(True, \"$e->{NAME}\", ps, depth, &$n)"; + return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)"; } my $known_types = -- cgit From 765f69ce42068cc2a41e010d08922a496da96054 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 19:53:41 +0000 Subject: r10739: Reduce number of calls to prs_align_custom() (This used to be commit ebeeec5406308d493d45b1088963a87cdb953cac) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 22 ++++++++++++---------- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 26 ++++++++++++++------------ 2 files changed, 26 insertions(+), 22 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index b65ece5a12..ac7fde69a6 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -71,14 +71,7 @@ sub ParseElementLevelData($$$$$$$) { my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - my @args = ($e,$l,$varname,$what); - - if (defined($e->{ALIGN})) { - Align($align, $e->{ALIGN}); - } else { - # Default to 4 - Align($align, 4); - } + my @args = ($e,$l,$varname,$what,$align); # See if we need to add a level argument because we're parsing a union foreach (@{$e->{LEVELS}}) { @@ -89,6 +82,13 @@ sub ParseElementLevelData($$$$$$$) my $c = DissectType(@args); return if not $c; + if (defined($e->{ALIGN})) { + Align($align, $e->{ALIGN}); + } else { + # Default to 4 + Align($align, 4); + } + pidl "if (!$c)"; pidl "\treturn False;"; } @@ -300,13 +300,15 @@ sub ParseStruct($$$) pidl "prs_debug(ps, depth, desc, \"$pfn\");"; pidl "depth++;"; + my $align = 8; if ($s->{SURROUNDING_ELEMENT}) { pidl "if (!prs_uint32(\"size_$s->{SURROUNDING_ELEMENT}->{NAME}\", ps, depth, &" . ParseExpr("size_$s->{SURROUNDING_ELEMENT}->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; + $align = 4; + } - my $align = 0; foreach (@{$s->{ELEMENTS}}) { ParseElement($_, $env, PRIMITIVES, \$align); pidl ""; @@ -393,7 +395,7 @@ sub ParseUnion($$$) if ($_->{TYPE} ne "EMPTY") { pidl "depth++;"; my $env = UnionGenerateEnvElement($_); - my $align = 0; + my $align = 8; ParseElement($_, $env, PRIMITIVES, \$align); pidl "depth--;"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 0c66d2c6ad..8cb09343ac 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -27,9 +27,9 @@ sub init_scalar($$$$) return "$n = $v;"; } -sub dissect_scalar($$$) +sub dissect_scalar($$$$$) { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; my $t = lc($e->{TYPE}); @@ -94,12 +94,13 @@ sub init_string($$$$) return "init_$t(&$n, $v, $flags);"; } -sub dissect_string($$$) +sub dissect_string($$$$$) { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; my $t = lc(decl_string($e)); + $$a = 1; return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)"; } @@ -162,7 +163,7 @@ my $known_types = DECL => "NTTIME", INIT => "", DISSECT_P => sub { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; return "smb_io_nttime(\"$e->{NAME}\", &n, ps, depth)"; } }, @@ -171,7 +172,7 @@ my $known_types = DECL => "DOM_SID", INIT => "", DISSECT_P => sub { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; return "smb_io_dom_sid(\"$e->{NAME}\", &n, ps, depth)"; } }, @@ -180,7 +181,7 @@ my $known_types = DECL => "POLICY_HND", INIT => "", DISSECT_P => sub { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; return "smb_io_pol_hnd(\"$e->{NAME}\", &n, ps, depth)"; } }, @@ -189,7 +190,7 @@ my $known_types = DECL => "uint64", INIT => "", DISSECT_P => sub { - my ($e,$l,$n) = @_; + my ($e,$l,$n,$w,$a) = @_; return "prs_uint64(\"$e->{NAME}\", ps, depth, &$n)"; } }, @@ -311,6 +312,7 @@ sub DissectType my $l = shift @_; my $varname = shift @_; my $what = shift @_; + my $align = shift @_; my $t = $known_types->{$l->{DATA_TYPE}}; @@ -355,25 +357,25 @@ sub LoadTypes($) if ($td->{DATA}->{TYPE} eq "UNION") { $decl.="_CTR"; $dissect_p = sub { - my ($e,$l,$n,$w,$s) = @_; + my ($e,$l,$n,$w,$a,$s) = @_; return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, $s, ps, depth)"; }; $dissect_d = sub { - my ($e,$l,$n,$w,$s) = @_; + my ($e,$l,$n,$w,$a,$s) = @_; return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, $s, ps, depth)"; }; } else { $dissect_p = sub { - my ($e,$l,$n,$w) = @_; + my ($e,$l,$n,$w,$a) = @_; return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; }; $dissect_d = sub { - my ($e,$l,$n,$w) = @_; + my ($e,$l,$n,$w,$a) = @_; return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; }; -- cgit From be9af1a4e8d474a544840f657b1be0c302986417 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Oct 2005 22:18:59 +0000 Subject: r10742: Support multi-level pointers + ref pointer fixes (This used to be commit 258b762dc62b257f99d1d859c5a3d850aba3e9fa) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 34 +++++++++++++++--- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 4 +-- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 54 ++++++++++++++++++---------- 3 files changed, 67 insertions(+), 25 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index b48a1b519f..164f53d06b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -20,6 +20,28 @@ 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 CopyLevel($$$$) +{ + sub CopyLevel($$$$); + my ($e,$l,$argument,$member) = @_; + + if ($l->{TYPE} eq "DATA") { + pidl "*$argument = $member;"; + } elsif ($l->{TYPE} eq "POINTER") { + pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {"; + indent; + pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));"; + CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member); + deindent; + pidl "}"; + } elsif ($l->{TYPE} eq "SWITCH") { + CopyLevel($e,GetNextLevel($e,$l),$argument,$member); + } elsif ($l->{TYPE} eq "ARRAY") { + pidl "*$argument = $member;"; + } +} sub ParseFunction($$) { @@ -59,10 +81,14 @@ sub ParseFunction($$) pidl "\tNT_STATUS_UNSUCCESSFUL);"; pidl ""; pidl "/* Return variables */"; - foreach (@{$fn->{ELEMENTS}}) { - next unless (grep(/out/, @{$_->{DIRECTION}})); - - pidl "*$_->{NAME} = r.$_->{NAME};"; + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/out/, @{$e->{DIRECTION}})); + + if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") { + warning($e->{ORIGINAL}, "First element not a pointer for [out] argument"); + next; + } + CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}"); } pidl""; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 4579ae2ec0..1bcaa5c672 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -29,7 +29,7 @@ sub ParseElement($) foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "POINTER") { return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); - pidl "\tuint32 ptr_$e->{NAME};"; + pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; } elsif ($l->{TYPE} eq "SWITCH") { pidl "\tuint32 level_$e->{NAME};"; } elsif ($l->{TYPE} eq "DATA") { @@ -120,7 +120,7 @@ sub ParseUnion($$$) $extra->{"length"} = $extra->{"offset"} = 1; } } elsif ($l->{TYPE} eq "POINTER") { - $extra->{"ptr"} = 1; + $extra->{"ptr$l->{POINTER_INDEX}"} = 1; } elsif ($l->{TYPE} eq "SWITCH") { $extra->{"level"} = 1; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index ac7fde69a6..7cd1255a40 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -158,14 +158,16 @@ sub ParseElementLevelPtr($$$$$$$) my ($e,$l,$nl,$env,$varname,$what,$align) = @_; if ($what == PRIMITIVES) { - if ($l->{POINTER_TYPE} eq "ref" and - $l->{LEVEL} eq "TOP") { - pidl "if (!" . ParseExpr("ptr_$e->{NAME}", $env) . ")"; + if (($l->{POINTER_TYPE} eq "ref") and ($l->{LEVEL} eq "EMBEDDED")) { + # Ref pointers always have to be non-NULL + pidl "if (MARSHALLING(ps) && !" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ")"; pidl "\treturn False;"; pidl ""; - } else { + } + + unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { Align($align, 4); - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . "))"; + pidl "if (!prs_uint32(\"ptr$l->{POINTER_INDEX}_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . "))"; pidl "\treturn False;"; pidl ""; } @@ -177,12 +179,16 @@ sub ParseElementLevelPtr($$$$$$$) } if ($what == DEFERRED) { - pidl "if (" . ParseExpr("ptr_$e->{NAME}", $env) . ") {"; - indent; + if ($l->{POINTER_TYPE} ne "ref") { + pidl "if (" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ") {"; + indent; + } ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES,$align); ParseElementLevel($e,$nl,$env,$varname,DEFERRED,$align); - deindent; - pidl "}"; + if ($l->{POINTER_TYPE} ne "ref") { + deindent; + pidl "}"; + } $$align = 0; } } @@ -221,14 +227,24 @@ sub InitLevel($$$$) my ($e,$l,$varname,$env) = @_; if ($l->{TYPE} eq "POINTER") { - pidl "if ($varname) {"; - indent; - pidl ParseExpr("ptr_$e->{NAME}", $env) . " = 1;"; + if ($l->{POINTER_TYPE} eq "ref") { + pidl "if (!$varname)"; + pidl "\treturn False;"; + pidl ""; + } else { + pidl "if ($varname) {"; + indent; + } + + pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;"; InitLevel($e, GetNextLevel($e,$l), "*$varname", $env); - deindent; - pidl "} else {"; - pidl "\t" . ParseExpr("ptr_$e->{NAME}", $env) . " = 0;"; - pidl "}"; + + if ($l->{POINTER_TYPE} ne "ref") { + deindent; + pidl "} else {"; + pidl "\t" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 0;"; + pidl "}"; + } } elsif ($l->{TYPE} eq "ARRAY") { pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; } elsif ($l->{TYPE} eq "DATA") { @@ -245,7 +261,7 @@ sub GenerateEnvElement($$) if ($l->{TYPE} eq "DATA") { $env->{$e->{NAME}} = "v->$e->{NAME}"; } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = "v->ptr_$e->{NAME}"; + $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}"; } elsif ($l->{TYPE} eq "SWITCH") { $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; } elsif ($l->{TYPE} eq "ARRAY") { @@ -350,7 +366,7 @@ sub UnionGenerateEnvElement($) if ($l->{TYPE} eq "DATA") { $env->{$e->{NAME}} = "v->u.$e->{NAME}"; } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = "v->ptr"; + $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}"; } elsif ($l->{TYPE} eq "SWITCH") { $env->{"level_$e->{NAME}"} = "v->level"; } elsif ($l->{TYPE} eq "ARRAY") { @@ -480,7 +496,7 @@ sub CreateFnDirection($$$$) pidl "prs_debug(ps, depth, desc, \"$fn\");"; pidl "depth++;"; - my $align = 0; + my $align = 8; foreach (@$es) { ParseElement($_, $env, PRIMITIVES, \$align); ParseElement($_, $env, DEFERRED, \$align); -- cgit From 0ef04670398f27d36bf9dabf39a925a2ba2b29d0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Oct 2005 20:07:53 +0000 Subject: r10787: Fix silly nodiscriminant-issue (This used to be commit 43a5c863bf81af9b8415b6ccf8a386c36d4fa7f9) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 7cd1255a40..eaab50b553 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -394,7 +394,7 @@ sub ParseUnion($$$) indent; DeclareArrayVariables($u->{ELEMENTS}); - if (has_property($u, "nodiscriminant")) { + unless (has_property($u, "nodiscriminant")) { pidl "if (!prs_uint32(\"switch_value\", ps, depth, &v->switch_value))"; pidl "\treturn False;"; pidl ""; -- cgit From c5069ba7e3dbabd586a3a313d6c2d287b0a46e2f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Oct 2005 20:53:55 +0000 Subject: r10788: - Give unions a name - Check initialisation function return value (This used to be commit ebb8e75ebd572d62bdb3615d41c210bcc918fa41) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 3 ++- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index 164f53d06b..ee1ab09324 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -71,7 +71,8 @@ sub ParseFunction($$) pidl ""; pidl "/* Marshall data and send request */"; pidl ""; - pidl "init_$if->{NAME}_q_$fn->{NAME}(&q$inargs);"; + pidl "if (!init_$if->{NAME}_q_$fn->{NAME}(&q$inargs))"; + pidl "\treturn NT_STATUS_INVALID_PARAMETER;"; pidl ""; pidl "CLI_DO_RPC(cli, mem_ctx, PI_$uif, $ufn,"; pidl "\tq, r,"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 1bcaa5c672..78bd8fe339 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -130,7 +130,7 @@ sub ParseUnion($$$) pidl "typedef struct $if->{NAME}_$n\_ctr {"; indent; pidl "uint32 $_;" foreach (keys %$extra); - pidl "union {"; + pidl "union $if->{NAME}_$n {"; indent; foreach (@{$u->{ELEMENTS}}) { next if ($_->{TYPE} eq "EMPTY"); -- cgit From 848dff8f0d9242c0c7a417a1482c14ac289deb6f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Oct 2005 00:33:19 +0000 Subject: r10829: Documentation updates Update TODO Some small fixes to the modules (This used to be commit 0c53e7c3cf7fd91fd34c48a5e68c1bcf70569854) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 15 +++++------ source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 40 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 17 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 78bd8fe339..25102e511a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -31,7 +31,6 @@ sub ParseElement($) return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; } elsif ($l->{TYPE} eq "SWITCH") { - pidl "\tuint32 level_$e->{NAME};"; } elsif ($l->{TYPE} eq "DATA") { pidl "\t" . DeclShort($e) . ";"; } elsif ($l->{TYPE} eq "ARRAY") { @@ -106,30 +105,28 @@ sub ParseUnion($$$) my $extra = {}; - unless (has_property($u, "nodiscriminant")) { - $extra->{switch_value} = 1; - } + $extra->{switch_value} = $u->{SWITCH_TYPE}; foreach my $e (@{$u->{ELEMENTS}}) { foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "ARRAY") { if ($l->{IS_CONFORMANT}) { - $extra->{"size"} = 1; + $extra->{"size"} = "uint32"; } if ($l->{IS_VARYING}) { - $extra->{"length"} = $extra->{"offset"} = 1; + $extra->{"length"} = $extra->{"offset"} = "uint32"; } } elsif ($l->{TYPE} eq "POINTER") { - $extra->{"ptr$l->{POINTER_INDEX}"} = 1; + $extra->{"ptr$l->{POINTER_INDEX}"} = "uint32"; } elsif ($l->{TYPE} eq "SWITCH") { - $extra->{"level"} = 1; + $extra->{"level"} = "uint32"; } } } pidl "typedef struct $if->{NAME}_$n\_ctr {"; indent; - pidl "uint32 $_;" foreach (keys %$extra); + pidl "$extra->{$_} $_;" foreach (keys %$extra); pidl "union $if->{NAME}_$n {"; indent; foreach (@{$u->{ELEMENTS}}) { diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index eaab50b553..c6cc188391 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -75,8 +75,18 @@ sub ParseElementLevelData($$$$$$$) # See if we need to add a level argument because we're parsing a union foreach (@{$e->{LEVELS}}) { - push (@args, ParseExpr("level_$e->{NAME}", $env)) - if ($_->{TYPE} eq "SWITCH"); + next unless ($_->{TYPE} eq "SWITCH"); + my $t = getType($l->{DATA_TYPE}); + + # Set 0 here because one of the variables referenced in SWITCH_IS + # might be an in variable while this one is [out] + if (grep(/in/, @{$e->{DIRECTION}}) or + not defined($t) or + has_property($t->{DATA}, "nodiscriminant")) { + push (@args, ParseExpr($_->{SWITCH_IS}, $env)); + } else { + push (@args, -1); + } } my $c = DissectType(@args); @@ -263,7 +273,6 @@ sub GenerateEnvElement($$) } elsif ($l->{TYPE} eq "POINTER") { $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}"; } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; } elsif ($l->{TYPE} eq "ARRAY") { $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; $env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}"; @@ -368,7 +377,6 @@ sub UnionGenerateEnvElement($) } elsif ($l->{TYPE} eq "POINTER") { $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}"; } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = "v->level"; } elsif ($l->{TYPE} eq "ARRAY") { $env->{"length_$e->{NAME}"} = "v->length"; $env->{"size_$e->{NAME}"} = "v->size"; @@ -394,15 +402,20 @@ sub ParseUnion($$$) indent; DeclareArrayVariables($u->{ELEMENTS}); - unless (has_property($u, "nodiscriminant")) { - pidl "if (!prs_uint32(\"switch_value\", ps, depth, &v->switch_value))"; + if (defined ($u->{SWITCH_TYPE})) { + pidl "if (MARSHALLING(ps)) "; + pidl "\tv->switch_value = level;"; + pidl ""; + pidl "if (!prs_$u->{SWITCH_TYPE}(\"switch_value\", ps, depth, &v->switch_value))"; pidl "\treturn False;"; pidl ""; + } else { + pidl "v->switch_value = level;"; } # Maybe check here that level and v->switch_value are equal? - pidl "switch (level) {"; + pidl "switch (v->switch_value) {"; indent; foreach (@{$u->{ELEMENTS}}) { @@ -420,19 +433,30 @@ sub ParseUnion($$$) pidl ""; } + unless ($u->{HAS_DEFAULT}) { + pidl "default:"; + pidl "\treturn False;"; + pidl ""; + } + deindent; pidl "}"; pidl ""; pidl "return True;"; deindent; pidl "}"; + pidl ""; pidl "BOOL $dfn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); - pidl "switch (level) {"; + if (defined($u->{SWITCH_TYPE})) { + pidl "switch (v->switch_value) {"; + } else { + pidl "switch (level) {"; + } indent; foreach (@{$u->{ELEMENTS}}) { -- cgit From 36517c801cb7116df635dea8a129730c5bc014ea Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Oct 2005 20:19:35 +0000 Subject: r10842: Fix some issues with [out] unions that have a discriminator that is only [in] (This used to be commit 3a4086d6142fa73b3adb2d66b1bfc9cd2585f31d) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 3 +- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 10 ++++-- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 52 +++++++++------------------- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 48 +++++++------------------ 4 files changed, 37 insertions(+), 76 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index ee1ab09324..ceeb81c3d7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -84,11 +84,12 @@ sub ParseFunction($$) pidl "/* Return variables */"; foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - + if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") { warning($e->{ORIGINAL}, "First element not a pointer for [out] argument"); next; } + CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}"); } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 25102e511a..d14bac2df7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -103,9 +103,13 @@ sub ParseUnion($$$) { my ($if,$u,$n) = @_; - my $extra = {}; - - $extra->{switch_value} = $u->{SWITCH_TYPE}; + my $extra = { + switch_value => $u->{SWITCH_TYPE} + }; + + if (not defined($extra->{switch_value})) { + $extra->{switch_value} = "uint32"; + } foreach my $e (@{$u->{ELEMENTS}}) { foreach my $l (@{$e->{LEVELS}}) { diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index c6cc188391..b87951adee 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -71,25 +71,7 @@ sub ParseElementLevelData($$$$$$$) { my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - my @args = ($e,$l,$varname,$what,$align); - - # See if we need to add a level argument because we're parsing a union - foreach (@{$e->{LEVELS}}) { - next unless ($_->{TYPE} eq "SWITCH"); - my $t = getType($l->{DATA_TYPE}); - - # Set 0 here because one of the variables referenced in SWITCH_IS - # might be an in variable while this one is [out] - if (grep(/in/, @{$e->{DIRECTION}}) or - not defined($t) or - has_property($t->{DATA}, "nodiscriminant")) { - push (@args, ParseExpr($_->{SWITCH_IS}, $env)); - } else { - push (@args, -1); - } - } - - my $c = DissectType(@args); + my $c = DissectType($e,$l,$varname,$what,$align); return if not $c; if (defined($e->{ALIGN})) { @@ -261,6 +243,7 @@ sub InitLevel($$$$) pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); } elsif ($l->{TYPE} eq "SWITCH") { InitLevel($e, GetNextLevel($e,$l), $varname, $env); + pidl ParseExpr($e->{NAME}, $env) . ".switch_value = " . ParseExpr($l->{SWITCH_IS}, $env) . ";"; } } @@ -397,20 +380,15 @@ sub ParseUnion($$$) my $pfn = "$fn\_p"; my $dfn = "$fn\_d"; - pidl "BOOL $pfn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; + pidl "BOOL $pfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); if (defined ($u->{SWITCH_TYPE})) { - pidl "if (MARSHALLING(ps)) "; - pidl "\tv->switch_value = level;"; - pidl ""; pidl "if (!prs_$u->{SWITCH_TYPE}(\"switch_value\", ps, depth, &v->switch_value))"; pidl "\treturn False;"; pidl ""; - } else { - pidl "v->switch_value = level;"; } # Maybe check here that level and v->switch_value are equal? @@ -447,7 +425,7 @@ sub ParseUnion($$$) pidl "}"; pidl ""; - pidl "BOOL $dfn(const char *desc, $sn* v, uint32 level, prs_struct *ps, int depth)"; + pidl "BOOL $dfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; pidl "{"; indent; DeclareArrayVariables($u->{ELEMENTS}); @@ -483,16 +461,14 @@ sub ParseUnion($$$) } -sub CreateFnDirection($$$$) +sub CreateFnDirection($$$$$) { - my ($fn,$ifn, $s,$es) = @_; + my ($fn,$ifn,$s,$all,$es) = @_; my $args = ""; - foreach (@$es) { - $args .= ", " . DeclLong($_); - } + foreach (@$all) { $args .= ", " . DeclLong($_); } - my $env = { "this" => "v" }; + my $env = { }; GenerateEnvElement($_, $env) foreach (@$es); pidl "BOOL $ifn($s *v$args)"; @@ -539,6 +515,7 @@ sub ParseFunction($$) my @in = (); my @out = (); + my @all = @{$fn->{ELEMENTS}}; foreach (@{$fn->{ELEMENTS}}) { push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); @@ -546,7 +523,7 @@ sub ParseFunction($$) } if (defined($fn->{RETURN_TYPE})) { - push (@out, { + my $status = { NAME => "status", TYPE => $fn->{RETURN_TYPE}, LEVELS => [ @@ -555,17 +532,20 @@ sub ParseFunction($$) DATA_TYPE => $fn->{RETURN_TYPE} } ] - } ); + }; + + push (@out, $status); + push (@all, $status); } CreateFnDirection("$if->{NAME}_io_q_$fn->{NAME}", "init_$if->{NAME}_q_$fn->{NAME}", uc("$if->{NAME}_q_$fn->{NAME}"), - \@in); + \@in, \@in); CreateFnDirection("$if->{NAME}_io_r_$fn->{NAME}", "init_$if->{NAME}_r_$fn->{NAME}", uc("$if->{NAME}_r_$fn->{NAME}"), - \@out); + \@all, \@out); } sub ParseInterface($) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 8cb09343ac..135b02f1e3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -205,12 +205,6 @@ sub AddType($$) $known_types->{$t} = $d; } -sub GetType($) -{ - my $e = shift; - -} - # Return type without special stuff, as used in # declarations for internal structs sub DeclShort($) @@ -305,14 +299,9 @@ sub InitType($$$$) } } -sub DissectType +sub DissectType($$$$$) { - my @args = @_; - my $e = shift @_; - my $l = shift @_; - my $varname = shift @_; - my $what = shift @_; - my $align = shift @_; + my ($e,$l,$varname,$what,$align) = @_; my $t = $known_types->{$l->{DATA_TYPE}}; @@ -332,7 +321,7 @@ sub DissectType # DISSECT can be a function if (ref($dissect) eq "CODE") { - return $dissect->(@args); + return $dissect->($e,$l,$varname,$what,$align); } else { return $dissect; } @@ -356,31 +345,18 @@ sub LoadTypes($) my $dissect_p; if ($td->{DATA}->{TYPE} eq "UNION") { $decl.="_CTR"; - $dissect_p = sub { - my ($e,$l,$n,$w,$a,$s) = @_; - - return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, $s, ps, depth)"; - }; + } - $dissect_d = sub { - my ($e,$l,$n,$w,$a,$s) = @_; + $dissect_p = sub { + my ($e,$l,$n,$w,$a) = @_; - return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, $s, ps, depth)"; - }; - - } else { - $dissect_p = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; - }; - $dissect_d = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; - }; + return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; + }; + $dissect_d = sub { + my ($e,$l,$n,$w,$a) = @_; - } + return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; + }; AddType($td->{NAME}, { DECL => $decl, -- cgit From 399533dc6465e9010e3d6ef06e54e138513f12c5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Oct 2005 20:03:34 +0000 Subject: r10879: Added the ZERO_STRUCT(q_u), (r_u) entries to the generated Samba3 code. Jelmer please check ! Jeremy. (This used to be commit 534e8d16228ad4f1306ddf21ea9c9b988d736525) --- source4/pidl/lib/Parse/Pidl/Samba3/Server.pm | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm index 3f1f4645a1..b4eb6329eb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm @@ -36,6 +36,9 @@ sub ParseFunction($$) pidl "prs_struct *data = &p->in_data.data;"; pidl "prs_struct *rdata = &p->out_data.rdata;"; pidl ""; + pidl "ZERO_STRUCT(q_u);" + pidl "ZERO_STRUCT(r_u);" + pidl ""; pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; pidl "\treturn False;"; pidl ""; -- cgit From d2376d70b280a0642ecac23cfc526b76819d6bb1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Oct 2005 20:05:29 +0000 Subject: r10880: Missed terminating ';', sorry. Jeremy. (This used to be commit 2680aeffb1e40a7d1d59c98f0ee533d7c4362f40) --- source4/pidl/lib/Parse/Pidl/Samba3/Server.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm index b4eb6329eb..179ace7dbb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm @@ -36,8 +36,8 @@ sub ParseFunction($$) pidl "prs_struct *data = &p->in_data.data;"; pidl "prs_struct *rdata = &p->out_data.rdata;"; pidl ""; - pidl "ZERO_STRUCT(q_u);" - pidl "ZERO_STRUCT(r_u);" + pidl "ZERO_STRUCT(q_u);"; + pidl "ZERO_STRUCT(r_u);"; pidl ""; pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; pidl "\treturn False;"; -- cgit From 6f3caf73e13f32e5482d09b3fd2fbcf61ac88bc1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 14 Oct 2005 16:40:47 +0000 Subject: r11061: Samba3 parser generator fixes: * Add (limited) support for [string] * Don't generate (and set) header elements for top level ref pointers as they don't appear on the wire (This used to be commit 765adaf19be264e2d23a22eaed3027faededf8b6) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 8 ++++++-- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 28 +++++++++++++++++++--------- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 16 +++++++++++++++- 3 files changed, 40 insertions(+), 12 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index d14bac2df7..b49e64c337 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort); +use Parse::Pidl::Samba3::Types qw(DeclShort StringType); use vars qw($VERSION); $VERSION = '0.01'; @@ -28,11 +28,15 @@ sub ParseElement($) foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "POINTER") { - return if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "top"); + next if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP"); pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; } elsif ($l->{TYPE} eq "SWITCH") { } elsif ($l->{TYPE} eq "DATA") { pidl "\t" . DeclShort($e) . ";"; + } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { + my ($t,$f) = StringType($e,$l); + pidl "\t" . uc($t) . " $e->{NAME};"; + return; } elsif ($l->{TYPE} eq "ARRAY") { if ($l->{IS_CONFORMANT}) { pidl "\tuint32 size_$e->{NAME};"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index b87951adee..d582305326 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -9,7 +9,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType); +use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType StringType); use vars qw($VERSION); $VERSION = '0.01'; @@ -27,7 +27,7 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Add some security checks (array sizes, memory alloc == NULL, etc) # - Don't add seperate _p and _d functions if there is no deferred data -# - [string] +# - [string] with non-varying arrays # - subcontext() # - DATA_BLOB @@ -58,7 +58,7 @@ sub DeclareArrayVariables next if ($l->{IS_DEFERRED} and $what == PRIMITIVES); next if (not $l->{IS_DEFERRED} and $what == DEFERRED); } - if ($l->{TYPE} eq "ARRAY") { + if ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; $output = 1; } @@ -90,9 +90,14 @@ sub ParseElementLevelArray($$$$$$$) my ($e,$l,$nl,$env,$varname,$what,$align) = @_; if ($l->{IS_ZERO_TERMINATED}) { - fatal($e, "[string] attribute not supported for Samba3 yet"); - - #FIXME + my ($t,$f) = StringType($e,$l); + + pidl "if (!prs_io_$t(\"$e->{VARNAME}\", ps, depth, $varname))"; + pidl "\treturn False;"; + pidl ""; + + $$align = 0; + return; } my $len = ParseExpr($l->{LENGTH_IS}, $env); @@ -228,7 +233,9 @@ sub InitLevel($$$$) indent; } - pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;"; + unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { + pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;"; + } InitLevel($e, GetNextLevel($e,$l), "*$varname", $env); if ($l->{POINTER_TYPE} ne "ref") { @@ -237,6 +244,9 @@ sub InitLevel($$$$) pidl "\t" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 0;"; pidl "}"; } + } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { + my ($t,$f) = StringType($e,$l); + pidl "init_$t(" . ParseExpr($e->{NAME}, $env) . ", $varname, $f);"; } elsif ($l->{TYPE} eq "ARRAY") { pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; } elsif ($l->{TYPE} eq "DATA") { @@ -256,7 +266,7 @@ sub GenerateEnvElement($$) } elsif ($l->{TYPE} eq "POINTER") { $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}"; } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY") { + } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; $env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}"; $env->{"offset_$e->{NAME}"} = "v->offset_$e->{NAME}"; @@ -360,7 +370,7 @@ sub UnionGenerateEnvElement($) } elsif ($l->{TYPE} eq "POINTER") { $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}"; } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY") { + } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { $env->{"length_$e->{NAME}"} = "v->length"; $env->{"size_$e->{NAME}"} = "v->size"; $env->{"offset_$e->{NAME}"} = "v->offset"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 135b02f1e3..db20372bba 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -7,7 +7,7 @@ package Parse::Pidl::Samba3::Types; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType); +@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType StringType); use strict; use Parse::Pidl::Util qw(has_property ParseExpr property_matches); @@ -104,6 +104,20 @@ sub dissect_string($$$$$) return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)"; } +sub StringType($$) +{ + my ($e,$l) = @_; + my $nl = GetNextLevel($e,$l); + + if ($l->{IS_VARYING} and $l->{IS_CONFORMANT} and $nl->{DATA_TYPE} eq "uint16") { + return ("unistr2", 0); + } elsif ($l->{IS_CONFORMANT} and $l->{IS_VARYING} and $nl->{DATA_TYPE} eq "uint8") { + return ("string2", 0); + } else { + fatal($e, "[string] non-varying string not supported for Samba3 yet"); + } +} + my $known_types = { uint8 => -- cgit From 5a937a0f6f62de25ce7721413a4bbf3b9b31ea59 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 15 Oct 2005 00:45:16 +0000 Subject: r11077: Fix [string] for Samba3 (This used to be commit 2f76e2a6bf8ff99ac2f9b61669d09d76a2fe920a) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 10 ++++++---- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index d582305326..9ef8f09dc4 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -27,7 +27,7 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Add some security checks (array sizes, memory alloc == NULL, etc) # - Don't add seperate _p and _d functions if there is no deferred data -# - [string] with non-varying arrays +# - [string] with non-varying arrays and "surrounding" strings # - subcontext() # - DATA_BLOB @@ -90,11 +90,13 @@ sub ParseElementLevelArray($$$$$$$) my ($e,$l,$nl,$env,$varname,$what,$align) = @_; if ($l->{IS_ZERO_TERMINATED}) { + return if ($what == DEFERRED); + my ($t,$f) = StringType($e,$l); - pidl "if (!prs_io_$t(\"$e->{VARNAME}\", ps, depth, $varname))"; + Align($align, 4); + pidl "if (!smb_io_$t(\"$e->{NAME}\", &$varname, 1, ps, depth))"; pidl "\treturn False;"; - pidl ""; $$align = 0; return; @@ -246,7 +248,7 @@ sub InitLevel($$$$) } } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { my ($t,$f) = StringType($e,$l); - pidl "init_$t(" . ParseExpr($e->{NAME}, $env) . ", $varname, $f);"; + pidl "init_$t(&" . ParseExpr($e->{NAME}, $env) . ", ".substr($varname, 1) . ", $f);"; } elsif ($l->{TYPE} eq "ARRAY") { pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; } elsif ($l->{TYPE} eq "DATA") { diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index db20372bba..3f7e8ae134 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -11,7 +11,7 @@ require Exporter; use strict; use Parse::Pidl::Util qw(has_property ParseExpr property_matches); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString); use vars qw($VERSION); $VERSION = '0.01'; @@ -110,7 +110,7 @@ sub StringType($$) my $nl = GetNextLevel($e,$l); if ($l->{IS_VARYING} and $l->{IS_CONFORMANT} and $nl->{DATA_TYPE} eq "uint16") { - return ("unistr2", 0); + return ("unistr2", "UNI_FLAGS_NONE"); } elsif ($l->{IS_CONFORMANT} and $l->{IS_VARYING} and $nl->{DATA_TYPE} eq "uint8") { return ("string2", 0); } else { @@ -282,7 +282,10 @@ sub DeclLong($) my $suffixes = ""; foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { + if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { + $p = "const char"; + last; + } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { $prefixes = "*$prefixes"; } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { $suffixes.="[$l->{SIZE_IS}]"; -- cgit From 94793b80d7fbd6121bb30e36b25e63abe078feee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Dec 2005 17:12:52 +0000 Subject: r12484: Initial work on supporting non-typedeffed types (This used to be commit e7ac6c708dde7afb4c92a8cc4dea7a95b7054e3e) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index b49e64c337..fb02120a42 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -183,7 +183,7 @@ sub ParseInterface($) pidl ""; - foreach (@{$if->{TYPEDEFS}}) { + foreach (@{$if->{TYPES}}) { ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "ENUM"); ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "BITMAP"); diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 9ef8f09dc4..c12f7554e9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -566,7 +566,7 @@ sub ParseInterface($) # Structures first pidl "/* $if->{NAME} structures */"; - foreach (@{$if->{TYPEDEFS}}) { + foreach (@{$if->{TYPES}}) { ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); } diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index 3f7e8ae134..d1f1032714 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -350,7 +350,7 @@ sub LoadTypes($) foreach my $if (@{$ndr}) { next unless ($if->{TYPE} eq "INTERFACE"); - foreach my $td (@{$if->{TYPEDEFS}}) { + foreach my $td (@{$if->{TYPES}}) { my $decl = uc("$if->{NAME}_$td->{NAME}"); my $init = sub { -- cgit From 39f1f55610594c4b82c4b0f1ec7c9611b2f3f8a4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Mar 2006 23:00:14 +0000 Subject: r14215: Improve warning/error messages. (This used to be commit 80b9865b373ee542da2d56d6688b4c8fd4c6275c) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 4 ++-- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 4 ++-- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 12 +++++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index ceeb81c3d7..59f0341d02 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/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/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index fb02120a42..480a6c8e44 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/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($) { diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index c12f7554e9..a6b4b38cdf 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/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/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index d1f1032714..c31f406a38 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/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, @@ -228,7 +234,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 +268,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; } -- cgit From 9edbad7a36a2a7e61439eba9cd043adf81f70468 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Mar 2006 23:20:37 +0000 Subject: r14223: Couple of small fixes: - properly support --samba3-header argument used alone - support `security_descriptor' data type - only print pidl warnings, not perl warnings on erratic input - insert copyright header in templates (This used to be commit db1d7358b2ba9b104c1a96762af89b500b79172f) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 3 ++- source4/pidl/lib/Parse/Pidl/Samba3/Template.pm | 36 +++++++++++++++++++------- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 9 +++++++ 3 files changed, 37 insertions(+), 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm index 480a6c8e44..c479b14afa 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm @@ -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/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm index 072aa07850..47d565dce6 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm +++ b/source4/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/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm index c31f406a38..666d23e669 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm @@ -205,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", -- cgit From e81fd2e11918a775175a91744bced45689343914 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 4 May 2006 16:04:08 +0000 Subject: r15437: Add generator that creates Samba3 client code which uses Samba4's NDR routines. (This used to be commit 538be4a6319b6f8235ed450740784104671ab0b5) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 136 ++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm new file mode 100644 index 0000000000..ec3287ffb0 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -0,0 +1,136 @@ +################################################### +# Samba3 client generator for IDL structures +# on top of Samba4 style NDR functions +# Copyright jelmer@samba.org 2005-2006 +# released under the GNU GPL + +package Parse::Pidl::Samba3::ClientNDR; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType); +use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba3::Types qw(DeclLong); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res = ""; +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->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } +sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } + +sub CopyLevel($$$$) +{ + sub CopyLevel($$$$); + my ($e,$l,$argument,$member) = @_; + + if ($l->{TYPE} eq "DATA") { + pidl "*$argument = *$member;"; + } elsif ($l->{TYPE} eq "POINTER") { + pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {"; + indent; + pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));"; + CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member); + deindent; + pidl "}"; + } elsif ($l->{TYPE} eq "SWITCH") { + CopyLevel($e,GetNextLevel($e,$l),$argument,$member); + } elsif ($l->{TYPE} eq "ARRAY") { + pidl "*$argument = $member;"; + } +} + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + my $inargs = ""; + my $defargs = ""; + my $uif = uc($if->{NAME}); + my $ufn = uc($fn->{NAME}); + + foreach (@{$fn->{ELEMENTS}}) { + $defargs .= ", " . DeclLong($_); + } + pidl "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; + pidl "{"; + indent; + pidl "struct $fn->{NAME} r;"; + pidl "NTSTATUS status;"; + pidl ""; + pidl "/* In parameters */"; + + foreach (@{$fn->{ELEMENTS}}) { + if (grep(/in/, @{$_->{DIRECTION}})) { + pidl "r.in.$_->{NAME} = $_->{NAME};"; + } + } + + pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, ndr_pull_$fn->{NAME}, ndr_push_$fn->{NAME});"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\treturn status;"; + pidl "}"; + pidl ""; + pidl "/* Return variables */"; + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/out/, @{$e->{DIRECTION}})); + + if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") { + warning($e, "First element not a pointer for [out] argument"); + next; + } + + CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.out.$e->{NAME}"); + } + + pidl""; + pidl "/* Return result */"; + if (not $fn->{RETURN_TYPE}) { + pidl "return NT_STATUS_OK;"; + } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { + pidl "return r.status;"; + } elsif ($fn->{RETURN_TYPE} eq "WERROR") { + pidl "return werror_to_ntstatus(r.status);"; + } else { + pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; + pidl "return NT_STATUS_OK;"; + } + + deindent; + pidl "}"; + pidl ""; +} + +sub ParseInterface($) +{ + my $if = shift; + + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); +} + +sub Parse($$) +{ + my($ndr,$filename) = @_; + + $res = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * client auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return $res; +} + +1; -- cgit From a3f2ed12b9cde474a8d5ec96eb0bd0b6211c45a9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 May 2006 11:44:00 +0000 Subject: r15470: Write header file with prototypes for Samba3-Client-With-Samba4-NDR code. (This used to be commit a2bb0b6012b14787825a9cd5f33e2c0e989b65a7) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index ec3287ffb0..92bb440e7c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -15,13 +15,16 @@ use Parse::Pidl::Samba3::Types qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; -my $res = ""; +my $res; +my $res_hdr; my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } +sub pidl_hdr($) { $res_hdr .= (shift)."\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 fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } sub CopyLevel($$$$) { @@ -51,12 +54,12 @@ sub ParseFunction($$) my $inargs = ""; my $defargs = ""; my $uif = uc($if->{NAME}); - my $ufn = uc($fn->{NAME}); + my $ufn = "DCERPC_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { $defargs .= ", " . DeclLong($_); } - pidl "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; + fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; pidl "{"; indent; pidl "struct $fn->{NAME} r;"; @@ -79,10 +82,7 @@ sub ParseFunction($$) foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") { - warning($e, "First element not a pointer for [out] argument"); - next; - } + fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER"); CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.out.$e->{NAME}"); } @@ -109,7 +109,12 @@ sub ParseInterface($) { my $if = shift; + my $uif = uc($if->{NAME}); + + pidl_hdr "#ifndef __CLI_$uif\__"; + pidl_hdr "#define __CLI_$uif\__"; ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + pidl_hdr "#endif /* __CLI_$uif\__ */"; } sub Parse($$) @@ -117,6 +122,7 @@ sub Parse($$) my($ndr,$filename) = @_; $res = ""; + $res_hdr = ""; pidl "/*"; pidl " * Unix SMB/CIFS implementation."; @@ -130,7 +136,7 @@ sub Parse($$) ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); } - return $res; + return ($res, $res_hdr); } 1; -- cgit From 55969efea3185a9aaf2ffa86969be9554c84863b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 May 2006 16:19:29 +0000 Subject: r15474: Generate proper type declarations, fix headers (This used to be commit 1405f59d5501319c7d08861e19165e012c4bc3a9) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 53 +++++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 92bb440e7c..eda2ab99d7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -7,10 +7,9 @@ package Parse::Pidl::Samba3::ClientNDR; use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); +use Parse::Pidl::Util qw(has_property ParseExpr is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; @@ -47,6 +46,42 @@ sub CopyLevel($$$$) } } +sub DeclLong($) +{ + my($element) = shift; + my $ret = ""; + + if (has_property($element, "represent_as")) { + $ret.=mapType($element->{PROPERTIES}->{represent_as})." "; + } else { + if (has_property($element, "charset")) { + $ret.="const char"; + } else { + $ret.=mapType($element->{TYPE}); + } + + $ret.=" "; + my $numstar = $element->{ORIGINAL}->{POINTERS}; + if ($numstar >= 1) { + $numstar-- if scalar_is_reference($element->{TYPE}); + } + foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}}) + { + next if is_constant($_) and + not has_property($element, "charset"); + $numstar++; + } + $ret.="*" foreach (1..$numstar); + } + $ret.=$element->{NAME}; + foreach (@{$element->{ARRAY_LEN}}) { + next unless (is_constant($_) and not has_property($element, "charset")); + $ret.="[$_]"; + } + + return $ret; +} + sub ParseFunction($$) { my ($if,$fn) = @_; @@ -73,7 +108,7 @@ sub ParseFunction($$) } } - pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, ndr_pull_$fn->{NAME}, ndr_push_$fn->{NAME});"; + pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"; pidl "if (NT_STATUS_IS_ERR(status)) {"; pidl "\treturn status;"; pidl "}"; @@ -92,9 +127,9 @@ sub ParseFunction($$) if (not $fn->{RETURN_TYPE}) { pidl "return NT_STATUS_OK;"; } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - pidl "return r.status;"; + pidl "return r.out.result;"; } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - pidl "return werror_to_ntstatus(r.status);"; + pidl "return werror_to_ntstatus(r.out.result);"; } else { pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; pidl "return NT_STATUS_OK;"; @@ -117,9 +152,9 @@ sub ParseInterface($) pidl_hdr "#endif /* __CLI_$uif\__ */"; } -sub Parse($$) +sub Parse($$$) { - my($ndr,$filename) = @_; + my($ndr,$header,$ndr_header) = @_; $res = ""; $res_hdr = ""; @@ -130,6 +165,8 @@ sub Parse($$) pidl " */"; pidl ""; pidl "#include \"includes.h\""; + pidl "#include \"$header\""; + pidl_hdr "#include \"$ndr_header\""; pidl ""; foreach (@$ndr) { -- cgit From 8d6249814f45e95a9941dfc7d6d3d2a93811efb0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 22:03:44 +0000 Subject: r15587: Generate stubs for the SWIG functions (This used to be commit 746d0a7fa7a43685e6ebb4877bb5459101e51ed1) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 37 +------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index eda2ab99d7..3b8c92ebe4 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -10,6 +10,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); use Parse::Pidl::Util qw(has_property ParseExpr is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; @@ -46,42 +47,6 @@ sub CopyLevel($$$$) } } -sub DeclLong($) -{ - my($element) = shift; - my $ret = ""; - - if (has_property($element, "represent_as")) { - $ret.=mapType($element->{PROPERTIES}->{represent_as})." "; - } else { - if (has_property($element, "charset")) { - $ret.="const char"; - } else { - $ret.=mapType($element->{TYPE}); - } - - $ret.=" "; - my $numstar = $element->{ORIGINAL}->{POINTERS}; - if ($numstar >= 1) { - $numstar-- if scalar_is_reference($element->{TYPE}); - } - foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}}) - { - next if is_constant($_) and - not has_property($element, "charset"); - $numstar++; - } - $ret.="*" foreach (1..$numstar); - } - $ret.=$element->{NAME}; - foreach (@{$element->{ARRAY_LEN}}) { - next unless (is_constant($_) and not has_property($element, "charset")); - $ret.="[$_]"; - } - - return $ret; -} - sub ParseFunction($$) { my ($if,$fn) = @_; -- cgit From fde2d769eb7c63a92704135e5ce49712dd30a1ca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 23:58:16 +0000 Subject: r15591: Generate function calls correctly as well. (This used to be commit b0439779b8eba68680cfd49ea2364affc739300e) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 3b8c92ebe4..fa629e6101 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -26,27 +26,6 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LI sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } -sub CopyLevel($$$$) -{ - sub CopyLevel($$$$); - my ($e,$l,$argument,$member) = @_; - - if ($l->{TYPE} eq "DATA") { - pidl "*$argument = *$member;"; - } elsif ($l->{TYPE} eq "POINTER") { - pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {"; - indent; - pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));"; - CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member); - deindent; - pidl "}"; - } elsif ($l->{TYPE} eq "SWITCH") { - CopyLevel($e,GetNextLevel($e,$l),$argument,$member); - } elsif ($l->{TYPE} eq "ARRAY") { - pidl "*$argument = $member;"; - } -} - sub ParseFunction($$) { my ($if,$fn) = @_; @@ -84,7 +63,7 @@ sub ParseFunction($$) fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER"); - CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.out.$e->{NAME}"); + pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } pidl""; -- cgit From 2a9407fad39a472a356adbcdac3c0fa0a4d69a5f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 May 2006 00:22:24 +0000 Subject: r15593: Warn about [out] arguments that are not pointers. These can all be fixed by adding [ref] pointers. This will cause a lot of warnings to be outputted by pidl for now. I will fix these gradually over the next few days. We need to avoid [out] arguments that are not pointers because they are not understood by other IDL compilers and don't work with some of our output modules (Samba3, Samba3NDR and ethereal) (This used to be commit c4ab021ee8d93aa74f15deebf64a366b33b7bb9f) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm index 59f0341d02..9e26e9a21e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm @@ -85,11 +85,6 @@ sub ParseFunction($$) foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - if ($e->{LEVELS}[0]->{TYPE} ne "POINTER") { - warning($e->{ORIGINAL}, "First element not a pointer for [out] argument"); - next; - } - CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}"); } -- cgit From e3a6c6be79326578a1e9c7cb8547234eab62235f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 8 Jun 2006 15:20:05 +0000 Subject: r16100: Patch from Michael Wood : s/then/than/ for correct grammar (This used to be commit 26a2fa97e4c819e630bc9b50e11c8d5328c7b8c8) --- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index a6b4b38cdf..57fa3867f7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -35,7 +35,7 @@ sub Align($$) { my ($a,$b) = @_; - # Only align if previous element was smaller then current one + # Only align if previous element was smaller than current one if ($$a < $b) { pidl "if (!prs_align_custom(ps, $b))"; pidl "\treturn False;"; -- cgit From e26ed8b3e2e6b30de424dea27ed7ca55f2b50c05 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 13:45:36 +0000 Subject: r18470: Remove obsolete client generator code for Samba3 (we're now using the new code that uses libndr) (This used to be commit ea0ef1542f78e3a58d86b5693ec17c145050526b) --- source4/pidl/lib/Parse/Pidl/Samba3/Client.pm | 137 --------------------------- 1 file changed, 137 deletions(-) delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Client.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm deleted file mode 100644 index 9e26e9a21e..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Client.pm +++ /dev/null @@ -1,137 +0,0 @@ -################################################### -# Samba3 NDR client generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Client; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclLong); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res = ""; -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->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -sub CopyLevel($$$$) -{ - sub CopyLevel($$$$); - my ($e,$l,$argument,$member) = @_; - - if ($l->{TYPE} eq "DATA") { - pidl "*$argument = $member;"; - } elsif ($l->{TYPE} eq "POINTER") { - pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {"; - indent; - pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));"; - CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member); - deindent; - pidl "}"; - } elsif ($l->{TYPE} eq "SWITCH") { - CopyLevel($e,GetNextLevel($e,$l),$argument,$member); - } elsif ($l->{TYPE} eq "ARRAY") { - pidl "*$argument = $member;"; - } -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my $inargs = ""; - my $defargs = ""; - foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . DeclLong($_); - if (grep(/in/, @{$_->{DIRECTION}})) { - $inargs .= ", $_->{NAME}"; - } - } - - my $uif = uc($if->{NAME}); - my $ufn = uc($fn->{NAME}); - - pidl "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; - pidl "{"; - indent; - pidl "prs_struct qbuf, rbuf;"; - pidl "$uif\_Q_$ufn q;"; - pidl "$uif\_R_$ufn r;"; - pidl ""; - pidl "ZERO_STRUCT(q);"; - pidl "ZERO_STRUCT(r);"; - pidl ""; - pidl "/* Marshall data and send request */"; - pidl ""; - pidl "if (!init_$if->{NAME}_q_$fn->{NAME}(&q$inargs))"; - pidl "\treturn NT_STATUS_INVALID_PARAMETER;"; - pidl ""; - pidl "CLI_DO_RPC(cli, mem_ctx, PI_$uif, $ufn,"; - pidl "\tq, r,"; - pidl "\tqbuf, rbuf, "; - pidl "\t$if->{NAME}_io_q_$fn->{NAME},"; - pidl "\t$if->{NAME}_io_r_$fn->{NAME},"; - pidl "\tNT_STATUS_UNSUCCESSFUL);"; - pidl ""; - pidl "/* Return variables */"; - foreach my $e (@{$fn->{ELEMENTS}}) { - next unless (grep(/out/, @{$e->{DIRECTION}})); - - CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.$e->{NAME}"); - } - - pidl""; - pidl "/* Return result */"; - if (not $fn->{RETURN_TYPE}) { - pidl "return NT_STATUS_OK;"; - } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - pidl "return r.status;"; - } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - pidl "return werror_to_ntstatus(r.status);"; - } else { - pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; - pidl "return NT_STATUS_OK;"; - } - - deindent; - pidl "}"; - pidl ""; -} - -sub ParseInterface($) -{ - my $if = shift; - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * client auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; -- cgit From 0eb9794e9f254445ba8a264c06b8ab21b82619c1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 13:49:17 +0000 Subject: r18471: Remove other Samba3 parser generator support as well - it's no longer necessary as we can use libndr now. (This used to be commit 22142a9f3d5e759742c79a591413e5e8af04b22f) --- source4/pidl/lib/Parse/Pidl/Samba3/Header.pm | 223 --------- source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 603 ------------------------- source4/pidl/lib/Parse/Pidl/Samba3/Template.pm | 82 ---- source4/pidl/lib/Parse/Pidl/Samba3/Types.pm | 403 ----------------- 4 files changed, 1311 deletions(-) delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Header.pm delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Template.pm delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Types.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm deleted file mode 100644 index c479b14afa..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Header.pm +++ /dev/null @@ -1,223 +0,0 @@ -################################################### -# Samba3 NDR header generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Header; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort StringType); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res = ""; -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->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } -sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -sub ParseElement($) -{ - my $e = shift; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "POINTER") { - next if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP"); - pidl "\tuint32 ptr$l->{POINTER_INDEX}_$e->{NAME};"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "DATA") { - 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};"; - return; - } elsif ($l->{TYPE} eq "ARRAY") { - if ($l->{IS_CONFORMANT}) { - pidl "\tuint32 size_$e->{NAME};"; - } - if ($l->{IS_VARYING}) { - pidl "\tuint32 length_$e->{NAME};"; - pidl "\tuint32 offset_$e->{NAME};"; - } - } - } -} - -sub CreateStruct($$$$) -{ - my ($if,$fn,$n,$t) = @_; - - pidl "typedef struct $n {"; - ParseElement($_) foreach (@$t); - - if (not @$t) { - # Some compilers don't like empty structs - pidl "\tuint32 dummy;"; - } - - pidl "} " . uc($n) . ";"; - pidl ""; -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my @in = (); - my @out = (); - - foreach (@{$fn->{ELEMENTS}}) { - push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); - push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); - } - - if (defined($fn->{RETURN_TYPE})) { - push (@out, { - NAME => "status", - TYPE => $fn->{RETURN_TYPE}, - LEVELS => [ - { - TYPE => "DATA", - DATA_TYPE => $fn->{RETURN_TYPE} - } - ] - } ); - } - - # define Q + R structures for functions - - CreateStruct($if, $fn, "$if->{NAME}_q_$fn->{NAME}", \@in); - CreateStruct($if, $fn, "$if->{NAME}_r_$fn->{NAME}", \@out); -} - -sub ParseStruct($$$) -{ - my ($if,$s,$n) = @_; - - CreateStruct($if, $s, "$if->{NAME}_$n", $s->{ELEMENTS}); -} - -sub ParseUnion($$$) -{ - my ($if,$u,$n) = @_; - - my $extra = { - switch_value => $u->{SWITCH_TYPE} - }; - - if (not defined($extra->{switch_value})) { - $extra->{switch_value} = "uint32"; - } - - foreach my $e (@{$u->{ELEMENTS}}) { - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY") { - if ($l->{IS_CONFORMANT}) { - $extra->{"size"} = "uint32"; - } - if ($l->{IS_VARYING}) { - $extra->{"length"} = $extra->{"offset"} = "uint32"; - } - } elsif ($l->{TYPE} eq "POINTER") { - $extra->{"ptr$l->{POINTER_INDEX}"} = "uint32"; - } elsif ($l->{TYPE} eq "SWITCH") { - $extra->{"level"} = "uint32"; - } - } - } - - pidl "typedef struct $if->{NAME}_$n\_ctr {"; - indent; - pidl "$extra->{$_} $_;" foreach (keys %$extra); - pidl "union $if->{NAME}_$n {"; - indent; - foreach (@{$u->{ELEMENTS}}) { - next if ($_->{TYPE} eq "EMPTY"); - pidl "\t" . DeclShort($_) . ";"; - } - deindent; - pidl "} u;"; - deindent; - pidl "} ".uc("$if->{NAME}_$n\_ctr") .";"; - pidl ""; -} - -sub ParseEnum($$$) -{ - my ($if,$s,$n) = @_; - - pidl "typedef enum {"; - pidl "$_," foreach (@{$s->{ELEMENTS}}); - pidl "} $n;"; -} - -sub ParseBitmap($$$) -{ - my ($if,$s,$n) = @_; - - pidl "#define $_" foreach (@{$s->{ELEMENTS}}); -} - -sub ParseInterface($) -{ - my $if = shift; - - my $def = "_RPC_" . uc($if->{NAME}) . "_H"; - - pidl ""; - - pidl "\#ifndef $def"; - pidl "\#define $def"; - - pidl ""; - - foreach (@{$if->{FUNCTIONS}}) { - pidl "\#define " . uc($_->{NAME}) . " $_->{OPNUM}" ; - } - - pidl ""; - - foreach (@{$if->{TYPES}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); - ParseEnum($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "ENUM"); - ParseBitmap($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "BITMAP"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); - } - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - - foreach (@{$if->{CONSTS}}) { - pidl "$_->{NAME} ($_->{VALUE})"; - } - - pidl "\#endif /* $def */"; -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - $tabs = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * header auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - - # Loop over interfaces - foreach (@{$ndr}) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - return $res; -} - -1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm deleted file mode 100644 index 57fa3867f7..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ /dev/null @@ -1,603 +0,0 @@ -################################################### -# Samba3 NDR parser generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Parser; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba3::Types qw(DeclShort DeclLong InitType DissectType StringType); - -use vars qw($VERSION); -$VERSION = '0.01'; - -use constant PRIMITIVES => 1; -use constant DEFERRED => 2; - -my $res = ""; -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->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } - -#TODO: -# - Add some security checks (array sizes, memory alloc == NULL, etc) -# - Don't add seperate _p and _d functions if there is no deferred data -# - [string] with non-varying arrays and "surrounding" strings -# - subcontext() -# - DATA_BLOB - -sub Align($$) -{ - my ($a,$b) = @_; - - # Only align if previous element was smaller than current one - if ($$a < $b) { - pidl "if (!prs_align_custom(ps, $b))"; - pidl "\treturn False;"; - pidl ""; - } - - $$a = $b; -} - -sub DeclareArrayVariables -{ - my $es = shift; - my $what = shift; - - my $output = 0; - - foreach my $e (@$es) { - foreach my $l (@{$e->{LEVELS}}) { - if ($what) { - next if ($l->{IS_DEFERRED} and $what == PRIMITIVES); - next if (not $l->{IS_DEFERRED} and $what == DEFERRED); - } - if ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - pidl "uint32 i_$e->{NAME}_$l->{LEVEL_INDEX};"; - $output = 1; - } - } - } - pidl "" if $output; -} - -sub ParseElementLevelData($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - my $c = DissectType($e,$l,$varname,$what,$align); - return if not $c; - - if (defined($e->{ALIGN})) { - Align($align, $e->{ALIGN}); - } else { - # Default to 4 - Align($align, 4); - } - - pidl "if (!$c)"; - pidl "\treturn False;"; -} - -sub ParseElementLevelArray($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - if ($l->{IS_ZERO_TERMINATED}) { - return if ($what == DEFERRED); - - my ($t,$f) = StringType($e,$l); - - Align($align, 4); - pidl "if (!smb_io_$t(\"$e->{NAME}\", &$varname, 1, ps, depth))"; - pidl "\treturn False;"; - - $$align = 0; - return; - } - - my $len = ParseExpr($l->{LENGTH_IS}, $env); - my $size = ParseExpr($l->{SIZE_IS}, $env); - - if ($what == PRIMITIVES) { - # Fetch headers - if ($l->{IS_CONFORMANT} and not $l->{IS_SURROUNDING}) { - Align($align, 4); - pidl "if (!prs_uint32(\"size_$e->{NAME}\", ps, depth, &" . ParseExpr("size_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - - if ($l->{IS_VARYING}) { - Align($align, 4); - pidl "if (!prs_uint32(\"offset_$e->{NAME}\", ps, depth, &" . ParseExpr("offset_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - - pidl "if (!prs_uint32(\"length_$e->{NAME}\", ps, depth, &" . ParseExpr("length_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - } - - # Everything but fixed arrays have to be allocated - if (!$l->{IS_FIXED} and $what == PRIMITIVES) { - pidl "if (UNMARSHALLING(ps)) {"; - indent; - pidl "$varname = (void *)PRS_ALLOC_MEM_VOID(ps,sizeof(*$varname)*$size);"; - deindent; - pidl "}"; - } - - return if ($what == DEFERRED and not ContainsDeferred($e,$l)); - - my $i = "i_$e->{NAME}_$l->{LEVEL_INDEX}"; - pidl "for ($i=0; $i<$len;$i++) {"; - indent; - ParseElementLevel($e,$nl,$env,$varname."[$i]",$what,$align); - deindent; - pidl "}"; -} - -sub ParseElementLevelSwitch($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - ParseElementLevel($e,$nl,$env,$varname,$what,$align); -} - -sub ParseElementLevelPtr($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - if ($what == PRIMITIVES) { - if (($l->{POINTER_TYPE} eq "ref") and ($l->{LEVEL} eq "EMBEDDED")) { - # Ref pointers always have to be non-NULL - pidl "if (MARSHALLING(ps) && !" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ")"; - pidl "\treturn False;"; - pidl ""; - } - - unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { - Align($align, 4); - pidl "if (!prs_uint32(\"ptr$l->{POINTER_INDEX}_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - } - } - - if ($l->{POINTER_TYPE} eq "relative") { - fatal($e, "relative pointers not supported for Samba 3"); - #FIXME - } - - if ($what == DEFERRED) { - if ($l->{POINTER_TYPE} ne "ref") { - pidl "if (" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . ") {"; - indent; - } - ParseElementLevel($e,$nl,$env,$varname,PRIMITIVES,$align); - ParseElementLevel($e,$nl,$env,$varname,DEFERRED,$align); - if ($l->{POINTER_TYPE} ne "ref") { - deindent; - pidl "}"; - } - $$align = 0; - } -} - -sub ParseElementLevelSubcontext($$$$$$$) -{ - my ($e,$l,$nl,$env,$varname,$what,$align) = @_; - - fatal($e, "subcontext() not supported for Samba 3"); - #FIXME -} - -sub ParseElementLevel($$$$$$) -{ - my ($e,$l,$env,$varname,$what,$align) = @_; - - { - DATA => \&ParseElementLevelData, - SUBCONTEXT => \&ParseElementLevelSubcontext, - POINTER => \&ParseElementLevelPtr, - SWITCH => \&ParseElementLevelSwitch, - ARRAY => \&ParseElementLevelArray - }->{$l->{TYPE}}->($e,$l,GetNextLevel($e,$l),$env,$varname,$what,$align); -} - -sub ParseElement($$$$) -{ - my ($e,$env,$what,$align) = @_; - - ParseElementLevel($e, $e->{LEVELS}[0], $env, ParseExpr($e->{NAME}, $env), $what, $align); -} - -sub InitLevel($$$$) -{ - sub InitLevel($$$$); - my ($e,$l,$varname,$env) = @_; - - if ($l->{TYPE} eq "POINTER") { - if ($l->{POINTER_TYPE} eq "ref") { - pidl "if (!$varname)"; - pidl "\treturn False;"; - pidl ""; - } else { - pidl "if ($varname) {"; - indent; - } - - unless ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { - pidl ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 1;"; - } - InitLevel($e, GetNextLevel($e,$l), "*$varname", $env); - - if ($l->{POINTER_TYPE} ne "ref") { - deindent; - pidl "} else {"; - pidl "\t" . ParseExpr("ptr$l->{POINTER_INDEX}_$e->{NAME}", $env) . " = 0;"; - pidl "}"; - } - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { - my ($t,$f) = StringType($e,$l); - pidl "init_$t(&" . ParseExpr($e->{NAME}, $env) . ", ".substr($varname, 1) . ", $f);"; - } elsif ($l->{TYPE} eq "ARRAY") { - pidl ParseExpr($e->{NAME}, $env) . " = $varname;"; - } elsif ($l->{TYPE} eq "DATA") { - pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); - } elsif ($l->{TYPE} eq "SWITCH") { - InitLevel($e, GetNextLevel($e,$l), $varname, $env); - pidl ParseExpr($e->{NAME}, $env) . ".switch_value = " . ParseExpr($l->{SWITCH_IS}, $env) . ";"; - } -} - -sub GenerateEnvElement($$) -{ - my ($e,$env) = @_; - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{$e->{NAME}} = "v->$e->{NAME}"; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}_$e->{NAME}"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; - $env->{"size_$e->{NAME}"} = "v->size_$e->{NAME}"; - $env->{"offset_$e->{NAME}"} = "v->offset_$e->{NAME}"; - } - } -} - -sub ParseStruct($$$) -{ - my ($if,$s,$n) = @_; - - my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n"); - my $ifn = "init_$if->{NAME}_$n"; - - my $args = ""; - foreach (@{$s->{ELEMENTS}}) { - $args .= ", " . DeclLong($_); - } - - my $env = { "this" => "v" }; - GenerateEnvElement($_, $env) foreach (@{$s->{ELEMENTS}}); - - pidl "BOOL $ifn($sn *v$args)"; - pidl "{"; - indent; - pidl "DEBUG(5,(\"$ifn\\n\"));"; - pidl ""; - # Call init for all arguments - foreach (@{$s->{ELEMENTS}}) { - InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); - pidl ""; - } - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - my $pfn = "$fn\_p"; - my $dfn = "$fn\_d"; - - pidl "BOOL $pfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($s->{ELEMENTS}, PRIMITIVES); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$pfn\");"; - pidl "depth++;"; - - my $align = 8; - if ($s->{SURROUNDING_ELEMENT}) { - pidl "if (!prs_uint32(\"size_$s->{SURROUNDING_ELEMENT}->{NAME}\", ps, depth, &" . ParseExpr("size_$s->{SURROUNDING_ELEMENT}->{NAME}", $env) . "))"; - pidl "\treturn False;"; - pidl ""; - $align = 4; - - } - - foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, PRIMITIVES, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $dfn(const char *desc, $sn *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($s->{ELEMENTS}, DEFERRED); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$dfn\");"; - pidl "depth++;"; - - $align = 0; - foreach (@{$s->{ELEMENTS}}) { - ParseElement($_, $env, DEFERRED, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; -} - -sub UnionGenerateEnvElement($) -{ - my $e = shift; - my $env = {}; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "DATA") { - $env->{$e->{NAME}} = "v->u.$e->{NAME}"; - } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr$l->{POINTER_INDEX}_$e->{NAME}"} = "v->ptr$l->{POINTER_INDEX}"; - } elsif ($l->{TYPE} eq "SWITCH") { - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_ZERO_TERMINATED}) { - $env->{"length_$e->{NAME}"} = "v->length"; - $env->{"size_$e->{NAME}"} = "v->size"; - $env->{"offset_$e->{NAME}"} = "v->offset"; - } - } - - return $env; -} - -sub ParseUnion($$$) -{ - my ($if,$u,$n) = @_; - - my $fn = "$if->{NAME}_io_$n"; - my $sn = uc("$if->{NAME}_$n\_ctr"); - - my $pfn = "$fn\_p"; - my $dfn = "$fn\_d"; - - pidl "BOOL $pfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($u->{ELEMENTS}); - - if (defined ($u->{SWITCH_TYPE})) { - pidl "if (!prs_$u->{SWITCH_TYPE}(\"switch_value\", ps, depth, &v->switch_value))"; - pidl "\treturn False;"; - pidl ""; - } - - # Maybe check here that level and v->switch_value are equal? - - pidl "switch (v->switch_value) {"; - indent; - - foreach (@{$u->{ELEMENTS}}) { - pidl "$_->{CASE}:"; - indent; - if ($_->{TYPE} ne "EMPTY") { - pidl "depth++;"; - my $env = UnionGenerateEnvElement($_); - my $align = 8; - ParseElement($_, $env, PRIMITIVES, \$align); - pidl "depth--;"; - } - pidl "break;"; - deindent; - pidl ""; - } - - unless ($u->{HAS_DEFAULT}) { - pidl "default:"; - pidl "\treturn False;"; - pidl ""; - } - - deindent; - pidl "}"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $dfn(const char *desc, $sn* v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($u->{ELEMENTS}); - - if (defined($u->{SWITCH_TYPE})) { - pidl "switch (v->switch_value) {"; - } else { - pidl "switch (level) {"; - } - indent; - - foreach (@{$u->{ELEMENTS}}) { - pidl "$_->{CASE}:"; - indent; - if ($_->{TYPE} ne "EMPTY") { - pidl "depth++;"; - my $env = UnionGenerateEnvElement($_); - my $align = 0; - ParseElement($_, $env, DEFERRED, \$align); - pidl "depth--;"; - } - pidl "break;"; - deindent; - pidl ""; - } - - deindent; - pidl "}"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; - -} - -sub CreateFnDirection($$$$$) -{ - my ($fn,$ifn,$s,$all,$es) = @_; - - my $args = ""; - foreach (@$all) { $args .= ", " . DeclLong($_); } - - my $env = { }; - GenerateEnvElement($_, $env) foreach (@$es); - - pidl "BOOL $ifn($s *v$args)"; - pidl "{"; - indent; - pidl "DEBUG(5,(\"$ifn\\n\"));"; - pidl ""; - # Call init for all arguments - foreach (@$es) { - InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); - pidl ""; - } - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; - - pidl "BOOL $fn(const char *desc, $s *v, prs_struct *ps, int depth)"; - pidl "{"; - indent; - DeclareArrayVariables($es); - pidl "if (v == NULL)"; - pidl "\treturn False;"; - pidl ""; - pidl "prs_debug(ps, depth, desc, \"$fn\");"; - pidl "depth++;"; - - my $align = 8; - foreach (@$es) { - ParseElement($_, $env, PRIMITIVES, \$align); - ParseElement($_, $env, DEFERRED, \$align); - pidl ""; - } - - pidl "return True;"; - deindent; - pidl "}"; - pidl ""; -} - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - my @in = (); - my @out = (); - my @all = @{$fn->{ELEMENTS}}; - - foreach (@{$fn->{ELEMENTS}}) { - push (@in, $_) if (grep(/in/, @{$_->{DIRECTION}})); - push (@out, $_) if (grep(/out/, @{$_->{DIRECTION}})); - } - - if (defined($fn->{RETURN_TYPE})) { - my $status = { - NAME => "status", - TYPE => $fn->{RETURN_TYPE}, - LEVELS => [ - { - TYPE => "DATA", - DATA_TYPE => $fn->{RETURN_TYPE} - } - ] - }; - - push (@out, $status); - push (@all, $status); - } - - CreateFnDirection("$if->{NAME}_io_q_$fn->{NAME}", - "init_$if->{NAME}_q_$fn->{NAME}", - uc("$if->{NAME}_q_$fn->{NAME}"), - \@in, \@in); - CreateFnDirection("$if->{NAME}_io_r_$fn->{NAME}", - "init_$if->{NAME}_r_$fn->{NAME}", - uc("$if->{NAME}_r_$fn->{NAME}"), - \@all, \@out); -} - -sub ParseInterface($) -{ - my $if = shift; - - # Structures first - pidl "/* $if->{NAME} structures */"; - foreach (@{$if->{TYPES}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); - } - - pidl "/* $if->{NAME} functions */"; - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $tabs = ""; - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * parser auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl ""; - pidl "#undef DBGC_CLASS"; - pidl "#define DBGC_CLASS DBGC_RPC_PARSE"; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm deleted file mode 100644 index 47d565dce6..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Template.pm +++ /dev/null @@ -1,82 +0,0 @@ -################################################### -# Samba3 NDR client generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Template; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); - -use vars qw($VERSION); -$VERSION = '0.01'; - -my $res; -sub pidl($) { my $x = shift; $res.="$x\n"; } - -sub ParseInterface($) -{ - my $if = shift; - - foreach (@{$if->{FUNCTIONS}}) { - my $ret = $_->{RETURN_TYPE}; - if (not $ret) { $ret = "void"; } - pidl "$ret _$_->{NAME}(pipes_struct *p, " . uc($if->{NAME}) . "_Q_" . uc($_->{NAME}) . " *q_u, " . uc($if->{NAME}) . "_R_" . uc($_->{NAME}) . " *r_u)"; - pidl "{"; - pidl "\t/* FIXME: Implement your code here */"; - if (not defined($_->{RETURN_TYPE})) { - } elsif ($_->{RETURN_TYPE} eq "WERROR") { - pidl "\treturn WERR_NOT_SUPPORTED;"; - } elsif ($_->{RETURN_TYPE} eq "NTSTATUS") { - pidl "\treturn NT_STATUS_NOT_IMPLEMENTED;"; - } elsif ($_->{RETURN_TYPE} eq "uint32") { - pidl "\treturn 0;"; - } - pidl "}"; - pidl ""; - } -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $res = ""; - - 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"); - } - - return $res; -} - -1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm deleted file mode 100644 index 666d23e669..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Types.pm +++ /dev/null @@ -1,403 +0,0 @@ -################################################### -# Samba3 type-specific declarations / initialization / marshalling -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Types; - -require Exporter; -@ISA = qw(Exporter); -@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType StringType); - -use strict; -use Parse::Pidl::Util qw(has_property ParseExpr property_matches); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString); - -use vars qw($VERSION); -$VERSION = '0.01'; - -# TODO: Find external types somehow? - -sub warning($$) { my ($e,$s) = @_; print STDERR "$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"; } - -sub init_scalar($$$$) -{ - my ($e,$l,$n,$v) = @_; - - return "$n = $v;"; -} - -sub dissect_scalar($$$$$) -{ - my ($e,$l,$n,$w,$a) = @_; - - my $t = lc($e->{TYPE}); - - return "prs_$t(\"$e->{NAME}\", ps, depth, &$n)"; -} - -sub decl_string($) -{ - my $e = shift; - - my $is_conformant = property_matches($e, "flag", ".*STR_SIZE4.*"); - my $is_varying = property_matches($e, "flag", ".*STR_LEN4.*"); - my $is_ascii = property_matches($e, "flag", ".*STR_ASCII.*"); - - return "STRING2" if ($is_conformant and $is_varying and $is_ascii); - - return "UNISTR2" if ($is_conformant and $is_varying); - return "UNISTR3" if ($is_varying); - # We don't do UNISTR4, as we have lsa_String for that in Samba4's IDL - - die("Don't know what string type to use"); -} - -sub contains_pointer($) -{ - my $e = shift; - - foreach my $l (@{$e->{LEVELS}}) { - return 1 if ($l->{TYPE} eq "POINTER"); - } - - return 0; -} - -sub ext_decl_string($) -{ - my $e = shift; - - # One pointer is sufficient.. - return "const char" if (contains_pointer($e)); - return "const char *"; -} - -sub init_string($$$$) -{ - my ($e,$l,$n,$v) = @_; - - my $t = lc(decl_string($e)); - - my $flags; - if (property_matches($e, "flag", ".*STR_NULLTERM.*")) { - $flags = "UNI_STR_TERMINATE"; - } elsif (property_matches($e, "flag", ".*STR_NOTERM.*")) { - $flags = "UNI_STR_NOTERM"; - } else { - $flags = "UNI_FLAGS_NONE"; - } - - # One pointer is sufficient - if (substr($v, 0, 1) eq "*") { $v = substr($v, 1); } - - return "init_$t(&$n, $v, $flags);"; -} - -sub dissect_string($$$$$) -{ - my ($e,$l,$n,$w,$a) = @_; - - my $t = lc(decl_string($e)); - - $$a = 1; - return "smb_io_$t(\"$e->{NAME}\", &$n, 1, ps, depth)"; -} - -sub StringType($$) -{ - my ($e,$l) = @_; - my $nl = GetNextLevel($e,$l); - - if ($l->{IS_VARYING} and $l->{IS_CONFORMANT} and $nl->{DATA_TYPE} eq "uint16") { - return ("unistr2", "UNI_FLAGS_NONE"); - } elsif ($l->{IS_CONFORMANT} and $l->{IS_VARYING} and $nl->{DATA_TYPE} eq "uint8") { - return ("string2", 0); - } else { - fatal($e, "[string] non-varying string not supported for Samba3 yet"); - } -} - -my $known_types = -{ - uint8 => - { - DECL => "uint8", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint16 => - { - DECL => "uint16", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint32 => - { - DECL => "uint32", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - uint64 => - { - DECL => "uint64", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - int32 => - { - DECL => "int32", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - string => - { - DECL => \&decl_string, - EXT_DECL => \&ext_decl_string, - INIT => \&init_string, - DISSECT_P => \&dissect_string, - }, - NTSTATUS => - { - DECL => "NTSTATUS", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - WERROR => - { - DECL => "WERROR", - INIT => \&init_scalar, - DISSECT_P => \&dissect_scalar, - }, - GUID => - { - DECL => "struct uuid", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n) = @_; - return "smb_io_uuid(\"$e->{NAME}\", &$n, ps, depth)"; - } - }, - NTTIME => - { - DECL => "NTTIME", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "smb_io_nttime(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - dom_sid => - { - DECL => "DOM_SID", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "smb_io_dom_sid(\"$e->{NAME}\", &n, ps, depth)"; - } - }, - policy_handle => - { - DECL => "POLICY_HND", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - 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", - INIT => "", - DISSECT_P => sub { - my ($e,$l,$n,$w,$a) = @_; - return "prs_uint64(\"$e->{NAME}\", ps, depth, &$n)"; - } - }, -}; - -sub AddType($$) -{ - my ($t,$d) = @_; - - warn("Reregistering type $t") if (defined($known_types->{$t})); - - $known_types->{$t} = $d; -} - -# Return type without special stuff, as used in -# declarations for internal structs -sub DeclShort($) -{ - my $e = shift; - - my $t = $known_types->{$e->{TYPE}}; - - if (not $t) { - warning($e, "Can't declare unknown type `$e->{TYPE}'"); - return undef; - } - - my $p; - - # DECL can be a function - if (ref($t->{DECL}) eq "CODE") { - $p = $t->{DECL}->($e); - } else { - $p = $t->{DECL}; - } - - my $prefixes = ""; - my $suffixes = ""; - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { - $prefixes = "*$prefixes"; - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { - $suffixes.="[$l->{SIZE_IS}]"; - } - } - - return "$p $prefixes$e->{NAME}$suffixes"; -} - -# Return type including special stuff (pointers, etc). -sub DeclLong($) -{ - my $e = shift; - - my $t = $known_types->{$e->{TYPE}}; - - if (not $t) { - warning($e, "Can't declare unknown type `$e->{TYPE}'"); - return undef; - } - - my $p; - - if (defined($t->{EXT_DECL})) { - $p = $t->{EXT_DECL} - } else { - $p = $t->{DECL}; - } - - if (ref($p) eq "CODE") { - $p = $p->($e); - } - - my $prefixes = ""; - my $suffixes = ""; - - foreach my $l (@{$e->{LEVELS}}) { - if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}) { - $p = "const char"; - last; - } elsif ($l->{TYPE} eq "ARRAY" and not $l->{IS_FIXED}) { - $prefixes = "*$prefixes"; - } elsif ($l->{TYPE} eq "ARRAY" and $l->{IS_FIXED}) { - $suffixes.="[$l->{SIZE_IS}]"; - } elsif ($l->{TYPE} eq "POINTER") { - $prefixes = "*$prefixes"; - } - } - - return "$p $prefixes$e->{NAME}$suffixes"; -} - -sub InitType($$$$) -{ - my ($e, $l, $varname, $value) = @_; - - my $t = $known_types->{$l->{DATA_TYPE}}; - - if (not $t) { - warning($e, "Don't know how to initialize type $l->{DATA_TYPE}"); - return undef; - } - - # INIT can be a function - if (ref($t->{INIT}) eq "CODE") { - return $t->{INIT}->($e, $l, $varname, $value); - } else { - return $t->{INIT}; - } -} - -sub DissectType($$$$$) -{ - my ($e,$l,$varname,$what,$align) = @_; - - my $t = $known_types->{$l->{DATA_TYPE}}; - - if (not $t) { - warning($e, "Don't know how to dissect type $l->{DATA_TYPE}"); - return undef; - } - - my $dissect; - if ($what == 1) { #primitives - $dissect = $t->{DISSECT_P}; - } elsif ($what == 2) { - $dissect = $t->{DISSECT_D}; - } - - return "" if not defined($dissect); - - # DISSECT can be a function - if (ref($dissect) eq "CODE") { - return $dissect->($e,$l,$varname,$what,$align); - } else { - return $dissect; - } -} - -sub LoadTypes($) -{ - my $ndr = shift; - foreach my $if (@{$ndr}) { - next unless ($if->{TYPE} eq "INTERFACE"); - - foreach my $td (@{$if->{TYPES}}) { - my $decl = uc("$if->{NAME}_$td->{NAME}"); - - my $init = sub { - my ($e,$l,$n,$v) = @_; - return "$n = $v;"; - }; - - my $dissect_d; - my $dissect_p; - if ($td->{DATA}->{TYPE} eq "UNION") { - $decl.="_CTR"; - } - - $dissect_p = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_p(\"$e->{NAME}\", &$n, ps, depth)"; - }; - $dissect_d = sub { - my ($e,$l,$n,$w,$a) = @_; - - return "$if->{NAME}_io_$td->{NAME}_d(\"$e->{NAME}\", &$n, ps, depth)"; - }; - - AddType($td->{NAME}, { - DECL => $decl, - INIT => $init, - DISSECT_D => $dissect_d, - DISSECT_P => $dissect_p - }); - } - } -} - -1; -- cgit From 2fb4ecebc11152d770d07370b996b878338bcf46 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 14:13:48 +0000 Subject: r18475: Start working on server code generator that uses libndr. (This used to be commit aa1c550d371c5874668baf06be7168c85dc5d48b) --- source4/pidl/lib/Parse/Pidl/Samba3/Server.pm | 122 ------------------------ source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 110 +++++++++++++++++++++ 2 files changed, 110 insertions(+), 122 deletions(-) delete mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/Server.pm create mode 100644 source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm deleted file mode 100644 index 179ace7dbb..0000000000 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Server.pm +++ /dev/null @@ -1,122 +0,0 @@ -################################################### -# Samba3 NDR server generator for IDL structures -# Copyright jelmer@samba.org 2005 -# released under the GNU GPL - -package Parse::Pidl::Samba3::Server; - -use strict; -use Parse::Pidl::Typelist qw(hasType getType mapType); -use Parse::Pidl::Util qw(has_property ParseExpr); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); - -my $res = ""; -my $tabs = ""; - -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } - -use vars qw($VERSION); -$VERSION = '0.01'; - -sub ParseFunction($$) -{ - my ($if,$fn) = @_; - - pidl "/******************************************************************"; - pidl " api_$fn->{NAME}"; - pidl " *****************************************************************/"; - pidl ""; - pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; - pidl "{"; - indent; - pidl uc("$if->{NAME}_q_$fn->{NAME}") . " q_u;"; - pidl uc("$if->{NAME}_r_$fn->{NAME}") . " r_u;"; - pidl "prs_struct *data = &p->in_data.data;"; - pidl "prs_struct *rdata = &p->out_data.rdata;"; - pidl ""; - pidl "ZERO_STRUCT(q_u);"; - pidl "ZERO_STRUCT(r_u);"; - pidl ""; - pidl "if (!$if->{NAME}_io_q_$fn->{NAME}(\"\", &q_u, data, 0))"; - pidl "\treturn False;"; - pidl ""; - if ($fn->{RETURN_TYPE}) { - pidl "r_u.status = _$fn->{NAME}(p, &q_u, &r_u);"; - } else { - pidl "_$fn->{NAME}(p, &q_u, &r_u);"; - } - pidl ""; - pidl "if (!$if->{NAME}_io_r_$fn->{NAME}(\"\", &r_u, rdata, 0))"; - pidl "\treturn False;"; - pidl ""; - pidl "return True;"; - deindent; - pidl "}"; -} - -sub ParseInterface($) -{ - my $if = shift; - - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); - - pidl ""; - pidl "/* Tables */"; - pidl "static struct api_struct api_$if->{NAME}_cmds[] = "; - pidl "{"; - indent; - foreach (@{$if->{FUNCTIONS}}) { - pidl "{\"" . uc($_->{NAME}) . "\", " . uc($_->{NAME}) . ", api_$_->{NAME}},"; - } - deindent; - pidl "};"; - - pidl ""; - - pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)"; - pidl "{"; - indent; - pidl "*fns = api_$if->{NAME}_cmds;"; - pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);"; - deindent; - pidl "}"; - - pidl ""; - - pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; - pidl "{"; - indent; - pidl "return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; - deindent; - pidl "}"; -} - -sub Parse($$) -{ - my($ndr,$filename) = @_; - - $tabs = ""; - $res = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * server auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl "#include \"nterr.h\""; - pidl ""; - pidl "#undef DBGC_CLASS"; - pidl "#define DBGC_CLASS DBGC_RPC"; - pidl ""; - - foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); - } - - return $res; -} - -1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm new file mode 100644 index 0000000000..327aea2f0e --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -0,0 +1,110 @@ +################################################### +# Samba3 server generator for IDL structures +# on top of Samba4 style NDR functions +# Copyright jelmer@samba.org 2005-2006 +# released under the GNU GPL + +package Parse::Pidl::Samba3::ServerNDR; + +use strict; +use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); +use Parse::Pidl::Util qw(has_property ParseExpr is_constant); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Samba4 qw(DeclLong); + +use vars qw($VERSION); +$VERSION = '0.01'; + +my $res; +my $res_hdr; +my $tabs = ""; +sub indent() { $tabs.="\t"; } +sub deindent() { $tabs = substr($tabs, 1); } +sub pidl($) { $res .= $tabs.(shift)."\n"; } +sub pidl_hdr($) { $res_hdr .= (shift)."\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 fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } + +sub ParseFunction($$) +{ + my ($if,$fn) = @_; + + pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; + pidl "{"; + indent; + + deindent; + pidl "}"; + pidl ""; +} + +sub ParseInterface($) +{ + my $if = shift; + + my $uif = uc($if->{NAME}); + + pidl_hdr "#ifndef __SRV_$uif\__"; + pidl_hdr "#define __SRV_$uif\__"; + ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + + pidl ""; + pidl "/* Tables */"; + pidl "static struct api_struct api_$if->{NAME}_cmds[] = "; + pidl "{"; + indent; + + foreach (@{$if->{FUNCTIONS}}) { + pidl "{\"" . uc($_->{NAME}) . "\", DCERPC_" . uc($_->{NAME}) . ", api_$_->{NAME}},"; + } + + deindent; + pidl "};"; + + pidl ""; + + pidl_hdr "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns);"; + pidl "void $if->{NAME}_get_pipe_fns(struct api_struct **fns, int *n_fns)"; + pidl "{"; + indent; + pidl "*fns = api_$if->{NAME}_cmds;"; + pidl "*n_fns = sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct);"; + deindent; + pidl "}"; + pidl ""; + + pidl_hdr "NTSTATUS rpc_netdfs_init(void);"; + pidl "NTSTATUS rpc_netdfs_init(void)"; + pidl "{"; + pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; + pidl "}"; + + pidl_hdr "#endif /* __SRV_$uif\__ */"; +} + +sub Parse($$$) +{ + my($ndr,$header,$ndr_header) = @_; + + $res = ""; + $res_hdr = ""; + + pidl "/*"; + pidl " * Unix SMB/CIFS implementation."; + pidl " * server auto-generated by pidl. DO NOT MODIFY!"; + pidl " */"; + pidl ""; + pidl "#include \"includes.h\""; + pidl "#include \"$header\""; + pidl_hdr "#include \"$ndr_header\""; + pidl ""; + + foreach (@$ndr) { + ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + } + + return ($res, $res_hdr); +} + +1; -- cgit From 6a2b54149723d283878e3295bfe3a48d67e2d495 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 15:45:20 +0000 Subject: r18477: Finish server code generator for Samba 3. (This used to be commit 4e2f20042448721ba1df5bbbb77710e155f23953) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 327aea2f0e..7fba856617 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -33,7 +33,75 @@ sub ParseFunction($$) pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; pidl "{"; indent; + pidl "struct ndr_pull *pull;"; + pidl "struct ndr_push *push;"; + pidl "DATA_BLOB blob;"; + pidl "struct $fn->{NAME} r;"; + pidl "TALLOC_CTX *mem_ctx = talloc_init(\"api_$fn->{NAME}\");"; + pidl ""; + pidl "if (!prs_data_blob(&p->in_data.data, &blob, mem_ctx)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "pull = ndr_pull_init_blob(&blob, mem_ctx);"; + pidl "if (pull == NULL)"; + pidl "\treturn False;"; + pidl ""; + pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; + pidl "status = ndr_pull_$fn->{NAME}(pull, NDR_IN, &r);"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + my $proto = "_$fn->{NAME}(pipes_struct *p"; + my $ret = "_$fn->{NAME}(p"; + foreach (@{$fn->{ELEMENTS}}) { + my @dir = @{$_->{DIRECTION}}; + if (grep(@dir, /in/) and grep(@dir, /out/)) { + pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; + } + if (grep(@dir, /in/)) { $ret .= ", r.in.$_->{NAME}"; } + else { $ret .= ", r.out.$_->{NAME}"; } + + $proto .= ", " . DeclLong($_); + } + $ret .= ")"; + $proto .= ");"; + + if ($fn->{RETURN_TYPE}) { + $ret = "r.out.result = $ret"; + $proto = "$fn->{RETURN_TYPE} $proto"; + } else { + $proto = "void $proto"; + } + + pidl_hdr "$proto"; + pidl "$ret;"; + pidl ""; + pidl "push = ndr_push_init_ctx(mem_ctx);"; + pidl "if (push == NULL) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "status = ndr_push_$fn->{NAME}(push, NDR_OUT, &r);"; + pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "blob = ndr_push_blob(push);"; + pidl "if (!prs_init_data_blob(&p->in_data.rdata, &blob, p->mem_ctx)) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; + pidl "talloc_free(mem_ctx);"; + pidl ""; + pidl "return True;"; deindent; pidl "}"; pidl ""; -- cgit From ea50e4f30aad94320c7d8bbc3e33dd6b10777bbe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 15:54:08 +0000 Subject: r18478: Add missing declaration for status. (This used to be commit 64909a0d69a938e96f7a04b4288ca851fb8fe18a) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 7fba856617..47e18fee69 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -35,6 +35,7 @@ sub ParseFunction($$) indent; pidl "struct ndr_pull *pull;"; pidl "struct ndr_push *push;"; + pidl "NTSTATUS status;"; pidl "DATA_BLOB blob;"; pidl "struct $fn->{NAME} r;"; pidl "TALLOC_CTX *mem_ctx = talloc_init(\"api_$fn->{NAME}\");"; -- cgit From 965633a5b4c93e34723f753a807ef0cc77f916fa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Sep 2006 16:29:14 +0000 Subject: r18482: Fix a couple of small issues in the generated server code. (This used to be commit ddfe3c54439eb76327608e04df9381621ab875b8) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 47e18fee69..9ecd7d1e83 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -60,10 +60,10 @@ sub ParseFunction($$) my $ret = "_$fn->{NAME}(p"; foreach (@{$fn->{ELEMENTS}}) { my @dir = @{$_->{DIRECTION}}; - if (grep(@dir, /in/) and grep(@dir, /out/)) { + if (grep(/in/, @dir) and grep(/out/, @dir)) { pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; } - if (grep(@dir, /in/)) { $ret .= ", r.in.$_->{NAME}"; } + if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; } else { $ret .= ", r.out.$_->{NAME}"; } $proto .= ", " . DeclLong($_); @@ -95,7 +95,7 @@ sub ParseFunction($$) pidl "}"; pidl ""; pidl "blob = ndr_push_blob(push);"; - pidl "if (!prs_init_data_blob(&p->in_data.rdata, &blob, p->mem_ctx)) {"; + pidl "if (!prs_init_data_blob(&p->out_data.rdata, &blob, p->mem_ctx)) {"; pidl "\ttalloc_free(mem_ctx);"; pidl "\treturn False;"; pidl "}"; -- cgit From 5f68b76c4a02b2681e4533d010628a0dd6338768 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 14 Sep 2006 12:23:02 +0000 Subject: r18522: It's probably not a good idea to use rpc_netdfs_init() as initialization function name for _all_ RPC servers... (This used to be commit 234272e39d7dc79f5e7e0399aebf5681a92981b2) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 9ecd7d1e83..dea3a32607 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -143,8 +143,8 @@ sub ParseInterface($) pidl "}"; pidl ""; - pidl_hdr "NTSTATUS rpc_netdfs_init(void);"; - pidl "NTSTATUS rpc_netdfs_init(void)"; + pidl_hdr "NTSTATUS rpc_$if->{NAME}_init(void);"; + pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; pidl "{"; pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; pidl "}"; -- cgit From df08af841881d331285a56f76a826ebd19b426b8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 14 Sep 2006 12:25:41 +0000 Subject: r18523: Allow [out] on arrays as well as pointers, use in unixinfo. (This used to be commit f67b4d58acd2c3746e5ffeffa804e888ca3c49a5) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index fa629e6101..31ea73f7aa 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -61,7 +61,7 @@ sub ParseFunction($$) foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER"); + fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } -- cgit From f78ff444e68aa45674310e5c679b8caef69e35c9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 14 Sep 2006 13:37:17 +0000 Subject: r18524: Pre-allocate out arguments. (This used to be commit 0ee42669d3a5ec062ec14ecda94342b0df519964) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index dea3a32607..4d3dba2e0e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -26,6 +26,30 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LI sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); } sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } +sub AllocOutVar($$$$) +{ + my ($e, $mem_ctx, $name, $env) = @_; + + my $l = $e->{LEVELS}[0]; + + if ($l->{TYPE} eq "POINTER") { + $l = GetNextLevel($e, $l); + } + + if ($l->{TYPE} eq "ARRAY") { + my $size = ParseExpr($l->{SIZE_IS}, $env); + pidl "$name = talloc_array_size($mem_ctx, sizeof(*$name), $size);"; + } else { + pidl "$name = talloc_size($mem_ctx, sizeof(*$name));"; + } + + pidl "if ($name == NULL) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\treturn False;"; + pidl "}"; + pidl ""; +} + sub ParseFunction($$) { my ($if,$fn) = @_; @@ -56,12 +80,21 @@ sub ParseFunction($$) pidl "\treturn False;"; pidl "}"; pidl ""; + + my %env = (); + foreach (@{$fn->{ELEMENTS}}) { + next unless (grep (/in/, @{$_->{DIRECTION}})); + $env{$_->{NAME}} = "r.in.$_->{NAME}"; + } + my $proto = "_$fn->{NAME}(pipes_struct *p"; my $ret = "_$fn->{NAME}(p"; foreach (@{$fn->{ELEMENTS}}) { my @dir = @{$_->{DIRECTION}}; if (grep(/in/, @dir) and grep(/out/, @dir)) { pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; + } elsif (grep(/out/, @dir)) { + AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env); } if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; } else { $ret .= ", r.out.$_->{NAME}"; } -- cgit From 1463ca1d2bafd5eff003cb4dbb5671e5e8afe80a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 19 Sep 2006 22:18:16 +0000 Subject: r18689: Initialize r.out in the server side code, in case the handler function doesn't touch them. (This used to be commit 2ac2c7ca60c70d70a07162c63bfb492c74816c7c) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 4d3dba2e0e..8ef4529402 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -82,11 +82,15 @@ sub ParseFunction($$) pidl ""; my %env = (); + my $hasout = 0; foreach (@{$fn->{ELEMENTS}}) { + if (grep(/out/, @{$_->{DIRECTION}})) { $hasout = 1; } next unless (grep (/in/, @{$_->{DIRECTION}})); $env{$_->{NAME}} = "r.in.$_->{NAME}"; } + pidl "ZERO_STRUCT(r.out);" if ($hasout); + my $proto = "_$fn->{NAME}(pipes_struct *p"; my $ret = "_$fn->{NAME}(p"; foreach (@{$fn->{ELEMENTS}}) { -- cgit From b9785235b40ed0506fd920214967f6b0bd9fc659 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 19 Sep 2006 22:39:49 +0000 Subject: r18693: Print debug info when DEBUGLEVEL >= 10 in the Samba3 code. (This used to be commit d28ae3f70ad4f6b09780e600ecb98c39cc62fd24) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 8 ++++++++ source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 6 ++++++ 2 files changed, 14 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 31ea73f7aa..3b75bf33a6 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -52,7 +52,15 @@ sub ParseFunction($$) } } + pidl ""; + pidl "if (DEBUGLEVEL >= 10)"; + pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; + pidl ""; pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"; + pidl ""; + pidl "if (DEBUGLEVEL >= 10)"; + pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; + pidl ""; pidl "if (NT_STATUS_IS_ERR(status)) {"; pidl "\treturn status;"; pidl "}"; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 8ef4529402..070ccde8ee 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -80,6 +80,9 @@ sub ParseFunction($$) pidl "\treturn False;"; pidl "}"; pidl ""; + pidl "if (DEBUGLEVEL >= 10)"; + pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; + pidl ""; my %env = (); my $hasout = 0; @@ -118,6 +121,9 @@ sub ParseFunction($$) pidl_hdr "$proto"; pidl "$ret;"; + pidl ""; + pidl "if (DEBUGLEVEL >= 10)"; + pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; pidl ""; pidl "push = ndr_push_init_ctx(mem_ctx);"; pidl "if (push == NULL) {"; -- cgit From d094a421d3e85d4c27119f6cd4fd3e8e164f2f4c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 19 Sep 2006 22:48:08 +0000 Subject: r18696: Zero initialize ref ptrs. (This used to be commit 8de48f62e7840431fe5bfbb1c61daaafcf421ff1) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 070ccde8ee..928a88ba5e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -38,9 +38,9 @@ sub AllocOutVar($$$$) if ($l->{TYPE} eq "ARRAY") { my $size = ParseExpr($l->{SIZE_IS}, $env); - pidl "$name = talloc_array_size($mem_ctx, sizeof(*$name), $size);"; + pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name) * $size);"; } else { - pidl "$name = talloc_size($mem_ctx, sizeof(*$name));"; + pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name));"; } pidl "if ($name == NULL) {"; -- cgit From a22d785d7cdfbb662a0755552acfbf995d865d0c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 2 Oct 2006 16:19:05 +0000 Subject: r19049: Samba 3 client fixes * Make sure to check for NULL pointers when dealing with [out,unique] before assigning valoues * Detect RPC faults and return immediately (This used to be commit c96dae478c2fee2fede9c853a71c8079bbb8ba47) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 3b75bf33a6..c939feb1b9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -57,6 +57,14 @@ sub ParseFunction($$) pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; pidl ""; pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"; + pidl ""; + + pidl "if ( !NT_STATUS_IS_OK(status) ) {"; + indent; + pidl "return status;"; + deindent; + pidl "}"; + pidl ""; pidl "if (DEBUGLEVEL >= 10)"; pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; @@ -71,7 +79,16 @@ sub ParseFunction($$) fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") && ($e->{LEVELS}[0]->{POINTER_TYPE} eq "unique") ) { + pidl "if ( $e->{NAME} ) {"; + indent; + pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + deindent; + pidl "}"; + } else { + pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + } + } pidl""; -- cgit From e461cfee2ed62ad001d5e5a57fa32b83a3905733 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Oct 2006 19:40:48 +0000 Subject: r19208: Fix Samba3 pidl generation to remove memory leaks. Jermey. (This used to be commit 4b878578c27d499e38b208c87b4fd4b399474092) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 928a88ba5e..02fd1884a2 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -138,7 +138,7 @@ sub ParseFunction($$) pidl "}"; pidl ""; pidl "blob = ndr_push_blob(push);"; - pidl "if (!prs_init_data_blob(&p->out_data.rdata, &blob, p->mem_ctx)) {"; + pidl "if (!prs_copy_data_in(&p->out_data.rdata, blob.data, (uint32)blob.length)) {"; pidl "\ttalloc_free(mem_ctx);"; pidl "\treturn False;"; pidl "}"; -- cgit From af5e5175215145fb36bb28357894c41abd3bca84 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 10 Oct 2006 07:52:31 +0000 Subject: r19219: Fix a memleak in the generated srv_code. Fix a warning. Implement the rng_fault_state return check. After this (and Jeremy's fix) all Samba3-developers should do a 'make idl' and do a complete rebuild. Volker (This used to be commit 0c0a861c8b5b4c44d290f8db0d4c5e95260140ca) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 02fd1884a2..a7c81e4e2b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -70,8 +70,10 @@ sub ParseFunction($$) pidl "}"; pidl ""; pidl "pull = ndr_pull_init_blob(&blob, mem_ctx);"; - pidl "if (pull == NULL)"; + pidl "if (pull == NULL) {"; + pidl "\ttalloc_free(mem_ctx);"; pidl "\treturn False;"; + pidl "}"; pidl ""; pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; pidl "status = ndr_pull_$fn->{NAME}(pull, NDR_IN, &r);"; @@ -121,6 +123,12 @@ sub ParseFunction($$) pidl_hdr "$proto"; pidl "$ret;"; + pidl ""; + pidl "if (p->rng_fault_state) {"; + pidl "\ttalloc_free(mem_ctx);"; + pidl "\t/* Return True here, srv_pipe_hnd.c will take care */"; + pidl "\treturn True;"; + pidl "}"; pidl ""; pidl "if (DEBUGLEVEL >= 10)"; pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; @@ -138,7 +146,7 @@ sub ParseFunction($$) pidl "}"; pidl ""; pidl "blob = ndr_push_blob(push);"; - pidl "if (!prs_copy_data_in(&p->out_data.rdata, blob.data, (uint32)blob.length)) {"; + pidl "if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32)blob.length)) {"; pidl "\ttalloc_free(mem_ctx);"; pidl "\treturn False;"; pidl "}"; -- cgit From f4c4e0cf7fde6c5b5cffef2e3ad4ec24bb8fb894 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Nov 2006 17:56:35 +0000 Subject: r19790: Check in the PIDL change and the converted unixinfo and winbind pipes without waiting for comments. This is what version control is for, and it does fix a segfault I ran into ;-) Nevertheless, Jelmer & Jerry, please take a look! Thanks, Volker (This used to be commit 10dcaf89ed07b9d5d1c89da33b50fcaadead32b2) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index c939feb1b9..6cfab753e9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -10,7 +10,7 @@ use strict; use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); use Parse::Pidl::Util qw(has_property ParseExpr is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba4 qw(DeclLong); +use Parse::Pidl::Samba4 qw(DeclLong_cli IsUniqueOut); use vars qw($VERSION); $VERSION = '0.01'; @@ -36,7 +36,7 @@ sub ParseFunction($$) my $ufn = "DCERPC_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . DeclLong($_); + $defargs .= ", " . DeclLong_cli($_); } fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; pidl "{"; @@ -48,7 +48,12 @@ sub ParseFunction($$) foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/, @{$_->{DIRECTION}})) { + if ( IsUniqueOut($_) ) { + pidl "r.in.$_->{NAME} = *$_->{NAME};"; + } + else { pidl "r.in.$_->{NAME} = $_->{NAME};"; + } } } @@ -79,12 +84,8 @@ sub ParseFunction($$) fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") && ($e->{LEVELS}[0]->{POINTER_TYPE} eq "unique") ) { - pidl "if ( $e->{NAME} ) {"; - indent; - pidl "*$e->{NAME} = *r.out.$e->{NAME};"; - deindent; - pidl "}"; + if ( IsUniqueOut($e) ) { + pidl "*$e->{NAME} = r.out.$e->{NAME};"; } else { pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } -- cgit From f97f11eab25f0c294ff02b3c4485d7a0a91b5501 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 3 Jan 2007 15:34:01 +0000 Subject: r20511: Combine warnings/errors/fatal functions and move them to Parse::Pidl. (This used to be commit 959adfd0a682a4894c3bdd4ae9c6fc3ebfeeef1f) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 3 +-- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 6cfab753e9..5c88e3d22f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -7,6 +7,7 @@ package Parse::Pidl::Samba3::ClientNDR; use strict; +use Parse::Pidl qw(fatal warning); use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); use Parse::Pidl::Util qw(has_property ParseExpr is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); @@ -22,8 +23,6 @@ sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } sub pidl_hdr($) { $res_hdr .= (shift)."\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 fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } sub ParseFunction($$) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index a7c81e4e2b..8d42b483ec 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -7,6 +7,7 @@ package Parse::Pidl::Samba3::ServerNDR; use strict; +use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); use Parse::Pidl::Util qw(has_property ParseExpr is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); @@ -22,8 +23,6 @@ sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } sub pidl($) { $res .= $tabs.(shift)."\n"; } sub pidl_hdr($) { $res_hdr .= (shift)."\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 fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } sub AllocOutVar($$$$) -- cgit From a7bc3801f94891880a90b2974dfbadc9e9f8c2ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 20:52:12 +0000 Subject: r20567: Print proper errors with filename and line numbers in ParseExpr() (This used to be commit f5dc1b47ecf18068a47f8f68016463ef4a55dc03) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 5c88e3d22f..f6b3a6dcac 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR; use strict; use Parse::Pidl qw(fatal warning); use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); -use Parse::Pidl::Util qw(has_property ParseExpr is_constant); +use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong_cli IsUniqueOut); diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 8d42b483ec..f8ff458275 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -36,7 +36,7 @@ sub AllocOutVar($$$$) } if ($l->{TYPE} eq "ARRAY") { - my $size = ParseExpr($l->{SIZE_IS}, $env); + my $size = ParseExpr($l->{SIZE_IS}, $env, $e); pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name) * $size);"; } else { pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name));"; -- cgit From 85520faa42647c9d7ee7e519d4f2139de82ae4a9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 16 Jan 2007 15:51:37 +0000 Subject: r20834: No longer generate extra pointers for top-level [out] unique pointers. (This used to be commit b967f5851f24a4716d386fc569e384b9320b162a) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index f6b3a6dcac..ade2711d85 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -11,7 +11,7 @@ use Parse::Pidl qw(fatal warning); use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); -use Parse::Pidl::Samba4 qw(DeclLong_cli IsUniqueOut); +use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; @@ -35,7 +35,7 @@ sub ParseFunction($$) my $ufn = "DCERPC_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . DeclLong_cli($_); + $defargs .= ", " . DeclLong($_); } fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; pidl "{"; @@ -47,12 +47,7 @@ sub ParseFunction($$) foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/, @{$_->{DIRECTION}})) { - if ( IsUniqueOut($_) ) { - pidl "r.in.$_->{NAME} = *$_->{NAME};"; - } - else { pidl "r.in.$_->{NAME} = $_->{NAME};"; - } } } @@ -83,8 +78,12 @@ sub ParseFunction($$) fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - if ( IsUniqueOut($e) ) { - pidl "*$e->{NAME} = r.out.$e->{NAME};"; + if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") && ($e->{LEVELS}[0]->{POINTER_TYPE} eq "unique") ) { + pidl "if ( $e->{NAME} ) {"; + indent; + pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + deindent; + pidl "}"; } else { pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } -- cgit From 652f0a7ef8986acc26381c05b16c55c9f8c31e3a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 16 Jan 2007 17:45:33 +0000 Subject: r20836: Use real type name, to fix compilation with -WC++-compat (This used to be commit 10ca65bd78d27c425ae0347930fd2c9a92fe345c) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 53 +++++++++++++++++++++---- 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index f8ff458275..97cbc8b0ab 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -8,9 +8,9 @@ package Parse::Pidl::Samba3::ServerNDR; use strict; use Parse::Pidl qw(warning fatal); -use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); -use Parse::Pidl::Util qw(has_property ParseExpr is_constant); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::Typelist qw(mapType scalar_is_reference); +use Parse::Pidl::Util qw(ParseExpr has_property is_constant); +use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); @@ -25,21 +25,59 @@ sub pidl($) { $res .= $tabs.(shift)."\n"; } sub pidl_hdr($) { $res_hdr .= (shift)."\n"; } sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } +sub DeclLevel($$) +{ + sub DeclLevel($$); + my ($e, $l) = @_; + + my $ret = ""; + + if (has_property($e, "charset")) { + $ret.="const char"; + } else { + $ret.=mapType($e->{TYPE}); + } + + my $numstar = $e->{ORIGINAL}->{POINTERS}; + if ($numstar >= 1) { + $numstar-- if scalar_is_reference($e->{TYPE}); + } + foreach (@{$e->{ORIGINAL}->{ARRAY_LEN}}) + { + next if is_constant($_) and + not has_property($e, "charset"); + $numstar++; + } + $numstar -= $l; + die ("Too few pointers") if $numstar < 0; + if ($numstar > 0) + { + $ret.=" "; + $ret.="*" foreach (1..$numstar); + } + + return $ret; +} + sub AllocOutVar($$$$) { my ($e, $mem_ctx, $name, $env) = @_; my $l = $e->{LEVELS}[0]; + my $nl = $l; if ($l->{TYPE} eq "POINTER") { - $l = GetNextLevel($e, $l); + $nl = GetNextLevel($e, $l); } if ($l->{TYPE} eq "ARRAY") { my $size = ParseExpr($l->{SIZE_IS}, $env, $e); - pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name) * $size);"; + pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);"; + } elsif ($l->{TYPE} eq "POINTER" and $nl->{TYPE} eq "ARRAY") { + my $size = ParseExpr($nl->{SIZE_IS}, $env, $e); + pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);"; } else { - pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name));"; + pidl "$name = talloc_zero($mem_ctx, " . DeclLevel($e, 1) . ");"; } pidl "if ($name == NULL) {"; @@ -101,7 +139,8 @@ sub ParseFunction($$) my @dir = @{$_->{DIRECTION}}; if (grep(/in/, @dir) and grep(/out/, @dir)) { pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; - } elsif (grep(/out/, @dir)) { + } elsif (grep(/out/, @dir) and not + has_property($_, "represent_as")) { AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env); } if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; } -- cgit From dd08678adda6067a302677f4259719669261c081 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 31 Jan 2007 11:54:01 +0000 Subject: r21075: Generate parameters in structs for the server side Samba 3 code. The current code in Samba 3 is already generated using this pidl patch. (This used to be commit 30a06273d28fb59c6f20154f97c67f4c0a63dee9) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 97cbc8b0ab..52e384814d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -133,8 +133,8 @@ sub ParseFunction($$) pidl "ZERO_STRUCT(r.out);" if ($hasout); - my $proto = "_$fn->{NAME}(pipes_struct *p"; - my $ret = "_$fn->{NAME}(p"; + my $proto = "_$fn->{NAME}(pipes_struct *p, struct $fn->{NAME} *r"; + my $ret = "_$fn->{NAME}(p, &r"; foreach (@{$fn->{ELEMENTS}}) { my @dir = @{$_->{DIRECTION}}; if (grep(/in/, @dir) and grep(/out/, @dir)) { @@ -143,10 +143,6 @@ sub ParseFunction($$) has_property($_, "represent_as")) { AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env); } - if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; } - else { $ret .= ", r.out.$_->{NAME}"; } - - $proto .= ", " . DeclLong($_); } $ret .= ")"; $proto .= ");"; -- cgit From a7fa0d7063dd8abe5d9cdb3721fe0733983f5310 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 14 Feb 2007 14:23:59 +0000 Subject: r21338: Fix handling of top-level arrays for the Samba 3 client code. This doesn't fix the winreg code yet (as that's an array on top of a pointer), but at least it gets us closer. Also added a couple of tests for the Samba 3 client code. (This used to be commit 4a5b62ad622d7be08591e19bc2e89f665fff445a) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 54 +++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index ade2711d85..3b596aba65 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -6,18 +6,22 @@ package Parse::Pidl::Samba3::ClientNDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(GenerateFunctionInEnv ParseFunction $res $res_hdr); + use strict; use Parse::Pidl qw(fatal warning); use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); -use Parse::Pidl::Util qw(has_property is_constant); +use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; -my $res; -my $res_hdr; +our $res; +our $res_hdr; my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } @@ -25,13 +29,26 @@ sub pidl($) { $res .= $tabs.(shift)."\n"; } sub pidl_hdr($) { $res_hdr .= (shift)."\n"; } sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } +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 ParseFunction($$) { - my ($if,$fn) = @_; + my ($uif, $fn) = @_; my $inargs = ""; my $defargs = ""; - my $uif = uc($if->{NAME}); my $ufn = "DCERPC_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { @@ -58,7 +75,7 @@ sub ParseFunction($$) pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"; pidl ""; - pidl "if ( !NT_STATUS_IS_OK(status) ) {"; + pidl "if (!NT_STATUS_IS_OK(status)) {"; indent; pidl "return status;"; deindent; @@ -78,16 +95,29 @@ sub ParseFunction($$) fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") && ($e->{LEVELS}[0]->{POINTER_TYPE} eq "unique") ) { + if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and + ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { pidl "if ( $e->{NAME} ) {"; indent; + } + + if ($e->{LEVELS}[0]->{TYPE} eq "ARRAY") { + # This is a call to GenerateFunctionInEnv intentionally. + # Since the data is being copied into a user-provided data + # structure, the user should be able to know the size beforehand + # to allocate a structure of the right size. + my $env = GenerateFunctionInEnv($fn); + my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e); + pidl "memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"; + } else { pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + } + + if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and + ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { deindent; pidl "}"; - } else { - pidl "*$e->{NAME} = *r.out.$e->{NAME};"; } - } pidl""; @@ -99,7 +129,7 @@ sub ParseFunction($$) } elsif ($fn->{RETURN_TYPE} eq "WERROR") { pidl "return werror_to_ntstatus(r.out.result);"; } else { - pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */"; + pidl "#warning Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS"; pidl "return NT_STATUS_OK;"; } @@ -116,7 +146,7 @@ sub ParseInterface($) pidl_hdr "#ifndef __CLI_$uif\__"; pidl_hdr "#define __CLI_$uif\__"; - ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}}); + ParseFunction($if->{NAME}, $_) foreach (@{$if->{FUNCTIONS}}); pidl_hdr "#endif /* __CLI_$uif\__ */"; } -- cgit From 0fd260039498ac8331665cd2102b597198f58fbb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Feb 2007 14:13:14 +0000 Subject: r21384: Change warning to pidl warning, fix uppercasing. (This used to be commit a45a677084ba1bc63a8f74892c12ca6f0d9b5071) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 3b596aba65..0ffa321782 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -129,7 +129,7 @@ sub ParseFunction($$) } elsif ($fn->{RETURN_TYPE} eq "WERROR") { pidl "return werror_to_ntstatus(r.out.result);"; } else { - pidl "#warning Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS"; + warning($fn->{ORIGINAL}, "Unable to convert $fn->{RETURN_TYPE} to NTSTATUS"); pidl "return NT_STATUS_OK;"; } @@ -146,7 +146,7 @@ sub ParseInterface($) pidl_hdr "#ifndef __CLI_$uif\__"; pidl_hdr "#define __CLI_$uif\__"; - ParseFunction($if->{NAME}, $_) foreach (@{$if->{FUNCTIONS}}); + ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}}); pidl_hdr "#endif /* __CLI_$uif\__ */"; } -- cgit From 0515f728e64dde0c197aee6180dce79ad281d5f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 Feb 2007 18:44:56 +0000 Subject: r21433: Get rid of the COM support code - it's not used and unmaintained. We can always bring it back if we need to. This code was getting in the way while refactoring. Add some tests for TDR. Get rid of typedef in lib/registry/tdr_regf.idl and fix the TDR code to be able to deal with it. (This used to be commit 1ad0f99a439f0d52a735b391bf9900d50171aca5) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 0ffa321782..8fa37ca300 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -12,7 +12,7 @@ use Exporter; use strict; use Parse::Pidl qw(fatal warning); -use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference); +use Parse::Pidl::Typelist qw(hasType getType mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 52e384814d..aa4f3dd1ce 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -8,7 +8,7 @@ package Parse::Pidl::Samba3::ServerNDR; use strict; use Parse::Pidl qw(warning fatal); -use Parse::Pidl::Typelist qw(mapType scalar_is_reference); +use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(DeclLong); @@ -35,7 +35,7 @@ sub DeclLevel($$) if (has_property($e, "charset")) { $ret.="const char"; } else { - $ret.=mapType($e->{TYPE}); + $ret.=mapTypeName($e->{TYPE}); } my $numstar = $e->{ORIGINAL}->{POINTERS}; -- cgit From a0bfcfa55d9f00ffab59e8cf7529cadf108a5629 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 19 Apr 2007 01:26:15 +0000 Subject: r22357: Don't use 'our' (This used to be commit 7989ee2aa015264dc9334b5e15d4fe6cb55f4e09) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 8fa37ca300..a2219bdab2 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -20,8 +20,8 @@ use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; -our $res; -our $res_hdr; +my $res; +my $res_hdr; my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } -- cgit From b0d209087939c0de765349c80a22884b956f3f0f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 22 Apr 2007 14:19:22 +0000 Subject: r22457: Fix tests for Samba3 client generator. (This used to be commit cf5162ad100c1a8201d3309549c8ff0d3bd5a732) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 157 ++++++++++++------------ 1 file changed, 79 insertions(+), 78 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index a2219bdab2..27b71053fb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -20,14 +20,18 @@ use Parse::Pidl::Samba4 qw(DeclLong); use vars qw($VERSION); $VERSION = '0.01'; -my $res; -my $res_hdr; -my $tabs = ""; -sub indent() { $tabs.="\t"; } -sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } -sub pidl_hdr($) { $res_hdr .= (shift)."\n"; } -sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } +sub indent($) { my ($self) = @_; $self->{tabs}.="\t"; } +sub deindent($) { my ($self) = @_; $self->{tabs} = substr($self->{tabs}, 1); } +sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= "$self->{tabs}$txt\n"; } +sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; } +sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); } + +sub new($) +{ + my ($class) = shift; + my $self = { res => "", res_hdr => "", tabs => "" }; + bless($self, $class); +} sub GenerateFunctionInEnv($) { @@ -43,9 +47,9 @@ sub GenerateFunctionInEnv($) return \%env; } -sub ParseFunction($$) +sub ParseFunction($$$) { - my ($uif, $fn) = @_; + my ($self, $uif, $fn) = @_; my $inargs = ""; my $defargs = ""; @@ -54,42 +58,42 @@ sub ParseFunction($$) foreach (@{$fn->{ELEMENTS}}) { $defargs .= ", " . DeclLong($_); } - fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"; - pidl "{"; - indent; - pidl "struct $fn->{NAME} r;"; - pidl "NTSTATUS status;"; - pidl ""; - pidl "/* In parameters */"; + $self->fn_declare("NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"); + $self->pidl("{"); + $self->indent; + $self->pidl("struct $fn->{NAME} r;"); + $self->pidl("NTSTATUS status;"); + $self->pidl(""); + $self->pidl("/* In parameters */"); foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/, @{$_->{DIRECTION}})) { - pidl "r.in.$_->{NAME} = $_->{NAME};"; + $self->pidl("r.in.$_->{NAME} = $_->{NAME};"); } } - pidl ""; - pidl "if (DEBUGLEVEL >= 10)"; - pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; - pidl ""; - pidl "status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"; - pidl ""; - - pidl "if (!NT_STATUS_IS_OK(status)) {"; - indent; - pidl "return status;"; - deindent; - pidl "}"; - - pidl ""; - pidl "if (DEBUGLEVEL >= 10)"; - pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; - pidl ""; - pidl "if (NT_STATUS_IS_ERR(status)) {"; - pidl "\treturn status;"; - pidl "}"; - pidl ""; - pidl "/* Return variables */"; + $self->pidl(""); + $self->pidl("if (DEBUGLEVEL >= 10)"); + $self->pidl("\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"); + $self->pidl(""); + $self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"); + $self->pidl(""); + + $self->pidl("if (!NT_STATUS_IS_OK(status)) {"); + $self->indent; + $self->pidl("return status;"); + $self->deindent; + $self->pidl("}"); + + $self->pidl(""); + $self->pidl("if (DEBUGLEVEL >= 10)"); + $self->pidl("\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"); + $self->pidl(""); + $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); + $self->pidl("\treturn status;"); + $self->pidl("}"); + $self->pidl(""); + $self->pidl("/* Return variables */"); foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); @@ -97,8 +101,8 @@ sub ParseFunction($$) if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { - pidl "if ( $e->{NAME} ) {"; - indent; + $self->pidl("if ( $e->{NAME} ) {"); + $self->indent; } if ($e->{LEVELS}[0]->{TYPE} eq "ARRAY") { @@ -108,70 +112,67 @@ sub ParseFunction($$) # to allocate a structure of the right size. my $env = GenerateFunctionInEnv($fn); my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e); - pidl "memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"; + $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"); } else { - pidl "*$e->{NAME} = *r.out.$e->{NAME};"; + $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); } if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { - deindent; - pidl "}"; + $self->deindent; + $self->pidl("}"); } } - pidl""; - pidl "/* Return result */"; + $self->pidl(""); + $self->pidl("/* Return result */"); if (not $fn->{RETURN_TYPE}) { - pidl "return NT_STATUS_OK;"; + $self->pidl("return NT_STATUS_OK;"); } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - pidl "return r.out.result;"; + $self->pidl("return r.out.result;"); } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - pidl "return werror_to_ntstatus(r.out.result);"; + $self->pidl("return werror_to_ntstatus(r.out.result);"); } else { warning($fn->{ORIGINAL}, "Unable to convert $fn->{RETURN_TYPE} to NTSTATUS"); - pidl "return NT_STATUS_OK;"; + $self->pidl("return NT_STATUS_OK;"); } - deindent; - pidl "}"; - pidl ""; + $self->deindent; + $self->pidl("}"); + $self->pidl(""); } -sub ParseInterface($) +sub ParseInterface($$) { - my $if = shift; + my ($self, $if) = @_; my $uif = uc($if->{NAME}); - pidl_hdr "#ifndef __CLI_$uif\__"; - pidl_hdr "#define __CLI_$uif\__"; - ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}}); - pidl_hdr "#endif /* __CLI_$uif\__ */"; + $self->pidl_hdr("#ifndef __CLI_$uif\__"); + $self->pidl_hdr("#define __CLI_$uif\__"); + $self->ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}}); + $self->pidl_hdr("#endif /* __CLI_$uif\__ */"); } -sub Parse($$$) +sub Parse($$$$) { - my($ndr,$header,$ndr_header) = @_; - - $res = ""; - $res_hdr = ""; - - pidl "/*"; - pidl " * Unix SMB/CIFS implementation."; - pidl " * client auto-generated by pidl. DO NOT MODIFY!"; - pidl " */"; - pidl ""; - pidl "#include \"includes.h\""; - pidl "#include \"$header\""; - pidl_hdr "#include \"$ndr_header\""; - pidl ""; + my($self,$ndr,$header,$ndr_header) = @_; + + $self->pidl("/*"); + $self->pidl(" * Unix SMB/CIFS implementation."); + $self->pidl(" * client auto-generated by pidl. DO NOT MODIFY!"); + $self->pidl(" */"); + $self->pidl(""); + $self->pidl("#include \"includes.h\""); + $self->pidl("#include \"$header\""); + $self->pidl_hdr("#include \"$ndr_header\""); + $self->pidl(""); foreach (@$ndr) { - ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); + $self->ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); } - return ($res, $res_hdr); + return ($self->{res}, $self->{res_hdr}); } 1; -- cgit From 645e87281c78f944fd6fe2ae52c6e0f058c665ff Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Aug 2007 06:08:02 +0000 Subject: r24446: We only need one genric GenerateFunctionInEnv function metze (This used to be commit 0c5be644ba13c68b7378a6ae9dcd314018ece25d) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 27b71053fb..5352e41f24 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -16,6 +16,7 @@ use Parse::Pidl::Typelist qw(hasType getType mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); +use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv); use vars qw($VERSION); $VERSION = '0.01'; @@ -33,20 +34,6 @@ sub new($) bless($self, $class); } -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 ParseFunction($$$) { my ($self, $uif, $fn) = @_; @@ -110,7 +97,7 @@ sub ParseFunction($$$) # Since the data is being copied into a user-provided data # structure, the user should be able to know the size beforehand # to allocate a structure of the right size. - my $env = GenerateFunctionInEnv($fn); + my $env = GenerateFunctionInEnv($fn, "r."); my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e); $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"); } else { -- cgit From 449c9f1f1c03fdc026c56a900dd23b9506dbabf1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Aug 2007 10:23:28 +0000 Subject: r24454: when level 0 is a pointer we need to look for an array in level 1... metze (This used to be commit ca50b1ad3afbf02fef7c6d1fcbe11d23c515d340) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 5352e41f24..42120bec78 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -83,31 +83,35 @@ sub ParseFunction($$$) $self->pidl("/* Return variables */"); foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); + my $level = 0; fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and - ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { - $self->pidl("if ( $e->{NAME} ) {"); - $self->indent; + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $level = 1; + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->pidl("if ( $e->{NAME} ) {"); + $self->indent; + } } - if ($e->{LEVELS}[0]->{TYPE} eq "ARRAY") { + if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") { # This is a call to GenerateFunctionInEnv intentionally. # Since the data is being copied into a user-provided data # structure, the user should be able to know the size beforehand # to allocate a structure of the right size. my $env = GenerateFunctionInEnv($fn, "r."); - my $size_is = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e); + my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"); } else { $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); } - if ( ($e->{LEVELS}[0]->{TYPE} eq "POINTER") and - ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") ) { - $self->deindent; - $self->pidl("}"); + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } } } -- cgit From ff71b118b8050c419f98e4e306994523922488cb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Aug 2007 14:02:23 +0000 Subject: r24463: we have a function to correctly create an $env object so don't try it manually and introduce bugs:-) metze (This used to be commit a79129a4ae412f29a0d730f49327269a92ec8402) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index aa4f3dd1ce..d6311ed360 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -12,6 +12,7 @@ use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(DeclLong); +use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; @@ -123,12 +124,10 @@ sub ParseFunction($$) pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; pidl ""; - my %env = (); + my $env = GenerateFunctionOutEnv($fn, "r."); my $hasout = 0; foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/, @{$_->{DIRECTION}})) { $hasout = 1; } - next unless (grep (/in/, @{$_->{DIRECTION}})); - $env{$_->{NAME}} = "r.in.$_->{NAME}"; } pidl "ZERO_STRUCT(r.out);" if ($hasout); @@ -141,7 +140,7 @@ sub ParseFunction($$) pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; } elsif (grep(/out/, @dir) and not has_property($_, "represent_as")) { - AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env); + AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", $env); } } $ret .= ")"; -- cgit From a1707f2689448125abbde7efc4c86f5518ebe718 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 17 Aug 2007 09:12:13 +0000 Subject: r24511: pass the correct thing to fatal() metze (This used to be commit 82cc41c5589899552256b06a3b1ae84e24d3b71f) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 42120bec78..3f9d1f0464 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -85,7 +85,7 @@ sub ParseFunction($$$) next unless (grep(/out/, @{$e->{DIRECTION}})); my $level = 0; - fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); + fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { $level = 1; -- cgit From 456f3b378d79a32b3092a0f8e11c81ed29f89ddd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 17 Aug 2007 13:45:18 +0000 Subject: r24522: make the "skip pointer to an array" logic a bit easier metze (This used to be commit a698fb18573baf016009bdd2d02aaf336dc92a63) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index d6311ed360..cc5057aef4 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -65,18 +65,16 @@ sub AllocOutVar($$$$) my ($e, $mem_ctx, $name, $env) = @_; my $l = $e->{LEVELS}[0]; - my $nl = $l; + # we skip pointer to arrays if ($l->{TYPE} eq "POINTER") { - $nl = GetNextLevel($e, $l); + my $nl = GetNextLevel($e, $l); + $l = $nl if ($nl->{TYPE} eq "ARRAY"); } if ($l->{TYPE} eq "ARRAY") { my $size = ParseExpr($l->{SIZE_IS}, $env, $e); pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);"; - } elsif ($l->{TYPE} eq "POINTER" and $nl->{TYPE} eq "ARRAY") { - my $size = ParseExpr($nl->{SIZE_IS}, $env, $e); - pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);"; } else { pidl "$name = talloc_zero($mem_ctx, " . DeclLevel($e, 1) . ");"; } -- cgit From b379e50351c7cd7069ab75115a39749d6eba60ac Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 17 Aug 2007 13:47:03 +0000 Subject: r24523: we don't support multi-dimentional [out] arrays for the samba3 server stubs yet, so bail out. metze (This used to be commit ff11f2ce0c3f9c882d93bda0c89577adaf8c2a41) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index cc5057aef4..a8e7c347b3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -72,6 +72,14 @@ sub AllocOutVar($$$$) $l = $nl if ($nl->{TYPE} eq "ARRAY"); } + # we don't support multi-dimentional arrays yet + if ($l->{TYPE} eq "ARRAY") { + my $nl = GetNextLevel($e, $l); + if ($nl->{TYPE} eq "ARRAY") { + fatal($e->{ORIGINAL},"multi-dimentional [out] arrays are not supported!"); + } + } + if ($l->{TYPE} eq "ARRAY") { my $size = ParseExpr($l->{SIZE_IS}, $env, $e); pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);"; -- cgit From 75564a9d0ece0c050923339b09457bc3dd1a5f5d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 17 Aug 2007 13:53:12 +0000 Subject: r24524: make use of ElementStars() metze (This used to be commit 701aa31d14cde412c1fecef694d851882be8d17f) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 32 +++++++------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index a8e7c347b3..071163c300 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -11,7 +11,7 @@ use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); -use Parse::Pidl::Samba4 qw(DeclLong); +use Parse::Pidl::Samba4 qw(ElementStars DeclLong); use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); use vars qw($VERSION); @@ -28,36 +28,20 @@ sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } sub DeclLevel($$) { - sub DeclLevel($$); my ($e, $l) = @_; - - my $ret = ""; + my $res = ""; if (has_property($e, "charset")) { - $ret.="const char"; + $res .= "const char"; } else { - $ret.=mapTypeName($e->{TYPE}); + $res .= mapTypeName($e->{TYPE}); } - my $numstar = $e->{ORIGINAL}->{POINTERS}; - if ($numstar >= 1) { - $numstar-- if scalar_is_reference($e->{TYPE}); - } - foreach (@{$e->{ORIGINAL}->{ARRAY_LEN}}) - { - next if is_constant($_) and - not has_property($e, "charset"); - $numstar++; - } - $numstar -= $l; - die ("Too few pointers") if $numstar < 0; - if ($numstar > 0) - { - $ret.=" "; - $ret.="*" foreach (1..$numstar); - } + my $stars = ElementStars($e, $l); + + $res .= " ".$stars unless ($stars eq ""); - return $ret; + return $res; } sub AllocOutVar($$$$) -- cgit From 0d7d5a6d492253f184ac58fe45ca22af5a3731de Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 19 Aug 2007 22:09:21 +0000 Subject: r24560: rename some DCERPC_ prefixes into NDR_ metze (This used to be commit f874eca5dab74e930d0ec52abeb06295d2d90476) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 3f9d1f0464..b4e635f0db 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -40,7 +40,7 @@ sub ParseFunction($$$) my $inargs = ""; my $defargs = ""; - my $ufn = "DCERPC_".uc($fn->{NAME}); + my $ufn = "NDR_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { $defargs .= ", " . DeclLong($_); diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 071163c300..f7acddc7c4 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -199,7 +199,7 @@ sub ParseInterface($) indent; foreach (@{$if->{FUNCTIONS}}) { - pidl "{\"" . uc($_->{NAME}) . "\", DCERPC_" . uc($_->{NAME}) . ", api_$_->{NAME}},"; + pidl "{\"" . uc($_->{NAME}) . "\", NDR_" . uc($_->{NAME}) . ", api_$_->{NAME}},"; } deindent; -- cgit From 02467edf5cc3dbaac8bec15deff4fb606ab76f75 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 21 Aug 2007 12:19:56 +0000 Subject: r24592: pass down the ndr_interface_table in the samba3 client bindings instead of the pull and push functions metze (This used to be commit 9b59534a14700f7bfe56cae448030df59ced0ba5) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index b4e635f0db..9c3f01ad93 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -36,10 +36,11 @@ sub new($) sub ParseFunction($$$) { - my ($self, $uif, $fn) = @_; + my ($self, $if, $fn) = @_; my $inargs = ""; my $defargs = ""; + my $uif = uc($if); my $ufn = "NDR_".uc($fn->{NAME}); foreach (@{$fn->{ELEMENTS}}) { @@ -63,7 +64,7 @@ sub ParseFunction($$$) $self->pidl("if (DEBUGLEVEL >= 10)"); $self->pidl("\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"); $self->pidl(""); - $self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, $ufn, &r, (ndr_pull_flags_fn_t)ndr_pull_$fn->{NAME}, (ndr_push_flags_fn_t)ndr_push_$fn->{NAME});"); + $self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, &ndr_table_$if, $ufn, &r);"); $self->pidl(""); $self->pidl("if (!NT_STATUS_IS_OK(status)) {"); @@ -141,7 +142,7 @@ sub ParseInterface($$) $self->pidl_hdr("#ifndef __CLI_$uif\__"); $self->pidl_hdr("#define __CLI_$uif\__"); - $self->ParseFunction(uc($if->{NAME}), $_) foreach (@{$if->{FUNCTIONS}}); + $self->ParseFunction($if->{NAME}, $_) foreach (@{$if->{FUNCTIONS}}); $self->pidl_hdr("#endif /* __CLI_$uif\__ */"); } -- cgit From edb4fefeb74cd7a2390cbf962048c320d21b7d8c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 21 Aug 2007 14:06:33 +0000 Subject: r24596: - talloc request structure for the samba3 server bindings and make that the primary context for the request which the implementations can also use. - go via functions pointers in the ndr_interface_table instead of calling functions directly. metze (This used to be commit fa577a12940d2df9d5ea9e3e0fed40021d59647d) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 57 ++++++++++++++----------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index f7acddc7c4..b3aa98ee0a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -72,7 +72,7 @@ sub AllocOutVar($$$$) } pidl "if ($name == NULL) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free($mem_ctx);"; pidl "\treturn False;"; pidl "}"; pidl ""; @@ -82,62 +82,71 @@ sub ParseFunction($$) { my ($if,$fn) = @_; + my $op = "NDR_".uc($fn->{NAME}); + pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; pidl "{"; indent; + pidl "const struct ndr_interface_call *call;"; pidl "struct ndr_pull *pull;"; pidl "struct ndr_push *push;"; pidl "NTSTATUS status;"; pidl "DATA_BLOB blob;"; - pidl "struct $fn->{NAME} r;"; - pidl "TALLOC_CTX *mem_ctx = talloc_init(\"api_$fn->{NAME}\");"; + pidl "struct $fn->{NAME} *r;"; + pidl ""; + pidl "call = &ndr_table_$if->{NAME}.calls[$op];"; + pidl ""; + pidl "r = talloc(NULL, struct $fn->{NAME});"; + pidl "if (r == NULL) {"; + pidl "\treturn False;"; + pidl "}"; pidl ""; - pidl "if (!prs_data_blob(&p->in_data.data, &blob, mem_ctx)) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "if (!prs_data_blob(&p->in_data.data, &blob, r)) {"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; - pidl "pull = ndr_pull_init_blob(&blob, mem_ctx);"; + pidl "pull = ndr_pull_init_blob(&blob, r);"; pidl "if (pull == NULL) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; - pidl "status = ndr_pull_$fn->{NAME}(pull, NDR_IN, &r);"; + pidl "status = call->ndr_pull(pull, NDR_IN, r);"; pidl "if (NT_STATUS_IS_ERR(status)) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; pidl "if (DEBUGLEVEL >= 10)"; - pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"; + pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, r);"; pidl ""; - my $env = GenerateFunctionOutEnv($fn, "r."); + my $env = GenerateFunctionOutEnv($fn); my $hasout = 0; foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/, @{$_->{DIRECTION}})) { $hasout = 1; } } - pidl "ZERO_STRUCT(r.out);" if ($hasout); + pidl "ZERO_STRUCT(r->out);" if ($hasout); my $proto = "_$fn->{NAME}(pipes_struct *p, struct $fn->{NAME} *r"; - my $ret = "_$fn->{NAME}(p, &r"; + my $ret = "_$fn->{NAME}(p, r"; foreach (@{$fn->{ELEMENTS}}) { my @dir = @{$_->{DIRECTION}}; if (grep(/in/, @dir) and grep(/out/, @dir)) { - pidl "r.out.$_->{NAME} = r.in.$_->{NAME};"; + pidl "r->out.$_->{NAME} = r->in.$_->{NAME};"; } elsif (grep(/out/, @dir) and not has_property($_, "represent_as")) { - AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", $env); + AllocOutVar($_, "r", "r->out.$_->{NAME}", $env); } } $ret .= ")"; $proto .= ");"; if ($fn->{RETURN_TYPE}) { - $ret = "r.out.result = $ret"; + $ret = "r->out.result = $ret"; $proto = "$fn->{RETURN_TYPE} $proto"; } else { $proto = "void $proto"; @@ -148,33 +157,33 @@ sub ParseFunction($$) pidl ""; pidl "if (p->rng_fault_state) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\t/* Return True here, srv_pipe_hnd.c will take care */"; pidl "\treturn True;"; pidl "}"; pidl ""; pidl "if (DEBUGLEVEL >= 10)"; - pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"; + pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, r);"; pidl ""; - pidl "push = ndr_push_init_ctx(mem_ctx);"; + pidl "push = ndr_push_init_ctx(r);"; pidl "if (push == NULL) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; - pidl "status = ndr_push_$fn->{NAME}(push, NDR_OUT, &r);"; + pidl "status = call->ndr_push(push, NDR_OUT, r);"; pidl "if (NT_STATUS_IS_ERR(status)) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; pidl "blob = ndr_push_blob(push);"; pidl "if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32)blob.length)) {"; - pidl "\ttalloc_free(mem_ctx);"; + pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; pidl ""; - pidl "talloc_free(mem_ctx);"; + pidl "talloc_free(r);"; pidl ""; pidl "return True;"; deindent; -- cgit From c28074da329d7370e978df65e899c8cf834307eb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 17 Oct 2007 08:26:55 +0200 Subject: r25674: fix crash bug in pidl generated client code, this could have happend with [in,out,unique] pointers when the clients sends a valid pointer, but the server reponse with a NULL pointer (as samba-3.0.26a do for some calls). I've tested with midl to see how windows handles this situation and also the reverse case where the client sends NULL and the server reposnse with non-NULL. It appears that midl generated code just ignores this and only copies the result if both pointers are non-NULL. metze (This used to be commit 7203f717a676a741e49f96f2d477f4f459575caf) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 9c3f01ad93..f6c9a04a8e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -91,7 +91,7 @@ sub ParseFunction($$$) if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { $level = 1; if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { - $self->pidl("if ( $e->{NAME} ) {"); + $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {"); $self->indent; } } -- cgit From c940bec8d7ba06773c22fa3e73f873360ee23adb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Oct 2007 00:40:51 +0200 Subject: r25700: Now BOOL no longer exists in Samba 3.2, use bool instead. Jeremy. (This used to be commit ad0b9792f2dc91208a199060585c83ed7f622451) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index b3aa98ee0a..82cadd9bcc 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -84,7 +84,7 @@ sub ParseFunction($$) my $op = "NDR_".uc($fn->{NAME}); - pidl "static BOOL api_$fn->{NAME}(pipes_struct *p)"; + pidl "static bool api_$fn->{NAME}(pipes_struct *p)"; pidl "{"; indent; pidl "const struct ndr_interface_call *call;"; -- cgit From 3e1fb13024eec442bfdd0335bc03689f64d50c0e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 9 Nov 2007 19:23:25 +0100 Subject: r25915: ndr/pidl: change NTSTAUS into enum ndr_err_code (pidl code) Samba4/NDR/Parser.pm Samba4/NDR/Server.pm Samba3/ServerNDR.pm tests/ metze (This used to be commit 7106f21de8dfc472aa0846b49bfdb7543c63b310) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 82cadd9bcc..a07d0ddc6c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -90,7 +90,7 @@ sub ParseFunction($$) pidl "const struct ndr_interface_call *call;"; pidl "struct ndr_pull *pull;"; pidl "struct ndr_push *push;"; - pidl "NTSTATUS status;"; + pidl "enum ndr_err_code ndr_err;"; pidl "DATA_BLOB blob;"; pidl "struct $fn->{NAME} *r;"; pidl ""; @@ -113,8 +113,8 @@ sub ParseFunction($$) pidl "}"; pidl ""; pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; - pidl "status = call->ndr_pull(pull, NDR_IN, r);"; - pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "ndr_err = call->ndr_pull(pull, NDR_IN, r);"; + pidl "if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {"; pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; @@ -171,8 +171,8 @@ sub ParseFunction($$) pidl "\treturn False;"; pidl "}"; pidl ""; - pidl "status = call->ndr_push(push, NDR_OUT, r);"; - pidl "if (NT_STATUS_IS_ERR(status)) {"; + pidl "ndr_err = call->ndr_push(push, NDR_OUT, r);"; + pidl "if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {"; pidl "\ttalloc_free(r);"; pidl "\treturn False;"; pidl "}"; -- cgit From ef792cc8a54d99d8c32251fbae9e2178f5838576 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 3 Dec 2007 16:49:45 +0100 Subject: r26256: When generating Samba3 pidl output for WERROR based functions, make sure the client caller can retrieve the WERROR. Jelmer, no idea how to add a test for that... Guenther (This used to be commit cf55365177e2d9ca64a80bbeafeb91deb7e2c8b3) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index f6c9a04a8e..d77a166445 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -46,6 +46,11 @@ sub ParseFunction($$$) foreach (@{$fn->{ELEMENTS}}) { $defargs .= ", " . DeclLong($_); } + + if ($fn->{RETURN_TYPE} eq "WERROR") { + $defargs .= ", WERROR *werror"; + } + $self->fn_declare("NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"); $self->pidl("{"); $self->indent; @@ -123,6 +128,12 @@ sub ParseFunction($$$) } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { $self->pidl("return r.out.result;"); } elsif ($fn->{RETURN_TYPE} eq "WERROR") { + $self->pidl("if (werror) {"); + $self->indent; + $self->pidl("*werror = r.out.result;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); $self->pidl("return werror_to_ntstatus(r.out.result);"); } else { warning($fn->{ORIGINAL}, "Unable to convert $fn->{RETURN_TYPE} to NTSTATUS"); -- cgit From 133ee7014caecbe2236fa5bf2292a5f8c71e58ef Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 3 Dec 2007 17:00:10 +0100 Subject: r26257: Get rid of "uninitialized value" warning in the samba3 pidl generator. Jelmer, please check. Guenther (This used to be commit 2f693292882f2929ff5d23e4009dabbb0443f891) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index d77a166445..e174f77542 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -47,7 +47,7 @@ sub ParseFunction($$$) $defargs .= ", " . DeclLong($_); } - if ($fn->{RETURN_TYPE} eq "WERROR") { + if (defined($fn->{RETURN_TYPE}) && ($fn->{RETURN_TYPE} eq "WERROR")) { $defargs .= ", WERROR *werror"; } -- cgit From 0f32132b884fa56fde806ba33d082456b53e0df9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 17:02:53 -0600 Subject: r26695: Cosmetic fix for pidl generated samba3 client code. Guenther (This used to be commit c52d9e6e60e0765e4f793d64e94571b6f6c3f9c7) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index e174f77542..d6b6296bd8 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -23,7 +23,7 @@ $VERSION = '0.01'; sub indent($) { my ($self) = @_; $self->{tabs}.="\t"; } sub deindent($) { my ($self) = @_; $self->{tabs} = substr($self->{tabs}, 1); } -sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= "$self->{tabs}$txt\n"; } +sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= $txt ? "$self->{tabs}$txt\n" : "\n"; } sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; } sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); } -- cgit From e3f0e64ef083cbad37c0e967e5ab3de6a840b7f9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 22:56:44 -0600 Subject: r26696: Some more minor pidl samba3 client cosmetics. Guenther (This used to be commit 7ee3fd43f964d3161c075dae8de73c77de146538) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index d6b6296bd8..01b77c0c9f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -66,8 +66,11 @@ sub ParseFunction($$$) } $self->pidl(""); - $self->pidl("if (DEBUGLEVEL >= 10)"); - $self->pidl("\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"); + $self->pidl("if (DEBUGLEVEL >= 10) {"); + $self->indent; + $self->pidl("NDR_PRINT_IN_DEBUG($fn->{NAME}, &r);"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); $self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, &ndr_table_$if, $ufn, &r);"); $self->pidl(""); @@ -79,11 +82,16 @@ sub ParseFunction($$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("if (DEBUGLEVEL >= 10)"); - $self->pidl("\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"); + $self->pidl("if (DEBUGLEVEL >= 10) {"); + $self->indent; + $self->pidl("NDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); - $self->pidl("\treturn status;"); + $self->indent; + $self->pidl("return status;"); + $self->deindent; $self->pidl("}"); $self->pidl(""); $self->pidl("/* Return variables */"); -- cgit From e6968df1e57e1c09bee21019fc1eec15e7a06005 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Jan 2008 10:56:07 -0600 Subject: r26698: Prettify samba3 client code a little more. Guenther (This used to be commit 6ac36d6a4b83b9ef794a2022c4d46ed0b69758e9) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 01b77c0c9f..b7372a802a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -2,6 +2,7 @@ # Samba3 client generator for IDL structures # on top of Samba4 style NDR functions # Copyright jelmer@samba.org 2005-2006 +# Copyright gd@samba.org 2008 # released under the GNU GPL package Parse::Pidl::Samba3::ClientNDR; @@ -27,6 +28,15 @@ sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= $txt ? "$self->{tabs}$txt\n sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; } sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); } +sub genpad($) +{ + my ($s) = @_; + my $nt = int((length($s)+1)/8); + my $lt = ($nt*8)-1; + my $ns = (length($s)-$lt); + return "\t"x($nt)." "x($ns); +} + sub new($) { my ($class) = shift; @@ -38,20 +48,23 @@ sub ParseFunction($$$) { my ($self, $if, $fn) = @_; - my $inargs = ""; - my $defargs = ""; + my $fn_args = ""; my $uif = uc($if); my $ufn = "NDR_".uc($fn->{NAME}); + my $fn_str = "NTSTATUS rpccli_$fn->{NAME}"; + my $pad = genpad($fn_str); + + $fn_args .= "struct rpc_pipe_client *cli,\n" . $pad . "TALLOC_CTX *mem_ctx"; foreach (@{$fn->{ELEMENTS}}) { - $defargs .= ", " . DeclLong($_); + $fn_args .= ",\n" . $pad . DeclLong($_); } if (defined($fn->{RETURN_TYPE}) && ($fn->{RETURN_TYPE} eq "WERROR")) { - $defargs .= ", WERROR *werror"; + $fn_args .= ",\n" . $pad . "WERROR *werror"; } - $self->fn_declare("NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)"); + $self->fn_declare("$fn_str($fn_args)"); $self->pidl("{"); $self->indent; $self->pidl("struct $fn->{NAME} r;"); @@ -62,7 +75,7 @@ sub ParseFunction($$$) foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/, @{$_->{DIRECTION}})) { $self->pidl("r.in.$_->{NAME} = $_->{NAME};"); - } + } } $self->pidl(""); @@ -72,7 +85,12 @@ sub ParseFunction($$$) $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("status = cli_do_rpc_ndr(cli, mem_ctx, PI_$uif, &ndr_table_$if, $ufn, &r);"); + $self->pidl("status = cli_do_rpc_ndr(cli,"); + $self->pidl("\t\t\tmem_ctx,"); + $self->pidl("\t\t\tPI_$uif,"); + $self->pidl("\t\t\t&ndr_table_$if,"); + $self->pidl("\t\t\t$ufn,"); + $self->pidl("\t\t\t&r);"); $self->pidl(""); $self->pidl("if (!NT_STATUS_IS_OK(status)) {"); -- cgit From c781879e35b5ff29a21ab9ea4f0ca3b7c53280f7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 9 Jan 2008 11:28:53 -0600 Subject: r26699: Some minor cosmetics for pidl samba3 server code. Guenther (This used to be commit 81fa63dfe6004d916bbe653cbb1b4cbdf5d3d97d) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 38 +++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index a07d0ddc6c..47312bc83d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -22,11 +22,11 @@ my $res_hdr; my $tabs = ""; sub indent() { $tabs.="\t"; } sub deindent() { $tabs = substr($tabs, 1); } -sub pidl($) { $res .= $tabs.(shift)."\n"; } +sub pidl($) { my ($txt) = @_; $res .= $txt?$tabs.(shift)."\n":"\n"; } sub pidl_hdr($) { $res_hdr .= (shift)."\n"; } sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; } -sub DeclLevel($$) +sub DeclLevel($$) { my ($e, $l) = @_; my $res = ""; @@ -73,7 +73,7 @@ sub AllocOutVar($$$$) pidl "if ($name == NULL) {"; pidl "\ttalloc_free($mem_ctx);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; } @@ -98,29 +98,30 @@ sub ParseFunction($$) pidl ""; pidl "r = talloc(NULL, struct $fn->{NAME});"; pidl "if (r == NULL) {"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "if (!prs_data_blob(&p->in_data.data, &blob, r)) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "pull = ndr_pull_init_blob(&blob, r);"; pidl "if (pull == NULL) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "pull->flags |= LIBNDR_FLAG_REF_ALLOC;"; pidl "ndr_err = call->ndr_pull(pull, NDR_IN, r);"; pidl "if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; - pidl "if (DEBUGLEVEL >= 10)"; + pidl "if (DEBUGLEVEL >= 10) {"; pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, r);"; + pidl "}"; pidl ""; my $env = GenerateFunctionOutEnv($fn); @@ -137,7 +138,7 @@ sub ParseFunction($$) my @dir = @{$_->{DIRECTION}}; if (grep(/in/, @dir) and grep(/out/, @dir)) { pidl "r->out.$_->{NAME} = r->in.$_->{NAME};"; - } elsif (grep(/out/, @dir) and not + } elsif (grep(/out/, @dir) and not has_property($_, "represent_as")) { AllocOutVar($_, "r", "r->out.$_->{NAME}", $env); } @@ -158,34 +159,35 @@ sub ParseFunction($$) pidl ""; pidl "if (p->rng_fault_state) {"; pidl "\ttalloc_free(r);"; - pidl "\t/* Return True here, srv_pipe_hnd.c will take care */"; - pidl "\treturn True;"; + pidl "\t/* Return true here, srv_pipe_hnd.c will take care */"; + pidl "\treturn true;"; pidl "}"; pidl ""; - pidl "if (DEBUGLEVEL >= 10)"; + pidl "if (DEBUGLEVEL >= 10) {"; pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, r);"; + pidl "}"; pidl ""; pidl "push = ndr_push_init_ctx(r);"; pidl "if (push == NULL) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "ndr_err = call->ndr_push(push, NDR_OUT, r);"; pidl "if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "blob = ndr_push_blob(push);"; - pidl "if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32)blob.length)) {"; + pidl "if (!prs_copy_data_in(&p->out_data.rdata, (const char *)blob.data, (uint32_t)blob.length)) {"; pidl "\ttalloc_free(r);"; - pidl "\treturn False;"; + pidl "\treturn false;"; pidl "}"; pidl ""; pidl "talloc_free(r);"; pidl ""; - pidl "return True;"; + pidl "return true;"; deindent; pidl "}"; pidl ""; @@ -251,7 +253,7 @@ sub Parse($$$) pidl "#include \"$header\""; pidl_hdr "#include \"$ndr_header\""; pidl ""; - + foreach (@$ndr) { ParseInterface($_) if ($_->{TYPE} eq "INTERFACE"); } -- cgit From a99dff8660ca2d168523b7264d9208a8a12ca5cc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Jan 2008 18:15:12 +0100 Subject: pidl: Move Generate*Env functions to Parse::Pidl::Samba4::Header because they only work with the structures generated by that file. (This used to be commit 9aeb7f31b0fc3b9679e5af07e65e79bc8073c4e1) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index b7372a802a..86b8951026 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(GenerateFunctionInEnv ParseFunction $res $res_hdr); +@EXPORT_OK = qw(ParseFunction $res $res_hdr); use strict; use Parse::Pidl qw(fatal warning); @@ -17,7 +17,7 @@ use Parse::Pidl::Typelist qw(hasType getType mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv); use vars qw($VERSION); $VERSION = '0.01'; -- cgit From 39cc507d1b7b0454d8f380fc3127fa966a0f972c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 14:54:29 +0100 Subject: pidl: Fix imported function for ServerNDR and add test to make sure it doesn't regress again. (This used to be commit 0e036948307c8ca5013e20a17a10d109830e4df1) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 47312bc83d..ecc43ab896 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -12,7 +12,7 @@ use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(ElementStars DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; -- cgit From 3e53ad6f4a5767fd1a26a35a0060b03a6e77161c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 15:07:00 +0100 Subject: pidl: Add simple test for ServerNDR. (This used to be commit 5b2ea43ed8613ac10ebe7feda0cf070c8079137a) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index ecc43ab896..ca9e7d15db 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -6,6 +6,10 @@ package Parse::Pidl::Samba3::ServerNDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclLevel); + use strict; use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); -- cgit From dbba1925d15046dbb837b6e2d48ca38cbd4ed426 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 11 Feb 2008 08:44:56 +0100 Subject: pidl/Samba3::ServerNDR: use talloc_tos() instead of NULL metze (This used to be commit 99d6f49340d6f190ac318af939eeec17c29f1bbd) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index ca9e7d15db..4af9da0f52 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -100,7 +100,7 @@ sub ParseFunction($$) pidl ""; pidl "call = &ndr_table_$if->{NAME}.calls[$op];"; pidl ""; - pidl "r = talloc(NULL, struct $fn->{NAME});"; + pidl "r = talloc(talloc_tos(), struct $fn->{NAME});"; pidl "if (r == NULL) {"; pidl "\treturn false;"; pidl "}"; -- cgit From 07251792d4e020217ba23896dc65702853f31939 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 25 Mar 2008 17:38:27 +0100 Subject: Add some more header properties as inline comments to the generated samba3 client. Guenther (This used to be commit 8ca4b0b0942564afa70b2e8a6d67d65ea8b75e43) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 86b8951026..7a2575b897 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -44,6 +44,36 @@ sub new($) bless($self, $class); } +sub ElementDirection($) +{ + my ($e) = @_; + + return "[in,out]" if (has_property($e, "in") and has_property($e, "out")); + return "[in]" if (has_property($e, "in")); + return "[out]" if (has_property($e, "out")); + return "[in,out]"; +} + +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) { + return "[" . substr($ret, 0, -1) . "]"; + } +} + + sub ParseFunction($$$) { my ($self, $if, $fn) = @_; @@ -57,7 +87,9 @@ sub ParseFunction($$$) $fn_args .= "struct rpc_pipe_client *cli,\n" . $pad . "TALLOC_CTX *mem_ctx"; foreach (@{$fn->{ELEMENTS}}) { - $fn_args .= ",\n" . $pad . DeclLong($_); + my $dir = ElementDirection($_); + my $prop = HeaderProperties($_->{PROPERTIES}, ["in", "out"]); + $fn_args .= ",\n" . $pad . DeclLong($_) . " /* $dir $prop */"; } if (defined($fn->{RETURN_TYPE}) && ($fn->{RETURN_TYPE} eq "WERROR")) { -- cgit From 7bb2ebb884c35676a6cf03efe6ecc15b3e232a43 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 16:00:07 +0200 Subject: Fix size to memcpy call in generated Samba 3 client code. Reported-By: vl (This used to be commit a28807569d0cf32968bacdc0bd88197b19fbae49) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 65 ++++++++++++++----------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 7a2575b897..87ed29b54e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(ParseFunction $res $res_hdr); +@EXPORT_OK = qw(ParseFunction $res $res_hdr ParseOutputArgument); use strict; use Parse::Pidl qw(fatal warning); @@ -73,6 +73,40 @@ sub HeaderProperties($$) } } +sub ParseOutputArgument($$$) +{ + my ($self, $fn, $e) = @_; + my $level = 0; + + fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); + + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $level = 1; + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {"); + $self->indent; + } + } + + if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") { + # This is a call to GenerateFunctionInEnv intentionally. + # Since the data is being copied into a user-provided data + # structure, the user should be able to know the size beforehand + # to allocate a structure of the right size. + my $env = GenerateFunctionInEnv($fn, "r."); + my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); + $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));"); + } else { + $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); + } + + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } + } +} sub ParseFunction($$$) { @@ -147,36 +181,9 @@ sub ParseFunction($$$) $self->pidl("/* Return variables */"); foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - my $level = 0; - fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - - if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { - $level = 1; - if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { - $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {"); - $self->indent; - } - } + $self->ParseOutputArgument($fn, $e); - if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") { - # This is a call to GenerateFunctionInEnv intentionally. - # Since the data is being copied into a user-provided data - # structure, the user should be able to know the size beforehand - # to allocate a structure of the right size. - my $env = GenerateFunctionInEnv($fn, "r."); - my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); - $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"); - } else { - $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); - } - - if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { - if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { - $self->deindent; - $self->pidl("}"); - } - } } $self->pidl(""); -- cgit From 8025edf335dbb66c7efa1d51a0e600a9e3c13bba Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 Jul 2008 21:50:25 +0200 Subject: Add the interface ID to the rpc_pipe_register_commands call in s3 srv code (This used to be commit efe249928312f730ee580e72b9c640ef88b0ed5b) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 4af9da0f52..b21d3f4bbc 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -235,7 +235,7 @@ sub ParseInterface($) pidl_hdr "NTSTATUS rpc_$if->{NAME}_init(void);"; pidl "NTSTATUS rpc_$if->{NAME}_init(void)"; pidl "{"; - pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; + pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", \&ndr_table_$if->{NAME}.syntax_id, api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));"; pidl "}"; pidl_hdr "#endif /* __SRV_$uif\__ */"; -- cgit From a819f4e88c9398dbac17d102ad8b58e1a5f02df3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Jul 2008 13:05:23 +0200 Subject: s3 cli_do_rpc_ndr does not use PI_* anymore (This used to be commit e625c6b2516111002c99239c1a2188c6d5d87ab6) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Samba3') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 87ed29b54e..d2ab407eb0 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -153,7 +153,6 @@ sub ParseFunction($$$) $self->pidl(""); $self->pidl("status = cli_do_rpc_ndr(cli,"); $self->pidl("\t\t\tmem_ctx,"); - $self->pidl("\t\t\tPI_$uif,"); $self->pidl("\t\t\t&ndr_table_$if,"); $self->pidl("\t\t\t$ufn,"); $self->pidl("\t\t\t&r);"); -- cgit