STEP01x: pidl: add missing colon.
[metze/samba/wip.git] / pidl / lib / Parse / Pidl / Samba3 / CompatServer.pm
1 ###################################################
2 # Samba3 server generator for IDL structures
3 # Copyright jelmer@samba.org 2005-2006
4 # Copyright metze@samba.org 2014
5 # released under the GNU GPL
6
7 package Parse::Pidl::Samba3::CompatServer;
8
9 use Exporter;
10 @ISA = qw(Exporter);
11
12 use strict;
13 use Parse::Pidl qw(warning error fatal);
14 use Parse::Pidl::Util qw(has_property);
15 use Parse::Pidl::Samba3::ServerNDR qw(CallWithStructExported);
16
17 use vars qw($VERSION);
18 $VERSION = '0.01';
19
20 my $res;
21 my $res_hdr;
22 my $tabs = "";
23 sub pidl_reset() { $res=""; $res_hdr="", $tabs=""; }
24 sub pidl_return() { my $s = $res; my $h = $res_hdr; pidl_reset(); return ($s, $h) }
25 sub indent() { $tabs.="\t"; }
26 sub deindent() { $tabs = substr($tabs, 1); }
27 sub pidl($) { my ($txt) = @_; $res .= $txt?$tabs.(shift)."\n":"\n"; }
28 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
29 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
30
31 sub ParseFunctionState($$)
32 {
33         my ($if,$fn) = @_;
34
35         my $op = "NDR_".uc($fn->{NAME});
36
37         my $fnprefix = "_s3_compat_$fn->{NAME}";
38
39         pidl "struct ${fnprefix}_state {";
40         indent;
41         pidl "struct tevent_context *ev;";
42         pidl "struct dcerpc_call_handle *call;";
43         pidl "struct $fn->{NAME} *r;";
44         deindent;
45         pidl "};";
46         pidl "";
47 }
48
49 sub ParseFunctionSend($$)
50 {
51         my ($if,$fn) = @_;
52
53         my $op = "NDR_".uc($fn->{NAME});
54
55         my $fnprefix = "_s3_compat_$fn->{NAME}";
56
57         pidl "static struct tevent_req *${fnprefix}_send(TALLOC_CTX *mem_ctx,";
58         pidl "\t\t\t\t\tstruct tevent_context *ev,";
59         pidl "\t\t\t\t\tstruct dcerpc_call_handle *call,";
60         pidl "\t\t\t\t\tstruct $fn->{NAME} *r)";
61         pidl "{";
62         indent;
63         pidl "struct tevent_req *req;";
64         pidl "struct ${fnprefix}_state *state;";
65         pidl "struct pipes_struct *p;";
66         pidl "";
67         pidl "req = tevent_req_create(mem_ctx, &state,";
68         pidl "\t\t\tstruct ${fnprefix}_state);";
69         pidl "if (req == NULL) {";
70         indent;
71         pidl "return NULL;";
72         deindent;
73         pidl "}";
74         pidl "state->ev = ev;";
75         pidl "state->call = call;";
76         pidl "state->r = r;";
77         pidl "";
78
79         pidl "p = dcerpc_call_handle_get_pipes_struct(call);";
80         pidl "";
81
82         my ($s, $h) = CallWithStructExported("p", "r", $fn,
83                 sub ($) {
84                         my ($name) = @_;
85                         return "tevent_req_nomem(${name}, req)";
86                 },
87                 undef,
88                 sub {
89                         return "return tevent_req_post(req, ev);";
90                 }
91         );
92         $res_hdr .= $h;
93         $res .= $s;
94         pidl "";
95
96         pidl "if (p->fault_state) {";
97         indent;
98         pidl "NTSTATUS status = dcerpc_fault_to_nt_status(p->fault_state);";
99         pidl "tevent_req_nterror(status);";
100         pidl "return tevent_req_post(req, ev);";
101         deindent;
102         pidl "}";
103         pidl "";
104
105         pidl "tevent_req_done(req);";
106         pidl "return tevent_req_post(req, ev);";
107         deindent;
108         pidl "}";
109         pidl "";
110 }
111
112 sub ParseFunctionRecv($$)
113 {
114         my ($if,$fn) = @_;
115
116         my $op = "NDR_".uc($fn->{NAME});
117
118         my $fnprefix = "_s3_compat_$fn->{NAME}";
119
120         pidl "static NTSTATUS ${fnprefix}_recv(struct tevent_req *req)";
121         pidl "{";
122         indent;
123         pidl "return tevent_req_simple_recv_ntstatus(req);";
124         deindent;
125         pidl "}";
126         pidl "";
127 }
128
129 sub ParseFunction($$)
130 {
131         my ($if,$fn) = @_;
132
133         ParseFunctionState($fn, $fn);
134         ParseFunctionSend($fn, $fn);
135         ParseFunctionRecv($fn, $fn);
136 }
137
138 sub ParseInterface($)
139 {
140         my $if = shift;
141
142         my $uif = uc($if->{NAME});
143
144         pidl_hdr "#ifndef __S3COMPAT_$uif\__";
145         pidl_hdr "#define __S3COMPAT_$uif\__";
146
147         foreach (@{$if->{FUNCTIONS}}) {
148                 next if ($_->{PROPERTIES}{noopnum});
149                 ParseFunction($if, $_);
150         }
151
152         pidl "";
153         pidl "static const struct dcerpc_call_entry_point_fns struct _s3_compat_$if->{NAME}_fns[] = {";
154         indent;
155
156         my $count = 0;
157         foreach (@{$if->{FUNCTIONS}}) {
158                 next if ($_->{PROPERTIES}{noopnum});
159                 my $op = "NDR_".uc($_->{NAME});
160                 my $fnprefix = "_s3_compat_$_->{NAME}";
161
162                 pidl "{";
163                 indent;
164                 pidl ".send_fn = (dcerpc_call_entry_point_send_fn_t)";
165                 pidl "\t${fnprefix}_send,";
166                 pidl ".recv_fn = (dcerpc_call_entry_point_recv_fn_t)";
167                 pidl "\t${fnprefix}_recv,";
168                 deindent;
169                 pidl "},";
170
171                 $count += 1;
172         }
173
174         pidl "{";
175         indent;
176         pidl ".send_fn = NULL,";
177         pidl ".recv_fn = NULL,";
178         deindent;
179         pidl "},";
180         deindent;
181         pidl "};";
182         pidl "";
183
184         pidl "static const struct dcerpc_call_entry_point_vector _s3_compat_$if->{NAME}_epv[] = {";
185         indent;
186         pidl ".name = \"_s3_compat_$if->{NAME}\",";
187         pidl ".table = &ndr_table_$if->{NAME},";
188         pidl ".num_fns = $count,";
189         pidl ".fns = _s3_compat_$if->{NAME}_fns,";
190         deindent;
191         pidl "};";
192         pidl "";
193
194         if (not has_property($if, "no_srv_register")) {
195                 pidl_hdr "struct dcerpc_server;";
196                 fn_declare "NTSTATUS dcerpc_server_setup_s3compat_$if->{NAME}(struct dcerpc_server *server)";
197                 pidl "{";
198                 indent;
199                 pidl "return NT_STATUS_NOT_IMPLEMENTED;";
200                 deindent;
201                 pidl "}";
202         }
203
204         pidl_hdr "#endif /* __S3COMPAT_$uif\__ */";
205 }
206
207 sub Parse($$$)
208 {
209         my($ndr,$header,$ndr_header) = @_;
210
211         pidl_reset();
212
213         pidl_hdr "/*";
214         pidl_hdr " * Unix SMB/CIFS implementation.";
215         pidl_hdr " * server auto-generated by pidl. DO NOT MODIFY!";
216         pidl_hdr " */";
217         pidl_hdr "";
218         pidl "#include \"includes.h\"";
219         pidl "#include \"ntdomain.h\"";
220         pidl "#include \"$header\"";
221         pidl_hdr "#include \"$ndr_header\"";
222         pidl "";
223
224         foreach (@$ndr) {
225                 ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
226         }
227
228         return pidl_return;
229 }
230
231 1;