rx-xdr-rename-userland-symbols-also-on-amd64-linux-20030627
[openafs.git] / src / rx / xdr.h
1 /*
2  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3  * unrestricted use provided that this legend is included on all tape
4  * media and as a part of the software program in whole or part.  Users
5  * may copy or modify Sun RPC without charge, but are not authorized
6  * to license or distribute it to anyone else except as part of a product or
7  * program developed by the user.
8  * 
9  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12  * 
13  * Sun RPC is provided with no support and without any obligation on the
14  * part of Sun Microsystems, Inc. to assist in its use, correction,
15  * modification or enhancement.
16  * 
17  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19  * OR ANY PART THEREOF.
20  * 
21  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22  * or profits or other special, indirect and consequential damages, even if
23  * Sun has been advised of the possibility of such damages.
24  * 
25  * Sun Microsystems, Inc.
26  * 2550 Garcia Avenue
27  * Mountain View, California  94043
28  */
29
30 /* This file has the contents of Sun's orginal types.h file added. */
31
32 /*      @(#)types.h 1.1 86/02/03 SMI      */
33
34 /*
35  * Rpc additions to <sys/types.h>
36  */
37
38 #ifndef __XDR_INCLUDE__
39 #define __XDR_INCLUDE__
40 #include <afs/param.h>
41 #ifdef AFS_NT40_ENV
42 #ifndef _MFC_VER
43 #include <winsock2.h>
44 #endif /* _MFC_VER */
45 #endif
46 #ifndef bool_t
47 #define bool_t  int
48 #define enum_t  int
49 #endif
50 #ifndef FALSE
51 #define FALSE   0
52 #endif /* !FALSE */
53 #ifndef TRUE
54 #define TRUE    1
55 #endif /* !TRUE */
56 #define __dontcare__    -1
57
58 #ifndef mem_alloc
59 #define mem_alloc(bsize)        malloc(bsize)
60 #endif
61
62 #ifndef mem_free
63 #define mem_free(ptr, bsize)    free(ptr)
64 #endif
65
66 #if defined(AFS_AMD64_LINUX24_ENV) || (defined(KERNEL) && !defined(UKERNEL))
67 #define xdr_void afs_xdr_void
68 #define xdr_int afs_xdr_int
69 #define xdr_u_int afs_xdr_u_int
70 #define xdr_short afs_xdr_short
71 #define xdr_u_short afs_xdr_u_short
72 #define xdr_long afs_xdr_long
73 #define xdr_u_long afs_xdr_u_long
74 #define xdr_char afs_xdr_char
75 #define xdr_u_char afs_xdr_u_char
76 #define xdr_bool afs_xdr_bool
77 #define xdr_enum afs_xdr_enum
78 #define xdr_array afs_xdr_array
79 #define xdr_arrayN afs_xdr_arrayN
80 #define xdr_bytes afs_xdr_bytes
81 #define xdr_opaque afs_xdr_opaque
82 #define xdr_string afs_xdr_string
83 #define xdr_union afs_xdr_union
84 #define xdr_float afs_xdr_float
85 #define xdr_double afs_xdr_double
86 #define xdr_reference afs_xdr_reference
87 #define xdr_wrapstring afs_xdr_wrapstring
88 #define xdr_vector afs_xdr_vector
89 #define xdr_int64 afs_xdr_int64
90 #define xdr_uint64 afs_xdr_uint64
91 #endif
92
93 #ifdef  KERNEL
94 #define osi_alloc               afs_osi_Alloc
95 #define osi_free                afs_osi_Free
96
97 /* keep here for now, 64 bit issues */
98 extern void *afs_osi_Alloc(size_t x);
99 extern void *afs_osi_Alloc_NoSleep(size_t x);
100 extern void afs_osi_Free(void *x, size_t asize);
101
102 #endif
103 #ifndef major           /* ouch! */
104 #include <sys/types.h>
105 #endif
106
107 /*      @(#)xdr.h 1.1 86/02/03 SMI      */
108
109 /*
110  * xdr.h, External Data Representation Serialization Routines.
111  *
112  * Copyright (C) 1984, Sun Microsystems, Inc.
113  */
114
115 /*
116  * XDR provides a conventional way for converting between C data
117  * types and an external bit-string representation.  Library supplied
118  * routines provide for the conversion on built-in C data types.  These
119  * routines and utility routines defined here are used to help implement
120  * a type encode/decode routine for each user-defined type.
121  *
122  * Each data type provides a single procedure which takes two arguments:
123  *
124  *      bool_t
125  *      xdrproc(xdrs, argresp)
126  *              XDR *xdrs;
127  *              <type> *argresp;
128  *
129  * xdrs is an instance of a XDR handle, to which or from which the data
130  * type is to be converted.  argresp is a pointer to the structure to be
131  * converted.  The XDR handle contains an operation field which indicates
132  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
133  *
134  * XDR_DECODE may allocate space if the pointer argresp is null.  This
135  * data can be freed with the XDR_FREE operation.
136  *
137  * We write only one procedure per data type to make it easy
138  * to keep the encode and decode procedures for a data type consistent.
139  * In many cases the same code performs all operations on a user defined type,
140  * because all the hard work is done in the component type routines.
141  * decode as a series of calls on the nested data types.
142  */
143
144 /*
145  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
146  * stream.  XDR_DECODE causes the type to be extracted from the stream.
147  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
148  * request.
149  */
150 enum xdr_op {
151         XDR_ENCODE=0,
152         XDR_DECODE=1,
153         XDR_FREE=2
154 };
155
156 /*
157  * This is the number of bytes per unit of external data.
158  */
159 #define BYTES_PER_XDR_UNIT      (4)
160
161 /*
162  * A xdrproc_t exists for each data type which is to be encoded or decoded.
163  *
164  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
165  * The opaque pointer generally points to a structure of the data type
166  * to be decoded.  If this pointer is 0, then the type routines should
167  * allocate dynamic storage of the appropriate size and return it.
168  * bool_t       (*xdrproc_t)(XDR *, caddr_t *);
169  */
170 #if 0
171 typedef bool_t (*xdrproc_t)();
172 #else
173 typedef bool_t (*xdrproc_t) (void *, ...);
174 #endif
175
176
177 /*
178  * The XDR handle.
179  * Contains operation which is being applied to the stream,
180  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
181  * and two private fields for the use of the particular impelementation.
182  */
183 typedef struct {
184         enum xdr_op     x_op;           /* operation; fast additional param */
185         struct xdr_ops {
186 #if defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV))
187 /* NOTE: SGI 6.1 adds two routines to the xdr_ops if the size of a long is
188  * 64 bits. I've only done this for the kernel, since other changes may
189  * be necessary if we make a 64 bit user version of AFS.
190  */
191                 bool_t  (*x_getint64)(void *xdrs, afs_int64 *lp); /* get 32 bits into a long */
192                 bool_t  (*x_putint64)(void *xdrs, afs_int64 *lp); /* send 32 bits of a long */
193 #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */
194 #if !(defined(KERNEL) && defined(AFS_SUN57_ENV))
195                 bool_t  (*x_getint32)(void *xdrs, afs_int32 *lp);       /* get an afs_int32 from underlying stream */
196                 bool_t  (*x_putint32)(void *xdrs, afs_int32 *lp);       /* put an afs_int32 to " */
197 #endif
198                 bool_t  (*x_getbytes)(void *xdrs, caddr_t addr, u_int len);/* get some bytes from " */
199                 bool_t  (*x_putbytes)(void *xdrs, caddr_t addr, u_int len);/* put some bytes to " */
200                 u_int   (*x_getpostn)(void *xdrs);/* returns bytes off from beginning */
201                 bool_t  (*x_setpostn)(void *xdrs, u_int pos);/* lets you reposition the stream */
202                 afs_int32 *     (*x_inline)(void *xdrs, u_int len);     /* buf quick ptr to buffered data */
203                 void    (*x_destroy)(void *xdrs);       /* free privates of this xdr_stream */
204 #if defined(KERNEL) && defined(AFS_SUN57_ENV)
205                 bool_t  (*x_control)(void *xdrs);
206                 bool_t  (*x_getint32)(void *xdrs, afs_int32 *lp);
207                 bool_t  (*x_putint32)(void *xdrs, afs_int32 *lp);
208 #endif
209         } *x_ops;
210         caddr_t         x_public;       /* users' data */
211         caddr_t         x_private;      /* pointer to private data */
212         caddr_t         x_base;         /* private used for position info */
213         int             x_handy;        /* extra private word */
214 } XDR;
215
216 /*
217  * Operations defined on a XDR handle
218  *
219  * XDR          *xdrs;
220  * afs_int32            *int32p;
221  * caddr_t       addr;
222  * u_int         len;
223  * u_int         pos;
224  */
225 #if defined(AFS_SGI61_ENV) && defined(KERNEL) && (_MIPS_SZLONG != _MIPS_SZINT) || defined(AFS_HPUX_64BIT_ENV)
226 #define XDR_GETINT64(xdrs, int64p)                      \
227         (*(xdrs)->x_ops->x_getint64)(xdrs, int64p)
228 #define xdr_getint64(xdrs, int64p)                      \
229         (*(xdrs)->x_ops->x_getint64)(xdrs, int64p)
230
231 #define XDR_PUTINT64(xdrs, int64p)                      \
232         (*(xdrs)->x_ops->x_putint64)(xdrs, int64p)
233 #define xdr_putint64(xdrs, int64p)                      \
234         (*(xdrs)->x_ops->x_putint64)(xdrs, int64p)
235 #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */
236
237 #define XDR_GETINT32(xdrs, int32p)                      \
238         (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
239 #define xdr_getint32(xdrs, int32p)                      \
240         (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
241
242 #define XDR_PUTINT32(xdrs, int32p)                      \
243         (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
244 #define xdr_putint32(xdrs, int32p)                      \
245         (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
246
247 #define XDR_GETBYTES(xdrs, addr, len)                   \
248         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
249 #define xdr_getbytes(xdrs, addr, len)                   \
250         (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
251
252 #define XDR_PUTBYTES(xdrs, addr, len)                   \
253         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
254 #define xdr_putbytes(xdrs, addr, len)                   \
255         (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
256
257 #define XDR_GETPOS(xdrs)                                \
258         (*(xdrs)->x_ops->x_getpostn)(xdrs)
259 #define xdr_getpos(xdrs)                                \
260         (*(xdrs)->x_ops->x_getpostn)(xdrs)
261
262 #define XDR_SETPOS(xdrs, pos)                           \
263         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
264 #define xdr_setpos(xdrs, pos)                           \
265         (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
266
267 #define XDR_INLINE(xdrs, len)                           \
268         (*(xdrs)->x_ops->x_inline)(xdrs, len)
269 #define xdr_inline(xdrs, len)                           \
270         (*(xdrs)->x_ops->x_inline)(xdrs, len)
271
272 #define XDR_DESTROY(xdrs)                               \
273         if ((xdrs)->x_ops->x_destroy)                   \
274                 (*(xdrs)->x_ops->x_destroy)(xdrs)
275 #define xdr_destroy(xdrs)                               \
276         if ((xdrs)->x_ops->x_destroy)                   \
277                 (*(xdrs)->x_ops->x_destroy)(xdrs)
278
279 /*
280  * Support struct for discriminated unions.
281  * You create an array of xdrdiscrim structures, terminated with
282  * a entry with a null procedure pointer.  The xdr_union routine gets
283  * the discriminant value and then searches the array of structures
284  * for a matching value.  If a match is found the associated xdr routine
285  * is called to handle that part of the union.  If there is
286  * no match, then a default routine may be called.
287  * If there is no match and no default routine it is an error.
288  */
289 #define NULL_xdrproc_t ((xdrproc_t)0)
290 struct xdr_discrim {
291         int     value;
292         xdrproc_t proc;
293 };
294
295 /*
296  * In-line routines for fast encode/decode of primitve data types.
297  * Caveat emptor: these use single memory cycles to get the
298  * data from the underlying buffer, and will fail to operate
299  * properly if the data is not aligned.  The standard way to use these
300  * is to say:
301  *      if ((buf = XDR_INLINE(xdrs, count)) == NULL)
302  *              return (FALSE);
303  *      <<< macro calls >>>
304  * where ``count'' is the number of bytes of data occupied
305  * by the primitive data types.
306  *
307  * N.B. and frozen for all time: each data type here uses 4 bytes
308  * of external representation.
309  */
310 #define IXDR_GET_INT32(buf)             ntohl(*buf++)
311 #define IXDR_PUT_INT32(buf, v)          (*buf++ = htonl(v))
312
313 #define IXDR_GET_BOOL(buf)              ((bool_t)IXDR_GET_INT32(buf))
314 #define IXDR_GET_ENUM(buf, t)           ((t)IXDR_GET_INT32(buf))
315 #define IXDR_GET_U_INT32(buf)           ((afs_uint32)IXDR_GET_INT32(buf))
316 #define IXDR_GET_SHORT(buf)             ((short)IXDR_GET_INT32(buf))
317 #define IXDR_GET_U_SHORT(buf)           ((u_short)IXDR_GET_INT32(buf))
318
319 #define IXDR_PUT_BOOL(buf, v)           IXDR_PUT_INT32((buf), ((afs_int32)(v)))
320 #define IXDR_PUT_ENUM(buf, v)           IXDR_PUT_INT32((buf), ((afs_int32)(v)))
321 #define IXDR_PUT_U_INT32(buf, v)        IXDR_PUT_INT32((buf), ((afs_int32)(v)))
322 #define IXDR_PUT_SHORT(buf, v)          IXDR_PUT_INT32((buf), ((afs_int32)(v)))
323 #define IXDR_PUT_U_SHORT(buf, v)        IXDR_PUT_INT32((buf), ((afs_int32)(v)))
324
325 #include "xdr_prototypes.h"
326
327 #endif /* __XDR_INCLUDE__ */