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