source: rtems/cpukit/librpc/src/rpc/clnt_raw.c @ 5220ae2

4.104.114.84.9
Last change on this file since 5220ae2 was 5220ae2, checked in by Ralf Corsepius <ralf.corsepius@…>, on Nov 21, 2004 at 5:33:00 AM

2004-11-21 Ralf Corsepius <ralf.corsepius@…>

  • librpc/include/rpc/types.h: Include <rtems/stdint.h>.
  • librpc/src/rpc/clnt_raw.c, librpc/src/rpc/rpcdname.c, librpc/src/rpc/rtems_portmapper.c, librpc/src/rpc/svc.c, librpc/src/rpc/svc_simple.c: Misc. cast-related fixes. Convert to ANSI.
  • Property mode set to 100644
File size: 5.8 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 kernal.
45 */
46
47#include <rpc/rpc.h>
48#include <stdlib.h>
49#include <stdio.h>
50
51#define MCALL_MSG_SIZE 24
52
53/*
54 * This is the "network" we will be moving stuff over.
55 */
56struct clnt_raw_private {
57        CLIENT  client_object;
58        XDR     xdr_stream;
59        char    _raw_buf[UDPMSGSIZE];
60        char    mashl_callmsg[MCALL_MSG_SIZE];
61        u_int   mcnt;
62};
63#define clntraw_private (rtems_rpc_task_variables->clnt_raw_private)
64
65static enum clnt_stat   clntraw_call();
66static void             clntraw_abort();
67static void             clntraw_geterr();
68static bool_t           clntraw_freeres();
69static bool_t           clntraw_control();
70static void             clntraw_destroy();
71
72static struct clnt_ops client_ops = {
73        clntraw_call,
74        clntraw_abort,
75        clntraw_geterr,
76        clntraw_freeres,
77        clntraw_destroy,
78        clntraw_control
79};
80
81void    svc_getreq();
82
83/*
84 * Create a client handle for memory based rpc.
85 */
86CLIENT *
87clntraw_create(
88        u_long prog,
89        u_long vers )
90{
91        register struct clnt_raw_private *clp = clntraw_private;
92        struct rpc_msg call_msg;
93        XDR *xdrs = &clp->xdr_stream;
94        CLIENT  *client = &clp->client_object;
95
96        if (clp == 0) {
97                clp = (struct clnt_raw_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                perror("clnt_raw.c - Fatal header serialization error.");
112        }
113        clp->mcnt = XDR_GETPOS(xdrs);
114        XDR_DESTROY(xdrs);
115
116        /*
117         * Set xdrmem for client/server shared buffer
118         */
119        xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
120
121        /*
122         * create client handle
123         */
124        client->cl_ops = &client_ops;
125        client->cl_auth = authnone_create();
126        return (client);
127}
128
129static enum clnt_stat
130clntraw_call(
131        CLIENT *h,
132        u_long proc,
133        xdrproc_t xargs,
134        caddr_t argsp,
135        xdrproc_t xresults,
136        caddr_t resultsp,
137        struct timeval timeout )
138{
139        register struct clnt_raw_private *clp = clntraw_private;
140        register XDR *xdrs = &clp->xdr_stream;
141        struct rpc_msg msg;
142        enum clnt_stat status;
143        struct rpc_err error;
144
145        if (clp == 0)
146                return (RPC_FAILED);
147call_again:
148        /*
149         * send request
150         */
151        xdrs->x_op = XDR_ENCODE;
152        XDR_SETPOS(xdrs, 0);
153        ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
154        if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
155            (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
156            (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
157            (! (*xargs)(xdrs, argsp))) {
158                return (RPC_CANTENCODEARGS);
159        }
160        (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
161
162        /*
163         * We have to call server input routine here because this is
164         * all going on in one process. Yuk.
165         */
166        svc_getreq(1);
167
168        /*
169         * get results
170         */
171        xdrs->x_op = XDR_DECODE;
172        XDR_SETPOS(xdrs, 0);
173        msg.acpted_rply.ar_verf = _null_auth;
174        msg.acpted_rply.ar_results.where = resultsp;
175        msg.acpted_rply.ar_results.proc = xresults;
176        if (! xdr_replymsg(xdrs, &msg))
177                return (RPC_CANTDECODERES);
178        _seterr_reply(&msg, &error);
179        status = error.re_status;
180
181        if (status == RPC_SUCCESS) {
182                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
183                        status = RPC_AUTHERROR;
184                }
185        }  /* end successful completion */
186        else {
187                if (AUTH_REFRESH(h->cl_auth))
188                        goto call_again;
189        }  /* end of unsuccessful completion */
190
191        if (status == RPC_SUCCESS) {
192                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
193                        status = RPC_AUTHERROR;
194                }
195                if (msg.acpted_rply.ar_verf.oa_base != NULL) {
196                        xdrs->x_op = XDR_FREE;
197                        (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
198                }
199        }
200
201        return (status);
202}
203
204static void
205clntraw_geterr()
206{
207}
208
209
210static bool_t
211clntraw_freeres(
212        CLIENT *cl,
213        xdrproc_t xdr_res,
214        caddr_t res_ptr )
215{
216        register struct clnt_raw_private *clp = clntraw_private;
217        register XDR *xdrs = &clp->xdr_stream;
218        bool_t rval;
219
220        if (clp == 0)
221        {
222                rval = (bool_t) RPC_FAILED;
223                return (rval);
224        }
225        xdrs->x_op = XDR_FREE;
226        return ((*xdr_res)(xdrs, res_ptr));
227}
228
229static void
230clntraw_abort()
231{
232}
233
234static bool_t
235clntraw_control()
236{
237        return (FALSE);
238}
239
240static void
241clntraw_destroy()
242{
243}
Note: See TracBrowser for help on using the repository browser.