ReactOS 0.4.15-dev-7788-g1ad9096
xdr.h
Go to the documentation of this file.
1/* $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */
2
3/*
4 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * from: @(#)xdr.h 1.19 87/04/22 SMI
31 * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC
32 * $FreeBSD: src/include/rpc/xdr.h,v 1.23 2003/03/07 13:19:40 nectar Exp $
33 */
34
35/*
36 * xdr.h, External Data Representation Serialization Routines.
37 *
38 * Copyright (C) 1984, Sun Microsystems, Inc.
39 */
40
41#ifndef _TIRPC_XDR_H
42#define _TIRPC_XDR_H
43//#include <sys/cdefs.h>
44#include <stdio.h>
45//#include <netinet/in.h>
46// Rajout pour la définition des types
47#include <rpc/types.h>
48
49/*
50 * XDR provides a conventional way for converting between C data
51 * types and an external bit-string representation. Library supplied
52 * routines provide for the conversion on built-in C data types. These
53 * routines and utility routines defined here are used to help implement
54 * a type encode/decode routine for each user-defined type.
55 *
56 * Each data type provides a single procedure which takes two arguments:
57 *
58 * bool_t
59 * xdrproc(xdrs, argresp)
60 * XDR *xdrs;
61 * <type> *argresp;
62 *
63 * xdrs is an instance of a XDR handle, to which or from which the data
64 * type is to be converted. argresp is a pointer to the structure to be
65 * converted. The XDR handle contains an operation field which indicates
66 * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
67 *
68 * XDR_DECODE may allocate space if the pointer argresp is null. This
69 * data can be freed with the XDR_FREE operation.
70 *
71 * We write only one procedure per data type to make it easy
72 * to keep the encode and decode procedures for a data type consistent.
73 * In many cases the same code performs all operations on a user defined type,
74 * because all the hard work is done in the component type routines.
75 * decode as a series of calls on the nested data types.
76 */
77
78/*
79 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
80 * stream. XDR_DECODE causes the type to be extracted from the stream.
81 * XDR_FREE can be used to release the space allocated by an XDR_DECODE
82 * request.
83 */
84enum xdr_op {
87 XDR_FREE=2
88};
89
90/*
91 * This is the number of bytes per unit of external data.
92 */
93#define BYTES_PER_XDR_UNIT (4)
94#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
95 * BYTES_PER_XDR_UNIT)
96
97/*
98 * The XDR handle.
99 * Contains operation which is being applied to the stream,
100 * an operations vector for the particular implementation (e.g. see xdr_mem.c),
101 * and two private fields for the use of the particular implementation.
102 */
103typedef struct __rpc_xdr {
104 enum xdr_op x_op; /* operation; fast additional param */
105 const struct xdr_ops {
106 /* get a long from underlying stream */
107 bool_t (*x_getlong)(struct __rpc_xdr *, long *);
108 /* put a long to " */
109 bool_t (*x_putlong)(struct __rpc_xdr *, const long *);
110 /* get some bytes from " */
111 bool_t (*x_getbytes)(struct __rpc_xdr *, char *, u_int);
112 /* put some bytes to " */
113 bool_t (*x_putbytes)(struct __rpc_xdr *, const char *, u_int);
114 /* returns bytes off from beginning */
116 /* lets you reposition the stream */
118 /* buf quick ptr to buffered data */
119 int32_t *(*x_inline)(struct __rpc_xdr *, u_int);
120 /* free privates of this xdr_stream */
122 bool_t (*x_control)(struct __rpc_xdr *, int, void *);
124 char * x_public; /* users' data */
125 void * x_private; /* pointer to private data */
126 char * x_base; /* private used for position info */
127 u_int x_handy; /* extra private word */
129
130/*
131 * A xdrproc_t exists for each data type which is to be encoded or decoded.
132 *
133 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
134 * The opaque pointer generally points to a structure of the data type
135 * to be decoded. If this pointer is 0, then the type routines should
136 * allocate dynamic storage of the appropriate size and return it.
137 */
138#ifdef _KERNEL
139typedef bool_t (*xdrproc_t)(XDR *, void *, u_int);
140#else
141/*
142 * XXX can't actually prototype it, because some take three args!!!
143 */
144typedef bool_t (*xdrproc_t)(XDR *, ...);
145#endif
146
147/*
148 * Operations defined on a XDR handle
149 *
150 * XDR *xdrs;
151 * long *longp;
152 * char * addr;
153 * u_int len;
154 * u_int pos;
155 */
156#define XDR_GETLONG(xdrs, longp) \
157 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
158#define xdr_getlong(xdrs, longp) \
159 (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
160
161#define XDR_PUTLONG(xdrs, longp) \
162 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
163#define xdr_putlong(xdrs, longp) \
164 (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
165
166static __inline int
168{
169 long l;
170
171 if (!xdr_getlong(xdrs, &l))
172 return (FALSE);
173 *ip = (int32_t)l;
174 return (TRUE);
175}
176
177static __inline int
179{
180 long l;
181
182 l = (long)*ip;
183 return xdr_putlong(xdrs, &l);
184}
185
186#define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p)
187#define XDR_PUTINT32(xdrs, int32p) xdr_putint32(xdrs, int32p)
188
189#define XDR_GETBYTES(xdrs, addr, len) \
190 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
191#define xdr_getbytes(xdrs, addr, len) \
192 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
193
194#define XDR_PUTBYTES(xdrs, addr, len) \
195 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
196#define xdr_putbytes(xdrs, addr, len) \
197 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
198
199#define XDR_GETPOS(xdrs) \
200 (*(xdrs)->x_ops->x_getpostn)(xdrs)
201#define xdr_getpos(xdrs) \
202 (*(xdrs)->x_ops->x_getpostn)(xdrs)
203
204#define XDR_SETPOS(xdrs, pos) \
205 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
206#define xdr_setpos(xdrs, pos) \
207 (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
208
209#define XDR_INLINE(xdrs, len) \
210 (*(xdrs)->x_ops->x_inline)(xdrs, len)
211#define xdr_inline(xdrs, len) \
212 (*(xdrs)->x_ops->x_inline)(xdrs, len)
213
214#define XDR_DESTROY(xdrs) \
215 if ((xdrs)->x_ops->x_destroy) \
216 (*(xdrs)->x_ops->x_destroy)(xdrs)
217#define xdr_destroy(xdrs) \
218 if ((xdrs)->x_ops->x_destroy) \
219 (*(xdrs)->x_ops->x_destroy)(xdrs)
220
221#define XDR_CONTROL(xdrs, req, op) \
222 if ((xdrs)->x_ops->x_control) \
223 (*(xdrs)->x_ops->x_control)(xdrs, req, op)
224#define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op)
225
226/*
227 * Solaris strips the '_t' from these types -- not sure why.
228 * But, let's be compatible.
229 */
230#define xdr_rpcvers(xdrs, versp) xdr_u_int32(xdrs, versp)
231#define xdr_rpcprog(xdrs, progp) xdr_u_int32(xdrs, progp)
232#define xdr_rpcproc(xdrs, procp) xdr_u_int32(xdrs, procp)
233#define xdr_rpcprot(xdrs, protp) xdr_u_int32(xdrs, protp)
234#define xdr_rpcport(xdrs, portp) xdr_u_int32(xdrs, portp)
235
236/*
237 * Support struct for discriminated unions.
238 * You create an array of xdrdiscrim structures, terminated with
239 * an entry with a null procedure pointer. The xdr_union routine gets
240 * the discriminant value and then searches the array of structures
241 * for a matching value. If a match is found the associated xdr routine
242 * is called to handle that part of the union. If there is
243 * no match, then a default routine may be called.
244 * If there is no match and no default routine it is an error.
245 */
246#define NULL_xdrproc_t ((xdrproc_t)0)
248 int value;
250};
251
252/*
253 * In-line routines for fast encode/decode of primitive data types.
254 * Caveat emptor: these use single memory cycles to get the
255 * data from the underlying buffer, and will fail to operate
256 * properly if the data is not aligned. The standard way to use these
257 * is to say:
258 * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
259 * return (FALSE);
260 * <<< macro calls >>>
261 * where ``count'' is the number of bytes of data occupied
262 * by the primitive data types.
263 *
264 * N.B. and frozen for all time: each data type here uses 4 bytes
265 * of external representation.
266 */
267#define IXDR_GET_INT32(buf) ((int32_t)ntohl((u_int32_t)*(buf)++))
268#define IXDR_PUT_INT32(buf, v) (*(buf)++ =(int32_t)htonl((u_int32_t)v))
269#define IXDR_GET_U_INT32(buf) ((u_int32_t)IXDR_GET_INT32(buf))
270#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v)))
271
272#define IXDR_GET_LONG(buf) ((long)ntohl((u_int32_t)*(buf)++))
273#define IXDR_PUT_LONG(buf, v) (*(buf)++ =(int32_t)htonl((u_int32_t)v))
274
275#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
276#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
277#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
278#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
279#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
280
281#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v))
282#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v))
283#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v))
284#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), (v))
285#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), (v))
286
287/*
288 * These are the "generic" xdr routines.
289 */
291extern bool_t xdr_void(void);
292extern bool_t xdr_int(XDR *, int *);
293extern bool_t xdr_u_int(XDR *, u_int *);
294extern bool_t xdr_long(XDR *, long *);
295extern bool_t xdr_u_long(XDR *, u_long *);
296extern bool_t xdr_short(XDR *, short *);
297extern bool_t xdr_u_short(XDR *, u_short *);
298extern bool_t xdr_int16_t(XDR *, int16_t *);
299extern bool_t xdr_u_int16_t(XDR *, u_int16_t *);
300extern bool_t xdr_int32_t(XDR *, int32_t *);
301extern bool_t xdr_u_int32_t(XDR *, u_int32_t *);
302extern bool_t xdr_int64_t(XDR *, int64_t *);
303extern bool_t xdr_u_int64_t(XDR *, u_int64_t *);
304extern bool_t xdr_bool(XDR *, bool_t *);
305extern bool_t xdr_enum(XDR *, enum_t *);
306extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t);
307extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int);
308extern bool_t xdr_opaque(XDR *, char *, u_int);
309extern bool_t xdr_string(XDR *, char **, u_int);
310extern bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t);
311extern bool_t xdr_char(XDR *, char *);
312extern bool_t xdr_u_char(XDR *, u_char *);
313extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t);
314extern bool_t xdr_float(XDR *, float *);
315extern bool_t xdr_double(XDR *, double *);
316extern bool_t xdr_quadruple(XDR *, long double *);
318extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t);
319extern bool_t xdr_wrapstring(XDR *, char **);
320extern void xdr_free(xdrproc_t, void *);
321extern bool_t xdr_hyper(XDR *, quad_t *);
322extern bool_t xdr_u_hyper(XDR *, u_quad_t *);
323extern bool_t xdr_longlong_t(XDR *, quad_t *);
326
327/*
328 * Common opaque bytes objects used by many rpc protocols;
329 * declared here due to commonality.
330 */
331#define MAX_NETOBJ_SZ 1024
332struct netobj {
334 char *n_bytes;
335};
336typedef struct netobj netobj;
337extern bool_t xdr_netobj(XDR *, struct netobj *);
338
339/*
340 * These are the public routines for the various implementations of
341 * xdr streams.
342 */
344/* XDR using memory buffers */
345extern void xdrmem_create(XDR *, char *, u_int, enum xdr_op);
346
347/* XDR using stdio library */
348extern void xdrstdio_create(XDR *, FILE *, enum xdr_op);
349
350/* XDR pseudo records for tcp */
351extern void xdrrec_create(XDR *, u_int, u_int, void *,
352 int (*)(void *, void *, int),
353 int (*)(void *, void *, int));
354
355/* make end of xdr record */
357extern int32_t *xdrrec_getoutbase(XDR *);
358
359/* move to beginning of next record */
361extern void xdrrec_setlastfrag(XDR *);
362
363/* true if no more input */
364extern bool_t xdrrec_eof(XDR *);
367
368#endif /* !_TIRPC_XDR_H */
r l[0]
Definition: byte_order.h:168
UINT32 u_int
Definition: types.h:82
INT64 quad_t
Definition: types.h:85
UINT64 u_quad_t
Definition: types.h:86
UINT64 u_int64_t
Definition: types.h:76
int32_t bool_t
Definition: types.h:101
#define TRUE
Definition: types.h:120
unsigned short u_short
Definition: types.h:81
#define FALSE
Definition: types.h:117
INT32 int32_t
Definition: types.h:71
UCHAR u_char
Definition: types.h:80
INT16 int16_t
Definition: types.h:70
int32_t enum_t
Definition: types.h:102
INT64 int64_t
Definition: types.h:72
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned long u_long
Definition: linux.h:269
#define int32_t
Definition: nsiface.idl:56
#define long
Definition: qsort.c:33
unsigned int u_int32_t
Definition: rosdhcp.h:35
unsigned short u_int16_t
Definition: rosdhcp.h:34
char * caddr_t
Definition: rosdhcp.h:36
void(* x_destroy)(struct __rpc_xdr *)
Definition: xdr.h:121
bool_t(* x_control)(struct __rpc_xdr *, int, void *)
Definition: xdr.h:122
bool_t(* x_getlong)(struct __rpc_xdr *, long *)
Definition: xdr.h:107
bool_t(* x_putlong)(struct __rpc_xdr *, const long *)
Definition: xdr.h:109
bool_t(* x_putbytes)(struct __rpc_xdr *, const char *, u_int)
Definition: xdr.h:113
bool_t(* x_setpostn)(struct __rpc_xdr *, u_int)
Definition: xdr.h:117
u_int(* x_getpostn)(struct __rpc_xdr *)
Definition: xdr.h:115
bool_t(* x_getbytes)(struct __rpc_xdr *, char *, u_int)
Definition: xdr.h:111
Definition: xdr.h:103
const struct __rpc_xdr::xdr_ops * x_ops
enum xdr_op x_op
Definition: xdr.h:104
char * x_base
Definition: xdr.h:126
void * x_private
Definition: xdr.h:125
char * x_public
Definition: xdr.h:124
u_int x_handy
Definition: xdr.h:127
Definition: dhcpd.h:62
Definition: xdr.h:332
u_int n_len
Definition: xdr.h:333
char * n_bytes
Definition: xdr.h:334
int value
Definition: xdr.h:248
xdrproc_t proc
Definition: xdr.h:249
#define __END_DECLS
Definition: wintirpc.h:63
#define __BEGIN_DECLS
Definition: wintirpc.h:62
bool_t xdr_reference(XDR *, char **, u_int, xdrproc_t)
bool_t xdr_netobj(XDR *, struct netobj *)
Definition: xdr.c:609
__BEGIN_DECLS bool_t xdr_void(void)
Definition: xdr.c:92
__BEGIN_DECLS void xdrmem_create(XDR *, char *, u_int, enum xdr_op)
Definition: xdr_mem.c:94
bool_t xdr_double(XDR *, double *)
Definition: xdr_float.c:197
bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t)
bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t)
bool_t xdr_bool(XDR *, bool_t *)
Definition: xdr.c:428
int32_t * xdrrec_getoutbase(XDR *)
Definition: xdr_rec.c:415
bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t)
Definition: xdr.c:629
bool_t xdr_u_longlong_t(XDR *, u_quad_t *)
Definition: xdr.c:912
bool_t xdr_longlong_t(XDR *, quad_t *)
Definition: xdr.c:895
xdr_op
Definition: xdr.h:84
@ XDR_DECODE
Definition: xdr.h:86
@ XDR_FREE
Definition: xdr.h:87
@ XDR_ENCODE
Definition: xdr.h:85
bool_t xdr_u_char(XDR *, u_char *)
Definition: xdr.c:410
bool_t xdr_hyper(XDR *, quad_t *)
Definition: xdr.c:861
bool_t xdrrec_skiprecord(XDR *)
Definition: xdr_rec.c:496
bool_t xdr_string(XDR *, char **, u_int)
Definition: xdr.c:678
u_int xdrrec_readbytes(XDR *, caddr_t, u_int)
struct __rpc_xdr XDR
bool_t xdr_u_int(XDR *, u_int *)
Definition: xdr.c:133
bool_t xdr_quadruple(XDR *, long double *)
void xdr_free(xdrproc_t, void *)
Definition: xdr.c:78
bool_t xdr_int(XDR *, int *)
Definition: xdr.c:103
void xdrrec_setlastfrag(XDR *)
Definition: xdr_rec.c:488
static __inline int xdr_getint32(XDR *xdrs, int32_t *ip)
Definition: xdr.h:167
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
bool_t xdr_bytes(XDR *, char **, u_int *, u_int)
Definition: xdr.c:536
void xdrrec_create(XDR *, u_int, u_int, void *, int(*)(void *, void *, int), int(*)(void *, void *, int))
#define xdr_putlong(xdrs, longp)
Definition: xdr.h:163
bool_t xdr_float(XDR *, float *)
Definition: xdr_float.c:95
bool_t xdr_u_long(XDR *, u_long *)
Definition: xdr.c:186
bool_t xdr_int64_t(XDR *, int64_t *)
Definition: xdr.c:795
bool_t xdr_u_int64_t(XDR *, u_int64_t *)
Definition: xdr.c:828
bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t)
Definition: xdr_array.c:139
bool_t xdr_enum(XDR *, enum_t *)
Definition: xdr.c:458
bool_t xdr_int16_t(XDR *, int16_t *)
Definition: xdr.c:331
bool_t xdr_opaque(XDR *, char *, u_int)
bool_t xdr_int32_t(XDR *, int32_t *)
Definition: xdr.c:208
bool_t xdr_u_int32_t(XDR *, u_int32_t *)
Definition: xdr.c:239
bool_t xdr_u_int16_t(XDR *, u_int16_t *)
Definition: xdr.c:361
bool_t xdr_long(XDR *, long *)
Definition: xdr.c:165
bool_t xdr_u_hyper(XDR *, u_quad_t *)
Definition: xdr.c:878
static __inline int xdr_putint32(XDR *xdrs, int32_t *ip)
Definition: xdr.h:178
bool_t xdr_short(XDR *, short *)
Definition: xdr.c:270
bool_t xdrrec_eof(XDR *)
Definition: xdr_rec.c:531
bool_t xdr_u_short(XDR *, u_short *)
Definition: xdr.c:300
#define xdr_getlong(xdrs, longp)
Definition: xdr.h:158
void xdrstdio_create(XDR *, FILE *, enum xdr_op)
Definition: xdr_stdio.c:79
bool_t xdr_wrapstring(XDR *, char **)
Definition: xdr.c:772
bool_t xdrrec_endofrecord(XDR *, int)
bool_t xdr_char(XDR *, char *)
Definition: xdr.c:392