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