0
|
1 |
/*********************************************************************
|
|
2 |
* RPC for the Windows NT Operating System
|
|
3 |
* 1993 by Martin F. Gergeleit
|
|
4 |
* Users may use, copy or modify Sun RPC for the Windows NT Operating
|
|
5 |
* System according to the Sun copyright below.
|
|
6 |
*
|
|
7 |
* RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
|
|
8 |
* WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
|
|
9 |
* USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
|
|
10 |
*********************************************************************/
|
|
11 |
|
|
12 |
/* @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC */
|
|
13 |
/*
|
|
14 |
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
|
15 |
* unrestricted use provided that this legend is included on all tape
|
|
16 |
* media and as a part of the software program in whole or part. Users
|
|
17 |
* may copy or modify Sun RPC without charge, but are not authorized
|
|
18 |
* to license or distribute it to anyone else except as part of a product or
|
|
19 |
* program developed by the user.
|
|
20 |
*
|
|
21 |
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
|
22 |
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
|
23 |
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
|
24 |
*
|
|
25 |
* Sun RPC is provided with no support and without any obligation on the
|
|
26 |
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
|
27 |
* modification or enhancement.
|
|
28 |
*
|
|
29 |
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
|
30 |
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
|
31 |
* OR ANY PART THEREOF.
|
|
32 |
*
|
|
33 |
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
|
34 |
* or profits or other special, indirect and consequential damages, even if
|
|
35 |
* Sun has been advised of the possibility of such damages.
|
|
36 |
*
|
|
37 |
* Sun Microsystems, Inc.
|
|
38 |
* 2550 Garcia Avenue
|
|
39 |
* Mountain View, California 94043
|
|
40 |
*/
|
|
41 |
/* @(#)xdr.h 1.19 87/04/22 SMI */
|
|
42 |
|
|
43 |
/*
|
|
44 |
* xdr.h, External Data Representation Serialization Routines.
|
|
45 |
*
|
|
46 |
* Copyright (C) 1984, Sun Microsystems, Inc.
|
|
47 |
*/
|
|
48 |
|
|
49 |
#ifndef __XDR_HEADER__
|
|
50 |
#define __XDR_HEADER__
|
|
51 |
|
|
52 |
#ifdef __cplusplus
|
|
53 |
extern "C" {
|
|
54 |
#define DOTS ...
|
|
55 |
#else
|
|
56 |
#define DOTS
|
|
57 |
#endif
|
|
58 |
|
|
59 |
/*
|
|
60 |
* XDR provides a conventional way for converting between C data
|
|
61 |
* types and an external bit-string representation. Library supplied
|
|
62 |
* routines provide for the conversion on built-in C data types. These
|
|
63 |
* routines and utility routines defined here are used to help implement
|
|
64 |
* a type encode/decode routine for each user-defined type.
|
|
65 |
*
|
|
66 |
* Each data type provides a single procedure which takes two arguments:
|
|
67 |
*
|
|
68 |
* bool_t
|
|
69 |
* xdrproc(xdrs, argresp)
|
|
70 |
* XDR *xdrs;
|
|
71 |
* <type> *argresp;
|
|
72 |
*
|
|
73 |
* xdrs is an instance of a XDR handle, to which or from which the data
|
|
74 |
* type is to be converted. argresp is a pointer to the structure to be
|
|
75 |
* converted. The XDR handle contains an operation field which indicates
|
|
76 |
* which of the operations (ENCODE, DECODE * or FREE) is to be performed.
|
|
77 |
*
|
|
78 |
* XDR_DECODE may allocate space if the pointer argresp is null. This
|
|
79 |
* data can be freed with the XDR_FREE operation.
|
|
80 |
*
|
|
81 |
* We write only one procedure per data type to make it easy
|
|
82 |
* to keep the encode and decode procedures for a data type consistent.
|
|
83 |
* In many cases the same code performs all operations on a user defined type,
|
|
84 |
* because all the hard work is done in the component type routines.
|
|
85 |
* decode as a series of calls on the nested data types.
|
|
86 |
*/
|
|
87 |
|
|
88 |
/*
|
|
89 |
* Xdr operations. XDR_ENCODE causes the type to be encoded into the
|
|
90 |
* stream. XDR_DECODE causes the type to be extracted from the stream.
|
|
91 |
* XDR_FREE can be used to release the space allocated by an XDR_DECODE
|
|
92 |
* request.
|
|
93 |
*/
|
|
94 |
enum xdr_op {
|
|
95 |
XDR_ENCODE=0,
|
|
96 |
XDR_DECODE=1,
|
|
97 |
XDR_FREE=2
|
|
98 |
};
|
|
99 |
|
|
100 |
/*
|
|
101 |
* This is the number of bytes per unit of external data.
|
|
102 |
*/
|
|
103 |
#define BYTES_PER_XDR_UNIT (4)
|
|
104 |
#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
|
|
105 |
* BYTES_PER_XDR_UNIT)
|
|
106 |
|
|
107 |
/*
|
|
108 |
* A xdrproc_t exists for each data type which is to be encoded or decoded.
|
|
109 |
*
|
|
110 |
* The second argument to the xdrproc_t is a pointer to an opaque pointer.
|
|
111 |
* The opaque pointer generally points to a structure of the data type
|
|
112 |
* to be decoded. If this pointer is 0, then the type routines should
|
|
113 |
* allocate dynamic storage of the appropriate size and return it.
|
|
114 |
* bool_t (*xdrproc_t)(XDR *, caddr_t *);
|
|
115 |
*/
|
|
116 |
typedef bool_t (*xdrproc_t)(DOTS);
|
|
117 |
|
|
118 |
/*
|
|
119 |
* The XDR handle.
|
|
120 |
* Contains operation which is being applied to the stream,
|
|
121 |
* an operations vector for the paticular implementation (e.g. see xdr_mem.c),
|
|
122 |
* and two private fields for the use of the particular impelementation.
|
|
123 |
*/
|
|
124 |
typedef struct {
|
|
125 |
enum xdr_op x_op; /* operation; fast additional param */
|
|
126 |
struct xdr_ops {
|
|
127 |
bool_t (*x_getlong)(DOTS); /* get a long from underlying stream */
|
|
128 |
bool_t (*x_putlong)(DOTS); /* put a long to " */
|
|
129 |
bool_t (*x_getbytes)(DOTS);/* get some bytes from " */
|
|
130 |
bool_t (*x_putbytes)(DOTS);/* put some bytes to " */
|
|
131 |
u_int (*x_getpostn)(DOTS);/* returns bytes off from beginning */
|
|
132 |
bool_t (*x_setpostn)(DOTS);/* lets you reposition the stream */
|
|
133 |
long * (*x_inline)(DOTS); /* buf quick ptr to buffered data */
|
|
134 |
void (*x_destroy)(DOTS); /* free privates of this xdr_stream */
|
|
135 |
} *x_ops;
|
|
136 |
caddr_t x_public; /* users' data */
|
|
137 |
caddr_t x_private; /* pointer to private data */
|
|
138 |
caddr_t x_base; /* private used for position info */
|
|
139 |
int x_handy; /* extra private word */
|
|
140 |
} XDR;
|
|
141 |
|
|
142 |
/*
|
|
143 |
* Operations defined on a XDR handle
|
|
144 |
*
|
|
145 |
* XDR *xdrs;
|
|
146 |
* long *longp;
|
|
147 |
* caddr_t addr;
|
|
148 |
* u_int len;
|
|
149 |
* u_int pos;
|
|
150 |
*/
|
|
151 |
#define XDR_GETLONG(xdrs, longp) \
|
|
152 |
(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
|
|
153 |
#define xdr_getlong(xdrs, longp) \
|
|
154 |
(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
|
|
155 |
|
|
156 |
#define XDR_PUTLONG(xdrs, longp) \
|
|
157 |
(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
|
|
158 |
#define xdr_putlong(xdrs, longp) \
|
|
159 |
(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
|
|
160 |
|
|
161 |
#define XDR_GETBYTES(xdrs, addr, len) \
|
|
162 |
(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
|
|
163 |
#define xdr_getbytes(xdrs, addr, len) \
|
|
164 |
(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
|
|
165 |
|
|
166 |
#define XDR_PUTBYTES(xdrs, addr, len) \
|
|
167 |
(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
|
|
168 |
#define xdr_putbytes(xdrs, addr, len) \
|
|
169 |
(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
|
|
170 |
|
|
171 |
#define XDR_GETPOS(xdrs) \
|
|
172 |
(*(xdrs)->x_ops->x_getpostn)(xdrs)
|
|
173 |
#define xdr_getpos(xdrs) \
|
|
174 |
(*(xdrs)->x_ops->x_getpostn)(xdrs)
|
|
175 |
|
|
176 |
#define XDR_SETPOS(xdrs, pos) \
|
|
177 |
(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
|
|
178 |
#define xdr_setpos(xdrs, pos) \
|
|
179 |
(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
|
|
180 |
|
|
181 |
#define XDR_INLINE(xdrs, len) \
|
|
182 |
(*(xdrs)->x_ops->x_inline)(xdrs, len)
|
|
183 |
#define xdr_inline(xdrs, len) \
|
|
184 |
(*(xdrs)->x_ops->x_inline)(xdrs, len)
|
|
185 |
|
|
186 |
#define XDR_DESTROY(xdrs) \
|
|
187 |
if ((xdrs)->x_ops->x_destroy) \
|
|
188 |
(*(xdrs)->x_ops->x_destroy)(xdrs)
|
|
189 |
#define xdr_destroy(xdrs) \
|
|
190 |
if ((xdrs)->x_ops->x_destroy) \
|
|
191 |
(*(xdrs)->x_ops->x_destroy)(xdrs)
|
|
192 |
|
|
193 |
/*
|
|
194 |
* Support struct for discriminated unions.
|
|
195 |
* You create an array of xdrdiscrim structures, terminated with
|
|
196 |
* a entry with a null procedure pointer. The xdr_union routine gets
|
|
197 |
* the discriminant value and then searches the array of structures
|
|
198 |
* for a matching value. If a match is found the associated xdr routine
|
|
199 |
* is called to handle that part of the union. If there is
|
|
200 |
* no match, then a default routine may be called.
|
|
201 |
* If there is no match and no default routine it is an error.
|
|
202 |
*/
|
|
203 |
#define NULL_xdrproc_t ((xdrproc_t)0)
|
|
204 |
struct xdr_discrim {
|
|
205 |
int value;
|
|
206 |
xdrproc_t proc;
|
|
207 |
};
|
|
208 |
|
|
209 |
/*
|
|
210 |
* In-line routines for fast encode/decode of primitve data types.
|
|
211 |
* Caveat emptor: these use single memory cycles to get the
|
|
212 |
* data from the underlying buffer, and will fail to operate
|
|
213 |
* properly if the data is not aligned. The standard way to use these
|
|
214 |
* is to say:
|
|
215 |
* if ((buf = XDR_INLINE(xdrs, count)) == NULL)
|
|
216 |
* return (FALSE);
|
|
217 |
* <<< macro calls >>>
|
|
218 |
* where ``count'' is the number of bytes of data occupied
|
|
219 |
* by the primitive data types.
|
|
220 |
*
|
|
221 |
* N.B. and frozen for all time: each data type here uses 4 bytes
|
|
222 |
* of external representation.
|
|
223 |
*/
|
|
224 |
#define IXDR_GET_LONG(buf) ((long)ntohl((u_long)*(buf)++))
|
|
225 |
#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((u_long)v))
|
|
226 |
|
|
227 |
#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
|
|
228 |
#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
|
|
229 |
#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
|
|
230 |
#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
|
|
231 |
#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
|
|
232 |
|
|
233 |
#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
|
|
234 |
#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
|
|
235 |
#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
|
|
236 |
#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
|
|
237 |
#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
|
|
238 |
|
|
239 |
/*
|
|
240 |
* These are the "generic" xdr routines.
|
|
241 |
*/
|
|
242 |
extern bool_t xdr_void(DOTS);
|
|
243 |
extern bool_t xdr_int(DOTS);
|
|
244 |
extern bool_t xdr_u_int(DOTS);
|
|
245 |
extern bool_t xdr_long(DOTS);
|
|
246 |
extern bool_t xdr_u_long(DOTS);
|
|
247 |
extern bool_t xdr_short(DOTS);
|
|
248 |
extern bool_t xdr_u_short(DOTS);
|
|
249 |
extern bool_t xdr_bool(DOTS);
|
|
250 |
extern bool_t xdr_enum(DOTS);
|
|
251 |
extern bool_t xdr_array(DOTS);
|
|
252 |
extern bool_t xdr_bytes(DOTS);
|
|
253 |
extern bool_t xdr_opaque(DOTS);
|
|
254 |
extern bool_t xdr_string(DOTS);
|
|
255 |
extern bool_t xdr_union(DOTS);
|
|
256 |
extern bool_t xdr_char(DOTS);
|
|
257 |
extern bool_t xdr_u_char(DOTS);
|
|
258 |
extern bool_t xdr_vector(DOTS);
|
|
259 |
extern bool_t xdr_float(DOTS);
|
|
260 |
extern bool_t xdr_double(DOTS);
|
|
261 |
extern bool_t xdr_reference(DOTS);
|
|
262 |
extern bool_t xdr_pointer(DOTS);
|
|
263 |
extern bool_t xdr_wrapstring(DOTS);
|
|
264 |
|
|
265 |
/*
|
|
266 |
* Common opaque bytes objects used by many rpc protocols;
|
|
267 |
* declared here due to commonality.
|
|
268 |
*/
|
|
269 |
#define MAX_NETOBJ_SZ 1024
|
|
270 |
struct netobj {
|
|
271 |
u_int n_len;
|
|
272 |
char *n_bytes;
|
|
273 |
};
|
|
274 |
typedef struct netobj netobj;
|
|
275 |
extern bool_t xdr_netobj(DOTS);
|
|
276 |
|
|
277 |
/*
|
|
278 |
* These are the public routines for the various implementations of
|
|
279 |
* xdr streams.
|
|
280 |
*/
|
|
281 |
extern void xdrmem_create(DOTS); /* XDR using memory buffers */
|
|
282 |
extern void xdrstdio_create(DOTS); /* XDR using stdio library */
|
|
283 |
extern void xdrrec_create(DOTS); /* XDR pseudo records for tcp */
|
|
284 |
extern bool_t xdrrec_endofrecord(DOTS); /* make end of xdr record */
|
|
285 |
extern bool_t xdrrec_skiprecord(DOTS); /* move to beginning of next record */
|
|
286 |
extern bool_t xdrrec_eof(DOTS); /* true if no more input */
|
|
287 |
|
|
288 |
#ifdef __cplusplus
|
|
289 |
};
|
|
290 |
#endif
|
|
291 |
|
|
292 |
#endif /* __XDR_HEADER__ */
|