summaryrefslogtreecommitdiffstats
path: root/testprogs/win32/midltests/valid/midltests-pipe-sync-ndr32-downgrade-02.idl
blob: 888ba794d4685016c4e93eb354340d8ada4f3769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#ifndef MIDLTESTS_C_CODE

/*
 * For midltests_tcp.exe you may want to
 * redirect the traffic via rinetd
 * with a /etc/rinetd.conf like this:
 *
 * 172.31.9.1 5032 172.31.9.8 5032
 * 172.31.9.1 5064 172.31.9.8 5064
 *
 * This is useful to watch the traffic with
 * a network sniffer.
 */
/*
cpp_quote("#define LISTEN_IP \"0.0.0.0\"")
cpp_quote("#define FORWARD_IP \"127.0.0.1\"")
cpp_quote("#define CONNECT_IP \"172.31.9.1\"")
*/

/*
 * With midltests_tcp.exe NDR64 is enforced by default.
 * For testing it might be needed to allow downgrades
 * to NDR32. This is needed when you use 'pipe'.
 */
cpp_quote("#define DONOT_FORCE_NDR64 1")

[
  uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
  pointer_default(unique)
]
interface midltests
{
	typedef pipe char pipe_char;
	typedef pipe hyper pipe_hyper;
	typedef struct {
		long l;
		short s;
	} structtype;
	typedef pipe structtype pipe_structtype;

	struct msg {
		long l;
		[size_is(l)] char *m;
	};

	long midltests_fn(
		[out,ref] struct msg *out1,
		[out] pipe_structtype outp,
		[in] pipe_structtype inp,
		[in] struct msg in1
	);

	long midltests_ping( [in] struct msg in1);

}

#elif MIDLTESTS_C_CODE

struct pipe_char_state {
	const char *name;
	unsigned long count;
	unsigned long sleep;
};

void pipe_char_pull(
            char * _state,
            unsigned char * buf,
            unsigned long esize,
            unsigned long * ecount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("pull1:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
	*ecount = state->count--;
	if (*ecount > esize) {
		*ecount = esize;
	}
	memset(buf, 0xDD, *ecount * sizeof(*buf));
	printf("pull2:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
}

void pipe_char_push(
            char * _state,
            unsigned char * buf,
            unsigned long ecount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("push:%s: ecount[%u]\n",
		state->name, ecount);
}

void pipe_char_alloc(
            char * _state,
            unsigned long bsize,
            unsigned char * * buf,
            unsigned long * bcount)
{
	struct pipe_char_state *state = (struct pipe_char_state *)_state;

	printf("alloc1:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
	*bcount = bsize / sizeof(**buf);
	*buf = malloc(*bcount * sizeof(**buf));
	printf("alloc2:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
}

struct pipe_hyper_state {
	const char *name;
	unsigned long count;
	unsigned long sleep;
};

void pipe_hyper_pull(
            char * _state,
            hyper * buf,
            unsigned long esize,
            unsigned long * ecount)
{
	struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;

	printf("pull1:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
	*ecount = state->count--;
	if (*ecount > esize) {
		*ecount = esize;
	}
	memset(buf, 0xDD, *ecount * sizeof(*buf));
	printf("pull2:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
}

void pipe_hyper_push(
            char * _state,
            hyper * buf,
            unsigned long ecount)
{
	struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;

	printf("push:%s: ecount[%u]\n",
		state->name, ecount);
}

void pipe_hyper_alloc(
            char * _state,
            unsigned long bsize,
            hyper * * buf,
            unsigned long * bcount)
{
	struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;

	printf("alloc1:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
	*bcount = bsize / sizeof(**buf);
	*buf = malloc(*bcount * sizeof(**buf));
	printf("alloc2:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
}
struct pipe_structtype_state {
	const char *name;
	unsigned long count;
	unsigned long sleep;
};

void pipe_structtype_pull(
            char * _state,
            structtype * buf,
            unsigned long esize,
            unsigned long * ecount)
{
	struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;

	printf("pull1:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
	*ecount = state->count--;
	if (*ecount > esize) {
		*ecount = esize;
	}
	memset(buf, 0xDD, *ecount * sizeof(*buf));
	printf("pull2:%s: esize[%u] ecount[%u]\n",
		state->name, esize, *ecount);
}

void pipe_structtype_push(
            char * _state,
            structtype * buf,
            unsigned long ecount)
{
	struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;

	printf("push:%s: ecount[%u]\n",
		state->name, ecount);
}

void pipe_structtype_alloc(
            char * _state,
            unsigned long bsize,
            structtype * * buf,
            unsigned long * bcount)
{
	struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;

	printf("alloc1:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
	*bcount = bsize / sizeof(**buf);
	*buf = malloc(*bcount * sizeof(**buf));
	printf("alloc2:%s: bsize[%u], bcount[%u]\n",
		state->name, bsize, *bcount);
}
static void midltests(void)
{
	struct msg out1;
	unsigned char out1b[3];
	struct pipe_structtype_state outs;
	pipe_structtype outp;
	struct pipe_structtype_state ins;
	pipe_structtype inp;
	struct msg in1;
	unsigned char in1b[3000];

	in1.l = sizeof(in1b);
	memset(&in1b, 0xAA, sizeof(in1b));
	in1.m = in1b;

	memset(&outs, 0, sizeof(outs));
	outs.name = "outp";
	memset(&outp, 0, sizeof(outp));
	outp.pull = pipe_structtype_pull;
	outp.push = pipe_structtype_push;
	outp.alloc = pipe_structtype_alloc;
	outp.state = (char *)&outs;

	memset(&ins, 0, sizeof(ins));
	ins.name = "inp";
	ins.count = 35;
	memset(&inp, 0, sizeof(inp));
	inp.pull = pipe_structtype_pull;
	inp.push = pipe_structtype_push;
	inp.alloc = pipe_structtype_alloc;
	inp.state = (char *)&ins;

	out1.l = sizeof(out1b);
	memset(&out1b, 0xFF, sizeof(out1b));
	out1.m = out1b;

	cli_midltests_ping(in1);
	cli_midltests_fn(&out1, outp, inp, in1);
}

long srv_midltests_fn(
	    /* [ref][out] */ struct msg *out1,
    /* [out] */ pipe_structtype outp,
    /* [in] */ pipe_structtype inp,
    /* [in] */ struct msg in1)
{
	structtype inb[2500];
	unsigned long inb_len = 0;
	structtype *outb = NULL;
	unsigned long outb_size = 0;
	unsigned long outb_len = 0;

	printf("srv_midltests_fn: Start\n");
	fflush(stdout);

	do {
		inp.pull(inp.state, inb, sizeof(inb), &inb_len);
		printf("pull inp_len[%u]\n", inb_len);
		fflush(stdout);
	} while (inb_len > 0);

	outb_size = 50;
	do {
		outp.alloc(outp.state, outb_size, &outb, &outb_len);
		memset(outb, 0xCC, outb_len * sizeof(*outb));
		printf("push outb_len[%u]\n", outb_len);
		fflush(stdout);
		outp.push(outp.state, outb, outb_len);
		//Sleep(1000);
		outb_size--;
	} while (outb_len > 0);

	out1->l = 3;
	out1->m = (unsigned char *)malloc(out1->l);
	memset(out1->m, 0xBB, out1->l);
	printf("srv_midltests_fn: End\n");
	fflush(stdout);
	return 0x65757254;
}

long srv_midltests_ping(
    /* [in] */ struct msg in1)
{
	printf("srv_midltests_fn: Start\n");
	printf("srv_midltests_fn: End\n");
	return 0x65757254;
}
#endif