]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/clnt_raw.c
Update.
[thirdparty/glibc.git] / sunrpc / clnt_raw.c
CommitLineData
28f540f4
RM
1/* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */
2/*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
cbd3dceb 9 *
28f540f4
RM
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
cbd3dceb 13 *
28f540f4
RM
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
17 *
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
cbd3dceb 21 *
28f540f4
RM
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
cbd3dceb 25 *
28f540f4
RM
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
29 */
30#if !defined(lint) && defined(SCCSIDS)
31static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
32#endif
33
34/*
35 * clnt_raw.c
36 *
37 * Copyright (C) 1984, Sun Microsystems, Inc.
38 *
39 * Memory based rpc for simple testing and timing.
40 * Interface to create an rpc client and server in the same process.
6d52618b
UD
41 * This lets us simulate rpc and get round trip overhead, without
42 * any interference from the kernel.
28f540f4
RM
43 */
44
45#include <rpc/rpc.h>
e7fd8a39
UD
46#include <rpc/svc.h>
47#include <rpc/xdr.h>
48
49extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
28f540f4
RM
50
51#define MCALL_MSG_SIZE 24
52
53/*
54 * This is the "network" we will be moving stuff over.
55 */
e7fd8a39
UD
56static struct clntraw_private
57 {
58 CLIENT client_object;
59 XDR xdr_stream;
60 char _raw_buf[UDPMSGSIZE];
61 char mashl_callmsg[MCALL_MSG_SIZE];
62 u_int mcnt;
63 }
64 *clntraw_private;
65
66static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
67 xdrproc_t, caddr_t, struct timeval);
68static void clntraw_abort (void);
69static void clntraw_geterr (CLIENT *, struct rpc_err *);
70static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
71static bool_t clntraw_control (CLIENT *, int, char *);
72static void clntraw_destroy (CLIENT *);
73
74static struct clnt_ops client_ops =
75{
76 clntraw_call,
77 clntraw_abort,
78 clntraw_geterr,
79 clntraw_freeres,
80 clntraw_destroy,
81 clntraw_control
28f540f4
RM
82};
83
28f540f4
RM
84/*
85 * Create a client handle for memory based rpc.
86 */
87CLIENT *
e7fd8a39 88clntraw_create (u_long prog, u_long vers)
28f540f4 89{
e7fd8a39
UD
90 struct clntraw_private *clp = clntraw_private;
91 struct rpc_msg call_msg;
92 XDR *xdrs = &clp->xdr_stream;
93 CLIENT *client = &clp->client_object;
94
95 if (clp == 0)
96 {
97 clp = (struct clntraw_private *) calloc (1, sizeof (*clp));
98 if (clp == 0)
99 return (0);
100 clntraw_private = clp;
101 }
102 /*
103 * pre-serialize the static part of the call msg and stash it away
104 */
105 call_msg.rm_direction = CALL;
106 call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
107 call_msg.rm_call.cb_prog = prog;
108 call_msg.rm_call.cb_vers = vers;
109 xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
110 if (!xdr_callhdr (xdrs, &call_msg))
111 {
112 perror (_ ("clnt_raw.c - Fatal header serialization error."));
113 }
114 clp->mcnt = XDR_GETPOS (xdrs);
115 XDR_DESTROY (xdrs);
116
117 /*
118 * Set xdrmem for client/server shared buffer
119 */
120 xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
121
122 /*
123 * create client handle
124 */
125 client->cl_ops = &client_ops;
126 client->cl_auth = authnone_create ();
127 return client;
28f540f4
RM
128}
129
cbd3dceb 130static enum clnt_stat
e7fd8a39
UD
131clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
132 CLIENT *h;
133 u_long proc;
134 xdrproc_t xargs;
135 caddr_t argsp;
136 xdrproc_t xresults;
137 caddr_t resultsp;
138 struct timeval timeout;
28f540f4 139{
e7fd8a39
UD
140 struct clntraw_private *clp = clntraw_private;
141 XDR *xdrs = &clp->xdr_stream;
142 struct rpc_msg msg;
143 enum clnt_stat status;
144 struct rpc_err error;
145
146 if (clp == NULL)
147 return RPC_FAILED;
28f540f4 148call_again:
e7fd8a39
UD
149 /*
150 * send request
151 */
152 xdrs->x_op = XDR_ENCODE;
153 XDR_SETPOS (xdrs, 0);
154 ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
155 if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
156 (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
157 (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
158 (!(*xargs) (xdrs, argsp)))
159 {
160 return (RPC_CANTENCODEARGS);
161 }
162 (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
163
164 /*
165 * We have to call server input routine here because this is
166 * all going on in one process. Yuk.
167 */
168 svc_getreq (1);
169
170 /*
171 * get results
172 */
173 xdrs->x_op = XDR_DECODE;
174 XDR_SETPOS (xdrs, 0);
175 msg.acpted_rply.ar_verf = _null_auth;
176 msg.acpted_rply.ar_results.where = resultsp;
177 msg.acpted_rply.ar_results.proc = xresults;
178 if (!xdr_replymsg (xdrs, &msg))
179 return RPC_CANTDECODERES;
180 _seterr_reply (&msg, &error);
181 status = error.re_status;
182
183 if (status == RPC_SUCCESS)
184 {
185 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
186 {
187 status = RPC_AUTHERROR;
28f540f4 188 }
e7fd8a39
UD
189 } /* end successful completion */
190 else
191 {
192 if (AUTH_REFRESH (h->cl_auth))
193 goto call_again;
194 } /* end of unsuccessful completion */
195
196 if (status == RPC_SUCCESS)
197 {
198 if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
199 {
200 status = RPC_AUTHERROR;
201 }
202 if (msg.acpted_rply.ar_verf.oa_base != NULL)
203 {
204 xdrs->x_op = XDR_FREE;
205 (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
28f540f4 206 }
e7fd8a39 207 }
28f540f4 208
e7fd8a39 209 return status;
28f540f4
RM
210}
211
212static void
e7fd8a39 213clntraw_geterr (CLIENT *cl, struct rpc_err *err)
28f540f4
RM
214{
215}
216
217
218static bool_t
e7fd8a39
UD
219clntraw_freeres (cl, xdr_res, res_ptr)
220 CLIENT *cl;
221 xdrproc_t xdr_res;
222 caddr_t res_ptr;
28f540f4 223{
e7fd8a39
UD
224 struct clntraw_private *clp = clntraw_private;
225 XDR *xdrs = &clp->xdr_stream;
226 bool_t rval;
227
228 if (clp == NULL)
229 {
230 rval = (bool_t) RPC_FAILED;
231 return rval;
232 }
233 xdrs->x_op = XDR_FREE;
234 return (*xdr_res) (xdrs, res_ptr);
28f540f4
RM
235}
236
237static void
e7fd8a39 238clntraw_abort (void)
28f540f4
RM
239{
240}
241
242static bool_t
e7fd8a39 243clntraw_control (CLIENT *cl, int i, char *c)
28f540f4 244{
e7fd8a39 245 return FALSE;
28f540f4
RM
246}
247
248static void
e7fd8a39 249clntraw_destroy (CLIENT *cl)
28f540f4
RM
250{
251}