(client_ops): Mark as const.
[platform/upstream/glibc.git] / sunrpc / clnt_raw.c
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.
9  *
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.
13  *
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.
21  *
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.
25  *
26  * Sun Microsystems, Inc.
27  * 2550 Garcia Avenue
28  * Mountain View, California  94043
29  */
30 #if !defined(lint) && defined(SCCSIDS)
31 static 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.
41  * This lets us simulate rpc and get round trip overhead, without
42  * any interference from the kernel.
43  */
44
45 #include <rpc/rpc.h>
46 #include <rpc/svc.h>
47 #include <rpc/xdr.h>
48 #include <libintl.h>
49
50 #define MCALL_MSG_SIZE 24
51
52 /*
53  * This is the "network" we will be moving stuff over.
54  */
55 struct clntraw_private_s
56   {
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 #ifdef _RPC_THREAD_SAFE_
64 #define clntraw_private RPC_THREAD_VARIABLE(clntraw_private_s)
65 #else
66 static struct clntraw_private_s *clntraw_private;
67 #endif
68
69 static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
70                                     xdrproc_t, caddr_t, struct timeval);
71 static void clntraw_abort (void);
72 static void clntraw_geterr (CLIENT *, struct rpc_err *);
73 static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
74 static bool_t clntraw_control (CLIENT *, int, char *);
75 static void clntraw_destroy (CLIENT *);
76
77 static const struct clnt_ops client_ops =
78 {
79   clntraw_call,
80   clntraw_abort,
81   clntraw_geterr,
82   clntraw_freeres,
83   clntraw_destroy,
84   clntraw_control
85 };
86
87 /*
88  * Create a client handle for memory based rpc.
89  */
90 CLIENT *
91 clntraw_create (u_long prog, u_long vers)
92 {
93   struct clntraw_private_s *clp = clntraw_private;
94   struct rpc_msg call_msg;
95   XDR *xdrs;
96   CLIENT *client;
97
98   if (clp == 0)
99     {
100       clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
101       if (clp == 0)
102         return (0);
103       clntraw_private = clp;
104     }
105   xdrs = &clp->xdr_stream;
106   client = &clp->client_object;
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   INTUSE(xdrmem_create) (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
115   if (!INTUSE(xdr_callhdr) (xdrs, &call_msg))
116     {
117       perror (_ ("clnt_raw.c - Fatal header serialization error."));
118     }
119   clp->mcnt = XDR_GETPOS (xdrs);
120   XDR_DESTROY (xdrs);
121
122   /*
123    * Set xdrmem for client/server shared buffer
124    */
125   INTUSE(xdrmem_create) (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
126
127   /*
128    * create client handle
129    */
130   client->cl_ops = (struct clnt_ops *) &client_ops;
131   client->cl_auth = INTUSE(authnone_create) ();
132   return client;
133 }
134
135 static enum clnt_stat
136 clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
137      CLIENT *h;
138      u_long proc;
139      xdrproc_t xargs;
140      caddr_t argsp;
141      xdrproc_t xresults;
142      caddr_t resultsp;
143      struct timeval timeout;
144 {
145   struct clntraw_private_s *clp = clntraw_private;
146   XDR *xdrs = &clp->xdr_stream;
147   struct rpc_msg msg;
148   enum clnt_stat status;
149   struct rpc_err error;
150
151   if (clp == NULL)
152     return RPC_FAILED;
153 call_again:
154   /*
155    * send request
156    */
157   xdrs->x_op = XDR_ENCODE;
158   XDR_SETPOS (xdrs, 0);
159   ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
160   if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
161       (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
162       (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
163       (!(*xargs) (xdrs, argsp)))
164     {
165       return (RPC_CANTENCODEARGS);
166     }
167   (void) XDR_GETPOS (xdrs);     /* called just to cause overhead */
168
169   /*
170    * We have to call server input routine here because this is
171    * all going on in one process. Yuk.
172    */
173   INTUSE(svc_getreq) (1);
174
175   /*
176    * get results
177    */
178   xdrs->x_op = XDR_DECODE;
179   XDR_SETPOS (xdrs, 0);
180   msg.acpted_rply.ar_verf = _null_auth;
181   msg.acpted_rply.ar_results.where = resultsp;
182   msg.acpted_rply.ar_results.proc = xresults;
183   if (!INTUSE(xdr_replymsg) (xdrs, &msg))
184     return RPC_CANTDECODERES;
185   _seterr_reply (&msg, &error);
186   status = error.re_status;
187
188   if (status == RPC_SUCCESS)
189     {
190       if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
191         {
192           status = RPC_AUTHERROR;
193         }
194     }                           /* end successful completion */
195   else
196     {
197       if (AUTH_REFRESH (h->cl_auth))
198         goto call_again;
199     }                           /* end of unsuccessful completion */
200
201   if (status == RPC_SUCCESS)
202     {
203       if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
204         {
205           status = RPC_AUTHERROR;
206         }
207       if (msg.acpted_rply.ar_verf.oa_base != NULL)
208         {
209           xdrs->x_op = XDR_FREE;
210           (void) INTUSE(xdr_opaque_auth) (xdrs, &(msg.acpted_rply.ar_verf));
211         }
212     }
213
214   return status;
215 }
216
217 static void
218 clntraw_geterr (CLIENT *cl, struct rpc_err *err)
219 {
220 }
221
222
223 static bool_t
224 clntraw_freeres (cl, xdr_res, res_ptr)
225      CLIENT *cl;
226      xdrproc_t xdr_res;
227      caddr_t res_ptr;
228 {
229   struct clntraw_private_s *clp = clntraw_private;
230   XDR *xdrs = &clp->xdr_stream;
231   bool_t rval;
232
233   if (clp == NULL)
234     {
235       rval = (bool_t) RPC_FAILED;
236       return rval;
237     }
238   xdrs->x_op = XDR_FREE;
239   return (*xdr_res) (xdrs, res_ptr);
240 }
241
242 static void
243 clntraw_abort (void)
244 {
245 }
246
247 static bool_t
248 clntraw_control (CLIENT *cl, int i, char *c)
249 {
250   return FALSE;
251 }
252
253 static void
254 clntraw_destroy (CLIENT *cl)
255 {
256 }