home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / os2emx / rpc / svc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-04  |  8.8 KB  |  295 lines

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