home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / rpc / svc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  10.4 KB  |  367 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ident    "@(#)/usr/include/rpc/svc.h.sl 1.1 4.0 12/08/90 1277 AT&T-USL"
  11.  
  12. /*      @(#)svc.h 1.35 88/12/17 SMI      */
  13.  
  14. /*
  15.  *          PROPRIETARY NOTICE (Combined)
  16.  *  
  17.  *  This source code is unpublished proprietary information
  18.  *  constituting, or derived under license from AT&T's Unix(r) System V.
  19.  *  In addition, portions of such source code were derived from Berkeley
  20.  *  4.3 BSD under license from the Regents of the University of
  21.  *  California.
  22.  *  
  23.  *  
  24.  *  
  25.  *          Copyright Notice 
  26.  *  
  27.  *  Notice of copyright on this source code product does not indicate 
  28.  *  publication.
  29.  *  
  30.  *      (c) 1986,1987,1988,1989  Sun Microsystems, Inc.
  31.  *      (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  32.  *                All rights reserved.
  33.  */
  34.  
  35. /*
  36.  * svc.h, Server-side remote procedure call interface.
  37.  *
  38.  */
  39.  
  40. #ifndef _RPC_SVC_H
  41. #define _RPC_SVC_H
  42.  
  43. #include <rpc/rpc_com.h>
  44.  
  45. /*
  46.  * This interface must manage two items concerning remote procedure calling:
  47.  *
  48.  * 1) An arbitrary number of transport connections upon which rpc requests
  49.  * are received. They are created and registered by routines in svc_generic.c,
  50.  * svc_vc.c and svc_dg.c; they in turn call xprt_register and 
  51.  * xprt_unregister.
  52.  *
  53.  * 2) An arbitrary number of locally registered services.  Services are
  54.  * described by the following four data: program number, version number,
  55.  * "service dispatch" function, a transport handle, and a boolean that
  56.  * indicates whether or not the exported program should be registered with a
  57.  * local binder service;  if true the program's number and version and the
  58.  * address from the transport handle are registered with the binder.
  59.  * These data are registered with rpcbind via svc_reg().
  60.  *
  61.  * A service's dispatch function is called whenever an rpc request comes in
  62.  * on a transport.  The request's program and version numbers must match
  63.  * those of the registered service.  The dispatch function is passed two
  64.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  65.  */
  66.  
  67. enum xprt_stat {
  68.     XPRT_DIED,
  69.     XPRT_MOREREQS,
  70.     XPRT_IDLE
  71. };
  72.  
  73. /*
  74.  * Server side transport handle
  75.  */
  76. typedef struct {
  77. #ifdef _KERNEL
  78.     TIUSER        *xp_tiptr;
  79. #else
  80.     int        xp_fd;
  81. #define xp_sock        xp_fd
  82. #endif
  83.     u_short        xp_port;     /* associated port number.
  84.                       * Obsoleted, but still used to
  85.                       * specify whether rendezvouser
  86.                       * or normal connection
  87.                       */
  88.     struct xp_ops {
  89.         bool_t    (*xp_recv)();     /* receive incoming requests */
  90.         enum xprt_stat (*xp_stat)(); /* get transport status */
  91.         bool_t    (*xp_getargs)(); /* get arguments */
  92.         bool_t    (*xp_reply)();     /* send reply */
  93.         bool_t    (*xp_freeargs)();/* free mem allocated for args */
  94.         void    (*xp_destroy)(); /* destroy this struct */
  95.     } *xp_ops;
  96. #ifndef _KERNEL
  97.     int        xp_addrlen;     /* length of remote addr. Obsoleted */
  98.     char        *xp_tp;         /* transport provider device name */
  99.     char        *xp_netid;     /* network token */
  100. #endif
  101.     struct netbuf    xp_ltaddr;     /* local transport address */
  102.     struct netbuf    xp_rtaddr;     /* remote transport address */
  103. #ifndef _KERNEL
  104.     char        xp_raddr[16];     /* remote address. Now obsoleted */
  105. #endif
  106.     struct opaque_auth xp_verf;     /* raw response verifier */
  107.     caddr_t        xp_p1;         /* private: for use by svc ops */
  108. #ifdef _KERNEL
  109.     u_int        xp_p1len;     /* size of p1 */
  110. #endif
  111.     caddr_t        xp_p2;         /* private: for use by svc ops */
  112.     caddr_t        xp_p3;         /* private: for use by svc lib */
  113. } SVCXPRT;
  114.  
  115. /*
  116.  *  Approved way of getting address of caller
  117.  */
  118. #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
  119. #ifdef _KERNEL
  120. #define svc_getcaller(x) (&(x)->xp_rtaddr.buf)
  121. #endif
  122.  
  123. /*
  124.  * Operations defined on an SVCXPRT handle
  125.  *
  126.  * SVCXPRT        *xprt;
  127.  * struct rpc_msg    *msg;
  128.  * xdrproc_t         xargs;
  129.  * caddr_t         argsp;
  130.  */
  131. #define SVC_RECV(xprt, msg)                \
  132.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  133. #define svc_recv(xprt, msg)                \
  134.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  135.  
  136. #define SVC_STAT(xprt)                    \
  137.     (*(xprt)->xp_ops->xp_stat)(xprt)
  138. #define svc_stat(xprt)                    \
  139.     (*(xprt)->xp_ops->xp_stat)(xprt)
  140.  
  141. #define SVC_GETARGS(xprt, xargs, argsp)            \
  142.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  143. #define svc_getargs(xprt, xargs, argsp)            \
  144.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  145.  
  146. #define SVC_REPLY(xprt, msg)                \
  147.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  148. #define svc_reply(xprt, msg)                \
  149.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  150.  
  151. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  152.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  153. #define svc_freeargs(xprt, xargs, argsp)        \
  154.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  155.  
  156. #define SVC_DESTROY(xprt)                \
  157.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  158. #define svc_destroy(xprt)                \
  159.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  160.  
  161.  
  162. /*
  163.  * Service request
  164.  */
  165. struct svc_req {
  166.     u_long        rq_prog;    /* service program number */
  167.     u_long        rq_vers;    /* service protocol version */
  168.     u_long        rq_proc;    /* the desired procedure */
  169.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  170.     caddr_t        rq_clntcred;    /* read only cooked cred */
  171.     SVCXPRT        *rq_xprt;    /* associated transport */
  172. };
  173.  
  174.  
  175. /*
  176.  * Service registration
  177.  *
  178.  * svc_reg(xprt, prog, vers, dispatch, nconf)
  179.  *    SVCXPRT *xprt;
  180.  *    u_long prog;
  181.  *    u_long vers;
  182.  *    void (*dispatch)();
  183.  *    struct netconfig *nconf;
  184.  */
  185. extern bool_t    svc_reg();
  186.  
  187. /*
  188.  * Service un-registration
  189.  *
  190.  * svc_unreg(prog, vers)
  191.  *    u_long prog;
  192.  *    u_long vers;
  193.  */
  194. extern void    svc_unreg();
  195.  
  196. /*
  197.  * Transport registration.
  198.  *
  199.  * xprt_register(xprt)
  200.  *    SVCXPRT *xprt;
  201.  */
  202. extern void    xprt_register();
  203.  
  204. /*
  205.  * Transport un-register
  206.  *
  207.  * xprt_unregister(xprt)
  208.  *    SVCXPRT *xprt;
  209.  */
  210. extern void    xprt_unregister();
  211.  
  212.  
  213. /*
  214.  * When the service routine is called, it must first check to see if it
  215.  * knows about the procedure;  if not, it should call svcerr_noproc
  216.  * and return.  If so, it should deserialize its arguments via 
  217.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  218.  * svcerr_decode should be called followed by a return.  Successful
  219.  * decoding of the arguments should be followed the execution of the
  220.  * procedure's code and a call to svc_sendreply.
  221.  *
  222.  * Also, if the service refuses to execute the procedure due to too-
  223.  * weak authentication parameters, svcerr_weakauth should be called.
  224.  * Note: do not confuse access-control failure with weak authentication!
  225.  *
  226.  * NB: In pure implementations of rpc, the caller always waits for a reply
  227.  * msg.  This message is sent when svc_sendreply is called.  
  228.  * Therefore pure service implementations should always call
  229.  * svc_sendreply even if the function logically returns void;  use
  230.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, connectionful rpc allows
  231.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  232.  * case of a batched call, svc_sendreply should NOT be called since
  233.  * this would send a return message, which is what batching tries to avoid.
  234.  * It is the service/protocol writer's responsibility to know which calls are
  235.  * batched and which are not.  Warning: responding to batch calls may
  236.  * deadlock the caller and server processes!
  237.  */
  238.  
  239. extern bool_t    svc_sendreply();
  240. extern void    svcerr_decode();
  241. extern void    svcerr_weakauth();
  242. extern void    svcerr_noproc();
  243. extern void    svcerr_progvers();
  244. extern void    svcerr_auth();
  245. extern void    svcerr_noprog();
  246. #ifndef _KERNEL
  247. extern void    svcerr_systemerr();
  248. #endif
  249.     
  250. /*
  251.  * Lowest level dispatching -OR- who owns this process anyway.
  252.  * Somebody has to wait for incoming requests and then call the correct
  253.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  254.  * svc_run never returns.
  255.  * Since another (co-existant) package may wish to selectively wait for
  256.  * incoming calls or other events outside of the rpc architecture, the
  257.  * routine svc_getreq is provided.  It must be passed readfds, the
  258.  * "in-place" results of a select call (see select, section XXX).
  259.  */
  260.  
  261. #ifndef _KERNEL
  262. /*
  263.  * Global keeper of rpc service descriptors in use
  264.  * dynamic; must be inspected before each call to select 
  265.  */
  266. extern fd_set svc_fdset;
  267. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  268.  
  269. /*
  270.  * a small program implemented by the svc_rpc implementation itself;
  271.  * also see clnt.h for protocol numbers.
  272.  */
  273. extern void rpctest_service();
  274. #endif /* !_KERNEL */
  275.  
  276. extern void    svc_getreq();
  277. #ifndef _KERNEL
  278. extern void    svc_getreqset();    /* takes fdset instead of int */
  279. #endif
  280. extern void    svc_run();
  281.  
  282.  
  283. #ifndef _KERNEL
  284. /*
  285.  * These are the existing service side transport implementations
  286.  */
  287. /*
  288.  * Transport independent svc_create routine.
  289.  */
  290. extern int
  291. svc_create(/* dispatch, prognum, versnum, nettype*/); /*
  292.     void (*dispatch)();        -- dispatch routine
  293.     u_long prognum;            -- program number
  294.     u_long versnum;            -- version number
  295.     char *nettype;            -- network type
  296. */
  297.  
  298. /*
  299.  * Generic server creation routine. It takes a netconfig structure
  300.  * instead of a nettype.
  301.  */
  302. extern SVCXPRT    *
  303. svc_tp_create(/* dispatch, prognum, versnum, nconf*/); /*
  304.     void (*dispatch)();        -- dispatch routine
  305.     u_long prognum;            -- program number
  306.     u_long versnum;            -- version number
  307.     struct netconfig *nconf;    -- netconfig structure
  308. */
  309.  
  310. /*
  311.  * Generic TLI create routine
  312.  */
  313. extern SVCXPRT *
  314. svc_tli_create(/* fd, nconf, bindaddr, sendsz, recvsz*/) ; /*
  315.     int fd;                 -- connection end point
  316.     struct netconfig *nconf;    -- netconfig structure for network
  317.     struct t_bind *bindaddr;    -- local bind address
  318.     u_int sendsz;            -- max sendsize
  319.     u_int recvsz;            -- max recvsize
  320. */
  321.  
  322. /*
  323.  * Connectionless and connectionful create routines
  324.  */
  325. extern SVCXPRT    *
  326. svc_vc_create(/* fd, sendsize, recvsize*/); /*
  327.     int fd;                -- open connection end point
  328.     u_int sendsize;            -- max send size
  329.     u_int recvsize;            -- max recv size
  330. */
  331.  
  332. extern SVCXPRT    *
  333. svc_dg_create(/* fd, sendsize, recvsize*/); /*
  334.     int fd;                -- open connection end point
  335.     u_int sendsize;            -- max send size
  336.     u_int recvsize;            -- max recv size
  337. */
  338.  
  339. /*
  340.  * the routine takes any *open* TLI file
  341.  * descriptor as its first input and is used for open connections.
  342.  */
  343. extern SVCXPRT *
  344. svc_fd_create(/* fd, sendsize, recvsize*/); /*
  345.     int fd;                -- open connection end point
  346.     u_int sendsize;            -- max send size
  347.     u_int recvsize;            -- max recv size
  348. */
  349.  
  350. /*
  351.  * Memory based rpc (for speed check and testing)
  352.  */
  353. extern SVCXPRT *
  354. svc_raw_create();
  355.  
  356. #ifdef PORTMAP
  357. /* For backword compatibility */
  358. #include <rpc/svc_soc.h>
  359. #endif
  360.  
  361. #else
  362. /* kernel based rpc
  363.  */
  364. extern int svc_tli_kcreate();
  365. #endif /* !_KERNEL */
  366. #endif /* !_RPC_SVC_H */
  367.