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