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