MySQL 8.4.0
Source Code Documentation
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 GNU General Public License, version 2.0, for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 @file windeps/sunrpc/rpc/xdr.h
26 External Data Representation Serialization Routines.
29#ifndef _RPC_XDR_H
30#define _RPC_XDR_H 1
32#ifdef __linux__
33#include <features.h>
36#include <rpc/types.h>
37#include <sys/types.h>
39/* We need FILE. */
40#include <stdio.h>
45 * XDR provides a conventional way for converting between C data
46 * types and an external bit-string representation. Library supplied
47 * routines provide for the conversion on built-in C data types. These
48 * routines and utility routines defined here are used to help implement
49 * a type encode/decode routine for each user-defined type.
50 *
51 * Each data type provides a single procedure which takes two arguments:
52 *
53 * bool_t
54 * xdrproc(xdrs, argresp)
55 * XDR *xdrs;
56 * <type> *argresp;
57 *
58 * xdrs is an instance of a XDR handle, to which or from which the data
59 * type is to be converted. argresp is a pointer to the structure to be
60 * converted. The XDR handle contains an operation field which indicates
61 * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
62 *
63 * XDR_DECODE may allocate space if the pointer argresp is null. This
64 * data can be freed with the XDR_FREE operation.
65 *
66 * We write only one procedure per data type to make it easy
67 * to keep the encode and decode procedures for a data type consistent.
68 * In many cases the same code performs all operations on a user defined type,
69 * because all the hard work is done in the component type routines.
70 * decode as a series of calls on the nested data types.
71 */
74 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
75 * stream. XDR_DECODE causes the type to be extracted from the stream.
76 * XDR_FREE can be used to release the space allocated by an XDR_DECODE
77 * request.
78 */
79enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 };
82 * This is the number of bytes per unit of external data.
83 */
84#define BYTES_PER_XDR_UNIT (4)
86 * This only works if the above is a power of 2. But it's defined to be
87 * 4 by the appropriate RFCs. So it will work. And it's normally quicker
88 * than the old routine.
89 */
90#if 1
91#define RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1))
92#else /* this is the old routine */
93#define RNDUP(x) \
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 XDR XDR;
104struct XDR {
105 enum xdr_op x_op; /* operation; fast additional param */
106 struct xdr_ops {
107 bool_t (*x_getlong)(XDR *__xdrs, long *__lp);
108 /* get a long from underlying stream */
109 bool_t (*x_putlong)(XDR *__xdrs, __const long *__lp);
110 /* put a long to " */
111 bool_t (*x_getbytes)(XDR *__xdrs, caddr_t __addr, u_int __len);
112 /* get some bytes from " */
113 bool_t (*x_putbytes)(XDR *__xdrs, __const char *__addr, u_int __len);
114 /* put some bytes to " */
115 u_int (*x_getpostn)(__const XDR *__xdrs);
116 /* returns bytes off from beginning */
117 bool_t (*x_setpostn)(XDR *__xdrs, u_int __pos);
118 /* lets you reposition the stream */
119 int32_t *(*x_inline)(XDR *__xdrs, u_int __len);
120 /* buf quick ptr to buffered data */
121 void (*x_destroy)(XDR *__xdrs);
122 /* free privates of this xdr_stream */
123 bool_t (*x_getint32)(XDR *__xdrs, int32_t *__ip);
124 /* get a int from underlying stream */
125 bool_t (*x_putint32)(XDR *__xdrs, __const int32_t *__ip);
126 /* put a int to " */
127 } * x_ops;
128 caddr_t x_public; /* users' data */
129 caddr_t x_private; /* pointer to private data */
130 caddr_t x_base; /* private used for position info */
131 u_int x_handy; /* extra private word */
135 * A xdrproc_t exists for each data type which is to be encoded or decoded.
136 *
137 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
138 * The opaque pointer generally points to a structure of the data type
139 * to be decoded. If this pointer is 0, then the type routines should
140 * allocate dynamic storage of the appropriate size and return it.
141 * bool_t (*xdrproc_t)(XDR *, caddr_t *);
142 */
143typedef bool_t (*xdrproc_t)(XDR *, void *, ...);
146 * Operations defined on a XDR handle
147 *
148 * XDR *xdrs;
149 * int32_t *int32p;
150 * long *longp;
151 * caddr_t addr;
152 * u_int len;
153 * u_int pos;
154 */
155#define XDR_GETINT32(xdrs, int32p) (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
156#define xdr_getint32(xdrs, int32p) (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
158#define XDR_PUTINT32(xdrs, int32p) (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
159#define xdr_putint32(xdrs, int32p) (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
161#define XDR_GETLONG(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
162#define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
164#define XDR_PUTLONG(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
165#define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
167#define XDR_GETBYTES(xdrs, addr, len) \
168 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
169#define xdr_getbytes(xdrs, addr, len) \
170 (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
172#define XDR_PUTBYTES(xdrs, addr, len) \
173 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
174#define xdr_putbytes(xdrs, addr, len) \
175 (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
177#define XDR_GETPOS(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs)
178#define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs)
180#define XDR_SETPOS(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
181#define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
183#define XDR_INLINE(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len)
184#define xdr_inline(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len)
186#define XDR_DESTROY(xdrs) \
187 do { \
188 if ((xdrs)->x_ops->x_destroy) (*(xdrs)->x_ops->x_destroy)(xdrs); \
189 } while (0)
190#define xdr_destroy(xdrs) \
191 do { \
192 if ((xdrs)->x_ops->x_destroy) (*(xdrs)->x_ops->x_destroy)(xdrs); \
193 } while (0)
196 * Support struct for discriminated unions.
197 * You create an array of xdrdiscrim structures, terminated with
198 * a entry with a null procedure pointer. The xdr_union routine gets
199 * the discriminant value and then searches the array of structures
200 * for a matching value. If a match is found the associated xdr routine
201 * is called to handle that part of the union. If there is
202 * no match, then a default routine may be called.
203 * If there is no match and no default routine it is an error.
204 */
205#define NULL_xdrproc_t ((xdrproc_t)0)
207 int value;
212 * Inline routines for fast encode/decode of primitive data types.
213 * Caveat emptor: these use single memory cycles to get the
214 * data from the underlying buffer, and will fail to operate
215 * properly if the data is not aligned. The standard way to use these
216 * is to say:
217 * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
218 * return (FALSE);
219 * <<< macro calls >>>
220 * where ``count'' is the number of bytes of data occupied
221 * by the primitive data types.
222 *
223 * N.B. and frozen for all time: each data type here uses 4 bytes
224 * of external representation.
225 */
227#define IXDR_GET_INT32(buf) ((int32_t)ntohl((uint32_t) * (buf)++))
228#define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((uint32_t)(v)))
229#define IXDR_GET_U_INT32(buf) ((uint32_t)IXDR_GET_INT32(buf))
230#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32(buf, (int32_t)(v))
232/* WARNING: The IXDR_*_LONG defines are removed by Sun for new platforms
233 * and shouldn't be used any longer. Code which use this defines or longs
234 * in the RPC code will not work on 64bit Solaris platforms !
235 */
236#define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf))
237#define IXDR_PUT_LONG(buf, v) ((long)IXDR_PUT_INT32(buf, (long)(v)))
238#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf))
239#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG(buf, (long)(v))
241#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
242#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
243#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
244#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf))
246#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG(buf, (long)(v))
247#define IXDR_PUT_ENUM(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.
253 * None of these can have const applied because it's not possible to
254 * know whether the call is a read or a write to the passed parameter
255 * also, the XDR structure is always updated by some of these calls.
256 */
257extern bool_t xdr_void(void) __THROW;
258extern bool_t xdr_short(XDR *__xdrs, short *__sp) __THROW;
259extern bool_t xdr_u_short(XDR *__xdrs, u_short *__usp) __THROW;
260extern bool_t xdr_int(XDR *__xdrs, int *__ip) __THROW;
261extern bool_t xdr_u_int(XDR *__xdrs, u_int *__up) __THROW;
262extern bool_t xdr_long(XDR *__xdrs, long *__lp) __THROW;
263extern bool_t xdr_u_long(XDR *__xdrs, u_long *__ulp) __THROW;
264extern bool_t xdr_hyper(XDR *__xdrs, quad_t *__llp) __THROW;
265extern bool_t xdr_u_hyper(XDR *__xdrs, u_quad_t *__ullp) __THROW;
266extern bool_t xdr_longlong_t(XDR *__xdrs, quad_t *__llp) __THROW;
267extern bool_t xdr_u_longlong_t(XDR *__xdrs, u_quad_t *__ullp) __THROW;
268extern bool_t xdr_int8_t(XDR *__xdrs, int8_t *__ip) __THROW;
269extern bool_t xdr_uint8_t(XDR *__xdrs, uint8_t *__up) __THROW;
270extern bool_t xdr_int16_t(XDR *__xdrs, int16_t *__ip) __THROW;
271extern bool_t xdr_uint16_t(XDR *__xdrs, uint16_t *__up) __THROW;
272extern bool_t xdr_int32_t(XDR *__xdrs, int32_t *__ip) __THROW;
273extern bool_t xdr_uint32_t(XDR *__xdrs, uint32_t *__up) __THROW;
274extern bool_t xdr_int64_t(XDR *__xdrs, int64_t *__ip) __THROW;
275extern bool_t xdr_uint64_t(XDR *__xdrs, uint64_t *__up) __THROW;
276extern bool_t xdr_quad_t(XDR *__xdrs, quad_t *__ip) __THROW;
277extern bool_t xdr_u_quad_t(XDR *__xdrs, u_quad_t *__up) __THROW;
278extern bool_t xdr_bool(XDR *__xdrs, bool_t *__bp) __THROW;
279extern bool_t xdr_enum(XDR *__xdrs, enum_t *__ep) __THROW;
280extern bool_t xdr_array(XDR *_xdrs, caddr_t *__addrp, u_int *__sizep,
281 u_int __maxsize, u_int __elsize,
282 xdrproc_t __elproc) __THROW;
283extern bool_t xdr_bytes(XDR *__xdrs, char **__cpp, u_int *__sizep,
284 u_int __maxsize) __THROW;
285extern bool_t xdr_opaque(XDR *__xdrs, caddr_t __cp, u_int __cnt) __THROW;
286extern bool_t xdr_string(XDR *__xdrs, char **__cpp, u_int __maxsize) __THROW;
287extern bool_t xdr_union(XDR *__xdrs, enum_t *__dscmp, char *__unp,
288 __const struct xdr_discrim *__choices,
289 xdrproc_t __dfault) __THROW;
290extern bool_t xdr_char(XDR *__xdrs, char *__cp) __THROW;
291extern bool_t xdr_u_char(XDR *__xdrs, u_char *__cp) __THROW;
292extern bool_t xdr_vector(XDR *__xdrs, char *__basep, u_int __nelem,
293 u_int __elemsize, xdrproc_t __xdr_elem) __THROW;
294extern bool_t xdr_float(XDR *__xdrs, float *__fp) __THROW;
295extern bool_t xdr_double(XDR *__xdrs, double *__dp) __THROW;
296extern bool_t xdr_reference(XDR *__xdrs, caddr_t *__xpp, u_int __size,
297 xdrproc_t __proc) __THROW;
298extern bool_t xdr_pointer(XDR *__xdrs, char **__objpp, u_int __obj_size,
299 xdrproc_t __xdr_obj) __THROW;
300extern bool_t xdr_wrapstring(XDR *__xdrs, char **__cpp) __THROW;
301extern u_long xdr_sizeof(xdrproc_t, void *) __THROW;
304 * Common opaque bytes objects used by many rpc protocols;
305 * declared here due to commonality.
306 */
307#define MAX_NETOBJ_SZ 1024
308struct netobj {
310 char *n_bytes;
312typedef struct netobj netobj;
313extern bool_t xdr_netobj(XDR *__xdrs, struct netobj *__np) __THROW;
316 * These are the public routines for the various implementations of
317 * xdr streams.
318 */
320/* XDR using memory buffers */
321extern void xdrmem_create(XDR *__xdrs, __const caddr_t __addr, u_int __size,
322 enum xdr_op __xop) __THROW;
324/* XDR using stdio library */
325extern void xdrstdio_create(XDR *__xdrs, FILE *__file,
326 enum xdr_op __xop) __THROW;
328/* XDR pseudo records for tcp */
329extern void xdrrec_create(XDR *__xdrs, u_int __sendsize, u_int __recvsize,
330 caddr_t __tcp_handle,
331 int (*__readit)(char *, char *, int),
332 int (*__writeit)(char *, char *, int)) __THROW;
334/* make end of xdr record */
335extern bool_t xdrrec_endofrecord(XDR *__xdrs, bool_t __sendnow) __THROW;
337/* move to beginning of next record */
338extern bool_t xdrrec_skiprecord(XDR *__xdrs) __THROW;
340/* true if no more input */
341extern bool_t xdrrec_eof(XDR *__xdrs) __THROW;
343/* free memory buffers for xdr */
344extern void xdr_free(xdrproc_t __proc, char *__objp) __THROW;
348#endif /* rpc/xdr.h */
const std::string FILE("FILE")
Definition: xdr.h:106
u_int(* x_getpostn)(__const XDR *__xdrs)
Definition: xdr.h:115
bool_t(* x_getbytes)(XDR *__xdrs, caddr_t __addr, u_int __len)
Definition: xdr.h:111
bool_t(* x_putlong)(XDR *__xdrs, __const long *__lp)
Definition: xdr.h:109
void(* x_destroy)(XDR *__xdrs)
Definition: xdr.h:121
bool_t(* x_getint32)(XDR *__xdrs, int32_t *__ip)
Definition: xdr.h:123
bool_t(* x_getlong)(XDR *__xdrs, long *__lp)
Definition: xdr.h:107
bool_t(* x_setpostn)(XDR *__xdrs, u_int __pos)
Definition: xdr.h:117
bool_t(* x_putbytes)(XDR *__xdrs, __const char *__addr, u_int __len)
Definition: xdr.h:113
bool_t(* x_putint32)(XDR *__xdrs, __const int32_t *__ip)
Definition: xdr.h:125
Definition: xdr.h:104
caddr_t x_public
Definition: xdr.h:128
struct XDR::xdr_ops * x_ops
caddr_t x_base
Definition: xdr.h:130
u_int x_handy
Definition: xdr.h:131
caddr_t x_private
Definition: xdr.h:129
enum xdr_op x_op
Definition: xdr.h:105
Definition: xdr.h:308
u_int n_len
Definition: xdr.h:309
char * n_bytes
Definition: xdr.h:310
Definition: xdr.h:206
int value
Definition: xdr.h:207
xdrproc_t proc
Definition: xdr.h:208
__u_int u_int
Definition: types.h:73
__u_long u_long
Definition: types.h:74
__u_short u_short
Definition: types.h:72
int bool_t
Definition: types.h:35
__quad_t quad_t
Definition: types.h:75
__u_char u_char
Definition: types.h:71
__caddr_t caddr_t
Definition: types.h:82
int enum_t
Definition: types.h:36
__u_quad_t u_quad_t
Definition: types.h:76
bool_t xdr_u_short(XDR *__xdrs, u_short *__usp) __THROW
Definition: xdr.c:307
bool_t(* xdrproc_t)(XDR *, void *,...)
Definition: xdr.h:143
void xdrrec_create(XDR *__xdrs, u_int __sendsize, u_int __recvsize, caddr_t __tcp_handle, int(*__readit)(char *, char *, int), int(*__writeit)(char *, char *, int)) __THROW
bool_t xdrrec_skiprecord(XDR *__xdrs) __THROW
bool_t xdr_u_int(XDR *__xdrs, u_int *__up) __THROW
Definition: xdr.c:123
bool_t xdr_wrapstring(XDR *__xdrs, char **__cpp) __THROW
Definition: xdr.c:651
bool_t xdr_u_hyper(XDR *__xdrs, u_quad_t *__ullp) __THROW
Definition: xdr.c:241
bool_t xdr_vector(XDR *__xdrs, char *__basep, u_int __nelem, u_int __elemsize, xdrproc_t __xdr_elem) __THROW
Definition: xdr_array.c:125
void xdrmem_create(XDR *__xdrs, __const caddr_t __addr, u_int __size, enum xdr_op __xop) __THROW
bool_t xdr_quad_t(XDR *__xdrs, quad_t *__ip) __THROW
bool_t xdr_uint16_t(XDR *__xdrs, uint16_t *__up) __THROW
bool_t xdr_uint8_t(XDR *__xdrs, uint8_t *__up) __THROW
bool_t xdr_u_longlong_t(XDR *__xdrs, u_quad_t *__ullp) __THROW
Definition: xdr.c:267
void xdrstdio_create(XDR *__xdrs, FILE *__file, enum xdr_op __xop) __THROW
bool_t xdr_netobj(XDR *__xdrs, struct netobj *__np) __THROW
Definition: xdr.c:520
Definition: xdr.h:79
Definition: xdr.h:79
Definition: xdr.h:79
Definition: xdr.h:79
bool_t xdr_string(XDR *__xdrs, char **__cpp, u_int __maxsize) __THROW
Definition: xdr.c:584
bool_t xdr_char(XDR *__xdrs, char *__cp) __THROW
Definition: xdr.c:332
bool_t xdr_int16_t(XDR *__xdrs, int16_t *__ip) __THROW
bool_t xdr_double(XDR *__xdrs, double *__dp) __THROW
Definition: xdr_float.c:187
bool_t xdr_void(void) __THROW
Definition: xdr.c:73
bool_t xdr_pointer(XDR *__xdrs, char **__objpp, u_int __obj_size, xdrproc_t __xdr_obj) __THROW
Definition: xdr_ref.c:104
bool_t xdr_float(XDR *__xdrs, float *__fp) __THROW
Definition: xdr_float.c:76
bool_t xdr_reference(XDR *__xdrs, caddr_t *__xpp, u_int __size, xdrproc_t __proc) __THROW
Definition: xdr_ref.c:52
bool_t xdr_int32_t(XDR *__xdrs, int32_t *__ip) __THROW
Definition: xdr.c:107
void xdr_free(xdrproc_t __proc, char *__objp) __THROW
Definition: xdr.c:63
bool_t xdr_long(XDR *__xdrs, long *__lp) __THROW
Definition: xdr.c:169
bool_t xdr_u_long(XDR *__xdrs, u_long *__ulp) __THROW
Definition: xdr.c:187
bool_t xdr_bytes(XDR *__xdrs, char **__cpp, u_int *__sizep, u_int __maxsize) __THROW
Definition: xdr.c:467
bool_t xdr_int64_t(XDR *__xdrs, int64_t *__ip) __THROW
bool_t xdr_longlong_t(XDR *__xdrs, quad_t *__llp) __THROW
Definition: xdr.c:263
bool_t xdrrec_eof(XDR *__xdrs) __THROW
bool_t xdr_bool(XDR *__xdrs, bool_t *__bp) __THROW
Definition: xdr.c:360
bool_t xdr_enum(XDR *__xdrs, enum_t *__ep) __THROW
Definition: xdr.c:385
bool_t xdr_union(XDR *__xdrs, enum_t *__dscmp, char *__unp, __const struct xdr_discrim *__choices, xdrproc_t __dfault) __THROW
bool_t xdr_short(XDR *__xdrs, short *__sp) __THROW
Definition: xdr.c:282
bool_t xdrrec_endofrecord(XDR *__xdrs, bool_t __sendnow) __THROW
u_long xdr_sizeof(xdrproc_t, void *) __THROW
Definition: xdr_sizeof.c:95
bool_t xdr_u_char(XDR *__xdrs, u_char *__cp) __THROW
Definition: xdr.c:346
bool_t xdr_uint32_t(XDR *__xdrs, uint32_t *__up) __THROW
Definition: xdr.c:151
bool_t xdr_opaque(XDR *__xdrs, caddr_t __cp, u_int __cnt) __THROW
Definition: xdr.c:425
bool_t xdr_u_quad_t(XDR *__xdrs, u_quad_t *__up) __THROW
bool_t xdr_uint64_t(XDR *__xdrs, uint64_t *__up) __THROW
bool_t xdr_array(XDR *_xdrs, caddr_t *__addrp, u_int *__sizep, u_int __maxsize, u_int __elsize, xdrproc_t __elproc) __THROW
Definition: xdr_array.c:51
bool_t xdr_hyper(XDR *__xdrs, quad_t *__llp) __THROW
Definition: xdr.c:215
bool_t xdr_int(XDR *__xdrs, int *__ip) __THROW
Definition: xdr.c:79
bool_t xdr_int8_t(XDR *__xdrs, int8_t *__ip) __THROW