home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilss / sockets / include / rpc / h / svc < prev    next >
Encoding:
Text File  |  1995-01-11  |  8.9 KB  |  296 lines

  1. /* -*-C-*-
  2.  *
  3.  * $Header: /ax/networking:include/rpc/svc.h:networking  1.1  $
  4.  * $Source: /ax/networking:include/rpc/svc.h: $
  5.  *
  6.  * Copyright (c) 1995 Acorn Computers Ltd., Cambridge, England
  7.  *
  8.  * $Log:    svc.h,v $
  9.  * Revision 1.1  95/01/11  10:18:35  kwelton
  10.  * Initial revision
  11.  * 
  12.  */
  13.  
  14. /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
  15. /*
  16.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  17.  * unrestricted use provided that this legend is included on all tape
  18.  * media and as a part of the software program in whole or part.  Users
  19.  * may copy or modify Sun RPC without charge, but are not authorized
  20.  * to license or distribute it to anyone else except as part of a product or
  21.  * program developed by the user.
  22.  * 
  23.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  24.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  25.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  26.  * 
  27.  * Sun RPC is provided with no support and without any obligation on the
  28.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  29.  * modification or enhancement.
  30.  * 
  31.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  32.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  33.  * OR ANY PART THEREOF.
  34.  * 
  35.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  36.  * or profits or other special, indirect and consequential damages, even if
  37.  * Sun has been advised of the possibility of such damages.
  38.  * 
  39.  * Sun Microsystems, Inc.
  40.  * 2550 Garcia Avenue
  41.  * Mountain View, California  94043
  42.  */
  43.  
  44. /*
  45.  * svc.h, Server-side remote procedure call interface.
  46.  *
  47.  * Copyright (C) 1984, Sun Microsystems, Inc.
  48.  */
  49.  
  50. #ifndef __SVC_HEADER__
  51. #define __SVC_HEADER__
  52.  
  53. /*
  54.  * This interface must manage two items concerning remote procedure calling:
  55.  *
  56.  * 1) An arbitrary number of transport connections upon which rpc requests
  57.  * are received.  The two most notable transports are TCP and UDP;  they are
  58.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  59.  * they in turn call xprt_register and xprt_unregister.
  60.  *
  61.  * 2) An arbitrary number of locally registered services.  Services are
  62.  * described by the following four data: program number, version number,
  63.  * "service dispatch" function, a transport handle, and a boolean that
  64.  * indicates whether or not the exported program should be registered with a
  65.  * local binder service;  if true the program's number and version and the
  66.  * port number from the transport handle are registered with the binder.
  67.  * These data are registered with the rpc svc system via svc_register.
  68.  *
  69.  * A service's dispatch function is called whenever an rpc request comes in
  70.  * on a transport.  The request's program and version numbers must match
  71.  * those of the registered service.  The dispatch function is passed two
  72.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  73.  */
  74.  
  75. enum xprt_stat {
  76.     XPRT_DIED,
  77.     XPRT_MOREREQS,
  78.     XPRT_IDLE
  79. };
  80.  
  81. /*
  82.  * Server side transport handle
  83.  */
  84. typedef struct {
  85.     int        xp_sock;
  86.     u_short        xp_port;     /* associated port number */
  87.     struct xp_ops {
  88.         bool_t    (*xp_recv)();     /* receive incomming requests */
  89.         enum xprt_stat (*xp_stat)(); /* get transport status */
  90.         bool_t    (*xp_getargs)(); /* get arguments */
  91.         bool_t    (*xp_reply)();     /* send reply */
  92.         bool_t    (*xp_freeargs)();/* free mem allocated for args */
  93.         void    (*xp_destroy)(); /* destroy this struct */
  94.     } *xp_ops;
  95.     int        xp_addrlen;     /* length of remote address */
  96.     struct sockaddr_in xp_raddr;     /* remote address */
  97.     struct opaque_auth xp_verf;     /* raw response verifier */
  98.     caddr_t        xp_p1;         /* private */
  99.     caddr_t        xp_p2;         /* private */
  100. } SVCXPRT;
  101.  
  102. /*
  103.  *  Approved way of getting address of caller
  104.  */
  105. #define svc_getcaller(x) (&(x)->xp_raddr)
  106.  
  107. /*
  108.  * Operations defined on an SVCXPRT handle
  109.  *
  110.  * SVCXPRT        *xprt;
  111.  * struct rpc_msg    *msg;
  112.  * xdrproc_t         xargs;
  113.  * caddr_t         argsp;
  114.  */
  115. #define SVC_RECV(xprt, msg)                \
  116.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  117. #define svc_recv(xprt, msg)                \
  118.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  119.  
  120. #define SVC_STAT(xprt)                    \
  121.     (*(xprt)->xp_ops->xp_stat)(xprt)
  122. #define svc_stat(xprt)                    \
  123.     (*(xprt)->xp_ops->xp_stat)(xprt)
  124.  
  125. #define SVC_GETARGS(xprt, xargs, argsp)            \
  126.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  127. #define svc_getargs(xprt, xargs, argsp)            \
  128.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  129.  
  130. #define SVC_REPLY(xprt, msg)                \
  131.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  132. #define svc_reply(xprt, msg)                \
  133.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  134.  
  135. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  136.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  137. #define svc_freeargs(xprt, xargs, argsp)        \
  138.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  139.  
  140. #define SVC_DESTROY(xprt)                \
  141.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  142. #define svc_destroy(xprt)                \
  143.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  144.  
  145.  
  146. /*
  147.  * Service request
  148.  */
  149. struct svc_req {
  150.     u_long        rq_prog;    /* service program number */
  151.     u_long        rq_vers;    /* service protocol version */
  152.     u_long        rq_proc;    /* the desired procedure */
  153.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  154.     caddr_t        rq_clntcred;    /* read only cooked cred */
  155.     SVCXPRT    *rq_xprt;        /* associated transport */
  156. };
  157.  
  158.  
  159. /*
  160.  * Service registration
  161.  *
  162.  * svc_register(xprt, prog, vers, dispatch, protocol)
  163.  *    SVCXPRT *xprt;
  164.  *    u_long prog;
  165.  *    u_long vers;
  166.  *    void (*dispatch)();
  167.  *    int protocol;   * like TCP or UDP, zero means do not register 
  168.  */
  169. extern bool_t    svc_register();
  170.  
  171. /*
  172.  * Service un-registration
  173.  *
  174.  * svc_unregister(prog, vers)
  175.  *    u_long prog;
  176.  *    u_long vers;
  177.  */
  178. extern void    svc_unregister();
  179.  
  180. /*
  181.  * Transport registration.
  182.  *
  183.  * xprt_register(xprt)
  184.  *    SVCXPRT *xprt;
  185.  */
  186. extern void    xprt_register();
  187.  
  188. /*
  189.  * Transport un-register
  190.  *
  191.  * xprt_unregister(xprt)
  192.  *    SVCXPRT *xprt;
  193.  */
  194. extern void    xprt_unregister();
  195.  
  196.  
  197.  
  198.  
  199. /*
  200.  * When the service routine is called, it must first check to see if it
  201.  * knows about the procedure;  if not, it should call svcerr_noproc
  202.  * and return.  If so, it should deserialize its arguments via 
  203.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  204.  * svcerr_decode should be called followed by a return.  Successful
  205.  * decoding of the arguments should be followed the execution of the
  206.  * procedure's code and a call to svc_sendreply.
  207.  *
  208.  * Also, if the service refuses to execute the procedure due to too-
  209.  * weak authentication parameters, svcerr_weakauth should be called.
  210.  * Note: do not confuse access-control failure with weak authentication!
  211.  *
  212.  * NB: In pure implementations of rpc, the caller always waits for a reply
  213.  * msg.  This message is sent when svc_sendreply is called.  
  214.  * Therefore pure service implementations should always call
  215.  * svc_sendreply even if the function logically returns void;  use
  216.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  217.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  218.  * case of a batched call, svc_sendreply should NOT be called since
  219.  * this would send a return message, which is what batching tries to avoid.
  220.  * It is the service/protocol writer's responsibility to know which calls are
  221.  * batched and which are not.  Warning: responding to batch calls may
  222.  * deadlock the caller and server processes!
  223.  */
  224.  
  225. extern bool_t    svc_sendreply();
  226. extern void    svcerr_decode();
  227. extern void    svcerr_weakauth();
  228. extern void    svcerr_noproc();
  229. extern void    svcerr_progvers();
  230. extern void    svcerr_auth();
  231. extern void    svcerr_noprog();
  232. extern void    svcerr_systemerr();
  233.     
  234. /*
  235.  * Lowest level dispatching -OR- who owns this process anyway.
  236.  * Somebody has to wait for incoming requests and then call the correct
  237.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  238.  * svc_run never returns.
  239.  * Since another (co-existant) package may wish to selectively wait for
  240.  * incoming calls or other events outside of the rpc architecture, the
  241.  * routine svc_getreq is provided.  It must be passed readfds, the
  242.  * "in-place" results of a select system call (see select, section 2).
  243.  */
  244.  
  245. /*
  246.  * Global keeper of rpc service descriptors in use
  247.  * dynamic; must be inspected before each call to select 
  248.  */
  249. #ifdef FD_SETSIZE
  250. extern fd_set svc_fdset;
  251. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  252. #else
  253. extern int svc_fds;
  254. #endif /* def FD_SETSIZE */
  255.  
  256. /*
  257.  * a small program implemented by the svc_rpc implementation itself;
  258.  * also see clnt.h for protocol numbers.
  259.  */
  260. extern void rpctest_service();
  261.  
  262. extern void    svc_getreq();
  263. extern void    svc_getreqset();    /* takes fdset instead of int */
  264. extern void    svc_run();      /* never returns */
  265.  
  266. /*
  267.  * Socket to use on svcxxx_create call to get default socket
  268.  */
  269. #define    RPC_ANYSOCK    -1
  270.  
  271. /*
  272.  * These are the existing service side transport implementations
  273.  */
  274.  
  275. /*
  276.  * Memory based rpc for testing and timing.
  277.  */
  278. extern SVCXPRT *svcraw_create();
  279.  
  280. /*
  281.  * Udp based rpc.
  282.  */
  283. extern SVCXPRT *svcudp_create();
  284. extern SVCXPRT *svcudp_bufcreate();
  285.  
  286. /*
  287.  * Tcp based rpc.
  288.  */
  289. extern SVCXPRT *svctcp_create();
  290.  
  291.  
  292.  
  293. #endif !__SVC_HEADER__
  294.  
  295. /* EOF svc.h */
  296.