Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xdr.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  * RPC for the Windows NT Operating System
00003  * 1993 by Martin F. Gergeleit
00004  * Users may use, copy or modify Sun RPC for the Windows NT Operating
00005  * System according to the Sun copyright below.
00006  *
00007  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
00008  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
00009  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
00010  *********************************************************************/
00011 
00012 /* @(#)xdr.h    2.2 88/07/29 4.0 RPCSRC */
00013 /*
00014  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00015  * unrestricted use provided that this legend is included on all tape
00016  * media and as a part of the software program in whole or part.  Users
00017  * may copy or modify Sun RPC without charge, but are not authorized
00018  * to license or distribute it to anyone else except as part of a product or
00019  * program developed by the user.
00020  *
00021  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00022  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00023  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00024  *
00025  * Sun RPC is provided with no support and without any obligation on the
00026  * part of Sun Microsystems, Inc. to assist in its use, correction,
00027  * modification or enhancement.
00028  *
00029  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00030  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00031  * OR ANY PART THEREOF.
00032  *
00033  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00034  * or profits or other special, indirect and consequential damages, even if
00035  * Sun has been advised of the possibility of such damages.
00036  *
00037  * Sun Microsystems, Inc.
00038  * 2550 Garcia Avenue
00039  * Mountain View, California  94043
00040  */
00041 /*      @(#)xdr.h 1.19 87/04/22 SMI      */
00042 
00043 /*
00044  * xdr.h, External Data Representation Serialization Routines.
00045  *
00046  * Copyright (C) 1984, Sun Microsystems, Inc.
00047  */
00048 
00049 #ifndef __XDR_HEADER__
00050 #define __XDR_HEADER__
00051 
00052 #if !defined(_WINDOWS) && !defined(WIN32)
00053 #error This version of XDR only for Windows NT.
00054 #endif
00055 
00056 
00057 // The file was originally types.h but I changed the name to
00058 // avoid conflicts with other types.h files.
00059 #include "xdrtypes.h"
00060 
00061 #define _X86_
00062 /*
00063  * XDR provides a conventional way for converting between C data
00064  * types and an external bit-string representation.  Library supplied
00065  * routines provide for the conversion on built-in C data types.  These
00066  * routines and utility routines defined here are used to help implement
00067  * a type encode/decode routine for each user-defined type.
00068  *
00069  * Each data type provides a single procedure which takes two arguments:
00070  *
00071  *      bool_t
00072  *      xdrproc(xdrs, argresp)
00073  *              XDR *xdrs;
00074  *              <type> *argresp;
00075  *
00076  * xdrs is an instance of a XDR handle, to which or from which the data
00077  * type is to be converted.  argresp is a pointer to the structure to be
00078  * converted.  The XDR handle contains an operation field which indicates
00079  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
00080  *
00081  * XDR_DECODE may allocate space if the pointer argresp is null.  This
00082  * data can be freed with the XDR_FREE operation.
00083  *
00084  * We write only one procedure per data type to make it easy
00085  * to keep the encode and decode procedures for a data type consistent.
00086  * In many cases the same code performs all operations on a user defined type,
00087  * because all the hard work is done in the component type routines.
00088  * decode as a series of calls on the nested data types.
00089  */
00090 
00091 /*
00092  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
00093  * stream.  XDR_DECODE causes the type to be extracted from the stream.
00094  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
00095  * request.
00096  */
00097 enum xdr_op {
00098         XDR_ENCODE=0,
00099         XDR_DECODE=1,
00100         XDR_FREE=2
00101 };
00102 
00103 /*
00104  * This is the number of bytes per unit of external data.
00105  */
00106 #define BYTES_PER_XDR_UNIT      (4)
00107 #define RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
00108                     * BYTES_PER_XDR_UNIT)
00109 
00110 /*
00111  * A xdrproc_t exists for each data type which is to be encoded or decoded.
00112  *
00113  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
00114  * The opaque pointer generally points to a structure of the data type
00115  * to be decoded.  If this pointer is 0, then the type routines should
00116  * allocate dynamic storage of the appropriate size and return it.
00117  * bool_t       (*xdrproc_t)(XDR *, caddr_t *);
00118  */
00119 typedef bool_t (*xdrproc_t)();
00120 
00121 /*
00122  * The XDR handle.
00123  * Contains operation which is being applied to the stream,
00124  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
00125  * and two private fields for the use of the particular impelementation.
00126  */
00127 
00128 #ifdef __cplusplus
00129 
00130 typedef struct {
00131         enum xdr_op     x_op;           /* operation; fast additional param */
00132         struct xdr_ops {
00133                 bool_t  (*x_getlong)(void *, long *);   /* get a long from underlying stream */
00134                 bool_t  (*x_putlong)(void *, long *);   /* put a long to " */
00135                 bool_t  (*x_getbytes)(void *, void *, int );/* get some bytes from " */
00136                 bool_t  (*x_putbytes)(void *, void *, int);/* put some bytes to " */
00137                 u_int   (*x_getpostn)(void *);/* returns bytes off from beginning */
00138                 bool_t  (*x_setpostn)(void *, int);/* lets you reposition the stream */
00139                 long *  (*x_inline)(void *, int);       /* buf quick ptr to buffered data */
00140                 void    (*x_destroy)(void *);   /* free privates of this xdr_stream */
00141         } *x_ops;
00142         caddr_t         x_public;       /* users' data */
00143         caddr_t         x_private;      /* pointer to private data */
00144         caddr_t         x_base;         /* private used for position info */
00145         int             x_handy;        /* extra private word */
00146 } XDR;
00147 
00148 #else
00149 
00150 typedef struct {
00151         enum xdr_op     x_op;           /* operation; fast additional param */
00152         struct xdr_ops {
00153                 bool_t  (*x_getlong)(); /* get a long from underlying stream */
00154                 bool_t  (*x_putlong)(); /* put a long to " */
00155                 bool_t  (*x_getbytes)();/* get some bytes from " */
00156                 bool_t  (*x_putbytes)();/* put some bytes to " */
00157                 u_int   (*x_getpostn)();/* returns bytes off from beginning */
00158                 bool_t  (*x_setpostn)();/* lets you reposition the stream */
00159                 long *  (*x_inline)();  /* buf quick ptr to buffered data */
00160                 void    (*x_destroy)(); /* free privates of this xdr_stream */
00161         } *x_ops;
00162         caddr_t         x_public;       /* users' data */
00163         caddr_t         x_private;      /* pointer to private data */
00164         caddr_t         x_base;         /* private used for position info */
00165         int             x_handy;        /* extra private word */
00166 } XDR;
00167 
00168 #endif
00169 
00170 /*
00171  * Operations defined on a XDR handle
00172  *
00173  * XDR          *xdrs;
00174  * long         *longp;
00175  * caddr_t       addr;
00176  * u_int         len;
00177  * u_int         pos;
00178  */
00179 #define XDR_GETLONG(xdrs, longp)                        \
00180         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
00181 #define xdr_getlong(xdrs, longp)                        \
00182         (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
00183 
00184 #define XDR_PUTLONG(xdrs, longp)                        \
00185         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
00186 #define xdr_putlong(xdrs, longp)                        \
00187         (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
00188 
00189 #define XDR_GETBYTES(xdrs, addr, len)                   \
00190         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
00191 #define xdr_getbytes(xdrs, addr, len)                   \
00192         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
00193 
00194 #define XDR_PUTBYTES(xdrs, addr, len)                   \
00195         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
00196 #define xdr_putbytes(xdrs, addr, len)                   \
00197         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
00198 
00199 #define XDR_GETPOS(xdrs)                                \
00200         (*(xdrs)->x_ops->x_getpostn)(xdrs)
00201 #define xdr_getpos(xdrs)                                \
00202         (*(xdrs)->x_ops->x_getpostn)(xdrs)
00203 
00204 #define XDR_SETPOS(xdrs, pos)                           \
00205         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
00206 #define xdr_setpos(xdrs, pos)                           \
00207         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
00208 
00209 #define XDR_INLINE(xdrs, len)                           \
00210         (*(xdrs)->x_ops->x_inline)(xdrs, len)
00211 #define xdr_inline(xdrs, len)                           \
00212         (*(xdrs)->x_ops->x_inline)(xdrs, len)
00213 
00214 #define XDR_DESTROY(xdrs)                               \
00215         if ((xdrs)->x_ops->x_destroy)                   \
00216                 (*(xdrs)->x_ops->x_destroy)(xdrs)
00217 #define xdr_destroy(xdrs)                               \
00218         if ((xdrs)->x_ops->x_destroy)                   \
00219                 (*(xdrs)->x_ops->x_destroy)(xdrs)
00220 
00221 /*
00222  * Support struct for discriminated unions.
00223  * You create an array of xdrdiscrim structures, terminated with
00224  * a entry with a null procedure pointer.  The xdr_union routine gets
00225  * the discriminant value and then searches the array of structures
00226  * for a matching value.  If a match is found the associated xdr routine
00227  * is called to handle that part of the union.  If there is
00228  * no match, then a default routine may be called.
00229  * If there is no match and no default routine it is an error.
00230  */
00231 #define NULL_xdrproc_t ((xdrproc_t)0)
00232 struct xdr_discrim {
00233         int     value;
00234         xdrproc_t proc;
00235 };
00236 
00237 /*
00238  * In-line routines for fast encode/decode of primitve data types.
00239  * Caveat emptor: these use single memory cycles to get the
00240  * data from the underlying buffer, and will fail to operate
00241  * properly if the data is not aligned.  The standard way to use these
00242  * is to say:
00243  *      if ((buf = XDR_INLINE(xdrs, count)) == NULL)
00244  *              return (FALSE);
00245  *      <<< macro calls >>>
00246  * where ``count'' is the number of bytes of data occupied
00247  * by the primitive data types.
00248  *
00249  * N.B. and frozen for all time: each data type here uses 4 bytes
00250  * of external representation.
00251  */
00252 #define IXDR_GET_LONG(buf)              ((long)ntohl((u_long)*(buf)++))
00253 #define IXDR_PUT_LONG(buf, v)           (*(buf)++ = (long)htonl((u_long)v))
00254 
00255 #define IXDR_GET_BOOL(buf)              ((bool_t)IXDR_GET_LONG(buf))
00256 #define IXDR_GET_ENUM(buf, t)           ((t)IXDR_GET_LONG(buf))
00257 #define IXDR_GET_U_LONG(buf)            ((u_long)IXDR_GET_LONG(buf))
00258 #define IXDR_GET_SHORT(buf)             ((short)IXDR_GET_LONG(buf))
00259 #define IXDR_GET_U_SHORT(buf)           ((u_short)IXDR_GET_LONG(buf))
00260 
00261 #define IXDR_PUT_BOOL(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
00262 #define IXDR_PUT_ENUM(buf, v)           IXDR_PUT_LONG((buf), ((long)(v)))
00263 #define IXDR_PUT_U_LONG(buf, v)         IXDR_PUT_LONG((buf), ((long)(v)))
00264 #define IXDR_PUT_SHORT(buf, v)          IXDR_PUT_LONG((buf), ((long)(v)))
00265 #define IXDR_PUT_U_SHORT(buf, v)        IXDR_PUT_LONG((buf), ((long)(v)))
00266 
00267 
00268 
00269 /*
00270  * Common opaque bytes objects used by many rpc protocols;
00271  * declared here due to commonality.
00272  */
00273 #define MAX_NETOBJ_SZ 1024
00274 struct netobj {
00275         u_int   n_len;
00276         char    *n_bytes;
00277 };
00278 typedef struct netobj netobj;
00279 extern bool_t   xdr_netobj();
00280 
00281 
00282 /*
00283  * These are the public routines for the various implementations of
00284  * xdr streams.
00285  */
00286 #ifdef __cplusplus
00287 void xdrmem_create(XDR *xdrs, caddr_t addr, u_int size, enum xdr_op op);
00288 
00289 /*
00290  * These are the "generic" xdr routines.
00291  */
00292 extern bool_t   xdr_void();
00293 extern bool_t   xdr_int(XDR *, int *);
00294 extern bool_t   xdr_u_int(XDR *, unsigned int *);
00295 extern bool_t   xdr_long(XDR *, long *);
00296 extern bool_t   xdr_u_long(XDR *,unsigned long *);
00297 extern bool_t   xdr_short(XDR *, short *);
00298 extern bool_t   xdr_u_short(XDR *, unsigned short *);
00299 extern bool_t   xdr_bool();
00300 extern bool_t   xdr_enum();
00301 extern bool_t   xdr_array();
00302 extern bool_t   xdr_bytes(XDR *, char **, unsigned int *, unsigned int);
00303 extern bool_t   xdr_opaque();
00304 extern bool_t   xdr_string();
00305 extern bool_t   xdr_union();
00306 extern bool_t   xdr_char(XDR *, char *);
00307 extern bool_t   xdr_u_char(XDR *, unsigned char *);
00308 extern bool_t   xdr_vector(XDR *, char *, int , int, xdrproc_t);
00309 extern bool_t   xdr_float(XDR *, float *);
00310 extern bool_t   xdr_double(XDR *, double *);
00311 extern bool_t   xdr_reference();
00312 extern bool_t   xdr_pointer();
00313 extern bool_t   xdr_wrapstring();
00314 
00315 #else
00316 
00317 /*
00318  * These are the "generic" xdr routines.
00319  */
00320 extern bool_t   xdr_void();
00321 extern bool_t   xdr_int();
00322 extern bool_t   xdr_u_int();
00323 extern bool_t   xdr_long();
00324 extern bool_t   xdr_u_long();
00325 extern bool_t   xdr_short();
00326 extern bool_t   xdr_u_short();
00327 extern bool_t   xdr_bool();
00328 extern bool_t   xdr_enum();
00329 extern bool_t   xdr_array();
00330 extern bool_t   xdr_bytes();
00331 extern bool_t   xdr_opaque();
00332 extern bool_t   xdr_string();
00333 extern bool_t   xdr_union();
00334 extern bool_t   xdr_char();
00335 extern bool_t   xdr_u_char();
00336 extern bool_t   xdr_vector();
00337 extern bool_t   xdr_float();
00338 extern bool_t   xdr_double();
00339 extern bool_t   xdr_reference();
00340 extern bool_t   xdr_pointer();
00341 extern bool_t   xdr_wrapstring();
00342 
00343 extern void   xdrmem_create();          /* XDR using memory buffers */
00344 #endif
00345 
00346 #if !defined(UNDER_CE) && !defined(WINDOWS_CE)
00347 extern void   xdrstdio_create();        /* XDR using stdio library */
00348 #endif
00349 
00350 extern void   xdrrec_create();          /* XDR pseudo records for tcp */
00351 extern bool_t xdrrec_endofrecord();     /* make end of xdr record */
00352 extern bool_t xdrrec_skiprecord();      /* move to beginning of next record */
00353 extern bool_t xdrrec_eof();             /* true if no more input */
00354 
00355 #endif /* __XDR_HEADER__ */

Generated on Sun Dec 2 15:56:54 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001