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