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\"")
21 * With midltests_tcp.exe NDR64 is enforced by default.
22 * For testing it might be needed to allow downgrades
23 * to NDR32. This is needed when you use 'pipe'.
25 cpp_quote("#define DONOT_FORCE_NDR64 1")
28 uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
29 pointer_default(unique)
33 typedef pipe char pipe_char;
34 typedef pipe hyper pipe_hyper;
39 typedef pipe structtype pipe_structtype;
47 * async pipes need to be passed by reference
50 [out,ref] struct msg *out1,
51 [out,ref] pipe_structtype *outp,
52 [in,ref] pipe_structtype *inp,
56 long midltests_ping( [in] struct msg in1);
60 #elif MIDLTESTS_C_CODE
62 struct pipe_char_state {
72 unsigned long * ecount)
74 struct pipe_char_state *state = (struct pipe_char_state *)_state;
76 printf("pull1:%s: esize[%u] ecount[%u]\n",
77 state->name, esize, *ecount);
78 *ecount = state->count--;
79 if (*ecount > esize) {
82 memset(buf, 0xDD, *ecount * sizeof(*buf));
83 printf("pull2:%s: esize[%u] ecount[%u]\n",
84 state->name, esize, *ecount);
92 struct pipe_char_state *state = (struct pipe_char_state *)_state;
94 printf("push:%s: ecount[%u]\n",
101 unsigned char * * buf,
102 unsigned long * bcount)
104 struct pipe_char_state *state = (struct pipe_char_state *)_state;
106 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
107 state->name, bsize, *bcount);
108 *bcount = bsize / sizeof(**buf);
109 *buf = malloc(*bcount * sizeof(**buf));
110 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
111 state->name, bsize, *bcount);
114 struct pipe_hyper_state {
120 void pipe_hyper_pull(
124 unsigned long * ecount)
126 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
128 printf("pull1:%s: esize[%u] ecount[%u]\n",
129 state->name, esize, *ecount);
130 *ecount = state->count--;
131 if (*ecount > esize) {
134 memset(buf, 0xDD, *ecount * sizeof(*buf));
135 printf("pull2:%s: esize[%u] ecount[%u]\n",
136 state->name, esize, *ecount);
139 void pipe_hyper_push(
142 unsigned long ecount)
144 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
146 printf("push:%s: ecount[%u]\n",
147 state->name, ecount);
150 void pipe_hyper_alloc(
154 unsigned long * bcount)
156 struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
158 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
159 state->name, bsize, *bcount);
160 *bcount = bsize / sizeof(**buf);
161 *buf = malloc(*bcount * sizeof(**buf));
162 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
163 state->name, bsize, *bcount);
165 struct pipe_structtype_state {
171 RPC_STATUS pipe_structtype_pull(
175 unsigned long * ecount)
177 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
179 printf("pull1:%s: esize[%u] ecount[%u]\n",
180 state->name, esize, *ecount);
181 *ecount = state->count--;
182 if (*ecount > esize) {
185 memset(buf, 0xDD, *ecount * sizeof(*buf));
186 printf("pull2:%s: esize[%u] ecount[%u]\n",
187 state->name, esize, *ecount);
190 RPC_STATUS pipe_structtype_push(
193 unsigned long ecount)
195 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
197 printf("push:%s: ecount[%u]\n",
198 state->name, ecount);
201 RPC_STATUS pipe_structtype_alloc(
205 unsigned long * bcount)
207 struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
209 printf("alloc1:%s: bsize[%u], bcount[%u]\n",
210 state->name, bsize, *bcount);
211 *bcount = bsize / sizeof(**buf);
212 *buf = malloc(*bcount * sizeof(**buf));
213 printf("alloc2:%s: bsize[%u], bcount[%u]\n",
214 state->name, bsize, *bcount);
216 static void midltests(void)
218 RPC_ASYNC_STATE aping;
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[3000];
230 in1.l = sizeof(in1b);
231 memset(&in1b, 0xAA, sizeof(in1b));
234 memset(&outs, 0, sizeof(outs));
236 memset(&outp, 0, sizeof(outp));
237 outp.pull = pipe_structtype_pull;
238 outp.push = pipe_structtype_push;
239 outp.alloc = pipe_structtype_alloc;
240 outp.state = (char *)&outs;
242 memset(&ins, 0, sizeof(ins));
245 memset(&inp, 0, sizeof(inp));
246 inp.pull = pipe_structtype_pull;
247 inp.push = pipe_structtype_push;
248 inp.alloc = pipe_structtype_alloc;
249 inp.state = (char *)&ins;
251 out1.l = sizeof(out1b);
252 memset(&out1b, 0xFF, sizeof(out1b));
255 RpcAsyncInitializeHandle(&aping, sizeof(aping));
256 cli_midltests_ping(&aping, in1);
259 status = RpcAsyncCompleteCall(&aping, &ret);
260 if (status != RPC_S_ASYNC_CALL_PENDING) {
265 RpcAsyncInitializeHandle(&afn, sizeof(afn));
266 cli_midltests_fn(&afn, &out1, &outp, &inp, in1);
269 status = RpcAsyncCompleteCall(&aping, &ret);
270 if (status != RPC_S_ASYNC_CALL_PENDING) {
277 void srv_midltests_fn(
278 PRPC_ASYNC_STATE midltests_fn_AsyncHandle,
279 /* [ref][out] */ struct msg *out1,
280 /* [out] */ ASYNC_pipe_structtype *outp,
281 /* [in] */ ASYNC_pipe_structtype *inp,
282 /* [in] */ struct msg in1)
285 structtype inb[2500];
286 unsigned long inb_len = 0;
287 structtype *outb = NULL;
288 unsigned long outb_size = 0;
289 unsigned long outb_len = 0;
291 printf("srv_midltests_fn: Start\n");
295 inp->pull(inp->state, inb, sizeof(inb), &inb_len);
296 printf("pull inp_len[%u]\n", inb_len);
298 } while (inb_len > 0);
302 outp->alloc(outp->state, outb_size, &outb, &outb_len);
303 memset(outb, 0xCC, outb_len * sizeof(*outb));
304 printf("push outb_len[%u]\n", outb_len);
306 outp->push(outp->state, outb, outb_len);
309 } while (outb_len > 0);
312 out1->m = (unsigned char *)malloc(out1->l);
313 memset(out1->m, 0xBB, out1->l);
314 printf("srv_midltests_fn: End\n");
317 RpcAsyncCompleteCall(midltests_fn_AsyncHandle, &ret);
320 void srv_midltests_ping(
321 PRPC_ASYNC_STATE midltests_ping_AsyncHandle,
322 /* [in] */ struct msg in1)
325 printf("srv_midltests_ping: Start\n");
326 printf("srv_midltests_ping: End\n");
328 RpcAsyncCompleteCall(midltests_ping_AsyncHandle, &ret);