replace source with . in configure script and fix toolchain detection
1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4
|
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6
|
* THE BSD LICENSE
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8
|
* Redistribution and use in source and binary forms, with or without
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9
|
* modification, are permitted provided that the following conditions are met:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11
|
* Redistributions of source code must retain the above copyright notice, this
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12
|
* list of conditions and the following disclaimer.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13
|
* Redistributions in binary form must reproduce the above copyright notice,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14
|
* this list of conditions and the following disclaimer in the documentation
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15
|
* and/or other materials provided with the distribution.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17
|
* Neither the name of the nor the names of its contributors may be
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18
|
* used to endorse or promote products derived from this software without
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19
|
* specific prior written permission.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35
|
* MODULE: plist.c
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39
|
* This module implements property lists. A property list is an
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40
|
* ordered array of property values. Each property value has an
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41
|
* handle for some data item, and may have a reference to
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42
|
* another property list which describes the type of the data
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43
|
* item. Each property value has a property index which specifies
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44
|
* its position in the property list. A property value may also
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45
|
* have a name. Since the data item associated with a property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46
|
* value may reference another property list, it is possible to
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47
|
* construct arbitrary linked structures of property lists.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49
|
* IMPLEMENTATION NOTES:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51
|
|
14
|
52
|
#include "../daemon/netsite.h"
|
1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53
|
#include "plist.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54
|
#include "plist_pvt.h"
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56
|
int plistHashSizes[] = PLSTSIZES;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59
|
* FUNCTION: PListAssignValue
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63
|
* This function sets the value and/or type of a defined property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64
|
* in given property list. If the property type is specified as
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65
|
* NULL, it is unchanged. However, the property value is always
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66
|
* set to the specified value.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71
|
* pname - the property name
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72
|
* pvalue - the new property value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73
|
* ptype - the new property type, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77
|
* If successful, the property index of the referenced property is
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78
|
* returned as the function value. Errors are indicated by a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79
|
* negative return code as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83
|
PListAssignValue(PList_t plist, const char *pname,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84
|
const void *pvalue, PList_t ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88
|
int pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93
|
/* Got a symbol table for this property list? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94
|
if (pl->pl_symtab) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96
|
/* Yes, compute hash of specified name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97
|
i = PListHashName(pl->pl_symtab, pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99
|
/* Search hash collision list for matching name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100
|
for (pv = pl->pl_symtab->pt_hash[i]; pv; pv = pv->pv_next) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102
|
if (!strcmp(pname, pv->pv_name)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104
|
/* Name match, get property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105
|
pindex = pv->pv_pi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107
|
/* Set the new value */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108
|
pv->pv_value = (char *)pvalue;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110
|
/* Set type if type is given */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111
|
if (ptype) pv->pv_type = (PListStruct_t *)ptype;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113
|
/* Return the property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119
|
/* Error - specified property name is undefined */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120
|
return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124
|
* FUNCTION: PListCreate
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128
|
* This function creates a new property list and returns a handle for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129
|
* it. It allows the caller to reserve a specified number of
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130
|
* property indices at the beginning of the list, and also to limit
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131
|
* the total number of property values that may be added to the list.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135
|
* mempool - handle for a memory pool to be associated
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136
|
* with the new property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137
|
* resvprop - number of reserved property indices
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138
|
* maxprop - maximum number of properties in list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139
|
* (zero or negative imposes no limit)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140
|
* flags - unused, reserved, must be zero
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144
|
* If successful, the function return value is a handle for the new
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145
|
* property list. Otherwise NULL is returned.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148
|
NSAPI_PUBLIC PList_t
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149
|
PListCreate(pool_handle_t *mempool, int resvprop, int maxprop, int flags)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151
|
PListStruct_t *plist; /* pointer to property list structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154
|
plist = (PListStruct_t *)pool_malloc(mempool, sizeof(PListStruct_t));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155
|
if (plist) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157
|
/* Negative maxprop is the same as zero, i.e. no limit */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158
|
if (maxprop < 0) maxprop = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160
|
/* If resvprop and maxprop are both specified, limit resvprop */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161
|
if (resvprop > 0) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162
|
if (maxprop && (resvprop > maxprop)) resvprop = maxprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164
|
else resvprop = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166
|
/* Initialize property list structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167
|
plist->pl_mempool = mempool;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168
|
plist->pl_symtab = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169
|
plist->pl_maxprop = maxprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170
|
plist->pl_resvpi = resvprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171
|
plist->pl_initpi = resvprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172
|
plist->pl_lastpi = resvprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174
|
/* Set initialize size for array of property value pointers */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175
|
plist->pl_cursize = (resvprop) ? resvprop : PLIST_DEFSIZE;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177
|
/* Allocate the initial array of property value pointers */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178
|
plist->pl_ppval = (pb_entry **)pool_malloc(mempool,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179
|
(plist->pl_cursize *
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180
|
sizeof(PLValueStruct_t *)));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181
|
if (!plist->pl_ppval) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183
|
/* Failed - insufficient memory */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184
|
pool_free(mempool, (void *)plist);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185
|
plist = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188
|
/* NULL out pointers in the reserved index range, if any */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189
|
for (i = 0; i < plist->pl_lastpi; ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190
|
plist->pl_ppval[i] = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195
|
return (PList_t)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199
|
* FUNCTION: PListDefProp
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203
|
* This function creates a new property in a specified property list.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204
|
* The 'pindex' argument may be used to request a particular property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205
|
* index for the new property. If 'pindex' is greater than zero,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206
|
* the specified value is used as the new property's index, provided
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207
|
* there is no property at that index already. If 'pindex' is zero,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208
|
* then the next available property index is assigned to the new
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209
|
* property. A name may optionally be specified for the new property.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214
|
* pindex - new property index (or zero)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215
|
* pname - new property name (or NULL)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219
|
* If successful, the index of the new property is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225
|
PListDefProp(PList_t plist, int pindex, const char *pname, const int flags)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232
|
/* Is pindex specified? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233
|
if (pindex > 0) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235
|
/* Yes, is it in the reserved range? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236
|
if (flags != PLFLG_IGN_RES && pindex > pl->pl_resvpi) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237
|
/* No, error */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238
|
return ERRPLINVPI;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241
|
PLValueStruct_t **ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242
|
if (ppval[pindex - 1]) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243
|
/* Error - property already exists at specified index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244
|
return ERRPLEXIST;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249
|
/* Look for a free property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250
|
pindex = PListGetFreeIndex(pl);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251
|
if (pindex < 1) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252
|
/* Error - no free property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257
|
/* We have a property index. Create a new property value */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258
|
pv = (PLValueStruct_t *)pool_calloc(pl->pl_mempool,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259
|
1, sizeof(PLValueStruct_t));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260
|
if (!pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262
|
/* Error - insufficient memory */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263
|
return ERRPLNOMEM;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266
|
PLValueStruct_t **ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267
|
pv->pv_pbentry.param = &pv->pv_pbparam;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268
|
pv->pv_pi = pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269
|
pv->pv_mempool = pl->pl_mempool;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270
|
ppval[pindex - 1] = pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272
|
/* Name the property if the name was specified */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273
|
if (pname) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275
|
/* XXX Maybe should delete property if naming fails */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276
|
return PListNameProp(plist, pindex, pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279
|
/* Return the property index of the new property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284
|
* FUNCTION: PListDeleteProp
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288
|
* This function deletes a property from a specified property list.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289
|
* The property can be specified by its property index, using a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290
|
* pindex value greater than zero, or by its name, by specifying
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291
|
* pindex as zero and pname as the property name. This does not
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292
|
* have any effect on the data referenced by the property value,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293
|
* if any, nor does it have any effect on the property list that
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294
|
* describes the property value's type, if any.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299
|
* pindex - the property index, or zero
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300
|
* pname - the property name, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303
|
NSAPI_PUBLIC const void *
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304
|
PListDeleteProp(PList_t plist, int pindex, const char *pname_in)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308
|
PLValueStruct_t **pvp;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309
|
PLValueStruct_t *pv = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311
|
const void *pvalue = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312
|
char *pname = (char *)pname_in;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314
|
if (!plist) return NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318
|
/* Check for valid property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319
|
if ((pindex > 0) && (pindex <= pl->pl_initpi)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321
|
/* Get the pointer to the property structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322
|
pv = ppval[pindex - 1];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323
|
pname = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325
|
pname = pv->pv_name;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329
|
if (pname && pl->pl_symtab) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331
|
/* Compute hash of specified property name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332
|
i = PListHashName(pl->pl_symtab, pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334
|
/* Search hash collision list for matching name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335
|
for (pvp = &pl->pl_symtab->pt_hash[i]; *pvp; pvp = &(*pvp)->pv_next) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337
|
pv = *pvp;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338
|
if (!strcmp(pname, pv->pv_name)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340
|
/* Found it. Get its index and remove it. */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341
|
pindex = pv->pv_pi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342
|
*pvp = pv->pv_next;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343
|
pl->pl_symtab->pt_nsyms--;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344
|
break;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346
|
pv = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350
|
/* Found the indicated property by index or name? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353
|
/* Yes, remove it from the property list */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354
|
ppval[pindex - 1] = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356
|
/* Free the property name, if any */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357
|
if (pv->pv_name) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358
|
pool_free(pv->pv_mempool, (void *)(pv->pv_name));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360
|
pvalue = pv->pv_value;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362
|
/* Free the property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363
|
pool_free(pv->pv_mempool, (void *)pv);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365
|
return(pvalue);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369
|
* FUNCTION: PListFindValue
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373
|
* This function retrieves the value and type of a property with a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374
|
* specified property name. If the pvalue argument is non-NULL,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375
|
* it specifies a location in which to return the property value.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376
|
* Similarly, if ptype is non-NULL, it specifies where the property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377
|
* list describing the property type is to be returned. If a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378
|
* property has no value, the value returned for pvalue is NULL.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379
|
* If a property has no type, the value returned for ptype is NULL.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380
|
* A property can have a value, a type, both, or neither.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385
|
* pname - pointer to property name string
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386
|
* pvalue - property value return pointer
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387
|
* ptype - property type return pointer
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391
|
* If successful, the index of the referenced property is returned
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392
|
* as the function value. Errors are indicated by a negative
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393
|
* return code as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397
|
PListFindValue(PList_t plist, const char *pname, void **pvalue, PList_t *ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401
|
int pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406
|
/* Got a symbol table for this property list? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407
|
if (pl->pl_symtab) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409
|
/* Yes, compute hash of specified name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410
|
i = PListHashName(pl->pl_symtab, pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412
|
/* Search hash collision list for matching name */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413
|
for (pv = pl->pl_symtab->pt_hash[i]; pv; pv = pv->pv_next) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415
|
if (!strcmp(pname, pv->pv_name)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417
|
/* Name match, get property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418
|
pindex = pv->pv_pi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420
|
/* Return the value if requested */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421
|
if (pvalue) *pvalue = (void *)(pv->pv_value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423
|
/* Return the type if requested */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424
|
if (ptype) *ptype = (PList_t)(pv->pv_type);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426
|
/* Return the property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432
|
/* Error - specified property name is undefined */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433
|
return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437
|
* FUNCTION: PListInitProp
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441
|
* This function combines the functions of PListDefProp() and
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442
|
* PListSetValue(), defining a new property and assigning it an
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443
|
* initial value and optionally a type and/or a name.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448
|
* pindex - a reserved property index, or zero
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449
|
* pname - the new property name, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450
|
* pvalue - the new property value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451
|
* ptype - the new property type, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455
|
* If successful, the property index (pindex) is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461
|
PListInitProp(PList_t plist, int pindex, const char *pname,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462
|
const void *pvalue, PList_t ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464
|
int rv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468
|
/* Create the property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469
|
rv = PListDefProp(plist, pindex, pname, PLFLG_USE_RES);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470
|
if (rv > 0) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472
|
/* If that worked, set the value and type */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473
|
rv = PListSetValue(plist, rv, pvalue, ptype);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476
|
return rv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480
|
* FUNCTION: PListNew
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484
|
* This function creates a new property list, using the specified
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485
|
* memory pool for allocating the internal data structures used to
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486
|
* represent it. If the mempool argument is NULL, the default
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487
|
* memory pool is used.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491
|
* mempool - handle for a memory pool to be associated
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492
|
* with the new property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496
|
* If successful, the function return value is a handle for the new
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497
|
* property list. Otherwise NULL is returned.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500
|
NSAPI_PUBLIC PList_t
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501
|
PListNew(pool_handle_t *mempool)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503
|
/* Just call PListCreate with default parameters */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504
|
return PListCreate(mempool, 0, 0, 0);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508
|
* FUNCTION: PListDestroy
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512
|
* This function destroys a specified property list. This means
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513
|
* that any dynamic memory which was allocated as a result of calls
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514
|
* to the property list API is freed to the memory pool from which
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515
|
* it was allocated. Property value data is not freed, nor are
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516
|
* any property lists associated with property types.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523
|
void
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524
|
PListDestroy(PList_t plist)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531
|
if (!plist) return;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533
|
/* Free the property name symbol table if any */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534
|
if (pl->pl_symtab) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
535
|
pool_free(pl->pl_mempool, (void *)(pl->pl_symtab));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
536
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
537
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
538
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
539
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
540
|
/* Loop over the initialized property indices */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
541
|
for (i = 0; i < pl->pl_initpi; ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
542
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
543
|
/* Got a property here? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
544
|
pv = ppval[i];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
545
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
546
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
547
|
/* Free the property name string if any */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
548
|
if (pv->pv_name) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
549
|
pool_free(pv->pv_mempool, (void *)(pv->pv_name));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
550
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
551
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
552
|
/* Free the property value structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
553
|
pool_free(pv->pv_mempool, (void *)pv);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
554
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
555
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
556
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
557
|
/* Free the array of pointers to property values */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
558
|
pool_free(pl->pl_mempool, (void *)ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
559
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
560
|
/* Free the property list head */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
561
|
pool_free(pl->pl_mempool, (void *)pl);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
562
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
563
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
564
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
565
|
* FUNCTION: PListGetValue
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
567
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
569
|
* This function retrieves the value and type of the property with
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570
|
* the property index given by pindex in the specified property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
571
|
* list. The pindex argument must specify the index of a defined
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572
|
* property. If the pvalue argument is non-NULL, it specifies a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573
|
* location in which to return the property value. Similarly, if
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574
|
* ptype is non-NULL, it specifies where the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575
|
* describing the property type is to be returned. If a property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576
|
* has no value, the value returned for pvalue is NULL. If a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
577
|
* property has no type, the value returned for ptype is NULL. A
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578
|
* property can have a value, a type, both, or neither.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
582
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
583
|
* pindex - the property index
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584
|
* pvalue - property value return pointer
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585
|
* ptype - property type return pointer
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
588
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589
|
* If successful, the property index (pindex) is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595
|
PListGetValue(PList_t plist, int pindex, void **pvalue, PList_t *ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
596
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
601
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
602
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605
|
/* Check for valid property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
606
|
if ((pindex > 0) && (pindex <= pl->pl_initpi)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
607
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608
|
/* Does the property exist? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609
|
pv = ppval[pindex - 1];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
611
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
612
|
/* Yes, return the value if requested */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613
|
if (pvalue) *pvalue = (void *)(pv->pv_value);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
614
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615
|
/* Return the type if requested */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616
|
if (ptype) *ptype = (PList_t)(pv->pv_type);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
617
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
618
|
/* Successful return */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
620
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
621
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
622
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
623
|
/* Error - invalid property index or non-existent property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
624
|
return ERRPLINVPI;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
625
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
626
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
627
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
628
|
* FUNCTION: PListHash
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
629
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
630
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
631
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
632
|
* This function hashes a given string.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
633
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
634
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
635
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
636
|
* string - pointer to the string to hash
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
637
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
638
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
639
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
640
|
* The hash value is returned as the function value.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
641
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
642
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
643
|
unsigned int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
644
|
PListHash(const char *string)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
645
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
646
|
unsigned int hashval = 0; /* hash value */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
647
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
648
|
while (*string) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
649
|
hashval = (hashval<<5) ^ (*string++ & 0x7f);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
650
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
651
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
652
|
return hashval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
653
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
654
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
655
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
656
|
* FUNCTION: PListHashName
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
657
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
658
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
659
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
660
|
* This function hashes a given property name for a specified
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
661
|
* symbol table. It produces a value that can be used as an
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
662
|
* index in the pt_hash array associated with the symbol table.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
663
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
664
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
665
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
666
|
* symtab - pointer to the symbol table
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
667
|
* pname - pointer to the property name string
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
668
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
669
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
670
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
671
|
* The hash index is returned as the function value.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
672
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
673
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
674
|
int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
675
|
PListHashName(PLSymbolTable_t *symtab, const char *pname)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677
|
return PListHash(pname) % PLSIZENDX(symtab->pt_sizendx);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
679
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
681
|
* FUNCTION: PListNameProp
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685
|
* This function assigns a name to a defined property with the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686
|
* property index, pindex. If the property has an existing name,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687
|
* it will be replaced with the name specified by pname.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692
|
* pindex - the property index
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693
|
* pname - the new property name
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697
|
* If successful, the property index (pindex) is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703
|
PListNameProp(PList_t plist, int pindex, const char *pname)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
707
|
PLSymbolTable_t *pt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712
|
pt = pl->pl_symtab;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714
|
/* Check for valid property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715
|
if ((pindex > 0) && (pindex <= pl->pl_initpi)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717
|
/* Does the property exist? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718
|
pv = ((PLValueStruct_t **)(pl->pl_ppval))[pindex - 1];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721
|
/* If it has a name already, unname it */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722
|
if (pv->pv_name) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723
|
PLValueStruct_t **pvp;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725
|
/* Get hash bucket index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726
|
i = PListHashName(pt, pv->pv_name);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728
|
/* Seach hash collision list for this property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
729
|
for (pvp = &pt->pt_hash[i];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
730
|
*pvp; pvp = &(*pvp)->pv_next) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732
|
if (*pvp == pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734
|
/* Remove it from the list */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735
|
*pvp = pv->pv_next;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736
|
pt->pt_nsyms--;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737
|
break;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741
|
/* Free the current name string */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742
|
pool_free(pv->pv_mempool, (void *)(pv->pv_name));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745
|
/* Got a new name? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746
|
if (pname) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748
|
/* Allocate/grow the symbol table as needed */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
749
|
pt = PListSymbolTable(pl);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
750
|
if (!pt) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
751
|
return ERRPLNOMEM;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754
|
/* Duplicate the name string */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755
|
pv->pv_name = pool_strdup(pv->pv_mempool, (char *)pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757
|
/* Add name to symbol table */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758
|
i = PListHashName(pt, pname);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759
|
pv->pv_next = pt->pt_hash[i];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760
|
pt->pt_hash[i] = pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761
|
pt->pt_nsyms++;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
762
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764
|
/* Successful return */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
765
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769
|
/* Error - invalid property index or non-existent property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770
|
return ERRPLINVPI;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774
|
* FUNCTION: PListSetType
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778
|
* This function sets the property type of the defined property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779
|
* with the property index, pindex. The property list describing
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780
|
* the property type is specified by ptype. If ptype is NULL,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781
|
* the property type will be set to be undefined (NULL).
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
782
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
783
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
784
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
787
|
* pindex - the property index
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788
|
* ptype - the new property type, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792
|
* If successful, the property index (pindex) is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
794
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
795
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798
|
PListSetType(PList_t plist, int pindex, PList_t ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
801
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808
|
/* Check for valid property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
809
|
if ((pindex > 0) && (pindex <= pl->pl_initpi)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811
|
/* Does the property exist? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812
|
pv = ppval[pindex - 1];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815
|
/* Yes, set the new type */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816
|
pv->pv_type = ptype;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
817
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
818
|
/* Successful return */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
823
|
/* Error - invalid property index or non-existent property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824
|
return ERRPLINVPI;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828
|
* FUNCTION: PListSetValue
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832
|
* This function sets the value and optionally the type of a
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833
|
* defined property in a given property list. The pindex argument
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834
|
* specifies the property index, which must be greater than zero.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
835
|
* The ptype argument specifies a property list that describes the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836
|
* property type. If ptype is NULL, the property type, if any, is
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
837
|
* unchanged by this function. However, the property value is
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838
|
* always set to the value given by pvalue.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843
|
* pindex - the property index
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844
|
* pvalue - the new property value
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845
|
* ptype - the new property type, or NULL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849
|
* If successful, the property index (pindex) is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854
|
NSAPI_PUBLIC int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855
|
PListSetValue(PList_t plist, int pindex, const void *pvalue, PList_t ptype)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
856
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
857
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
858
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
859
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
861
|
if (!plist) return ERRPLUNDEF;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
862
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
863
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
864
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
865
|
/* Check for valid property index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
866
|
if ((pindex > 0) && (pindex <= pl->pl_initpi)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
867
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868
|
/* Does the property exist? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
869
|
pv = ppval[pindex - 1];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
870
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
871
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
872
|
/* Yes, set the new value */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
873
|
pv->pv_value = (char *)pvalue;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
874
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
875
|
/* Set type if type is given */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
876
|
if (ptype) pv->pv_type = (PListStruct_t *)ptype;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
877
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
878
|
/* Successful return */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
879
|
return pindex;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
880
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
881
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
882
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
883
|
/* Error - invalid property index or non-existent property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
884
|
return ERRPLINVPI;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
885
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
886
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
887
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
888
|
* FUNCTION: PListEnumerate
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
889
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
890
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
891
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
892
|
* This function walks through a specified property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893
|
* calling a user supplied function with the property
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894
|
* name and value as parameters.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
895
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
897
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
898
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
899
|
* user_func - handle for the user function
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902
|
NSAPI_PUBLIC void
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
903
|
PListEnumerate(PList_t plist, PListFunc_t *user_func, void *user_data)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
904
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
906
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
908
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
909
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910
|
if (!plist) return;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914
|
/* Loop over the initialized property indices */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915
|
for (i = 0; i < pl->pl_initpi; ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
917
|
/* Got a property here? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918
|
pv = ppval[i];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
920
|
(*user_func)(pv->pv_name, pv->pv_value, user_data);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
921
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
925
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
927
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928
|
* FUNCTION: PListCreateDuplicate
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932
|
* This function creates a new property list and returns a handle for
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933
|
* it. The source plist provides the new plists parameters.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937
|
* src_plist - source plist to duplicate
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938
|
* mempool - handle for a memory pool to be associated
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939
|
* with the new property list, only
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
940
|
* used if flags is set to PLFLG_NEW_MPOOL
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941
|
* flags - if PLFLG_NEW_MPOOL uses new_mempool
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
942
|
* parameter
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
946
|
* If successful, the function return value is a handle for the new
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947
|
* property list. Otherwise NULL is returned.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950
|
static PList_t
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951
|
PListCreateDuplicate(PList_t src_plist, pool_handle_t *new_mempool, int flags)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
952
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953
|
PListStruct_t *plist; /* pointer to property list structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955
|
pool_handle_t *mempool;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957
|
mempool = (flags == PLFLG_NEW_MPOOL) ? new_mempool : src_plist->pl_mempool;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959
|
plist = (PListStruct_t *)pool_malloc(mempool, sizeof(PListStruct_t));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960
|
if (plist) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962
|
/* Initialize property list structure */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
963
|
plist->pl_mempool = mempool;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964
|
plist->pl_symtab = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965
|
plist->pl_maxprop = src_plist->pl_maxprop;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
966
|
plist->pl_resvpi = src_plist->pl_resvpi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
967
|
plist->pl_initpi = src_plist->pl_initpi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
968
|
plist->pl_lastpi = src_plist->pl_lastpi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970
|
/* Set initialize size for array of property value pointers */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
971
|
plist->pl_cursize = src_plist->pl_cursize;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
972
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
973
|
/* Allocate the initial array of property value pointers */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
974
|
plist->pl_ppval = (pb_entry **)pool_malloc(mempool,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
975
|
(plist->pl_cursize *
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
976
|
sizeof(PLValueStruct_t *)));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
977
|
if (!plist->pl_ppval) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
978
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
979
|
/* Failed - insufficient memory */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
980
|
pool_free(mempool, (void *)plist);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
981
|
plist = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
982
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
983
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
984
|
/* NULL out pointers in the reserved index range, if any */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
985
|
for (i = 0; i < plist->pl_lastpi; ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
986
|
plist->pl_ppval[i] = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
987
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
988
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
989
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
990
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
991
|
return (PList_t)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
992
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
993
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
994
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
995
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
996
|
* FUNCTION: PListDuplicate
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
997
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
998
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
999
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1000
|
* This function duplicates a specified PList_t.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1001
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1002
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1003
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1004
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1005
|
* mempool - handle for a memory pool to be associated
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1006
|
* with the new property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1007
|
* resvprop - number of reserved property indices
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1008
|
* maxprop - maximum number of properties in list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1009
|
* (zero or negative imposes no limit)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1010
|
* flags - unused, reserved, must be zero
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1011
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1012
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1013
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1014
|
* If successful, the function return value is a handle for the new
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1015
|
* property list. Otherwise NULL is returned.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1016
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1017
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1018
|
NSAPI_PUBLIC PList_t
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1019
|
PListDuplicate(PList_t plist, pool_handle_t *new_mempool, int flags)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1020
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1021
|
PListStruct_t *pl = (PListStruct_t *)plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1022
|
PLValueStruct_t **ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1023
|
PLValueStruct_t *pv;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1024
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1025
|
int rv = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1026
|
PList_t new_plist;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1027
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1028
|
if (!plist) return NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1030
|
new_plist = PListCreateDuplicate(plist, new_mempool, flags);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1031
|
if (new_plist == NULL) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1032
|
return(NULL);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1033
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1034
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035
|
ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1036
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1037
|
/* Loop over the initialized property indices */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1038
|
for (i = 0; i < pl->pl_initpi; ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1039
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1040
|
/* Got a property here? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1041
|
pv = ppval[i];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1042
|
if (pv) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1043
|
/* Create the property */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1044
|
rv = PListDefProp(new_plist, i + 1, pv->pv_name, PLFLG_IGN_RES);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1045
|
if (rv > 0) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1046
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1047
|
/* If that worked, set the value and type */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1048
|
rv = PListSetValue(new_plist, rv, pv->pv_value, pv->pv_type);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1049
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1050
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1051
|
if ( rv <= 0 ) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1052
|
PListDestroy(new_plist);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1053
|
return(NULL);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1054
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1055
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1056
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1057
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1058
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1059
|
return(new_plist);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1060
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1061
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1062
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1063
|
* FUNCTION: PListGetPool
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1064
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1065
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1066
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1067
|
* This function returns the memory pool the PList is allocated from.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1068
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1069
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1070
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1071
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1072
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1073
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1074
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1075
|
* The memory pool address, which can be NULL.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1076
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1077
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1078
|
NSAPI_PUBLIC pool_handle_t *
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1079
|
PListGetPool(PList_t plist)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1080
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1081
|
if (!plist) return NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1082
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1083
|
return(plist->pl_mempool);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1084
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1085
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1086
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1087
|
* FUNCTION: PListGetFreeIndex
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1088
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1089
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1090
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1091
|
* This function returns an available property index.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1092
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1093
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1094
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1095
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1096
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1097
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1098
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1099
|
* If successful, an available property index is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1100
|
* function value. Errors are indicated by a negative return code
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1101
|
* as defined in plist.h.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1102
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1103
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1104
|
int
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1105
|
PListGetFreeIndex(PListStruct_t *pl)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1106
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1107
|
PLValueStruct_t **ppval = (PLValueStruct_t **)(pl->pl_ppval);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1108
|
int wrapped;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1109
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1110
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1111
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1112
|
* Look for a free property index, starting at pl_lastpi + 1.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1113
|
* (Note that i is the property index - 1)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1114
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1115
|
for (wrapped = 0, i = pl->pl_lastpi; ;) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1116
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1117
|
/* Are we in an initialized part of the array? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1118
|
if (i < pl->pl_initpi) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1119
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1120
|
/* Yes, use this index if it's free */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1121
|
if (ppval[i] == 0) break;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1122
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1123
|
/* Otherwise step to the next one */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1124
|
++i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1125
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1126
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1127
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1128
|
/* Have we reached the end yet? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1129
|
if (i < pl->pl_cursize) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1130
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1131
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1132
|
* We are above the highest initialized index, but
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1133
|
* still within the allocated size. An index in
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1134
|
* this range can be used with no further checks.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1135
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1136
|
ppval[i] = 0;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1137
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1138
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1139
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1140
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1141
|
* It's looking like time to grow the array, but
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1142
|
* first go back and look for an unused, unreserved
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1143
|
* index that might have been freed.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1144
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1145
|
if (!wrapped) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1146
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1147
|
i = pl->pl_resvpi;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1148
|
wrapped = 1;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1149
|
continue;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1150
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1151
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1152
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1153
|
* Grow the array unless there is a specified maximum
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1154
|
* size and we've reached it.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1155
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1156
|
i = pl->pl_cursize;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1157
|
if (pl->pl_maxprop && (i > pl->pl_maxprop)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1158
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1159
|
/* Error - property list is full */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1160
|
return ERRPLFULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1161
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1162
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1163
|
/* Increase planned size of list */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1164
|
int cursize = i + PLIST_DEFGROW;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1165
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1166
|
/* Reallocate the array of property value pointers */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1167
|
ppval = (PLValueStruct_t **)pool_realloc(pl->pl_mempool,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1168
|
(void *)ppval,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1169
|
(cursize * sizeof(PLValueStruct_t *)));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1170
|
if (!ppval) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1171
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1172
|
/* Error - insufficient memory */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1173
|
return ERRPLNOMEM;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1174
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1175
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1176
|
/* Initialize the first new entry and select it */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1177
|
ppval[i] = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1178
|
pl->pl_ppval = (pb_entry **)ppval;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1179
|
pl->pl_cursize = cursize;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1180
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1181
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1182
|
/* Update the highest initialized index value */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1183
|
pl->pl_initpi = i + 1;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1184
|
break;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1185
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1186
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1187
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1188
|
/* Set the starting point for the next allocation */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1189
|
pl->pl_lastpi = i + 1;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1190
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1191
|
return i + 1;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1192
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1193
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1194
|
/*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1195
|
* FUNCTION: PListSymbolTable
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1196
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1197
|
* DESCRIPTION:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1198
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1199
|
* This function allocates or grows a property list's symbol table as
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1200
|
* needed.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1201
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1202
|
* ARGUMENTS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1203
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1204
|
* plist - handle for the property list
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1205
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1206
|
* RETURNS:
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1207
|
*
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1208
|
* If successful, a pointer to the symbol table is returned as the
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1209
|
* function value. Errors are indicated by a NULL return code.
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1210
|
*/
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1211
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1212
|
PLSymbolTable_t *
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1213
|
PListSymbolTable(PListStruct_t *pl)
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1214
|
{
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1215
|
PLSymbolTable_t *pt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1216
|
int i;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1217
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1218
|
pt = pl->pl_symtab;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1219
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1220
|
/* Is there a hash table? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1221
|
if (!pl->pl_symtab) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1222
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1223
|
/* No, create one */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1224
|
pt = (PLSymbolTable_t *)pool_calloc(pl->pl_mempool, 1, PLHASHSIZE(0));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1225
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1226
|
pl->pl_symtab = pt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1227
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1228
|
else {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1229
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1230
|
/* Is it time to grow the hash table? */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1231
|
i = PLSIZENDX(pt->pt_sizendx);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1232
|
if ((pt->pt_sizendx < PLMAXSIZENDX) && pt->pt_nsyms >= (i + i)) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1233
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1234
|
PLSymbolTable_t *npt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1235
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1236
|
/* Yes, allocate the new table */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1237
|
npt = (PLSymbolTable_t *)pool_calloc(pl->pl_mempool, 1,
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1238
|
PLHASHSIZE(pt->pt_sizendx+1));
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1239
|
if (npt) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1240
|
npt->pt_sizendx = pt->pt_sizendx + 1;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1241
|
npt->pt_nsyms = pt->pt_nsyms;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1242
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1243
|
/* Rehash all the names into the new table, preserving order */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1244
|
for (i = 0; i < PLSIZENDX(pt->pt_sizendx); ++i) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1245
|
/* While there are names at this hash index... */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1246
|
while (pt->pt_hash[i]) {
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1247
|
PLValueStruct_t **pvp;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1248
|
int j;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1249
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1250
|
/* Find the last name at this hash index */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1251
|
for (pvp = &pt->pt_hash[i]; (*pvp)->pv_next; pvp = &(*pvp)->pv_next);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1252
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1253
|
/* Move the name to the new table */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1254
|
j = PListHashName(npt, (*pvp)->pv_name);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1255
|
(*pvp)->pv_next = npt->pt_hash[j];
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1256
|
npt->pt_hash[j] = (*pvp);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1257
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1258
|
/* Remove the name from the old table */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1259
|
*pvp = NULL;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1260
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1261
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1262
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1263
|
pl->pl_symtab = npt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1264
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1265
|
/* Free the old symbol table */
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1266
|
pool_free(pl->pl_mempool, (void *)pt);
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1267
|
pt = npt;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1268
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1269
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1270
|
}
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1271
|
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1272
|
return pl->pl_symtab;
|
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1273
|
}
|