xref: /freebsd/lib/libc/rpc/rpcb_st_xdr.c (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*	$NetBSD: rpcb_st_xdr.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 2009, Sun Microsystems, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * - Redistributions of source code must retain the above copyright notice,
12  *   this list of conditions and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright notice,
14  *   this list of conditions and the following disclaimer in the documentation
15  *   and/or other materials provided with the distribution.
16  * - Neither the name of Sun Microsystems, Inc. nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Copyright 1991 Sun Microsystems, Inc.
34  * rpcb_stat_xdr.c
35  */
36 
37 /*
38  * This file was generated from rpcb_prot.x, but includes only those
39  * routines used with the rpcbind stats facility.
40  */
41 
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
44 
45 #include "namespace.h"
46 #include <rpc/rpc.h>
47 #include <rpc/rpc_com.h>
48 #include "un-namespace.h"
49 
50 /* Link list of all the stats about getport and getaddr */
51 
52 bool_t
53 xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
54 {
55 	struct rpcbs_addrlist **pnext;
56 
57 	if (!xdr_rpcprog(xdrs, &objp->prog)) {
58 		return (FALSE);
59 	}
60 	if (!xdr_rpcvers(xdrs, &objp->vers)) {
61 		return (FALSE);
62 	}
63 	if (!xdr_int(xdrs, &objp->success)) {
64 		return (FALSE);
65 	}
66 	if (!xdr_int(xdrs, &objp->failure)) {
67 		return (FALSE);
68 	}
69 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
70 		return (FALSE);
71 	}
72 
73 	pnext = &objp->next;
74 	if (!xdr_pointer(xdrs, (char **) pnext,
75 			sizeof (rpcbs_addrlist),
76 			(xdrproc_t)xdr_rpcbs_addrlist)) {
77 		return (FALSE);
78 	}
79 
80 	return (TRUE);
81 }
82 
83 /* Link list of all the stats about rmtcall */
84 
85 bool_t
86 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
87 {
88 	struct rpcbs_rmtcalllist **pnext;
89 	int32_t *buf;
90 
91 	pnext = &objp->next;
92 	if (xdrs->x_op == XDR_ENCODE) {
93 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
94 		if (buf == NULL) {
95 			if (!xdr_rpcprog(xdrs, &objp->prog)) {
96 				return (FALSE);
97 			}
98 			if (!xdr_rpcvers(xdrs, &objp->vers)) {
99 				return (FALSE);
100 			}
101 			if (!xdr_rpcproc(xdrs, &objp->proc)) {
102 				return (FALSE);
103 			}
104 			if (!xdr_int(xdrs, &objp->success)) {
105 				return (FALSE);
106 			}
107 			if (!xdr_int(xdrs, &objp->failure)) {
108 				return (FALSE);
109 			}
110 			if (!xdr_int(xdrs, &objp->indirect)) {
111 				return (FALSE);
112 			}
113 		} else {
114 			IXDR_PUT_U_INT32(buf, objp->prog);
115 			IXDR_PUT_U_INT32(buf, objp->vers);
116 			IXDR_PUT_U_INT32(buf, objp->proc);
117 			IXDR_PUT_INT32(buf, objp->success);
118 			IXDR_PUT_INT32(buf, objp->failure);
119 			IXDR_PUT_INT32(buf, objp->indirect);
120 		}
121 		if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
122 			return (FALSE);
123 		}
124 		if (!xdr_pointer(xdrs, (char **) pnext,
125 				sizeof (rpcbs_rmtcalllist),
126 				(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
127 			return (FALSE);
128 		}
129 		return (TRUE);
130 	} else if (xdrs->x_op == XDR_DECODE) {
131 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
132 		if (buf == NULL) {
133 			if (!xdr_rpcprog(xdrs, &objp->prog)) {
134 				return (FALSE);
135 			}
136 			if (!xdr_rpcvers(xdrs, &objp->vers)) {
137 				return (FALSE);
138 			}
139 			if (!xdr_rpcproc(xdrs, &objp->proc)) {
140 				return (FALSE);
141 			}
142 			if (!xdr_int(xdrs, &objp->success)) {
143 				return (FALSE);
144 			}
145 			if (!xdr_int(xdrs, &objp->failure)) {
146 				return (FALSE);
147 			}
148 			if (!xdr_int(xdrs, &objp->indirect)) {
149 				return (FALSE);
150 			}
151 		} else {
152 			objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
153 			objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
154 			objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
155 			objp->success = (int)IXDR_GET_INT32(buf);
156 			objp->failure = (int)IXDR_GET_INT32(buf);
157 			objp->indirect = (int)IXDR_GET_INT32(buf);
158 		}
159 		if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
160 			return (FALSE);
161 		}
162 		if (!xdr_pointer(xdrs, (char **) pnext,
163 				sizeof (rpcbs_rmtcalllist),
164 				(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
165 			return (FALSE);
166 		}
167 		return (TRUE);
168 	}
169 	if (!xdr_rpcprog(xdrs, &objp->prog)) {
170 		return (FALSE);
171 	}
172 	if (!xdr_rpcvers(xdrs, &objp->vers)) {
173 		return (FALSE);
174 	}
175 	if (!xdr_rpcproc(xdrs, &objp->proc)) {
176 		return (FALSE);
177 	}
178 	if (!xdr_int(xdrs, &objp->success)) {
179 		return (FALSE);
180 	}
181 	if (!xdr_int(xdrs, &objp->failure)) {
182 		return (FALSE);
183 	}
184 	if (!xdr_int(xdrs, &objp->indirect)) {
185 		return (FALSE);
186 	}
187 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
188 		return (FALSE);
189 	}
190 	if (!xdr_pointer(xdrs, (char **) pnext,
191 			sizeof (rpcbs_rmtcalllist),
192 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
193 		return (FALSE);
194 	}
195 	return (TRUE);
196 }
197 
198 bool_t
199 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
200 {
201 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
202 	    sizeof (int), (xdrproc_t)xdr_int)) {
203 		return (FALSE);
204 	}
205 	return (TRUE);
206 }
207 
208 bool_t
209 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
210 {
211 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
212 			(xdrproc_t)xdr_rpcbs_addrlist)) {
213 		return (FALSE);
214 	}
215 	return (TRUE);
216 }
217 
218 bool_t
219 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
220 {
221 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
222 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
223 		return (FALSE);
224 	}
225 	return (TRUE);
226 }
227 
228 bool_t
229 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
230 {
231 
232 	if (!xdr_rpcbs_proc(xdrs, objp->info)) {
233 		return (FALSE);
234 	}
235 	if (!xdr_int(xdrs, &objp->setinfo)) {
236 		return (FALSE);
237 	}
238 	if (!xdr_int(xdrs, &objp->unsetinfo)) {
239 		return (FALSE);
240 	}
241 	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
242 		return (FALSE);
243 	}
244 	if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
245 		return (FALSE);
246 	}
247 	return (TRUE);
248 }
249 
250 /*
251  * One rpcb_stat structure is returned for each version of rpcbind
252  * being monitored.
253  */
254 bool_t
255 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
256 {
257 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
258 	    sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
259 		return (FALSE);
260 	}
261 	return (TRUE);
262 }
263