home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / bsd / rpc / svc.h < prev    next >
Text File  |  1991-06-21  |  8KB  |  253 lines

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