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 | #define bool_t int |
---|
47 | #define enum_t int |
---|
48 | #ifndef FALSE |
---|
49 | #define FALSE 0 |
---|
50 | #endif /* !FALSE */ |
---|
51 | #ifndef TRUE |
---|
52 | #define TRUE 1 |
---|
53 | #endif /* !TRUE */ |
---|
54 | #define __dontcare__ -1 |
---|
55 | |
---|
56 | #ifndef mem_alloc |
---|
57 | #define mem_alloc(bsize) malloc(bsize) |
---|
58 | #endif |
---|
59 | |
---|
60 | #ifndef mem_free |
---|
61 | #define mem_free(ptr, bsize) free(ptr) |
---|
62 | #endif |
---|
63 | |
---|
64 | #ifdef KERNEL |
---|
65 | void *afs_osi_Alloc(); |
---|
66 | #define osi_alloc afs_osi_Alloc |
---|
67 | #define osi_free afs_osi_Free |
---|
68 | |
---|
69 | #ifndef UKERNEL |
---|
70 | #define xdr_void afs_xdr_void |
---|
71 | #define xdr_int afs_xdr_int |
---|
72 | #define xdr_u_int afs_xdr_u_int |
---|
73 | #define xdr_short afs_xdr_short |
---|
74 | #define xdr_u_short afs_xdr_u_short |
---|
75 | #define xdr_long afs_xdr_long |
---|
76 | #define xdr_u_long afs_xdr_u_long |
---|
77 | #define xdr_char afs_xdr_char |
---|
78 | #define xdr_u_char afs_xdr_u_char |
---|
79 | #define xdr_bool afs_xdr_bool |
---|
80 | #define xdr_enum afs_xdr_enum |
---|
81 | #define xdr_array afs_xdr_array |
---|
82 | #define xdr_arrayN afs_xdr_arrayN |
---|
83 | #define xdr_bytes afs_xdr_bytes |
---|
84 | #define xdr_opaque afs_xdr_opaque |
---|
85 | #define xdr_string afs_xdr_string |
---|
86 | #define xdr_union afs_xdr_union |
---|
87 | #define xdr_float afs_xdr_float |
---|
88 | #define xdr_double afs_xdr_double |
---|
89 | #define xdr_reference afs_xdr_reference |
---|
90 | #define xdr_wrapstring afs_xdr_wrapstring |
---|
91 | #define xdr_vector afs_xdr_vector |
---|
92 | #define xdr_int64 afs_xdr_int64 |
---|
93 | #define xdr_uint64 afs_xdr_uint64 |
---|
94 | #endif |
---|
95 | #endif |
---|
96 | #ifndef major /* ouch! */ |
---|
97 | #include <sys/types.h> |
---|
98 | #endif |
---|
99 | |
---|
100 | /* @(#)xdr.h 1.1 86/02/03 SMI */ |
---|
101 | |
---|
102 | /* |
---|
103 | * xdr.h, External Data Representation Serialization Routines. |
---|
104 | * |
---|
105 | * Copyright (C) 1984, Sun Microsystems, Inc. |
---|
106 | */ |
---|
107 | |
---|
108 | /* |
---|
109 | * XDR provides a conventional way for converting between C data |
---|
110 | * types and an external bit-string representation. Library supplied |
---|
111 | * routines provide for the conversion on built-in C data types. These |
---|
112 | * routines and utility routines defined here are used to help implement |
---|
113 | * a type encode/decode routine for each user-defined type. |
---|
114 | * |
---|
115 | * Each data type provides a single procedure which takes two arguments: |
---|
116 | * |
---|
117 | * bool_t |
---|
118 | * xdrproc(xdrs, argresp) |
---|
119 | * XDR *xdrs; |
---|
120 | * <type> *argresp; |
---|
121 | * |
---|
122 | * xdrs is an instance of a XDR handle, to which or from which the data |
---|
123 | * type is to be converted. argresp is a pointer to the structure to be |
---|
124 | * converted. The XDR handle contains an operation field which indicates |
---|
125 | * which of the operations (ENCODE, DECODE * or FREE) is to be performed. |
---|
126 | * |
---|
127 | * XDR_DECODE may allocate space if the pointer argresp is null. This |
---|
128 | * data can be freed with the XDR_FREE operation. |
---|
129 | * |
---|
130 | * We write only one procedure per data type to make it easy |
---|
131 | * to keep the encode and decode procedures for a data type consistent. |
---|
132 | * In many cases the same code performs all operations on a user defined type, |
---|
133 | * because all the hard work is done in the component type routines. |
---|
134 | * decode as a series of calls on the nested data types. |
---|
135 | */ |
---|
136 | |
---|
137 | /* |
---|
138 | * Xdr operations. XDR_ENCODE causes the type to be encoded into the |
---|
139 | * stream. XDR_DECODE causes the type to be extracted from the stream. |
---|
140 | * XDR_FREE can be used to release the space allocated by an XDR_DECODE |
---|
141 | * request. |
---|
142 | */ |
---|
143 | enum xdr_op { |
---|
144 | XDR_ENCODE=0, |
---|
145 | XDR_DECODE=1, |
---|
146 | XDR_FREE=2 |
---|
147 | }; |
---|
148 | |
---|
149 | /* |
---|
150 | * This is the number of bytes per unit of external data. |
---|
151 | */ |
---|
152 | #define BYTES_PER_XDR_UNIT (4) |
---|
153 | |
---|
154 | /* |
---|
155 | * A xdrproc_t exists for each data type which is to be encoded or decoded. |
---|
156 | * |
---|
157 | * The second argument to the xdrproc_t is a pointer to an opaque pointer. |
---|
158 | * The opaque pointer generally points to a structure of the data type |
---|
159 | * to be decoded. If this pointer is 0, then the type routines should |
---|
160 | * allocate dynamic storage of the appropriate size and return it. |
---|
161 | * bool_t (*xdrproc_t)(XDR *, caddr_t *); |
---|
162 | */ |
---|
163 | typedef bool_t (*xdrproc_t)(); |
---|
164 | |
---|
165 | /* |
---|
166 | * The XDR handle. |
---|
167 | * Contains operation which is being applied to the stream, |
---|
168 | * an operations vector for the paticular implementation (e.g. see xdr_mem.c), |
---|
169 | * and two private fields for the use of the particular impelementation. |
---|
170 | */ |
---|
171 | typedef struct { |
---|
172 | enum xdr_op x_op; /* operation; fast additional param */ |
---|
173 | struct xdr_ops { |
---|
174 | #if defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) |
---|
175 | /* NOTE: SGI 6.1 adds two routines to the xdr_ops if the size of a long is |
---|
176 | * 64 bits. I've only done this for the kernel, since other changes may |
---|
177 | * be necessary if we make a 64 bit user version of AFS. |
---|
178 | */ |
---|
179 | bool_t (*x_getint64)(); /* get 32 bits into a long */ |
---|
180 | bool_t (*x_putint64)(); /* send 32 bits of a long */ |
---|
181 | #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */ |
---|
182 | #if !(defined(KERNEL) && defined(AFS_SUN57_ENV)) |
---|
183 | bool_t (*x_getint32)(); /* get an afs_int32 from underlying stream */ |
---|
184 | bool_t (*x_putint32)(); /* put an afs_int32 to " */ |
---|
185 | #endif |
---|
186 | bool_t (*x_getbytes)();/* get some bytes from " */ |
---|
187 | bool_t (*x_putbytes)();/* put some bytes to " */ |
---|
188 | u_int (*x_getpostn)();/* returns bytes off from beginning */ |
---|
189 | bool_t (*x_setpostn)();/* lets you reposition the stream */ |
---|
190 | afs_int32 * (*x_inline)(); /* buf quick ptr to buffered data */ |
---|
191 | void (*x_destroy)(); /* free privates of this xdr_stream */ |
---|
192 | #if defined(KERNEL) && defined(AFS_SUN57_ENV) |
---|
193 | bool_t (*x_control)(); |
---|
194 | bool_t (*x_getint32)(); |
---|
195 | bool_t (*x_putint32)(); |
---|
196 | #endif |
---|
197 | } *x_ops; |
---|
198 | caddr_t x_public; /* users' data */ |
---|
199 | caddr_t x_private; /* pointer to private data */ |
---|
200 | caddr_t x_base; /* private used for position info */ |
---|
201 | int x_handy; /* extra private word */ |
---|
202 | } XDR; |
---|
203 | |
---|
204 | /* |
---|
205 | * Operations defined on a XDR handle |
---|
206 | * |
---|
207 | * XDR *xdrs; |
---|
208 | * afs_int32 *int32p; |
---|
209 | * caddr_t addr; |
---|
210 | * u_int len; |
---|
211 | * u_int pos; |
---|
212 | */ |
---|
213 | #if defined(AFS_SGI61_ENV) && defined(KERNEL) && (_MIPS_SZLONG != _MIPS_SZINT) || defined(AFS_HPUX_64BIT_ENV) |
---|
214 | #define XDR_GETINT64(xdrs, int64p) \ |
---|
215 | (*(xdrs)->x_ops->x_getint64)(xdrs, int64p) |
---|
216 | #define xdr_getint64(xdrs, int64p) \ |
---|
217 | (*(xdrs)->x_ops->x_getint64)(xdrs, int64p) |
---|
218 | |
---|
219 | #define XDR_PUTINT64(xdrs, int64p) \ |
---|
220 | (*(xdrs)->x_ops->x_putint64)(xdrs, int64p) |
---|
221 | #define xdr_putint64(xdrs, int64p) \ |
---|
222 | (*(xdrs)->x_ops->x_putint64)(xdrs, int64p) |
---|
223 | #endif /* defined(KERNEL) && ((defined(AFS_SGI61_ENV) && (_MIPS_SZLONG != _MIPS_SZINT)) || defined(AFS_HPUX_64BIT_ENV)) */ |
---|
224 | |
---|
225 | #define XDR_GETINT32(xdrs, int32p) \ |
---|
226 | (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) |
---|
227 | #define xdr_getint32(xdrs, int32p) \ |
---|
228 | (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) |
---|
229 | |
---|
230 | #define XDR_PUTINT32(xdrs, int32p) \ |
---|
231 | (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) |
---|
232 | #define xdr_putint32(xdrs, int32p) \ |
---|
233 | (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) |
---|
234 | |
---|
235 | #define XDR_GETBYTES(xdrs, addr, len) \ |
---|
236 | (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) |
---|
237 | #define xdr_getbytes(xdrs, addr, len) \ |
---|
238 | (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) |
---|
239 | |
---|
240 | #define XDR_PUTBYTES(xdrs, addr, len) \ |
---|
241 | (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) |
---|
242 | #define xdr_putbytes(xdrs, addr, len) \ |
---|
243 | (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) |
---|
244 | |
---|
245 | #define XDR_GETPOS(xdrs) \ |
---|
246 | (*(xdrs)->x_ops->x_getpostn)(xdrs) |
---|
247 | #define xdr_getpos(xdrs) \ |
---|
248 | (*(xdrs)->x_ops->x_getpostn)(xdrs) |
---|
249 | |
---|
250 | #define XDR_SETPOS(xdrs, pos) \ |
---|
251 | (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) |
---|
252 | #define xdr_setpos(xdrs, pos) \ |
---|
253 | (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) |
---|
254 | |
---|
255 | #define XDR_INLINE(xdrs, len) \ |
---|
256 | (*(xdrs)->x_ops->x_inline)(xdrs, len) |
---|
257 | #define xdr_inline(xdrs, len) \ |
---|
258 | (*(xdrs)->x_ops->x_inline)(xdrs, len) |
---|
259 | |
---|
260 | #define XDR_DESTROY(xdrs) \ |
---|
261 | if ((xdrs)->x_ops->x_destroy) \ |
---|
262 | (*(xdrs)->x_ops->x_destroy)(xdrs) |
---|
263 | #define xdr_destroy(xdrs) \ |
---|
264 | if ((xdrs)->x_ops->x_destroy) \ |
---|
265 | (*(xdrs)->x_ops->x_destroy)(xdrs) |
---|
266 | |
---|
267 | /* |
---|
268 | * Support struct for discriminated unions. |
---|
269 | * You create an array of xdrdiscrim structures, terminated with |
---|
270 | * a entry with a null procedure pointer. The xdr_union routine gets |
---|
271 | * the discriminant value and then searches the array of structures |
---|
272 | * for a matching value. If a match is found the associated xdr routine |
---|
273 | * is called to handle that part of the union. If there is |
---|
274 | * no match, then a default routine may be called. |
---|
275 | * If there is no match and no default routine it is an error. |
---|
276 | */ |
---|
277 | #define NULL_xdrproc_t ((xdrproc_t)0) |
---|
278 | struct xdr_discrim { |
---|
279 | int value; |
---|
280 | xdrproc_t proc; |
---|
281 | }; |
---|
282 | |
---|
283 | /* |
---|
284 | * In-line routines for fast encode/decode of primitve data types. |
---|
285 | * Caveat emptor: these use single memory cycles to get the |
---|
286 | * data from the underlying buffer, and will fail to operate |
---|
287 | * properly if the data is not aligned. The standard way to use these |
---|
288 | * is to say: |
---|
289 | * if ((buf = XDR_INLINE(xdrs, count)) == NULL) |
---|
290 | * return (FALSE); |
---|
291 | * <<< macro calls >>> |
---|
292 | * where ``count'' is the number of bytes of data occupied |
---|
293 | * by the primitive data types. |
---|
294 | * |
---|
295 | * N.B. and frozen for all time: each data type here uses 4 bytes |
---|
296 | * of external representation. |
---|
297 | */ |
---|
298 | #define IXDR_GET_INT32(buf) ntohl(*buf++) |
---|
299 | #define IXDR_PUT_INT32(buf, v) (*buf++ = htonl(v)) |
---|
300 | |
---|
301 | #define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_INT32(buf)) |
---|
302 | #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_INT32(buf)) |
---|
303 | #define IXDR_GET_U_INT32(buf) ((afs_uint32)IXDR_GET_INT32(buf)) |
---|
304 | #define IXDR_GET_SHORT(buf) ((short)IXDR_GET_INT32(buf)) |
---|
305 | #define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_INT32(buf)) |
---|
306 | |
---|
307 | #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_INT32((buf), ((afs_int32)(v))) |
---|
308 | #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_INT32((buf), ((afs_int32)(v))) |
---|
309 | #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((afs_int32)(v))) |
---|
310 | #define IXDR_PUT_SHORT(buf, v) IXDR_PUT_INT32((buf), ((afs_int32)(v))) |
---|
311 | #define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_INT32((buf), ((afs_int32)(v))) |
---|
312 | |
---|
313 | /* |
---|
314 | * These are the "generic" xdr routines. |
---|
315 | */ |
---|
316 | extern bool_t xdr_void(); |
---|
317 | extern bool_t xdr_int(); |
---|
318 | extern bool_t xdr_u_int(); |
---|
319 | extern bool_t xdr_short(); |
---|
320 | extern bool_t xdr_u_short(); |
---|
321 | extern bool_t xdr_long(); |
---|
322 | extern bool_t xdr_char(); |
---|
323 | extern bool_t xdr_u_char(); |
---|
324 | extern bool_t xdr_bool(); |
---|
325 | extern bool_t xdr_enum(); |
---|
326 | extern bool_t xdr_array(); |
---|
327 | extern bool_t xdr_bytes(); |
---|
328 | extern bool_t xdr_opaque(); |
---|
329 | extern bool_t xdr_string(); |
---|
330 | extern bool_t xdr_union(); |
---|
331 | extern bool_t xdr_float(); |
---|
332 | extern bool_t xdr_double(); |
---|
333 | extern bool_t xdr_reference(); |
---|
334 | extern bool_t xdr_wrapstring(); |
---|
335 | extern bool_t xdr_vector(); |
---|
336 | extern bool_t xdr_int64(); |
---|
337 | extern bool_t xdr_uint64(); |
---|
338 | |
---|
339 | /* |
---|
340 | * These are the public routines for the various implementations of |
---|
341 | * xdr streams. |
---|
342 | */ |
---|
343 | extern void xdrmem_create(); /* XDR using memory buffers */ |
---|
344 | extern void xdrrx_create(); /* XDR using rx */ |
---|
345 | extern void xdrstdio_create(); /* XDR using stdio library */ |
---|
346 | extern void xdrrec_create(); /* XDR pseudo records for tcp */ |
---|
347 | extern bool_t xdrrec_endofrecord(); /* make end of xdr record */ |
---|
348 | extern bool_t xdrrec_skiprecord(); /* move to begining of next record */ |
---|
349 | extern bool_t xdrrec_eof(); /* true iff no more input */ |
---|
350 | |
---|
351 | /* |
---|
352 | * If you change the definitions of xdr_afs_int32 and xdr_afs_uint32, be sure |
---|
353 | * to change them in BOTH rx/xdr.h and rxgen/rpc_main.c. Also, config/stds.h |
---|
354 | * has the defines for afs_int32 which should match below. |
---|
355 | */ |
---|
356 | |
---|
357 | #ifndef xdr_afs_int32 |
---|
358 | #define xdr_afs_int32 xdr_int |
---|
359 | #endif |
---|
360 | #ifndef xdr_afs_uint32 |
---|
361 | #define xdr_afs_uint32 xdr_u_int |
---|
362 | #endif |
---|
363 | #ifndef xdr_afs_int64 |
---|
364 | #define xdr_afs_int64 xdr_int64 |
---|
365 | #endif |
---|
366 | #ifndef xdr_afs_uint64 |
---|
367 | #define xdr_afs_uint64 xdr_uint64 |
---|
368 | #endif |
---|
369 | |
---|
370 | #endif /* __XDR_INCLUDE__ */ |
---|