1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * This is a non-recursive version of XDR routine used for db_index_entry
24*7c478bd9Sstevel@tonic-gate * type.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/syslog.h>
31*7c478bd9Sstevel@tonic-gate #include <stdio.h>
32*7c478bd9Sstevel@tonic-gate #include <rpc/types.h>
33*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
34*7c478bd9Sstevel@tonic-gate #include <memory.h>
35*7c478bd9Sstevel@tonic-gate #include "db_index_entry_c.h"
36*7c478bd9Sstevel@tonic-gate #include "db_table_c.h"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate bool_t
xdr_db_index_entry(xdrs,objp)39*7c478bd9Sstevel@tonic-gate xdr_db_index_entry(xdrs, objp)
40*7c478bd9Sstevel@tonic-gate register XDR *xdrs;
41*7c478bd9Sstevel@tonic-gate db_index_entry *objp;
42*7c478bd9Sstevel@tonic-gate {
43*7c478bd9Sstevel@tonic-gate bool_t more_data;
44*7c478bd9Sstevel@tonic-gate register db_index_entry *ep = objp;
45*7c478bd9Sstevel@tonic-gate register db_index_entry *loc;
46*7c478bd9Sstevel@tonic-gate register db_index_entry *freeptr = NULL;
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate for (;;) {
49*7c478bd9Sstevel@tonic-gate if (!xdr_u_long(xdrs, &ep->hashval))
50*7c478bd9Sstevel@tonic-gate return (FALSE);
51*7c478bd9Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)&ep->key, sizeof (item),
52*7c478bd9Sstevel@tonic-gate (xdrproc_t) xdr_item))
53*7c478bd9Sstevel@tonic-gate return (FALSE);
54*7c478bd9Sstevel@tonic-gate if (!xdr_entryp(xdrs, &ep->location))
55*7c478bd9Sstevel@tonic-gate return (FALSE);
56*7c478bd9Sstevel@tonic-gate if (!xdr_nullptr(xdrs, &ep->next_result))
57*7c478bd9Sstevel@tonic-gate return (FALSE);
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate * The following code replaces the call to
61*7c478bd9Sstevel@tonic-gate * xdr_pointer(
62*7c478bd9Sstevel@tonic-gate * xdrs,
63*7c478bd9Sstevel@tonic-gate * (char **)&ep->next,
64*7c478bd9Sstevel@tonic-gate * sizeof (db_index_entry),
65*7c478bd9Sstevel@tonic-gate * (xdrproc_t) xdr_db_index_entry))
66*7c478bd9Sstevel@tonic-gate *
67*7c478bd9Sstevel@tonic-gate * It's a modified version of xdr_refer.c from the rpc library:
68*7c478bd9Sstevel@tonic-gate * @(#)xdr_refer.c 1.8 92/07/20 SMI
69*7c478bd9Sstevel@tonic-gate */
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate * the following assignment to more_data is only useful when
74*7c478bd9Sstevel@tonic-gate * encoding and freeing. When decoding, more_data will be
75*7c478bd9Sstevel@tonic-gate * filled by the xdr_bool() routine.
76*7c478bd9Sstevel@tonic-gate */
77*7c478bd9Sstevel@tonic-gate more_data = (ep->next != NULL);
78*7c478bd9Sstevel@tonic-gate if (! xdr_bool(xdrs, &more_data))
79*7c478bd9Sstevel@tonic-gate return (FALSE);
80*7c478bd9Sstevel@tonic-gate if (! more_data) {
81*7c478bd9Sstevel@tonic-gate ep->next = NULL;
82*7c478bd9Sstevel@tonic-gate break;
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate loc = ep->next;
86*7c478bd9Sstevel@tonic-gate
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate switch (xdrs->x_op) {
89*7c478bd9Sstevel@tonic-gate case XDR_DECODE:
90*7c478bd9Sstevel@tonic-gate if (loc == NULL) {
91*7c478bd9Sstevel@tonic-gate ep->next = loc = (db_index_entry *)
92*7c478bd9Sstevel@tonic-gate mem_alloc(sizeof (db_index_entry));
93*7c478bd9Sstevel@tonic-gate if (loc == NULL) {
94*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
95*7c478bd9Sstevel@tonic-gate "xdr_db_index_entry: mem_alloc failed");
96*7c478bd9Sstevel@tonic-gate return (FALSE);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate memset(loc, 0, sizeof (db_index_entry));
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate break;
101*7c478bd9Sstevel@tonic-gate case XDR_FREE:
102*7c478bd9Sstevel@tonic-gate if (freeptr != NULL) {
103*7c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_index_entry));
104*7c478bd9Sstevel@tonic-gate } else
105*7c478bd9Sstevel@tonic-gate ep->next = NULL;
106*7c478bd9Sstevel@tonic-gate freeptr = loc;
107*7c478bd9Sstevel@tonic-gate break;
108*7c478bd9Sstevel@tonic-gate }
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate if (loc == NULL)
111*7c478bd9Sstevel@tonic-gate break;
112*7c478bd9Sstevel@tonic-gate ep = loc;
113*7c478bd9Sstevel@tonic-gate } /* for loop */
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
116*7c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_index_entry));
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate return (TRUE);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate bool_t
xdr_db_index_entry_p(xdrs,objp)124*7c478bd9Sstevel@tonic-gate xdr_db_index_entry_p(xdrs, objp)
125*7c478bd9Sstevel@tonic-gate register XDR *xdrs;
126*7c478bd9Sstevel@tonic-gate db_index_entry_p *objp;
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)objp, sizeof (db_index_entry),
130*7c478bd9Sstevel@tonic-gate (xdrproc_t) xdr_db_index_entry))
131*7c478bd9Sstevel@tonic-gate return (FALSE);
132*7c478bd9Sstevel@tonic-gate return (TRUE);
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate bool_t
xdr_db_free_entry(xdrs,objp)138*7c478bd9Sstevel@tonic-gate xdr_db_free_entry(xdrs, objp)
139*7c478bd9Sstevel@tonic-gate register XDR *xdrs;
140*7c478bd9Sstevel@tonic-gate db_free_entry *objp;
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate bool_t more_data;
143*7c478bd9Sstevel@tonic-gate register db_free_entry *ep = objp;
144*7c478bd9Sstevel@tonic-gate register db_free_entry *loc;
145*7c478bd9Sstevel@tonic-gate register db_free_entry *freeptr = NULL;
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate for (;;) {
148*7c478bd9Sstevel@tonic-gate if (!xdr_entryp(xdrs, &ep->where))
149*7c478bd9Sstevel@tonic-gate return (FALSE);
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate * The following code replaces the call to
153*7c478bd9Sstevel@tonic-gate * xdr_pointer(
154*7c478bd9Sstevel@tonic-gate * xdrs,
155*7c478bd9Sstevel@tonic-gate * (char **)&ep->next,
156*7c478bd9Sstevel@tonic-gate * sizeof (db_free_entry),
157*7c478bd9Sstevel@tonic-gate * (xdrproc_t) xdr_db_free_entry))
158*7c478bd9Sstevel@tonic-gate *
159*7c478bd9Sstevel@tonic-gate * It's a modified version of xdr_refer.c from the rpc library:
160*7c478bd9Sstevel@tonic-gate * @(#)xdr_refer.c 1.8 92/07/20 SMI
161*7c478bd9Sstevel@tonic-gate */
162*7c478bd9Sstevel@tonic-gate
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate /*
165*7c478bd9Sstevel@tonic-gate * the following assignment to more_data is only useful when
166*7c478bd9Sstevel@tonic-gate * encoding and freeing. When decoding, more_data will be
167*7c478bd9Sstevel@tonic-gate * filled by the xdr_bool() routine.
168*7c478bd9Sstevel@tonic-gate */
169*7c478bd9Sstevel@tonic-gate more_data = (ep->next != NULL);
170*7c478bd9Sstevel@tonic-gate if (! xdr_bool(xdrs, &more_data))
171*7c478bd9Sstevel@tonic-gate return (FALSE);
172*7c478bd9Sstevel@tonic-gate if (! more_data) {
173*7c478bd9Sstevel@tonic-gate ep->next = NULL;
174*7c478bd9Sstevel@tonic-gate break;
175*7c478bd9Sstevel@tonic-gate }
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate loc = ep->next;
178*7c478bd9Sstevel@tonic-gate
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate switch (xdrs->x_op) {
181*7c478bd9Sstevel@tonic-gate case XDR_DECODE:
182*7c478bd9Sstevel@tonic-gate if (loc == NULL) {
183*7c478bd9Sstevel@tonic-gate ep->next = loc = (db_free_entry *)
184*7c478bd9Sstevel@tonic-gate mem_alloc(sizeof (db_free_entry));
185*7c478bd9Sstevel@tonic-gate if (loc == NULL) {
186*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
187*7c478bd9Sstevel@tonic-gate "db_free_entry: mem_alloc failed");
188*7c478bd9Sstevel@tonic-gate return (FALSE);
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate memset(loc, 0, sizeof (db_free_entry));
191*7c478bd9Sstevel@tonic-gate }
192*7c478bd9Sstevel@tonic-gate break;
193*7c478bd9Sstevel@tonic-gate case XDR_FREE:
194*7c478bd9Sstevel@tonic-gate if (freeptr != NULL) {
195*7c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_free_entry));
196*7c478bd9Sstevel@tonic-gate } else
197*7c478bd9Sstevel@tonic-gate ep->next = NULL;
198*7c478bd9Sstevel@tonic-gate freeptr = loc;
199*7c478bd9Sstevel@tonic-gate break;
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate if (loc == NULL)
203*7c478bd9Sstevel@tonic-gate break;
204*7c478bd9Sstevel@tonic-gate ep = loc;
205*7c478bd9Sstevel@tonic-gate } /* for loop */
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
208*7c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_free_entry));
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate return (TRUE);
211*7c478bd9Sstevel@tonic-gate }
212