home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp-sdk / src / rpclib / clnt_raw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  5.0 KB  |  222 lines

  1. /*
  2.  * $Id: clnt_raw.c,v 4.2 1994/09/29 23:48:50 jraja Exp $
  3.  *
  4.  * Copyright © 1994 AmiTCP/IP Group,
  5.  *                  Network Solutions Development Inc.
  6.  *                  All rights reserved. 
  7.  */
  8.  
  9. /* @(#)clnt_raw.c    2.2 88/08/01 4.0 RPCSRC */
  10. #if !defined(lint) && defined(SCCSIDS)
  11. static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
  12. #endif
  13.  
  14. /*
  15.  * Copyright (C) 1984, Sun Microsystems, Inc.
  16.  *
  17.  * Memory based rpc for simple testing and timing.
  18.  * Interface to create an rpc client and server in the same process.
  19.  * This lets us similate rpc and get round trip overhead, without
  20.  * any interference from the kernal.
  21.  */
  22.  
  23. #include <sys/param.h>
  24. #include <rpc/rpc.h>
  25.  
  26. #define MCALL_MSG_SIZE 24
  27.  
  28. /*
  29.  * This is the "network" we will be moving stuff over.
  30.  */
  31. static struct clntraw_private {
  32.     CLIENT    client_object;
  33.     XDR    xdr_stream;
  34.     char    _raw_buf[UDPMSGSIZE];
  35.     char    mashl_callmsg[MCALL_MSG_SIZE];
  36.     u_int    mcnt;
  37. } *clntraw_private;
  38.  
  39. static enum clnt_stat    clntraw_call(CLIENT * h, u_long proc,
  40.                      xdrproc_t xdr_args, caddr_t args_ptr,
  41.                      xdrproc_t xdr_results,
  42.                      caddr_t results_ptr,
  43.                      struct timeval timeout);
  44. static void        clntraw_abort(CLIENT * h);
  45. static void        clntraw_geterr(CLIENT * h, struct rpc_err * errp);
  46. static bool_t        clntraw_freeres(CLIENT * cl, 
  47.                     xdrproc_t xdr_res, caddr_t res_ptr);
  48. static bool_t        clntraw_control(CLIENT * cl,
  49.                     u_int request, caddr_t info);
  50. static void        clntraw_destroy(CLIENT * h);
  51.  
  52. static struct clnt_ops client_ops = {
  53.     clntraw_call,
  54.     clntraw_abort,
  55.     clntraw_geterr,
  56.     clntraw_freeres,
  57.     clntraw_destroy,
  58.     clntraw_control
  59. };
  60.  
  61. /*
  62.  * Create a client handle for memory based rpc.
  63.  */
  64. CLIENT *
  65. clntraw_create(prog, vers)
  66.     u_long prog;
  67.     u_long vers;
  68. {
  69.     register struct clntraw_private *clp = clntraw_private;
  70.     struct rpc_msg call_msg;
  71.     XDR *xdrs = &clp->xdr_stream;
  72.     CLIENT    *client = &clp->client_object;
  73.  
  74.     if (clp == 0) {
  75.         clp = (struct clntraw_private *)mem_calloc(1, sizeof (*clp));
  76.         if (clp == 0)
  77.             return (0);
  78.         clntraw_private = clp;
  79.     }
  80.     /*
  81.      * pre-serialize the staic part of the call msg and stash it away
  82.      */
  83.     call_msg.rm_direction = CALL;
  84.     call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  85.     call_msg.rm_call.cb_prog = prog;
  86.     call_msg.rm_call.cb_vers = vers;
  87.     xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); 
  88.     if (! xdr_callhdr(xdrs, &call_msg)) {
  89.         perror("clnt_raw.c - Fatal header serialization error.");
  90.     }
  91.     clp->mcnt = XDR_GETPOS(xdrs);
  92.     XDR_DESTROY(xdrs);
  93.  
  94.     /*
  95.      * Set xdrmem for client/server shared buffer
  96.      */
  97.     xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
  98.  
  99.     /*
  100.      * create client handle
  101.      */
  102.     client->cl_ops = &client_ops;
  103.     client->cl_auth = authnone_create();
  104.     return (client);
  105. }
  106.  
  107. static enum clnt_stat 
  108. clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
  109.     CLIENT *h;
  110.     u_long proc;
  111.     xdrproc_t xargs;
  112.     caddr_t argsp;
  113.     xdrproc_t xresults;
  114.     caddr_t resultsp;
  115.     struct timeval timeout;
  116. {
  117.     register struct clntraw_private *clp = clntraw_private;
  118.     register XDR *xdrs = &clp->xdr_stream;
  119.     struct rpc_msg msg;
  120.     enum clnt_stat status;
  121.     struct rpc_err error;
  122.  
  123.     if (clp == 0)
  124.         return (RPC_FAILED);
  125. call_again:
  126.     /*
  127.      * send request
  128.      */
  129.     xdrs->x_op = XDR_ENCODE;
  130.     XDR_SETPOS(xdrs, 0);
  131.     ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
  132.     if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
  133.         (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
  134.         (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
  135.         (! (*xargs)(xdrs, argsp))) {
  136.         return (RPC_CANTENCODEARGS);
  137.     }
  138.     (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
  139.  
  140.     /*
  141.      * We have to call server input routine here because this is
  142.      * all going on in one process. Yuk.
  143.      */
  144.     svc_getreq(1);
  145.  
  146.     /*
  147.      * get results
  148.      */
  149.     xdrs->x_op = XDR_DECODE;
  150.     XDR_SETPOS(xdrs, 0);
  151.     msg.acpted_rply.ar_verf = _null_auth;
  152.     msg.acpted_rply.ar_results.where = resultsp;
  153.     msg.acpted_rply.ar_results.proc = xresults;
  154.     if (! xdr_replymsg(xdrs, &msg))
  155.         return (RPC_CANTDECODERES);
  156.     _seterr_reply(&msg, &error);
  157.     status = error.re_status;
  158.  
  159.     if (status == RPC_SUCCESS) {
  160.         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  161.             status = RPC_AUTHERROR;
  162.         }
  163.     }  /* end successful completion */
  164.     else {
  165.         if (AUTH_REFRESH(h->cl_auth))
  166.             goto call_again;
  167.     }  /* end of unsuccessful completion */
  168.  
  169.     if (status == RPC_SUCCESS) {
  170.         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  171.             status = RPC_AUTHERROR;
  172.         }
  173.         if (msg.acpted_rply.ar_verf.oa_base != NULL) {
  174.             xdrs->x_op = XDR_FREE;
  175.             (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
  176.         }
  177.     }
  178.  
  179.     return (status);
  180. }
  181.  
  182. static void
  183. clntraw_geterr(CLIENT * h, struct rpc_err * errp)
  184. {
  185. }
  186.  
  187.  
  188. static bool_t
  189. clntraw_freeres(cl, xdr_res, res_ptr)
  190.     CLIENT *cl;
  191.     xdrproc_t xdr_res;
  192.     caddr_t res_ptr;
  193. {
  194.     register struct clntraw_private *clp = clntraw_private;
  195.     register XDR *xdrs = &clp->xdr_stream;
  196.     bool_t rval;
  197.  
  198.     if (clp == 0)
  199.     {
  200.         rval = (bool_t) RPC_FAILED;
  201.         return (rval);
  202.     }
  203.     xdrs->x_op = XDR_FREE;
  204.     return ((*xdr_res)(xdrs, res_ptr));
  205. }
  206.  
  207. static void
  208. clntraw_abort(CLIENT * h)
  209. {
  210. }
  211.  
  212. static bool_t
  213. clntraw_control(CLIENT * cl, u_int request, caddr_t info)
  214. {
  215.     return (FALSE);
  216. }
  217.  
  218. static void
  219. clntraw_destroy(CLIENT * h)
  220. {
  221. }
  222.