xref: /freebsd/lib/libc/rpc/rpcb_st_xdr.c (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
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 
75 	    if (!xdr_pointer(xdrs, (char **) pnext,
76 			sizeof (rpcbs_addrlist),
77 			(xdrproc_t)xdr_rpcbs_addrlist)) {
78 		return (FALSE);
79 	    }
80 
81 	return (TRUE);
82 }
83 
84 /* Link list of all the stats about rmtcall */
85 
86 bool_t
87 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
88 {
89 	int32_t *buf;
90 	struct rpcbs_rmtcalllist **pnext;
91 
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 	pnext = &objp->next;
125 	if (!xdr_pointer(xdrs, (char **) pnext,
126 			sizeof (rpcbs_rmtcalllist),
127 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
128 		return (FALSE);
129 	}
130 	return (TRUE);
131 	} else if (xdrs->x_op == XDR_DECODE) {
132 	buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
133 	if (buf == NULL) {
134 		if (!xdr_rpcprog(xdrs, &objp->prog)) {
135 			return (FALSE);
136 		}
137 		if (!xdr_rpcvers(xdrs, &objp->vers)) {
138 			return (FALSE);
139 		}
140 		if (!xdr_rpcproc(xdrs, &objp->proc)) {
141 			return (FALSE);
142 		}
143 		if (!xdr_int(xdrs, &objp->success)) {
144 			return (FALSE);
145 		}
146 		if (!xdr_int(xdrs, &objp->failure)) {
147 			return (FALSE);
148 		}
149 		if (!xdr_int(xdrs, &objp->indirect)) {
150 			return (FALSE);
151 		}
152 	} else {
153 		objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
154 		objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
155 		objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
156 		objp->success = (int)IXDR_GET_INT32(buf);
157 		objp->failure = (int)IXDR_GET_INT32(buf);
158 		objp->indirect = (int)IXDR_GET_INT32(buf);
159 	}
160 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
161 		return (FALSE);
162 	}
163 	if (!xdr_pointer(xdrs, (char **) pnext,
164 			sizeof (rpcbs_rmtcalllist),
165 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
166 		return (FALSE);
167 	}
168 	return (TRUE);
169 	}
170 	if (!xdr_rpcprog(xdrs, &objp->prog)) {
171 		return (FALSE);
172 	}
173 	if (!xdr_rpcvers(xdrs, &objp->vers)) {
174 		return (FALSE);
175 	}
176 	if (!xdr_rpcproc(xdrs, &objp->proc)) {
177 		return (FALSE);
178 	}
179 	if (!xdr_int(xdrs, &objp->success)) {
180 		return (FALSE);
181 	}
182 	if (!xdr_int(xdrs, &objp->failure)) {
183 		return (FALSE);
184 	}
185 	if (!xdr_int(xdrs, &objp->indirect)) {
186 		return (FALSE);
187 	}
188 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
189 		return (FALSE);
190 	}
191 	if (!xdr_pointer(xdrs, (char **) pnext,
192 			sizeof (rpcbs_rmtcalllist),
193 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
194 		return (FALSE);
195 	}
196 	return (TRUE);
197 }
198 
199 bool_t
200 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
201 {
202 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
203 	    sizeof (int), (xdrproc_t)xdr_int)) {
204 		return (FALSE);
205 	}
206 	return (TRUE);
207 }
208 
209 bool_t
210 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
211 {
212 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
213 			(xdrproc_t)xdr_rpcbs_addrlist)) {
214 		return (FALSE);
215 	}
216 	return (TRUE);
217 }
218 
219 bool_t
220 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
221 {
222 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
223 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
224 		return (FALSE);
225 	}
226 	return (TRUE);
227 }
228 
229 bool_t
230 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
231 {
232 
233 	if (!xdr_rpcbs_proc(xdrs, objp->info)) {
234 		return (FALSE);
235 	}
236 	if (!xdr_int(xdrs, &objp->setinfo)) {
237 		return (FALSE);
238 	}
239 	if (!xdr_int(xdrs, &objp->unsetinfo)) {
240 		return (FALSE);
241 	}
242 	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
243 		return (FALSE);
244 	}
245 	if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
246 		return (FALSE);
247 	}
248 	return (TRUE);
249 }
250 
251 /*
252  * One rpcb_stat structure is returned for each version of rpcbind
253  * being monitored.
254  */
255 bool_t
256 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
257 {
258 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
259 	    sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
260 		return (FALSE);
261 	}
262 	return (TRUE);
263 }
264