760401e412f9d8a54f57b13c32aab6e4e8584ba9
[ira/wip.git] / testprogs / win32 / midltests / todo / midltests-pipe-sync-ndr32-downgrade-02.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 /*
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'.
24  */
25 cpp_quote("#define DONOT_FORCE_NDR64 1")
26
27 [
28   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
29   pointer_default(unique)
30 ]
31 interface midltests
32 {
33         typedef pipe char pipe_char;
34         typedef pipe hyper pipe_hyper;
35         typedef struct {
36                 long l;
37                 short s;
38         } structtype;
39         typedef pipe structtype pipe_structtype;
40
41         struct msg {
42                 long l;
43                 [size_is(l)] char *m;
44         };
45
46         long midltests_fn(
47                 [out,ref] struct msg *out1,
48                 [out] pipe_structtype outp,
49                 [in] pipe_structtype inp,
50                 [in] struct msg in1
51         );
52
53         long midltests_ping( [in] struct msg in1);
54
55 }
56
57 #elif MIDLTESTS_C_CODE
58
59 struct pipe_char_state {
60         const char *name;
61         unsigned long count;
62         unsigned long sleep;
63 };
64
65 void pipe_char_pull(
66             char * _state,
67             unsigned char * buf,
68             unsigned long esize,
69             unsigned long * ecount)
70 {
71         struct pipe_char_state *state = (struct pipe_char_state *)_state;
72
73         printf("pull1:%s: esize[%u] ecount[%u]\n",
74                 state->name, esize, *ecount);
75         *ecount = state->count--;
76         if (*ecount > esize) {
77                 *ecount = esize;
78         }
79         memset(buf, 0xDD, *ecount * sizeof(*buf));
80         printf("pull2:%s: esize[%u] ecount[%u]\n",
81                 state->name, esize, *ecount);
82 }
83
84 void pipe_char_push(
85             char * _state,
86             unsigned char * buf,
87             unsigned long ecount)
88 {
89         struct pipe_char_state *state = (struct pipe_char_state *)_state;
90
91         printf("push:%s: ecount[%u]\n",
92                 state->name, ecount);
93 }
94
95 void pipe_char_alloc(
96             char * _state,
97             unsigned long bsize,
98             unsigned char * * buf,
99             unsigned long * bcount)
100 {
101         struct pipe_char_state *state = (struct pipe_char_state *)_state;
102
103         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
104                 state->name, bsize, *bcount);
105         *bcount = bsize / sizeof(**buf);
106         *buf = malloc(*bcount * sizeof(**buf));
107         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
108                 state->name, bsize, *bcount);
109 }
110
111 struct pipe_hyper_state {
112         const char *name;
113         unsigned long count;
114         unsigned long sleep;
115 };
116
117 void pipe_hyper_pull(
118             char * _state,
119             hyper * buf,
120             unsigned long esize,
121             unsigned long * ecount)
122 {
123         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
124
125         printf("pull1:%s: esize[%u] ecount[%u]\n",
126                 state->name, esize, *ecount);
127         *ecount = state->count--;
128         if (*ecount > esize) {
129                 *ecount = esize;
130         }
131         memset(buf, 0xDD, *ecount * sizeof(*buf));
132         printf("pull2:%s: esize[%u] ecount[%u]\n",
133                 state->name, esize, *ecount);
134 }
135
136 void pipe_hyper_push(
137             char * _state,
138             hyper * buf,
139             unsigned long ecount)
140 {
141         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
142
143         printf("push:%s: ecount[%u]\n",
144                 state->name, ecount);
145 }
146
147 void pipe_hyper_alloc(
148             char * _state,
149             unsigned long bsize,
150             hyper * * buf,
151             unsigned long * bcount)
152 {
153         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
154
155         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
156                 state->name, bsize, *bcount);
157         *bcount = bsize / sizeof(**buf);
158         *buf = malloc(*bcount * sizeof(**buf));
159         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
160                 state->name, bsize, *bcount);
161 }
162 struct pipe_structtype_state {
163         const char *name;
164         unsigned long count;
165         unsigned long sleep;
166 };
167
168 void pipe_structtype_pull(
169             char * _state,
170             structtype * buf,
171             unsigned long esize,
172             unsigned long * ecount)
173 {
174         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
175
176         printf("pull1:%s: esize[%u] ecount[%u]\n",
177                 state->name, esize, *ecount);
178         *ecount = state->count--;
179         if (*ecount > esize) {
180                 *ecount = esize;
181         }
182         memset(buf, 0xDD, *ecount * sizeof(*buf));
183         printf("pull2:%s: esize[%u] ecount[%u]\n",
184                 state->name, esize, *ecount);
185 }
186
187 void pipe_structtype_push(
188             char * _state,
189             structtype * buf,
190             unsigned long ecount)
191 {
192         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
193
194         printf("push:%s: ecount[%u]\n",
195                 state->name, ecount);
196 }
197
198 void pipe_structtype_alloc(
199             char * _state,
200             unsigned long bsize,
201             structtype * * buf,
202             unsigned long * bcount)
203 {
204         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
205
206         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
207                 state->name, bsize, *bcount);
208         *bcount = bsize / sizeof(**buf);
209         *buf = malloc(*bcount * sizeof(**buf));
210         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
211                 state->name, bsize, *bcount);
212 }
213 static void midltests(void)
214 {
215         struct msg out1;
216         unsigned char out1b[3];
217         struct pipe_structtype_state outs;
218         pipe_structtype outp;
219         struct pipe_structtype_state ins;
220         pipe_structtype inp;
221         struct msg in1;
222         unsigned char in1b[5000];
223
224         in1.l = sizeof(in1b);
225         memset(&in1b, 0xAA, sizeof(in1b));
226         in1.m = in1b;
227
228         memset(&outs, 0, sizeof(outs));
229         outs.name = "outp";
230         memset(&outp, 0, sizeof(outp));
231         outp.pull = pipe_structtype_pull;
232         outp.push = pipe_structtype_push;
233         outp.alloc = pipe_structtype_alloc;
234         outp.state = (char *)&outs;
235
236         memset(&ins, 0, sizeof(ins));
237         ins.name = "inp";
238         ins.count = 100;
239         memset(&inp, 0, sizeof(inp));
240         inp.pull = pipe_structtype_pull;
241         inp.push = pipe_structtype_push;
242         inp.alloc = pipe_structtype_alloc;
243         inp.state = (char *)&ins;
244
245         out1.l = sizeof(out1b);
246         memset(&out1b, 0xFF, sizeof(out1b));
247         out1.m = out1b;
248
249         cli_midltests_ping(in1);
250         cli_midltests_fn(&out1, outp, inp, in1);
251 }
252
253 long srv_midltests_fn(
254             /* [ref][out] */ struct msg *out1,
255     /* [out] */ pipe_structtype outp,
256     /* [in] */ pipe_structtype inp,
257     /* [in] */ struct msg in1)
258 {
259         structtype inb[500];
260         unsigned long inb_len = 0;
261         structtype *outb = NULL;
262         unsigned long outb_size = 0;
263         unsigned long outb_len = 0;
264
265         printf("srv_midltests_fn: Start\n");
266
267         do {
268                 inp.pull(inp.state, inb, sizeof(inb), &inb_len);
269                 printf("pull inp_len[%u]\n", inb_len);
270         } while (inb_len > 0);
271
272         outb_size = 5;
273         do {
274                 outp.alloc(outp.state, outb_size, &outb, &outb_len);
275                 memset(outb, 0xCC, outb_len * sizeof(*outb));
276                 outp.push(outp.state, outb, outb_len);
277                 printf("push outb_len[%u]\n", outb_len);
278                 //Sleep(1000);
279                 outb_size--;
280         } while (outb_len > 0);
281
282         out1->l = 3;
283         out1->m = (unsigned char *)malloc(out1->l);
284         memset(out1->m, 0xBB, out1->l);
285         printf("srv_midltests_fn: End\n");
286         return 0x65757254;
287 }
288
289 long srv_midltests_ping(
290     /* [in] */ struct msg in1)
291 {
292         printf("srv_midltests_fn: Start\n");
293         printf("srv_midltests_fn: End\n");
294         return 0x65757254;
295 }
296 #endif