2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
26 * unrestricted use provided that this legend is included on all tape
27 * media and as a part of the software program in whole or part. Users
28 * may copy or modify Sun RPC without charge, but are not authorized
29 * to license or distribute it to anyone else except as part of a product or
30 * program developed by the user.
32 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
33 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
36 * Sun RPC is provided with no support and without any obligation on the
37 * part of Sun Microsystems, Inc. to assist in its use, correction,
38 * modification or enhancement.
40 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
41 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
42 * OR ANY PART THEREOF.
44 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
45 * or profits or other special, indirect and consequential damages, even if
46 * Sun has been advised of the possibility of such damages.
48 * Sun Microsystems, Inc.
50 * Mountain View, California 94043
52 * from: @(#)xdr.h 1.19 87/04/22 SMI
53 * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC
54 * $Id: xdr.h,v 1.2 1999/10/14 21:56:54 wsanchez Exp $
58 * xdr.h, External Data Representation Serialization Routines.
60 * Copyright (C) 1984, Sun Microsystems, Inc.
65 #include <sys/cdefs.h>
68 * XDR provides a conventional way for converting between C data
69 * types and an external bit-string representation. Library supplied
70 * routines provide for the conversion on built-in C data types. These
71 * routines and utility routines defined here are used to help implement
72 * a type encode/decode routine for each user-defined type.
74 * Each data type provides a single procedure which takes two arguments:
77 * xdrproc(xdrs, argresp)
81 * xdrs is an instance of a XDR handle, to which or from which the data
82 * type is to be converted. argresp is a pointer to the structure to be
83 * converted. The XDR handle contains an operation field which indicates
84 * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
86 * XDR_DECODE may allocate space if the pointer argresp is null. This
87 * data can be freed with the XDR_FREE operation.
89 * We write only one procedure per data type to make it easy
90 * to keep the encode and decode procedures for a data type consistent.
91 * In many cases the same code performs all operations on a user defined type,
92 * because all the hard work is done in the component type routines.
93 * decode as a series of calls on the nested data types.
97 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
98 * stream. XDR_DECODE causes the type to be extracted from the stream.
99 * XDR_FREE can be used to release the space allocated by an XDR_DECODE
109 * This is the number of bytes per unit of external data.
111 #define BYTES_PER_XDR_UNIT (4)
112 #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
113 * BYTES_PER_XDR_UNIT)
116 * A xdrproc_t exists for each data type which is to be encoded or decoded.
118 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
119 * The opaque pointer generally points to a structure of the data type
120 * to be decoded. If this pointer is 0, then the type routines should
121 * allocate dynamic storage of the appropriate size and return it.
122 * bool_t (*xdrproc_t)(XDR *, caddr_t *);
124 typedef bool_t (*xdrproc_t
)();
128 * Contains operation which is being applied to the stream,
129 * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
130 * and two private fields for the use of the particular impelementation.
133 enum xdr_op x_op
; /* operation; fast additional param */
135 bool_t (*x_getlong
)(); /* get a long from underlying stream */
136 bool_t (*x_putlong
)(); /* put a long to " */
137 bool_t (*x_getbytes
)();/* get some bytes from " */
138 bool_t (*x_putbytes
)();/* put some bytes to " */
139 u_int (*x_getpostn
)();/* returns bytes off from beginning */
140 bool_t (*x_setpostn
)();/* lets you reposition the stream */
141 long * (*x_inline
)(); /* buf quick ptr to buffered data */
142 void (*x_destroy
)(); /* free privates of this xdr_stream */
144 caddr_t x_public
; /* users' data */
145 caddr_t x_private
; /* pointer to private data */
146 caddr_t x_base
; /* private used for position info */
147 int x_handy
; /* extra private word */
151 * Operations defined on a XDR handle
159 #define XDR_GETLONG(xdrs, longp) \
160 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
161 #define xdr_getlong(xdrs, longp) \
162 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
164 #define XDR_PUTLONG(xdrs, longp) \
165 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
166 #define xdr_putlong(xdrs, longp) \
167 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
169 #define XDR_GETBYTES(xdrs, addr, len) \
170 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
171 #define xdr_getbytes(xdrs, addr, len) \
172 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
174 #define XDR_PUTBYTES(xdrs, addr, len) \
175 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
176 #define xdr_putbytes(xdrs, addr, len) \
177 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
179 #define XDR_GETPOS(xdrs) \
180 (*(xdrs)->x_ops->x_getpostn)(xdrs)
181 #define xdr_getpos(xdrs) \
182 (*(xdrs)->x_ops->x_getpostn)(xdrs)
184 #define XDR_SETPOS(xdrs, pos) \
185 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
186 #define xdr_setpos(xdrs, pos) \
187 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
189 #define XDR_INLINE(xdrs, len) \
190 (*(xdrs)->x_ops->x_inline)(xdrs, len)
191 #define xdr_inline(xdrs, len) \
192 (*(xdrs)->x_ops->x_inline)(xdrs, len)
194 #define XDR_DESTROY(xdrs) \
197 if ((xdrs)->x_ops->x_destroy) \
198 (*(xdrs)->x_ops->x_destroy)(xdrs)
199 #define xdr_destroy(xdrs) \
202 if ((xdrs)->x_ops->x_destroy) \
203 (*(xdrs)->x_ops->x_destroy)(xdrs)
206 * Support struct for discriminated unions.
207 * You create an array of xdrdiscrim structures, terminated with
208 * a entry with a null procedure pointer. The xdr_union routine gets
209 * the discriminant value and then searches the array of structures
210 * for a matching value. If a match is found the associated xdr routine
211 * is called to handle that part of the union. If there is
212 * no match, then a default routine may be called.
213 * If there is no match and no default routine it is an error.
215 #define NULL_xdrproc_t ((xdrproc_t)0)
222 * In-line routines for fast encode/decode of primitve data types.
223 * Caveat emptor: these use single memory cycles to get the
224 * data from the underlying buffer, and will fail to operate
225 * properly if the data is not aligned. The standard way to use these
227 * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
229 * <<< macro calls >>>
230 * where ``count'' is the number of bytes of data occupied
231 * by the primitive data types.
233 * N.B. and frozen for all time: each data type here uses 4 bytes
234 * of external representation.
236 #define IXDR_GET_LONG(buf) ((long)ntohl((u_long)*(buf)++))
237 #define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((u_long)v))
239 #define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
240 #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
241 #define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
242 #define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
243 #define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
245 #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
246 #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
247 #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
248 #define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
249 #define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
252 * These are the "generic" xdr routines.
255 extern bool_t xdr_void
__P((void));
256 extern bool_t xdr_int
__P((XDR
*, int *));
257 extern bool_t xdr_u_int
__P((XDR
*, u_int
*));
258 extern bool_t xdr_long
__P((XDR
*, long *));
259 extern bool_t xdr_u_long
__P((XDR
*, u_long
*));
260 extern bool_t xdr_short
__P((XDR
*, short *));
261 extern bool_t xdr_u_short
__P((XDR
*, u_short
*));
262 extern bool_t xdr_bool
__P((XDR
*, bool_t
*));
263 extern bool_t xdr_enum
__P((XDR
*, enum_t
*));
264 extern bool_t xdr_array
__P((XDR
*, char **, u_int
*, u_int
, u_int
, xdrproc_t
));
265 extern bool_t xdr_bytes
__P((XDR
*, char **, u_int
*, u_int
));
266 extern bool_t xdr_opaque
__P((XDR
*, caddr_t
, u_int
));
267 extern bool_t xdr_string
__P((XDR
*, char **, u_int
));
268 extern bool_t xdr_union
__P((XDR
*, enum_t
*, char *, struct xdr_discrim
*, xdrproc_t
));
269 extern bool_t xdr_char
__P((XDR
*, char *));
270 extern bool_t xdr_u_char
__P((XDR
*, u_char
*));
271 extern bool_t xdr_vector
__P((XDR
*, char *, u_int
, u_int
, xdrproc_t
));
272 extern bool_t xdr_float
__P((XDR
*, float *));
273 extern bool_t xdr_double
__P((XDR
*, double *));
274 extern bool_t xdr_reference
__P((XDR
*, caddr_t
*, u_int
, xdrproc_t
));
275 extern bool_t xdr_pointer
__P((XDR
*, caddr_t
*, u_int
, xdrproc_t
));
276 extern bool_t xdr_wrapstring
__P((XDR
*, char **));
277 extern void xdr_free
__P((xdrproc_t
, void *));
281 * Common opaque bytes objects used by many rpc protocols;
282 * declared here due to commonality.
284 #define MAX_NETOBJ_SZ 1024
289 typedef struct netobj netobj
;
290 extern bool_t
xdr_netobj();
293 * These are the public routines for the various implementations of
297 /* XDR using memory buffers */
298 extern void xdrmem_create
__P((XDR
*, void *, u_int
, enum xdr_op
));
301 /* XDR using stdio library */
302 extern void xdrstdio_create
__P((XDR
*, FILE *, enum xdr_op
));
305 /* XDR pseudo records for tcp */
306 extern void xdrrec_create
__P((XDR
*, u_int
, u_int
, char *, int (*)(), int (*)()));
308 /* make end of xdr record */
309 extern bool_t xdrrec_endofrecord
__P((XDR
*, int));
311 /* move to beginning of next record */
312 extern bool_t xdrrec_skiprecord
__P((XDR
*));
314 /* true if no more input */
315 extern bool_t xdrrec_eof
__P((XDR
*));
318 #endif /* !_RPC_XDR_H */