2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 9;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse
::Pidl
::Samba3
::ClientNDR
qw(ParseFunction ParseOutputArgument);
13 use Parse
::Pidl
::Samba4
::Header
qw(GenerateFunctionInEnv GenerateFunctionOutEnv);
15 # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work
16 my $fn = { ELEMENTS
=> [ { DIRECTION
=> ["in"], NAME
=> "foo" } ] };
17 is_deeply
({ "foo" => "r.in.foo" }, GenerateFunctionInEnv
($fn, "r."));
18 is_deeply
({ "foo" => "r.in.foo" }, GenerateFunctionOutEnv
($fn, "r."));
20 $fn = { ELEMENTS
=> [ { DIRECTION
=> ["out", "in"], NAME
=> "foo" } ] };
21 is_deeply
({ "foo" => "r.in.foo" }, GenerateFunctionInEnv
($fn, "r."));
22 is_deeply
({ "foo" => "r.out.foo" }, GenerateFunctionOutEnv
($fn, "r."));
24 $fn = { ELEMENTS
=> [ { DIRECTION
=> ["out"], NAME
=> "foo" } ] };
25 is_deeply
({ }, GenerateFunctionInEnv
($fn, "r."));
26 is_deeply
({ "foo" => "r.out.foo" }, GenerateFunctionOutEnv
($fn, "r."));
28 my $x = new Parse
::Pidl
::Samba3
::ClientNDR
();
30 $fn = { NAME
=> "bar", ELEMENTS
=> [ ] };
31 $x->ParseFunction("foo", $fn);
33 "struct rpccli_bar_state {
36 TALLOC_CTX *out_mem_ctx;
37 NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
40 static void rpccli_bar_done(struct tevent_req *subreq);
42 struct tevent_req *rpccli_bar_send(TALLOC_CTX *mem_ctx,
43 struct tevent_context *ev,
44 struct rpc_pipe_client *cli)
46 struct tevent_req *req;
47 struct rpccli_bar_state *state;
48 struct tevent_req *subreq;
50 req = tevent_req_create(mem_ctx, &state,
51 struct rpccli_bar_state);
55 state->out_mem_ctx = NULL;
56 state->dispatch_recv = cli->dispatch_recv;
62 if (DEBUGLEVEL >= 10) {
63 NDR_PRINT_IN_DEBUG(bar, &state->orig);
66 /* make a temporary copy, that we pass to the dispatch function */
67 state->tmp = state->orig;
69 subreq = cli->dispatch_send(state, ev, cli,
73 if (tevent_req_nomem(subreq, req)) {
74 return tevent_req_post(req, ev);
76 tevent_req_set_callback(subreq, rpccli_bar_done, req);
80 static void rpccli_bar_done(struct tevent_req *subreq)
82 struct tevent_req *req = tevent_req_callback_data(
83 subreq, struct tevent_req);
84 struct rpccli_bar_state *state = tevent_req_data(
85 req, struct rpccli_bar_state);
89 if (state->out_mem_ctx) {
90 mem_ctx = state->out_mem_ctx;
95 status = state->dispatch_recv(subreq, mem_ctx);
97 if (!NT_STATUS_IS_OK(status)) {
98 tevent_req_nterror(req, status);
102 /* Copy out parameters */
104 /* Reset temporary structure */
105 ZERO_STRUCT(state->tmp);
107 if (DEBUGLEVEL >= 10) {
108 NDR_PRINT_OUT_DEBUG(bar, &state->orig);
111 tevent_req_done(req);
114 NTSTATUS rpccli_bar_recv(struct tevent_req *req,
117 struct rpccli_bar_state *state = tevent_req_data(
118 req, struct rpccli_bar_state);
121 if (tevent_req_is_nterror(req, &status)) {
122 tevent_req_received(req);
126 /* Steal possbile out parameters to the callers context */
127 talloc_steal(mem_ctx, state->out_mem_ctx);
129 tevent_req_received(req);
133 NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
139 \t/* In parameters */
141 \tif (DEBUGLEVEL >= 10) {
142 \t\tNDR_PRINT_IN_DEBUG(bar, &r);
145 status = cli->dispatch(cli,
151 \tif (!NT_STATUS_IS_OK(status)) {
155 \tif (DEBUGLEVEL >= 10) {
156 \t\tNDR_PRINT_OUT_DEBUG(bar, &r);
159 \tif (NT_STATUS_IS_ERR(status)) {
163 \t/* Return variables */
165 \t/* Return result */
166 \treturn NT_STATUS_OK;
171 $x = new Parse
::Pidl
::Samba3
::ClientNDR
();
173 $fn = { NAME
=> "bar", ELEMENTS
=> [ ], RETURN_TYPE
=> "WERROR" };
174 $x->ParseFunction("foo", $fn);
176 "struct rpccli_bar_state {
179 TALLOC_CTX *out_mem_ctx;
180 NTSTATUS (*dispatch_recv)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
183 static void rpccli_bar_done(struct tevent_req *subreq);
185 struct tevent_req *rpccli_bar_send(TALLOC_CTX *mem_ctx,
186 struct tevent_context *ev,
187 struct rpc_pipe_client *cli)
189 struct tevent_req *req;
190 struct rpccli_bar_state *state;
191 struct tevent_req *subreq;
193 req = tevent_req_create(mem_ctx, &state,
194 struct rpccli_bar_state);
198 state->out_mem_ctx = NULL;
199 state->dispatch_recv = cli->dispatch_recv;
206 ZERO_STRUCT(state->orig.out.result);
208 if (DEBUGLEVEL >= 10) {
209 NDR_PRINT_IN_DEBUG(bar, &state->orig);
212 /* make a temporary copy, that we pass to the dispatch function */
213 state->tmp = state->orig;
215 subreq = cli->dispatch_send(state, ev, cli,
219 if (tevent_req_nomem(subreq, req)) {
220 return tevent_req_post(req, ev);
222 tevent_req_set_callback(subreq, rpccli_bar_done, req);
226 static void rpccli_bar_done(struct tevent_req *subreq)
228 struct tevent_req *req = tevent_req_callback_data(
229 subreq, struct tevent_req);
230 struct rpccli_bar_state *state = tevent_req_data(
231 req, struct rpccli_bar_state);
235 if (state->out_mem_ctx) {
236 mem_ctx = state->out_mem_ctx;
241 status = state->dispatch_recv(subreq, mem_ctx);
243 if (!NT_STATUS_IS_OK(status)) {
244 tevent_req_nterror(req, status);
248 /* Copy out parameters */
251 state->orig.out.result = state->tmp.out.result;
253 /* Reset temporary structure */
254 ZERO_STRUCT(state->tmp);
256 if (DEBUGLEVEL >= 10) {
257 NDR_PRINT_OUT_DEBUG(bar, &state->orig);
260 tevent_req_done(req);
263 NTSTATUS rpccli_bar_recv(struct tevent_req *req,
267 struct rpccli_bar_state *state = tevent_req_data(
268 req, struct rpccli_bar_state);
271 if (tevent_req_is_nterror(req, &status)) {
272 tevent_req_received(req);
276 /* Steal possbile out parameters to the callers context */
277 talloc_steal(mem_ctx, state->out_mem_ctx);
280 *result = state->orig.out.result;
282 tevent_req_received(req);
286 NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
293 \t/* In parameters */
295 \tif (DEBUGLEVEL >= 10) {
296 \t\tNDR_PRINT_IN_DEBUG(bar, &r);
299 status = cli->dispatch(cli,
305 \tif (!NT_STATUS_IS_OK(status)) {
309 \tif (DEBUGLEVEL >= 10) {
310 \t\tNDR_PRINT_OUT_DEBUG(bar, &r);
313 \tif (NT_STATUS_IS_ERR(status)) {
317 \t/* Return variables */
319 \t/* Return result */
321 \t\t*werror = r.out.result;
324 \treturn werror_to_ntstatus(r.out.result);
329 $x = new Parse
::Pidl
::Samba3
::ClientNDR
();
331 $fn = { NAME
=> "bar", ELEMENTS
=> [ ], RETURN_TYPE
=> "WERROR" };
332 my $e = { NAME
=> "foo", ORIGINAL
=> { FILE
=> "f", LINE
=> -1 },
333 LEVELS
=> [ { TYPE
=> "ARRAY", SIZE_IS
=> "mysize" }, { TYPE
=> "DATA", DATA_TYPE
=> "int" } ]};
335 $x->ParseOutputArgument($fn, $e);
336 is
($x->{res
}, "memcpy(foo, r.out.foo, (mysize) * sizeof(*foo));\n");