home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / xdr.zip / XDR.H
Text File  |  1992-12-30  |  17KB  |  392 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. /*
  14.  *     This product contains:
  15.  *              "Restricted Materials of IBM"
  16.  *              (c) Copyright IBM Corp. 1987
  17.  *              All Rights Reserved
  18.  *              Licensed Materials-Property of IBM
  19.  *
  20.  *     See Copyright Instructions, G120-2083
  21.  *
  22.  * $Header:   R:\include\rpc\xdr.h_v   1.0   22 Dec 1988 13:56:26   Philip Shafer/2  $
  23.  *
  24.  * $Log:   R:\include\rpc\xdr.h_v  $
  25.  *
  26.  *    Rev 1.0   22 Dec 1988 13:56:26   Philip Shafer/2
  27.  * Initial revision.
  28.  *
  29.  * @(#)xdr.h    1.1 87/11/04 3.9 RPCSRC
  30.  *
  31.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  32.  * unrestricted use provided that this legend is included on all tape
  33.  * media and as a part of the software program in whole or part.  Users
  34.  * may copy or modify Sun RPC without charge, but are not authorized
  35.  * to license or distribute it to anyone else except as part of a product or
  36.  * program developed by the user.
  37.  *
  38.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  39.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  40.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  41.  *
  42.  * Sun RPC is provided with no support and without any obligation on the
  43.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  44.  * modification or enhancement.
  45.  *
  46.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  47.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  48.  * OR ANY PART THEREOF.
  49.  *
  50.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  51.  * or profits or other special, indirect and consequential damages, even if
  52.  * Sun has been advised of the possibility of such damages.
  53.  *
  54.  * Sun Microsystems, Inc.
  55.  * 2550 Garcia Avenue
  56.  * Mountain View, California  94043
  57.  *
  58.  *      @(#)xdr.h 1.19 87/04/22 SMI
  59.  *
  60.  * xdr.h, External Data Representation Serialization Routines.
  61.  *
  62.  * Copyright (C) 1984, Sun Microsystems, Inc.
  63.  *
  64.  * XDR provides a conventional way for converting between C data
  65.  * types and an external bit-string representation.  Library supplied
  66.  * routines provide for the conversion on built-in C data types.  These
  67.  * routines and utility routines defined here are used to help implement
  68.  * a type encode/decode routine for each user-defined type.
  69.  *
  70.  * Each data type provides a single procedure which takes two arguments:
  71.  *
  72.  *      bool_t
  73.  *      xdrproc(xdrs, argresp)
  74.  *              XDR *xdrs;
  75.  *              <type> *argresp;
  76.  *
  77.  * xdrs is an instance of a XDR handle, to which or from which the data
  78.  * type is to be converted.  argresp is a pointer to the structure to be
  79.  * converted.  The XDR handle contains an operation field which indicates
  80.  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
  81.  *
  82.  * XDR_DECODE may allocate space if the pointer argresp is null.  This
  83.  * data can be freed with the XDR_FREE operation.
  84.  *
  85.  * We write only one procedure per data type to make it easy
  86.  * to keep the encode and decode procedures for a data type consistent.
  87.  * In many cases the same code performs all operations on a user defined type,
  88.  * because all the hard work is done in the component type routines.
  89.  * decode as a series of calls on the nested data types.
  90.  */
  91. #ifndef RPC_XDR_H
  92. #define RPC_XDR_H
  93. #ifndef __32BIT__
  94. #define _Packed
  95. #define _Seg16
  96. #define _Far16
  97. #define _Cdecl
  98. #endif
  99.  
  100.  
  101. /*
  102.  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
  103.  * stream.  XDR_DECODE causes the type to be extracted from the stream.
  104.  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
  105.  * request.
  106.  */
  107. enum xdr_op {
  108.         XDR_ENCODE=0,
  109.         XDR_DECODE=1,
  110.         XDR_FREE=2
  111. #ifdef __32BIT__
  112.         , XDR_DUMMY=32767
  113. #endif
  114. };
  115.  
  116. /*
  117.  * This is the number of bytes per unit of external data.
  118.  */
  119. #define BYTES_PER_XDR_UNIT      (4)
  120. #define RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
  121.                     * BYTES_PER_XDR_UNIT)
  122.  
  123. /*
  124.  * A xdrproc_t exists for each data type which is to be encoded or decoded.
  125.  *
  126.  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
  127.  * The opaque pointer generally points to a structure of the data type
  128.  * to be decoded.  If this pointer is 0, then the type routines should
  129.  * allocate dynamic storage of the appropriate size and return it.
  130.  * bool_t       (*xdrproc_t)(XDR *, caddr_t *);
  131.  */
  132.  
  133. /*
  134.  * The XDR handle.
  135.  * Contains operation which is being applied to the stream,
  136.  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
  137.  * and two private fields for the use of the particular impelementation.
  138.  */
  139. typedef _Packed struct _XDR {
  140.         enum xdr_op     x_op;           /* operation; fast additional param */
  141.         struct xdr_ops {
  142.                 bool_t  (* _Seg16 _Far16 _Cdecl x_getlong)(_Packed struct _XDR * _Seg16,void * _Seg16); /* get a long from underlying stream */
  143.                 bool_t  (* _Seg16 _Far16 _Cdecl x_putlong)(_Packed struct _XDR * _Seg16,void * _Seg16); /* put a long to " */
  144.                 bool_t  (* _Seg16 _Far16 _Cdecl x_getbytes)(_Packed struct _XDR * _Seg16,void * _Seg16,short);/* get some bytes from " */
  145.                 bool_t  (* _Seg16 _Far16 _Cdecl x_putbytes)(_Packed struct _XDR * _Seg16,void * _Seg16,short);/* put some bytes to " */
  146.                 u_int   (* _Seg16 _Far16 _Cdecl x_getpostn)(_Packed struct _XDR * _Seg16);/* returns bytes off from beginning */
  147.                 bool_t  (* _Seg16 _Far16 _Cdecl x_setpostn)(_Packed struct _XDR * _Seg16);/* lets you reposition the stream */
  148.                 long * _Seg16 (* _Seg16 _Far16 _Cdecl x_inline)(_Packed struct _XDR * _Seg16,short);  /* buf quick ptr to buffered data */
  149.                 void    (* _Seg16 _Far16 _Cdecl x_destroy)(_Packed struct _XDR * _Seg16,short); /* free privates of this xdr_stream */
  150.         } * _Seg16 x_ops;
  151.         char * _Seg16   x_public;       /* users' data */
  152.         char * _Seg16   x_private;      /* pointer to private data */
  153.         char * _Seg16   x_base;         /* private used for position info */
  154.         short           x_handy;        /* extra private word */
  155. } XDR;
  156.  
  157. //typedef bool_t (* _Seg16 _Far16 _Cdecl xdrproc_t)(XDR * _Seg16,void * _Seg16);
  158. #ifdef __32BIT__
  159. #pragma checkout(suspend)
  160. #endif
  161. typedef bool_t (* _Seg16 _Far16 _Cdecl xdrproc_t)();
  162. #ifdef __32BIT__
  163. #pragma checkout(resume)
  164. #endif
  165. /*
  166.  * Operations defined on a XDR handle
  167.  *
  168.  * XDR          *xdrs;
  169.  * long         *longp;
  170.  * caddr_t       addr;
  171.  * u_int         len;
  172.  * u_int         pos;
  173.  */
  174. #define XDR_GETLONG(xdrs, longp)                        \
  175.         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
  176. #define xdr_getlong(xdrs, longp)                        \
  177.         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
  178.  
  179. #define XDR_PUTLONG(xdrs, longp)                        \
  180.         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
  181. #define xdr_putlong(xdrs, longp)                        \
  182.         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
  183.  
  184. #define XDR_GETBYTES(xdrs, addr, len)                   \
  185.         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
  186. #define xdr_getbytes(xdrs, addr, len)                   \
  187.         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
  188.  
  189. #define XDR_PUTBYTES(xdrs, addr, len)                   \
  190.         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
  191. #define xdr_putbytes(xdrs, addr, len)                   \
  192.         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
  193.  
  194. #define XDR_GETPOS(xdrs)                                \
  195.         (*(xdrs)->x_ops->x_getpostn)(xdrs)
  196. #define xdr_getpos(xdrs)                                \
  197.         (*(xdrs)->x_ops->x_getpostn)(xdrs)
  198.  
  199. #define XDR_SETPOS(xdrs, pos)                           \
  200.         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
  201. #define xdr_setpos(xdrs, pos)                           \
  202.         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
  203.  
  204. #define XDR_INLINE(xdrs, len)                           \
  205.         (*(xdrs)->x_ops->x_inline)(xdrs, len)
  206. #define xdr_inline(xdrs, len)                           \
  207.         (*(xdrs)->x_ops->x_inline)(xdrs, len)
  208.  
  209. #define XDR_DESTROY(xdrs)                               \
  210.         if ((xdrs)->x_ops->x_destroy)                   \
  211.                 (*(xdrs)->x_ops->x_destroy)(xdrs)
  212. #define xdr_destroy(xdrs)                               \
  213.         if ((xdrs)->x_ops->x_destroy)                   \
  214.                 (*(xdrs)->x_ops->x_destroy)(xdrs)
  215.  
  216. /*
  217.  * Support struct for discriminated unions.
  218.  * You create an array of xdrdiscrim structures, terminated with
  219.  * a entry with a null procedure pointer.  The xdr_union routine gets
  220.  * the discriminant value and then searches the array of structures
  221.  * for a matching value.  If a match is found the associated xdr routine
  222.  * is called to handle that part of the union.  If there is
  223.  * no match, then a default routine may be called.
  224.  * If there is no match and no default routine it is an error.
  225.  */
  226. #define NULL_xdrproc_t ((xdrproc_t)0)
  227. _Packed struct xdr_discrim {
  228.         short   value;
  229.         xdrproc_t proc;
  230. };
  231.  
  232. /*
  233.  * In-line routines for fast encode/decode of primitve data types.
  234.  * Caveat emptor: these use single memory cycles to get the
  235.  * data from the underlying buffer, and will fail to operate
  236.  * properly if the data is not aligned.  The standard way to use these
  237.  * is to say:
  238.  *      if ((buf = XDR_INLINE(xdrs, count)) == NULL)
  239.  *              return (FALSE);
  240.  *      <<< macro calls >>>
  241.  * where ``count'' is the number of bytes of data occupied
  242.  * by the primitive data types.
  243.  *
  244.  * N.B. and frozen for all time: each data type here uses 4 bytes
  245.  * of external representation.
  246.  */
  247. #define IXDR_GET_LONG(buf)              ((long)ntohl((u_long)*(buf)++))
  248. #define IXDR_PUT_LONG(buf, v)           (*(buf)++ = (long)htonl((u_long)v))
  249.  
  250. #define IXDR_GET_BOOL(buf)              ((bool_t)IXDR_GET_LONG(buf))
  251. #define IXDR_GET_ENUM(buf, t)           ((t)IXDR_GET_LONG(buf))
  252. #define IXDR_GET_U_LONG(buf)            ((u_long)IXDR_GET_LONG(buf))
  253. #define IXDR_GET_SHORT(buf)             ((short)IXDR_GET_LONG(buf))
  254. #define IXDR_GET_U_SHORT(buf)           ((u_short)IXDR_GET_LONG(buf))
  255.  
  256. #define IXDR_PUT_BOOL(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
  257. #define IXDR_PUT_ENUM(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
  258. #define IXDR_PUT_U_LONG(buf, v)         IXDR_PUT_LONG((buf), ((long)(v)))
  259. #define IXDR_PUT_SHORT(buf, v)          IXDR_PUT_LONG((buf), ((long)(v)))
  260. #define IXDR_PUT_U_SHORT(buf, v)        IXDR_PUT_LONG((buf), ((long)(v)))
  261.  
  262. /*
  263.  * These are the "generic" xdr routines.
  264.  */
  265. #if 0
  266. extern bool_t   xdr_void();
  267. extern bool_t   xdr_int();
  268. extern bool_t   xdr_u_int();
  269. extern bool_t   xdr_long();
  270. extern bool_t   xdr_u_long();
  271. extern bool_t   xdr_short();
  272. extern bool_t   xdr_u_short();
  273. extern bool_t   xdr_bool();
  274. extern bool_t   xdr_enum();
  275. extern bool_t   xdr_array();
  276. extern bool_t   xdr_bytes();
  277. extern bool_t   xdr_opaque();
  278. extern bool_t   xdr_string();
  279. extern bool_t   xdr_union();
  280. extern bool_t   xdr_char();
  281. extern bool_t   xdr_u_char();
  282. extern bool_t   xdr_vector();
  283. extern bool_t   xdr_float();
  284. extern bool_t   xdr_double();
  285. extern bool_t   xdr_reference();
  286. extern bool_t   xdr_pointer();
  287. extern bool_t   xdr_wrapstring();
  288. #endif
  289.  
  290. /*
  291.  * Common opaque bytes objects used by many rpc protocols;
  292.  * declared here due to commonality.
  293.  */
  294. #define MAX_NETOBJ_SZ 1024
  295. _Packed struct netobj {
  296.         u_short n_len;
  297.         char    * _Seg16 n_bytes;
  298. };
  299. typedef _Packed struct netobj netobj;
  300.  
  301. /*
  302.  * These are the public routines for the various implementations of
  303.  * xdr streams.
  304.  */
  305. #ifdef __32BIT__
  306. #pragma linkage(xdr_accepted_reply,far16 cdecl)
  307. #pragma linkage(xdr_array,far16 cdecl)
  308. #pragma linkage(xdr_bool,far16 cdecl)
  309. #pragma linkage(xdr_bytes,far16 cdecl)
  310. #pragma linkage(xdr_callhdr,far16 cdecl)
  311. #pragma linkage(xdr_callmsg,far16 cdecl)
  312. #pragma linkage(xdr_char,far16 cdecl)
  313. #pragma linkage(xdr_deskey,far16 cdecl)
  314. #pragma linkage(xdr_double,far16 cdecl)
  315. #pragma linkage(xdr_enum,far16 cdecl)
  316. #pragma linkage(xdr_float,far16 cdecl)
  317. #pragma linkage(xdr_free,far16 cdecl)
  318. #pragma linkage(xdr_int,far16 cdecl)
  319. #pragma linkage(xdr_long,far16 cdecl)
  320. #pragma linkage(xdr_netobj,far16 cdecl)
  321. #pragma linkage(xdr_opaque,far16 cdecl)
  322. #pragma linkage(xdr_opaque_auth,far16 cdecl)
  323. #pragma linkage(xdr_pointer,far16 cdecl)
  324. #pragma linkage(xdr_reference,far16 cdecl)
  325. #pragma linkage(xdr_rejected_reply,far16 cdecl)
  326. #pragma linkage(xdr_replymsg,far16 cdecl)
  327. #pragma linkage(xdr_short,far16 cdecl)
  328. #pragma linkage(xdr_string,far16 cdecl)
  329. #pragma linkage(xdr_u_char,far16 cdecl)
  330. #pragma linkage(xdr_u_int,far16 cdecl)
  331. #pragma linkage(xdr_u_long,far16 cdecl)
  332. #pragma linkage(xdr_u_short,far16 cdecl)
  333. #pragma linkage(xdr_union,far16 cdecl)
  334. #pragma linkage(xdr_vector,far16 cdecl)
  335. #pragma linkage(xdr_void,far16 cdecl)
  336. #pragma linkage(xdr_wrapstring,far16 cdecl)
  337. #pragma linkage(xdrmem_create,far16 cdecl)
  338. #pragma linkage(xdrrec_create,far16 cdecl)
  339. #pragma linkage(xdrrec_endofrecord,far16 cdecl)
  340. #pragma linkage(xdrrec_eof,far16 cdecl)
  341. #pragma linkage(xdrrec_skiprecord,far16 cdecl)
  342. #pragma linkage(xdrstdio_create,far16 cdecl)
  343. #endif
  344. bool_t   xdr_accepted_reply(XDR * , void * );
  345. bool_t   xdr_array(XDR * , char *  * , u_short * , u_short, u_short, xdrproc_t);
  346. bool_t   xdr_bool(XDR * , short * );
  347. bool_t   xdr_bytes(XDR * , char * *, u_short * , u_long); // kludge here ... last parm should be u_short, but C Set/2 does not accept (?)
  348. bool_t   xdr_callhdr( XDR * , void * );
  349. bool_t   xdr_callmsg(XDR * , void * );
  350. bool_t   xdr_char( XDR * , char * );
  351. bool_t   xdr_deskey(XDR * , void * );
  352. bool_t   xdr_double(XDR * , double * );
  353. bool_t   xdr_enum(XDR * ,void * );
  354. bool_t   xdr_float(  XDR * , float * );
  355. bool_t   xdr_int( XDR * , short * );
  356. bool_t   xdr_long(XDR * , long * );
  357. bool_t   xdr_netobj( XDR * , _Packed struct netobj * );
  358. bool_t   xdr_opaque(XDR * , void * , u_long); // s/b u_short for last parm
  359. bool_t   xdr_opaque_auth(XDR * , void * );
  360. bool_t   xdr_pointer(XDR * , char * * , u_short, xdrproc_t);
  361. bool_t   xdr_reference(XDR * , void *  * , u_short, xdrproc_t);
  362. bool_t   xdr_rejected_reply(XDR * , void * );
  363. bool_t   xdr_replymsg(XDR * , void * );
  364. bool_t   xdr_short(XDR * , short * );
  365. bool_t   xdr_string(XDR * ,char * * , u_long);  // s/b u_short for last parm
  366. bool_t   xdr_u_char( XDR * , u_char * );
  367. bool_t   xdr_u_int( XDR * , u_short * );
  368. bool_t   xdr_u_long(XDR * ,u_long * );
  369. bool_t   xdr_u_short(XDR * , u_short * );
  370. bool_t   xdr_union(XDR * , enum_t * , char * , _Packed struct xdr_discrim * , xdrproc_t);
  371. bool_t   xdr_vector(XDR * , char * , u_short, u_short, xdrproc_t);
  372. bool_t   xdr_void(void);
  373. bool_t   xdr_wrapstring( XDR * , char * * );
  374. bool_t   xdrrec_endofrecord( XDR * , bool_t);
  375. bool_t   xdrrec_eof( XDR * );
  376. bool_t   xdrrec_skiprecord( XDR * );
  377. void     xdrmem_create(XDR *,void *,u_short,enum xdr_op);          /* XDR using memory buffers */
  378. void     xdrstdio_create(XDR *,void *,enum xdr_op);        /* XDR using stdio library */
  379. void   xdr_free( xdrproc_t , void * );
  380. void   xdrrec_create(XDR * , u_short,u_short, char * , short (*  )(void *,short,short), short (*  )(void *,void *,short));
  381. #ifdef __32BIT__
  382. #pragma checkout(suspend)
  383. short _Far16 _Cdecl registerrpc(unsigned long, unsigned long, unsigned long,
  384.   void * _Seg16 (* _Seg16 _Far16 _Cdecl myproc)(),
  385.   xdrproc_t,
  386.   xdrproc_t);
  387. #pragma checkout(resume)
  388. #else
  389. short _Far16 _Cdecl registerrpc();
  390. #endif
  391. #endif /* RPC_XDR_H */
  392.