home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / include / rpc / svc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  9.4 KB  |  299 lines

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