home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / detk45he.zip / stack16 / rpc / svc.h < prev    next >
C/C++ Source or Header  |  1999-05-11  |  11KB  |  291 lines

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