source: rtems-libbsd/services/librpc/src/rpc/clnt_raw.c @ 20ec9e6

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 20ec9e6 was 20ec9e6, checked in by Joel Sherrill <joel.sherrill@…>, on 08/03/12 at 19:19:49

librpc: Initial addition

This does not currently compile. There is an include file
issue and int32_t is not defined even though stdint.h is included
before its use.

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