1 ###################################################
2 # Samba3 client generator for IDL structures
3 # on top of Samba4 style NDR functions
4 # Copyright jelmer@samba.org 2005-2006
5 # released under the GNU GPL
7 package Parse::Pidl::Samba3::ClientNDR;
10 use Parse::Pidl qw(fatal warning);
11 use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference);
12 use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
13 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
14 use Parse::Pidl::Samba4 qw(DeclLong_cli IsUniqueOut);
16 use vars qw($VERSION);
22 sub indent() { $tabs.="\t"; }
23 sub deindent() { $tabs = substr($tabs, 1); }
24 sub pidl($) { $res .= $tabs.(shift)."\n"; }
25 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
26 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
34 my $uif = uc($if->{NAME});
35 my $ufn = "DCERPC_".uc($fn->{NAME});
37 foreach (@{$fn->{ELEMENTS}}) {
38 $defargs .= ", " . DeclLong_cli($_);
40 fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)";
43 pidl "struct $fn->{NAME} r;";
44 pidl "NTSTATUS status;";
46 pidl "/* In parameters */";
48 foreach (@{$fn->{ELEMENTS}}) {
49 if (grep(/in/, @{$_->{DIRECTION}})) {
50 if ( IsUniqueOut($_) ) {
51 pidl "r.in.$_->{NAME} = *$_->{NAME};";
54 pidl "r.in.$_->{NAME} = $_->{NAME};";
60 pidl "if (DEBUGLEVEL >= 10)";
61 pidl "\tNDR_PRINT_IN_DEBUG($fn->{NAME}, &r);";
63 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});";
66 pidl "if ( !NT_STATUS_IS_OK(status) ) {";
68 pidl "return status;";
73 pidl "if (DEBUGLEVEL >= 10)";
74 pidl "\tNDR_PRINT_OUT_DEBUG($fn->{NAME}, &r);";
76 pidl "if (NT_STATUS_IS_ERR(status)) {";
77 pidl "\treturn status;";
80 pidl "/* Return variables */";
81 foreach my $e (@{$fn->{ELEMENTS}}) {
82 next unless (grep(/out/, @{$e->{DIRECTION}}));
84 fatal($e, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY");
86 if ( IsUniqueOut($e) ) {
87 pidl "*$e->{NAME} = r.out.$e->{NAME};";
89 pidl "*$e->{NAME} = *r.out.$e->{NAME};";
95 pidl "/* Return result */";
96 if (not $fn->{RETURN_TYPE}) {
97 pidl "return NT_STATUS_OK;";
98 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
99 pidl "return r.out.result;";
100 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
101 pidl "return werror_to_ntstatus(r.out.result);";
103 pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */";
104 pidl "return NT_STATUS_OK;";
112 sub ParseInterface($)
116 my $uif = uc($if->{NAME});
118 pidl_hdr "#ifndef __CLI_$uif\__";
119 pidl_hdr "#define __CLI_$uif\__";
120 ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}});
121 pidl_hdr "#endif /* __CLI_$uif\__ */";
126 my($ndr,$header,$ndr_header) = @_;
132 pidl " * Unix SMB/CIFS implementation.";
133 pidl " * client auto-generated by pidl. DO NOT MODIFY!";
136 pidl "#include \"includes.h\"";
137 pidl "#include \"$header\"";
138 pidl_hdr "#include \"$ndr_header\"";
142 ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
145 return ($res, $res_hdr);