VM: simplify slab allocator
[minix.git] / lib / libc / rpc / rpcb_prot.c
blob37c73e70d088ef81242d8c7e97278d15e6c374b9
1 /* $NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg Exp $ */
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.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
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.
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.
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.
27 * Sun Microsystems, Inc.
28 * 2550 Garcia Avenue
29 * Mountain View, California 94043
32 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
35 /* #ident "@(#)rpcb_prot.c 1.13 94/04/24 SMI" */
37 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
39 #if 0
40 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro";
41 #else
42 __RCSID("$NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg Exp $");
43 #endif
44 #endif
47 * rpcb_prot.c
48 * XDR routines for the rpcbinder version 3.
50 * Copyright (C) 1984, 1988, Sun Microsystems, Inc.
53 #include "namespace.h"
55 #include <rpc/rpc.h>
56 #include <rpc/types.h>
57 #include <rpc/xdr.h>
58 #include <rpc/rpcb_prot.h>
60 #include <assert.h>
62 #ifdef __weak_alias
63 __weak_alias(xdr_rpcb,_xdr_rpcb)
64 __weak_alias(xdr_rpcblist_ptr,_xdr_rpcblist_ptr)
65 __weak_alias(xdr_rpcblist,_xdr_rpcblist)
66 __weak_alias(xdr_rpcb_entry,_xdr_rpcb_entry)
67 __weak_alias(xdr_rpcb_entry_list_ptr,_xdr_rpcb_entry_list_ptr)
68 __weak_alias(xdr_rpcb_rmtcallargs,_xdr_rpcb_rmtcallargs)
69 __weak_alias(xdr_rpcb_rmtcallres,_xdr_rpcb_rmtcallres)
70 __weak_alias(xdr_netbuf,_xdr_netbuf)
71 #endif
74 bool_t
75 xdr_rpcb(xdrs, objp)
76 XDR *xdrs;
77 RPCB *objp;
80 _DIAGASSERT(objp != NULL);
82 if (!xdr_u_int32_t(xdrs, &objp->r_prog)) {
83 return (FALSE);
85 if (!xdr_u_int32_t(xdrs, &objp->r_vers)) {
86 return (FALSE);
88 if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) {
89 return (FALSE);
91 if (!xdr_string(xdrs, &objp->r_addr, (u_int)~0)) {
92 return (FALSE);
94 if (!xdr_string(xdrs, &objp->r_owner, (u_int)~0)) {
95 return (FALSE);
97 return (TRUE);
101 * rpcblist_ptr implements a linked list. The RPCL definition from
102 * rpcb_prot.x is:
104 * struct rpcblist {
105 * rpcb rpcb_map;
106 * struct rpcblist *rpcb_next;
107 * };
108 * typedef rpcblist *rpcblist_ptr;
110 * Recall that "pointers" in XDR are encoded as a boolean, indicating whether
111 * there's any data behind the pointer, followed by the data (if any exists).
112 * The boolean can be interpreted as ``more data follows me''; if FALSE then
113 * nothing follows the boolean; if TRUE then the boolean is followed by an
114 * actual struct rpcb, and another rpcblist_ptr (declared in RPCL as "struct
115 * rpcblist *").
117 * This could be implemented via the xdr_pointer type, though this would
118 * result in one recursive call per element in the list. Rather than do that
119 * we can ``unwind'' the recursion into a while loop and use xdr_reference to
120 * serialize the rpcb elements.
123 bool_t
124 xdr_rpcblist_ptr(xdrs, rp)
125 XDR *xdrs;
126 rpcblist_ptr *rp;
129 * more_elements is pre-computed in case the direction is
130 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
131 * xdr_bool when the direction is XDR_DECODE.
133 bool_t more_elements;
134 int freeing;
135 rpcblist_ptr next;
136 rpcblist_ptr next_copy;
138 _DIAGASSERT(xdrs != NULL);
139 /* XXX: rp may be NULL ??? */
141 freeing = (xdrs->x_op == XDR_FREE);
142 next = NULL;
144 for (;;) {
145 more_elements = (bool_t)(*rp != NULL);
146 if (! xdr_bool(xdrs, &more_elements)) {
147 return (FALSE);
149 if (! more_elements) {
150 return (TRUE); /* we are done */
153 * the unfortunate side effect of non-recursion is that in
154 * the case of freeing we must remember the next object
155 * before we free the current object ...
157 if (freeing && *rp)
158 next = (*rp)->rpcb_next;
159 if (! xdr_reference(xdrs, (caddr_t *)rp,
160 (u_int)sizeof (rpcblist), (xdrproc_t)xdr_rpcb)) {
161 return (FALSE);
163 if (freeing) {
164 next_copy = next;
165 rp = &next_copy;
167 * Note that in the subsequent iteration, next_copy
168 * gets nulled out by the xdr_reference
169 * but next itself survives.
171 } else if (*rp) {
172 rp = &((*rp)->rpcb_next);
175 /*NOTREACHED*/
179 * xdr_rpcblist() is specified to take a RPCBLIST **, but is identical in
180 * functionality to xdr_rpcblist_ptr().
182 bool_t
183 xdr_rpcblist(xdrs, rp)
184 XDR *xdrs;
185 RPCBLIST **rp;
187 bool_t dummy;
189 dummy = xdr_rpcblist_ptr(xdrs, (rpcblist_ptr *)rp);
190 return (dummy);
194 bool_t
195 xdr_rpcb_entry(xdrs, objp)
196 XDR *xdrs;
197 rpcb_entry *objp;
200 _DIAGASSERT(objp != NULL);
202 if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) {
203 return (FALSE);
205 if (!xdr_string(xdrs, &objp->r_nc_netid, (u_int)~0)) {
206 return (FALSE);
208 if (!xdr_u_int32_t(xdrs, &objp->r_nc_semantics)) {
209 return (FALSE);
211 if (!xdr_string(xdrs, &objp->r_nc_protofmly, (u_int)~0)) {
212 return (FALSE);
214 if (!xdr_string(xdrs, &objp->r_nc_proto, (u_int)~0)) {
215 return (FALSE);
217 return (TRUE);
220 bool_t
221 xdr_rpcb_entry_list_ptr(xdrs, rp)
222 XDR *xdrs;
223 rpcb_entry_list_ptr *rp;
226 * more_elements is pre-computed in case the direction is
227 * XDR_ENCODE or XDR_FREE. more_elements is overwritten by
228 * xdr_bool when the direction is XDR_DECODE.
230 bool_t more_elements;
231 int freeing;
232 rpcb_entry_list_ptr next;
233 rpcb_entry_list_ptr next_copy;
235 _DIAGASSERT(xdrs != NULL);
236 /* XXX: rp is allowed to be NULL ??? */
238 freeing = (xdrs->x_op == XDR_FREE);
239 next = NULL;
241 for (;;) {
242 more_elements = (bool_t)(*rp != NULL);
243 if (! xdr_bool(xdrs, &more_elements)) {
244 return (FALSE);
246 if (! more_elements) {
247 return (TRUE); /* we are done */
250 * the unfortunate side effect of non-recursion is that in
251 * the case of freeing we must remember the next object
252 * before we free the current object ...
254 if (freeing && *rp)
255 next = (*rp)->rpcb_entry_next;
256 if (! xdr_reference(xdrs, (caddr_t *)rp,
257 (u_int)sizeof (rpcb_entry_list),
258 (xdrproc_t)xdr_rpcb_entry)) {
259 return (FALSE);
261 if (freeing) {
262 next_copy = next;
263 rp = &next_copy;
265 * Note that in the subsequent iteration, next_copy
266 * gets nulled out by the xdr_reference
267 * but next itself survives.
269 } else if (*rp) {
270 rp = &((*rp)->rpcb_entry_next);
273 /*NOTREACHED*/
277 * XDR remote call arguments
278 * written for XDR_ENCODE direction only
280 bool_t
281 xdr_rpcb_rmtcallargs(xdrs, p)
282 XDR *xdrs;
283 struct rpcb_rmtcallargs *p;
285 struct r_rpcb_rmtcallargs *objp =
286 (struct r_rpcb_rmtcallargs *)(void *)p;
287 u_int lenposition, argposition, position;
288 int32_t *buf;
290 _DIAGASSERT(p != NULL);
292 buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
293 if (buf == NULL) {
294 if (!xdr_u_int32_t(xdrs, &objp->prog)) {
295 return (FALSE);
297 if (!xdr_u_int32_t(xdrs, &objp->vers)) {
298 return (FALSE);
300 if (!xdr_u_int32_t(xdrs, &objp->proc)) {
301 return (FALSE);
303 } else {
304 IXDR_PUT_U_INT32(buf, objp->prog);
305 IXDR_PUT_U_INT32(buf, objp->vers);
306 IXDR_PUT_U_INT32(buf, objp->proc);
310 * All the jugglery for just getting the size of the arguments
312 lenposition = XDR_GETPOS(xdrs);
313 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
314 return (FALSE);
316 argposition = XDR_GETPOS(xdrs);
317 if (! (*objp->xdr_args)(xdrs, objp->args.args_val)) {
318 return (FALSE);
320 position = XDR_GETPOS(xdrs);
321 objp->args.args_len = (u_int)((u_long)position - (u_long)argposition);
322 XDR_SETPOS(xdrs, lenposition);
323 if (! xdr_u_int(xdrs, &(objp->args.args_len))) {
324 return (FALSE);
326 XDR_SETPOS(xdrs, position);
327 return (TRUE);
331 * XDR remote call results
332 * written for XDR_DECODE direction only
334 bool_t
335 xdr_rpcb_rmtcallres(xdrs, p)
336 XDR *xdrs;
337 struct rpcb_rmtcallres *p;
339 bool_t dummy;
340 struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p;
342 _DIAGASSERT(p != NULL);
344 if (!xdr_string(xdrs, &objp->addr, (u_int)~0)) {
345 return (FALSE);
347 if (!xdr_u_int(xdrs, &objp->results.results_len)) {
348 return (FALSE);
350 dummy = (*(objp->xdr_res))(xdrs, objp->results.results_val);
351 return (dummy);
354 bool_t
355 xdr_netbuf(xdrs, objp)
356 XDR *xdrs;
357 struct netbuf *objp;
359 bool_t dummy;
361 _DIAGASSERT(objp != NULL);
363 if (!xdr_u_int32_t(xdrs, (u_int32_t *) &objp->maxlen)) {
364 return (FALSE);
366 dummy = xdr_bytes(xdrs, (char **)(void *)&(objp->buf),
367 (u_int *)&(objp->len), objp->maxlen);
368 return (dummy);