summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2008-01-11 09:25:14 +1100
committerAndrew Bartlett <abartlet@samba.org>2008-01-11 09:25:14 +1100
commit80902a2a2b14bc27af0f195d18c40ccef9cb780c (patch)
tree792ae2b86096db9026933c7fe22c57ff7a401bf4 /source4/pidl/lib/Parse/Pidl
parent7054ce65485482d1cc5fa4ff83272feb752e71c2 (diff)
parent84c9b6235ed52770eb6dfae8b75c346d435cb260 (diff)
downloadsamba-80902a2a2b14bc27af0f195d18c40ccef9cb780c.tar.gz
samba-80902a2a2b14bc27af0f195d18c40ccef9cb780c.tar.bz2
samba-80902a2a2b14bc27af0f195d18c40ccef9cb780c.zip
Merge commit 'origin/v4-0-test' into 4-0-local
(This used to be commit 4720f53a92644dd6959e18923924fbe01889111c)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm52
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm38
2 files changed, 59 insertions, 31 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
index e174f77542..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;
@@ -23,10 +24,19 @@ $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;"); }
+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,14 +75,22 @@ sub ParseFunction($$$)
foreach (@{$fn->{ELEMENTS}}) {
if (grep(/in/, @{$_->{DIRECTION}})) {
$self->pidl("r.in.$_->{NAME} = $_->{NAME};");
- }
+ }
}
$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("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)) {");
@@ -79,11 +100,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 */");
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");
}