ReactOS 0.4.15-dev-8116-gf69e256
clnt_raw.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * clnt_raw.c
31 *
32 * Copyright (C) 1984, Sun Microsystems, Inc.
33 *
34 * Memory based rpc for simple testing and timing.
35 * Interface to create an rpc client and server in the same process.
36 * This lets us similate rpc and get round trip overhead, without
37 * any interference from the kernel.
38 */
39#include <wintirpc.h>
40//#include <pthread.h>
41#include <reentrant.h>
42#include <assert.h>
43//#include <err.h>
44#include <stdio.h>
45#include <stdlib.h>
46
47#include <rpc/rpc.h>
48#include <rpc/raw.h>
49
51
52#define MCALL_MSG_SIZE 24
53
54/*
55 * This is the "network" we will be moving stuff over.
56 */
57static struct clntraw_private {
60 char *_raw_buf;
61 union {
64 } u;
67
68static enum clnt_stat clnt_raw_call(CLIENT *, rpcproc_t, xdrproc_t, void *,
69 xdrproc_t, void *, struct timeval);
70static void clnt_raw_geterr(CLIENT *, struct rpc_err *);
71static bool_t clnt_raw_freeres(CLIENT *, xdrproc_t, void *);
72static void clnt_raw_abort(CLIENT *);
73static bool_t clnt_raw_control(CLIENT *, u_int, void *);
74static void clnt_raw_destroy(CLIENT *);
75static struct clnt_ops *clnt_raw_ops(void);
76
77/*
78 * Create a client handle for memory based rpc.
79 */
80CLIENT *
83 rpcvers_t vers;
84{
85 struct clntraw_private *clp;
86 struct rpc_msg call_msg;
87 XDR *xdrs;
89
91 clp = clntraw_private;
92 if (clp == NULL) {
93 clp = (struct clntraw_private *)calloc(1, sizeof (*clp));
94 if (clp == NULL) {
96 return NULL;
97 }
98 if (__rpc_rawcombuf == NULL)
100 (char *)calloc(UDPMSGSIZE, sizeof (char));
102 clntraw_private = clp;
103 }
104 xdrs = &clp->xdr_stream;
105 client = &clp->client_object;
106 /*
107 * pre-serialize the static part of the call msg and stash it away
108 */
109 call_msg.rm_direction = CALL;
110 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
111 /* XXX: prog and vers have been long historically :-( */
112 call_msg.rm_call.cb_prog = (u_int32_t)prog;
113 call_msg.rm_call.cb_vers = (u_int32_t)vers;
115 if (! xdr_callhdr(xdrs, &call_msg))
116 //warnx("clntraw_create - Fatal header serialization error.");
117 clp->mcnt = XDR_GETPOS(xdrs);
118 XDR_DESTROY(xdrs);
119
120 /*
121 * Set xdrmem for client/server shared buffer
122 */
124
125 /*
126 * create client handle
127 */
128 client->cl_ops = clnt_raw_ops();
129 client->cl_auth = authnone_create();
131 return (client);
132}
133
134/* ARGSUSED */
135static enum clnt_stat
136clnt_raw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
137 CLIENT *h;
139 xdrproc_t xargs;
140 void *argsp;
141 xdrproc_t xresults;
142 void *resultsp;
143 struct timeval timeout;
144{
145 struct clntraw_private *clp = clntraw_private;
146 XDR *xdrs = &clp->xdr_stream;
147 struct rpc_msg msg;
148 enum clnt_stat status;
149 struct rpc_err error;
150
151 assert(h != NULL);
152
154 if (clp == NULL) {
156 return (RPC_FAILED);
157 }
159
160call_again:
161 /*
162 * send request
163 */
164 xdrs->x_op = XDR_ENCODE;
165 XDR_SETPOS(xdrs, 0);
166 clp->u.mashl_rpcmsg.rm_xid ++ ;
167 if ((! XDR_PUTBYTES(xdrs, clp->u.mashl_callmsg, clp->mcnt)) ||
168 (! XDR_PUTINT32(xdrs, (int32_t *)&proc)) ||
169 (! AUTH_MARSHALL(h->cl_auth, xdrs, NULL)) ||
170 (! (*xargs)(xdrs, argsp))) {
171 return (RPC_CANTENCODEARGS);
172 }
173 (void)XDR_GETPOS(xdrs); /* called just to cause overhead */
174
175 /*
176 * We have to call server input routine here because this is
177 * all going on in one process. Yuk.
178 */
180
181 /*
182 * get results
183 */
184 xdrs->x_op = XDR_DECODE;
185 XDR_SETPOS(xdrs, 0);
186 msg.acpted_rply.ar_verf = _null_auth;
187 msg.acpted_rply.ar_results.where = resultsp;
188 msg.acpted_rply.ar_results.proc = xresults;
189 if (! xdr_replymsg(xdrs, &msg)) {
190 /*
191 * It's possible for xdr_replymsg() to fail partway
192 * through its attempt to decode the result from the
193 * server. If this happens, it will leave the reply
194 * structure partially populated with dynamically
195 * allocated memory. (This can happen if someone uses
196 * clntudp_bufcreate() to create a CLIENT handle and
197 * specifies a receive buffer size that is too small.)
198 * This memory must be free()ed to avoid a leak.
199 */
200 int op = xdrs->x_op;
201 xdrs->x_op = XDR_FREE;
202 xdr_replymsg(xdrs, &msg);
203 xdrs->x_op = op;
204 return (RPC_CANTDECODERES);
205 }
207 status = error.re_status;
208
209 if (status == RPC_SUCCESS) {
210 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf, 0)) {
212 }
213 } /* end successful completion */
214 else {
215 if (AUTH_REFRESH(h->cl_auth, &msg))
216 goto call_again;
217 } /* end of unsuccessful completion */
218
219 if (status == RPC_SUCCESS) {
220 if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf, 0)) {
222 }
223 if (msg.acpted_rply.ar_verf.oa_base != NULL) {
224 xdrs->x_op = XDR_FREE;
225 (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
226 }
227 }
228
229 return (status);
230}
231
232/*ARGSUSED*/
233static void
235 CLIENT *cl;
236 struct rpc_err *err;
237{
238}
239
240
241/* ARGSUSED */
242static bool_t
243clnt_raw_freeres(cl, xdr_res, res_ptr)
244 CLIENT *cl;
245 xdrproc_t xdr_res;
246 void *res_ptr;
247{
248 struct clntraw_private *clp = clntraw_private;
249 XDR *xdrs = &clp->xdr_stream;
250 bool_t rval;
251
253 if (clp == NULL) {
256 return (rval);
257 }
259 xdrs->x_op = XDR_FREE;
260 return ((*xdr_res)(xdrs, res_ptr));
261}
262
263/*ARGSUSED*/
264static void
266 CLIENT *cl;
267{
268}
269
270/*ARGSUSED*/
271static bool_t
273 CLIENT *cl;
274 u_int ui;
275 void *str;
276{
277 return (FALSE);
278}
279
280/*ARGSUSED*/
281static void
283 CLIENT *cl;
284{
285}
286
287static struct clnt_ops *
289{
290 static struct clnt_ops ops;
291 extern mutex_t ops_lock;
292
293 /* VARIABLES PROTECTED BY ops_lock: ops */
294
296 if (ops.cl_call == NULL) {
297 ops.cl_call = clnt_raw_call;
298 ops.cl_abort = clnt_raw_abort;
299 ops.cl_geterr = clnt_raw_geterr;
300 ops.cl_freeres = clnt_raw_freeres;
301 ops.cl_destroy = clnt_raw_destroy;
302 ops.cl_control = clnt_raw_control;
303 }
305 return (&ops);
306}
bool_t xdr_opaque_auth()
AUTH * authnone_create()
Definition: auth_none.c:100
#define msg(x)
Definition: auth_time.c:54
static bool_t clnt_raw_freeres(CLIENT *, xdrproc_t, void *)
Definition: clnt_raw.c:243
static void clnt_raw_abort(CLIENT *)
Definition: clnt_raw.c:265
static enum clnt_stat clnt_raw_call(CLIENT *, rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval)
Definition: clnt_raw.c:136
static bool_t clnt_raw_control(CLIENT *, u_int, void *)
Definition: clnt_raw.c:272
static void clnt_raw_geterr(CLIENT *, struct rpc_err *)
Definition: clnt_raw.c:234
CLIENT * clnt_raw_create(rpcprog_t prog, rpcvers_t vers)
Definition: clnt_raw.c:81
static struct clnt_ops * clnt_raw_ops(void)
Definition: clnt_raw.c:288
static void clnt_raw_destroy(CLIENT *)
Definition: clnt_raw.c:282
#define MCALL_MSG_SIZE
Definition: clnt_raw.c:52
mutex_t clntraw_lock
Definition: mt_misc.c:53
clnt_stat
Definition: clnt_stat.h:21
@ RPC_SUCCESS
Definition: clnt_stat.h:22
@ RPC_CANTDECODERES
Definition: clnt_stat.h:27
@ RPC_AUTHERROR
Definition: clnt_stat.h:38
@ RPC_FAILED
Definition: clnt_stat.h:68
@ RPC_CANTENCODEARGS
Definition: clnt_stat.h:26
float rval
Definition: cylfrac.c:48
#define AUTH_MARSHALL(auth, xdrs, seq)
Definition: auth.h:242
#define AUTH_VALIDATE(auth, verfp, seq)
Definition: auth.h:247
#define AUTH_REFRESH(auth, msg)
Definition: auth.h:252
UINT32 u_int
Definition: types.h:82
#define NULL
Definition: types.h:112
u_int32_t rpcprog_t
Definition: types.h:104
int32_t bool_t
Definition: types.h:101
#define FALSE
Definition: types.h:117
INT32 int32_t
Definition: types.h:71
u_int32_t rpcvers_t
Definition: types.h:105
u_int32_t rpcproc_t
Definition: types.h:106
UINT op
Definition: effect.c:236
#define assert(x)
Definition: debug.h:53
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
char * prog
Definition: isohybrid.c:47
#define error(str)
Definition: mkdosfs.c:1605
mutex_t ops_lock
Definition: mt_misc.c:71
UINT ui
Definition: oleauto.h:49
static HANDLE proc()
Definition: pdb.c:34
#define err(...)
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
unsigned int u_int32_t
Definition: rosdhcp.h:35
#define calloc
Definition: rosglue.h:14
struct opaque_auth _null_auth
#define RPC_MSG_VERSION
Definition: rpc_msg.h:66
@ CALL
Definition: rpc_msg.h:78
bool_t xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg)
Definition: rpc_prot.c:257
bool_t xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
Definition: rpc_prot.c:188
void _seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
Definition: rpc_prot.c:348
const WCHAR * str
static FILE * client
Definition: client.c:41
Definition: xdr.h:103
enum xdr_op x_op
Definition: xdr.h:104
CLIENT client_object
Definition: clnt_raw.c:58
char mashl_callmsg[MCALL_MSG_SIZE]
Definition: clnt_raw.c:63
struct rpc_msg mashl_rpcmsg
Definition: clnt_raw.c:62
union clntraw_private::@192 u
char * _raw_buf
Definition: clnt_raw.c:60
Definition: module.h:456
Definition: clnt.h:95
enum msg_type rm_direction
Definition: rpc_msg.h:174
Definition: ps.c:97
Definition: dhcpd.h:245
void svc_getreq_common(SOCKET fd)
Definition: svc.c:641
char * __rpc_rawcombuf
Definition: svc_raw.c:73
#define UDPMSGSIZE
Definition: svc_raw.c:49
#define FD_SETSIZE
Definition: winsock.h:50
#define XDR_PUTINT32(xdrs, int32p)
Definition: xdr.h:187
@ XDR_DECODE
Definition: xdr.h:86
@ XDR_FREE
Definition: xdr.h:87
@ XDR_ENCODE
Definition: xdr.h:85
#define XDR_PUTBYTES(xdrs, addr, len)
Definition: xdr.h:194
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94