home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / ntwrkprt / rpcmdfct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  5.6 KB  |  161 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/drapeau/NetworkProtocol/RCS/rpcModifications.c,v 1.13 92/05/29 12:40:44 drapeau Exp $ */
  25. /* $Log:    rpcModifications.c,v $
  26.  * Revision 1.13  92/05/29  12:40:44  drapeau
  27.  * Changed the name of the "Selection" structure to "MAESelection",
  28.  * to avoid name conflicts with other software packages and toolkits
  29.  * that might also define a "Selection" structure.
  30.  * 
  31.  * Revision 1.12  91/06/17  18:17:26  drapeau
  32.  * Added copyright notice.
  33.  * 
  34.  * Revision 1.11  1991/02/28  07:19:24  drapeau
  35.  * No code changes; this version uses a new version numbering scheme and a new
  36.  * version of RCS.
  37.  *
  38.  * Revision 1.1  90/10/24  18:31:21  drapeau
  39.  * Initial revision
  40.  *  */
  41.  
  42. static char rpcModificationsRcsid[] = "$Header: /Source/Media/drapeau/NetworkProtocol/RCS/rpcModifications.c,v 1.13 92/05/29 12:40:44 drapeau Exp $";
  43.  
  44. #include <stdio.h>
  45. #include <rpc/rpc.h>
  46. #include <sys/socket.h>
  47. #include <netdb.h>
  48. #include <errno.h>
  49. #include <rpc/pmap_clnt.h>
  50.  
  51. #define MCALL_MSG_SIZE 24
  52.  
  53. struct ct_data {
  54.     int        ct_sock;
  55.     bool_t        ct_closeit;
  56.     struct timeval    ct_wait;
  57.     bool_t          ct_waitset;       /* wait set by clnt_control? */
  58.     struct sockaddr_in ct_addr; 
  59.     struct rpc_err    ct_error;
  60.     char        ct_mcall[MCALL_MSG_SIZE];    /* marshalled callmsg */
  61.     u_int        ct_mpos;            /* pos after marshal */
  62.     XDR        ct_xdrs;
  63. };
  64.   
  65.   
  66. static enum clnt_stat clnttcp_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
  67.      register CLIENT *h;
  68.      u_long proc;
  69.      xdrproc_t xdr_args;
  70.      caddr_t args_ptr;
  71.      xdrproc_t xdr_results;
  72.      caddr_t results_ptr;
  73.      struct timeval *timeout;                        /* Changed timeout to be a pointer to the timeval ... */
  74. {                                    /* structure instead of the whole struct. */
  75.                                     /* George D. Drapeau, 10/15/90 */
  76.   register struct ct_data *ct = (struct ct_data *) h->cl_private;
  77.   register XDR *xdrs = &(ct->ct_xdrs);
  78.   struct rpc_msg reply_msg;
  79.   u_long x_id;
  80.   u_long *msg_x_id = (u_long *)(ct->ct_mcall);                /* yuk */
  81.   register bool_t shipnow;
  82.   int refreshes = 2;
  83.   
  84.   if (!ct->ct_waitset)
  85.     {
  86.     ct->ct_wait.tv_sec = timeout->tv_sec;
  87.     ct->ct_wait.tv_usec = timeout->tv_usec;
  88.     }
  89.   shipnow = (xdr_results == (xdrproc_t)0
  90.          && timeout->tv_sec == 0
  91.          && timeout->tv_usec == 0) ? FALSE : TRUE;
  92.   
  93.   call_again:
  94.   xdrs->x_op = XDR_ENCODE;
  95.   ct->ct_error.re_status = RPC_SUCCESS;
  96.   x_id = ntohl(--(*msg_x_id));
  97.   if ((! XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
  98.       (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
  99.       (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
  100.       (! (*xdr_args)(xdrs, args_ptr)))
  101.     {
  102.     if (ct->ct_error.re_status == RPC_SUCCESS)
  103.       ct->ct_error.re_status = RPC_CANTENCODEARGS;
  104.     (void)xdrrec_endofrecord(xdrs, TRUE);
  105.     return (ct->ct_error.re_status);
  106.     }
  107.   if (! xdrrec_endofrecord(xdrs, shipnow))
  108.     return (ct->ct_error.re_status = RPC_CANTSEND);
  109.   if (! shipnow)
  110.     return (RPC_SUCCESS);
  111.  
  112.   if (timeout->tv_sec == 0 && timeout->tv_usec == 0)            /* Hack to provide rpc-based message passing */
  113.     {
  114.     return(ct->ct_error.re_status = RPC_TIMEDOUT);
  115.     }
  116.   xdrs->x_op = XDR_DECODE;                        /* Keep receiving until we get a valid transaction id */
  117.   while (TRUE)
  118.     {
  119.     reply_msg.acpted_rply.ar_verf = _null_auth;
  120.     reply_msg.acpted_rply.ar_results.where = NULL;
  121.     reply_msg.acpted_rply.ar_results.proc = xdr_void;
  122.     if (! xdrrec_skiprecord(xdrs))
  123.       return (ct->ct_error.re_status);
  124.                                     /* now decode and validate the response header */
  125.     if (! xdr_replymsg(xdrs, &reply_msg))
  126.       {
  127.       if (ct->ct_error.re_status == RPC_SUCCESS)
  128.     continue;
  129.       return (ct->ct_error.re_status);
  130.       }
  131.     if (reply_msg.rm_xid == x_id)
  132.       break;
  133.     }
  134.   _seterr_reply(&reply_msg, &(ct->ct_error));                /* process header */
  135.   if (ct->ct_error.re_status == RPC_SUCCESS)
  136.     {
  137.     if (! AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf))
  138.       {
  139.       ct->ct_error.re_status = RPC_AUTHERROR;
  140.       ct->ct_error.re_why = AUTH_INVALIDRESP;
  141.       }
  142.     else
  143.       if (! (*xdr_results)(xdrs, results_ptr))
  144.     {
  145.     if (ct->ct_error.re_status == RPC_SUCCESS)
  146.       ct->ct_error.re_status = RPC_CANTDECODERES;
  147.     }
  148.     if (reply_msg.acpted_rply.ar_verf.oa_base != NULL)            /* free verifier ... */
  149.       {
  150.       xdrs->x_op = XDR_FREE;
  151.       (void)xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
  152.       }
  153.     }                                    /* end successful completion */
  154.   else
  155.     {
  156.     if (refreshes-- && AUTH_REFRESH(h->cl_auth))            /* maybe our credentials need to be refreshed ... */
  157.       goto call_again;
  158.     }                                    /* end of unsuccessful completion */
  159.   return (ct->ct_error.re_status);
  160.   }                                    /* end function clnttcp_call */
  161.