home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Contributions / Interworks / Networking / INet-225 / include / rpc / svc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-08  |  9.0 KB  |  284 lines

  1. /* @(#)svc.h    1.2 87/11/09 3.9 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. /*    @(#)svc.h 1.18 87/07/14 SMI      *
  31.  
  32. /*
  33.  * svc.h, Server-side remote procedure call interface.
  34.  *
  35.  * Copyright (C) 1984, Sun Microsystems, Inc.
  36.  */
  37.  
  38. #ifndef __SVC_HEADER__
  39. #define __SVC_HEADER__
  40.  
  41. /*
  42.  * This interface must manage two items concerning remote procedure calling:
  43.  *
  44.  * 1) An arbitrary number of transport connections upon which rpc requests
  45.  * are received.  The two most notable transports are TCP and UDP;  they are
  46.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  47.  * they in turn call xprt_register and xprt_unregister.
  48.  *
  49.  * 2) An arbitrary number of locally registered services.  Services are
  50.  * described by the following four data: program number, version number,
  51.  * "service dispatch" function, a transport handle, and a boolean that
  52.  * indicates whether or not the exported program should be registered with a
  53.  * local binder service;  if true the program's number and version and the
  54.  * port number from the transport handle are registered with the binder.
  55.  * These data are registered with the rpc svc system via svc_register.
  56.  *
  57.  * A service's dispatch function is called whenever an rpc request comes in
  58.  * on a transport.  The request's program and version numbers must match
  59.  * those of the registered service.  The dispatch function is passed two
  60.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  61.  */
  62.  
  63. enum xprt_stat {
  64.     XPRT_DIED,
  65.     XPRT_MOREREQS,
  66.     XPRT_IDLE
  67. };
  68.  
  69. /*
  70.  * Server side transport handle
  71.  */
  72. typedef struct SVCXPRT {
  73.     int        xp_sock;
  74.     u_short     xp_port;     /* associated port number */
  75.     struct xp_ops {
  76.         /* receive incoming requests */
  77.         bool_t    (*xp_recv)(struct SVCXPRT *, struct rpc_msg *);
  78.         /* get transport status */
  79.         enum xprt_stat (*xp_stat)(struct SVCXPRT *);
  80.         /* get arguments */
  81.         bool_t    (*xp_getargs)(struct SVCXPRT *, xdrproc_t, caddr_t);
  82.         /* send reply */
  83.         bool_t    (*xp_reply)(struct SVCXPRT *, struct rpc_msg *);
  84.         /* free mem allocated for args */
  85.         bool_t    (*xp_freeargs)(struct SVCXPRT *, xdrproc_t, caddr_t);
  86.         /* destroy this struct */
  87.         void    (*xp_destroy)(struct SVCXPRT *);
  88.     } *xp_ops;
  89.     int        xp_addrlen;     /* length of remote address */
  90.     struct sockaddr_in xp_raddr;     /* remote address */
  91.     struct opaque_auth xp_verf;     /* raw response verifier */
  92.     caddr_t     xp_p1;         /* private */
  93.     caddr_t     xp_p2;         /* private */
  94. } SVCXPRT;
  95.  
  96. /*
  97.  *  Approved way of getting address of caller
  98.  */
  99. #define svc_getcaller(x) (&(x)->xp_raddr)
  100.  
  101. /*
  102.  * Operations defined on an SVCXPRT handle
  103.  *
  104.  * SVCXPRT        *xprt;
  105.  * struct rpc_msg    *msg;
  106.  * xdrproc_t         xargs;
  107.  * caddr_t         argsp;
  108.  */
  109. #define SVC_RECV(xprt, msg)                             \
  110.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  111. #define svc_recv(xprt, msg)                             \
  112.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  113.  
  114. #define SVC_STAT(xprt)                                  \
  115.     (*(xprt)->xp_ops->xp_stat)(xprt)
  116. #define svc_stat(xprt)                                  \
  117.     (*(xprt)->xp_ops->xp_stat)(xprt)
  118.  
  119. #define SVC_GETARGS(xprt, xargs, argsp)                 \
  120.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  121. #define svc_getargs(xprt, xargs, argsp)                 \
  122.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  123.  
  124. #define SVC_REPLY(xprt, msg)                            \
  125.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  126. #define svc_reply(xprt, msg)                            \
  127.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  128.  
  129. #define SVC_FREEARGS(xprt, xargs, argsp)                \
  130.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  131. #define svc_freeargs(xprt, xargs, argsp)                \
  132.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  133.  
  134. #define SVC_DESTROY(xprt)                               \
  135.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  136. #define svc_destroy(xprt)                               \
  137.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  138.  
  139.  
  140. /*
  141.  * Service request
  142.  */
  143. struct svc_req {
  144.     u_long        rq_prog;    /* service program number */
  145.     u_long        rq_vers;    /* service protocol version */
  146.     u_long        rq_proc;    /* the desired procedure */
  147.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  148.     caddr_t     rq_clntcred;    /* read only cooked cred */
  149.     SVCXPRT *rq_xprt;        /* associated transport */
  150. };
  151.  
  152.  
  153. /*
  154.  * Service registration
  155.  *
  156.  * svc_register(xprt, prog, vers, dispatch, protocol)
  157.  *    SVCXPRT *xprt;
  158.  *    u_long prog;
  159.  *    u_long vers;
  160.  *    void (*dispatch)();
  161.  *    int protocol;  /* like TCP or UDP, zero means do not register
  162.  */
  163. extern bool_t    svc_register();
  164.  
  165. /*
  166.  * Service un-registration
  167.  *
  168.  * svc_unregister(prog, vers)
  169.  *    u_long prog;
  170.  *    u_long vers;
  171.  */
  172. extern void    svc_unregister();
  173.  
  174. /*
  175.  * Transport registration.
  176.  *
  177.  * xprt_register(xprt)
  178.  *    SVCXPRT *xprt;
  179.  */
  180. extern void    xprt_register();
  181.  
  182. /*
  183.  * Transport un-register
  184.  *
  185.  * xprt_unregister(xprt)
  186.  *    SVCXPRT *xprt;
  187.  */
  188. extern void    xprt_unregister();
  189.  
  190.  
  191.  
  192.  
  193. /*
  194.  * When the service routine is called, it must first check to see if it
  195.  * knows about the procedure;  if not, it should call svcerr_noproc
  196.  * and return.    If so, it should deserialize its arguments via
  197.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  198.  * svcerr_decode should be called followed by a return.  Successful
  199.  * decoding of the arguments should be followed the execution of the
  200.  * procedure's code and a call to svc_sendreply.
  201.  *
  202.  * Also, if the service refuses to execute the procedure due to too-
  203.  * weak authentication parameters, svcerr_weakauth should be called.
  204.  * Note: do not confuse access-control failure with weak authentication!
  205.  *
  206.  * NB: In pure implementations of rpc, the caller always waits for a reply
  207.  * msg.  This message is sent when svc_sendreply is called.
  208.  * Therefore pure service implementations should always call
  209.  * svc_sendreply even if the function logically returns void;  use
  210.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  211.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  212.  * case of a batched call, svc_sendreply should NOT be called since
  213.  * this would send a return message, which is what batching tries to avoid.
  214.  * It is the service/protocol writer's responsibility to know which calls are
  215.  * batched and which are not.  Warning: responding to batch calls may
  216.  * deadlock the caller and server processes!
  217.  */
  218.  
  219. extern bool_t  svc_sendreply();
  220. extern void    svcerr_decode();
  221. extern void    svcerr_weakauth();
  222. extern void    svcerr_noproc();
  223.  
  224. /*
  225.  * Lowest level dispatching -OR- who owns this process anyway.
  226.  * Somebody has to wait for incoming requests and then call the correct
  227.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  228.  * svc_run never returns.
  229.  * Since another (co-existant) package may wish to selectively wait for
  230.  * incoming calls or other events outside of the rpc architecture, the
  231.  * routine svc_getreq is provided.  It must be passed readfds, the
  232.  * "in-place" results of a select system call (see select, section 2).
  233.  */
  234.  
  235. /*
  236.  * Global keeper of rpc service descriptors in use
  237.  * dynamic; must be inspected before each call to select
  238.  */
  239. #ifdef FD_SETSIZE
  240. extern fd_set svc_fdset;
  241. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  242. #else
  243. extern int svc_fds;
  244. #endif /* def FD_SETSIZE */
  245.  
  246. /*
  247.  * a small program implemented by the svc_rpc implementation itself;
  248.  * also see clnt.h for protocol numbers.
  249.  */
  250. extern void rpctest_service();
  251.  
  252. extern void    svc_getreq();
  253. extern void    svc_getreqset();        /* takes fdset instead of int */
  254. extern void    svc_run();       /* never returns */
  255.  
  256. /*
  257.  * Socket to use on svcxxx_create call to get default socket
  258.  */
  259. #define RPC_ANYSOCK    -1
  260.  
  261. /*
  262.  * These are the existing service side transport implementations
  263.  */
  264.  
  265. /*
  266.  * Memory based rpc for testing and timing.
  267.  */
  268. extern SVCXPRT *svcraw_create();
  269.  
  270. /*
  271.  * Udp based rpc.
  272.  */
  273. extern SVCXPRT *svcudp_create();
  274. extern SVCXPRT *svcudp_bufcreate();
  275.  
  276. /*
  277.  * Tcp based rpc.
  278.  */
  279. extern SVCXPRT *svctcp_create();
  280.  
  281.  
  282.  
  283. #endif /* !__SVC_HEADER__ */
  284.