UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 5 * 6 * THE BSD LICENSE 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * Redistributions of source code must retain the above copyright notice, this 12 * list of conditions and the following disclaimer. 13 * Redistributions in binary form must reproduce the above copyright notice, 14 * this list of conditions and the following disclaimer in the documentation 15 * and/or other materials provided with the distribution. 16 * 17 * Neither the name of the nor the names of its contributors may be 18 * used to endorse or promote products derived from this software without 19 * specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _PLIST_PVT_H 35 #define _PLIST_PVT_H 36 37 /* 38 * FILE: plist_pvt.h 39 * 40 * DESCRIPTION: 41 * 42 * This file contains private definitions for the property list 43 * utility implementation. 44 */ 45 46 #include "../public/nsapi.h" 47 #include "pool.h" 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /* Forward declarations */ 54 typedef struct PLValueStruct_s PLValueStruct_t; 55 typedef struct PLSymbol_s PLSymbol_t; 56 typedef struct PLSymbolTable_s PLSymbolTable_t; 57 typedef struct PListStruct_s PListStruct_t; 58 59 /* 60 * TYPE: PLValueStruct_t 61 * 62 * DESCRIPTION: 63 * 64 * This type represents a property value. It is dynamically 65 * allocated when a new property is added to a property list. 66 * It contains a reference to a property list that contains 67 * information about the property value, and a reference to 68 * the property value data. 69 */ 70 71 #ifndef PBLOCK_H 72 #include "pblock.h" 73 #endif /* PBLOCK_H */ 74 75 struct PLValueStruct_s { 76 pb_entry pv_pbentry; /* used for pblock compatibility */ 77 pb_param pv_pbparam; /* property name and value pointers */ 78 const pb_key *pv_pbkey; /* property pb_key pointer (optional) */ 79 PLValueStruct_t *pv_next; /* property name hash collision link */ 80 PListStruct_t *pv_type; /* property value type reference */ 81 int pv_pi; /* property index */ 82 pool_handle_t *pv_mempool; /* pool we were allocated from */ 83 }; 84 85 #define pv_name pv_pbparam.name 86 #define pv_value pv_pbparam.value 87 88 /* Offset to pv_pbparam in PLValueStruct_t */ 89 #define PVPBOFFSET ((char *)&((PLValueStruct_t *)0)->pv_pbparam) 90 91 /* Convert pb_param pointer to PLValueStruct_t pointer */ 92 #define PATOPV(p) ((PLValueStruct_t *)((char *)(p) - PVPBOFFSET)) 93 94 /* 95 * TYPE: PLSymbolTable_t 96 * 97 * DESCRIPTION: 98 * 99 * This type represents a symbol table that maps property names 100 * to properties. It is dynamically allocated the first time a 101 * property is named. 102 */ 103 104 #define PLSTSIZES {7, 19, 31, 67, 123, 257, 513} 105 #define PLMAXSIZENDX (sizeof(plistHashSizes)/sizeof(plistHashSizes[0]) - 1) 106 107 struct PLSymbolTable_s { 108 int pt_sizendx; /* pt_hash size, as an index in PLSTSIZES */ 109 int pt_nsyms; /* number of symbols in table */ 110 PLValueStruct_t *pt_hash[1];/* variable-length array */ 111 }; 112 113 /* 114 * TYPE: PListStruct_t 115 * 116 * DESCRIPTION: 117 * 118 * This type represents the top-level of a property list structure. 119 * It is dynamically allocated when a property list is created, and 120 * freed when the property list is destroyed. It references a 121 * dynamically allocated array of pointers to property value 122 * structures (PLValueStruct_t). 123 */ 124 125 #define PLIST_DEFSIZE 8 /* default initial entries in pl_ppval */ 126 #define PLIST_DEFGROW 16 /* default incremental entries for pl_ppval */ 127 128 struct PListStruct_s { 129 pblock pl_pb; /* pblock subset of property list head */ 130 PLSymbolTable_t *pl_symtab; /* property name to index symbol table */ 131 pool_handle_t *pl_mempool; /* associated memory pool handle */ 132 int pl_maxprop; /* maximum number of properties */ 133 int pl_resvpi; /* number of reserved property indices */ 134 int pl_lastpi; /* last allocated property index */ 135 int pl_cursize; /* current size of pl_ppval in entries */ 136 }; 137 138 #define pl_initpi pl_pb.hsize /* number of pl_ppval entries initialized */ 139 #define pl_ppval pl_pb.ht /* pointer to array of value pointers */ 140 141 /* Convert pblock pointer to PListStruct_t pointer */ 142 #define PBTOPL(p) ((PListStruct_t *)(p)) 143 144 #define PLSIZENDX(i) (plistHashSizes[i]) 145 #define PLHASHSIZE(i) (sizeof(PLSymbolTable_t) + \ 146 (PLSIZENDX(i) - 1)*sizeof(PLValueStruct_t *)) 147 148 extern int plistHashSizes[7]; 149 150 unsigned int PListHash(const char *string); 151 152 int PListHashName(PLSymbolTable_t *symtab, const char *pname); 153 154 int PListGetFreeIndex(PListStruct_t *pl); 155 156 PLSymbolTable_t *PListSymbolTable(PListStruct_t *pl); 157 158 #ifdef __cplusplus 159 } 160 #endif 161 162 #endif /* _PLIST_PVT_H */ 163