1 #ifndef MIDLTESTS_C_CODE
4 * For midltests_tcp.exe you may want to
5 * redirect the traffic via rinetd
6 * with a /etc/rinetd.conf like this:
8 * 172.31.9.1 5032 172.31.9.8 5032
9 * 172.31.9.1 5064 172.31.9.8 5064
11 * This is useful to watch the traffic with
15 cpp_quote("#define LISTEN_IP \"0.0.0.0\"")
16 cpp_quote("#define FORWARD_IP \"127.0.0.1\"")
17 cpp_quote("#define CONNECT_IP \"172.31.9.1\"")
20 * With midltests_tcp.exe NDR64 is enforced by default.
21 * For testing it might be needed to allow downgrades
22 * to NDR32. This is needed when you use 'pipe'.
24 cpp_quote("#define DONOT_FORCE_NDR64 1")
27 uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
28 pointer_default(unique)
32 typedef pipe char pipe_char;
33 typedef pipe hyper pipe_hyper;
38 typedef pipe structtype pipe_structtype;
46 * async pipes need to be passed by reference
49 [out,ref] struct msg *out1,
50 [out,ref] pipe_structtype *outp,
51 [in,ref] pipe_structtype *inp,
55 long midltests_ping( [in] struct msg in1);
59 #elif MIDLTESTS_C_CODE
61 struct pipe_char_state {
71 unsigned long * ecount)
73 struct pipe_char_state *state = (struct pipe_char_state *)_state;
75 printf("pull1:%s: esize[%u] ecount[%u]\n",
76 state->name, esize, *ecount);
77 *ecount = state->count--;
78 if (*ecount > esize) {
81 memset(buf, 0xDD, *ecount * sizeof(*buf));
82 printf("pull2:%s: esize[%u] ecount[%u]\n",
83 state->name, esize, *ecount);
91 struct pipe_char_state *state = (struct pipe_char_state *)_state;
93 printf("push:%s: ecount[%u]\n",
100 unsigned char * * buf,
101 unsigned long * bcount)
103 struct pipe_char_state *state = (struct pipe_char_state *)_state;
105 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
106 state->name, bsize, *bcount);
107 *bcount = bsize / sizeof(**buf);
108 *buf = malloc(*bcount * sizeof(**buf));
109 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
110 state->name, bsize, *bcount);
113 struct pipe_hyper_state {
119 void pipe_hyper_pull(
123 unsigned long * ecount)
125 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
127 printf("pull1:%s: esize[%u] ecount[%u]\n",
128 state->name, esize, *ecount);
129 *ecount = state->count--;
130 if (*ecount > esize) {
133 memset(buf, 0xDD, *ecount * sizeof(*buf));
134 printf("pull2:%s: esize[%u] ecount[%u]\n",
135 state->name, esize, *ecount);
138 void pipe_hyper_push(
141 unsigned long ecount)
143 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
145 printf("push:%s: ecount[%u]\n",
146 state->name, ecount);
149 void pipe_hyper_alloc(
153 unsigned long * bcount)
155 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
157 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
158 state->name, bsize, *bcount);
159 *bcount = bsize / sizeof(**buf);
160 *buf = malloc(*bcount * sizeof(**buf));
161 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
162 state->name, bsize, *bcount);
164 struct pipe_structtype_state {
170 RPC_STATUS pipe_structtype_pull(
174 unsigned long * ecount)
176 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
178 printf("pull1:%s: esize[%u] ecount[%u]\n",
179 state->name, esize, *ecount);
180 *ecount = state->count--;
181 if (*ecount > esize) {
184 memset(buf, 0xDD, *ecount * sizeof(*buf));
185 printf("pull2:%s: esize[%u] ecount[%u]\n",
186 state->name, esize, *ecount);
189 RPC_STATUS pipe_structtype_push(
192 unsigned long ecount)
194 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
196 printf("push:%s: ecount[%u]\n",
197 state->name, ecount);
200 RPC_STATUS pipe_structtype_alloc(
204 unsigned long * bcount)
206 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
208 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
209 state->name, bsize, *bcount);
210 *bcount = bsize / sizeof(**buf);
211 *buf = malloc(*bcount * sizeof(**buf));
212 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
213 state->name, bsize, *bcount);
215 static void midltests(void)
217 RPC_ASYNC_STATE aping;
219 RPC_STATUS status = 0;
222 unsigned char out1b[3];
223 struct pipe_structtype_state outs;
224 ASYNC_pipe_structtype outp;
225 struct pipe_structtype_state ins;
226 ASYNC_pipe_structtype inp;
228 unsigned char in1b[300];
229 structtype inpb[2500];
230 structtype *outb = NULL;
231 unsigned long outb_size = 0;
232 unsigned long outb_len = 0;
234 in1.l = sizeof(in1b);
235 memset(&in1b, 0xAA, sizeof(in1b));
238 memset(&outs, 0, sizeof(outs));
240 memset(&outp, 0, sizeof(outp));
241 outp.pull = pipe_structtype_pull;
242 outp.push = pipe_structtype_push;
243 outp.alloc = pipe_structtype_alloc;
244 outp.state = (char *)&outs;
246 memset(&ins, 0, sizeof(ins));
249 memset(&inp, 0, sizeof(inp));
250 inp.pull = pipe_structtype_pull;
251 inp.push = pipe_structtype_push;
252 inp.alloc = pipe_structtype_alloc;
253 inp.state = (char *)&ins;
255 out1.l = sizeof(out1b);
256 memset(&out1b, 0xFF, sizeof(out1b));
259 RpcAsyncInitializeHandle(&aping, sizeof(aping));
260 cli_midltests_ping(&aping, in1);
264 status = RpcAsyncCompleteCall(&aping, &ret);
265 if (status != RPC_S_ASYNC_CALL_PENDING) {
273 printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
274 RpcAsyncInitializeHandle(&afn, sizeof(afn));
275 cli_midltests_fn(&afn, &out1, &outp, &inp, in1);
277 printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
279 memset(inpb, 0xEE, sizeof(inpb));
280 printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
281 inp.push(inp.state, inpb, sizeof(inpb));
284 printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
285 inp.push(inp.state, inpb, 0);
288 outp.pull(outp.state, outb, sizeof(outb), &outb_len);
290 printf("HERE:%s:%d:%s() %d\n", __FILE__, __LINE__, __FUNCTION__,
293 } while (outb_len > 0);
295 printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
296 status = RpcAsyncCompleteCall(&afn, &ret);
297 if (status != RPC_S_ASYNC_CALL_PENDING) {
302 printf("HERE:%s:%d:%s() %\n",
303 __FILE__, __LINE__, __FUNCTION__,
307 void srv_midltests_fn(
308 PRPC_ASYNC_STATE midltests_fn_AsyncHandle,
309 /* [ref][out] */ struct msg *out1,
310 /* [out] */ ASYNC_pipe_structtype *outp,
311 /* [in] */ ASYNC_pipe_structtype *inp,
312 /* [in] */ struct msg in1)
315 structtype inb[2500];
316 unsigned long inb_len = 0;
317 structtype *outb = NULL;
318 unsigned long outb_size = 0;
319 unsigned long outb_len = 0;
321 printf("srv_midltests_fn: Start\n");
325 inp->pull(inp->state, inb, sizeof(inb), &inb_len);
326 printf("pull inp_len[%u]\n", inb_len);
328 } while (inb_len > 0);
332 outp->alloc(outp->state, outb_size, &outb, &outb_len);
333 memset(outb, 0xCC, outb_len * sizeof(*outb));
334 printf("push outb_len[%u]\n", outb_len);
336 outp->push(outp->state, outb, outb_len);
339 } while (outb_len > 0);
342 out1->m = (unsigned char *)malloc(out1->l);
343 memset(out1->m, 0xBB, out1->l);
344 printf("srv_midltests_fn: End\n");
347 RpcAsyncCompleteCall(midltests_fn_AsyncHandle, &ret);
350 void srv_midltests_ping(
351 PRPC_ASYNC_STATE midltests_ping_AsyncHandle,
352 /* [in] */ struct msg in1)
355 printf("srv_midltests_ping: Start\n");
356 printf("srv_midltests_ping: End\n");
358 RpcAsyncCompleteCall(midltests_ping_AsyncHandle, &ret);