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