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