• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libxml2 - Library for parsing XML documents
2  * Copyright (C) 2006-2019 Free Software Foundation, Inc.
3  *
4  * This file is not part of the GNU gettext program, but is used with
5  * GNU gettext.
6  *
7  * The original copyright notice is as follows:
8  */
9 
10 /*
11  * Copyright (C) 1998-2012 Daniel Veillard.  All Rights Reserved.
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this software and associated documentation files (the "Software"), to deal
15  * in the Software without restriction, including without limitation the rights
16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17  * copies of the Software, and to permit persons to whom the Software is fur-
18  * nished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
25  * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29  * THE SOFTWARE.
30  *
31  * Author: Bjorn Reese <bjorn.reese@systematic.dk>
32  */
33 
34 /*
35  * Summary: Chained hash tables
36  * Description: This module implements the hash table support used in
37  *		various places in the library.
38  */
39 
40 #ifndef __XML_HASH_H__
41 #define __XML_HASH_H__
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * The hash table.
49  */
50 typedef struct _xmlHashTable xmlHashTable;
51 typedef xmlHashTable *xmlHashTablePtr;
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 #include <libxml/xmlversion.h>
58 #include <libxml/parser.h>
59 #include <libxml/dict.h>
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /*
66  * Recent version of gcc produce a warning when a function pointer is assigned
67  * to an object pointer, or vice versa.  The following macro is a dirty hack
68  * to allow suppression of the warning.  If your architecture has function
69  * pointers which are a different size than a void pointer, there may be some
70  * serious trouble within the library.
71  */
72 /**
73  * XML_CAST_FPTR:
74  * @fptr:  pointer to a function
75  *
76  * Macro to do a casting from an object pointer to a
77  * function pointer without encountering a warning from
78  * gcc
79  *
80  * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
81  * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
82  * so it is disabled now
83  */
84 
85 #define XML_CAST_FPTR(fptr) fptr
86 
87 
88 /*
89  * function types:
90  */
91 /**
92  * xmlHashDeallocator:
93  * @payload:  the data in the hash
94  * @name:  the name associated
95  *
96  * Callback to free data from a hash.
97  */
98 typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name);
99 /**
100  * xmlHashCopier:
101  * @payload:  the data in the hash
102  * @name:  the name associated
103  *
104  * Callback to copy data from a hash.
105  *
106  * Returns a copy of the data or NULL in case of error.
107  */
108 typedef void *(*xmlHashCopier)(void *payload, const xmlChar *name);
109 /**
110  * xmlHashScanner:
111  * @payload:  the data in the hash
112  * @data:  extra scannner data
113  * @name:  the name associated
114  *
115  * Callback when scanning data in a hash with the simple scanner.
116  */
117 typedef void (*xmlHashScanner)(void *payload, void *data, const xmlChar *name);
118 /**
119  * xmlHashScannerFull:
120  * @payload:  the data in the hash
121  * @data:  extra scannner data
122  * @name:  the name associated
123  * @name2:  the second name associated
124  * @name3:  the third name associated
125  *
126  * Callback when scanning data in a hash with the full scanner.
127  */
128 typedef void (*xmlHashScannerFull)(void *payload, void *data,
129 				   const xmlChar *name, const xmlChar *name2,
130 				   const xmlChar *name3);
131 
132 /*
133  * Constructor and destructor.
134  */
135 XMLPUBFUN xmlHashTablePtr XMLCALL
136 			xmlHashCreate	(int size);
137 XMLPUBFUN xmlHashTablePtr XMLCALL
138 			xmlHashCreateDict(int size,
139 					 xmlDictPtr dict);
140 XMLPUBFUN void XMLCALL
141 			xmlHashFree	(xmlHashTablePtr table,
142 					 xmlHashDeallocator f);
143 XMLPUBFUN void XMLCALL
144 			xmlHashDefaultDeallocator(void *entry,
145 					 const xmlChar *name);
146 
147 /*
148  * Add a new entry to the hash table.
149  */
150 XMLPUBFUN int XMLCALL
151 			xmlHashAddEntry	(xmlHashTablePtr table,
152 		                         const xmlChar *name,
153 		                         void *userdata);
154 XMLPUBFUN int XMLCALL
155 			xmlHashUpdateEntry(xmlHashTablePtr table,
156 		                         const xmlChar *name,
157 		                         void *userdata,
158 					 xmlHashDeallocator f);
159 XMLPUBFUN int XMLCALL
160 			xmlHashAddEntry2(xmlHashTablePtr table,
161 		                         const xmlChar *name,
162 		                         const xmlChar *name2,
163 		                         void *userdata);
164 XMLPUBFUN int XMLCALL
165 			xmlHashUpdateEntry2(xmlHashTablePtr table,
166 		                         const xmlChar *name,
167 		                         const xmlChar *name2,
168 		                         void *userdata,
169 					 xmlHashDeallocator f);
170 XMLPUBFUN int XMLCALL
171 			xmlHashAddEntry3(xmlHashTablePtr table,
172 		                         const xmlChar *name,
173 		                         const xmlChar *name2,
174 		                         const xmlChar *name3,
175 		                         void *userdata);
176 XMLPUBFUN int XMLCALL
177 			xmlHashUpdateEntry3(xmlHashTablePtr table,
178 		                         const xmlChar *name,
179 		                         const xmlChar *name2,
180 		                         const xmlChar *name3,
181 		                         void *userdata,
182 					 xmlHashDeallocator f);
183 
184 /*
185  * Remove an entry from the hash table.
186  */
187 XMLPUBFUN int XMLCALL
188 			xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name,
189                            xmlHashDeallocator f);
190 XMLPUBFUN int XMLCALL
191 			xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name,
192                             const xmlChar *name2, xmlHashDeallocator f);
193 XMLPUBFUN int  XMLCALL
194 			xmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name,
195                             const xmlChar *name2, const xmlChar *name3,
196                             xmlHashDeallocator f);
197 
198 /*
199  * Retrieve the userdata.
200  */
201 XMLPUBFUN void * XMLCALL
202 			xmlHashLookup	(xmlHashTablePtr table,
203 					 const xmlChar *name);
204 XMLPUBFUN void * XMLCALL
205 			xmlHashLookup2	(xmlHashTablePtr table,
206 					 const xmlChar *name,
207 					 const xmlChar *name2);
208 XMLPUBFUN void * XMLCALL
209 			xmlHashLookup3	(xmlHashTablePtr table,
210 					 const xmlChar *name,
211 					 const xmlChar *name2,
212 					 const xmlChar *name3);
213 XMLPUBFUN void * XMLCALL
214 			xmlHashQLookup	(xmlHashTablePtr table,
215 					 const xmlChar *name,
216 					 const xmlChar *prefix);
217 XMLPUBFUN void * XMLCALL
218 			xmlHashQLookup2	(xmlHashTablePtr table,
219 					 const xmlChar *name,
220 					 const xmlChar *prefix,
221 					 const xmlChar *name2,
222 					 const xmlChar *prefix2);
223 XMLPUBFUN void * XMLCALL
224 			xmlHashQLookup3	(xmlHashTablePtr table,
225 					 const xmlChar *name,
226 					 const xmlChar *prefix,
227 					 const xmlChar *name2,
228 					 const xmlChar *prefix2,
229 					 const xmlChar *name3,
230 					 const xmlChar *prefix3);
231 
232 /*
233  * Helpers.
234  */
235 XMLPUBFUN xmlHashTablePtr XMLCALL
236 			xmlHashCopy	(xmlHashTablePtr table,
237 					 xmlHashCopier f);
238 XMLPUBFUN int XMLCALL
239 			xmlHashSize	(xmlHashTablePtr table);
240 XMLPUBFUN void XMLCALL
241 			xmlHashScan	(xmlHashTablePtr table,
242 					 xmlHashScanner f,
243 					 void *data);
244 XMLPUBFUN void XMLCALL
245 			xmlHashScan3	(xmlHashTablePtr table,
246 					 const xmlChar *name,
247 					 const xmlChar *name2,
248 					 const xmlChar *name3,
249 					 xmlHashScanner f,
250 					 void *data);
251 XMLPUBFUN void XMLCALL
252 			xmlHashScanFull	(xmlHashTablePtr table,
253 					 xmlHashScannerFull f,
254 					 void *data);
255 XMLPUBFUN void XMLCALL
256 			xmlHashScanFull3(xmlHashTablePtr table,
257 					 const xmlChar *name,
258 					 const xmlChar *name2,
259 					 const xmlChar *name3,
260 					 xmlHashScannerFull f,
261 					 void *data);
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif /* ! __XML_HASH_H__ */
266