2 # (C) 2007 Jelmer Vernooij <jelmer@samba.org>
3 # Published under the GNU General Public License
7 use Test
::More tests
=> 8;
8 use FindBin
qw($RealBin);
11 use Parse::Pidl::Util qw(MyDumper);
12 use Parse
::Pidl
::Samba3
::ClientNDR
;
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 {
34 TALLOC_CTX *out_mem_ctx;
37 static void rpccli_bar_done(struct tevent_req *subreq);
39 struct tevent_req *rpccli_bar_send(TALLOC_CTX *mem_ctx,
40 struct tevent_context *ev,
41 struct rpc_pipe_client *cli)
43 struct tevent_req *req;
44 struct rpccli_bar_state *state;
45 struct tevent_req *subreq;
47 req = tevent_req_create(mem_ctx, &state,
48 struct rpccli_bar_state);
52 state->out_mem_ctx = NULL;
54 subreq = dcerpc_bar_send(state,
57 if (tevent_req_nomem(subreq, req)) {
58 return tevent_req_post(req, ev);
60 tevent_req_set_callback(subreq, rpccli_bar_done, req);
64 static void rpccli_bar_done(struct tevent_req *subreq)
66 struct tevent_req *req = tevent_req_callback_data(
67 subreq, struct tevent_req);
68 struct rpccli_bar_state *state = tevent_req_data(
69 req, struct rpccli_bar_state);
73 if (state->out_mem_ctx) {
74 mem_ctx = state->out_mem_ctx;
79 status = dcerpc_bar_recv(subreq,
82 if (!NT_STATUS_IS_OK(status)) {
83 tevent_req_nterror(req, status);
90 NTSTATUS rpccli_bar_recv(struct tevent_req *req,
93 struct rpccli_bar_state *state = tevent_req_data(
94 req, struct rpccli_bar_state);
97 if (tevent_req_is_nterror(req, &status)) {
98 tevent_req_received(req);
102 /* Steal possible out parameters to the callers context */
103 talloc_steal(mem_ctx, state->out_mem_ctx);
105 tevent_req_received(req);
109 NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
114 status = dcerpc_bar(cli->binding_handle,
116 if (!NT_STATUS_IS_OK(status)) {
126 $x = new Parse
::Pidl
::Samba3
::ClientNDR
();
128 $fn = { NAME
=> "bar", ELEMENTS
=> [ ], RETURN_TYPE
=> "WERROR" };
129 $x->ParseFunction("foo", $fn);
131 "struct rpccli_bar_state {
132 TALLOC_CTX *out_mem_ctx;
136 static void rpccli_bar_done(struct tevent_req *subreq);
138 struct tevent_req *rpccli_bar_send(TALLOC_CTX *mem_ctx,
139 struct tevent_context *ev,
140 struct rpc_pipe_client *cli)
142 struct tevent_req *req;
143 struct rpccli_bar_state *state;
144 struct tevent_req *subreq;
146 req = tevent_req_create(mem_ctx, &state,
147 struct rpccli_bar_state);
151 state->out_mem_ctx = NULL;
153 subreq = dcerpc_bar_send(state,
155 cli->binding_handle);
156 if (tevent_req_nomem(subreq, req)) {
157 return tevent_req_post(req, ev);
159 tevent_req_set_callback(subreq, rpccli_bar_done, req);
163 static void rpccli_bar_done(struct tevent_req *subreq)
165 struct tevent_req *req = tevent_req_callback_data(
166 subreq, struct tevent_req);
167 struct rpccli_bar_state *state = tevent_req_data(
168 req, struct rpccli_bar_state);
172 if (state->out_mem_ctx) {
173 mem_ctx = state->out_mem_ctx;
178 status = dcerpc_bar_recv(subreq,
182 if (!NT_STATUS_IS_OK(status)) {
183 tevent_req_nterror(req, status);
187 tevent_req_done(req);
190 NTSTATUS rpccli_bar_recv(struct tevent_req *req,
194 struct rpccli_bar_state *state = tevent_req_data(
195 req, struct rpccli_bar_state);
198 if (tevent_req_is_nterror(req, &status)) {
199 tevent_req_received(req);
203 /* Steal possible out parameters to the callers context */
204 talloc_steal(mem_ctx, state->out_mem_ctx);
207 *result = state->result;
209 tevent_req_received(req);
213 NTSTATUS rpccli_bar(struct rpc_pipe_client *cli,
220 status = dcerpc_bar(cli->binding_handle,
223 if (!NT_STATUS_IS_OK(status)) {
232 return werror_to_ntstatus(result);