17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22*a87701e9SGary Mills
23*a87701e9SGary Mills /*
24*a87701e9SGary Mills * Copyright 2015 Gary Mills
25*a87701e9SGary Mills */
26*a87701e9SGary Mills
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * This is a non-recursive version of XDR routine used for db_index_entry
297c478bd9Sstevel@tonic-gate * type.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/syslog.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <rpc/types.h>
367c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
377c478bd9Sstevel@tonic-gate #include <memory.h>
387c478bd9Sstevel@tonic-gate #include "db_index_entry_c.h"
397c478bd9Sstevel@tonic-gate #include "db_table_c.h"
40*a87701e9SGary Mills #include "xdr_nullptr.h"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate bool_t
xdr_db_index_entry(xdrs,objp)437c478bd9Sstevel@tonic-gate xdr_db_index_entry(xdrs, objp)
447c478bd9Sstevel@tonic-gate register XDR *xdrs;
457c478bd9Sstevel@tonic-gate db_index_entry *objp;
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate bool_t more_data;
487c478bd9Sstevel@tonic-gate register db_index_entry *ep = objp;
497c478bd9Sstevel@tonic-gate register db_index_entry *loc;
507c478bd9Sstevel@tonic-gate register db_index_entry *freeptr = NULL;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate for (;;) {
537c478bd9Sstevel@tonic-gate if (!xdr_u_long(xdrs, &ep->hashval))
547c478bd9Sstevel@tonic-gate return (FALSE);
557c478bd9Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)&ep->key, sizeof (item),
567c478bd9Sstevel@tonic-gate (xdrproc_t) xdr_item))
577c478bd9Sstevel@tonic-gate return (FALSE);
587c478bd9Sstevel@tonic-gate if (!xdr_entryp(xdrs, &ep->location))
597c478bd9Sstevel@tonic-gate return (FALSE);
607c478bd9Sstevel@tonic-gate if (!xdr_nullptr(xdrs, &ep->next_result))
617c478bd9Sstevel@tonic-gate return (FALSE);
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate * The following code replaces the call to
657c478bd9Sstevel@tonic-gate * xdr_pointer(
667c478bd9Sstevel@tonic-gate * xdrs,
677c478bd9Sstevel@tonic-gate * (char **)&ep->next,
687c478bd9Sstevel@tonic-gate * sizeof (db_index_entry),
697c478bd9Sstevel@tonic-gate * (xdrproc_t) xdr_db_index_entry))
707c478bd9Sstevel@tonic-gate *
717c478bd9Sstevel@tonic-gate * It's a modified version of xdr_refer.c from the rpc library:
727c478bd9Sstevel@tonic-gate * @(#)xdr_refer.c 1.8 92/07/20 SMI
737c478bd9Sstevel@tonic-gate */
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate * the following assignment to more_data is only useful when
787c478bd9Sstevel@tonic-gate * encoding and freeing. When decoding, more_data will be
797c478bd9Sstevel@tonic-gate * filled by the xdr_bool() routine.
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate more_data = (ep->next != NULL);
827c478bd9Sstevel@tonic-gate if (! xdr_bool(xdrs, &more_data))
837c478bd9Sstevel@tonic-gate return (FALSE);
847c478bd9Sstevel@tonic-gate if (! more_data) {
857c478bd9Sstevel@tonic-gate ep->next = NULL;
867c478bd9Sstevel@tonic-gate break;
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate loc = ep->next;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate switch (xdrs->x_op) {
937c478bd9Sstevel@tonic-gate case XDR_DECODE:
947c478bd9Sstevel@tonic-gate if (loc == NULL) {
957c478bd9Sstevel@tonic-gate ep->next = loc = (db_index_entry *)
967c478bd9Sstevel@tonic-gate mem_alloc(sizeof (db_index_entry));
977c478bd9Sstevel@tonic-gate if (loc == NULL) {
987c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
997c478bd9Sstevel@tonic-gate "xdr_db_index_entry: mem_alloc failed");
1007c478bd9Sstevel@tonic-gate return (FALSE);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate memset(loc, 0, sizeof (db_index_entry));
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate break;
1057c478bd9Sstevel@tonic-gate case XDR_FREE:
1067c478bd9Sstevel@tonic-gate if (freeptr != NULL) {
1077c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_index_entry));
1087c478bd9Sstevel@tonic-gate } else
1097c478bd9Sstevel@tonic-gate ep->next = NULL;
1107c478bd9Sstevel@tonic-gate freeptr = loc;
1117c478bd9Sstevel@tonic-gate break;
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate if (loc == NULL)
1157c478bd9Sstevel@tonic-gate break;
1167c478bd9Sstevel@tonic-gate ep = loc;
1177c478bd9Sstevel@tonic-gate } /* for loop */
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
1207c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_index_entry));
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate return (TRUE);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate bool_t
xdr_db_index_entry_p(xdrs,objp)1287c478bd9Sstevel@tonic-gate xdr_db_index_entry_p(xdrs, objp)
1297c478bd9Sstevel@tonic-gate register XDR *xdrs;
1307c478bd9Sstevel@tonic-gate db_index_entry_p *objp;
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)objp, sizeof (db_index_entry),
1347c478bd9Sstevel@tonic-gate (xdrproc_t) xdr_db_index_entry))
1357c478bd9Sstevel@tonic-gate return (FALSE);
1367c478bd9Sstevel@tonic-gate return (TRUE);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate bool_t
xdr_db_free_entry(xdrs,objp)1427c478bd9Sstevel@tonic-gate xdr_db_free_entry(xdrs, objp)
1437c478bd9Sstevel@tonic-gate register XDR *xdrs;
1447c478bd9Sstevel@tonic-gate db_free_entry *objp;
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate bool_t more_data;
1477c478bd9Sstevel@tonic-gate register db_free_entry *ep = objp;
1487c478bd9Sstevel@tonic-gate register db_free_entry *loc;
1497c478bd9Sstevel@tonic-gate register db_free_entry *freeptr = NULL;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate for (;;) {
1527c478bd9Sstevel@tonic-gate if (!xdr_entryp(xdrs, &ep->where))
1537c478bd9Sstevel@tonic-gate return (FALSE);
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate * The following code replaces the call to
1577c478bd9Sstevel@tonic-gate * xdr_pointer(
1587c478bd9Sstevel@tonic-gate * xdrs,
1597c478bd9Sstevel@tonic-gate * (char **)&ep->next,
1607c478bd9Sstevel@tonic-gate * sizeof (db_free_entry),
1617c478bd9Sstevel@tonic-gate * (xdrproc_t) xdr_db_free_entry))
1627c478bd9Sstevel@tonic-gate *
1637c478bd9Sstevel@tonic-gate * It's a modified version of xdr_refer.c from the rpc library:
1647c478bd9Sstevel@tonic-gate * @(#)xdr_refer.c 1.8 92/07/20 SMI
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate * the following assignment to more_data is only useful when
1707c478bd9Sstevel@tonic-gate * encoding and freeing. When decoding, more_data will be
1717c478bd9Sstevel@tonic-gate * filled by the xdr_bool() routine.
1727c478bd9Sstevel@tonic-gate */
1737c478bd9Sstevel@tonic-gate more_data = (ep->next != NULL);
1747c478bd9Sstevel@tonic-gate if (! xdr_bool(xdrs, &more_data))
1757c478bd9Sstevel@tonic-gate return (FALSE);
1767c478bd9Sstevel@tonic-gate if (! more_data) {
1777c478bd9Sstevel@tonic-gate ep->next = NULL;
1787c478bd9Sstevel@tonic-gate break;
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate loc = ep->next;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate switch (xdrs->x_op) {
1857c478bd9Sstevel@tonic-gate case XDR_DECODE:
1867c478bd9Sstevel@tonic-gate if (loc == NULL) {
1877c478bd9Sstevel@tonic-gate ep->next = loc = (db_free_entry *)
1887c478bd9Sstevel@tonic-gate mem_alloc(sizeof (db_free_entry));
1897c478bd9Sstevel@tonic-gate if (loc == NULL) {
1907c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
1917c478bd9Sstevel@tonic-gate "db_free_entry: mem_alloc failed");
1927c478bd9Sstevel@tonic-gate return (FALSE);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate memset(loc, 0, sizeof (db_free_entry));
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate break;
1977c478bd9Sstevel@tonic-gate case XDR_FREE:
1987c478bd9Sstevel@tonic-gate if (freeptr != NULL) {
1997c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_free_entry));
2007c478bd9Sstevel@tonic-gate } else
2017c478bd9Sstevel@tonic-gate ep->next = NULL;
2027c478bd9Sstevel@tonic-gate freeptr = loc;
2037c478bd9Sstevel@tonic-gate break;
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate if (loc == NULL)
2077c478bd9Sstevel@tonic-gate break;
2087c478bd9Sstevel@tonic-gate ep = loc;
2097c478bd9Sstevel@tonic-gate } /* for loop */
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
2127c478bd9Sstevel@tonic-gate mem_free(freeptr, sizeof (db_free_entry));
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate return (TRUE);
2157c478bd9Sstevel@tonic-gate }
216