|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <stdio.h> |
|
21 #include <rpc/rpc.h> |
|
22 #ifdef WIN32 |
|
23 #include <rpc/PMAP_CLN.H> |
|
24 #else |
|
25 #include <rpc/pmap_clnt.h> |
|
26 #endif |
|
27 #include "GenericStub.h" |
|
28 |
|
29 static void genericstub_1(); |
|
30 |
|
31 int StartUCCService( int anIID, int aVersion ) |
|
32 { |
|
33 SVCXPRT *transp; |
|
34 |
|
35 #ifdef WIN32 |
|
36 rpc_nt_init(); |
|
37 #endif |
|
38 |
|
39 (void)pmap_unset(anIID, aVersion); |
|
40 |
|
41 transp = svcudp_create(RPC_ANYSOCK); |
|
42 if (transp == NULL) { |
|
43 (void)fprintf(stderr, "cannot create udp service.\n"); |
|
44 #ifdef WIN32 |
|
45 rpc_nt_exit(); |
|
46 #endif |
|
47 exit(1); |
|
48 } |
|
49 if (!svc_register(transp, anIID, aVersion, genericstub_1, IPPROTO_UDP)) { |
|
50 (void)fprintf(stderr, "unable to register (GENERICSTUB, GENERICSTUB_VERSION, udp).\n"); |
|
51 #ifdef WIN32 |
|
52 rpc_nt_exit(); |
|
53 #endif |
|
54 exit(1); |
|
55 } |
|
56 |
|
57 transp = svctcp_create(RPC_ANYSOCK, 0, 0); |
|
58 if (transp == NULL) { |
|
59 (void)fprintf(stderr, "cannot create tcp service.\n"); |
|
60 #ifdef WIN32 |
|
61 rpc_nt_exit(); |
|
62 #endif |
|
63 exit(1); |
|
64 } |
|
65 if (!svc_register(transp, anIID, aVersion, genericstub_1, IPPROTO_TCP)) { |
|
66 (void)fprintf(stderr, "unable to register (GENERICSTUB, GENERICSTUB_VERSION, tcp).\n"); |
|
67 #ifdef WIN32 |
|
68 rpc_nt_exit(); |
|
69 #endif |
|
70 exit(1); |
|
71 } |
|
72 svc_run(); |
|
73 (void)fprintf(stderr, "svc_run returned\n"); |
|
74 #ifdef WIN32 |
|
75 rpc_nt_exit(); |
|
76 #endif |
|
77 exit(1); |
|
78 } |
|
79 |
|
80 #ifdef MULTITHREAD |
|
81 struct call_params { |
|
82 struct svc_req *rqstp; |
|
83 SVCXPRT *transp; |
|
84 void *arg; |
|
85 char *(*local)(); |
|
86 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
87 }; |
|
88 static void genericstub_1_a (); |
|
89 #endif |
|
90 |
|
91 static void |
|
92 genericstub_1(rqstp, transp) |
|
93 struct svc_req *rqstp; |
|
94 SVCXPRT *transp; |
|
95 { |
|
96 union { |
|
97 TStartupInfo ss_startuprpcservice_1_arg; |
|
98 int sc_shutdownrpcservice_1_arg; |
|
99 char *cstr_startprocess_1_arg; |
|
100 int dstr_removeprocess_1_arg; |
|
101 TCall run_command_1_arg; |
|
102 } argument; |
|
103 char *result; |
|
104 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
105 char *(*local)(); |
|
106 |
|
107 |
|
108 #ifdef MULTITHREAD |
|
109 DWORD TID = 0; |
|
110 HANDLE threadHandle = NULL; |
|
111 struct call_params *params; |
|
112 #endif |
|
113 switch (rqstp->rq_proc) { |
|
114 case NULLPROC: |
|
115 (void)svc_sendreply(transp, (void*)xdr_void, (char *)NULL); |
|
116 return; |
|
117 |
|
118 case SS_STARTUPRPCSERVICE: |
|
119 xdr_argument = xdr_GenericStub_TStartupInfo; |
|
120 xdr_result = xdr_int; |
|
121 local = (char *(*)()) ss_startuprpcservice_1; |
|
122 break; |
|
123 |
|
124 case SC_SHUTDOWNRPCSERVICE: |
|
125 xdr_argument = xdr_int; |
|
126 xdr_result = xdr_int; |
|
127 local = (char *(*)()) sc_shutdownrpcservice_1; |
|
128 break; |
|
129 |
|
130 case LIST_CONNECTIONS: |
|
131 xdr_argument = xdr_void; |
|
132 xdr_result = xdr_GenericStub_TComponentList; |
|
133 local = (char *(*)()) list_connections_1; |
|
134 break; |
|
135 |
|
136 case CSTR_STARTPROCESS: |
|
137 xdr_argument = xdr_wrapstring; |
|
138 xdr_result = xdr_int; |
|
139 local = (char *(*)()) cstr_startprocess_1; |
|
140 break; |
|
141 |
|
142 case DSTR_REMOVEPROCESS: |
|
143 xdr_argument = xdr_int; |
|
144 xdr_result = xdr_int; |
|
145 local = (char *(*)()) dstr_removeprocess_1; |
|
146 break; |
|
147 |
|
148 case RUN_COMMAND: |
|
149 xdr_argument = xdr_GenericStub_TCall; |
|
150 xdr_result = xdr_int; |
|
151 local = (char *(*)()) run_command_1; |
|
152 break; |
|
153 |
|
154 default: |
|
155 svcerr_noproc(transp); |
|
156 return; |
|
157 } |
|
158 bzero((char *)&argument, sizeof(argument)); |
|
159 if (!svc_getargs(transp, (void*)xdr_argument, (void*)&argument)) { |
|
160 svcerr_decode(transp); |
|
161 return; |
|
162 } |
|
163 |
|
164 #ifdef MULTITHREAD |
|
165 params = (struct call_params*) malloc (sizeof(struct call_params)); |
|
166 |
|
167 params->rqstp = (struct svc_req*) malloc (sizeof(struct svc_req)); |
|
168 bcopy(rqstp, params->rqstp, sizeof(struct svc_req)); |
|
169 |
|
170 params->transp = transp; |
|
171 |
|
172 params->arg = malloc (sizeof(argument)); |
|
173 bcopy(&argument, params->arg, sizeof(argument)); |
|
174 |
|
175 params->local = local; |
|
176 |
|
177 params->xdr_argument = xdr_argument; |
|
178 params->xdr_result = xdr_result; |
|
179 |
|
180 threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)genericstub_1_a, params, 0, &TID); |
|
181 if (!threadHandle) |
|
182 genericstub_1_a(¶ms); |
|
183 } |
|
184 |
|
185 static void |
|
186 genericstub_1_a(params) |
|
187 struct call_params *params; |
|
188 { |
|
189 struct svc_req *rqstp; |
|
190 SVCXPRT *transp; |
|
191 void *argument; |
|
192 void (*destroy_proc)(); |
|
193 |
|
194 char *result; |
|
195 bool_t (*xdr_argument)(), (*xdr_result)(); |
|
196 char *(*local)(); |
|
197 |
|
198 |
|
199 argument = params->arg; |
|
200 rqstp = params->rqstp; |
|
201 transp = params->transp; |
|
202 xdr_argument = params->xdr_argument; |
|
203 xdr_result = params->xdr_result; |
|
204 local = params->local; |
|
205 destroy_proc = transp->xp_ops->xp_destroy; |
|
206 transp->xp_ops->xp_destroy = xprt_unregister; |
|
207 #endif |
|
208 |
|
209 result = (*local)(&argument, rqstp); |
|
210 if (result != NULL && !svc_sendreply(transp, (void*)xdr_result, result)) { |
|
211 svcerr_systemerr(transp); |
|
212 } |
|
213 #ifdef MULTITHREAD |
|
214 free(params->rqstp); |
|
215 free(params); |
|
216 #endif |
|
217 if (!svc_freeargs(transp, (void*)xdr_argument, (void*)&argument)) { |
|
218 (void)fprintf(stderr, "unable to free arguments\n"); |
|
219 #ifdef WIN32 |
|
220 rpc_nt_exit(); |
|
221 #endif |
|
222 exit(1); |
|
223 } |
|
224 #ifdef MULTITHREAD |
|
225 free(argument); |
|
226 transp->xp_ops->xp_destroy = destroy_proc; |
|
227 #endif |
|
228 } |
|
229 |