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