41b15517bc4778bc5ad78672317d905493a55457
[metze/samba/wip.git] / testprogs / win32 / midltests / midltests.idl
1 #ifndef MIDLTESTS_C_CODE
2
3 /*
4  * For midltests_tcp.exe you may want to
5  * redirect the traffic via rinetd
6  * with a /etc/rinetd.conf like this:
7  *
8  * 172.31.9.1 5032 172.31.9.8 5032
9  * 172.31.9.1 5064 172.31.9.8 5064
10  *
11  * This is useful to watch the traffic with
12  * a network sniffer.
13  */
14
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\"")
18
19 /*
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'.
23  */
24 cpp_quote("#define DONOT_FORCE_NDR64 1")
25
26 [
27   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
28   pointer_default(unique)
29 ]
30 interface midltests
31 {
32         typedef pipe char pipe_char;
33         typedef pipe hyper pipe_hyper;
34         typedef struct {
35                 long l;
36                 short s;
37         } structtype;
38         typedef pipe structtype pipe_structtype;
39
40         struct msg {
41                 long l;
42                 [size_is(l)] char *m;
43         };
44
45         /*
46          * async pipes need to be passed by reference
47          */
48         long midltests_fn(
49                 [out,ref] struct msg *out1,
50                 [out,ref] pipe_structtype *outp,
51                 [in,ref] pipe_structtype *inp,
52                 [in] struct msg in1
53         );
54
55         long midltests_ping( [in] struct msg in1);
56
57 }
58
59 #elif MIDLTESTS_C_CODE
60
61 struct pipe_char_state {
62         const char *name;
63         unsigned long count;
64         unsigned long sleep;
65 };
66
67 void pipe_char_pull(
68             char * _state,
69             unsigned char * buf,
70             unsigned long esize,
71             unsigned long * ecount)
72 {
73         struct pipe_char_state *state = (struct pipe_char_state *)_state;
74
75         printf("pull1:%s: esize[%u] ecount[%u]\n",
76                 state->name, esize, *ecount);
77         *ecount = state->count--;
78         if (*ecount > esize) {
79                 *ecount = esize;
80         }
81         memset(buf, 0xDD, *ecount * sizeof(*buf));
82         printf("pull2:%s: esize[%u] ecount[%u]\n",
83                 state->name, esize, *ecount);
84 }
85
86 void pipe_char_push(
87             char * _state,
88             unsigned char * buf,
89             unsigned long ecount)
90 {
91         struct pipe_char_state *state = (struct pipe_char_state *)_state;
92
93         printf("push:%s: ecount[%u]\n",
94                 state->name, ecount);
95 }
96
97 void pipe_char_alloc(
98             char * _state,
99             unsigned long bsize,
100             unsigned char * * buf,
101             unsigned long * bcount)
102 {
103         struct pipe_char_state *state = (struct pipe_char_state *)_state;
104
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);
111 }
112
113 struct pipe_hyper_state {
114         const char *name;
115         unsigned long count;
116         unsigned long sleep;
117 };
118
119 void pipe_hyper_pull(
120             char * _state,
121             hyper * buf,
122             unsigned long esize,
123             unsigned long * ecount)
124 {
125         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
126
127         printf("pull1:%s: esize[%u] ecount[%u]\n",
128                 state->name, esize, *ecount);
129         *ecount = state->count--;
130         if (*ecount > esize) {
131                 *ecount = esize;
132         }
133         memset(buf, 0xDD, *ecount * sizeof(*buf));
134         printf("pull2:%s: esize[%u] ecount[%u]\n",
135                 state->name, esize, *ecount);
136 }
137
138 void pipe_hyper_push(
139             char * _state,
140             hyper * buf,
141             unsigned long ecount)
142 {
143         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
144
145         printf("push:%s: ecount[%u]\n",
146                 state->name, ecount);
147 }
148
149 void pipe_hyper_alloc(
150             char * _state,
151             unsigned long bsize,
152             hyper * * buf,
153             unsigned long * bcount)
154 {
155         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
156
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);
163 }
164 struct pipe_structtype_state {
165         const char *name;
166         unsigned long count;
167         unsigned long sleep;
168 };
169
170 RPC_STATUS pipe_structtype_pull(
171             char * _state,
172             structtype * buf,
173             unsigned long esize,
174             unsigned long * ecount)
175 {
176         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
177
178         printf("pull1:%s: esize[%u] ecount[%u]\n",
179                 state->name, esize, *ecount);
180         *ecount = state->count--;
181         if (*ecount > esize) {
182                 *ecount = esize;
183         }
184         memset(buf, 0xDD, *ecount * sizeof(*buf));
185         printf("pull2:%s: esize[%u] ecount[%u]\n",
186                 state->name, esize, *ecount);
187 }
188
189 RPC_STATUS pipe_structtype_push(
190             char * _state,
191             structtype * buf,
192             unsigned long ecount)
193 {
194         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
195
196         printf("push:%s: ecount[%u]\n",
197                 state->name, ecount);
198 }
199
200 RPC_STATUS pipe_structtype_alloc(
201             char * _state,
202             unsigned long bsize,
203             structtype * * buf,
204             unsigned long * bcount)
205 {
206         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
207
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);
214 }
215 static void midltests(void)
216 {
217         RPC_ASYNC_STATE aping;
218         RPC_ASYNC_STATE afn;
219         RPC_STATUS status = 0;
220         long ret;
221         struct msg out1;
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;
227         struct msg in1;
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;
233
234         in1.l = sizeof(in1b);
235         memset(&in1b, 0xAA, sizeof(in1b));
236         in1.m = in1b;
237
238         memset(&outs, 0, sizeof(outs));
239         outs.name = "outp";
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;
245
246         memset(&ins, 0, sizeof(ins));
247         ins.name = "inp";
248         ins.count = 0;
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;
254
255         out1.l = sizeof(out1b);
256         memset(&out1b, 0xFF, sizeof(out1b));
257         out1.m = out1b;
258 #if 0
259         RpcAsyncInitializeHandle(&aping, sizeof(aping));
260         cli_midltests_ping(&aping, in1);
261
262         while (TRUE) {
263                 RPC_STATUS status;
264                 status = RpcAsyncCompleteCall(&aping, &ret);
265                 if (status != RPC_S_ASYNC_CALL_PENDING) {
266                         break;
267                 }
268                 Sleep(100);
269         }
270 #endif
271         ret = 0;
272
273         printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
274         RpcAsyncInitializeHandle(&afn, sizeof(afn));
275         cli_midltests_fn(&afn, &out1, &outp, &inp, in1);
276 #if 0
277         printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
278         Sleep(500);
279         memset(inpb, 0xEE, sizeof(inpb));
280         printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
281         inp.push(inp.state, inpb, sizeof(inpb));
282         Sleep(500);
283 #endif
284         printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
285         inp.push(inp.state, inpb, 0);
286         outb_size = 0;
287         do {
288                 outp.pull(outp.state, outb, sizeof(outb), &outb_len);
289                 Sleep(1000);
290                 printf("HERE:%s:%d:%s() %d\n", __FILE__, __LINE__, __FUNCTION__,
291 outb_len);
292                 outb_size--;
293         } while (outb_len > 0);
294         while (TRUE) {
295         printf("HERE:%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__);
296                 status = RpcAsyncCompleteCall(&afn, &ret);
297                 if (status != RPC_S_ASYNC_CALL_PENDING) {
298                         break;
299                 }
300                 Sleep(2000);
301         }
302         printf("HERE:%s:%d:%s() %\n",
303                 __FILE__, __LINE__, __FUNCTION__,
304                 status, ret);
305 }
306
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)
313 {
314         long ret;
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;
320
321         printf("srv_midltests_fn: Start\n");
322         fflush(stdout);
323
324         do {
325                 inp->pull(inp->state, inb, sizeof(inb), &inb_len);
326                 printf("pull inp_len[%u]\n", inb_len);
327                 fflush(stdout);
328         } while (inb_len > 0);
329
330         outb_size = 0;
331         do {
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);
335                 fflush(stdout);
336                 outp->push(outp->state, outb, outb_len);
337                 //Sleep(1000);
338                 outb_size--;
339         } while (outb_len > 0);
340
341         out1->l = 3;
342         out1->m = (unsigned char *)malloc(out1->l);
343         memset(out1->m, 0xBB, out1->l);
344         printf("srv_midltests_fn: End\n");
345         fflush(stdout);
346         ret = 0x65757254;
347         RpcAsyncCompleteCall(midltests_fn_AsyncHandle, &ret);
348 }
349
350 void srv_midltests_ping(
351         PRPC_ASYNC_STATE midltests_ping_AsyncHandle,
352     /* [in] */ struct msg in1)
353 {
354         long ret;
355         printf("srv_midltests_ping: Start\n");
356         printf("srv_midltests_ping: End\n");
357         ret = 0x65757254;
358         RpcAsyncCompleteCall(midltests_ping_AsyncHandle, &ret);
359 }
360 #endif