r26696: Some more minor pidl samba3 client cosmetics.
[samba.git] / source4 / pidl / lib / Parse / Pidl / Samba3 / ClientNDR.pm
index 9c3f01ad939205ce497c34fa12cee040d97074a2..01b77c0c9fd6c0e15b545d858ab7950190fa78f0 100644 (file)
@@ -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;"); }
 
@@ -46,6 +46,11 @@ sub ParseFunction($$$)
        foreach (@{$fn->{ELEMENTS}}) {
                $defargs .= ", " . DeclLong($_);
        }
+
+       if (defined($fn->{RETURN_TYPE}) && ($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;
@@ -61,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("");
@@ -74,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 */");
@@ -91,7 +104,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;
                        }
                }
@@ -123,6 +136,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");