source: rtems/cpukit/librpc/include/rpc/xdr.h @ f26145b

4.104.114.84.95
Last change on this file since f26145b was dab2d6eb, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/08/05 at 06:01:35

2005-01-07 Ralf Corsepius <ralf.corsepius@…>

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