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 / clnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-04  |  9.0 KB  |  353 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: @(#)clnt.h 1.31 88/02/08 SMI
  31.  *    from: @(#)clnt.h    2.1 88/07/29 4.0 RPCSRC
  32.  *    clnt.h,v 1.3 1995/05/30 04:55:14 rgrimes Exp
  33.  */
  34.  
  35. /*
  36.  * clnt.h - Client side remote procedure call interface.
  37.  *
  38.  * Copyright (C) 1984, Sun Microsystems, Inc.
  39.  */
  40.  
  41. #ifndef _RPC_CLNT_H_
  42. #define _RPC_CLNT_H_
  43.  
  44. #if defined(__cplusplus)
  45. extern "C" {
  46. #endif
  47.  
  48. /*
  49.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  50.  * since each implementation is required to live with this (implementation
  51.  * independent) list of errors.
  52.  */
  53. enum clnt_stat {
  54.     RPC_SUCCESS=0,            /* call succeeded */
  55.     /*
  56.      * local errors
  57.      */
  58.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  59.     RPC_CANTDECODERES=2,        /* can't decode results */
  60.     RPC_CANTSEND=3,            /* failure in sending call */
  61.     RPC_CANTRECV=4,            /* failure in receiving result */
  62.     RPC_TIMEDOUT=5,            /* call timed out */
  63.     /*
  64.      * remote errors
  65.      */
  66.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  67.     RPC_AUTHERROR=7,        /* authentication error */
  68.     RPC_PROGUNAVAIL=8,        /* program not available */
  69.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  70.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  71.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  72.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  73.  
  74.     /*
  75.      * callrpc & clnt_create errors
  76.      */
  77.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  78.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  79.  
  80.     /*
  81.      * _ create errors
  82.      */
  83.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  84.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  85.     /*
  86.      * unspecified error
  87.      */
  88.     RPC_FAILED=16
  89. };
  90.  
  91.  
  92. /*
  93.  * Error info.
  94.  */
  95. struct rpc_err {
  96.     enum clnt_stat re_status;
  97.     union {
  98.         int RE_errno;        /* realated system error */
  99.         enum auth_stat RE_why;    /* why the auth error occurred */
  100.         struct {
  101.             u_long low;    /* lowest verion supported */
  102.             u_long high;    /* highest verion supported */
  103.         } RE_vers;
  104.         struct {        /* maybe meaningful if RPC_FAILED */
  105.             long s1;
  106.             long s2;
  107.         } RE_lb;        /* life boot & debugging only */
  108.     } ru;
  109. #define    re_errno    ru.RE_errno
  110. #define    re_why        ru.RE_why
  111. #define    re_vers        ru.RE_vers
  112. #define    re_lb        ru.RE_lb
  113. };
  114.  
  115.  
  116. /*
  117.  * Client rpc handle.
  118.  * Created by individual implementations, see e.g. rpc_udp.c.
  119.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  120.  */
  121. typedef struct {
  122.     AUTH    *cl_auth;            /* authenticator */
  123.     struct clnt_ops {
  124.         enum clnt_stat    (*cl_call)();    /* call remote procedure */
  125.         void        (*cl_abort)();    /* abort a call */
  126.         void        (*cl_geterr)();    /* get specific error code */
  127.         bool_t        (*cl_freeres)(); /* frees results */
  128.         void        (*cl_destroy)();/* destroy this structure */
  129.         bool_t          (*cl_control)();/* the ioctl() of rpc */
  130.     } *cl_ops;
  131.     caddr_t            cl_private;    /* private stuff */
  132. } CLIENT;
  133.  
  134.  
  135. /*
  136.  * client side rpc interface ops
  137.  *
  138.  * Parameter types are:
  139.  *
  140.  */
  141.  
  142. /*
  143.  * enum clnt_stat
  144.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  145.  *     CLIENT *rh;
  146.  *    u_long proc;
  147.  *    xdrproc_t xargs;
  148.  *    caddr_t argsp;
  149.  *    xdrproc_t xres;
  150.  *    caddr_t resp;
  151.  *    struct timeval timeout;
  152.  */
  153. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  154.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  155. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  156.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  157.  
  158. /*
  159.  * void
  160.  * CLNT_ABORT(rh);
  161.  *     CLIENT *rh;
  162.  */
  163. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  164. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  165.  
  166. /*
  167.  * struct rpc_err
  168.  * CLNT_GETERR(rh);
  169.  *     CLIENT *rh;
  170.  */
  171. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  172. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  173.  
  174.  
  175. /*
  176.  * bool_t
  177.  * CLNT_FREERES(rh, xres, resp);
  178.  *     CLIENT *rh;
  179.  *    xdrproc_t xres;
  180.  *    caddr_t resp;
  181.  */
  182. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  183. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  184.  
  185. /*
  186.  * bool_t
  187.  * CLNT_CONTROL(cl, request, info)
  188.  *      CLIENT *cl;
  189.  *      u_int request;
  190.  *      char *info;
  191.  */
  192. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  193. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  194.  
  195. /*
  196.  * control operations that apply to both udp and tcp transports
  197.  */
  198. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  199. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  200. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  201. /*
  202.  * udp only control operations
  203.  */
  204. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  205. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  206.  
  207. /*
  208.  * void
  209.  * CLNT_DESTROY(rh);
  210.  *     CLIENT *rh;
  211.  */
  212. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  213. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  214.  
  215.  
  216. /*
  217.  * RPCTEST is a test program which is accessable on every rpc
  218.  * transport/port.  It is used for testing, performance evaluation,
  219.  * and network administration.
  220.  */
  221.  
  222. #define RPCTEST_PROGRAM        ((u_long)1)
  223. #define RPCTEST_VERSION        ((u_long)1)
  224. #define RPCTEST_NULL_PROC    ((u_long)2)
  225. #define RPCTEST_NULL_BATCH_PROC    ((u_long)3)
  226.  
  227. /*
  228.  * By convention, procedure 0 takes null arguments and returns them
  229.  */
  230.  
  231. #define NULLPROC ((u_long)0)
  232.  
  233. /*
  234.  * Below are the client handle creation routines for the various
  235.  * implementations of client side rpc.  They can return NULL if a
  236.  * creation failure occurs.
  237.  */
  238.  
  239. /*
  240.  * Memory based rpc (for speed check and testing)
  241.  * CLIENT *
  242.  * clntraw_create(prog, vers)
  243.  *    u_long prog;
  244.  *    u_long vers;
  245.  */
  246. CLIENT *clntraw_create    (u_long, u_long);
  247.  
  248.  
  249. /*
  250.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  251.  * CLIENT *
  252.  * clnt_create(host, prog, vers, prot);
  253.  *    char *host;     -- hostname
  254.  *    u_long prog;    -- program number
  255.  *    u_long vers;    -- version number
  256.  *    char *prot;    -- protocol
  257.  */
  258. CLIENT *clnt_create    (char *, u_long, u_long, char *);
  259.  
  260.  
  261. /*
  262.  * TCP based rpc
  263.  * CLIENT *
  264.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  265.  *    struct sockaddr_in *raddr;
  266.  *    u_long prog;
  267.  *    u_long version;
  268.  *    register int *sockp;
  269.  *    u_int sendsz;
  270.  *    u_int recvsz;
  271.  */
  272. CLIENT *clnttcp_create    (struct sockaddr_in *,
  273.                      u_long,
  274.                      u_long,
  275.                      int *,
  276.                      u_int,
  277.                      u_int);
  278.  
  279.  
  280. /*
  281.  * UDP based rpc.
  282.  * CLIENT *
  283.  * clntudp_create(raddr, program, version, wait, sockp)
  284.  *    struct sockaddr_in *raddr;
  285.  *    u_long program;
  286.  *    u_long version;
  287.  *    struct timeval wait;
  288.  *    int *sockp;
  289.  *
  290.  * Same as above, but you specify max packet sizes.
  291.  * CLIENT *
  292.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  293.  *    struct sockaddr_in *raddr;
  294.  *    u_long program;
  295.  *    u_long version;
  296.  *    struct timeval wait;
  297.  *    int *sockp;
  298.  *    u_int sendsz;
  299.  *    u_int recvsz;
  300.  */
  301. CLIENT *clntudp_create    (struct sockaddr_in *,
  302.                      u_long,
  303.                      u_long,
  304.                      struct timeval,
  305.                      int *);
  306. CLIENT *clntudp_bufcreate (struct sockaddr_in *,
  307.                      u_long,
  308.                      u_long,
  309.                      struct timeval,
  310.                      int *,
  311.                      u_int,
  312.                      u_int);
  313.  
  314.  
  315. /*
  316.  * Print why creation failed
  317.  */
  318. void clnt_pcreateerror        (char *);            /* stderr */
  319. char *clnt_spcreateerror    (char *);            /* string */
  320.  
  321. /*
  322.  * Like clnt_perror(), but is more verbose in its output
  323.  */
  324. void clnt_perrno        (enum clnt_stat);        /* stderr */
  325. char *clnt_sperrno        (enum clnt_stat);        /* string */
  326.  
  327. /*
  328.  * Print an English error message, given the client error code
  329.  */
  330. void clnt_perror        (CLIENT *, char *);     /* stderr */
  331. char *clnt_sperror        (CLIENT *, char *);    /* string */
  332.  
  333.  
  334. /*
  335.  * If a creation fails, the following allows the user to figure out why.
  336.  */
  337. struct rpc_createerr {
  338.     enum clnt_stat cf_stat;
  339.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  340. };
  341.  
  342. extern struct rpc_createerr rpc_createerr;
  343.  
  344.  
  345. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  346. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  347.  
  348. #if defined(__cplusplus)
  349. }
  350. #endif
  351.  
  352. #endif /* !_RPC_CLNT_H */
  353.