xref: /freebsd/lib/libc/rpc/rpcb_st_xdr.c (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
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 "namespace.h"
43 #include <rpc/rpc.h>
44 #include <rpc/rpc_com.h>
45 #include "un-namespace.h"
46 
47 /* Link list of all the stats about getport and getaddr */
48 
49 bool_t
50 xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
51 {
52 	struct rpcbs_addrlist **pnext;
53 
54 	if (!xdr_rpcprog(xdrs, &objp->prog)) {
55 		return (FALSE);
56 	}
57 	if (!xdr_rpcvers(xdrs, &objp->vers)) {
58 		return (FALSE);
59 	}
60 	if (!xdr_int(xdrs, &objp->success)) {
61 		return (FALSE);
62 	}
63 	if (!xdr_int(xdrs, &objp->failure)) {
64 		return (FALSE);
65 	}
66 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
67 		return (FALSE);
68 	}
69 
70 	pnext = &objp->next;
71 	if (!xdr_pointer(xdrs, (char **) pnext,
72 			sizeof (rpcbs_addrlist),
73 			(xdrproc_t)xdr_rpcbs_addrlist)) {
74 		return (FALSE);
75 	}
76 
77 	return (TRUE);
78 }
79 
80 /* Link list of all the stats about rmtcall */
81 
82 bool_t
83 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
84 {
85 	struct rpcbs_rmtcalllist **pnext;
86 	int32_t *buf;
87 
88 	pnext = &objp->next;
89 	if (xdrs->x_op == XDR_ENCODE) {
90 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
91 		if (buf == NULL) {
92 			if (!xdr_rpcprog(xdrs, &objp->prog)) {
93 				return (FALSE);
94 			}
95 			if (!xdr_rpcvers(xdrs, &objp->vers)) {
96 				return (FALSE);
97 			}
98 			if (!xdr_rpcproc(xdrs, &objp->proc)) {
99 				return (FALSE);
100 			}
101 			if (!xdr_int(xdrs, &objp->success)) {
102 				return (FALSE);
103 			}
104 			if (!xdr_int(xdrs, &objp->failure)) {
105 				return (FALSE);
106 			}
107 			if (!xdr_int(xdrs, &objp->indirect)) {
108 				return (FALSE);
109 			}
110 		} else {
111 			IXDR_PUT_U_INT32(buf, objp->prog);
112 			IXDR_PUT_U_INT32(buf, objp->vers);
113 			IXDR_PUT_U_INT32(buf, objp->proc);
114 			IXDR_PUT_INT32(buf, objp->success);
115 			IXDR_PUT_INT32(buf, objp->failure);
116 			IXDR_PUT_INT32(buf, objp->indirect);
117 		}
118 		if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
119 			return (FALSE);
120 		}
121 		if (!xdr_pointer(xdrs, (char **) pnext,
122 				sizeof (rpcbs_rmtcalllist),
123 				(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
124 			return (FALSE);
125 		}
126 		return (TRUE);
127 	} else if (xdrs->x_op == XDR_DECODE) {
128 		buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
129 		if (buf == NULL) {
130 			if (!xdr_rpcprog(xdrs, &objp->prog)) {
131 				return (FALSE);
132 			}
133 			if (!xdr_rpcvers(xdrs, &objp->vers)) {
134 				return (FALSE);
135 			}
136 			if (!xdr_rpcproc(xdrs, &objp->proc)) {
137 				return (FALSE);
138 			}
139 			if (!xdr_int(xdrs, &objp->success)) {
140 				return (FALSE);
141 			}
142 			if (!xdr_int(xdrs, &objp->failure)) {
143 				return (FALSE);
144 			}
145 			if (!xdr_int(xdrs, &objp->indirect)) {
146 				return (FALSE);
147 			}
148 		} else {
149 			objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
150 			objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
151 			objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
152 			objp->success = (int)IXDR_GET_INT32(buf);
153 			objp->failure = (int)IXDR_GET_INT32(buf);
154 			objp->indirect = (int)IXDR_GET_INT32(buf);
155 		}
156 		if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
157 			return (FALSE);
158 		}
159 		if (!xdr_pointer(xdrs, (char **) pnext,
160 				sizeof (rpcbs_rmtcalllist),
161 				(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
162 			return (FALSE);
163 		}
164 		return (TRUE);
165 	}
166 	if (!xdr_rpcprog(xdrs, &objp->prog)) {
167 		return (FALSE);
168 	}
169 	if (!xdr_rpcvers(xdrs, &objp->vers)) {
170 		return (FALSE);
171 	}
172 	if (!xdr_rpcproc(xdrs, &objp->proc)) {
173 		return (FALSE);
174 	}
175 	if (!xdr_int(xdrs, &objp->success)) {
176 		return (FALSE);
177 	}
178 	if (!xdr_int(xdrs, &objp->failure)) {
179 		return (FALSE);
180 	}
181 	if (!xdr_int(xdrs, &objp->indirect)) {
182 		return (FALSE);
183 	}
184 	if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
185 		return (FALSE);
186 	}
187 	if (!xdr_pointer(xdrs, (char **) pnext,
188 			sizeof (rpcbs_rmtcalllist),
189 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
190 		return (FALSE);
191 	}
192 	return (TRUE);
193 }
194 
195 bool_t
196 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
197 {
198 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
199 	    sizeof (int), (xdrproc_t)xdr_int)) {
200 		return (FALSE);
201 	}
202 	return (TRUE);
203 }
204 
205 bool_t
206 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
207 {
208 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
209 			(xdrproc_t)xdr_rpcbs_addrlist)) {
210 		return (FALSE);
211 	}
212 	return (TRUE);
213 }
214 
215 bool_t
216 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
217 {
218 	if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
219 			(xdrproc_t)xdr_rpcbs_rmtcalllist)) {
220 		return (FALSE);
221 	}
222 	return (TRUE);
223 }
224 
225 bool_t
226 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
227 {
228 
229 	if (!xdr_rpcbs_proc(xdrs, objp->info)) {
230 		return (FALSE);
231 	}
232 	if (!xdr_int(xdrs, &objp->setinfo)) {
233 		return (FALSE);
234 	}
235 	if (!xdr_int(xdrs, &objp->unsetinfo)) {
236 		return (FALSE);
237 	}
238 	if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
239 		return (FALSE);
240 	}
241 	if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
242 		return (FALSE);
243 	}
244 	return (TRUE);
245 }
246 
247 /*
248  * One rpcb_stat structure is returned for each version of rpcbind
249  * being monitored.
250  */
251 bool_t
252 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
253 {
254 	if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
255 	    sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
256 		return (FALSE);
257 	}
258 	return (TRUE);
259 }
260