r6019: Add IDL and server side code for Test_DoublePointer
[kai/samba.git] / testprogs / win32 / rpcecho / server.c
1 /* 
2    RPC echo server.
3
4    Copyright (C) Tim Potter 2003
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #define _WIN32_WINNT 0x0500
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <ctype.h>
26 #include "rpcecho.h"
27
28 #define RPC_MIN_CALLS 1
29 #define RPC_MAX_CALLS 20
30 #define RPC_ENDPOINT "\\pipe\\rpcecho"
31
32 void AddOne(int in_data, __RPC_FAR int *out_data)
33 {
34         printf("AddOne: got in_data = %d\n", in_data);
35         *out_data = in_data + 1;
36 }
37
38 void EchoData(int len, unsigned char __RPC_FAR in_data[],
39         unsigned char __RPC_FAR out_data[])
40 {
41         printf("EchoData: got len = %d\n", len);
42         
43         memcpy(out_data, in_data, len);
44 }
45
46 void SinkData(int len, unsigned char __RPC_FAR in_data[  ])
47 {
48         printf("SinkData: got len = %d\n", len);
49 }
50
51 void SourceData(int len, unsigned char __RPC_FAR out_data[  ])
52 {
53         int i;
54
55         printf("SourceData: got len = %d\n", len);
56
57         for (i = 0; i < len; i++)
58                 out_data[i] = i & 0xff;
59 }
60
61 void TestCall(wchar_t **s1, wchar_t **s2)
62 {
63         if (*s1) {
64                 printf("s1='%S'\n", *s1);
65         } else {
66                 printf("s1=NULL\n");
67         }
68         *s2 = L"test string";
69 }
70
71 long TestCall2(short level, echo_Info **info)
72 {
73         static echo_Info i;
74
75         printf("TestCall2 level %d\n", level);
76
77         *info = &i;
78
79         switch (level) {
80         case 1:
81                 i.info1.v = 10;
82                 break;
83         case 2:
84                 i.info2.v = 20;
85                 break;
86         case 3:
87                 i.info3.v = 30;
88                 break;
89         case 4:
90                 i.info4.v = 40;
91                 break;
92         case 5:
93                 i.info5.v1 = 50;
94                 i.info5.v2 = 51;
95                 break;
96         case 6:
97                 i.info6.v1 = 60;
98                 i.info6.info1.v = 61;
99                 break;
100         case 7:
101                 i.info7.v1 = 70;
102                 i.info7.info4.v = 71;
103                 break;
104         default:
105                 return -1;
106         }
107         return 0;
108 }
109
110 #if 0
111 void TestSleep(PRPC_ASYNC_STATE pAsync, long seconds)
112 {
113         long ret;
114         printf("async Sleeping for %d seconds\n", seconds);
115         Sleep(1000 * seconds);
116         ret = seconds;
117         RpcAsyncCompleteCall(pAsync, &ret);
118 }
119 #else
120 long TestSleep(long seconds)
121 {
122         printf("non-async Sleeping for %d seconds\n", seconds);
123         Sleep(1000 * seconds);
124         return seconds;
125 }
126 #endif
127
128
129 void echo_TestEnum(echo_Enum1 *foo1,
130                    echo_Enum2 *foo2,
131                    echo_Enum3 *foo3)
132 {
133         foo2->e1 = ECHO_ENUM2;
134 }
135
136 void echo_TestSurrounding(echo_Surrounding *data)
137 {
138         printf("Incoming array of size %d\n", data->x);
139         data->x *= 2;
140 }
141
142 short echo_TestDoublePointer(short ***data)
143 {
144         if (!*data) {
145                 return 0;
146         }
147         if (!**data) {
148                 return 0;
149         }
150         printf("Incoming double pointer: %d\n", ***data);
151         return ***data;
152 }
153
154 void main(int argc, char **argv)
155 {
156         RPC_STATUS status;
157         RPC_BINDING_VECTOR *pBindingVector;
158
159         if (argc != 1) {
160                 printf("Usage: rpcechosrv\n");
161                 exit(0);
162         }
163
164         status = RpcServerUseProtseqEp("ncacn_np", RPC_MAX_CALLS, "\\pipe\\rpcecho", NULL);
165         if (status) {
166                 printf("Failed to register ncacn_np endpoint\n");
167                 exit(status);
168         }
169
170         status = RpcServerUseProtseqEp("ncacn_ip_tcp", RPC_MAX_CALLS, "1234", NULL);
171         if (status) {
172                 printf("Failed to register ncacn_ip_tcp endpoint\n");
173                 exit(status);
174         }
175
176         status = RpcServerInqBindings(&pBindingVector);
177         if (status) {
178                 printf("Failed RpcServerInqBindings\n");
179                 exit(status);
180         }
181
182         status = RpcEpRegister(rpcecho_v1_0_s_ifspec, pBindingVector, NULL, "rpcecho server");
183         if (status) {
184                 printf("Failed RpcEpRegister\n");
185                 exit(status);
186         }
187
188         status = RpcServerRegisterIf(rpcecho_v1_0_s_ifspec, NULL, NULL);
189
190         if (status) {
191                 printf("Failed to register interface\n");
192                 exit(status);
193         }
194
195         status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
196         if (status) {
197                 printf("Failed to setup auth info\n");
198         }
199                 
200         status = RpcServerListen(RPC_MIN_CALLS, RPC_MAX_CALLS, FALSE);
201
202         if (status) {
203                 printf("RpcServerListen returned error %d\n", status);
204                 exit(status);
205         }
206 }
207