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