3ec19fa158baf17e99152b46f94db21485960deb
[samba.git] / source4 / pidl / lib / Parse / Pidl / Samba / NDR / Client.pm
1 ###################################################
2 # client calls generator
3 # Copyright tridge@samba.org 2003
4 # released under the GNU GPL
5
6 package Parse::Pidl::Samba::NDR::Client;
7
8 use vars qw($VERSION);
9 $VERSION = '0.01';
10
11 use strict;
12
13 my($res);
14
15 #####################################################################
16 # parse a function
17 sub ParseFunction($$)
18 {
19         my ($interface, $fn) = @_;
20         my $name = $fn->{NAME};
21         my $uname = uc $name;
22
23         $res .= "
24 struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
25 {
26         if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
27                 NDR_PRINT_IN_DEBUG($name, r);
28         }
29         
30         return dcerpc_ndr_request_send(p, NULL, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
31 }
32
33 NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
34 {
35         struct rpc_request *req;
36         NTSTATUS status;
37         
38         req = dcerpc_$name\_send(p, mem_ctx, r);
39         if (req == NULL) return NT_STATUS_NO_MEMORY;
40
41         status = dcerpc_ndr_request_recv(req);
42
43     if (NT_STATUS_IS_OK(status) && (p->conn->flags & DCERPC_DEBUG_PRINT_OUT)) {
44                 NDR_PRINT_OUT_DEBUG($name, r);          
45         }
46 ";
47     
48         if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") {
49              $res .= "\tif (NT_STATUS_IS_OK(status)) status = r->out.result;\n";
50         }
51         $res .= 
52 "
53         return status;
54 }
55 ";
56 }
57
58 my %done;
59
60 #####################################################################
61 # parse the interface definitions
62 sub ParseInterface($)
63 {
64         my($interface) = shift;
65         $res .= "/* $interface->{NAME} - client functions generated by pidl */\n\n";
66
67         foreach my $fn (@{$interface->{FUNCTIONS}}) {
68                 next if not defined($fn->{OPNUM});
69                 next if defined($done{$fn->{NAME}});
70                 ParseFunction($interface, $fn);
71                 $done{$fn->{NAME}} = 1;
72         }
73
74         return $res;
75 }
76
77 sub Parse($$)
78 {
79         my($ndr) = shift;
80         my($filename) = shift;
81
82         my $h_filename = $filename;
83         $res = "";
84
85         if ($h_filename =~ /(.*)\.c/) {
86                 $h_filename = "$1.h";
87         }
88
89         $res .= "/* client functions auto-generated by pidl */\n";
90         $res .= "\n";
91         $res .= "#include \"includes.h\"\n";
92         $res .= "#include \"$h_filename\"\n";
93         $res .= "\n";
94
95         foreach my $x (@{$ndr}) {
96                 ($x->{TYPE} eq "INTERFACE") && ParseInterface($x);
97         }
98
99         return $res;
100 }
101
102 1;