1 ###################################################
2 # client calls generator
3 # Copyright tridge@samba.org 2003
4 # Copyright jelmer@samba.org 2005-2006
5 # released under the GNU GPL
7 package Parse
::Pidl
::Samba4
::NDR
::Client
;
9 use Parse
::Pidl
::Samba4
qw(choose_header is_intree);
10 use Parse
::Pidl
::Util
qw(has_property);
12 use vars
qw($VERSION);
19 sub ParseFunctionSend($$$)
21 my ($interface, $fn, $name) = @_;
24 my $proto = "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
26 $res_hdr .= "\n$proto;\n";
28 $res .= "$proto\n{\n";
30 if (has_property($fn, "todo")) {
31 $res .= "\treturn NULL;\n";
34 if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
35 NDR_PRINT_IN_DEBUG($name, r);
38 return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME}, NDR_$uname, mem_ctx, r);
45 sub ParseFunctionSync($$$)
47 my ($interface, $fn, $name) = @_;
49 my $proto = "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)";
51 $res_hdr .= "\n$proto;\n";
52 $res .= "$proto\n{\n";
54 if (has_property($fn, "todo")) {
55 $res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n";
58 struct rpc_request *req;
61 req = dcerpc_$name\_send(p, mem_ctx, r);
62 if (req == NULL) return NT_STATUS_NO_MEMORY;
64 status = dcerpc_ndr_request_recv(req);
66 if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
67 NDR_PRINT_OUT_DEBUG($name, r);
71 if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") {
72 $res .= "\tif (NT_STATUS_IS_OK(status)) status = r->out.result;\n";
83 #####################################################################
87 my ($interface, $fn) = @_;
89 ParseFunctionSend($interface, $fn, $fn->{NAME});
90 ParseFunctionSync($interface, $fn, $fn->{NAME});
95 #####################################################################
96 # parse the interface definitions
99 my($interface) = shift;
101 $res_hdr .= "#ifndef _HEADER_RPC_$interface->{NAME}\n";
102 $res_hdr .= "#define _HEADER_RPC_$interface->{NAME}\n\n";
104 if (defined $interface->{PROPERTIES}->{uuid}) {
105 $res_hdr .= "extern const struct ndr_interface_table ndr_table_$interface->{NAME};\n";
108 $res .= "/* $interface->{NAME} - client functions generated by pidl */\n\n";
110 foreach my $fn (@{$interface->{FUNCTIONS}}) {
111 next if not defined($fn->{OPNUM});
112 next if defined($done{$fn->{NAME}});
113 ParseFunction($interface, $fn);
114 $done{$fn->{NAME}} = 1;
117 $res_hdr .= "#endif /* _HEADER_RPC_$interface->{NAME} */\n";
124 my($ndr,$header,$ndr_header,$client_header) = @_;
129 $res .= "/* client functions auto-generated by pidl */\n";
132 $res .= "#include \"includes.h\"\n";
134 $res .= "#ifndef _GNU_SOURCE\n";
135 $res .= "#define _GNU_SOURCE\n";
137 $res .= "#include <stdio.h>\n";
138 $res .= "#include <stdbool.h>\n";
139 $res .= "#include <stdlib.h>\n";
140 $res .= "#include <stdint.h>\n";
141 $res .= "#include <stdarg.h>\n";
142 $res .= "#include <core/ntstatus.h>\n";
144 $res .= "#include \"$ndr_header\"\n";
145 $res .= "#include \"$client_header\"\n";
148 $res_hdr .= choose_header("librpc/rpc/dcerpc.h", "dcerpc.h")."\n";
149 $res_hdr .= "#include \"$header\"\n";
151 foreach my $x (@{$ndr}) {
152 ($x->{TYPE} eq "INTERFACE") && ParseInterface($x);
155 return ($res,$res_hdr);