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::Typelist qw(hasType getType mapType scalar_is_reference);
11 use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
12 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
13 use Parse::Pidl::Samba4 qw(DeclLong);
15 use vars qw($VERSION);
21 sub indent() { $tabs.="\t"; }
22 sub deindent() { $tabs = substr($tabs, 1); }
23 sub pidl($) { $res .= $tabs.(shift)."\n"; }
24 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
25 sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
26 sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
27 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
35 my $uif = uc($if->{NAME});
36 my $ufn = "DCERPC_".uc($fn->{NAME});
38 foreach (@{$fn->{ELEMENTS}}) {
39 $defargs .= ", " . DeclLong($_);
41 fn_declare "NTSTATUS rpccli_$fn->{NAME}(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx$defargs)";
44 pidl "struct $fn->{NAME} r;";
45 pidl "NTSTATUS status;";
47 pidl "/* In parameters */";
49 foreach (@{$fn->{ELEMENTS}}) {
50 if (grep(/in/, @{$_->{DIRECTION}})) {
51 pidl "r.in.$_->{NAME} = $_->{NAME};";
55 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});";
56 pidl "if (NT_STATUS_IS_ERR(status)) {";
57 pidl "\treturn status;";
60 pidl "/* Return variables */";
61 foreach my $e (@{$fn->{ELEMENTS}}) {
62 next unless (grep(/out/, @{$e->{DIRECTION}}));
64 fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER");
66 pidl "*$e->{NAME} = *r.out.$e->{NAME};";
70 pidl "/* Return result */";
71 if (not $fn->{RETURN_TYPE}) {
72 pidl "return NT_STATUS_OK;";
73 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
74 pidl "return r.out.result;";
75 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
76 pidl "return werror_to_ntstatus(r.out.result);";
78 pidl "/* Sorry, don't know how to convert $fn->{RETURN_TYPE} to NTSTATUS */";
79 pidl "return NT_STATUS_OK;";
91 my $uif = uc($if->{NAME});
93 pidl_hdr "#ifndef __CLI_$uif\__";
94 pidl_hdr "#define __CLI_$uif\__";
95 ParseFunction($if, $_) foreach (@{$if->{FUNCTIONS}});
96 pidl_hdr "#endif /* __CLI_$uif\__ */";
101 my($ndr,$header,$ndr_header) = @_;
107 pidl " * Unix SMB/CIFS implementation.";
108 pidl " * client auto-generated by pidl. DO NOT MODIFY!";
111 pidl "#include \"includes.h\"";
112 pidl "#include \"$header\"";
113 pidl_hdr "#include \"$ndr_header\"";
117 ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
120 return ($res, $res_hdr);