| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# xdr.h

Go to the documentation of this file.

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