Back to index

glibc  2.9
clnt_raw.c
Go to the documentation of this file.
00001 /* @(#)clnt_raw.c    2.2 88/08/01 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * clnt_raw.c
00036  *
00037  * Copyright (C) 1984, Sun Microsystems, Inc.
00038  *
00039  * Memory based rpc for simple testing and timing.
00040  * Interface to create an rpc client and server in the same process.
00041  * This lets us simulate rpc and get round trip overhead, without
00042  * any interference from the kernel.
00043  */
00044 
00045 #include <rpc/rpc.h>
00046 #include <rpc/svc.h>
00047 #include <rpc/xdr.h>
00048 #include <libintl.h>
00049 
00050 #define MCALL_MSG_SIZE 24
00051 
00052 /*
00053  * This is the "network" we will be moving stuff over.
00054  */
00055 struct clntraw_private_s
00056   {
00057     CLIENT client_object;
00058     XDR xdr_stream;
00059     char _raw_buf[UDPMSGSIZE];
00060     char mashl_callmsg[MCALL_MSG_SIZE];
00061     u_int mcnt;
00062   };
00063 #ifdef _RPC_THREAD_SAFE_
00064 #define clntraw_private RPC_THREAD_VARIABLE(clntraw_private_s)
00065 #else
00066 static struct clntraw_private_s *clntraw_private;
00067 #endif
00068 
00069 static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
00070                                 xdrproc_t, caddr_t, struct timeval);
00071 static void clntraw_abort (void);
00072 static void clntraw_geterr (CLIENT *, struct rpc_err *);
00073 static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
00074 static bool_t clntraw_control (CLIENT *, int, char *);
00075 static void clntraw_destroy (CLIENT *);
00076 
00077 static const struct clnt_ops client_ops =
00078 {
00079   clntraw_call,
00080   clntraw_abort,
00081   clntraw_geterr,
00082   clntraw_freeres,
00083   clntraw_destroy,
00084   clntraw_control
00085 };
00086 
00087 /*
00088  * Create a client handle for memory based rpc.
00089  */
00090 CLIENT *
00091 clntraw_create (u_long prog, u_long vers)
00092 {
00093   struct clntraw_private_s *clp = clntraw_private;
00094   struct rpc_msg call_msg;
00095   XDR *xdrs;
00096   CLIENT *client;
00097 
00098   if (clp == 0)
00099     {
00100       clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
00101       if (clp == 0)
00102        return (0);
00103       clntraw_private = clp;
00104     }
00105   xdrs = &clp->xdr_stream;
00106   client = &clp->client_object;
00107   /*
00108    * pre-serialize the static part of the call msg and stash it away
00109    */
00110   call_msg.rm_direction = CALL;
00111   call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
00112   call_msg.rm_call.cb_prog = prog;
00113   call_msg.rm_call.cb_vers = vers;
00114   INTUSE(xdrmem_create) (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
00115   if (!INTUSE(xdr_callhdr) (xdrs, &call_msg))
00116     {
00117       perror (_ ("clnt_raw.c: fatal header serialization error"));
00118     }
00119   clp->mcnt = XDR_GETPOS (xdrs);
00120   XDR_DESTROY (xdrs);
00121 
00122   /*
00123    * Set xdrmem for client/server shared buffer
00124    */
00125   INTUSE(xdrmem_create) (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
00126 
00127   /*
00128    * create client handle
00129    */
00130   client->cl_ops = (struct clnt_ops *) &client_ops;
00131   client->cl_auth = INTUSE(authnone_create) ();
00132   return client;
00133 }
00134 
00135 static enum clnt_stat
00136 clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
00137      CLIENT *h;
00138      u_long proc;
00139      xdrproc_t xargs;
00140      caddr_t argsp;
00141      xdrproc_t xresults;
00142      caddr_t resultsp;
00143      struct timeval timeout;
00144 {
00145   struct clntraw_private_s *clp = clntraw_private;
00146   XDR *xdrs = &clp->xdr_stream;
00147   struct rpc_msg msg;
00148   enum clnt_stat status;
00149   struct rpc_err error;
00150 
00151   if (clp == NULL)
00152     return RPC_FAILED;
00153 call_again:
00154   /*
00155    * send request
00156    */
00157   xdrs->x_op = XDR_ENCODE;
00158   XDR_SETPOS (xdrs, 0);
00159   ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
00160   if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
00161       (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
00162       (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
00163       (!(*xargs) (xdrs, argsp)))
00164     {
00165       return (RPC_CANTENCODEARGS);
00166     }
00167   (void) XDR_GETPOS (xdrs); /* called just to cause overhead */
00168 
00169   /*
00170    * We have to call server input routine here because this is
00171    * all going on in one process. Yuk.
00172    */
00173   INTUSE(svc_getreq) (1);
00174 
00175   /*
00176    * get results
00177    */
00178   xdrs->x_op = XDR_DECODE;
00179   XDR_SETPOS (xdrs, 0);
00180   msg.acpted_rply.ar_verf = _null_auth;
00181   msg.acpted_rply.ar_results.where = resultsp;
00182   msg.acpted_rply.ar_results.proc = xresults;
00183   if (!INTUSE(xdr_replymsg) (xdrs, &msg))
00184     return RPC_CANTDECODERES;
00185   _seterr_reply (&msg, &error);
00186   status = error.re_status;
00187 
00188   if (status == RPC_SUCCESS)
00189     {
00190       if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
00191        {
00192          status = RPC_AUTHERROR;
00193        }
00194     }                       /* end successful completion */
00195   else
00196     {
00197       if (AUTH_REFRESH (h->cl_auth))
00198        goto call_again;
00199     }                       /* end of unsuccessful completion */
00200 
00201   if (status == RPC_SUCCESS)
00202     {
00203       if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
00204        {
00205          status = RPC_AUTHERROR;
00206        }
00207       if (msg.acpted_rply.ar_verf.oa_base != NULL)
00208        {
00209          xdrs->x_op = XDR_FREE;
00210          (void) INTUSE(xdr_opaque_auth) (xdrs, &(msg.acpted_rply.ar_verf));
00211        }
00212     }
00213 
00214   return status;
00215 }
00216 
00217 static void
00218 clntraw_geterr (CLIENT *cl, struct rpc_err *err)
00219 {
00220 }
00221 
00222 
00223 static bool_t
00224 clntraw_freeres (cl, xdr_res, res_ptr)
00225      CLIENT *cl;
00226      xdrproc_t xdr_res;
00227      caddr_t res_ptr;
00228 {
00229   struct clntraw_private_s *clp = clntraw_private;
00230   XDR *xdrs = &clp->xdr_stream;
00231   bool_t rval;
00232 
00233   if (clp == NULL)
00234     {
00235       rval = (bool_t) RPC_FAILED;
00236       return rval;
00237     }
00238   xdrs->x_op = XDR_FREE;
00239   return (*xdr_res) (xdrs, res_ptr);
00240 }
00241 
00242 static void
00243 clntraw_abort (void)
00244 {
00245 }
00246 
00247 static bool_t
00248 clntraw_control (CLIENT *cl, int i, char *c)
00249 {
00250   return FALSE;
00251 }
00252 
00253 static void
00254 clntraw_destroy (CLIENT *cl)
00255 {
00256 }