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