1*1230fdc1SLionel Sambuc /* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
2*1230fdc1SLionel Sambuc See the file COPYING for copying permission.
3*1230fdc1SLionel Sambuc */
4*1230fdc1SLionel Sambuc
5*1230fdc1SLionel Sambuc #include <stddef.h>
6*1230fdc1SLionel Sambuc #include <string.h> /* memset(), memcpy() */
7*1230fdc1SLionel Sambuc #include <assert.h>
8*1230fdc1SLionel Sambuc #include <limits.h> /* UINT_MAX */
9*1230fdc1SLionel Sambuc #include <time.h> /* time() */
10*1230fdc1SLionel Sambuc
11*1230fdc1SLionel Sambuc #define XML_BUILDING_EXPAT 1
12*1230fdc1SLionel Sambuc
13*1230fdc1SLionel Sambuc #ifdef COMPILED_FROM_DSP
14*1230fdc1SLionel Sambuc #include "winconfig.h"
15*1230fdc1SLionel Sambuc #elif defined(MACOS_CLASSIC)
16*1230fdc1SLionel Sambuc #include "macconfig.h"
17*1230fdc1SLionel Sambuc #elif defined(__amigaos__)
18*1230fdc1SLionel Sambuc #include "amigaconfig.h"
19*1230fdc1SLionel Sambuc #elif defined(__WATCOMC__)
20*1230fdc1SLionel Sambuc #include "watcomconfig.h"
21*1230fdc1SLionel Sambuc #elif defined(HAVE_EXPAT_CONFIG_H)
22*1230fdc1SLionel Sambuc #include <expat_config.h>
23*1230fdc1SLionel Sambuc #endif /* ndef COMPILED_FROM_DSP */
24*1230fdc1SLionel Sambuc
25*1230fdc1SLionel Sambuc #include "ascii.h"
26*1230fdc1SLionel Sambuc #include "expat.h"
27*1230fdc1SLionel Sambuc
28*1230fdc1SLionel Sambuc #ifdef XML_UNICODE
29*1230fdc1SLionel Sambuc #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX
30*1230fdc1SLionel Sambuc #define XmlConvert XmlUtf16Convert
31*1230fdc1SLionel Sambuc #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding
32*1230fdc1SLionel Sambuc #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS
33*1230fdc1SLionel Sambuc #define XmlEncode XmlUtf16Encode
34*1230fdc1SLionel Sambuc /* Using pointer subtraction to convert to integer type. */
35*1230fdc1SLionel Sambuc #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1))
36*1230fdc1SLionel Sambuc typedef unsigned short ICHAR;
37*1230fdc1SLionel Sambuc #else
38*1230fdc1SLionel Sambuc #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX
39*1230fdc1SLionel Sambuc #define XmlConvert XmlUtf8Convert
40*1230fdc1SLionel Sambuc #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding
41*1230fdc1SLionel Sambuc #define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS
42*1230fdc1SLionel Sambuc #define XmlEncode XmlUtf8Encode
43*1230fdc1SLionel Sambuc #define MUST_CONVERT(enc, s) (!(enc)->isUtf8)
44*1230fdc1SLionel Sambuc typedef char ICHAR;
45*1230fdc1SLionel Sambuc #endif
46*1230fdc1SLionel Sambuc
47*1230fdc1SLionel Sambuc
48*1230fdc1SLionel Sambuc #ifndef XML_NS
49*1230fdc1SLionel Sambuc
50*1230fdc1SLionel Sambuc #define XmlInitEncodingNS XmlInitEncoding
51*1230fdc1SLionel Sambuc #define XmlInitUnknownEncodingNS XmlInitUnknownEncoding
52*1230fdc1SLionel Sambuc #undef XmlGetInternalEncodingNS
53*1230fdc1SLionel Sambuc #define XmlGetInternalEncodingNS XmlGetInternalEncoding
54*1230fdc1SLionel Sambuc #define XmlParseXmlDeclNS XmlParseXmlDecl
55*1230fdc1SLionel Sambuc
56*1230fdc1SLionel Sambuc #endif
57*1230fdc1SLionel Sambuc
58*1230fdc1SLionel Sambuc #ifdef XML_UNICODE
59*1230fdc1SLionel Sambuc
60*1230fdc1SLionel Sambuc #ifdef XML_UNICODE_WCHAR_T
61*1230fdc1SLionel Sambuc #define XML_T(x) (const wchar_t)x
62*1230fdc1SLionel Sambuc #define XML_L(x) L ## x
63*1230fdc1SLionel Sambuc #else
64*1230fdc1SLionel Sambuc #define XML_T(x) (const unsigned short)x
65*1230fdc1SLionel Sambuc #define XML_L(x) x
66*1230fdc1SLionel Sambuc #endif
67*1230fdc1SLionel Sambuc
68*1230fdc1SLionel Sambuc #else
69*1230fdc1SLionel Sambuc
70*1230fdc1SLionel Sambuc #define XML_T(x) x
71*1230fdc1SLionel Sambuc #define XML_L(x) x
72*1230fdc1SLionel Sambuc
73*1230fdc1SLionel Sambuc #endif
74*1230fdc1SLionel Sambuc
75*1230fdc1SLionel Sambuc /* Round up n to be a multiple of sz, where sz is a power of 2. */
76*1230fdc1SLionel Sambuc #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
77*1230fdc1SLionel Sambuc
78*1230fdc1SLionel Sambuc /* Handle the case where memmove() doesn't exist. */
79*1230fdc1SLionel Sambuc #ifndef HAVE_MEMMOVE
80*1230fdc1SLionel Sambuc #ifdef HAVE_BCOPY
81*1230fdc1SLionel Sambuc #define memmove(d,s,l) bcopy((s),(d),(l))
82*1230fdc1SLionel Sambuc #else
83*1230fdc1SLionel Sambuc #error memmove does not exist on this platform, nor is a substitute available
84*1230fdc1SLionel Sambuc #endif /* HAVE_BCOPY */
85*1230fdc1SLionel Sambuc #endif /* HAVE_MEMMOVE */
86*1230fdc1SLionel Sambuc
87*1230fdc1SLionel Sambuc #include "internal.h"
88*1230fdc1SLionel Sambuc #include "xmltok.h"
89*1230fdc1SLionel Sambuc #include "xmlrole.h"
90*1230fdc1SLionel Sambuc
91*1230fdc1SLionel Sambuc typedef const XML_Char *KEY;
92*1230fdc1SLionel Sambuc
93*1230fdc1SLionel Sambuc typedef struct {
94*1230fdc1SLionel Sambuc KEY name;
95*1230fdc1SLionel Sambuc } NAMED;
96*1230fdc1SLionel Sambuc
97*1230fdc1SLionel Sambuc typedef struct {
98*1230fdc1SLionel Sambuc NAMED **v;
99*1230fdc1SLionel Sambuc unsigned char power;
100*1230fdc1SLionel Sambuc size_t size;
101*1230fdc1SLionel Sambuc size_t used;
102*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite *mem;
103*1230fdc1SLionel Sambuc } HASH_TABLE;
104*1230fdc1SLionel Sambuc
105*1230fdc1SLionel Sambuc /* Basic character hash algorithm, taken from Python's string hash:
106*1230fdc1SLionel Sambuc h = h * 1000003 ^ character, the constant being a prime number.
107*1230fdc1SLionel Sambuc
108*1230fdc1SLionel Sambuc */
109*1230fdc1SLionel Sambuc #ifdef XML_UNICODE
110*1230fdc1SLionel Sambuc #define CHAR_HASH(h, c) \
111*1230fdc1SLionel Sambuc (((h) * 0xF4243) ^ (unsigned short)(c))
112*1230fdc1SLionel Sambuc #else
113*1230fdc1SLionel Sambuc #define CHAR_HASH(h, c) \
114*1230fdc1SLionel Sambuc (((h) * 0xF4243) ^ (unsigned char)(c))
115*1230fdc1SLionel Sambuc #endif
116*1230fdc1SLionel Sambuc
117*1230fdc1SLionel Sambuc /* For probing (after a collision) we need a step size relative prime
118*1230fdc1SLionel Sambuc to the hash table size, which is a power of 2. We use double-hashing,
119*1230fdc1SLionel Sambuc since we can calculate a second hash value cheaply by taking those bits
120*1230fdc1SLionel Sambuc of the first hash value that were discarded (masked out) when the table
121*1230fdc1SLionel Sambuc index was calculated: index = hash & mask, where mask = table->size - 1.
122*1230fdc1SLionel Sambuc We limit the maximum step size to table->size / 4 (mask >> 2) and make
123*1230fdc1SLionel Sambuc it odd, since odd numbers are always relative prime to a power of 2.
124*1230fdc1SLionel Sambuc */
125*1230fdc1SLionel Sambuc #define SECOND_HASH(hash, mask, power) \
126*1230fdc1SLionel Sambuc ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2))
127*1230fdc1SLionel Sambuc #define PROBE_STEP(hash, mask, power) \
128*1230fdc1SLionel Sambuc ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1))
129*1230fdc1SLionel Sambuc
130*1230fdc1SLionel Sambuc typedef struct {
131*1230fdc1SLionel Sambuc NAMED **p;
132*1230fdc1SLionel Sambuc NAMED **end;
133*1230fdc1SLionel Sambuc } HASH_TABLE_ITER;
134*1230fdc1SLionel Sambuc
135*1230fdc1SLionel Sambuc #define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */
136*1230fdc1SLionel Sambuc #define INIT_DATA_BUF_SIZE 1024
137*1230fdc1SLionel Sambuc #define INIT_ATTS_SIZE 16
138*1230fdc1SLionel Sambuc #define INIT_ATTS_VERSION 0xFFFFFFFF
139*1230fdc1SLionel Sambuc #define INIT_BLOCK_SIZE 1024
140*1230fdc1SLionel Sambuc #define INIT_BUFFER_SIZE 1024
141*1230fdc1SLionel Sambuc
142*1230fdc1SLionel Sambuc #define EXPAND_SPARE 24
143*1230fdc1SLionel Sambuc
144*1230fdc1SLionel Sambuc typedef struct binding {
145*1230fdc1SLionel Sambuc struct prefix *prefix;
146*1230fdc1SLionel Sambuc struct binding *nextTagBinding;
147*1230fdc1SLionel Sambuc struct binding *prevPrefixBinding;
148*1230fdc1SLionel Sambuc const struct attribute_id *attId;
149*1230fdc1SLionel Sambuc XML_Char *uri;
150*1230fdc1SLionel Sambuc int uriLen;
151*1230fdc1SLionel Sambuc int uriAlloc;
152*1230fdc1SLionel Sambuc } BINDING;
153*1230fdc1SLionel Sambuc
154*1230fdc1SLionel Sambuc typedef struct prefix {
155*1230fdc1SLionel Sambuc const XML_Char *name;
156*1230fdc1SLionel Sambuc BINDING *binding;
157*1230fdc1SLionel Sambuc } PREFIX;
158*1230fdc1SLionel Sambuc
159*1230fdc1SLionel Sambuc typedef struct {
160*1230fdc1SLionel Sambuc const XML_Char *str;
161*1230fdc1SLionel Sambuc const XML_Char *localPart;
162*1230fdc1SLionel Sambuc const XML_Char *prefix;
163*1230fdc1SLionel Sambuc int strLen;
164*1230fdc1SLionel Sambuc int uriLen;
165*1230fdc1SLionel Sambuc int prefixLen;
166*1230fdc1SLionel Sambuc } TAG_NAME;
167*1230fdc1SLionel Sambuc
168*1230fdc1SLionel Sambuc /* TAG represents an open element.
169*1230fdc1SLionel Sambuc The name of the element is stored in both the document and API
170*1230fdc1SLionel Sambuc encodings. The memory buffer 'buf' is a separately-allocated
171*1230fdc1SLionel Sambuc memory area which stores the name. During the XML_Parse()/
172*1230fdc1SLionel Sambuc XMLParseBuffer() when the element is open, the memory for the 'raw'
173*1230fdc1SLionel Sambuc version of the name (in the document encoding) is shared with the
174*1230fdc1SLionel Sambuc document buffer. If the element is open across calls to
175*1230fdc1SLionel Sambuc XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to
176*1230fdc1SLionel Sambuc contain the 'raw' name as well.
177*1230fdc1SLionel Sambuc
178*1230fdc1SLionel Sambuc A parser re-uses these structures, maintaining a list of allocated
179*1230fdc1SLionel Sambuc TAG objects in a free list.
180*1230fdc1SLionel Sambuc */
181*1230fdc1SLionel Sambuc typedef struct tag {
182*1230fdc1SLionel Sambuc struct tag *parent; /* parent of this element */
183*1230fdc1SLionel Sambuc const char *rawName; /* tagName in the original encoding */
184*1230fdc1SLionel Sambuc int rawNameLength;
185*1230fdc1SLionel Sambuc TAG_NAME name; /* tagName in the API encoding */
186*1230fdc1SLionel Sambuc char *buf; /* buffer for name components */
187*1230fdc1SLionel Sambuc char *bufEnd; /* end of the buffer */
188*1230fdc1SLionel Sambuc BINDING *bindings;
189*1230fdc1SLionel Sambuc } TAG;
190*1230fdc1SLionel Sambuc
191*1230fdc1SLionel Sambuc typedef struct {
192*1230fdc1SLionel Sambuc const XML_Char *name;
193*1230fdc1SLionel Sambuc const XML_Char *textPtr;
194*1230fdc1SLionel Sambuc int textLen; /* length in XML_Chars */
195*1230fdc1SLionel Sambuc int processed; /* # of processed bytes - when suspended */
196*1230fdc1SLionel Sambuc const XML_Char *systemId;
197*1230fdc1SLionel Sambuc const XML_Char *base;
198*1230fdc1SLionel Sambuc const XML_Char *publicId;
199*1230fdc1SLionel Sambuc const XML_Char *notation;
200*1230fdc1SLionel Sambuc XML_Bool open;
201*1230fdc1SLionel Sambuc XML_Bool is_param;
202*1230fdc1SLionel Sambuc XML_Bool is_internal; /* true if declared in internal subset outside PE */
203*1230fdc1SLionel Sambuc } ENTITY;
204*1230fdc1SLionel Sambuc
205*1230fdc1SLionel Sambuc typedef struct {
206*1230fdc1SLionel Sambuc enum XML_Content_Type type;
207*1230fdc1SLionel Sambuc enum XML_Content_Quant quant;
208*1230fdc1SLionel Sambuc const XML_Char * name;
209*1230fdc1SLionel Sambuc int firstchild;
210*1230fdc1SLionel Sambuc int lastchild;
211*1230fdc1SLionel Sambuc int childcnt;
212*1230fdc1SLionel Sambuc int nextsib;
213*1230fdc1SLionel Sambuc } CONTENT_SCAFFOLD;
214*1230fdc1SLionel Sambuc
215*1230fdc1SLionel Sambuc #define INIT_SCAFFOLD_ELEMENTS 32
216*1230fdc1SLionel Sambuc
217*1230fdc1SLionel Sambuc typedef struct block {
218*1230fdc1SLionel Sambuc struct block *next;
219*1230fdc1SLionel Sambuc int size;
220*1230fdc1SLionel Sambuc XML_Char s[1];
221*1230fdc1SLionel Sambuc } BLOCK;
222*1230fdc1SLionel Sambuc
223*1230fdc1SLionel Sambuc typedef struct {
224*1230fdc1SLionel Sambuc BLOCK *blocks;
225*1230fdc1SLionel Sambuc BLOCK *freeBlocks;
226*1230fdc1SLionel Sambuc const XML_Char *end;
227*1230fdc1SLionel Sambuc XML_Char *ptr;
228*1230fdc1SLionel Sambuc XML_Char *start;
229*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite *mem;
230*1230fdc1SLionel Sambuc } STRING_POOL;
231*1230fdc1SLionel Sambuc
232*1230fdc1SLionel Sambuc /* The XML_Char before the name is used to determine whether
233*1230fdc1SLionel Sambuc an attribute has been specified. */
234*1230fdc1SLionel Sambuc typedef struct attribute_id {
235*1230fdc1SLionel Sambuc XML_Char *name;
236*1230fdc1SLionel Sambuc PREFIX *prefix;
237*1230fdc1SLionel Sambuc XML_Bool maybeTokenized;
238*1230fdc1SLionel Sambuc XML_Bool xmlns;
239*1230fdc1SLionel Sambuc } ATTRIBUTE_ID;
240*1230fdc1SLionel Sambuc
241*1230fdc1SLionel Sambuc typedef struct {
242*1230fdc1SLionel Sambuc const ATTRIBUTE_ID *id;
243*1230fdc1SLionel Sambuc XML_Bool isCdata;
244*1230fdc1SLionel Sambuc const XML_Char *value;
245*1230fdc1SLionel Sambuc } DEFAULT_ATTRIBUTE;
246*1230fdc1SLionel Sambuc
247*1230fdc1SLionel Sambuc typedef struct {
248*1230fdc1SLionel Sambuc unsigned long version;
249*1230fdc1SLionel Sambuc unsigned long hash;
250*1230fdc1SLionel Sambuc const XML_Char *uriName;
251*1230fdc1SLionel Sambuc } NS_ATT;
252*1230fdc1SLionel Sambuc
253*1230fdc1SLionel Sambuc typedef struct {
254*1230fdc1SLionel Sambuc const XML_Char *name;
255*1230fdc1SLionel Sambuc PREFIX *prefix;
256*1230fdc1SLionel Sambuc const ATTRIBUTE_ID *idAtt;
257*1230fdc1SLionel Sambuc int nDefaultAtts;
258*1230fdc1SLionel Sambuc int allocDefaultAtts;
259*1230fdc1SLionel Sambuc DEFAULT_ATTRIBUTE *defaultAtts;
260*1230fdc1SLionel Sambuc } ELEMENT_TYPE;
261*1230fdc1SLionel Sambuc
262*1230fdc1SLionel Sambuc typedef struct {
263*1230fdc1SLionel Sambuc HASH_TABLE generalEntities;
264*1230fdc1SLionel Sambuc HASH_TABLE elementTypes;
265*1230fdc1SLionel Sambuc HASH_TABLE attributeIds;
266*1230fdc1SLionel Sambuc HASH_TABLE prefixes;
267*1230fdc1SLionel Sambuc STRING_POOL pool;
268*1230fdc1SLionel Sambuc STRING_POOL entityValuePool;
269*1230fdc1SLionel Sambuc /* false once a parameter entity reference has been skipped */
270*1230fdc1SLionel Sambuc XML_Bool keepProcessing;
271*1230fdc1SLionel Sambuc /* true once an internal or external PE reference has been encountered;
272*1230fdc1SLionel Sambuc this includes the reference to an external subset */
273*1230fdc1SLionel Sambuc XML_Bool hasParamEntityRefs;
274*1230fdc1SLionel Sambuc XML_Bool standalone;
275*1230fdc1SLionel Sambuc #ifdef XML_DTD
276*1230fdc1SLionel Sambuc /* indicates if external PE has been read */
277*1230fdc1SLionel Sambuc XML_Bool paramEntityRead;
278*1230fdc1SLionel Sambuc HASH_TABLE paramEntities;
279*1230fdc1SLionel Sambuc #endif /* XML_DTD */
280*1230fdc1SLionel Sambuc PREFIX defaultPrefix;
281*1230fdc1SLionel Sambuc /* === scaffolding for building content model === */
282*1230fdc1SLionel Sambuc XML_Bool in_eldecl;
283*1230fdc1SLionel Sambuc CONTENT_SCAFFOLD *scaffold;
284*1230fdc1SLionel Sambuc unsigned contentStringLen;
285*1230fdc1SLionel Sambuc unsigned scaffSize;
286*1230fdc1SLionel Sambuc unsigned scaffCount;
287*1230fdc1SLionel Sambuc int scaffLevel;
288*1230fdc1SLionel Sambuc int *scaffIndex;
289*1230fdc1SLionel Sambuc } DTD;
290*1230fdc1SLionel Sambuc
291*1230fdc1SLionel Sambuc typedef struct open_internal_entity {
292*1230fdc1SLionel Sambuc const char *internalEventPtr;
293*1230fdc1SLionel Sambuc const char *internalEventEndPtr;
294*1230fdc1SLionel Sambuc struct open_internal_entity *next;
295*1230fdc1SLionel Sambuc ENTITY *entity;
296*1230fdc1SLionel Sambuc int startTagLevel;
297*1230fdc1SLionel Sambuc XML_Bool betweenDecl; /* WFC: PE Between Declarations */
298*1230fdc1SLionel Sambuc } OPEN_INTERNAL_ENTITY;
299*1230fdc1SLionel Sambuc
300*1230fdc1SLionel Sambuc typedef enum XML_Error PTRCALL Processor(XML_Parser parser,
301*1230fdc1SLionel Sambuc const char *start,
302*1230fdc1SLionel Sambuc const char *end,
303*1230fdc1SLionel Sambuc const char **endPtr);
304*1230fdc1SLionel Sambuc
305*1230fdc1SLionel Sambuc static Processor prologProcessor;
306*1230fdc1SLionel Sambuc static Processor prologInitProcessor;
307*1230fdc1SLionel Sambuc static Processor contentProcessor;
308*1230fdc1SLionel Sambuc static Processor cdataSectionProcessor;
309*1230fdc1SLionel Sambuc #ifdef XML_DTD
310*1230fdc1SLionel Sambuc static Processor ignoreSectionProcessor;
311*1230fdc1SLionel Sambuc static Processor externalParEntProcessor;
312*1230fdc1SLionel Sambuc static Processor externalParEntInitProcessor;
313*1230fdc1SLionel Sambuc static Processor entityValueProcessor;
314*1230fdc1SLionel Sambuc static Processor entityValueInitProcessor;
315*1230fdc1SLionel Sambuc #endif /* XML_DTD */
316*1230fdc1SLionel Sambuc static Processor epilogProcessor;
317*1230fdc1SLionel Sambuc static Processor errorProcessor;
318*1230fdc1SLionel Sambuc static Processor externalEntityInitProcessor;
319*1230fdc1SLionel Sambuc static Processor externalEntityInitProcessor2;
320*1230fdc1SLionel Sambuc static Processor externalEntityInitProcessor3;
321*1230fdc1SLionel Sambuc static Processor externalEntityContentProcessor;
322*1230fdc1SLionel Sambuc static Processor internalEntityProcessor;
323*1230fdc1SLionel Sambuc
324*1230fdc1SLionel Sambuc static enum XML_Error
325*1230fdc1SLionel Sambuc handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName);
326*1230fdc1SLionel Sambuc static enum XML_Error
327*1230fdc1SLionel Sambuc processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
328*1230fdc1SLionel Sambuc const char *s, const char *next);
329*1230fdc1SLionel Sambuc static enum XML_Error
330*1230fdc1SLionel Sambuc initializeEncoding(XML_Parser parser);
331*1230fdc1SLionel Sambuc static enum XML_Error
332*1230fdc1SLionel Sambuc doProlog(XML_Parser parser, const ENCODING *enc, const char *s,
333*1230fdc1SLionel Sambuc const char *end, int tok, const char *next, const char **nextPtr,
334*1230fdc1SLionel Sambuc XML_Bool haveMore);
335*1230fdc1SLionel Sambuc static enum XML_Error
336*1230fdc1SLionel Sambuc processInternalEntity(XML_Parser parser, ENTITY *entity,
337*1230fdc1SLionel Sambuc XML_Bool betweenDecl);
338*1230fdc1SLionel Sambuc static enum XML_Error
339*1230fdc1SLionel Sambuc doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,
340*1230fdc1SLionel Sambuc const char *start, const char *end, const char **endPtr,
341*1230fdc1SLionel Sambuc XML_Bool haveMore);
342*1230fdc1SLionel Sambuc static enum XML_Error
343*1230fdc1SLionel Sambuc doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr,
344*1230fdc1SLionel Sambuc const char *end, const char **nextPtr, XML_Bool haveMore);
345*1230fdc1SLionel Sambuc #ifdef XML_DTD
346*1230fdc1SLionel Sambuc static enum XML_Error
347*1230fdc1SLionel Sambuc doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr,
348*1230fdc1SLionel Sambuc const char *end, const char **nextPtr, XML_Bool haveMore);
349*1230fdc1SLionel Sambuc #endif /* XML_DTD */
350*1230fdc1SLionel Sambuc
351*1230fdc1SLionel Sambuc static enum XML_Error
352*1230fdc1SLionel Sambuc storeAtts(XML_Parser parser, const ENCODING *, const char *s,
353*1230fdc1SLionel Sambuc TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
354*1230fdc1SLionel Sambuc static enum XML_Error
355*1230fdc1SLionel Sambuc addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
356*1230fdc1SLionel Sambuc const XML_Char *uri, BINDING **bindingsPtr);
357*1230fdc1SLionel Sambuc static int
358*1230fdc1SLionel Sambuc defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata,
359*1230fdc1SLionel Sambuc XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser);
360*1230fdc1SLionel Sambuc static enum XML_Error
361*1230fdc1SLionel Sambuc storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,
362*1230fdc1SLionel Sambuc const char *, const char *, STRING_POOL *);
363*1230fdc1SLionel Sambuc static enum XML_Error
364*1230fdc1SLionel Sambuc appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,
365*1230fdc1SLionel Sambuc const char *, const char *, STRING_POOL *);
366*1230fdc1SLionel Sambuc static ATTRIBUTE_ID *
367*1230fdc1SLionel Sambuc getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start,
368*1230fdc1SLionel Sambuc const char *end);
369*1230fdc1SLionel Sambuc static int
370*1230fdc1SLionel Sambuc setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *);
371*1230fdc1SLionel Sambuc static enum XML_Error
372*1230fdc1SLionel Sambuc storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start,
373*1230fdc1SLionel Sambuc const char *end);
374*1230fdc1SLionel Sambuc static int
375*1230fdc1SLionel Sambuc reportProcessingInstruction(XML_Parser parser, const ENCODING *enc,
376*1230fdc1SLionel Sambuc const char *start, const char *end);
377*1230fdc1SLionel Sambuc static int
378*1230fdc1SLionel Sambuc reportComment(XML_Parser parser, const ENCODING *enc, const char *start,
379*1230fdc1SLionel Sambuc const char *end);
380*1230fdc1SLionel Sambuc static void
381*1230fdc1SLionel Sambuc reportDefault(XML_Parser parser, const ENCODING *enc, const char *start,
382*1230fdc1SLionel Sambuc const char *end);
383*1230fdc1SLionel Sambuc
384*1230fdc1SLionel Sambuc static const XML_Char * getContext(XML_Parser parser);
385*1230fdc1SLionel Sambuc static XML_Bool
386*1230fdc1SLionel Sambuc setContext(XML_Parser parser, const XML_Char *context);
387*1230fdc1SLionel Sambuc
388*1230fdc1SLionel Sambuc static void FASTCALL normalizePublicId(XML_Char *s);
389*1230fdc1SLionel Sambuc
390*1230fdc1SLionel Sambuc static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms);
391*1230fdc1SLionel Sambuc /* do not call if parentParser != NULL */
392*1230fdc1SLionel Sambuc static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms);
393*1230fdc1SLionel Sambuc static void
394*1230fdc1SLionel Sambuc dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);
395*1230fdc1SLionel Sambuc static int
396*1230fdc1SLionel Sambuc dtdCopy(XML_Parser oldParser,
397*1230fdc1SLionel Sambuc DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms);
398*1230fdc1SLionel Sambuc static int
399*1230fdc1SLionel Sambuc copyEntityTable(XML_Parser oldParser,
400*1230fdc1SLionel Sambuc HASH_TABLE *, STRING_POOL *, const HASH_TABLE *);
401*1230fdc1SLionel Sambuc static NAMED *
402*1230fdc1SLionel Sambuc lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize);
403*1230fdc1SLionel Sambuc static void FASTCALL
404*1230fdc1SLionel Sambuc hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms);
405*1230fdc1SLionel Sambuc static void FASTCALL hashTableClear(HASH_TABLE *);
406*1230fdc1SLionel Sambuc static void FASTCALL hashTableDestroy(HASH_TABLE *);
407*1230fdc1SLionel Sambuc static void FASTCALL
408*1230fdc1SLionel Sambuc hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *);
409*1230fdc1SLionel Sambuc static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *);
410*1230fdc1SLionel Sambuc
411*1230fdc1SLionel Sambuc static void FASTCALL
412*1230fdc1SLionel Sambuc poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms);
413*1230fdc1SLionel Sambuc static void FASTCALL poolClear(STRING_POOL *);
414*1230fdc1SLionel Sambuc static void FASTCALL poolDestroy(STRING_POOL *);
415*1230fdc1SLionel Sambuc static XML_Char *
416*1230fdc1SLionel Sambuc poolAppend(STRING_POOL *pool, const ENCODING *enc,
417*1230fdc1SLionel Sambuc const char *ptr, const char *end);
418*1230fdc1SLionel Sambuc static XML_Char *
419*1230fdc1SLionel Sambuc poolStoreString(STRING_POOL *pool, const ENCODING *enc,
420*1230fdc1SLionel Sambuc const char *ptr, const char *end);
421*1230fdc1SLionel Sambuc static XML_Bool FASTCALL poolGrow(STRING_POOL *pool);
422*1230fdc1SLionel Sambuc static const XML_Char * FASTCALL
423*1230fdc1SLionel Sambuc poolCopyString(STRING_POOL *pool, const XML_Char *s);
424*1230fdc1SLionel Sambuc static const XML_Char *
425*1230fdc1SLionel Sambuc poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n);
426*1230fdc1SLionel Sambuc static const XML_Char * FASTCALL
427*1230fdc1SLionel Sambuc poolAppendString(STRING_POOL *pool, const XML_Char *s);
428*1230fdc1SLionel Sambuc
429*1230fdc1SLionel Sambuc static int FASTCALL nextScaffoldPart(XML_Parser parser);
430*1230fdc1SLionel Sambuc static XML_Content * build_model(XML_Parser parser);
431*1230fdc1SLionel Sambuc static ELEMENT_TYPE *
432*1230fdc1SLionel Sambuc getElementType(XML_Parser parser, const ENCODING *enc,
433*1230fdc1SLionel Sambuc const char *ptr, const char *end);
434*1230fdc1SLionel Sambuc
435*1230fdc1SLionel Sambuc static unsigned long generate_hash_secret_salt(void);
436*1230fdc1SLionel Sambuc static XML_Bool startParsing(XML_Parser parser);
437*1230fdc1SLionel Sambuc
438*1230fdc1SLionel Sambuc static XML_Parser
439*1230fdc1SLionel Sambuc parserCreate(const XML_Char *encodingName,
440*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite *memsuite,
441*1230fdc1SLionel Sambuc const XML_Char *nameSep,
442*1230fdc1SLionel Sambuc DTD *dtd);
443*1230fdc1SLionel Sambuc
444*1230fdc1SLionel Sambuc static void
445*1230fdc1SLionel Sambuc parserInit(XML_Parser parser, const XML_Char *encodingName);
446*1230fdc1SLionel Sambuc
447*1230fdc1SLionel Sambuc #define poolStart(pool) ((pool)->start)
448*1230fdc1SLionel Sambuc #define poolEnd(pool) ((pool)->ptr)
449*1230fdc1SLionel Sambuc #define poolLength(pool) ((pool)->ptr - (pool)->start)
450*1230fdc1SLionel Sambuc #define poolChop(pool) ((void)--(pool->ptr))
451*1230fdc1SLionel Sambuc #define poolLastChar(pool) (((pool)->ptr)[-1])
452*1230fdc1SLionel Sambuc #define poolDiscard(pool) ((pool)->ptr = (pool)->start)
453*1230fdc1SLionel Sambuc #define poolFinish(pool) ((pool)->start = (pool)->ptr)
454*1230fdc1SLionel Sambuc #define poolAppendChar(pool, c) \
455*1230fdc1SLionel Sambuc (((pool)->ptr == (pool)->end && !poolGrow(pool)) \
456*1230fdc1SLionel Sambuc ? 0 \
457*1230fdc1SLionel Sambuc : ((*((pool)->ptr)++ = c), 1))
458*1230fdc1SLionel Sambuc
459*1230fdc1SLionel Sambuc struct XML_ParserStruct {
460*1230fdc1SLionel Sambuc /* The first member must be userData so that the XML_GetUserData
461*1230fdc1SLionel Sambuc macro works. */
462*1230fdc1SLionel Sambuc void *m_userData;
463*1230fdc1SLionel Sambuc void *m_handlerArg;
464*1230fdc1SLionel Sambuc char *m_buffer;
465*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite m_mem;
466*1230fdc1SLionel Sambuc /* first character to be parsed */
467*1230fdc1SLionel Sambuc const char *m_bufferPtr;
468*1230fdc1SLionel Sambuc /* past last character to be parsed */
469*1230fdc1SLionel Sambuc char *m_bufferEnd;
470*1230fdc1SLionel Sambuc /* allocated end of buffer */
471*1230fdc1SLionel Sambuc const char *m_bufferLim;
472*1230fdc1SLionel Sambuc XML_Index m_parseEndByteIndex;
473*1230fdc1SLionel Sambuc const char *m_parseEndPtr;
474*1230fdc1SLionel Sambuc XML_Char *m_dataBuf;
475*1230fdc1SLionel Sambuc XML_Char *m_dataBufEnd;
476*1230fdc1SLionel Sambuc XML_StartElementHandler m_startElementHandler;
477*1230fdc1SLionel Sambuc XML_EndElementHandler m_endElementHandler;
478*1230fdc1SLionel Sambuc XML_CharacterDataHandler m_characterDataHandler;
479*1230fdc1SLionel Sambuc XML_ProcessingInstructionHandler m_processingInstructionHandler;
480*1230fdc1SLionel Sambuc XML_CommentHandler m_commentHandler;
481*1230fdc1SLionel Sambuc XML_StartCdataSectionHandler m_startCdataSectionHandler;
482*1230fdc1SLionel Sambuc XML_EndCdataSectionHandler m_endCdataSectionHandler;
483*1230fdc1SLionel Sambuc XML_DefaultHandler m_defaultHandler;
484*1230fdc1SLionel Sambuc XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler;
485*1230fdc1SLionel Sambuc XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler;
486*1230fdc1SLionel Sambuc XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler;
487*1230fdc1SLionel Sambuc XML_NotationDeclHandler m_notationDeclHandler;
488*1230fdc1SLionel Sambuc XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler;
489*1230fdc1SLionel Sambuc XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler;
490*1230fdc1SLionel Sambuc XML_NotStandaloneHandler m_notStandaloneHandler;
491*1230fdc1SLionel Sambuc XML_ExternalEntityRefHandler m_externalEntityRefHandler;
492*1230fdc1SLionel Sambuc XML_Parser m_externalEntityRefHandlerArg;
493*1230fdc1SLionel Sambuc XML_SkippedEntityHandler m_skippedEntityHandler;
494*1230fdc1SLionel Sambuc XML_UnknownEncodingHandler m_unknownEncodingHandler;
495*1230fdc1SLionel Sambuc XML_ElementDeclHandler m_elementDeclHandler;
496*1230fdc1SLionel Sambuc XML_AttlistDeclHandler m_attlistDeclHandler;
497*1230fdc1SLionel Sambuc XML_EntityDeclHandler m_entityDeclHandler;
498*1230fdc1SLionel Sambuc XML_XmlDeclHandler m_xmlDeclHandler;
499*1230fdc1SLionel Sambuc const ENCODING *m_encoding;
500*1230fdc1SLionel Sambuc INIT_ENCODING m_initEncoding;
501*1230fdc1SLionel Sambuc const ENCODING *m_internalEncoding;
502*1230fdc1SLionel Sambuc const XML_Char *m_protocolEncodingName;
503*1230fdc1SLionel Sambuc XML_Bool m_ns;
504*1230fdc1SLionel Sambuc XML_Bool m_ns_triplets;
505*1230fdc1SLionel Sambuc void *m_unknownEncodingMem;
506*1230fdc1SLionel Sambuc void *m_unknownEncodingData;
507*1230fdc1SLionel Sambuc void *m_unknownEncodingHandlerData;
508*1230fdc1SLionel Sambuc void (XMLCALL *m_unknownEncodingRelease)(void *);
509*1230fdc1SLionel Sambuc PROLOG_STATE m_prologState;
510*1230fdc1SLionel Sambuc Processor *m_processor;
511*1230fdc1SLionel Sambuc enum XML_Error m_errorCode;
512*1230fdc1SLionel Sambuc const char *m_eventPtr;
513*1230fdc1SLionel Sambuc const char *m_eventEndPtr;
514*1230fdc1SLionel Sambuc const char *m_positionPtr;
515*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *m_openInternalEntities;
516*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *m_freeInternalEntities;
517*1230fdc1SLionel Sambuc XML_Bool m_defaultExpandInternalEntities;
518*1230fdc1SLionel Sambuc int m_tagLevel;
519*1230fdc1SLionel Sambuc ENTITY *m_declEntity;
520*1230fdc1SLionel Sambuc const XML_Char *m_doctypeName;
521*1230fdc1SLionel Sambuc const XML_Char *m_doctypeSysid;
522*1230fdc1SLionel Sambuc const XML_Char *m_doctypePubid;
523*1230fdc1SLionel Sambuc const XML_Char *m_declAttributeType;
524*1230fdc1SLionel Sambuc const XML_Char *m_declNotationName;
525*1230fdc1SLionel Sambuc const XML_Char *m_declNotationPublicId;
526*1230fdc1SLionel Sambuc ELEMENT_TYPE *m_declElementType;
527*1230fdc1SLionel Sambuc ATTRIBUTE_ID *m_declAttributeId;
528*1230fdc1SLionel Sambuc XML_Bool m_declAttributeIsCdata;
529*1230fdc1SLionel Sambuc XML_Bool m_declAttributeIsId;
530*1230fdc1SLionel Sambuc DTD *m_dtd;
531*1230fdc1SLionel Sambuc const XML_Char *m_curBase;
532*1230fdc1SLionel Sambuc TAG *m_tagStack;
533*1230fdc1SLionel Sambuc TAG *m_freeTagList;
534*1230fdc1SLionel Sambuc BINDING *m_inheritedBindings;
535*1230fdc1SLionel Sambuc BINDING *m_freeBindingList;
536*1230fdc1SLionel Sambuc int m_attsSize;
537*1230fdc1SLionel Sambuc int m_nSpecifiedAtts;
538*1230fdc1SLionel Sambuc int m_idAttIndex;
539*1230fdc1SLionel Sambuc ATTRIBUTE *m_atts;
540*1230fdc1SLionel Sambuc NS_ATT *m_nsAtts;
541*1230fdc1SLionel Sambuc unsigned long m_nsAttsVersion;
542*1230fdc1SLionel Sambuc unsigned char m_nsAttsPower;
543*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
544*1230fdc1SLionel Sambuc XML_AttrInfo *m_attInfo;
545*1230fdc1SLionel Sambuc #endif
546*1230fdc1SLionel Sambuc POSITION m_position;
547*1230fdc1SLionel Sambuc STRING_POOL m_tempPool;
548*1230fdc1SLionel Sambuc STRING_POOL m_temp2Pool;
549*1230fdc1SLionel Sambuc char *m_groupConnector;
550*1230fdc1SLionel Sambuc unsigned int m_groupSize;
551*1230fdc1SLionel Sambuc XML_Char m_namespaceSeparator;
552*1230fdc1SLionel Sambuc XML_Parser m_parentParser;
553*1230fdc1SLionel Sambuc XML_ParsingStatus m_parsingStatus;
554*1230fdc1SLionel Sambuc #ifdef XML_DTD
555*1230fdc1SLionel Sambuc XML_Bool m_isParamEntity;
556*1230fdc1SLionel Sambuc XML_Bool m_useForeignDTD;
557*1230fdc1SLionel Sambuc enum XML_ParamEntityParsing m_paramEntityParsing;
558*1230fdc1SLionel Sambuc #endif
559*1230fdc1SLionel Sambuc unsigned long m_hash_secret_salt;
560*1230fdc1SLionel Sambuc };
561*1230fdc1SLionel Sambuc
562*1230fdc1SLionel Sambuc #define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
563*1230fdc1SLionel Sambuc #define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s)))
564*1230fdc1SLionel Sambuc #define FREE(p) (parser->m_mem.free_fcn((p)))
565*1230fdc1SLionel Sambuc
566*1230fdc1SLionel Sambuc #define userData (parser->m_userData)
567*1230fdc1SLionel Sambuc #define handlerArg (parser->m_handlerArg)
568*1230fdc1SLionel Sambuc #define startElementHandler (parser->m_startElementHandler)
569*1230fdc1SLionel Sambuc #define endElementHandler (parser->m_endElementHandler)
570*1230fdc1SLionel Sambuc #define characterDataHandler (parser->m_characterDataHandler)
571*1230fdc1SLionel Sambuc #define processingInstructionHandler \
572*1230fdc1SLionel Sambuc (parser->m_processingInstructionHandler)
573*1230fdc1SLionel Sambuc #define commentHandler (parser->m_commentHandler)
574*1230fdc1SLionel Sambuc #define startCdataSectionHandler \
575*1230fdc1SLionel Sambuc (parser->m_startCdataSectionHandler)
576*1230fdc1SLionel Sambuc #define endCdataSectionHandler (parser->m_endCdataSectionHandler)
577*1230fdc1SLionel Sambuc #define defaultHandler (parser->m_defaultHandler)
578*1230fdc1SLionel Sambuc #define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler)
579*1230fdc1SLionel Sambuc #define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler)
580*1230fdc1SLionel Sambuc #define unparsedEntityDeclHandler \
581*1230fdc1SLionel Sambuc (parser->m_unparsedEntityDeclHandler)
582*1230fdc1SLionel Sambuc #define notationDeclHandler (parser->m_notationDeclHandler)
583*1230fdc1SLionel Sambuc #define startNamespaceDeclHandler \
584*1230fdc1SLionel Sambuc (parser->m_startNamespaceDeclHandler)
585*1230fdc1SLionel Sambuc #define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler)
586*1230fdc1SLionel Sambuc #define notStandaloneHandler (parser->m_notStandaloneHandler)
587*1230fdc1SLionel Sambuc #define externalEntityRefHandler \
588*1230fdc1SLionel Sambuc (parser->m_externalEntityRefHandler)
589*1230fdc1SLionel Sambuc #define externalEntityRefHandlerArg \
590*1230fdc1SLionel Sambuc (parser->m_externalEntityRefHandlerArg)
591*1230fdc1SLionel Sambuc #define internalEntityRefHandler \
592*1230fdc1SLionel Sambuc (parser->m_internalEntityRefHandler)
593*1230fdc1SLionel Sambuc #define skippedEntityHandler (parser->m_skippedEntityHandler)
594*1230fdc1SLionel Sambuc #define unknownEncodingHandler (parser->m_unknownEncodingHandler)
595*1230fdc1SLionel Sambuc #define elementDeclHandler (parser->m_elementDeclHandler)
596*1230fdc1SLionel Sambuc #define attlistDeclHandler (parser->m_attlistDeclHandler)
597*1230fdc1SLionel Sambuc #define entityDeclHandler (parser->m_entityDeclHandler)
598*1230fdc1SLionel Sambuc #define xmlDeclHandler (parser->m_xmlDeclHandler)
599*1230fdc1SLionel Sambuc #define encoding (parser->m_encoding)
600*1230fdc1SLionel Sambuc #define initEncoding (parser->m_initEncoding)
601*1230fdc1SLionel Sambuc #define internalEncoding (parser->m_internalEncoding)
602*1230fdc1SLionel Sambuc #define unknownEncodingMem (parser->m_unknownEncodingMem)
603*1230fdc1SLionel Sambuc #define unknownEncodingData (parser->m_unknownEncodingData)
604*1230fdc1SLionel Sambuc #define unknownEncodingHandlerData \
605*1230fdc1SLionel Sambuc (parser->m_unknownEncodingHandlerData)
606*1230fdc1SLionel Sambuc #define unknownEncodingRelease (parser->m_unknownEncodingRelease)
607*1230fdc1SLionel Sambuc #define protocolEncodingName (parser->m_protocolEncodingName)
608*1230fdc1SLionel Sambuc #define ns (parser->m_ns)
609*1230fdc1SLionel Sambuc #define ns_triplets (parser->m_ns_triplets)
610*1230fdc1SLionel Sambuc #define prologState (parser->m_prologState)
611*1230fdc1SLionel Sambuc #define processor (parser->m_processor)
612*1230fdc1SLionel Sambuc #define errorCode (parser->m_errorCode)
613*1230fdc1SLionel Sambuc #define eventPtr (parser->m_eventPtr)
614*1230fdc1SLionel Sambuc #define eventEndPtr (parser->m_eventEndPtr)
615*1230fdc1SLionel Sambuc #define positionPtr (parser->m_positionPtr)
616*1230fdc1SLionel Sambuc #define position (parser->m_position)
617*1230fdc1SLionel Sambuc #define openInternalEntities (parser->m_openInternalEntities)
618*1230fdc1SLionel Sambuc #define freeInternalEntities (parser->m_freeInternalEntities)
619*1230fdc1SLionel Sambuc #define defaultExpandInternalEntities \
620*1230fdc1SLionel Sambuc (parser->m_defaultExpandInternalEntities)
621*1230fdc1SLionel Sambuc #define tagLevel (parser->m_tagLevel)
622*1230fdc1SLionel Sambuc #define buffer (parser->m_buffer)
623*1230fdc1SLionel Sambuc #define bufferPtr (parser->m_bufferPtr)
624*1230fdc1SLionel Sambuc #define bufferEnd (parser->m_bufferEnd)
625*1230fdc1SLionel Sambuc #define parseEndByteIndex (parser->m_parseEndByteIndex)
626*1230fdc1SLionel Sambuc #define parseEndPtr (parser->m_parseEndPtr)
627*1230fdc1SLionel Sambuc #define bufferLim (parser->m_bufferLim)
628*1230fdc1SLionel Sambuc #define dataBuf (parser->m_dataBuf)
629*1230fdc1SLionel Sambuc #define dataBufEnd (parser->m_dataBufEnd)
630*1230fdc1SLionel Sambuc #define _dtd (parser->m_dtd)
631*1230fdc1SLionel Sambuc #define curBase (parser->m_curBase)
632*1230fdc1SLionel Sambuc #define declEntity (parser->m_declEntity)
633*1230fdc1SLionel Sambuc #define doctypeName (parser->m_doctypeName)
634*1230fdc1SLionel Sambuc #define doctypeSysid (parser->m_doctypeSysid)
635*1230fdc1SLionel Sambuc #define doctypePubid (parser->m_doctypePubid)
636*1230fdc1SLionel Sambuc #define declAttributeType (parser->m_declAttributeType)
637*1230fdc1SLionel Sambuc #define declNotationName (parser->m_declNotationName)
638*1230fdc1SLionel Sambuc #define declNotationPublicId (parser->m_declNotationPublicId)
639*1230fdc1SLionel Sambuc #define declElementType (parser->m_declElementType)
640*1230fdc1SLionel Sambuc #define declAttributeId (parser->m_declAttributeId)
641*1230fdc1SLionel Sambuc #define declAttributeIsCdata (parser->m_declAttributeIsCdata)
642*1230fdc1SLionel Sambuc #define declAttributeIsId (parser->m_declAttributeIsId)
643*1230fdc1SLionel Sambuc #define freeTagList (parser->m_freeTagList)
644*1230fdc1SLionel Sambuc #define freeBindingList (parser->m_freeBindingList)
645*1230fdc1SLionel Sambuc #define inheritedBindings (parser->m_inheritedBindings)
646*1230fdc1SLionel Sambuc #define tagStack (parser->m_tagStack)
647*1230fdc1SLionel Sambuc #define atts (parser->m_atts)
648*1230fdc1SLionel Sambuc #define attsSize (parser->m_attsSize)
649*1230fdc1SLionel Sambuc #define nSpecifiedAtts (parser->m_nSpecifiedAtts)
650*1230fdc1SLionel Sambuc #define idAttIndex (parser->m_idAttIndex)
651*1230fdc1SLionel Sambuc #define nsAtts (parser->m_nsAtts)
652*1230fdc1SLionel Sambuc #define nsAttsVersion (parser->m_nsAttsVersion)
653*1230fdc1SLionel Sambuc #define nsAttsPower (parser->m_nsAttsPower)
654*1230fdc1SLionel Sambuc #define attInfo (parser->m_attInfo)
655*1230fdc1SLionel Sambuc #define tempPool (parser->m_tempPool)
656*1230fdc1SLionel Sambuc #define temp2Pool (parser->m_temp2Pool)
657*1230fdc1SLionel Sambuc #define groupConnector (parser->m_groupConnector)
658*1230fdc1SLionel Sambuc #define groupSize (parser->m_groupSize)
659*1230fdc1SLionel Sambuc #define namespaceSeparator (parser->m_namespaceSeparator)
660*1230fdc1SLionel Sambuc #define parentParser (parser->m_parentParser)
661*1230fdc1SLionel Sambuc #define ps_parsing (parser->m_parsingStatus.parsing)
662*1230fdc1SLionel Sambuc #define ps_finalBuffer (parser->m_parsingStatus.finalBuffer)
663*1230fdc1SLionel Sambuc #ifdef XML_DTD
664*1230fdc1SLionel Sambuc #define isParamEntity (parser->m_isParamEntity)
665*1230fdc1SLionel Sambuc #define useForeignDTD (parser->m_useForeignDTD)
666*1230fdc1SLionel Sambuc #define paramEntityParsing (parser->m_paramEntityParsing)
667*1230fdc1SLionel Sambuc #endif /* XML_DTD */
668*1230fdc1SLionel Sambuc #define hash_secret_salt (parser->m_hash_secret_salt)
669*1230fdc1SLionel Sambuc
670*1230fdc1SLionel Sambuc XML_Parser XMLCALL
XML_ParserCreate(const XML_Char * encodingName)671*1230fdc1SLionel Sambuc XML_ParserCreate(const XML_Char *encodingName)
672*1230fdc1SLionel Sambuc {
673*1230fdc1SLionel Sambuc return XML_ParserCreate_MM(encodingName, NULL, NULL);
674*1230fdc1SLionel Sambuc }
675*1230fdc1SLionel Sambuc
676*1230fdc1SLionel Sambuc XML_Parser XMLCALL
XML_ParserCreateNS(const XML_Char * encodingName,XML_Char nsSep)677*1230fdc1SLionel Sambuc XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep)
678*1230fdc1SLionel Sambuc {
679*1230fdc1SLionel Sambuc XML_Char tmp[2];
680*1230fdc1SLionel Sambuc *tmp = nsSep;
681*1230fdc1SLionel Sambuc return XML_ParserCreate_MM(encodingName, NULL, tmp);
682*1230fdc1SLionel Sambuc }
683*1230fdc1SLionel Sambuc
684*1230fdc1SLionel Sambuc static const XML_Char implicitContext[] = {
685*1230fdc1SLionel Sambuc ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p,
686*1230fdc1SLionel Sambuc ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w,
687*1230fdc1SLionel Sambuc ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g,
688*1230fdc1SLionel Sambuc ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9,
689*1230fdc1SLionel Sambuc ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e,
690*1230fdc1SLionel Sambuc ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'
691*1230fdc1SLionel Sambuc };
692*1230fdc1SLionel Sambuc
693*1230fdc1SLionel Sambuc static unsigned long
generate_hash_secret_salt(void)694*1230fdc1SLionel Sambuc generate_hash_secret_salt(void)
695*1230fdc1SLionel Sambuc {
696*1230fdc1SLionel Sambuc unsigned int seed = time(NULL) % UINT_MAX;
697*1230fdc1SLionel Sambuc srand(seed);
698*1230fdc1SLionel Sambuc return rand();
699*1230fdc1SLionel Sambuc }
700*1230fdc1SLionel Sambuc
701*1230fdc1SLionel Sambuc static XML_Bool /* only valid for root parser */
startParsing(XML_Parser parser)702*1230fdc1SLionel Sambuc startParsing(XML_Parser parser)
703*1230fdc1SLionel Sambuc {
704*1230fdc1SLionel Sambuc /* hash functions must be initialized before setContext() is called */
705*1230fdc1SLionel Sambuc if (hash_secret_salt == 0)
706*1230fdc1SLionel Sambuc hash_secret_salt = generate_hash_secret_salt();
707*1230fdc1SLionel Sambuc if (ns) {
708*1230fdc1SLionel Sambuc /* implicit context only set for root parser, since child
709*1230fdc1SLionel Sambuc parsers (i.e. external entity parsers) will inherit it
710*1230fdc1SLionel Sambuc */
711*1230fdc1SLionel Sambuc return setContext(parser, implicitContext);
712*1230fdc1SLionel Sambuc }
713*1230fdc1SLionel Sambuc return XML_TRUE;
714*1230fdc1SLionel Sambuc }
715*1230fdc1SLionel Sambuc
716*1230fdc1SLionel Sambuc XML_Parser XMLCALL
XML_ParserCreate_MM(const XML_Char * encodingName,const XML_Memory_Handling_Suite * memsuite,const XML_Char * nameSep)717*1230fdc1SLionel Sambuc XML_ParserCreate_MM(const XML_Char *encodingName,
718*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite *memsuite,
719*1230fdc1SLionel Sambuc const XML_Char *nameSep)
720*1230fdc1SLionel Sambuc {
721*1230fdc1SLionel Sambuc return parserCreate(encodingName, memsuite, nameSep, NULL);
722*1230fdc1SLionel Sambuc }
723*1230fdc1SLionel Sambuc
724*1230fdc1SLionel Sambuc static XML_Parser
parserCreate(const XML_Char * encodingName,const XML_Memory_Handling_Suite * memsuite,const XML_Char * nameSep,DTD * dtd)725*1230fdc1SLionel Sambuc parserCreate(const XML_Char *encodingName,
726*1230fdc1SLionel Sambuc const XML_Memory_Handling_Suite *memsuite,
727*1230fdc1SLionel Sambuc const XML_Char *nameSep,
728*1230fdc1SLionel Sambuc DTD *dtd)
729*1230fdc1SLionel Sambuc {
730*1230fdc1SLionel Sambuc XML_Parser parser;
731*1230fdc1SLionel Sambuc
732*1230fdc1SLionel Sambuc if (memsuite) {
733*1230fdc1SLionel Sambuc XML_Memory_Handling_Suite *mtemp;
734*1230fdc1SLionel Sambuc parser = (XML_Parser)
735*1230fdc1SLionel Sambuc memsuite->malloc_fcn(sizeof(struct XML_ParserStruct));
736*1230fdc1SLionel Sambuc if (parser != NULL) {
737*1230fdc1SLionel Sambuc mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem);
738*1230fdc1SLionel Sambuc mtemp->malloc_fcn = memsuite->malloc_fcn;
739*1230fdc1SLionel Sambuc mtemp->realloc_fcn = memsuite->realloc_fcn;
740*1230fdc1SLionel Sambuc mtemp->free_fcn = memsuite->free_fcn;
741*1230fdc1SLionel Sambuc }
742*1230fdc1SLionel Sambuc }
743*1230fdc1SLionel Sambuc else {
744*1230fdc1SLionel Sambuc XML_Memory_Handling_Suite *mtemp;
745*1230fdc1SLionel Sambuc parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct));
746*1230fdc1SLionel Sambuc if (parser != NULL) {
747*1230fdc1SLionel Sambuc mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem);
748*1230fdc1SLionel Sambuc mtemp->malloc_fcn = malloc;
749*1230fdc1SLionel Sambuc mtemp->realloc_fcn = realloc;
750*1230fdc1SLionel Sambuc mtemp->free_fcn = free;
751*1230fdc1SLionel Sambuc }
752*1230fdc1SLionel Sambuc }
753*1230fdc1SLionel Sambuc
754*1230fdc1SLionel Sambuc if (!parser)
755*1230fdc1SLionel Sambuc return parser;
756*1230fdc1SLionel Sambuc
757*1230fdc1SLionel Sambuc buffer = NULL;
758*1230fdc1SLionel Sambuc bufferLim = NULL;
759*1230fdc1SLionel Sambuc
760*1230fdc1SLionel Sambuc attsSize = INIT_ATTS_SIZE;
761*1230fdc1SLionel Sambuc atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE));
762*1230fdc1SLionel Sambuc if (atts == NULL) {
763*1230fdc1SLionel Sambuc FREE(parser);
764*1230fdc1SLionel Sambuc return NULL;
765*1230fdc1SLionel Sambuc }
766*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
767*1230fdc1SLionel Sambuc attInfo = (XML_AttrInfo*)MALLOC(attsSize * sizeof(XML_AttrInfo));
768*1230fdc1SLionel Sambuc if (attInfo == NULL) {
769*1230fdc1SLionel Sambuc FREE(atts);
770*1230fdc1SLionel Sambuc FREE(parser);
771*1230fdc1SLionel Sambuc return NULL;
772*1230fdc1SLionel Sambuc }
773*1230fdc1SLionel Sambuc #endif
774*1230fdc1SLionel Sambuc dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
775*1230fdc1SLionel Sambuc if (dataBuf == NULL) {
776*1230fdc1SLionel Sambuc FREE(atts);
777*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
778*1230fdc1SLionel Sambuc FREE(attInfo);
779*1230fdc1SLionel Sambuc #endif
780*1230fdc1SLionel Sambuc FREE(parser);
781*1230fdc1SLionel Sambuc return NULL;
782*1230fdc1SLionel Sambuc }
783*1230fdc1SLionel Sambuc dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
784*1230fdc1SLionel Sambuc
785*1230fdc1SLionel Sambuc if (dtd)
786*1230fdc1SLionel Sambuc _dtd = dtd;
787*1230fdc1SLionel Sambuc else {
788*1230fdc1SLionel Sambuc _dtd = dtdCreate(&parser->m_mem);
789*1230fdc1SLionel Sambuc if (_dtd == NULL) {
790*1230fdc1SLionel Sambuc FREE(dataBuf);
791*1230fdc1SLionel Sambuc FREE(atts);
792*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
793*1230fdc1SLionel Sambuc FREE(attInfo);
794*1230fdc1SLionel Sambuc #endif
795*1230fdc1SLionel Sambuc FREE(parser);
796*1230fdc1SLionel Sambuc return NULL;
797*1230fdc1SLionel Sambuc }
798*1230fdc1SLionel Sambuc }
799*1230fdc1SLionel Sambuc
800*1230fdc1SLionel Sambuc freeBindingList = NULL;
801*1230fdc1SLionel Sambuc freeTagList = NULL;
802*1230fdc1SLionel Sambuc freeInternalEntities = NULL;
803*1230fdc1SLionel Sambuc
804*1230fdc1SLionel Sambuc groupSize = 0;
805*1230fdc1SLionel Sambuc groupConnector = NULL;
806*1230fdc1SLionel Sambuc
807*1230fdc1SLionel Sambuc unknownEncodingHandler = NULL;
808*1230fdc1SLionel Sambuc unknownEncodingHandlerData = NULL;
809*1230fdc1SLionel Sambuc
810*1230fdc1SLionel Sambuc namespaceSeparator = ASCII_EXCL;
811*1230fdc1SLionel Sambuc ns = XML_FALSE;
812*1230fdc1SLionel Sambuc ns_triplets = XML_FALSE;
813*1230fdc1SLionel Sambuc
814*1230fdc1SLionel Sambuc nsAtts = NULL;
815*1230fdc1SLionel Sambuc nsAttsVersion = 0;
816*1230fdc1SLionel Sambuc nsAttsPower = 0;
817*1230fdc1SLionel Sambuc
818*1230fdc1SLionel Sambuc poolInit(&tempPool, &(parser->m_mem));
819*1230fdc1SLionel Sambuc poolInit(&temp2Pool, &(parser->m_mem));
820*1230fdc1SLionel Sambuc parserInit(parser, encodingName);
821*1230fdc1SLionel Sambuc
822*1230fdc1SLionel Sambuc if (encodingName && !protocolEncodingName) {
823*1230fdc1SLionel Sambuc XML_ParserFree(parser);
824*1230fdc1SLionel Sambuc return NULL;
825*1230fdc1SLionel Sambuc }
826*1230fdc1SLionel Sambuc
827*1230fdc1SLionel Sambuc if (nameSep) {
828*1230fdc1SLionel Sambuc ns = XML_TRUE;
829*1230fdc1SLionel Sambuc internalEncoding = XmlGetInternalEncodingNS();
830*1230fdc1SLionel Sambuc namespaceSeparator = *nameSep;
831*1230fdc1SLionel Sambuc }
832*1230fdc1SLionel Sambuc else {
833*1230fdc1SLionel Sambuc internalEncoding = XmlGetInternalEncoding();
834*1230fdc1SLionel Sambuc }
835*1230fdc1SLionel Sambuc
836*1230fdc1SLionel Sambuc return parser;
837*1230fdc1SLionel Sambuc }
838*1230fdc1SLionel Sambuc
839*1230fdc1SLionel Sambuc static void
parserInit(XML_Parser parser,const XML_Char * encodingName)840*1230fdc1SLionel Sambuc parserInit(XML_Parser parser, const XML_Char *encodingName)
841*1230fdc1SLionel Sambuc {
842*1230fdc1SLionel Sambuc processor = prologInitProcessor;
843*1230fdc1SLionel Sambuc XmlPrologStateInit(&prologState);
844*1230fdc1SLionel Sambuc protocolEncodingName = (encodingName != NULL
845*1230fdc1SLionel Sambuc ? poolCopyString(&tempPool, encodingName)
846*1230fdc1SLionel Sambuc : NULL);
847*1230fdc1SLionel Sambuc curBase = NULL;
848*1230fdc1SLionel Sambuc XmlInitEncoding(&initEncoding, &encoding, 0);
849*1230fdc1SLionel Sambuc userData = NULL;
850*1230fdc1SLionel Sambuc handlerArg = NULL;
851*1230fdc1SLionel Sambuc startElementHandler = NULL;
852*1230fdc1SLionel Sambuc endElementHandler = NULL;
853*1230fdc1SLionel Sambuc characterDataHandler = NULL;
854*1230fdc1SLionel Sambuc processingInstructionHandler = NULL;
855*1230fdc1SLionel Sambuc commentHandler = NULL;
856*1230fdc1SLionel Sambuc startCdataSectionHandler = NULL;
857*1230fdc1SLionel Sambuc endCdataSectionHandler = NULL;
858*1230fdc1SLionel Sambuc defaultHandler = NULL;
859*1230fdc1SLionel Sambuc startDoctypeDeclHandler = NULL;
860*1230fdc1SLionel Sambuc endDoctypeDeclHandler = NULL;
861*1230fdc1SLionel Sambuc unparsedEntityDeclHandler = NULL;
862*1230fdc1SLionel Sambuc notationDeclHandler = NULL;
863*1230fdc1SLionel Sambuc startNamespaceDeclHandler = NULL;
864*1230fdc1SLionel Sambuc endNamespaceDeclHandler = NULL;
865*1230fdc1SLionel Sambuc notStandaloneHandler = NULL;
866*1230fdc1SLionel Sambuc externalEntityRefHandler = NULL;
867*1230fdc1SLionel Sambuc externalEntityRefHandlerArg = parser;
868*1230fdc1SLionel Sambuc skippedEntityHandler = NULL;
869*1230fdc1SLionel Sambuc elementDeclHandler = NULL;
870*1230fdc1SLionel Sambuc attlistDeclHandler = NULL;
871*1230fdc1SLionel Sambuc entityDeclHandler = NULL;
872*1230fdc1SLionel Sambuc xmlDeclHandler = NULL;
873*1230fdc1SLionel Sambuc bufferPtr = buffer;
874*1230fdc1SLionel Sambuc bufferEnd = buffer;
875*1230fdc1SLionel Sambuc parseEndByteIndex = 0;
876*1230fdc1SLionel Sambuc parseEndPtr = NULL;
877*1230fdc1SLionel Sambuc declElementType = NULL;
878*1230fdc1SLionel Sambuc declAttributeId = NULL;
879*1230fdc1SLionel Sambuc declEntity = NULL;
880*1230fdc1SLionel Sambuc doctypeName = NULL;
881*1230fdc1SLionel Sambuc doctypeSysid = NULL;
882*1230fdc1SLionel Sambuc doctypePubid = NULL;
883*1230fdc1SLionel Sambuc declAttributeType = NULL;
884*1230fdc1SLionel Sambuc declNotationName = NULL;
885*1230fdc1SLionel Sambuc declNotationPublicId = NULL;
886*1230fdc1SLionel Sambuc declAttributeIsCdata = XML_FALSE;
887*1230fdc1SLionel Sambuc declAttributeIsId = XML_FALSE;
888*1230fdc1SLionel Sambuc memset(&position, 0, sizeof(POSITION));
889*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NONE;
890*1230fdc1SLionel Sambuc eventPtr = NULL;
891*1230fdc1SLionel Sambuc eventEndPtr = NULL;
892*1230fdc1SLionel Sambuc positionPtr = NULL;
893*1230fdc1SLionel Sambuc openInternalEntities = NULL;
894*1230fdc1SLionel Sambuc defaultExpandInternalEntities = XML_TRUE;
895*1230fdc1SLionel Sambuc tagLevel = 0;
896*1230fdc1SLionel Sambuc tagStack = NULL;
897*1230fdc1SLionel Sambuc inheritedBindings = NULL;
898*1230fdc1SLionel Sambuc nSpecifiedAtts = 0;
899*1230fdc1SLionel Sambuc unknownEncodingMem = NULL;
900*1230fdc1SLionel Sambuc unknownEncodingRelease = NULL;
901*1230fdc1SLionel Sambuc unknownEncodingData = NULL;
902*1230fdc1SLionel Sambuc parentParser = NULL;
903*1230fdc1SLionel Sambuc ps_parsing = XML_INITIALIZED;
904*1230fdc1SLionel Sambuc #ifdef XML_DTD
905*1230fdc1SLionel Sambuc isParamEntity = XML_FALSE;
906*1230fdc1SLionel Sambuc useForeignDTD = XML_FALSE;
907*1230fdc1SLionel Sambuc paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
908*1230fdc1SLionel Sambuc #endif
909*1230fdc1SLionel Sambuc hash_secret_salt = 0;
910*1230fdc1SLionel Sambuc }
911*1230fdc1SLionel Sambuc
912*1230fdc1SLionel Sambuc /* moves list of bindings to freeBindingList */
913*1230fdc1SLionel Sambuc static void FASTCALL
moveToFreeBindingList(XML_Parser parser,BINDING * bindings)914*1230fdc1SLionel Sambuc moveToFreeBindingList(XML_Parser parser, BINDING *bindings)
915*1230fdc1SLionel Sambuc {
916*1230fdc1SLionel Sambuc while (bindings) {
917*1230fdc1SLionel Sambuc BINDING *b = bindings;
918*1230fdc1SLionel Sambuc bindings = bindings->nextTagBinding;
919*1230fdc1SLionel Sambuc b->nextTagBinding = freeBindingList;
920*1230fdc1SLionel Sambuc freeBindingList = b;
921*1230fdc1SLionel Sambuc }
922*1230fdc1SLionel Sambuc }
923*1230fdc1SLionel Sambuc
924*1230fdc1SLionel Sambuc XML_Bool XMLCALL
XML_ParserReset(XML_Parser parser,const XML_Char * encodingName)925*1230fdc1SLionel Sambuc XML_ParserReset(XML_Parser parser, const XML_Char *encodingName)
926*1230fdc1SLionel Sambuc {
927*1230fdc1SLionel Sambuc TAG *tStk;
928*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *openEntityList;
929*1230fdc1SLionel Sambuc if (parentParser)
930*1230fdc1SLionel Sambuc return XML_FALSE;
931*1230fdc1SLionel Sambuc /* move tagStack to freeTagList */
932*1230fdc1SLionel Sambuc tStk = tagStack;
933*1230fdc1SLionel Sambuc while (tStk) {
934*1230fdc1SLionel Sambuc TAG *tag = tStk;
935*1230fdc1SLionel Sambuc tStk = tStk->parent;
936*1230fdc1SLionel Sambuc tag->parent = freeTagList;
937*1230fdc1SLionel Sambuc moveToFreeBindingList(parser, tag->bindings);
938*1230fdc1SLionel Sambuc tag->bindings = NULL;
939*1230fdc1SLionel Sambuc freeTagList = tag;
940*1230fdc1SLionel Sambuc }
941*1230fdc1SLionel Sambuc /* move openInternalEntities to freeInternalEntities */
942*1230fdc1SLionel Sambuc openEntityList = openInternalEntities;
943*1230fdc1SLionel Sambuc while (openEntityList) {
944*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *openEntity = openEntityList;
945*1230fdc1SLionel Sambuc openEntityList = openEntity->next;
946*1230fdc1SLionel Sambuc openEntity->next = freeInternalEntities;
947*1230fdc1SLionel Sambuc freeInternalEntities = openEntity;
948*1230fdc1SLionel Sambuc }
949*1230fdc1SLionel Sambuc moveToFreeBindingList(parser, inheritedBindings);
950*1230fdc1SLionel Sambuc FREE(unknownEncodingMem);
951*1230fdc1SLionel Sambuc if (unknownEncodingRelease)
952*1230fdc1SLionel Sambuc unknownEncodingRelease(unknownEncodingData);
953*1230fdc1SLionel Sambuc poolClear(&tempPool);
954*1230fdc1SLionel Sambuc poolClear(&temp2Pool);
955*1230fdc1SLionel Sambuc parserInit(parser, encodingName);
956*1230fdc1SLionel Sambuc dtdReset(_dtd, &parser->m_mem);
957*1230fdc1SLionel Sambuc return XML_TRUE;
958*1230fdc1SLionel Sambuc }
959*1230fdc1SLionel Sambuc
960*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_SetEncoding(XML_Parser parser,const XML_Char * encodingName)961*1230fdc1SLionel Sambuc XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName)
962*1230fdc1SLionel Sambuc {
963*1230fdc1SLionel Sambuc /* Block after XML_Parse()/XML_ParseBuffer() has been called.
964*1230fdc1SLionel Sambuc XXX There's no way for the caller to determine which of the
965*1230fdc1SLionel Sambuc XXX possible error cases caused the XML_STATUS_ERROR return.
966*1230fdc1SLionel Sambuc */
967*1230fdc1SLionel Sambuc if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
968*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
969*1230fdc1SLionel Sambuc if (encodingName == NULL)
970*1230fdc1SLionel Sambuc protocolEncodingName = NULL;
971*1230fdc1SLionel Sambuc else {
972*1230fdc1SLionel Sambuc protocolEncodingName = poolCopyString(&tempPool, encodingName);
973*1230fdc1SLionel Sambuc if (!protocolEncodingName)
974*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
975*1230fdc1SLionel Sambuc }
976*1230fdc1SLionel Sambuc return XML_STATUS_OK;
977*1230fdc1SLionel Sambuc }
978*1230fdc1SLionel Sambuc
979*1230fdc1SLionel Sambuc XML_Parser XMLCALL
XML_ExternalEntityParserCreate(XML_Parser oldParser,const XML_Char * context,const XML_Char * encodingName)980*1230fdc1SLionel Sambuc XML_ExternalEntityParserCreate(XML_Parser oldParser,
981*1230fdc1SLionel Sambuc const XML_Char *context,
982*1230fdc1SLionel Sambuc const XML_Char *encodingName)
983*1230fdc1SLionel Sambuc {
984*1230fdc1SLionel Sambuc XML_Parser parser = oldParser;
985*1230fdc1SLionel Sambuc DTD *newDtd = NULL;
986*1230fdc1SLionel Sambuc DTD *oldDtd = _dtd;
987*1230fdc1SLionel Sambuc XML_StartElementHandler oldStartElementHandler = startElementHandler;
988*1230fdc1SLionel Sambuc XML_EndElementHandler oldEndElementHandler = endElementHandler;
989*1230fdc1SLionel Sambuc XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler;
990*1230fdc1SLionel Sambuc XML_ProcessingInstructionHandler oldProcessingInstructionHandler
991*1230fdc1SLionel Sambuc = processingInstructionHandler;
992*1230fdc1SLionel Sambuc XML_CommentHandler oldCommentHandler = commentHandler;
993*1230fdc1SLionel Sambuc XML_StartCdataSectionHandler oldStartCdataSectionHandler
994*1230fdc1SLionel Sambuc = startCdataSectionHandler;
995*1230fdc1SLionel Sambuc XML_EndCdataSectionHandler oldEndCdataSectionHandler
996*1230fdc1SLionel Sambuc = endCdataSectionHandler;
997*1230fdc1SLionel Sambuc XML_DefaultHandler oldDefaultHandler = defaultHandler;
998*1230fdc1SLionel Sambuc XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler
999*1230fdc1SLionel Sambuc = unparsedEntityDeclHandler;
1000*1230fdc1SLionel Sambuc XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler;
1001*1230fdc1SLionel Sambuc XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler
1002*1230fdc1SLionel Sambuc = startNamespaceDeclHandler;
1003*1230fdc1SLionel Sambuc XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler
1004*1230fdc1SLionel Sambuc = endNamespaceDeclHandler;
1005*1230fdc1SLionel Sambuc XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler;
1006*1230fdc1SLionel Sambuc XML_ExternalEntityRefHandler oldExternalEntityRefHandler
1007*1230fdc1SLionel Sambuc = externalEntityRefHandler;
1008*1230fdc1SLionel Sambuc XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler;
1009*1230fdc1SLionel Sambuc XML_UnknownEncodingHandler oldUnknownEncodingHandler
1010*1230fdc1SLionel Sambuc = unknownEncodingHandler;
1011*1230fdc1SLionel Sambuc XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler;
1012*1230fdc1SLionel Sambuc XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler;
1013*1230fdc1SLionel Sambuc XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler;
1014*1230fdc1SLionel Sambuc XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler;
1015*1230fdc1SLionel Sambuc ELEMENT_TYPE * oldDeclElementType = declElementType;
1016*1230fdc1SLionel Sambuc
1017*1230fdc1SLionel Sambuc void *oldUserData = userData;
1018*1230fdc1SLionel Sambuc void *oldHandlerArg = handlerArg;
1019*1230fdc1SLionel Sambuc XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities;
1020*1230fdc1SLionel Sambuc XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg;
1021*1230fdc1SLionel Sambuc #ifdef XML_DTD
1022*1230fdc1SLionel Sambuc enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing;
1023*1230fdc1SLionel Sambuc int oldInEntityValue = prologState.inEntityValue;
1024*1230fdc1SLionel Sambuc #endif
1025*1230fdc1SLionel Sambuc XML_Bool oldns_triplets = ns_triplets;
1026*1230fdc1SLionel Sambuc /* Note that the new parser shares the same hash secret as the old
1027*1230fdc1SLionel Sambuc parser, so that dtdCopy and copyEntityTable can lookup values
1028*1230fdc1SLionel Sambuc from hash tables associated with either parser without us having
1029*1230fdc1SLionel Sambuc to worry which hash secrets each table has.
1030*1230fdc1SLionel Sambuc */
1031*1230fdc1SLionel Sambuc unsigned long oldhash_secret_salt = hash_secret_salt;
1032*1230fdc1SLionel Sambuc
1033*1230fdc1SLionel Sambuc #ifdef XML_DTD
1034*1230fdc1SLionel Sambuc if (!context)
1035*1230fdc1SLionel Sambuc newDtd = oldDtd;
1036*1230fdc1SLionel Sambuc #endif /* XML_DTD */
1037*1230fdc1SLionel Sambuc
1038*1230fdc1SLionel Sambuc /* Note that the magical uses of the pre-processor to make field
1039*1230fdc1SLionel Sambuc access look more like C++ require that `parser' be overwritten
1040*1230fdc1SLionel Sambuc here. This makes this function more painful to follow than it
1041*1230fdc1SLionel Sambuc would be otherwise.
1042*1230fdc1SLionel Sambuc */
1043*1230fdc1SLionel Sambuc if (ns) {
1044*1230fdc1SLionel Sambuc XML_Char tmp[2];
1045*1230fdc1SLionel Sambuc *tmp = namespaceSeparator;
1046*1230fdc1SLionel Sambuc parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd);
1047*1230fdc1SLionel Sambuc }
1048*1230fdc1SLionel Sambuc else {
1049*1230fdc1SLionel Sambuc parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd);
1050*1230fdc1SLionel Sambuc }
1051*1230fdc1SLionel Sambuc
1052*1230fdc1SLionel Sambuc if (!parser)
1053*1230fdc1SLionel Sambuc return NULL;
1054*1230fdc1SLionel Sambuc
1055*1230fdc1SLionel Sambuc startElementHandler = oldStartElementHandler;
1056*1230fdc1SLionel Sambuc endElementHandler = oldEndElementHandler;
1057*1230fdc1SLionel Sambuc characterDataHandler = oldCharacterDataHandler;
1058*1230fdc1SLionel Sambuc processingInstructionHandler = oldProcessingInstructionHandler;
1059*1230fdc1SLionel Sambuc commentHandler = oldCommentHandler;
1060*1230fdc1SLionel Sambuc startCdataSectionHandler = oldStartCdataSectionHandler;
1061*1230fdc1SLionel Sambuc endCdataSectionHandler = oldEndCdataSectionHandler;
1062*1230fdc1SLionel Sambuc defaultHandler = oldDefaultHandler;
1063*1230fdc1SLionel Sambuc unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler;
1064*1230fdc1SLionel Sambuc notationDeclHandler = oldNotationDeclHandler;
1065*1230fdc1SLionel Sambuc startNamespaceDeclHandler = oldStartNamespaceDeclHandler;
1066*1230fdc1SLionel Sambuc endNamespaceDeclHandler = oldEndNamespaceDeclHandler;
1067*1230fdc1SLionel Sambuc notStandaloneHandler = oldNotStandaloneHandler;
1068*1230fdc1SLionel Sambuc externalEntityRefHandler = oldExternalEntityRefHandler;
1069*1230fdc1SLionel Sambuc skippedEntityHandler = oldSkippedEntityHandler;
1070*1230fdc1SLionel Sambuc unknownEncodingHandler = oldUnknownEncodingHandler;
1071*1230fdc1SLionel Sambuc elementDeclHandler = oldElementDeclHandler;
1072*1230fdc1SLionel Sambuc attlistDeclHandler = oldAttlistDeclHandler;
1073*1230fdc1SLionel Sambuc entityDeclHandler = oldEntityDeclHandler;
1074*1230fdc1SLionel Sambuc xmlDeclHandler = oldXmlDeclHandler;
1075*1230fdc1SLionel Sambuc declElementType = oldDeclElementType;
1076*1230fdc1SLionel Sambuc userData = oldUserData;
1077*1230fdc1SLionel Sambuc if (oldUserData == oldHandlerArg)
1078*1230fdc1SLionel Sambuc handlerArg = userData;
1079*1230fdc1SLionel Sambuc else
1080*1230fdc1SLionel Sambuc handlerArg = parser;
1081*1230fdc1SLionel Sambuc if (oldExternalEntityRefHandlerArg != oldParser)
1082*1230fdc1SLionel Sambuc externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
1083*1230fdc1SLionel Sambuc defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
1084*1230fdc1SLionel Sambuc ns_triplets = oldns_triplets;
1085*1230fdc1SLionel Sambuc hash_secret_salt = oldhash_secret_salt;
1086*1230fdc1SLionel Sambuc parentParser = oldParser;
1087*1230fdc1SLionel Sambuc #ifdef XML_DTD
1088*1230fdc1SLionel Sambuc paramEntityParsing = oldParamEntityParsing;
1089*1230fdc1SLionel Sambuc prologState.inEntityValue = oldInEntityValue;
1090*1230fdc1SLionel Sambuc if (context) {
1091*1230fdc1SLionel Sambuc #endif /* XML_DTD */
1092*1230fdc1SLionel Sambuc if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem)
1093*1230fdc1SLionel Sambuc || !setContext(parser, context)) {
1094*1230fdc1SLionel Sambuc XML_ParserFree(parser);
1095*1230fdc1SLionel Sambuc return NULL;
1096*1230fdc1SLionel Sambuc }
1097*1230fdc1SLionel Sambuc processor = externalEntityInitProcessor;
1098*1230fdc1SLionel Sambuc #ifdef XML_DTD
1099*1230fdc1SLionel Sambuc }
1100*1230fdc1SLionel Sambuc else {
1101*1230fdc1SLionel Sambuc /* The DTD instance referenced by _dtd is shared between the document's
1102*1230fdc1SLionel Sambuc root parser and external PE parsers, therefore one does not need to
1103*1230fdc1SLionel Sambuc call setContext. In addition, one also *must* not call setContext,
1104*1230fdc1SLionel Sambuc because this would overwrite existing prefix->binding pointers in
1105*1230fdc1SLionel Sambuc _dtd with ones that get destroyed with the external PE parser.
1106*1230fdc1SLionel Sambuc This would leave those prefixes with dangling pointers.
1107*1230fdc1SLionel Sambuc */
1108*1230fdc1SLionel Sambuc isParamEntity = XML_TRUE;
1109*1230fdc1SLionel Sambuc XmlPrologStateInitExternalEntity(&prologState);
1110*1230fdc1SLionel Sambuc processor = externalParEntInitProcessor;
1111*1230fdc1SLionel Sambuc }
1112*1230fdc1SLionel Sambuc #endif /* XML_DTD */
1113*1230fdc1SLionel Sambuc return parser;
1114*1230fdc1SLionel Sambuc }
1115*1230fdc1SLionel Sambuc
1116*1230fdc1SLionel Sambuc static void FASTCALL
destroyBindings(BINDING * bindings,XML_Parser parser)1117*1230fdc1SLionel Sambuc destroyBindings(BINDING *bindings, XML_Parser parser)
1118*1230fdc1SLionel Sambuc {
1119*1230fdc1SLionel Sambuc for (;;) {
1120*1230fdc1SLionel Sambuc BINDING *b = bindings;
1121*1230fdc1SLionel Sambuc if (!b)
1122*1230fdc1SLionel Sambuc break;
1123*1230fdc1SLionel Sambuc bindings = b->nextTagBinding;
1124*1230fdc1SLionel Sambuc FREE(b->uri);
1125*1230fdc1SLionel Sambuc FREE(b);
1126*1230fdc1SLionel Sambuc }
1127*1230fdc1SLionel Sambuc }
1128*1230fdc1SLionel Sambuc
1129*1230fdc1SLionel Sambuc void XMLCALL
XML_ParserFree(XML_Parser parser)1130*1230fdc1SLionel Sambuc XML_ParserFree(XML_Parser parser)
1131*1230fdc1SLionel Sambuc {
1132*1230fdc1SLionel Sambuc TAG *tagList;
1133*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *entityList;
1134*1230fdc1SLionel Sambuc if (parser == NULL)
1135*1230fdc1SLionel Sambuc return;
1136*1230fdc1SLionel Sambuc /* free tagStack and freeTagList */
1137*1230fdc1SLionel Sambuc tagList = tagStack;
1138*1230fdc1SLionel Sambuc for (;;) {
1139*1230fdc1SLionel Sambuc TAG *p;
1140*1230fdc1SLionel Sambuc if (tagList == NULL) {
1141*1230fdc1SLionel Sambuc if (freeTagList == NULL)
1142*1230fdc1SLionel Sambuc break;
1143*1230fdc1SLionel Sambuc tagList = freeTagList;
1144*1230fdc1SLionel Sambuc freeTagList = NULL;
1145*1230fdc1SLionel Sambuc }
1146*1230fdc1SLionel Sambuc p = tagList;
1147*1230fdc1SLionel Sambuc tagList = tagList->parent;
1148*1230fdc1SLionel Sambuc FREE(p->buf);
1149*1230fdc1SLionel Sambuc destroyBindings(p->bindings, parser);
1150*1230fdc1SLionel Sambuc FREE(p);
1151*1230fdc1SLionel Sambuc }
1152*1230fdc1SLionel Sambuc /* free openInternalEntities and freeInternalEntities */
1153*1230fdc1SLionel Sambuc entityList = openInternalEntities;
1154*1230fdc1SLionel Sambuc for (;;) {
1155*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *openEntity;
1156*1230fdc1SLionel Sambuc if (entityList == NULL) {
1157*1230fdc1SLionel Sambuc if (freeInternalEntities == NULL)
1158*1230fdc1SLionel Sambuc break;
1159*1230fdc1SLionel Sambuc entityList = freeInternalEntities;
1160*1230fdc1SLionel Sambuc freeInternalEntities = NULL;
1161*1230fdc1SLionel Sambuc }
1162*1230fdc1SLionel Sambuc openEntity = entityList;
1163*1230fdc1SLionel Sambuc entityList = entityList->next;
1164*1230fdc1SLionel Sambuc FREE(openEntity);
1165*1230fdc1SLionel Sambuc }
1166*1230fdc1SLionel Sambuc
1167*1230fdc1SLionel Sambuc destroyBindings(freeBindingList, parser);
1168*1230fdc1SLionel Sambuc destroyBindings(inheritedBindings, parser);
1169*1230fdc1SLionel Sambuc poolDestroy(&tempPool);
1170*1230fdc1SLionel Sambuc poolDestroy(&temp2Pool);
1171*1230fdc1SLionel Sambuc #ifdef XML_DTD
1172*1230fdc1SLionel Sambuc /* external parameter entity parsers share the DTD structure
1173*1230fdc1SLionel Sambuc parser->m_dtd with the root parser, so we must not destroy it
1174*1230fdc1SLionel Sambuc */
1175*1230fdc1SLionel Sambuc if (!isParamEntity && _dtd)
1176*1230fdc1SLionel Sambuc #else
1177*1230fdc1SLionel Sambuc if (_dtd)
1178*1230fdc1SLionel Sambuc #endif /* XML_DTD */
1179*1230fdc1SLionel Sambuc dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem);
1180*1230fdc1SLionel Sambuc FREE((void *)atts);
1181*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
1182*1230fdc1SLionel Sambuc FREE((void *)attInfo);
1183*1230fdc1SLionel Sambuc #endif
1184*1230fdc1SLionel Sambuc FREE(groupConnector);
1185*1230fdc1SLionel Sambuc FREE(buffer);
1186*1230fdc1SLionel Sambuc FREE(dataBuf);
1187*1230fdc1SLionel Sambuc FREE(nsAtts);
1188*1230fdc1SLionel Sambuc FREE(unknownEncodingMem);
1189*1230fdc1SLionel Sambuc if (unknownEncodingRelease)
1190*1230fdc1SLionel Sambuc unknownEncodingRelease(unknownEncodingData);
1191*1230fdc1SLionel Sambuc FREE(parser);
1192*1230fdc1SLionel Sambuc }
1193*1230fdc1SLionel Sambuc
1194*1230fdc1SLionel Sambuc void XMLCALL
XML_UseParserAsHandlerArg(XML_Parser parser)1195*1230fdc1SLionel Sambuc XML_UseParserAsHandlerArg(XML_Parser parser)
1196*1230fdc1SLionel Sambuc {
1197*1230fdc1SLionel Sambuc handlerArg = parser;
1198*1230fdc1SLionel Sambuc }
1199*1230fdc1SLionel Sambuc
1200*1230fdc1SLionel Sambuc enum XML_Error XMLCALL
XML_UseForeignDTD(XML_Parser parser,XML_Bool useDTD)1201*1230fdc1SLionel Sambuc XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD)
1202*1230fdc1SLionel Sambuc {
1203*1230fdc1SLionel Sambuc #ifdef XML_DTD
1204*1230fdc1SLionel Sambuc /* block after XML_Parse()/XML_ParseBuffer() has been called */
1205*1230fdc1SLionel Sambuc if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1206*1230fdc1SLionel Sambuc return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING;
1207*1230fdc1SLionel Sambuc useForeignDTD = useDTD;
1208*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
1209*1230fdc1SLionel Sambuc #else
1210*1230fdc1SLionel Sambuc return XML_ERROR_FEATURE_REQUIRES_XML_DTD;
1211*1230fdc1SLionel Sambuc #endif
1212*1230fdc1SLionel Sambuc }
1213*1230fdc1SLionel Sambuc
1214*1230fdc1SLionel Sambuc void XMLCALL
XML_SetReturnNSTriplet(XML_Parser parser,int do_nst)1215*1230fdc1SLionel Sambuc XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
1216*1230fdc1SLionel Sambuc {
1217*1230fdc1SLionel Sambuc /* block after XML_Parse()/XML_ParseBuffer() has been called */
1218*1230fdc1SLionel Sambuc if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1219*1230fdc1SLionel Sambuc return;
1220*1230fdc1SLionel Sambuc ns_triplets = do_nst ? XML_TRUE : XML_FALSE;
1221*1230fdc1SLionel Sambuc }
1222*1230fdc1SLionel Sambuc
1223*1230fdc1SLionel Sambuc void XMLCALL
XML_SetUserData(XML_Parser parser,void * p)1224*1230fdc1SLionel Sambuc XML_SetUserData(XML_Parser parser, void *p)
1225*1230fdc1SLionel Sambuc {
1226*1230fdc1SLionel Sambuc if (handlerArg == userData)
1227*1230fdc1SLionel Sambuc handlerArg = userData = p;
1228*1230fdc1SLionel Sambuc else
1229*1230fdc1SLionel Sambuc userData = p;
1230*1230fdc1SLionel Sambuc }
1231*1230fdc1SLionel Sambuc
1232*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_SetBase(XML_Parser parser,const XML_Char * p)1233*1230fdc1SLionel Sambuc XML_SetBase(XML_Parser parser, const XML_Char *p)
1234*1230fdc1SLionel Sambuc {
1235*1230fdc1SLionel Sambuc if (p) {
1236*1230fdc1SLionel Sambuc p = poolCopyString(&_dtd->pool, p);
1237*1230fdc1SLionel Sambuc if (!p)
1238*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1239*1230fdc1SLionel Sambuc curBase = p;
1240*1230fdc1SLionel Sambuc }
1241*1230fdc1SLionel Sambuc else
1242*1230fdc1SLionel Sambuc curBase = NULL;
1243*1230fdc1SLionel Sambuc return XML_STATUS_OK;
1244*1230fdc1SLionel Sambuc }
1245*1230fdc1SLionel Sambuc
1246*1230fdc1SLionel Sambuc const XML_Char * XMLCALL
XML_GetBase(XML_Parser parser)1247*1230fdc1SLionel Sambuc XML_GetBase(XML_Parser parser)
1248*1230fdc1SLionel Sambuc {
1249*1230fdc1SLionel Sambuc return curBase;
1250*1230fdc1SLionel Sambuc }
1251*1230fdc1SLionel Sambuc
1252*1230fdc1SLionel Sambuc int XMLCALL
XML_GetSpecifiedAttributeCount(XML_Parser parser)1253*1230fdc1SLionel Sambuc XML_GetSpecifiedAttributeCount(XML_Parser parser)
1254*1230fdc1SLionel Sambuc {
1255*1230fdc1SLionel Sambuc return nSpecifiedAtts;
1256*1230fdc1SLionel Sambuc }
1257*1230fdc1SLionel Sambuc
1258*1230fdc1SLionel Sambuc int XMLCALL
XML_GetIdAttributeIndex(XML_Parser parser)1259*1230fdc1SLionel Sambuc XML_GetIdAttributeIndex(XML_Parser parser)
1260*1230fdc1SLionel Sambuc {
1261*1230fdc1SLionel Sambuc return idAttIndex;
1262*1230fdc1SLionel Sambuc }
1263*1230fdc1SLionel Sambuc
1264*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
1265*1230fdc1SLionel Sambuc const XML_AttrInfo * XMLCALL
XML_GetAttributeInfo(XML_Parser parser)1266*1230fdc1SLionel Sambuc XML_GetAttributeInfo(XML_Parser parser)
1267*1230fdc1SLionel Sambuc {
1268*1230fdc1SLionel Sambuc return attInfo;
1269*1230fdc1SLionel Sambuc }
1270*1230fdc1SLionel Sambuc #endif
1271*1230fdc1SLionel Sambuc
1272*1230fdc1SLionel Sambuc void XMLCALL
XML_SetElementHandler(XML_Parser parser,XML_StartElementHandler start,XML_EndElementHandler end)1273*1230fdc1SLionel Sambuc XML_SetElementHandler(XML_Parser parser,
1274*1230fdc1SLionel Sambuc XML_StartElementHandler start,
1275*1230fdc1SLionel Sambuc XML_EndElementHandler end)
1276*1230fdc1SLionel Sambuc {
1277*1230fdc1SLionel Sambuc startElementHandler = start;
1278*1230fdc1SLionel Sambuc endElementHandler = end;
1279*1230fdc1SLionel Sambuc }
1280*1230fdc1SLionel Sambuc
1281*1230fdc1SLionel Sambuc void XMLCALL
XML_SetStartElementHandler(XML_Parser parser,XML_StartElementHandler start)1282*1230fdc1SLionel Sambuc XML_SetStartElementHandler(XML_Parser parser,
1283*1230fdc1SLionel Sambuc XML_StartElementHandler start) {
1284*1230fdc1SLionel Sambuc startElementHandler = start;
1285*1230fdc1SLionel Sambuc }
1286*1230fdc1SLionel Sambuc
1287*1230fdc1SLionel Sambuc void XMLCALL
XML_SetEndElementHandler(XML_Parser parser,XML_EndElementHandler end)1288*1230fdc1SLionel Sambuc XML_SetEndElementHandler(XML_Parser parser,
1289*1230fdc1SLionel Sambuc XML_EndElementHandler end) {
1290*1230fdc1SLionel Sambuc endElementHandler = end;
1291*1230fdc1SLionel Sambuc }
1292*1230fdc1SLionel Sambuc
1293*1230fdc1SLionel Sambuc void XMLCALL
XML_SetCharacterDataHandler(XML_Parser parser,XML_CharacterDataHandler handler)1294*1230fdc1SLionel Sambuc XML_SetCharacterDataHandler(XML_Parser parser,
1295*1230fdc1SLionel Sambuc XML_CharacterDataHandler handler)
1296*1230fdc1SLionel Sambuc {
1297*1230fdc1SLionel Sambuc characterDataHandler = handler;
1298*1230fdc1SLionel Sambuc }
1299*1230fdc1SLionel Sambuc
1300*1230fdc1SLionel Sambuc void XMLCALL
XML_SetProcessingInstructionHandler(XML_Parser parser,XML_ProcessingInstructionHandler handler)1301*1230fdc1SLionel Sambuc XML_SetProcessingInstructionHandler(XML_Parser parser,
1302*1230fdc1SLionel Sambuc XML_ProcessingInstructionHandler handler)
1303*1230fdc1SLionel Sambuc {
1304*1230fdc1SLionel Sambuc processingInstructionHandler = handler;
1305*1230fdc1SLionel Sambuc }
1306*1230fdc1SLionel Sambuc
1307*1230fdc1SLionel Sambuc void XMLCALL
XML_SetCommentHandler(XML_Parser parser,XML_CommentHandler handler)1308*1230fdc1SLionel Sambuc XML_SetCommentHandler(XML_Parser parser,
1309*1230fdc1SLionel Sambuc XML_CommentHandler handler)
1310*1230fdc1SLionel Sambuc {
1311*1230fdc1SLionel Sambuc commentHandler = handler;
1312*1230fdc1SLionel Sambuc }
1313*1230fdc1SLionel Sambuc
1314*1230fdc1SLionel Sambuc void XMLCALL
XML_SetCdataSectionHandler(XML_Parser parser,XML_StartCdataSectionHandler start,XML_EndCdataSectionHandler end)1315*1230fdc1SLionel Sambuc XML_SetCdataSectionHandler(XML_Parser parser,
1316*1230fdc1SLionel Sambuc XML_StartCdataSectionHandler start,
1317*1230fdc1SLionel Sambuc XML_EndCdataSectionHandler end)
1318*1230fdc1SLionel Sambuc {
1319*1230fdc1SLionel Sambuc startCdataSectionHandler = start;
1320*1230fdc1SLionel Sambuc endCdataSectionHandler = end;
1321*1230fdc1SLionel Sambuc }
1322*1230fdc1SLionel Sambuc
1323*1230fdc1SLionel Sambuc void XMLCALL
XML_SetStartCdataSectionHandler(XML_Parser parser,XML_StartCdataSectionHandler start)1324*1230fdc1SLionel Sambuc XML_SetStartCdataSectionHandler(XML_Parser parser,
1325*1230fdc1SLionel Sambuc XML_StartCdataSectionHandler start) {
1326*1230fdc1SLionel Sambuc startCdataSectionHandler = start;
1327*1230fdc1SLionel Sambuc }
1328*1230fdc1SLionel Sambuc
1329*1230fdc1SLionel Sambuc void XMLCALL
XML_SetEndCdataSectionHandler(XML_Parser parser,XML_EndCdataSectionHandler end)1330*1230fdc1SLionel Sambuc XML_SetEndCdataSectionHandler(XML_Parser parser,
1331*1230fdc1SLionel Sambuc XML_EndCdataSectionHandler end) {
1332*1230fdc1SLionel Sambuc endCdataSectionHandler = end;
1333*1230fdc1SLionel Sambuc }
1334*1230fdc1SLionel Sambuc
1335*1230fdc1SLionel Sambuc void XMLCALL
XML_SetDefaultHandler(XML_Parser parser,XML_DefaultHandler handler)1336*1230fdc1SLionel Sambuc XML_SetDefaultHandler(XML_Parser parser,
1337*1230fdc1SLionel Sambuc XML_DefaultHandler handler)
1338*1230fdc1SLionel Sambuc {
1339*1230fdc1SLionel Sambuc defaultHandler = handler;
1340*1230fdc1SLionel Sambuc defaultExpandInternalEntities = XML_FALSE;
1341*1230fdc1SLionel Sambuc }
1342*1230fdc1SLionel Sambuc
1343*1230fdc1SLionel Sambuc void XMLCALL
XML_SetDefaultHandlerExpand(XML_Parser parser,XML_DefaultHandler handler)1344*1230fdc1SLionel Sambuc XML_SetDefaultHandlerExpand(XML_Parser parser,
1345*1230fdc1SLionel Sambuc XML_DefaultHandler handler)
1346*1230fdc1SLionel Sambuc {
1347*1230fdc1SLionel Sambuc defaultHandler = handler;
1348*1230fdc1SLionel Sambuc defaultExpandInternalEntities = XML_TRUE;
1349*1230fdc1SLionel Sambuc }
1350*1230fdc1SLionel Sambuc
1351*1230fdc1SLionel Sambuc void XMLCALL
XML_SetDoctypeDeclHandler(XML_Parser parser,XML_StartDoctypeDeclHandler start,XML_EndDoctypeDeclHandler end)1352*1230fdc1SLionel Sambuc XML_SetDoctypeDeclHandler(XML_Parser parser,
1353*1230fdc1SLionel Sambuc XML_StartDoctypeDeclHandler start,
1354*1230fdc1SLionel Sambuc XML_EndDoctypeDeclHandler end)
1355*1230fdc1SLionel Sambuc {
1356*1230fdc1SLionel Sambuc startDoctypeDeclHandler = start;
1357*1230fdc1SLionel Sambuc endDoctypeDeclHandler = end;
1358*1230fdc1SLionel Sambuc }
1359*1230fdc1SLionel Sambuc
1360*1230fdc1SLionel Sambuc void XMLCALL
XML_SetStartDoctypeDeclHandler(XML_Parser parser,XML_StartDoctypeDeclHandler start)1361*1230fdc1SLionel Sambuc XML_SetStartDoctypeDeclHandler(XML_Parser parser,
1362*1230fdc1SLionel Sambuc XML_StartDoctypeDeclHandler start) {
1363*1230fdc1SLionel Sambuc startDoctypeDeclHandler = start;
1364*1230fdc1SLionel Sambuc }
1365*1230fdc1SLionel Sambuc
1366*1230fdc1SLionel Sambuc void XMLCALL
XML_SetEndDoctypeDeclHandler(XML_Parser parser,XML_EndDoctypeDeclHandler end)1367*1230fdc1SLionel Sambuc XML_SetEndDoctypeDeclHandler(XML_Parser parser,
1368*1230fdc1SLionel Sambuc XML_EndDoctypeDeclHandler end) {
1369*1230fdc1SLionel Sambuc endDoctypeDeclHandler = end;
1370*1230fdc1SLionel Sambuc }
1371*1230fdc1SLionel Sambuc
1372*1230fdc1SLionel Sambuc void XMLCALL
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,XML_UnparsedEntityDeclHandler handler)1373*1230fdc1SLionel Sambuc XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
1374*1230fdc1SLionel Sambuc XML_UnparsedEntityDeclHandler handler)
1375*1230fdc1SLionel Sambuc {
1376*1230fdc1SLionel Sambuc unparsedEntityDeclHandler = handler;
1377*1230fdc1SLionel Sambuc }
1378*1230fdc1SLionel Sambuc
1379*1230fdc1SLionel Sambuc void XMLCALL
XML_SetNotationDeclHandler(XML_Parser parser,XML_NotationDeclHandler handler)1380*1230fdc1SLionel Sambuc XML_SetNotationDeclHandler(XML_Parser parser,
1381*1230fdc1SLionel Sambuc XML_NotationDeclHandler handler)
1382*1230fdc1SLionel Sambuc {
1383*1230fdc1SLionel Sambuc notationDeclHandler = handler;
1384*1230fdc1SLionel Sambuc }
1385*1230fdc1SLionel Sambuc
1386*1230fdc1SLionel Sambuc void XMLCALL
XML_SetNamespaceDeclHandler(XML_Parser parser,XML_StartNamespaceDeclHandler start,XML_EndNamespaceDeclHandler end)1387*1230fdc1SLionel Sambuc XML_SetNamespaceDeclHandler(XML_Parser parser,
1388*1230fdc1SLionel Sambuc XML_StartNamespaceDeclHandler start,
1389*1230fdc1SLionel Sambuc XML_EndNamespaceDeclHandler end)
1390*1230fdc1SLionel Sambuc {
1391*1230fdc1SLionel Sambuc startNamespaceDeclHandler = start;
1392*1230fdc1SLionel Sambuc endNamespaceDeclHandler = end;
1393*1230fdc1SLionel Sambuc }
1394*1230fdc1SLionel Sambuc
1395*1230fdc1SLionel Sambuc void XMLCALL
XML_SetStartNamespaceDeclHandler(XML_Parser parser,XML_StartNamespaceDeclHandler start)1396*1230fdc1SLionel Sambuc XML_SetStartNamespaceDeclHandler(XML_Parser parser,
1397*1230fdc1SLionel Sambuc XML_StartNamespaceDeclHandler start) {
1398*1230fdc1SLionel Sambuc startNamespaceDeclHandler = start;
1399*1230fdc1SLionel Sambuc }
1400*1230fdc1SLionel Sambuc
1401*1230fdc1SLionel Sambuc void XMLCALL
XML_SetEndNamespaceDeclHandler(XML_Parser parser,XML_EndNamespaceDeclHandler end)1402*1230fdc1SLionel Sambuc XML_SetEndNamespaceDeclHandler(XML_Parser parser,
1403*1230fdc1SLionel Sambuc XML_EndNamespaceDeclHandler end) {
1404*1230fdc1SLionel Sambuc endNamespaceDeclHandler = end;
1405*1230fdc1SLionel Sambuc }
1406*1230fdc1SLionel Sambuc
1407*1230fdc1SLionel Sambuc void XMLCALL
XML_SetNotStandaloneHandler(XML_Parser parser,XML_NotStandaloneHandler handler)1408*1230fdc1SLionel Sambuc XML_SetNotStandaloneHandler(XML_Parser parser,
1409*1230fdc1SLionel Sambuc XML_NotStandaloneHandler handler)
1410*1230fdc1SLionel Sambuc {
1411*1230fdc1SLionel Sambuc notStandaloneHandler = handler;
1412*1230fdc1SLionel Sambuc }
1413*1230fdc1SLionel Sambuc
1414*1230fdc1SLionel Sambuc void XMLCALL
XML_SetExternalEntityRefHandler(XML_Parser parser,XML_ExternalEntityRefHandler handler)1415*1230fdc1SLionel Sambuc XML_SetExternalEntityRefHandler(XML_Parser parser,
1416*1230fdc1SLionel Sambuc XML_ExternalEntityRefHandler handler)
1417*1230fdc1SLionel Sambuc {
1418*1230fdc1SLionel Sambuc externalEntityRefHandler = handler;
1419*1230fdc1SLionel Sambuc }
1420*1230fdc1SLionel Sambuc
1421*1230fdc1SLionel Sambuc void XMLCALL
XML_SetExternalEntityRefHandlerArg(XML_Parser parser,void * arg)1422*1230fdc1SLionel Sambuc XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg)
1423*1230fdc1SLionel Sambuc {
1424*1230fdc1SLionel Sambuc if (arg)
1425*1230fdc1SLionel Sambuc externalEntityRefHandlerArg = (XML_Parser)arg;
1426*1230fdc1SLionel Sambuc else
1427*1230fdc1SLionel Sambuc externalEntityRefHandlerArg = parser;
1428*1230fdc1SLionel Sambuc }
1429*1230fdc1SLionel Sambuc
1430*1230fdc1SLionel Sambuc void XMLCALL
XML_SetSkippedEntityHandler(XML_Parser parser,XML_SkippedEntityHandler handler)1431*1230fdc1SLionel Sambuc XML_SetSkippedEntityHandler(XML_Parser parser,
1432*1230fdc1SLionel Sambuc XML_SkippedEntityHandler handler)
1433*1230fdc1SLionel Sambuc {
1434*1230fdc1SLionel Sambuc skippedEntityHandler = handler;
1435*1230fdc1SLionel Sambuc }
1436*1230fdc1SLionel Sambuc
1437*1230fdc1SLionel Sambuc void XMLCALL
XML_SetUnknownEncodingHandler(XML_Parser parser,XML_UnknownEncodingHandler handler,void * data)1438*1230fdc1SLionel Sambuc XML_SetUnknownEncodingHandler(XML_Parser parser,
1439*1230fdc1SLionel Sambuc XML_UnknownEncodingHandler handler,
1440*1230fdc1SLionel Sambuc void *data)
1441*1230fdc1SLionel Sambuc {
1442*1230fdc1SLionel Sambuc unknownEncodingHandler = handler;
1443*1230fdc1SLionel Sambuc unknownEncodingHandlerData = data;
1444*1230fdc1SLionel Sambuc }
1445*1230fdc1SLionel Sambuc
1446*1230fdc1SLionel Sambuc void XMLCALL
XML_SetElementDeclHandler(XML_Parser parser,XML_ElementDeclHandler eldecl)1447*1230fdc1SLionel Sambuc XML_SetElementDeclHandler(XML_Parser parser,
1448*1230fdc1SLionel Sambuc XML_ElementDeclHandler eldecl)
1449*1230fdc1SLionel Sambuc {
1450*1230fdc1SLionel Sambuc elementDeclHandler = eldecl;
1451*1230fdc1SLionel Sambuc }
1452*1230fdc1SLionel Sambuc
1453*1230fdc1SLionel Sambuc void XMLCALL
XML_SetAttlistDeclHandler(XML_Parser parser,XML_AttlistDeclHandler attdecl)1454*1230fdc1SLionel Sambuc XML_SetAttlistDeclHandler(XML_Parser parser,
1455*1230fdc1SLionel Sambuc XML_AttlistDeclHandler attdecl)
1456*1230fdc1SLionel Sambuc {
1457*1230fdc1SLionel Sambuc attlistDeclHandler = attdecl;
1458*1230fdc1SLionel Sambuc }
1459*1230fdc1SLionel Sambuc
1460*1230fdc1SLionel Sambuc void XMLCALL
XML_SetEntityDeclHandler(XML_Parser parser,XML_EntityDeclHandler handler)1461*1230fdc1SLionel Sambuc XML_SetEntityDeclHandler(XML_Parser parser,
1462*1230fdc1SLionel Sambuc XML_EntityDeclHandler handler)
1463*1230fdc1SLionel Sambuc {
1464*1230fdc1SLionel Sambuc entityDeclHandler = handler;
1465*1230fdc1SLionel Sambuc }
1466*1230fdc1SLionel Sambuc
1467*1230fdc1SLionel Sambuc void XMLCALL
XML_SetXmlDeclHandler(XML_Parser parser,XML_XmlDeclHandler handler)1468*1230fdc1SLionel Sambuc XML_SetXmlDeclHandler(XML_Parser parser,
1469*1230fdc1SLionel Sambuc XML_XmlDeclHandler handler) {
1470*1230fdc1SLionel Sambuc xmlDeclHandler = handler;
1471*1230fdc1SLionel Sambuc }
1472*1230fdc1SLionel Sambuc
1473*1230fdc1SLionel Sambuc int XMLCALL
XML_SetParamEntityParsing(XML_Parser parser,enum XML_ParamEntityParsing peParsing)1474*1230fdc1SLionel Sambuc XML_SetParamEntityParsing(XML_Parser parser,
1475*1230fdc1SLionel Sambuc enum XML_ParamEntityParsing peParsing)
1476*1230fdc1SLionel Sambuc {
1477*1230fdc1SLionel Sambuc /* block after XML_Parse()/XML_ParseBuffer() has been called */
1478*1230fdc1SLionel Sambuc if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1479*1230fdc1SLionel Sambuc return 0;
1480*1230fdc1SLionel Sambuc #ifdef XML_DTD
1481*1230fdc1SLionel Sambuc paramEntityParsing = peParsing;
1482*1230fdc1SLionel Sambuc return 1;
1483*1230fdc1SLionel Sambuc #else
1484*1230fdc1SLionel Sambuc return peParsing == XML_PARAM_ENTITY_PARSING_NEVER;
1485*1230fdc1SLionel Sambuc #endif
1486*1230fdc1SLionel Sambuc }
1487*1230fdc1SLionel Sambuc
1488*1230fdc1SLionel Sambuc int XMLCALL
XML_SetHashSalt(XML_Parser parser,unsigned long hash_salt)1489*1230fdc1SLionel Sambuc XML_SetHashSalt(XML_Parser parser,
1490*1230fdc1SLionel Sambuc unsigned long hash_salt)
1491*1230fdc1SLionel Sambuc {
1492*1230fdc1SLionel Sambuc /* block after XML_Parse()/XML_ParseBuffer() has been called */
1493*1230fdc1SLionel Sambuc if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1494*1230fdc1SLionel Sambuc return 0;
1495*1230fdc1SLionel Sambuc hash_secret_salt = hash_salt;
1496*1230fdc1SLionel Sambuc return 1;
1497*1230fdc1SLionel Sambuc }
1498*1230fdc1SLionel Sambuc
1499*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_Parse(XML_Parser parser,const char * s,int len,int isFinal)1500*1230fdc1SLionel Sambuc XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
1501*1230fdc1SLionel Sambuc {
1502*1230fdc1SLionel Sambuc switch (ps_parsing) {
1503*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1504*1230fdc1SLionel Sambuc errorCode = XML_ERROR_SUSPENDED;
1505*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1506*1230fdc1SLionel Sambuc case XML_FINISHED:
1507*1230fdc1SLionel Sambuc errorCode = XML_ERROR_FINISHED;
1508*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1509*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1510*1230fdc1SLionel Sambuc if (parentParser == NULL && !startParsing(parser)) {
1511*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NO_MEMORY;
1512*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1513*1230fdc1SLionel Sambuc }
1514*1230fdc1SLionel Sambuc default:
1515*1230fdc1SLionel Sambuc ps_parsing = XML_PARSING;
1516*1230fdc1SLionel Sambuc }
1517*1230fdc1SLionel Sambuc
1518*1230fdc1SLionel Sambuc if (len == 0) {
1519*1230fdc1SLionel Sambuc ps_finalBuffer = (XML_Bool)isFinal;
1520*1230fdc1SLionel Sambuc if (!isFinal)
1521*1230fdc1SLionel Sambuc return XML_STATUS_OK;
1522*1230fdc1SLionel Sambuc positionPtr = bufferPtr;
1523*1230fdc1SLionel Sambuc parseEndPtr = bufferEnd;
1524*1230fdc1SLionel Sambuc
1525*1230fdc1SLionel Sambuc /* If data are left over from last buffer, and we now know that these
1526*1230fdc1SLionel Sambuc data are the final chunk of input, then we have to check them again
1527*1230fdc1SLionel Sambuc to detect errors based on that fact.
1528*1230fdc1SLionel Sambuc */
1529*1230fdc1SLionel Sambuc errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
1530*1230fdc1SLionel Sambuc
1531*1230fdc1SLionel Sambuc if (errorCode == XML_ERROR_NONE) {
1532*1230fdc1SLionel Sambuc switch (ps_parsing) {
1533*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1534*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1535*1230fdc1SLionel Sambuc positionPtr = bufferPtr;
1536*1230fdc1SLionel Sambuc return XML_STATUS_SUSPENDED;
1537*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1538*1230fdc1SLionel Sambuc case XML_PARSING:
1539*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1540*1230fdc1SLionel Sambuc /* fall through */
1541*1230fdc1SLionel Sambuc default:
1542*1230fdc1SLionel Sambuc return XML_STATUS_OK;
1543*1230fdc1SLionel Sambuc }
1544*1230fdc1SLionel Sambuc }
1545*1230fdc1SLionel Sambuc eventEndPtr = eventPtr;
1546*1230fdc1SLionel Sambuc processor = errorProcessor;
1547*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1548*1230fdc1SLionel Sambuc }
1549*1230fdc1SLionel Sambuc #ifndef XML_CONTEXT_BYTES
1550*1230fdc1SLionel Sambuc else if (bufferPtr == bufferEnd) {
1551*1230fdc1SLionel Sambuc const char *end;
1552*1230fdc1SLionel Sambuc int nLeftOver;
1553*1230fdc1SLionel Sambuc enum XML_Error result;
1554*1230fdc1SLionel Sambuc parseEndByteIndex += len;
1555*1230fdc1SLionel Sambuc positionPtr = s;
1556*1230fdc1SLionel Sambuc ps_finalBuffer = (XML_Bool)isFinal;
1557*1230fdc1SLionel Sambuc
1558*1230fdc1SLionel Sambuc errorCode = processor(parser, s, parseEndPtr = s + len, &end);
1559*1230fdc1SLionel Sambuc
1560*1230fdc1SLionel Sambuc if (errorCode != XML_ERROR_NONE) {
1561*1230fdc1SLionel Sambuc eventEndPtr = eventPtr;
1562*1230fdc1SLionel Sambuc processor = errorProcessor;
1563*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1564*1230fdc1SLionel Sambuc }
1565*1230fdc1SLionel Sambuc else {
1566*1230fdc1SLionel Sambuc switch (ps_parsing) {
1567*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1568*1230fdc1SLionel Sambuc result = XML_STATUS_SUSPENDED;
1569*1230fdc1SLionel Sambuc break;
1570*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1571*1230fdc1SLionel Sambuc case XML_PARSING:
1572*1230fdc1SLionel Sambuc if (isFinal) {
1573*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1574*1230fdc1SLionel Sambuc return XML_STATUS_OK;
1575*1230fdc1SLionel Sambuc }
1576*1230fdc1SLionel Sambuc /* fall through */
1577*1230fdc1SLionel Sambuc default:
1578*1230fdc1SLionel Sambuc result = XML_STATUS_OK;
1579*1230fdc1SLionel Sambuc }
1580*1230fdc1SLionel Sambuc }
1581*1230fdc1SLionel Sambuc
1582*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, end, &position);
1583*1230fdc1SLionel Sambuc nLeftOver = s + len - end;
1584*1230fdc1SLionel Sambuc if (nLeftOver) {
1585*1230fdc1SLionel Sambuc if (buffer == NULL || nLeftOver > bufferLim - buffer) {
1586*1230fdc1SLionel Sambuc /* FIXME avoid integer overflow */
1587*1230fdc1SLionel Sambuc char *temp;
1588*1230fdc1SLionel Sambuc temp = (buffer == NULL
1589*1230fdc1SLionel Sambuc ? (char *)MALLOC(len * 2)
1590*1230fdc1SLionel Sambuc : (char *)REALLOC(buffer, len * 2));
1591*1230fdc1SLionel Sambuc if (temp == NULL) {
1592*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NO_MEMORY;
1593*1230fdc1SLionel Sambuc eventPtr = eventEndPtr = NULL;
1594*1230fdc1SLionel Sambuc processor = errorProcessor;
1595*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1596*1230fdc1SLionel Sambuc }
1597*1230fdc1SLionel Sambuc buffer = temp;
1598*1230fdc1SLionel Sambuc bufferLim = buffer + len * 2;
1599*1230fdc1SLionel Sambuc }
1600*1230fdc1SLionel Sambuc memcpy(buffer, end, nLeftOver);
1601*1230fdc1SLionel Sambuc }
1602*1230fdc1SLionel Sambuc bufferPtr = buffer;
1603*1230fdc1SLionel Sambuc bufferEnd = buffer + nLeftOver;
1604*1230fdc1SLionel Sambuc positionPtr = bufferPtr;
1605*1230fdc1SLionel Sambuc parseEndPtr = bufferEnd;
1606*1230fdc1SLionel Sambuc eventPtr = bufferPtr;
1607*1230fdc1SLionel Sambuc eventEndPtr = bufferPtr;
1608*1230fdc1SLionel Sambuc return result;
1609*1230fdc1SLionel Sambuc }
1610*1230fdc1SLionel Sambuc #endif /* not defined XML_CONTEXT_BYTES */
1611*1230fdc1SLionel Sambuc else {
1612*1230fdc1SLionel Sambuc void *buff = XML_GetBuffer(parser, len);
1613*1230fdc1SLionel Sambuc if (buff == NULL)
1614*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1615*1230fdc1SLionel Sambuc else {
1616*1230fdc1SLionel Sambuc memcpy(buff, s, len);
1617*1230fdc1SLionel Sambuc return XML_ParseBuffer(parser, len, isFinal);
1618*1230fdc1SLionel Sambuc }
1619*1230fdc1SLionel Sambuc }
1620*1230fdc1SLionel Sambuc }
1621*1230fdc1SLionel Sambuc
1622*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_ParseBuffer(XML_Parser parser,int len,int isFinal)1623*1230fdc1SLionel Sambuc XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
1624*1230fdc1SLionel Sambuc {
1625*1230fdc1SLionel Sambuc const char *start;
1626*1230fdc1SLionel Sambuc enum XML_Status result = XML_STATUS_OK;
1627*1230fdc1SLionel Sambuc
1628*1230fdc1SLionel Sambuc switch (ps_parsing) {
1629*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1630*1230fdc1SLionel Sambuc errorCode = XML_ERROR_SUSPENDED;
1631*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1632*1230fdc1SLionel Sambuc case XML_FINISHED:
1633*1230fdc1SLionel Sambuc errorCode = XML_ERROR_FINISHED;
1634*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1635*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1636*1230fdc1SLionel Sambuc if (parentParser == NULL && !startParsing(parser)) {
1637*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NO_MEMORY;
1638*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1639*1230fdc1SLionel Sambuc }
1640*1230fdc1SLionel Sambuc default:
1641*1230fdc1SLionel Sambuc ps_parsing = XML_PARSING;
1642*1230fdc1SLionel Sambuc }
1643*1230fdc1SLionel Sambuc
1644*1230fdc1SLionel Sambuc start = bufferPtr;
1645*1230fdc1SLionel Sambuc positionPtr = start;
1646*1230fdc1SLionel Sambuc bufferEnd += len;
1647*1230fdc1SLionel Sambuc parseEndPtr = bufferEnd;
1648*1230fdc1SLionel Sambuc parseEndByteIndex += len;
1649*1230fdc1SLionel Sambuc ps_finalBuffer = (XML_Bool)isFinal;
1650*1230fdc1SLionel Sambuc
1651*1230fdc1SLionel Sambuc errorCode = processor(parser, start, parseEndPtr, &bufferPtr);
1652*1230fdc1SLionel Sambuc
1653*1230fdc1SLionel Sambuc if (errorCode != XML_ERROR_NONE) {
1654*1230fdc1SLionel Sambuc eventEndPtr = eventPtr;
1655*1230fdc1SLionel Sambuc processor = errorProcessor;
1656*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1657*1230fdc1SLionel Sambuc }
1658*1230fdc1SLionel Sambuc else {
1659*1230fdc1SLionel Sambuc switch (ps_parsing) {
1660*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1661*1230fdc1SLionel Sambuc result = XML_STATUS_SUSPENDED;
1662*1230fdc1SLionel Sambuc break;
1663*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1664*1230fdc1SLionel Sambuc case XML_PARSING:
1665*1230fdc1SLionel Sambuc if (isFinal) {
1666*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1667*1230fdc1SLionel Sambuc return result;
1668*1230fdc1SLionel Sambuc }
1669*1230fdc1SLionel Sambuc default: ; /* should not happen */
1670*1230fdc1SLionel Sambuc }
1671*1230fdc1SLionel Sambuc }
1672*1230fdc1SLionel Sambuc
1673*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1674*1230fdc1SLionel Sambuc positionPtr = bufferPtr;
1675*1230fdc1SLionel Sambuc return result;
1676*1230fdc1SLionel Sambuc }
1677*1230fdc1SLionel Sambuc
1678*1230fdc1SLionel Sambuc void * XMLCALL
XML_GetBuffer(XML_Parser parser,int len)1679*1230fdc1SLionel Sambuc XML_GetBuffer(XML_Parser parser, int len)
1680*1230fdc1SLionel Sambuc {
1681*1230fdc1SLionel Sambuc switch (ps_parsing) {
1682*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1683*1230fdc1SLionel Sambuc errorCode = XML_ERROR_SUSPENDED;
1684*1230fdc1SLionel Sambuc return NULL;
1685*1230fdc1SLionel Sambuc case XML_FINISHED:
1686*1230fdc1SLionel Sambuc errorCode = XML_ERROR_FINISHED;
1687*1230fdc1SLionel Sambuc return NULL;
1688*1230fdc1SLionel Sambuc default: ;
1689*1230fdc1SLionel Sambuc }
1690*1230fdc1SLionel Sambuc
1691*1230fdc1SLionel Sambuc if (len > bufferLim - bufferEnd) {
1692*1230fdc1SLionel Sambuc /* FIXME avoid integer overflow */
1693*1230fdc1SLionel Sambuc int neededSize = len + (int)(bufferEnd - bufferPtr);
1694*1230fdc1SLionel Sambuc #ifdef XML_CONTEXT_BYTES
1695*1230fdc1SLionel Sambuc int keep = (int)(bufferPtr - buffer);
1696*1230fdc1SLionel Sambuc
1697*1230fdc1SLionel Sambuc if (keep > XML_CONTEXT_BYTES)
1698*1230fdc1SLionel Sambuc keep = XML_CONTEXT_BYTES;
1699*1230fdc1SLionel Sambuc neededSize += keep;
1700*1230fdc1SLionel Sambuc #endif /* defined XML_CONTEXT_BYTES */
1701*1230fdc1SLionel Sambuc if (neededSize <= bufferLim - buffer) {
1702*1230fdc1SLionel Sambuc #ifdef XML_CONTEXT_BYTES
1703*1230fdc1SLionel Sambuc if (keep < bufferPtr - buffer) {
1704*1230fdc1SLionel Sambuc int offset = (int)(bufferPtr - buffer) - keep;
1705*1230fdc1SLionel Sambuc memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
1706*1230fdc1SLionel Sambuc bufferEnd -= offset;
1707*1230fdc1SLionel Sambuc bufferPtr -= offset;
1708*1230fdc1SLionel Sambuc }
1709*1230fdc1SLionel Sambuc #else
1710*1230fdc1SLionel Sambuc memmove(buffer, bufferPtr, bufferEnd - bufferPtr);
1711*1230fdc1SLionel Sambuc bufferEnd = buffer + (bufferEnd - bufferPtr);
1712*1230fdc1SLionel Sambuc bufferPtr = buffer;
1713*1230fdc1SLionel Sambuc #endif /* not defined XML_CONTEXT_BYTES */
1714*1230fdc1SLionel Sambuc }
1715*1230fdc1SLionel Sambuc else {
1716*1230fdc1SLionel Sambuc char *newBuf;
1717*1230fdc1SLionel Sambuc int bufferSize = (int)(bufferLim - bufferPtr);
1718*1230fdc1SLionel Sambuc if (bufferSize == 0)
1719*1230fdc1SLionel Sambuc bufferSize = INIT_BUFFER_SIZE;
1720*1230fdc1SLionel Sambuc do {
1721*1230fdc1SLionel Sambuc bufferSize *= 2;
1722*1230fdc1SLionel Sambuc } while (bufferSize < neededSize);
1723*1230fdc1SLionel Sambuc newBuf = (char *)MALLOC(bufferSize);
1724*1230fdc1SLionel Sambuc if (newBuf == 0) {
1725*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NO_MEMORY;
1726*1230fdc1SLionel Sambuc return NULL;
1727*1230fdc1SLionel Sambuc }
1728*1230fdc1SLionel Sambuc bufferLim = newBuf + bufferSize;
1729*1230fdc1SLionel Sambuc #ifdef XML_CONTEXT_BYTES
1730*1230fdc1SLionel Sambuc if (bufferPtr) {
1731*1230fdc1SLionel Sambuc int keep = (int)(bufferPtr - buffer);
1732*1230fdc1SLionel Sambuc if (keep > XML_CONTEXT_BYTES)
1733*1230fdc1SLionel Sambuc keep = XML_CONTEXT_BYTES;
1734*1230fdc1SLionel Sambuc memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep);
1735*1230fdc1SLionel Sambuc FREE(buffer);
1736*1230fdc1SLionel Sambuc buffer = newBuf;
1737*1230fdc1SLionel Sambuc bufferEnd = buffer + (bufferEnd - bufferPtr) + keep;
1738*1230fdc1SLionel Sambuc bufferPtr = buffer + keep;
1739*1230fdc1SLionel Sambuc }
1740*1230fdc1SLionel Sambuc else {
1741*1230fdc1SLionel Sambuc bufferEnd = newBuf + (bufferEnd - bufferPtr);
1742*1230fdc1SLionel Sambuc bufferPtr = buffer = newBuf;
1743*1230fdc1SLionel Sambuc }
1744*1230fdc1SLionel Sambuc #else
1745*1230fdc1SLionel Sambuc if (bufferPtr) {
1746*1230fdc1SLionel Sambuc memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr);
1747*1230fdc1SLionel Sambuc FREE(buffer);
1748*1230fdc1SLionel Sambuc }
1749*1230fdc1SLionel Sambuc bufferEnd = newBuf + (bufferEnd - bufferPtr);
1750*1230fdc1SLionel Sambuc bufferPtr = buffer = newBuf;
1751*1230fdc1SLionel Sambuc #endif /* not defined XML_CONTEXT_BYTES */
1752*1230fdc1SLionel Sambuc }
1753*1230fdc1SLionel Sambuc eventPtr = eventEndPtr = NULL;
1754*1230fdc1SLionel Sambuc positionPtr = NULL;
1755*1230fdc1SLionel Sambuc }
1756*1230fdc1SLionel Sambuc return bufferEnd;
1757*1230fdc1SLionel Sambuc }
1758*1230fdc1SLionel Sambuc
1759*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_StopParser(XML_Parser parser,XML_Bool resumable)1760*1230fdc1SLionel Sambuc XML_StopParser(XML_Parser parser, XML_Bool resumable)
1761*1230fdc1SLionel Sambuc {
1762*1230fdc1SLionel Sambuc switch (ps_parsing) {
1763*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1764*1230fdc1SLionel Sambuc if (resumable) {
1765*1230fdc1SLionel Sambuc errorCode = XML_ERROR_SUSPENDED;
1766*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1767*1230fdc1SLionel Sambuc }
1768*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1769*1230fdc1SLionel Sambuc break;
1770*1230fdc1SLionel Sambuc case XML_FINISHED:
1771*1230fdc1SLionel Sambuc errorCode = XML_ERROR_FINISHED;
1772*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1773*1230fdc1SLionel Sambuc default:
1774*1230fdc1SLionel Sambuc if (resumable) {
1775*1230fdc1SLionel Sambuc #ifdef XML_DTD
1776*1230fdc1SLionel Sambuc if (isParamEntity) {
1777*1230fdc1SLionel Sambuc errorCode = XML_ERROR_SUSPEND_PE;
1778*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1779*1230fdc1SLionel Sambuc }
1780*1230fdc1SLionel Sambuc #endif
1781*1230fdc1SLionel Sambuc ps_parsing = XML_SUSPENDED;
1782*1230fdc1SLionel Sambuc }
1783*1230fdc1SLionel Sambuc else
1784*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1785*1230fdc1SLionel Sambuc }
1786*1230fdc1SLionel Sambuc return XML_STATUS_OK;
1787*1230fdc1SLionel Sambuc }
1788*1230fdc1SLionel Sambuc
1789*1230fdc1SLionel Sambuc enum XML_Status XMLCALL
XML_ResumeParser(XML_Parser parser)1790*1230fdc1SLionel Sambuc XML_ResumeParser(XML_Parser parser)
1791*1230fdc1SLionel Sambuc {
1792*1230fdc1SLionel Sambuc enum XML_Status result = XML_STATUS_OK;
1793*1230fdc1SLionel Sambuc
1794*1230fdc1SLionel Sambuc if (ps_parsing != XML_SUSPENDED) {
1795*1230fdc1SLionel Sambuc errorCode = XML_ERROR_NOT_SUSPENDED;
1796*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1797*1230fdc1SLionel Sambuc }
1798*1230fdc1SLionel Sambuc ps_parsing = XML_PARSING;
1799*1230fdc1SLionel Sambuc
1800*1230fdc1SLionel Sambuc errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
1801*1230fdc1SLionel Sambuc
1802*1230fdc1SLionel Sambuc if (errorCode != XML_ERROR_NONE) {
1803*1230fdc1SLionel Sambuc eventEndPtr = eventPtr;
1804*1230fdc1SLionel Sambuc processor = errorProcessor;
1805*1230fdc1SLionel Sambuc return XML_STATUS_ERROR;
1806*1230fdc1SLionel Sambuc }
1807*1230fdc1SLionel Sambuc else {
1808*1230fdc1SLionel Sambuc switch (ps_parsing) {
1809*1230fdc1SLionel Sambuc case XML_SUSPENDED:
1810*1230fdc1SLionel Sambuc result = XML_STATUS_SUSPENDED;
1811*1230fdc1SLionel Sambuc break;
1812*1230fdc1SLionel Sambuc case XML_INITIALIZED:
1813*1230fdc1SLionel Sambuc case XML_PARSING:
1814*1230fdc1SLionel Sambuc if (ps_finalBuffer) {
1815*1230fdc1SLionel Sambuc ps_parsing = XML_FINISHED;
1816*1230fdc1SLionel Sambuc return result;
1817*1230fdc1SLionel Sambuc }
1818*1230fdc1SLionel Sambuc default: ;
1819*1230fdc1SLionel Sambuc }
1820*1230fdc1SLionel Sambuc }
1821*1230fdc1SLionel Sambuc
1822*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
1823*1230fdc1SLionel Sambuc positionPtr = bufferPtr;
1824*1230fdc1SLionel Sambuc return result;
1825*1230fdc1SLionel Sambuc }
1826*1230fdc1SLionel Sambuc
1827*1230fdc1SLionel Sambuc void XMLCALL
XML_GetParsingStatus(XML_Parser parser,XML_ParsingStatus * status)1828*1230fdc1SLionel Sambuc XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status)
1829*1230fdc1SLionel Sambuc {
1830*1230fdc1SLionel Sambuc assert(status != NULL);
1831*1230fdc1SLionel Sambuc *status = parser->m_parsingStatus;
1832*1230fdc1SLionel Sambuc }
1833*1230fdc1SLionel Sambuc
1834*1230fdc1SLionel Sambuc enum XML_Error XMLCALL
XML_GetErrorCode(XML_Parser parser)1835*1230fdc1SLionel Sambuc XML_GetErrorCode(XML_Parser parser)
1836*1230fdc1SLionel Sambuc {
1837*1230fdc1SLionel Sambuc return errorCode;
1838*1230fdc1SLionel Sambuc }
1839*1230fdc1SLionel Sambuc
1840*1230fdc1SLionel Sambuc XML_Index XMLCALL
XML_GetCurrentByteIndex(XML_Parser parser)1841*1230fdc1SLionel Sambuc XML_GetCurrentByteIndex(XML_Parser parser)
1842*1230fdc1SLionel Sambuc {
1843*1230fdc1SLionel Sambuc if (eventPtr)
1844*1230fdc1SLionel Sambuc return parseEndByteIndex - (parseEndPtr - eventPtr);
1845*1230fdc1SLionel Sambuc return -1;
1846*1230fdc1SLionel Sambuc }
1847*1230fdc1SLionel Sambuc
1848*1230fdc1SLionel Sambuc int XMLCALL
XML_GetCurrentByteCount(XML_Parser parser)1849*1230fdc1SLionel Sambuc XML_GetCurrentByteCount(XML_Parser parser)
1850*1230fdc1SLionel Sambuc {
1851*1230fdc1SLionel Sambuc if (eventEndPtr && eventPtr)
1852*1230fdc1SLionel Sambuc return (int)(eventEndPtr - eventPtr);
1853*1230fdc1SLionel Sambuc return 0;
1854*1230fdc1SLionel Sambuc }
1855*1230fdc1SLionel Sambuc
1856*1230fdc1SLionel Sambuc const char * XMLCALL
XML_GetInputContext(XML_Parser parser,int * offset,int * size)1857*1230fdc1SLionel Sambuc XML_GetInputContext(XML_Parser parser, int *offset, int *size)
1858*1230fdc1SLionel Sambuc {
1859*1230fdc1SLionel Sambuc #ifdef XML_CONTEXT_BYTES
1860*1230fdc1SLionel Sambuc if (eventPtr && buffer) {
1861*1230fdc1SLionel Sambuc *offset = (int)(eventPtr - buffer);
1862*1230fdc1SLionel Sambuc *size = (int)(bufferEnd - buffer);
1863*1230fdc1SLionel Sambuc return buffer;
1864*1230fdc1SLionel Sambuc }
1865*1230fdc1SLionel Sambuc #endif /* defined XML_CONTEXT_BYTES */
1866*1230fdc1SLionel Sambuc return (char *) 0;
1867*1230fdc1SLionel Sambuc }
1868*1230fdc1SLionel Sambuc
1869*1230fdc1SLionel Sambuc XML_Size XMLCALL
XML_GetCurrentLineNumber(XML_Parser parser)1870*1230fdc1SLionel Sambuc XML_GetCurrentLineNumber(XML_Parser parser)
1871*1230fdc1SLionel Sambuc {
1872*1230fdc1SLionel Sambuc if (eventPtr && eventPtr >= positionPtr) {
1873*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
1874*1230fdc1SLionel Sambuc positionPtr = eventPtr;
1875*1230fdc1SLionel Sambuc }
1876*1230fdc1SLionel Sambuc return position.lineNumber + 1;
1877*1230fdc1SLionel Sambuc }
1878*1230fdc1SLionel Sambuc
1879*1230fdc1SLionel Sambuc XML_Size XMLCALL
XML_GetCurrentColumnNumber(XML_Parser parser)1880*1230fdc1SLionel Sambuc XML_GetCurrentColumnNumber(XML_Parser parser)
1881*1230fdc1SLionel Sambuc {
1882*1230fdc1SLionel Sambuc if (eventPtr && eventPtr >= positionPtr) {
1883*1230fdc1SLionel Sambuc XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
1884*1230fdc1SLionel Sambuc positionPtr = eventPtr;
1885*1230fdc1SLionel Sambuc }
1886*1230fdc1SLionel Sambuc return position.columnNumber;
1887*1230fdc1SLionel Sambuc }
1888*1230fdc1SLionel Sambuc
1889*1230fdc1SLionel Sambuc void XMLCALL
XML_FreeContentModel(XML_Parser parser,XML_Content * model)1890*1230fdc1SLionel Sambuc XML_FreeContentModel(XML_Parser parser, XML_Content *model)
1891*1230fdc1SLionel Sambuc {
1892*1230fdc1SLionel Sambuc FREE(model);
1893*1230fdc1SLionel Sambuc }
1894*1230fdc1SLionel Sambuc
1895*1230fdc1SLionel Sambuc void * XMLCALL
XML_MemMalloc(XML_Parser parser,size_t size)1896*1230fdc1SLionel Sambuc XML_MemMalloc(XML_Parser parser, size_t size)
1897*1230fdc1SLionel Sambuc {
1898*1230fdc1SLionel Sambuc return MALLOC(size);
1899*1230fdc1SLionel Sambuc }
1900*1230fdc1SLionel Sambuc
1901*1230fdc1SLionel Sambuc void * XMLCALL
XML_MemRealloc(XML_Parser parser,void * ptr,size_t size)1902*1230fdc1SLionel Sambuc XML_MemRealloc(XML_Parser parser, void *ptr, size_t size)
1903*1230fdc1SLionel Sambuc {
1904*1230fdc1SLionel Sambuc return REALLOC(ptr, size);
1905*1230fdc1SLionel Sambuc }
1906*1230fdc1SLionel Sambuc
1907*1230fdc1SLionel Sambuc void XMLCALL
XML_MemFree(XML_Parser parser,void * ptr)1908*1230fdc1SLionel Sambuc XML_MemFree(XML_Parser parser, void *ptr)
1909*1230fdc1SLionel Sambuc {
1910*1230fdc1SLionel Sambuc FREE(ptr);
1911*1230fdc1SLionel Sambuc }
1912*1230fdc1SLionel Sambuc
1913*1230fdc1SLionel Sambuc void XMLCALL
XML_DefaultCurrent(XML_Parser parser)1914*1230fdc1SLionel Sambuc XML_DefaultCurrent(XML_Parser parser)
1915*1230fdc1SLionel Sambuc {
1916*1230fdc1SLionel Sambuc if (defaultHandler) {
1917*1230fdc1SLionel Sambuc if (openInternalEntities)
1918*1230fdc1SLionel Sambuc reportDefault(parser,
1919*1230fdc1SLionel Sambuc internalEncoding,
1920*1230fdc1SLionel Sambuc openInternalEntities->internalEventPtr,
1921*1230fdc1SLionel Sambuc openInternalEntities->internalEventEndPtr);
1922*1230fdc1SLionel Sambuc else
1923*1230fdc1SLionel Sambuc reportDefault(parser, encoding, eventPtr, eventEndPtr);
1924*1230fdc1SLionel Sambuc }
1925*1230fdc1SLionel Sambuc }
1926*1230fdc1SLionel Sambuc
1927*1230fdc1SLionel Sambuc const XML_LChar * XMLCALL
XML_ErrorString(enum XML_Error code)1928*1230fdc1SLionel Sambuc XML_ErrorString(enum XML_Error code)
1929*1230fdc1SLionel Sambuc {
1930*1230fdc1SLionel Sambuc static const XML_LChar* const message[] = {
1931*1230fdc1SLionel Sambuc 0,
1932*1230fdc1SLionel Sambuc XML_L("out of memory"),
1933*1230fdc1SLionel Sambuc XML_L("syntax error"),
1934*1230fdc1SLionel Sambuc XML_L("no element found"),
1935*1230fdc1SLionel Sambuc XML_L("not well-formed (invalid token)"),
1936*1230fdc1SLionel Sambuc XML_L("unclosed token"),
1937*1230fdc1SLionel Sambuc XML_L("partial character"),
1938*1230fdc1SLionel Sambuc XML_L("mismatched tag"),
1939*1230fdc1SLionel Sambuc XML_L("duplicate attribute"),
1940*1230fdc1SLionel Sambuc XML_L("junk after document element"),
1941*1230fdc1SLionel Sambuc XML_L("illegal parameter entity reference"),
1942*1230fdc1SLionel Sambuc XML_L("undefined entity"),
1943*1230fdc1SLionel Sambuc XML_L("recursive entity reference"),
1944*1230fdc1SLionel Sambuc XML_L("asynchronous entity"),
1945*1230fdc1SLionel Sambuc XML_L("reference to invalid character number"),
1946*1230fdc1SLionel Sambuc XML_L("reference to binary entity"),
1947*1230fdc1SLionel Sambuc XML_L("reference to external entity in attribute"),
1948*1230fdc1SLionel Sambuc XML_L("XML or text declaration not at start of entity"),
1949*1230fdc1SLionel Sambuc XML_L("unknown encoding"),
1950*1230fdc1SLionel Sambuc XML_L("encoding specified in XML declaration is incorrect"),
1951*1230fdc1SLionel Sambuc XML_L("unclosed CDATA section"),
1952*1230fdc1SLionel Sambuc XML_L("error in processing external entity reference"),
1953*1230fdc1SLionel Sambuc XML_L("document is not standalone"),
1954*1230fdc1SLionel Sambuc XML_L("unexpected parser state - please send a bug report"),
1955*1230fdc1SLionel Sambuc XML_L("entity declared in parameter entity"),
1956*1230fdc1SLionel Sambuc XML_L("requested feature requires XML_DTD support in Expat"),
1957*1230fdc1SLionel Sambuc XML_L("cannot change setting once parsing has begun"),
1958*1230fdc1SLionel Sambuc XML_L("unbound prefix"),
1959*1230fdc1SLionel Sambuc XML_L("must not undeclare prefix"),
1960*1230fdc1SLionel Sambuc XML_L("incomplete markup in parameter entity"),
1961*1230fdc1SLionel Sambuc XML_L("XML declaration not well-formed"),
1962*1230fdc1SLionel Sambuc XML_L("text declaration not well-formed"),
1963*1230fdc1SLionel Sambuc XML_L("illegal character(s) in public id"),
1964*1230fdc1SLionel Sambuc XML_L("parser suspended"),
1965*1230fdc1SLionel Sambuc XML_L("parser not suspended"),
1966*1230fdc1SLionel Sambuc XML_L("parsing aborted"),
1967*1230fdc1SLionel Sambuc XML_L("parsing finished"),
1968*1230fdc1SLionel Sambuc XML_L("cannot suspend in external parameter entity"),
1969*1230fdc1SLionel Sambuc XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"),
1970*1230fdc1SLionel Sambuc XML_L("reserved prefix (xmlns) must not be declared or undeclared"),
1971*1230fdc1SLionel Sambuc XML_L("prefix must not be bound to one of the reserved namespace names")
1972*1230fdc1SLionel Sambuc };
1973*1230fdc1SLionel Sambuc if (code > 0 && code < sizeof(message)/sizeof(message[0]))
1974*1230fdc1SLionel Sambuc return message[code];
1975*1230fdc1SLionel Sambuc return NULL;
1976*1230fdc1SLionel Sambuc }
1977*1230fdc1SLionel Sambuc
1978*1230fdc1SLionel Sambuc const XML_LChar * XMLCALL
XML_ExpatVersion(void)1979*1230fdc1SLionel Sambuc XML_ExpatVersion(void) {
1980*1230fdc1SLionel Sambuc
1981*1230fdc1SLionel Sambuc /* V1 is used to string-ize the version number. However, it would
1982*1230fdc1SLionel Sambuc string-ize the actual version macro *names* unless we get them
1983*1230fdc1SLionel Sambuc substituted before being passed to V1. CPP is defined to expand
1984*1230fdc1SLionel Sambuc a macro, then rescan for more expansions. Thus, we use V2 to expand
1985*1230fdc1SLionel Sambuc the version macros, then CPP will expand the resulting V1() macro
1986*1230fdc1SLionel Sambuc with the correct numerals. */
1987*1230fdc1SLionel Sambuc /* ### I'm assuming cpp is portable in this respect... */
1988*1230fdc1SLionel Sambuc
1989*1230fdc1SLionel Sambuc #define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c)
1990*1230fdc1SLionel Sambuc #define V2(a,b,c) XML_L("expat_")V1(a,b,c)
1991*1230fdc1SLionel Sambuc
1992*1230fdc1SLionel Sambuc return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION);
1993*1230fdc1SLionel Sambuc
1994*1230fdc1SLionel Sambuc #undef V1
1995*1230fdc1SLionel Sambuc #undef V2
1996*1230fdc1SLionel Sambuc }
1997*1230fdc1SLionel Sambuc
1998*1230fdc1SLionel Sambuc XML_Expat_Version XMLCALL
XML_ExpatVersionInfo(void)1999*1230fdc1SLionel Sambuc XML_ExpatVersionInfo(void)
2000*1230fdc1SLionel Sambuc {
2001*1230fdc1SLionel Sambuc XML_Expat_Version version;
2002*1230fdc1SLionel Sambuc
2003*1230fdc1SLionel Sambuc version.major = XML_MAJOR_VERSION;
2004*1230fdc1SLionel Sambuc version.minor = XML_MINOR_VERSION;
2005*1230fdc1SLionel Sambuc version.micro = XML_MICRO_VERSION;
2006*1230fdc1SLionel Sambuc
2007*1230fdc1SLionel Sambuc return version;
2008*1230fdc1SLionel Sambuc }
2009*1230fdc1SLionel Sambuc
2010*1230fdc1SLionel Sambuc const XML_Feature * XMLCALL
XML_GetFeatureList(void)2011*1230fdc1SLionel Sambuc XML_GetFeatureList(void)
2012*1230fdc1SLionel Sambuc {
2013*1230fdc1SLionel Sambuc static const XML_Feature features[] = {
2014*1230fdc1SLionel Sambuc {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"),
2015*1230fdc1SLionel Sambuc sizeof(XML_Char)},
2016*1230fdc1SLionel Sambuc {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"),
2017*1230fdc1SLionel Sambuc sizeof(XML_LChar)},
2018*1230fdc1SLionel Sambuc #ifdef XML_UNICODE
2019*1230fdc1SLionel Sambuc {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0},
2020*1230fdc1SLionel Sambuc #endif
2021*1230fdc1SLionel Sambuc #ifdef XML_UNICODE_WCHAR_T
2022*1230fdc1SLionel Sambuc {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0},
2023*1230fdc1SLionel Sambuc #endif
2024*1230fdc1SLionel Sambuc #ifdef XML_DTD
2025*1230fdc1SLionel Sambuc {XML_FEATURE_DTD, XML_L("XML_DTD"), 0},
2026*1230fdc1SLionel Sambuc #endif
2027*1230fdc1SLionel Sambuc #ifdef XML_CONTEXT_BYTES
2028*1230fdc1SLionel Sambuc {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"),
2029*1230fdc1SLionel Sambuc XML_CONTEXT_BYTES},
2030*1230fdc1SLionel Sambuc #endif
2031*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
2032*1230fdc1SLionel Sambuc {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0},
2033*1230fdc1SLionel Sambuc #endif
2034*1230fdc1SLionel Sambuc #ifdef XML_NS
2035*1230fdc1SLionel Sambuc {XML_FEATURE_NS, XML_L("XML_NS"), 0},
2036*1230fdc1SLionel Sambuc #endif
2037*1230fdc1SLionel Sambuc #ifdef XML_LARGE_SIZE
2038*1230fdc1SLionel Sambuc {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0},
2039*1230fdc1SLionel Sambuc #endif
2040*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
2041*1230fdc1SLionel Sambuc {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0},
2042*1230fdc1SLionel Sambuc #endif
2043*1230fdc1SLionel Sambuc {XML_FEATURE_END, NULL, 0}
2044*1230fdc1SLionel Sambuc };
2045*1230fdc1SLionel Sambuc
2046*1230fdc1SLionel Sambuc return features;
2047*1230fdc1SLionel Sambuc }
2048*1230fdc1SLionel Sambuc
2049*1230fdc1SLionel Sambuc /* Initially tag->rawName always points into the parse buffer;
2050*1230fdc1SLionel Sambuc for those TAG instances opened while the current parse buffer was
2051*1230fdc1SLionel Sambuc processed, and not yet closed, we need to store tag->rawName in a more
2052*1230fdc1SLionel Sambuc permanent location, since the parse buffer is about to be discarded.
2053*1230fdc1SLionel Sambuc */
2054*1230fdc1SLionel Sambuc static XML_Bool
storeRawNames(XML_Parser parser)2055*1230fdc1SLionel Sambuc storeRawNames(XML_Parser parser)
2056*1230fdc1SLionel Sambuc {
2057*1230fdc1SLionel Sambuc TAG *tag = tagStack;
2058*1230fdc1SLionel Sambuc while (tag) {
2059*1230fdc1SLionel Sambuc int bufSize;
2060*1230fdc1SLionel Sambuc int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);
2061*1230fdc1SLionel Sambuc char *rawNameBuf = tag->buf + nameLen;
2062*1230fdc1SLionel Sambuc /* Stop if already stored. Since tagStack is a stack, we can stop
2063*1230fdc1SLionel Sambuc at the first entry that has already been copied; everything
2064*1230fdc1SLionel Sambuc below it in the stack is already been accounted for in a
2065*1230fdc1SLionel Sambuc previous call to this function.
2066*1230fdc1SLionel Sambuc */
2067*1230fdc1SLionel Sambuc if (tag->rawName == rawNameBuf)
2068*1230fdc1SLionel Sambuc break;
2069*1230fdc1SLionel Sambuc /* For re-use purposes we need to ensure that the
2070*1230fdc1SLionel Sambuc size of tag->buf is a multiple of sizeof(XML_Char).
2071*1230fdc1SLionel Sambuc */
2072*1230fdc1SLionel Sambuc bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
2073*1230fdc1SLionel Sambuc if (bufSize > tag->bufEnd - tag->buf) {
2074*1230fdc1SLionel Sambuc char *temp = (char *)REALLOC(tag->buf, bufSize);
2075*1230fdc1SLionel Sambuc if (temp == NULL)
2076*1230fdc1SLionel Sambuc return XML_FALSE;
2077*1230fdc1SLionel Sambuc /* if tag->name.str points to tag->buf (only when namespace
2078*1230fdc1SLionel Sambuc processing is off) then we have to update it
2079*1230fdc1SLionel Sambuc */
2080*1230fdc1SLionel Sambuc if (tag->name.str == (XML_Char *)tag->buf)
2081*1230fdc1SLionel Sambuc tag->name.str = (XML_Char *)temp;
2082*1230fdc1SLionel Sambuc /* if tag->name.localPart is set (when namespace processing is on)
2083*1230fdc1SLionel Sambuc then update it as well, since it will always point into tag->buf
2084*1230fdc1SLionel Sambuc */
2085*1230fdc1SLionel Sambuc if (tag->name.localPart)
2086*1230fdc1SLionel Sambuc tag->name.localPart = (XML_Char *)temp + (tag->name.localPart -
2087*1230fdc1SLionel Sambuc (XML_Char *)tag->buf);
2088*1230fdc1SLionel Sambuc tag->buf = temp;
2089*1230fdc1SLionel Sambuc tag->bufEnd = temp + bufSize;
2090*1230fdc1SLionel Sambuc rawNameBuf = temp + nameLen;
2091*1230fdc1SLionel Sambuc }
2092*1230fdc1SLionel Sambuc memcpy(rawNameBuf, tag->rawName, tag->rawNameLength);
2093*1230fdc1SLionel Sambuc tag->rawName = rawNameBuf;
2094*1230fdc1SLionel Sambuc tag = tag->parent;
2095*1230fdc1SLionel Sambuc }
2096*1230fdc1SLionel Sambuc return XML_TRUE;
2097*1230fdc1SLionel Sambuc }
2098*1230fdc1SLionel Sambuc
2099*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
contentProcessor(XML_Parser parser,const char * start,const char * end,const char ** endPtr)2100*1230fdc1SLionel Sambuc contentProcessor(XML_Parser parser,
2101*1230fdc1SLionel Sambuc const char *start,
2102*1230fdc1SLionel Sambuc const char *end,
2103*1230fdc1SLionel Sambuc const char **endPtr)
2104*1230fdc1SLionel Sambuc {
2105*1230fdc1SLionel Sambuc enum XML_Error result = doContent(parser, 0, encoding, start, end,
2106*1230fdc1SLionel Sambuc endPtr, (XML_Bool)!ps_finalBuffer);
2107*1230fdc1SLionel Sambuc if (result == XML_ERROR_NONE) {
2108*1230fdc1SLionel Sambuc if (!storeRawNames(parser))
2109*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2110*1230fdc1SLionel Sambuc }
2111*1230fdc1SLionel Sambuc return result;
2112*1230fdc1SLionel Sambuc }
2113*1230fdc1SLionel Sambuc
2114*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalEntityInitProcessor(XML_Parser parser,const char * start,const char * end,const char ** endPtr)2115*1230fdc1SLionel Sambuc externalEntityInitProcessor(XML_Parser parser,
2116*1230fdc1SLionel Sambuc const char *start,
2117*1230fdc1SLionel Sambuc const char *end,
2118*1230fdc1SLionel Sambuc const char **endPtr)
2119*1230fdc1SLionel Sambuc {
2120*1230fdc1SLionel Sambuc enum XML_Error result = initializeEncoding(parser);
2121*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
2122*1230fdc1SLionel Sambuc return result;
2123*1230fdc1SLionel Sambuc processor = externalEntityInitProcessor2;
2124*1230fdc1SLionel Sambuc return externalEntityInitProcessor2(parser, start, end, endPtr);
2125*1230fdc1SLionel Sambuc }
2126*1230fdc1SLionel Sambuc
2127*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalEntityInitProcessor2(XML_Parser parser,const char * start,const char * end,const char ** endPtr)2128*1230fdc1SLionel Sambuc externalEntityInitProcessor2(XML_Parser parser,
2129*1230fdc1SLionel Sambuc const char *start,
2130*1230fdc1SLionel Sambuc const char *end,
2131*1230fdc1SLionel Sambuc const char **endPtr)
2132*1230fdc1SLionel Sambuc {
2133*1230fdc1SLionel Sambuc const char *next = start; /* XmlContentTok doesn't always set the last arg */
2134*1230fdc1SLionel Sambuc int tok = XmlContentTok(encoding, start, end, &next);
2135*1230fdc1SLionel Sambuc switch (tok) {
2136*1230fdc1SLionel Sambuc case XML_TOK_BOM:
2137*1230fdc1SLionel Sambuc /* If we are at the end of the buffer, this would cause the next stage,
2138*1230fdc1SLionel Sambuc i.e. externalEntityInitProcessor3, to pass control directly to
2139*1230fdc1SLionel Sambuc doContent (by detecting XML_TOK_NONE) without processing any xml text
2140*1230fdc1SLionel Sambuc declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent.
2141*1230fdc1SLionel Sambuc */
2142*1230fdc1SLionel Sambuc if (next == end && !ps_finalBuffer) {
2143*1230fdc1SLionel Sambuc *endPtr = next;
2144*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2145*1230fdc1SLionel Sambuc }
2146*1230fdc1SLionel Sambuc start = next;
2147*1230fdc1SLionel Sambuc break;
2148*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
2149*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
2150*1230fdc1SLionel Sambuc *endPtr = start;
2151*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2152*1230fdc1SLionel Sambuc }
2153*1230fdc1SLionel Sambuc eventPtr = start;
2154*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
2155*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
2156*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
2157*1230fdc1SLionel Sambuc *endPtr = start;
2158*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2159*1230fdc1SLionel Sambuc }
2160*1230fdc1SLionel Sambuc eventPtr = start;
2161*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
2162*1230fdc1SLionel Sambuc }
2163*1230fdc1SLionel Sambuc processor = externalEntityInitProcessor3;
2164*1230fdc1SLionel Sambuc return externalEntityInitProcessor3(parser, start, end, endPtr);
2165*1230fdc1SLionel Sambuc }
2166*1230fdc1SLionel Sambuc
2167*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalEntityInitProcessor3(XML_Parser parser,const char * start,const char * end,const char ** endPtr)2168*1230fdc1SLionel Sambuc externalEntityInitProcessor3(XML_Parser parser,
2169*1230fdc1SLionel Sambuc const char *start,
2170*1230fdc1SLionel Sambuc const char *end,
2171*1230fdc1SLionel Sambuc const char **endPtr)
2172*1230fdc1SLionel Sambuc {
2173*1230fdc1SLionel Sambuc int tok;
2174*1230fdc1SLionel Sambuc const char *next = start; /* XmlContentTok doesn't always set the last arg */
2175*1230fdc1SLionel Sambuc eventPtr = start;
2176*1230fdc1SLionel Sambuc tok = XmlContentTok(encoding, start, end, &next);
2177*1230fdc1SLionel Sambuc eventEndPtr = next;
2178*1230fdc1SLionel Sambuc
2179*1230fdc1SLionel Sambuc switch (tok) {
2180*1230fdc1SLionel Sambuc case XML_TOK_XML_DECL:
2181*1230fdc1SLionel Sambuc {
2182*1230fdc1SLionel Sambuc enum XML_Error result;
2183*1230fdc1SLionel Sambuc result = processXmlDecl(parser, 1, start, next);
2184*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
2185*1230fdc1SLionel Sambuc return result;
2186*1230fdc1SLionel Sambuc switch (ps_parsing) {
2187*1230fdc1SLionel Sambuc case XML_SUSPENDED:
2188*1230fdc1SLionel Sambuc *endPtr = next;
2189*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2190*1230fdc1SLionel Sambuc case XML_FINISHED:
2191*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
2192*1230fdc1SLionel Sambuc default:
2193*1230fdc1SLionel Sambuc start = next;
2194*1230fdc1SLionel Sambuc }
2195*1230fdc1SLionel Sambuc }
2196*1230fdc1SLionel Sambuc break;
2197*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
2198*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
2199*1230fdc1SLionel Sambuc *endPtr = start;
2200*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2201*1230fdc1SLionel Sambuc }
2202*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
2203*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
2204*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
2205*1230fdc1SLionel Sambuc *endPtr = start;
2206*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2207*1230fdc1SLionel Sambuc }
2208*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
2209*1230fdc1SLionel Sambuc }
2210*1230fdc1SLionel Sambuc processor = externalEntityContentProcessor;
2211*1230fdc1SLionel Sambuc tagLevel = 1;
2212*1230fdc1SLionel Sambuc return externalEntityContentProcessor(parser, start, end, endPtr);
2213*1230fdc1SLionel Sambuc }
2214*1230fdc1SLionel Sambuc
2215*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalEntityContentProcessor(XML_Parser parser,const char * start,const char * end,const char ** endPtr)2216*1230fdc1SLionel Sambuc externalEntityContentProcessor(XML_Parser parser,
2217*1230fdc1SLionel Sambuc const char *start,
2218*1230fdc1SLionel Sambuc const char *end,
2219*1230fdc1SLionel Sambuc const char **endPtr)
2220*1230fdc1SLionel Sambuc {
2221*1230fdc1SLionel Sambuc enum XML_Error result = doContent(parser, 1, encoding, start, end,
2222*1230fdc1SLionel Sambuc endPtr, (XML_Bool)!ps_finalBuffer);
2223*1230fdc1SLionel Sambuc if (result == XML_ERROR_NONE) {
2224*1230fdc1SLionel Sambuc if (!storeRawNames(parser))
2225*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2226*1230fdc1SLionel Sambuc }
2227*1230fdc1SLionel Sambuc return result;
2228*1230fdc1SLionel Sambuc }
2229*1230fdc1SLionel Sambuc
2230*1230fdc1SLionel Sambuc static enum XML_Error
doContent(XML_Parser parser,int startTagLevel,const ENCODING * enc,const char * s,const char * end,const char ** nextPtr,XML_Bool haveMore)2231*1230fdc1SLionel Sambuc doContent(XML_Parser parser,
2232*1230fdc1SLionel Sambuc int startTagLevel,
2233*1230fdc1SLionel Sambuc const ENCODING *enc,
2234*1230fdc1SLionel Sambuc const char *s,
2235*1230fdc1SLionel Sambuc const char *end,
2236*1230fdc1SLionel Sambuc const char **nextPtr,
2237*1230fdc1SLionel Sambuc XML_Bool haveMore)
2238*1230fdc1SLionel Sambuc {
2239*1230fdc1SLionel Sambuc /* save one level of indirection */
2240*1230fdc1SLionel Sambuc DTD * const dtd = _dtd;
2241*1230fdc1SLionel Sambuc
2242*1230fdc1SLionel Sambuc const char **eventPP;
2243*1230fdc1SLionel Sambuc const char **eventEndPP;
2244*1230fdc1SLionel Sambuc if (enc == encoding) {
2245*1230fdc1SLionel Sambuc eventPP = &eventPtr;
2246*1230fdc1SLionel Sambuc eventEndPP = &eventEndPtr;
2247*1230fdc1SLionel Sambuc }
2248*1230fdc1SLionel Sambuc else {
2249*1230fdc1SLionel Sambuc eventPP = &(openInternalEntities->internalEventPtr);
2250*1230fdc1SLionel Sambuc eventEndPP = &(openInternalEntities->internalEventEndPtr);
2251*1230fdc1SLionel Sambuc }
2252*1230fdc1SLionel Sambuc *eventPP = s;
2253*1230fdc1SLionel Sambuc
2254*1230fdc1SLionel Sambuc for (;;) {
2255*1230fdc1SLionel Sambuc const char *next = s; /* XmlContentTok doesn't always set the last arg */
2256*1230fdc1SLionel Sambuc int tok = XmlContentTok(enc, s, end, &next);
2257*1230fdc1SLionel Sambuc *eventEndPP = next;
2258*1230fdc1SLionel Sambuc switch (tok) {
2259*1230fdc1SLionel Sambuc case XML_TOK_TRAILING_CR:
2260*1230fdc1SLionel Sambuc if (haveMore) {
2261*1230fdc1SLionel Sambuc *nextPtr = s;
2262*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2263*1230fdc1SLionel Sambuc }
2264*1230fdc1SLionel Sambuc *eventEndPP = end;
2265*1230fdc1SLionel Sambuc if (characterDataHandler) {
2266*1230fdc1SLionel Sambuc XML_Char c = 0xA;
2267*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, &c, 1);
2268*1230fdc1SLionel Sambuc }
2269*1230fdc1SLionel Sambuc else if (defaultHandler)
2270*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, end);
2271*1230fdc1SLionel Sambuc /* We are at the end of the final buffer, should we check for
2272*1230fdc1SLionel Sambuc XML_SUSPENDED, XML_FINISHED?
2273*1230fdc1SLionel Sambuc */
2274*1230fdc1SLionel Sambuc if (startTagLevel == 0)
2275*1230fdc1SLionel Sambuc return XML_ERROR_NO_ELEMENTS;
2276*1230fdc1SLionel Sambuc if (tagLevel != startTagLevel)
2277*1230fdc1SLionel Sambuc return XML_ERROR_ASYNC_ENTITY;
2278*1230fdc1SLionel Sambuc *nextPtr = end;
2279*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2280*1230fdc1SLionel Sambuc case XML_TOK_NONE:
2281*1230fdc1SLionel Sambuc if (haveMore) {
2282*1230fdc1SLionel Sambuc *nextPtr = s;
2283*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2284*1230fdc1SLionel Sambuc }
2285*1230fdc1SLionel Sambuc if (startTagLevel > 0) {
2286*1230fdc1SLionel Sambuc if (tagLevel != startTagLevel)
2287*1230fdc1SLionel Sambuc return XML_ERROR_ASYNC_ENTITY;
2288*1230fdc1SLionel Sambuc *nextPtr = s;
2289*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2290*1230fdc1SLionel Sambuc }
2291*1230fdc1SLionel Sambuc return XML_ERROR_NO_ELEMENTS;
2292*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
2293*1230fdc1SLionel Sambuc *eventPP = next;
2294*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
2295*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
2296*1230fdc1SLionel Sambuc if (haveMore) {
2297*1230fdc1SLionel Sambuc *nextPtr = s;
2298*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2299*1230fdc1SLionel Sambuc }
2300*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
2301*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
2302*1230fdc1SLionel Sambuc if (haveMore) {
2303*1230fdc1SLionel Sambuc *nextPtr = s;
2304*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2305*1230fdc1SLionel Sambuc }
2306*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
2307*1230fdc1SLionel Sambuc case XML_TOK_ENTITY_REF:
2308*1230fdc1SLionel Sambuc {
2309*1230fdc1SLionel Sambuc const XML_Char *name;
2310*1230fdc1SLionel Sambuc ENTITY *entity;
2311*1230fdc1SLionel Sambuc XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc,
2312*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
2313*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
2314*1230fdc1SLionel Sambuc if (ch) {
2315*1230fdc1SLionel Sambuc if (characterDataHandler)
2316*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, &ch, 1);
2317*1230fdc1SLionel Sambuc else if (defaultHandler)
2318*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2319*1230fdc1SLionel Sambuc break;
2320*1230fdc1SLionel Sambuc }
2321*1230fdc1SLionel Sambuc name = poolStoreString(&dtd->pool, enc,
2322*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
2323*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
2324*1230fdc1SLionel Sambuc if (!name)
2325*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2326*1230fdc1SLionel Sambuc entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
2327*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
2328*1230fdc1SLionel Sambuc /* First, determine if a check for an existing declaration is needed;
2329*1230fdc1SLionel Sambuc if yes, check that the entity exists, and that it is internal,
2330*1230fdc1SLionel Sambuc otherwise call the skipped entity or default handler.
2331*1230fdc1SLionel Sambuc */
2332*1230fdc1SLionel Sambuc if (!dtd->hasParamEntityRefs || dtd->standalone) {
2333*1230fdc1SLionel Sambuc if (!entity)
2334*1230fdc1SLionel Sambuc return XML_ERROR_UNDEFINED_ENTITY;
2335*1230fdc1SLionel Sambuc else if (!entity->is_internal)
2336*1230fdc1SLionel Sambuc return XML_ERROR_ENTITY_DECLARED_IN_PE;
2337*1230fdc1SLionel Sambuc }
2338*1230fdc1SLionel Sambuc else if (!entity) {
2339*1230fdc1SLionel Sambuc if (skippedEntityHandler)
2340*1230fdc1SLionel Sambuc skippedEntityHandler(handlerArg, name, 0);
2341*1230fdc1SLionel Sambuc else if (defaultHandler)
2342*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2343*1230fdc1SLionel Sambuc break;
2344*1230fdc1SLionel Sambuc }
2345*1230fdc1SLionel Sambuc if (entity->open)
2346*1230fdc1SLionel Sambuc return XML_ERROR_RECURSIVE_ENTITY_REF;
2347*1230fdc1SLionel Sambuc if (entity->notation)
2348*1230fdc1SLionel Sambuc return XML_ERROR_BINARY_ENTITY_REF;
2349*1230fdc1SLionel Sambuc if (entity->textPtr) {
2350*1230fdc1SLionel Sambuc enum XML_Error result;
2351*1230fdc1SLionel Sambuc if (!defaultExpandInternalEntities) {
2352*1230fdc1SLionel Sambuc if (skippedEntityHandler)
2353*1230fdc1SLionel Sambuc skippedEntityHandler(handlerArg, entity->name, 0);
2354*1230fdc1SLionel Sambuc else if (defaultHandler)
2355*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2356*1230fdc1SLionel Sambuc break;
2357*1230fdc1SLionel Sambuc }
2358*1230fdc1SLionel Sambuc result = processInternalEntity(parser, entity, XML_FALSE);
2359*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
2360*1230fdc1SLionel Sambuc return result;
2361*1230fdc1SLionel Sambuc }
2362*1230fdc1SLionel Sambuc else if (externalEntityRefHandler) {
2363*1230fdc1SLionel Sambuc const XML_Char *context;
2364*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
2365*1230fdc1SLionel Sambuc context = getContext(parser);
2366*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
2367*1230fdc1SLionel Sambuc if (!context)
2368*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2369*1230fdc1SLionel Sambuc if (!externalEntityRefHandler(externalEntityRefHandlerArg,
2370*1230fdc1SLionel Sambuc context,
2371*1230fdc1SLionel Sambuc entity->base,
2372*1230fdc1SLionel Sambuc entity->systemId,
2373*1230fdc1SLionel Sambuc entity->publicId))
2374*1230fdc1SLionel Sambuc return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
2375*1230fdc1SLionel Sambuc poolDiscard(&tempPool);
2376*1230fdc1SLionel Sambuc }
2377*1230fdc1SLionel Sambuc else if (defaultHandler)
2378*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2379*1230fdc1SLionel Sambuc break;
2380*1230fdc1SLionel Sambuc }
2381*1230fdc1SLionel Sambuc case XML_TOK_START_TAG_NO_ATTS:
2382*1230fdc1SLionel Sambuc /* fall through */
2383*1230fdc1SLionel Sambuc case XML_TOK_START_TAG_WITH_ATTS:
2384*1230fdc1SLionel Sambuc {
2385*1230fdc1SLionel Sambuc TAG *tag;
2386*1230fdc1SLionel Sambuc enum XML_Error result;
2387*1230fdc1SLionel Sambuc XML_Char *toPtr;
2388*1230fdc1SLionel Sambuc if (freeTagList) {
2389*1230fdc1SLionel Sambuc tag = freeTagList;
2390*1230fdc1SLionel Sambuc freeTagList = freeTagList->parent;
2391*1230fdc1SLionel Sambuc }
2392*1230fdc1SLionel Sambuc else {
2393*1230fdc1SLionel Sambuc tag = (TAG *)MALLOC(sizeof(TAG));
2394*1230fdc1SLionel Sambuc if (!tag)
2395*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2396*1230fdc1SLionel Sambuc tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE);
2397*1230fdc1SLionel Sambuc if (!tag->buf) {
2398*1230fdc1SLionel Sambuc FREE(tag);
2399*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2400*1230fdc1SLionel Sambuc }
2401*1230fdc1SLionel Sambuc tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
2402*1230fdc1SLionel Sambuc }
2403*1230fdc1SLionel Sambuc tag->bindings = NULL;
2404*1230fdc1SLionel Sambuc tag->parent = tagStack;
2405*1230fdc1SLionel Sambuc tagStack = tag;
2406*1230fdc1SLionel Sambuc tag->name.localPart = NULL;
2407*1230fdc1SLionel Sambuc tag->name.prefix = NULL;
2408*1230fdc1SLionel Sambuc tag->rawName = s + enc->minBytesPerChar;
2409*1230fdc1SLionel Sambuc tag->rawNameLength = XmlNameLength(enc, tag->rawName);
2410*1230fdc1SLionel Sambuc ++tagLevel;
2411*1230fdc1SLionel Sambuc {
2412*1230fdc1SLionel Sambuc const char *rawNameEnd = tag->rawName + tag->rawNameLength;
2413*1230fdc1SLionel Sambuc const char *fromPtr = tag->rawName;
2414*1230fdc1SLionel Sambuc toPtr = (XML_Char *)tag->buf;
2415*1230fdc1SLionel Sambuc for (;;) {
2416*1230fdc1SLionel Sambuc int bufSize;
2417*1230fdc1SLionel Sambuc int convLen;
2418*1230fdc1SLionel Sambuc XmlConvert(enc,
2419*1230fdc1SLionel Sambuc &fromPtr, rawNameEnd,
2420*1230fdc1SLionel Sambuc (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
2421*1230fdc1SLionel Sambuc convLen = (int)(toPtr - (XML_Char *)tag->buf);
2422*1230fdc1SLionel Sambuc if (fromPtr == rawNameEnd) {
2423*1230fdc1SLionel Sambuc tag->name.strLen = convLen;
2424*1230fdc1SLionel Sambuc break;
2425*1230fdc1SLionel Sambuc }
2426*1230fdc1SLionel Sambuc bufSize = (int)(tag->bufEnd - tag->buf) << 1;
2427*1230fdc1SLionel Sambuc {
2428*1230fdc1SLionel Sambuc char *temp = (char *)REALLOC(tag->buf, bufSize);
2429*1230fdc1SLionel Sambuc if (temp == NULL)
2430*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2431*1230fdc1SLionel Sambuc tag->buf = temp;
2432*1230fdc1SLionel Sambuc tag->bufEnd = temp + bufSize;
2433*1230fdc1SLionel Sambuc toPtr = (XML_Char *)temp + convLen;
2434*1230fdc1SLionel Sambuc }
2435*1230fdc1SLionel Sambuc }
2436*1230fdc1SLionel Sambuc }
2437*1230fdc1SLionel Sambuc tag->name.str = (XML_Char *)tag->buf;
2438*1230fdc1SLionel Sambuc *toPtr = XML_T('\0');
2439*1230fdc1SLionel Sambuc result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
2440*1230fdc1SLionel Sambuc if (result)
2441*1230fdc1SLionel Sambuc return result;
2442*1230fdc1SLionel Sambuc if (startElementHandler)
2443*1230fdc1SLionel Sambuc startElementHandler(handlerArg, tag->name.str,
2444*1230fdc1SLionel Sambuc (const XML_Char **)atts);
2445*1230fdc1SLionel Sambuc else if (defaultHandler)
2446*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2447*1230fdc1SLionel Sambuc poolClear(&tempPool);
2448*1230fdc1SLionel Sambuc break;
2449*1230fdc1SLionel Sambuc }
2450*1230fdc1SLionel Sambuc case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
2451*1230fdc1SLionel Sambuc /* fall through */
2452*1230fdc1SLionel Sambuc case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
2453*1230fdc1SLionel Sambuc {
2454*1230fdc1SLionel Sambuc const char *rawName = s + enc->minBytesPerChar;
2455*1230fdc1SLionel Sambuc enum XML_Error result;
2456*1230fdc1SLionel Sambuc BINDING *bindings = NULL;
2457*1230fdc1SLionel Sambuc XML_Bool noElmHandlers = XML_TRUE;
2458*1230fdc1SLionel Sambuc TAG_NAME name;
2459*1230fdc1SLionel Sambuc name.str = poolStoreString(&tempPool, enc, rawName,
2460*1230fdc1SLionel Sambuc rawName + XmlNameLength(enc, rawName));
2461*1230fdc1SLionel Sambuc if (!name.str)
2462*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2463*1230fdc1SLionel Sambuc poolFinish(&tempPool);
2464*1230fdc1SLionel Sambuc result = storeAtts(parser, enc, s, &name, &bindings);
2465*1230fdc1SLionel Sambuc if (result)
2466*1230fdc1SLionel Sambuc return result;
2467*1230fdc1SLionel Sambuc poolFinish(&tempPool);
2468*1230fdc1SLionel Sambuc if (startElementHandler) {
2469*1230fdc1SLionel Sambuc startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
2470*1230fdc1SLionel Sambuc noElmHandlers = XML_FALSE;
2471*1230fdc1SLionel Sambuc }
2472*1230fdc1SLionel Sambuc if (endElementHandler) {
2473*1230fdc1SLionel Sambuc if (startElementHandler)
2474*1230fdc1SLionel Sambuc *eventPP = *eventEndPP;
2475*1230fdc1SLionel Sambuc endElementHandler(handlerArg, name.str);
2476*1230fdc1SLionel Sambuc noElmHandlers = XML_FALSE;
2477*1230fdc1SLionel Sambuc }
2478*1230fdc1SLionel Sambuc if (noElmHandlers && defaultHandler)
2479*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2480*1230fdc1SLionel Sambuc poolClear(&tempPool);
2481*1230fdc1SLionel Sambuc while (bindings) {
2482*1230fdc1SLionel Sambuc BINDING *b = bindings;
2483*1230fdc1SLionel Sambuc if (endNamespaceDeclHandler)
2484*1230fdc1SLionel Sambuc endNamespaceDeclHandler(handlerArg, b->prefix->name);
2485*1230fdc1SLionel Sambuc bindings = bindings->nextTagBinding;
2486*1230fdc1SLionel Sambuc b->nextTagBinding = freeBindingList;
2487*1230fdc1SLionel Sambuc freeBindingList = b;
2488*1230fdc1SLionel Sambuc b->prefix->binding = b->prevPrefixBinding;
2489*1230fdc1SLionel Sambuc }
2490*1230fdc1SLionel Sambuc }
2491*1230fdc1SLionel Sambuc if (tagLevel == 0)
2492*1230fdc1SLionel Sambuc return epilogProcessor(parser, next, end, nextPtr);
2493*1230fdc1SLionel Sambuc break;
2494*1230fdc1SLionel Sambuc case XML_TOK_END_TAG:
2495*1230fdc1SLionel Sambuc if (tagLevel == startTagLevel)
2496*1230fdc1SLionel Sambuc return XML_ERROR_ASYNC_ENTITY;
2497*1230fdc1SLionel Sambuc else {
2498*1230fdc1SLionel Sambuc int len;
2499*1230fdc1SLionel Sambuc const char *rawName;
2500*1230fdc1SLionel Sambuc TAG *tag = tagStack;
2501*1230fdc1SLionel Sambuc tagStack = tag->parent;
2502*1230fdc1SLionel Sambuc tag->parent = freeTagList;
2503*1230fdc1SLionel Sambuc freeTagList = tag;
2504*1230fdc1SLionel Sambuc rawName = s + enc->minBytesPerChar*2;
2505*1230fdc1SLionel Sambuc len = XmlNameLength(enc, rawName);
2506*1230fdc1SLionel Sambuc if (len != tag->rawNameLength
2507*1230fdc1SLionel Sambuc || memcmp(tag->rawName, rawName, len) != 0) {
2508*1230fdc1SLionel Sambuc *eventPP = rawName;
2509*1230fdc1SLionel Sambuc return XML_ERROR_TAG_MISMATCH;
2510*1230fdc1SLionel Sambuc }
2511*1230fdc1SLionel Sambuc --tagLevel;
2512*1230fdc1SLionel Sambuc if (endElementHandler) {
2513*1230fdc1SLionel Sambuc const XML_Char *localPart;
2514*1230fdc1SLionel Sambuc const XML_Char *prefix;
2515*1230fdc1SLionel Sambuc XML_Char *uri;
2516*1230fdc1SLionel Sambuc localPart = tag->name.localPart;
2517*1230fdc1SLionel Sambuc if (ns && localPart) {
2518*1230fdc1SLionel Sambuc /* localPart and prefix may have been overwritten in
2519*1230fdc1SLionel Sambuc tag->name.str, since this points to the binding->uri
2520*1230fdc1SLionel Sambuc buffer which gets re-used; so we have to add them again
2521*1230fdc1SLionel Sambuc */
2522*1230fdc1SLionel Sambuc uri = (XML_Char *)tag->name.str + tag->name.uriLen;
2523*1230fdc1SLionel Sambuc /* don't need to check for space - already done in storeAtts() */
2524*1230fdc1SLionel Sambuc while (*localPart) *uri++ = *localPart++;
2525*1230fdc1SLionel Sambuc prefix = (XML_Char *)tag->name.prefix;
2526*1230fdc1SLionel Sambuc if (ns_triplets && prefix) {
2527*1230fdc1SLionel Sambuc *uri++ = namespaceSeparator;
2528*1230fdc1SLionel Sambuc while (*prefix) *uri++ = *prefix++;
2529*1230fdc1SLionel Sambuc }
2530*1230fdc1SLionel Sambuc *uri = XML_T('\0');
2531*1230fdc1SLionel Sambuc }
2532*1230fdc1SLionel Sambuc endElementHandler(handlerArg, tag->name.str);
2533*1230fdc1SLionel Sambuc }
2534*1230fdc1SLionel Sambuc else if (defaultHandler)
2535*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2536*1230fdc1SLionel Sambuc while (tag->bindings) {
2537*1230fdc1SLionel Sambuc BINDING *b = tag->bindings;
2538*1230fdc1SLionel Sambuc if (endNamespaceDeclHandler)
2539*1230fdc1SLionel Sambuc endNamespaceDeclHandler(handlerArg, b->prefix->name);
2540*1230fdc1SLionel Sambuc tag->bindings = tag->bindings->nextTagBinding;
2541*1230fdc1SLionel Sambuc b->nextTagBinding = freeBindingList;
2542*1230fdc1SLionel Sambuc freeBindingList = b;
2543*1230fdc1SLionel Sambuc b->prefix->binding = b->prevPrefixBinding;
2544*1230fdc1SLionel Sambuc }
2545*1230fdc1SLionel Sambuc if (tagLevel == 0)
2546*1230fdc1SLionel Sambuc return epilogProcessor(parser, next, end, nextPtr);
2547*1230fdc1SLionel Sambuc }
2548*1230fdc1SLionel Sambuc break;
2549*1230fdc1SLionel Sambuc case XML_TOK_CHAR_REF:
2550*1230fdc1SLionel Sambuc {
2551*1230fdc1SLionel Sambuc int n = XmlCharRefNumber(enc, s);
2552*1230fdc1SLionel Sambuc if (n < 0)
2553*1230fdc1SLionel Sambuc return XML_ERROR_BAD_CHAR_REF;
2554*1230fdc1SLionel Sambuc if (characterDataHandler) {
2555*1230fdc1SLionel Sambuc XML_Char buf[XML_ENCODE_MAX];
2556*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf));
2557*1230fdc1SLionel Sambuc }
2558*1230fdc1SLionel Sambuc else if (defaultHandler)
2559*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2560*1230fdc1SLionel Sambuc }
2561*1230fdc1SLionel Sambuc break;
2562*1230fdc1SLionel Sambuc case XML_TOK_XML_DECL:
2563*1230fdc1SLionel Sambuc return XML_ERROR_MISPLACED_XML_PI;
2564*1230fdc1SLionel Sambuc case XML_TOK_DATA_NEWLINE:
2565*1230fdc1SLionel Sambuc if (characterDataHandler) {
2566*1230fdc1SLionel Sambuc XML_Char c = 0xA;
2567*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, &c, 1);
2568*1230fdc1SLionel Sambuc }
2569*1230fdc1SLionel Sambuc else if (defaultHandler)
2570*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2571*1230fdc1SLionel Sambuc break;
2572*1230fdc1SLionel Sambuc case XML_TOK_CDATA_SECT_OPEN:
2573*1230fdc1SLionel Sambuc {
2574*1230fdc1SLionel Sambuc enum XML_Error result;
2575*1230fdc1SLionel Sambuc if (startCdataSectionHandler)
2576*1230fdc1SLionel Sambuc startCdataSectionHandler(handlerArg);
2577*1230fdc1SLionel Sambuc #if 0
2578*1230fdc1SLionel Sambuc /* Suppose you doing a transformation on a document that involves
2579*1230fdc1SLionel Sambuc changing only the character data. You set up a defaultHandler
2580*1230fdc1SLionel Sambuc and a characterDataHandler. The defaultHandler simply copies
2581*1230fdc1SLionel Sambuc characters through. The characterDataHandler does the
2582*1230fdc1SLionel Sambuc transformation and writes the characters out escaping them as
2583*1230fdc1SLionel Sambuc necessary. This case will fail to work if we leave out the
2584*1230fdc1SLionel Sambuc following two lines (because & and < inside CDATA sections will
2585*1230fdc1SLionel Sambuc be incorrectly escaped).
2586*1230fdc1SLionel Sambuc
2587*1230fdc1SLionel Sambuc However, now we have a start/endCdataSectionHandler, so it seems
2588*1230fdc1SLionel Sambuc easier to let the user deal with this.
2589*1230fdc1SLionel Sambuc */
2590*1230fdc1SLionel Sambuc else if (characterDataHandler)
2591*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, dataBuf, 0);
2592*1230fdc1SLionel Sambuc #endif
2593*1230fdc1SLionel Sambuc else if (defaultHandler)
2594*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2595*1230fdc1SLionel Sambuc result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore);
2596*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
2597*1230fdc1SLionel Sambuc return result;
2598*1230fdc1SLionel Sambuc else if (!next) {
2599*1230fdc1SLionel Sambuc processor = cdataSectionProcessor;
2600*1230fdc1SLionel Sambuc return result;
2601*1230fdc1SLionel Sambuc }
2602*1230fdc1SLionel Sambuc }
2603*1230fdc1SLionel Sambuc break;
2604*1230fdc1SLionel Sambuc case XML_TOK_TRAILING_RSQB:
2605*1230fdc1SLionel Sambuc if (haveMore) {
2606*1230fdc1SLionel Sambuc *nextPtr = s;
2607*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2608*1230fdc1SLionel Sambuc }
2609*1230fdc1SLionel Sambuc if (characterDataHandler) {
2610*1230fdc1SLionel Sambuc if (MUST_CONVERT(enc, s)) {
2611*1230fdc1SLionel Sambuc ICHAR *dataPtr = (ICHAR *)dataBuf;
2612*1230fdc1SLionel Sambuc XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
2613*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, dataBuf,
2614*1230fdc1SLionel Sambuc (int)(dataPtr - (ICHAR *)dataBuf));
2615*1230fdc1SLionel Sambuc }
2616*1230fdc1SLionel Sambuc else
2617*1230fdc1SLionel Sambuc characterDataHandler(handlerArg,
2618*1230fdc1SLionel Sambuc (XML_Char *)s,
2619*1230fdc1SLionel Sambuc (int)((XML_Char *)end - (XML_Char *)s));
2620*1230fdc1SLionel Sambuc }
2621*1230fdc1SLionel Sambuc else if (defaultHandler)
2622*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, end);
2623*1230fdc1SLionel Sambuc /* We are at the end of the final buffer, should we check for
2624*1230fdc1SLionel Sambuc XML_SUSPENDED, XML_FINISHED?
2625*1230fdc1SLionel Sambuc */
2626*1230fdc1SLionel Sambuc if (startTagLevel == 0) {
2627*1230fdc1SLionel Sambuc *eventPP = end;
2628*1230fdc1SLionel Sambuc return XML_ERROR_NO_ELEMENTS;
2629*1230fdc1SLionel Sambuc }
2630*1230fdc1SLionel Sambuc if (tagLevel != startTagLevel) {
2631*1230fdc1SLionel Sambuc *eventPP = end;
2632*1230fdc1SLionel Sambuc return XML_ERROR_ASYNC_ENTITY;
2633*1230fdc1SLionel Sambuc }
2634*1230fdc1SLionel Sambuc *nextPtr = end;
2635*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2636*1230fdc1SLionel Sambuc case XML_TOK_DATA_CHARS:
2637*1230fdc1SLionel Sambuc {
2638*1230fdc1SLionel Sambuc XML_CharacterDataHandler charDataHandler = characterDataHandler;
2639*1230fdc1SLionel Sambuc if (charDataHandler) {
2640*1230fdc1SLionel Sambuc if (MUST_CONVERT(enc, s)) {
2641*1230fdc1SLionel Sambuc for (;;) {
2642*1230fdc1SLionel Sambuc ICHAR *dataPtr = (ICHAR *)dataBuf;
2643*1230fdc1SLionel Sambuc XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
2644*1230fdc1SLionel Sambuc *eventEndPP = s;
2645*1230fdc1SLionel Sambuc charDataHandler(handlerArg, dataBuf,
2646*1230fdc1SLionel Sambuc (int)(dataPtr - (ICHAR *)dataBuf));
2647*1230fdc1SLionel Sambuc if (s == next)
2648*1230fdc1SLionel Sambuc break;
2649*1230fdc1SLionel Sambuc *eventPP = s;
2650*1230fdc1SLionel Sambuc }
2651*1230fdc1SLionel Sambuc }
2652*1230fdc1SLionel Sambuc else
2653*1230fdc1SLionel Sambuc charDataHandler(handlerArg,
2654*1230fdc1SLionel Sambuc (XML_Char *)s,
2655*1230fdc1SLionel Sambuc (int)((XML_Char *)next - (XML_Char *)s));
2656*1230fdc1SLionel Sambuc }
2657*1230fdc1SLionel Sambuc else if (defaultHandler)
2658*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2659*1230fdc1SLionel Sambuc }
2660*1230fdc1SLionel Sambuc break;
2661*1230fdc1SLionel Sambuc case XML_TOK_PI:
2662*1230fdc1SLionel Sambuc if (!reportProcessingInstruction(parser, enc, s, next))
2663*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2664*1230fdc1SLionel Sambuc break;
2665*1230fdc1SLionel Sambuc case XML_TOK_COMMENT:
2666*1230fdc1SLionel Sambuc if (!reportComment(parser, enc, s, next))
2667*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2668*1230fdc1SLionel Sambuc break;
2669*1230fdc1SLionel Sambuc default:
2670*1230fdc1SLionel Sambuc if (defaultHandler)
2671*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
2672*1230fdc1SLionel Sambuc break;
2673*1230fdc1SLionel Sambuc }
2674*1230fdc1SLionel Sambuc *eventPP = s = next;
2675*1230fdc1SLionel Sambuc switch (ps_parsing) {
2676*1230fdc1SLionel Sambuc case XML_SUSPENDED:
2677*1230fdc1SLionel Sambuc *nextPtr = next;
2678*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2679*1230fdc1SLionel Sambuc case XML_FINISHED:
2680*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
2681*1230fdc1SLionel Sambuc default: ;
2682*1230fdc1SLionel Sambuc }
2683*1230fdc1SLionel Sambuc }
2684*1230fdc1SLionel Sambuc /* not reached */
2685*1230fdc1SLionel Sambuc }
2686*1230fdc1SLionel Sambuc
2687*1230fdc1SLionel Sambuc /* Precondition: all arguments must be non-NULL;
2688*1230fdc1SLionel Sambuc Purpose:
2689*1230fdc1SLionel Sambuc - normalize attributes
2690*1230fdc1SLionel Sambuc - check attributes for well-formedness
2691*1230fdc1SLionel Sambuc - generate namespace aware attribute names (URI, prefix)
2692*1230fdc1SLionel Sambuc - build list of attributes for startElementHandler
2693*1230fdc1SLionel Sambuc - default attributes
2694*1230fdc1SLionel Sambuc - process namespace declarations (check and report them)
2695*1230fdc1SLionel Sambuc - generate namespace aware element name (URI, prefix)
2696*1230fdc1SLionel Sambuc */
2697*1230fdc1SLionel Sambuc static enum XML_Error
storeAtts(XML_Parser parser,const ENCODING * enc,const char * attStr,TAG_NAME * tagNamePtr,BINDING ** bindingsPtr)2698*1230fdc1SLionel Sambuc storeAtts(XML_Parser parser, const ENCODING *enc,
2699*1230fdc1SLionel Sambuc const char *attStr, TAG_NAME *tagNamePtr,
2700*1230fdc1SLionel Sambuc BINDING **bindingsPtr)
2701*1230fdc1SLionel Sambuc {
2702*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
2703*1230fdc1SLionel Sambuc ELEMENT_TYPE *elementType;
2704*1230fdc1SLionel Sambuc int nDefaultAtts;
2705*1230fdc1SLionel Sambuc const XML_Char **appAtts; /* the attribute list for the application */
2706*1230fdc1SLionel Sambuc int attIndex = 0;
2707*1230fdc1SLionel Sambuc int prefixLen;
2708*1230fdc1SLionel Sambuc int i;
2709*1230fdc1SLionel Sambuc int n;
2710*1230fdc1SLionel Sambuc XML_Char *uri;
2711*1230fdc1SLionel Sambuc int nPrefixes = 0;
2712*1230fdc1SLionel Sambuc BINDING *binding;
2713*1230fdc1SLionel Sambuc const XML_Char *localPart;
2714*1230fdc1SLionel Sambuc
2715*1230fdc1SLionel Sambuc /* lookup the element type name */
2716*1230fdc1SLionel Sambuc elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0);
2717*1230fdc1SLionel Sambuc if (!elementType) {
2718*1230fdc1SLionel Sambuc const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2719*1230fdc1SLionel Sambuc if (!name)
2720*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2721*1230fdc1SLionel Sambuc elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name,
2722*1230fdc1SLionel Sambuc sizeof(ELEMENT_TYPE));
2723*1230fdc1SLionel Sambuc if (!elementType)
2724*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2725*1230fdc1SLionel Sambuc if (ns && !setElementTypePrefix(parser, elementType))
2726*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2727*1230fdc1SLionel Sambuc }
2728*1230fdc1SLionel Sambuc nDefaultAtts = elementType->nDefaultAtts;
2729*1230fdc1SLionel Sambuc
2730*1230fdc1SLionel Sambuc /* get the attributes from the tokenizer */
2731*1230fdc1SLionel Sambuc n = XmlGetAttributes(enc, attStr, attsSize, atts);
2732*1230fdc1SLionel Sambuc if (n + nDefaultAtts > attsSize) {
2733*1230fdc1SLionel Sambuc int oldAttsSize = attsSize;
2734*1230fdc1SLionel Sambuc ATTRIBUTE *temp;
2735*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
2736*1230fdc1SLionel Sambuc XML_AttrInfo *temp2;
2737*1230fdc1SLionel Sambuc #endif
2738*1230fdc1SLionel Sambuc attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
2739*1230fdc1SLionel Sambuc temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
2740*1230fdc1SLionel Sambuc if (temp == NULL)
2741*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2742*1230fdc1SLionel Sambuc atts = temp;
2743*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
2744*1230fdc1SLionel Sambuc temp2 = (XML_AttrInfo *)REALLOC((void *)attInfo, attsSize * sizeof(XML_AttrInfo));
2745*1230fdc1SLionel Sambuc if (temp2 == NULL)
2746*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2747*1230fdc1SLionel Sambuc attInfo = temp2;
2748*1230fdc1SLionel Sambuc #endif
2749*1230fdc1SLionel Sambuc if (n > oldAttsSize)
2750*1230fdc1SLionel Sambuc XmlGetAttributes(enc, attStr, n, atts);
2751*1230fdc1SLionel Sambuc }
2752*1230fdc1SLionel Sambuc
2753*1230fdc1SLionel Sambuc appAtts = (const XML_Char **)atts;
2754*1230fdc1SLionel Sambuc for (i = 0; i < n; i++) {
2755*1230fdc1SLionel Sambuc ATTRIBUTE *currAtt = &atts[i];
2756*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
2757*1230fdc1SLionel Sambuc XML_AttrInfo *currAttInfo = &attInfo[i];
2758*1230fdc1SLionel Sambuc #endif
2759*1230fdc1SLionel Sambuc /* add the name and value to the attribute list */
2760*1230fdc1SLionel Sambuc ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name,
2761*1230fdc1SLionel Sambuc currAtt->name
2762*1230fdc1SLionel Sambuc + XmlNameLength(enc, currAtt->name));
2763*1230fdc1SLionel Sambuc if (!attId)
2764*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2765*1230fdc1SLionel Sambuc #ifdef XML_ATTR_INFO
2766*1230fdc1SLionel Sambuc currAttInfo->nameStart = parseEndByteIndex - (parseEndPtr - currAtt->name);
2767*1230fdc1SLionel Sambuc currAttInfo->nameEnd = currAttInfo->nameStart +
2768*1230fdc1SLionel Sambuc XmlNameLength(enc, currAtt->name);
2769*1230fdc1SLionel Sambuc currAttInfo->valueStart = parseEndByteIndex -
2770*1230fdc1SLionel Sambuc (parseEndPtr - currAtt->valuePtr);
2771*1230fdc1SLionel Sambuc currAttInfo->valueEnd = parseEndByteIndex - (parseEndPtr - currAtt->valueEnd);
2772*1230fdc1SLionel Sambuc #endif
2773*1230fdc1SLionel Sambuc /* Detect duplicate attributes by their QNames. This does not work when
2774*1230fdc1SLionel Sambuc namespace processing is turned on and different prefixes for the same
2775*1230fdc1SLionel Sambuc namespace are used. For this case we have a check further down.
2776*1230fdc1SLionel Sambuc */
2777*1230fdc1SLionel Sambuc if ((attId->name)[-1]) {
2778*1230fdc1SLionel Sambuc if (enc == encoding)
2779*1230fdc1SLionel Sambuc eventPtr = atts[i].name;
2780*1230fdc1SLionel Sambuc return XML_ERROR_DUPLICATE_ATTRIBUTE;
2781*1230fdc1SLionel Sambuc }
2782*1230fdc1SLionel Sambuc (attId->name)[-1] = 1;
2783*1230fdc1SLionel Sambuc appAtts[attIndex++] = attId->name;
2784*1230fdc1SLionel Sambuc if (!atts[i].normalized) {
2785*1230fdc1SLionel Sambuc enum XML_Error result;
2786*1230fdc1SLionel Sambuc XML_Bool isCdata = XML_TRUE;
2787*1230fdc1SLionel Sambuc
2788*1230fdc1SLionel Sambuc /* figure out whether declared as other than CDATA */
2789*1230fdc1SLionel Sambuc if (attId->maybeTokenized) {
2790*1230fdc1SLionel Sambuc int j;
2791*1230fdc1SLionel Sambuc for (j = 0; j < nDefaultAtts; j++) {
2792*1230fdc1SLionel Sambuc if (attId == elementType->defaultAtts[j].id) {
2793*1230fdc1SLionel Sambuc isCdata = elementType->defaultAtts[j].isCdata;
2794*1230fdc1SLionel Sambuc break;
2795*1230fdc1SLionel Sambuc }
2796*1230fdc1SLionel Sambuc }
2797*1230fdc1SLionel Sambuc }
2798*1230fdc1SLionel Sambuc
2799*1230fdc1SLionel Sambuc /* normalize the attribute value */
2800*1230fdc1SLionel Sambuc result = storeAttributeValue(parser, enc, isCdata,
2801*1230fdc1SLionel Sambuc atts[i].valuePtr, atts[i].valueEnd,
2802*1230fdc1SLionel Sambuc &tempPool);
2803*1230fdc1SLionel Sambuc if (result)
2804*1230fdc1SLionel Sambuc return result;
2805*1230fdc1SLionel Sambuc appAtts[attIndex] = poolStart(&tempPool);
2806*1230fdc1SLionel Sambuc poolFinish(&tempPool);
2807*1230fdc1SLionel Sambuc }
2808*1230fdc1SLionel Sambuc else {
2809*1230fdc1SLionel Sambuc /* the value did not need normalizing */
2810*1230fdc1SLionel Sambuc appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,
2811*1230fdc1SLionel Sambuc atts[i].valueEnd);
2812*1230fdc1SLionel Sambuc if (appAtts[attIndex] == 0)
2813*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2814*1230fdc1SLionel Sambuc poolFinish(&tempPool);
2815*1230fdc1SLionel Sambuc }
2816*1230fdc1SLionel Sambuc /* handle prefixed attribute names */
2817*1230fdc1SLionel Sambuc if (attId->prefix) {
2818*1230fdc1SLionel Sambuc if (attId->xmlns) {
2819*1230fdc1SLionel Sambuc /* deal with namespace declarations here */
2820*1230fdc1SLionel Sambuc enum XML_Error result = addBinding(parser, attId->prefix, attId,
2821*1230fdc1SLionel Sambuc appAtts[attIndex], bindingsPtr);
2822*1230fdc1SLionel Sambuc if (result)
2823*1230fdc1SLionel Sambuc return result;
2824*1230fdc1SLionel Sambuc --attIndex;
2825*1230fdc1SLionel Sambuc }
2826*1230fdc1SLionel Sambuc else {
2827*1230fdc1SLionel Sambuc /* deal with other prefixed names later */
2828*1230fdc1SLionel Sambuc attIndex++;
2829*1230fdc1SLionel Sambuc nPrefixes++;
2830*1230fdc1SLionel Sambuc (attId->name)[-1] = 2;
2831*1230fdc1SLionel Sambuc }
2832*1230fdc1SLionel Sambuc }
2833*1230fdc1SLionel Sambuc else
2834*1230fdc1SLionel Sambuc attIndex++;
2835*1230fdc1SLionel Sambuc }
2836*1230fdc1SLionel Sambuc
2837*1230fdc1SLionel Sambuc /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */
2838*1230fdc1SLionel Sambuc nSpecifiedAtts = attIndex;
2839*1230fdc1SLionel Sambuc if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
2840*1230fdc1SLionel Sambuc for (i = 0; i < attIndex; i += 2)
2841*1230fdc1SLionel Sambuc if (appAtts[i] == elementType->idAtt->name) {
2842*1230fdc1SLionel Sambuc idAttIndex = i;
2843*1230fdc1SLionel Sambuc break;
2844*1230fdc1SLionel Sambuc }
2845*1230fdc1SLionel Sambuc }
2846*1230fdc1SLionel Sambuc else
2847*1230fdc1SLionel Sambuc idAttIndex = -1;
2848*1230fdc1SLionel Sambuc
2849*1230fdc1SLionel Sambuc /* do attribute defaulting */
2850*1230fdc1SLionel Sambuc for (i = 0; i < nDefaultAtts; i++) {
2851*1230fdc1SLionel Sambuc const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i;
2852*1230fdc1SLionel Sambuc if (!(da->id->name)[-1] && da->value) {
2853*1230fdc1SLionel Sambuc if (da->id->prefix) {
2854*1230fdc1SLionel Sambuc if (da->id->xmlns) {
2855*1230fdc1SLionel Sambuc enum XML_Error result = addBinding(parser, da->id->prefix, da->id,
2856*1230fdc1SLionel Sambuc da->value, bindingsPtr);
2857*1230fdc1SLionel Sambuc if (result)
2858*1230fdc1SLionel Sambuc return result;
2859*1230fdc1SLionel Sambuc }
2860*1230fdc1SLionel Sambuc else {
2861*1230fdc1SLionel Sambuc (da->id->name)[-1] = 2;
2862*1230fdc1SLionel Sambuc nPrefixes++;
2863*1230fdc1SLionel Sambuc appAtts[attIndex++] = da->id->name;
2864*1230fdc1SLionel Sambuc appAtts[attIndex++] = da->value;
2865*1230fdc1SLionel Sambuc }
2866*1230fdc1SLionel Sambuc }
2867*1230fdc1SLionel Sambuc else {
2868*1230fdc1SLionel Sambuc (da->id->name)[-1] = 1;
2869*1230fdc1SLionel Sambuc appAtts[attIndex++] = da->id->name;
2870*1230fdc1SLionel Sambuc appAtts[attIndex++] = da->value;
2871*1230fdc1SLionel Sambuc }
2872*1230fdc1SLionel Sambuc }
2873*1230fdc1SLionel Sambuc }
2874*1230fdc1SLionel Sambuc appAtts[attIndex] = 0;
2875*1230fdc1SLionel Sambuc
2876*1230fdc1SLionel Sambuc /* expand prefixed attribute names, check for duplicates,
2877*1230fdc1SLionel Sambuc and clear flags that say whether attributes were specified */
2878*1230fdc1SLionel Sambuc i = 0;
2879*1230fdc1SLionel Sambuc if (nPrefixes) {
2880*1230fdc1SLionel Sambuc int j; /* hash table index */
2881*1230fdc1SLionel Sambuc unsigned long version = nsAttsVersion;
2882*1230fdc1SLionel Sambuc int nsAttsSize = (int)1 << nsAttsPower;
2883*1230fdc1SLionel Sambuc /* size of hash table must be at least 2 * (# of prefixed attributes) */
2884*1230fdc1SLionel Sambuc if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */
2885*1230fdc1SLionel Sambuc NS_ATT *temp;
2886*1230fdc1SLionel Sambuc /* hash table size must also be a power of 2 and >= 8 */
2887*1230fdc1SLionel Sambuc while (nPrefixes >> nsAttsPower++);
2888*1230fdc1SLionel Sambuc if (nsAttsPower < 3)
2889*1230fdc1SLionel Sambuc nsAttsPower = 3;
2890*1230fdc1SLionel Sambuc nsAttsSize = (int)1 << nsAttsPower;
2891*1230fdc1SLionel Sambuc temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT));
2892*1230fdc1SLionel Sambuc if (!temp)
2893*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2894*1230fdc1SLionel Sambuc nsAtts = temp;
2895*1230fdc1SLionel Sambuc version = 0; /* force re-initialization of nsAtts hash table */
2896*1230fdc1SLionel Sambuc }
2897*1230fdc1SLionel Sambuc /* using a version flag saves us from initializing nsAtts every time */
2898*1230fdc1SLionel Sambuc if (!version) { /* initialize version flags when version wraps around */
2899*1230fdc1SLionel Sambuc version = INIT_ATTS_VERSION;
2900*1230fdc1SLionel Sambuc for (j = nsAttsSize; j != 0; )
2901*1230fdc1SLionel Sambuc nsAtts[--j].version = version;
2902*1230fdc1SLionel Sambuc }
2903*1230fdc1SLionel Sambuc nsAttsVersion = --version;
2904*1230fdc1SLionel Sambuc
2905*1230fdc1SLionel Sambuc /* expand prefixed names and check for duplicates */
2906*1230fdc1SLionel Sambuc for (; i < attIndex; i += 2) {
2907*1230fdc1SLionel Sambuc const XML_Char *s = appAtts[i];
2908*1230fdc1SLionel Sambuc if (s[-1] == 2) { /* prefixed */
2909*1230fdc1SLionel Sambuc ATTRIBUTE_ID *id;
2910*1230fdc1SLionel Sambuc const BINDING *b;
2911*1230fdc1SLionel Sambuc unsigned long uriHash = hash_secret_salt;
2912*1230fdc1SLionel Sambuc ((XML_Char *)s)[-1] = 0; /* clear flag */
2913*1230fdc1SLionel Sambuc id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0);
2914*1230fdc1SLionel Sambuc b = id->prefix->binding;
2915*1230fdc1SLionel Sambuc if (!b)
2916*1230fdc1SLionel Sambuc return XML_ERROR_UNBOUND_PREFIX;
2917*1230fdc1SLionel Sambuc
2918*1230fdc1SLionel Sambuc /* as we expand the name we also calculate its hash value */
2919*1230fdc1SLionel Sambuc for (j = 0; j < b->uriLen; j++) {
2920*1230fdc1SLionel Sambuc const XML_Char c = b->uri[j];
2921*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, c))
2922*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2923*1230fdc1SLionel Sambuc uriHash = CHAR_HASH(uriHash, c);
2924*1230fdc1SLionel Sambuc }
2925*1230fdc1SLionel Sambuc while (*s++ != XML_T(ASCII_COLON))
2926*1230fdc1SLionel Sambuc ;
2927*1230fdc1SLionel Sambuc do { /* copies null terminator */
2928*1230fdc1SLionel Sambuc const XML_Char c = *s;
2929*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *s))
2930*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2931*1230fdc1SLionel Sambuc uriHash = CHAR_HASH(uriHash, c);
2932*1230fdc1SLionel Sambuc } while (*s++);
2933*1230fdc1SLionel Sambuc
2934*1230fdc1SLionel Sambuc { /* Check hash table for duplicate of expanded name (uriName).
2935*1230fdc1SLionel Sambuc Derived from code in lookup(parser, HASH_TABLE *table, ...).
2936*1230fdc1SLionel Sambuc */
2937*1230fdc1SLionel Sambuc unsigned char step = 0;
2938*1230fdc1SLionel Sambuc unsigned long mask = nsAttsSize - 1;
2939*1230fdc1SLionel Sambuc j = uriHash & mask; /* index into hash table */
2940*1230fdc1SLionel Sambuc while (nsAtts[j].version == version) {
2941*1230fdc1SLionel Sambuc /* for speed we compare stored hash values first */
2942*1230fdc1SLionel Sambuc if (uriHash == nsAtts[j].hash) {
2943*1230fdc1SLionel Sambuc const XML_Char *s1 = poolStart(&tempPool);
2944*1230fdc1SLionel Sambuc const XML_Char *s2 = nsAtts[j].uriName;
2945*1230fdc1SLionel Sambuc /* s1 is null terminated, but not s2 */
2946*1230fdc1SLionel Sambuc for (; *s1 == *s2 && *s1 != 0; s1++, s2++);
2947*1230fdc1SLionel Sambuc if (*s1 == 0)
2948*1230fdc1SLionel Sambuc return XML_ERROR_DUPLICATE_ATTRIBUTE;
2949*1230fdc1SLionel Sambuc }
2950*1230fdc1SLionel Sambuc if (!step)
2951*1230fdc1SLionel Sambuc step = PROBE_STEP(uriHash, mask, nsAttsPower);
2952*1230fdc1SLionel Sambuc j < step ? (j += nsAttsSize - step) : (j -= step);
2953*1230fdc1SLionel Sambuc }
2954*1230fdc1SLionel Sambuc }
2955*1230fdc1SLionel Sambuc
2956*1230fdc1SLionel Sambuc if (ns_triplets) { /* append namespace separator and prefix */
2957*1230fdc1SLionel Sambuc tempPool.ptr[-1] = namespaceSeparator;
2958*1230fdc1SLionel Sambuc s = b->prefix->name;
2959*1230fdc1SLionel Sambuc do {
2960*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *s))
2961*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
2962*1230fdc1SLionel Sambuc } while (*s++);
2963*1230fdc1SLionel Sambuc }
2964*1230fdc1SLionel Sambuc
2965*1230fdc1SLionel Sambuc /* store expanded name in attribute list */
2966*1230fdc1SLionel Sambuc s = poolStart(&tempPool);
2967*1230fdc1SLionel Sambuc poolFinish(&tempPool);
2968*1230fdc1SLionel Sambuc appAtts[i] = s;
2969*1230fdc1SLionel Sambuc
2970*1230fdc1SLionel Sambuc /* fill empty slot with new version, uriName and hash value */
2971*1230fdc1SLionel Sambuc nsAtts[j].version = version;
2972*1230fdc1SLionel Sambuc nsAtts[j].hash = uriHash;
2973*1230fdc1SLionel Sambuc nsAtts[j].uriName = s;
2974*1230fdc1SLionel Sambuc
2975*1230fdc1SLionel Sambuc if (!--nPrefixes) {
2976*1230fdc1SLionel Sambuc i += 2;
2977*1230fdc1SLionel Sambuc break;
2978*1230fdc1SLionel Sambuc }
2979*1230fdc1SLionel Sambuc }
2980*1230fdc1SLionel Sambuc else /* not prefixed */
2981*1230fdc1SLionel Sambuc ((XML_Char *)s)[-1] = 0; /* clear flag */
2982*1230fdc1SLionel Sambuc }
2983*1230fdc1SLionel Sambuc }
2984*1230fdc1SLionel Sambuc /* clear flags for the remaining attributes */
2985*1230fdc1SLionel Sambuc for (; i < attIndex; i += 2)
2986*1230fdc1SLionel Sambuc ((XML_Char *)(appAtts[i]))[-1] = 0;
2987*1230fdc1SLionel Sambuc for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
2988*1230fdc1SLionel Sambuc binding->attId->name[-1] = 0;
2989*1230fdc1SLionel Sambuc
2990*1230fdc1SLionel Sambuc if (!ns)
2991*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
2992*1230fdc1SLionel Sambuc
2993*1230fdc1SLionel Sambuc /* expand the element type name */
2994*1230fdc1SLionel Sambuc if (elementType->prefix) {
2995*1230fdc1SLionel Sambuc binding = elementType->prefix->binding;
2996*1230fdc1SLionel Sambuc if (!binding)
2997*1230fdc1SLionel Sambuc return XML_ERROR_UNBOUND_PREFIX;
2998*1230fdc1SLionel Sambuc localPart = tagNamePtr->str;
2999*1230fdc1SLionel Sambuc while (*localPart++ != XML_T(ASCII_COLON))
3000*1230fdc1SLionel Sambuc ;
3001*1230fdc1SLionel Sambuc }
3002*1230fdc1SLionel Sambuc else if (dtd->defaultPrefix.binding) {
3003*1230fdc1SLionel Sambuc binding = dtd->defaultPrefix.binding;
3004*1230fdc1SLionel Sambuc localPart = tagNamePtr->str;
3005*1230fdc1SLionel Sambuc }
3006*1230fdc1SLionel Sambuc else
3007*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3008*1230fdc1SLionel Sambuc prefixLen = 0;
3009*1230fdc1SLionel Sambuc if (ns_triplets && binding->prefix->name) {
3010*1230fdc1SLionel Sambuc for (; binding->prefix->name[prefixLen++];)
3011*1230fdc1SLionel Sambuc ; /* prefixLen includes null terminator */
3012*1230fdc1SLionel Sambuc }
3013*1230fdc1SLionel Sambuc tagNamePtr->localPart = localPart;
3014*1230fdc1SLionel Sambuc tagNamePtr->uriLen = binding->uriLen;
3015*1230fdc1SLionel Sambuc tagNamePtr->prefix = binding->prefix->name;
3016*1230fdc1SLionel Sambuc tagNamePtr->prefixLen = prefixLen;
3017*1230fdc1SLionel Sambuc for (i = 0; localPart[i++];)
3018*1230fdc1SLionel Sambuc ; /* i includes null terminator */
3019*1230fdc1SLionel Sambuc n = i + binding->uriLen + prefixLen;
3020*1230fdc1SLionel Sambuc if (n > binding->uriAlloc) {
3021*1230fdc1SLionel Sambuc TAG *p;
3022*1230fdc1SLionel Sambuc uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char));
3023*1230fdc1SLionel Sambuc if (!uri)
3024*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3025*1230fdc1SLionel Sambuc binding->uriAlloc = n + EXPAND_SPARE;
3026*1230fdc1SLionel Sambuc memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char));
3027*1230fdc1SLionel Sambuc for (p = tagStack; p; p = p->parent)
3028*1230fdc1SLionel Sambuc if (p->name.str == binding->uri)
3029*1230fdc1SLionel Sambuc p->name.str = uri;
3030*1230fdc1SLionel Sambuc FREE(binding->uri);
3031*1230fdc1SLionel Sambuc binding->uri = uri;
3032*1230fdc1SLionel Sambuc }
3033*1230fdc1SLionel Sambuc /* if namespaceSeparator != '\0' then uri includes it already */
3034*1230fdc1SLionel Sambuc uri = binding->uri + binding->uriLen;
3035*1230fdc1SLionel Sambuc memcpy(uri, localPart, i * sizeof(XML_Char));
3036*1230fdc1SLionel Sambuc /* we always have a namespace separator between localPart and prefix */
3037*1230fdc1SLionel Sambuc if (prefixLen) {
3038*1230fdc1SLionel Sambuc uri += i - 1;
3039*1230fdc1SLionel Sambuc *uri = namespaceSeparator; /* replace null terminator */
3040*1230fdc1SLionel Sambuc memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char));
3041*1230fdc1SLionel Sambuc }
3042*1230fdc1SLionel Sambuc tagNamePtr->str = binding->uri;
3043*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3044*1230fdc1SLionel Sambuc }
3045*1230fdc1SLionel Sambuc
3046*1230fdc1SLionel Sambuc /* addBinding() overwrites the value of prefix->binding without checking.
3047*1230fdc1SLionel Sambuc Therefore one must keep track of the old value outside of addBinding().
3048*1230fdc1SLionel Sambuc */
3049*1230fdc1SLionel Sambuc static enum XML_Error
addBinding(XML_Parser parser,PREFIX * prefix,const ATTRIBUTE_ID * attId,const XML_Char * uri,BINDING ** bindingsPtr)3050*1230fdc1SLionel Sambuc addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
3051*1230fdc1SLionel Sambuc const XML_Char *uri, BINDING **bindingsPtr)
3052*1230fdc1SLionel Sambuc {
3053*1230fdc1SLionel Sambuc static const XML_Char xmlNamespace[] = {
3054*1230fdc1SLionel Sambuc ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH,
3055*1230fdc1SLionel Sambuc ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD,
3056*1230fdc1SLionel Sambuc ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L,
3057*1230fdc1SLionel Sambuc ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH,
3058*1230fdc1SLionel Sambuc ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c,
3059*1230fdc1SLionel Sambuc ASCII_e, '\0'
3060*1230fdc1SLionel Sambuc };
3061*1230fdc1SLionel Sambuc static const int xmlLen =
3062*1230fdc1SLionel Sambuc (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;
3063*1230fdc1SLionel Sambuc static const XML_Char xmlnsNamespace[] = {
3064*1230fdc1SLionel Sambuc ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH,
3065*1230fdc1SLionel Sambuc ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD,
3066*1230fdc1SLionel Sambuc ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0,
3067*1230fdc1SLionel Sambuc ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s,
3068*1230fdc1SLionel Sambuc ASCII_SLASH, '\0'
3069*1230fdc1SLionel Sambuc };
3070*1230fdc1SLionel Sambuc static const int xmlnsLen =
3071*1230fdc1SLionel Sambuc (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;
3072*1230fdc1SLionel Sambuc
3073*1230fdc1SLionel Sambuc XML_Bool mustBeXML = XML_FALSE;
3074*1230fdc1SLionel Sambuc XML_Bool isXML = XML_TRUE;
3075*1230fdc1SLionel Sambuc XML_Bool isXMLNS = XML_TRUE;
3076*1230fdc1SLionel Sambuc
3077*1230fdc1SLionel Sambuc BINDING *b;
3078*1230fdc1SLionel Sambuc int len;
3079*1230fdc1SLionel Sambuc
3080*1230fdc1SLionel Sambuc /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */
3081*1230fdc1SLionel Sambuc if (*uri == XML_T('\0') && prefix->name)
3082*1230fdc1SLionel Sambuc return XML_ERROR_UNDECLARING_PREFIX;
3083*1230fdc1SLionel Sambuc
3084*1230fdc1SLionel Sambuc if (prefix->name
3085*1230fdc1SLionel Sambuc && prefix->name[0] == XML_T(ASCII_x)
3086*1230fdc1SLionel Sambuc && prefix->name[1] == XML_T(ASCII_m)
3087*1230fdc1SLionel Sambuc && prefix->name[2] == XML_T(ASCII_l)) {
3088*1230fdc1SLionel Sambuc
3089*1230fdc1SLionel Sambuc /* Not allowed to bind xmlns */
3090*1230fdc1SLionel Sambuc if (prefix->name[3] == XML_T(ASCII_n)
3091*1230fdc1SLionel Sambuc && prefix->name[4] == XML_T(ASCII_s)
3092*1230fdc1SLionel Sambuc && prefix->name[5] == XML_T('\0'))
3093*1230fdc1SLionel Sambuc return XML_ERROR_RESERVED_PREFIX_XMLNS;
3094*1230fdc1SLionel Sambuc
3095*1230fdc1SLionel Sambuc if (prefix->name[3] == XML_T('\0'))
3096*1230fdc1SLionel Sambuc mustBeXML = XML_TRUE;
3097*1230fdc1SLionel Sambuc }
3098*1230fdc1SLionel Sambuc
3099*1230fdc1SLionel Sambuc for (len = 0; uri[len]; len++) {
3100*1230fdc1SLionel Sambuc if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
3101*1230fdc1SLionel Sambuc isXML = XML_FALSE;
3102*1230fdc1SLionel Sambuc
3103*1230fdc1SLionel Sambuc if (!mustBeXML && isXMLNS
3104*1230fdc1SLionel Sambuc && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
3105*1230fdc1SLionel Sambuc isXMLNS = XML_FALSE;
3106*1230fdc1SLionel Sambuc }
3107*1230fdc1SLionel Sambuc isXML = isXML && len == xmlLen;
3108*1230fdc1SLionel Sambuc isXMLNS = isXMLNS && len == xmlnsLen;
3109*1230fdc1SLionel Sambuc
3110*1230fdc1SLionel Sambuc if (mustBeXML != isXML)
3111*1230fdc1SLionel Sambuc return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML
3112*1230fdc1SLionel Sambuc : XML_ERROR_RESERVED_NAMESPACE_URI;
3113*1230fdc1SLionel Sambuc
3114*1230fdc1SLionel Sambuc if (isXMLNS)
3115*1230fdc1SLionel Sambuc return XML_ERROR_RESERVED_NAMESPACE_URI;
3116*1230fdc1SLionel Sambuc
3117*1230fdc1SLionel Sambuc if (namespaceSeparator)
3118*1230fdc1SLionel Sambuc len++;
3119*1230fdc1SLionel Sambuc if (freeBindingList) {
3120*1230fdc1SLionel Sambuc b = freeBindingList;
3121*1230fdc1SLionel Sambuc if (len > b->uriAlloc) {
3122*1230fdc1SLionel Sambuc XML_Char *temp = (XML_Char *)REALLOC(b->uri,
3123*1230fdc1SLionel Sambuc sizeof(XML_Char) * (len + EXPAND_SPARE));
3124*1230fdc1SLionel Sambuc if (temp == NULL)
3125*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3126*1230fdc1SLionel Sambuc b->uri = temp;
3127*1230fdc1SLionel Sambuc b->uriAlloc = len + EXPAND_SPARE;
3128*1230fdc1SLionel Sambuc }
3129*1230fdc1SLionel Sambuc freeBindingList = b->nextTagBinding;
3130*1230fdc1SLionel Sambuc }
3131*1230fdc1SLionel Sambuc else {
3132*1230fdc1SLionel Sambuc b = (BINDING *)MALLOC(sizeof(BINDING));
3133*1230fdc1SLionel Sambuc if (!b)
3134*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3135*1230fdc1SLionel Sambuc b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));
3136*1230fdc1SLionel Sambuc if (!b->uri) {
3137*1230fdc1SLionel Sambuc FREE(b);
3138*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3139*1230fdc1SLionel Sambuc }
3140*1230fdc1SLionel Sambuc b->uriAlloc = len + EXPAND_SPARE;
3141*1230fdc1SLionel Sambuc }
3142*1230fdc1SLionel Sambuc b->uriLen = len;
3143*1230fdc1SLionel Sambuc memcpy(b->uri, uri, len * sizeof(XML_Char));
3144*1230fdc1SLionel Sambuc if (namespaceSeparator)
3145*1230fdc1SLionel Sambuc b->uri[len - 1] = namespaceSeparator;
3146*1230fdc1SLionel Sambuc b->prefix = prefix;
3147*1230fdc1SLionel Sambuc b->attId = attId;
3148*1230fdc1SLionel Sambuc b->prevPrefixBinding = prefix->binding;
3149*1230fdc1SLionel Sambuc /* NULL binding when default namespace undeclared */
3150*1230fdc1SLionel Sambuc if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix)
3151*1230fdc1SLionel Sambuc prefix->binding = NULL;
3152*1230fdc1SLionel Sambuc else
3153*1230fdc1SLionel Sambuc prefix->binding = b;
3154*1230fdc1SLionel Sambuc b->nextTagBinding = *bindingsPtr;
3155*1230fdc1SLionel Sambuc *bindingsPtr = b;
3156*1230fdc1SLionel Sambuc /* if attId == NULL then we are not starting a namespace scope */
3157*1230fdc1SLionel Sambuc if (attId && startNamespaceDeclHandler)
3158*1230fdc1SLionel Sambuc startNamespaceDeclHandler(handlerArg, prefix->name,
3159*1230fdc1SLionel Sambuc prefix->binding ? uri : 0);
3160*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3161*1230fdc1SLionel Sambuc }
3162*1230fdc1SLionel Sambuc
3163*1230fdc1SLionel Sambuc /* The idea here is to avoid using stack for each CDATA section when
3164*1230fdc1SLionel Sambuc the whole file is parsed with one call.
3165*1230fdc1SLionel Sambuc */
3166*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
cdataSectionProcessor(XML_Parser parser,const char * start,const char * end,const char ** endPtr)3167*1230fdc1SLionel Sambuc cdataSectionProcessor(XML_Parser parser,
3168*1230fdc1SLionel Sambuc const char *start,
3169*1230fdc1SLionel Sambuc const char *end,
3170*1230fdc1SLionel Sambuc const char **endPtr)
3171*1230fdc1SLionel Sambuc {
3172*1230fdc1SLionel Sambuc enum XML_Error result = doCdataSection(parser, encoding, &start, end,
3173*1230fdc1SLionel Sambuc endPtr, (XML_Bool)!ps_finalBuffer);
3174*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3175*1230fdc1SLionel Sambuc return result;
3176*1230fdc1SLionel Sambuc if (start) {
3177*1230fdc1SLionel Sambuc if (parentParser) { /* we are parsing an external entity */
3178*1230fdc1SLionel Sambuc processor = externalEntityContentProcessor;
3179*1230fdc1SLionel Sambuc return externalEntityContentProcessor(parser, start, end, endPtr);
3180*1230fdc1SLionel Sambuc }
3181*1230fdc1SLionel Sambuc else {
3182*1230fdc1SLionel Sambuc processor = contentProcessor;
3183*1230fdc1SLionel Sambuc return contentProcessor(parser, start, end, endPtr);
3184*1230fdc1SLionel Sambuc }
3185*1230fdc1SLionel Sambuc }
3186*1230fdc1SLionel Sambuc return result;
3187*1230fdc1SLionel Sambuc }
3188*1230fdc1SLionel Sambuc
3189*1230fdc1SLionel Sambuc /* startPtr gets set to non-null if the section is closed, and to null if
3190*1230fdc1SLionel Sambuc the section is not yet closed.
3191*1230fdc1SLionel Sambuc */
3192*1230fdc1SLionel Sambuc static enum XML_Error
doCdataSection(XML_Parser parser,const ENCODING * enc,const char ** startPtr,const char * end,const char ** nextPtr,XML_Bool haveMore)3193*1230fdc1SLionel Sambuc doCdataSection(XML_Parser parser,
3194*1230fdc1SLionel Sambuc const ENCODING *enc,
3195*1230fdc1SLionel Sambuc const char **startPtr,
3196*1230fdc1SLionel Sambuc const char *end,
3197*1230fdc1SLionel Sambuc const char **nextPtr,
3198*1230fdc1SLionel Sambuc XML_Bool haveMore)
3199*1230fdc1SLionel Sambuc {
3200*1230fdc1SLionel Sambuc const char *s = *startPtr;
3201*1230fdc1SLionel Sambuc const char **eventPP;
3202*1230fdc1SLionel Sambuc const char **eventEndPP;
3203*1230fdc1SLionel Sambuc if (enc == encoding) {
3204*1230fdc1SLionel Sambuc eventPP = &eventPtr;
3205*1230fdc1SLionel Sambuc *eventPP = s;
3206*1230fdc1SLionel Sambuc eventEndPP = &eventEndPtr;
3207*1230fdc1SLionel Sambuc }
3208*1230fdc1SLionel Sambuc else {
3209*1230fdc1SLionel Sambuc eventPP = &(openInternalEntities->internalEventPtr);
3210*1230fdc1SLionel Sambuc eventEndPP = &(openInternalEntities->internalEventEndPtr);
3211*1230fdc1SLionel Sambuc }
3212*1230fdc1SLionel Sambuc *eventPP = s;
3213*1230fdc1SLionel Sambuc *startPtr = NULL;
3214*1230fdc1SLionel Sambuc
3215*1230fdc1SLionel Sambuc for (;;) {
3216*1230fdc1SLionel Sambuc const char *next;
3217*1230fdc1SLionel Sambuc int tok = XmlCdataSectionTok(enc, s, end, &next);
3218*1230fdc1SLionel Sambuc *eventEndPP = next;
3219*1230fdc1SLionel Sambuc switch (tok) {
3220*1230fdc1SLionel Sambuc case XML_TOK_CDATA_SECT_CLOSE:
3221*1230fdc1SLionel Sambuc if (endCdataSectionHandler)
3222*1230fdc1SLionel Sambuc endCdataSectionHandler(handlerArg);
3223*1230fdc1SLionel Sambuc #if 0
3224*1230fdc1SLionel Sambuc /* see comment under XML_TOK_CDATA_SECT_OPEN */
3225*1230fdc1SLionel Sambuc else if (characterDataHandler)
3226*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, dataBuf, 0);
3227*1230fdc1SLionel Sambuc #endif
3228*1230fdc1SLionel Sambuc else if (defaultHandler)
3229*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
3230*1230fdc1SLionel Sambuc *startPtr = next;
3231*1230fdc1SLionel Sambuc *nextPtr = next;
3232*1230fdc1SLionel Sambuc if (ps_parsing == XML_FINISHED)
3233*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
3234*1230fdc1SLionel Sambuc else
3235*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3236*1230fdc1SLionel Sambuc case XML_TOK_DATA_NEWLINE:
3237*1230fdc1SLionel Sambuc if (characterDataHandler) {
3238*1230fdc1SLionel Sambuc XML_Char c = 0xA;
3239*1230fdc1SLionel Sambuc characterDataHandler(handlerArg, &c, 1);
3240*1230fdc1SLionel Sambuc }
3241*1230fdc1SLionel Sambuc else if (defaultHandler)
3242*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
3243*1230fdc1SLionel Sambuc break;
3244*1230fdc1SLionel Sambuc case XML_TOK_DATA_CHARS:
3245*1230fdc1SLionel Sambuc {
3246*1230fdc1SLionel Sambuc XML_CharacterDataHandler charDataHandler = characterDataHandler;
3247*1230fdc1SLionel Sambuc if (charDataHandler) {
3248*1230fdc1SLionel Sambuc if (MUST_CONVERT(enc, s)) {
3249*1230fdc1SLionel Sambuc for (;;) {
3250*1230fdc1SLionel Sambuc ICHAR *dataPtr = (ICHAR *)dataBuf;
3251*1230fdc1SLionel Sambuc XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
3252*1230fdc1SLionel Sambuc *eventEndPP = next;
3253*1230fdc1SLionel Sambuc charDataHandler(handlerArg, dataBuf,
3254*1230fdc1SLionel Sambuc (int)(dataPtr - (ICHAR *)dataBuf));
3255*1230fdc1SLionel Sambuc if (s == next)
3256*1230fdc1SLionel Sambuc break;
3257*1230fdc1SLionel Sambuc *eventPP = s;
3258*1230fdc1SLionel Sambuc }
3259*1230fdc1SLionel Sambuc }
3260*1230fdc1SLionel Sambuc else
3261*1230fdc1SLionel Sambuc charDataHandler(handlerArg,
3262*1230fdc1SLionel Sambuc (XML_Char *)s,
3263*1230fdc1SLionel Sambuc (int)((XML_Char *)next - (XML_Char *)s));
3264*1230fdc1SLionel Sambuc }
3265*1230fdc1SLionel Sambuc else if (defaultHandler)
3266*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
3267*1230fdc1SLionel Sambuc }
3268*1230fdc1SLionel Sambuc break;
3269*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3270*1230fdc1SLionel Sambuc *eventPP = next;
3271*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3272*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3273*1230fdc1SLionel Sambuc if (haveMore) {
3274*1230fdc1SLionel Sambuc *nextPtr = s;
3275*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3276*1230fdc1SLionel Sambuc }
3277*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3278*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3279*1230fdc1SLionel Sambuc case XML_TOK_NONE:
3280*1230fdc1SLionel Sambuc if (haveMore) {
3281*1230fdc1SLionel Sambuc *nextPtr = s;
3282*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3283*1230fdc1SLionel Sambuc }
3284*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_CDATA_SECTION;
3285*1230fdc1SLionel Sambuc default:
3286*1230fdc1SLionel Sambuc *eventPP = next;
3287*1230fdc1SLionel Sambuc return XML_ERROR_UNEXPECTED_STATE;
3288*1230fdc1SLionel Sambuc }
3289*1230fdc1SLionel Sambuc
3290*1230fdc1SLionel Sambuc *eventPP = s = next;
3291*1230fdc1SLionel Sambuc switch (ps_parsing) {
3292*1230fdc1SLionel Sambuc case XML_SUSPENDED:
3293*1230fdc1SLionel Sambuc *nextPtr = next;
3294*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3295*1230fdc1SLionel Sambuc case XML_FINISHED:
3296*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
3297*1230fdc1SLionel Sambuc default: ;
3298*1230fdc1SLionel Sambuc }
3299*1230fdc1SLionel Sambuc }
3300*1230fdc1SLionel Sambuc /* not reached */
3301*1230fdc1SLionel Sambuc }
3302*1230fdc1SLionel Sambuc
3303*1230fdc1SLionel Sambuc #ifdef XML_DTD
3304*1230fdc1SLionel Sambuc
3305*1230fdc1SLionel Sambuc /* The idea here is to avoid using stack for each IGNORE section when
3306*1230fdc1SLionel Sambuc the whole file is parsed with one call.
3307*1230fdc1SLionel Sambuc */
3308*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
ignoreSectionProcessor(XML_Parser parser,const char * start,const char * end,const char ** endPtr)3309*1230fdc1SLionel Sambuc ignoreSectionProcessor(XML_Parser parser,
3310*1230fdc1SLionel Sambuc const char *start,
3311*1230fdc1SLionel Sambuc const char *end,
3312*1230fdc1SLionel Sambuc const char **endPtr)
3313*1230fdc1SLionel Sambuc {
3314*1230fdc1SLionel Sambuc enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
3315*1230fdc1SLionel Sambuc endPtr, (XML_Bool)!ps_finalBuffer);
3316*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3317*1230fdc1SLionel Sambuc return result;
3318*1230fdc1SLionel Sambuc if (start) {
3319*1230fdc1SLionel Sambuc processor = prologProcessor;
3320*1230fdc1SLionel Sambuc return prologProcessor(parser, start, end, endPtr);
3321*1230fdc1SLionel Sambuc }
3322*1230fdc1SLionel Sambuc return result;
3323*1230fdc1SLionel Sambuc }
3324*1230fdc1SLionel Sambuc
3325*1230fdc1SLionel Sambuc /* startPtr gets set to non-null is the section is closed, and to null
3326*1230fdc1SLionel Sambuc if the section is not yet closed.
3327*1230fdc1SLionel Sambuc */
3328*1230fdc1SLionel Sambuc static enum XML_Error
doIgnoreSection(XML_Parser parser,const ENCODING * enc,const char ** startPtr,const char * end,const char ** nextPtr,XML_Bool haveMore)3329*1230fdc1SLionel Sambuc doIgnoreSection(XML_Parser parser,
3330*1230fdc1SLionel Sambuc const ENCODING *enc,
3331*1230fdc1SLionel Sambuc const char **startPtr,
3332*1230fdc1SLionel Sambuc const char *end,
3333*1230fdc1SLionel Sambuc const char **nextPtr,
3334*1230fdc1SLionel Sambuc XML_Bool haveMore)
3335*1230fdc1SLionel Sambuc {
3336*1230fdc1SLionel Sambuc const char *next;
3337*1230fdc1SLionel Sambuc int tok;
3338*1230fdc1SLionel Sambuc const char *s = *startPtr;
3339*1230fdc1SLionel Sambuc const char **eventPP;
3340*1230fdc1SLionel Sambuc const char **eventEndPP;
3341*1230fdc1SLionel Sambuc if (enc == encoding) {
3342*1230fdc1SLionel Sambuc eventPP = &eventPtr;
3343*1230fdc1SLionel Sambuc *eventPP = s;
3344*1230fdc1SLionel Sambuc eventEndPP = &eventEndPtr;
3345*1230fdc1SLionel Sambuc }
3346*1230fdc1SLionel Sambuc else {
3347*1230fdc1SLionel Sambuc eventPP = &(openInternalEntities->internalEventPtr);
3348*1230fdc1SLionel Sambuc eventEndPP = &(openInternalEntities->internalEventEndPtr);
3349*1230fdc1SLionel Sambuc }
3350*1230fdc1SLionel Sambuc *eventPP = s;
3351*1230fdc1SLionel Sambuc *startPtr = NULL;
3352*1230fdc1SLionel Sambuc tok = XmlIgnoreSectionTok(enc, s, end, &next);
3353*1230fdc1SLionel Sambuc *eventEndPP = next;
3354*1230fdc1SLionel Sambuc switch (tok) {
3355*1230fdc1SLionel Sambuc case XML_TOK_IGNORE_SECT:
3356*1230fdc1SLionel Sambuc if (defaultHandler)
3357*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
3358*1230fdc1SLionel Sambuc *startPtr = next;
3359*1230fdc1SLionel Sambuc *nextPtr = next;
3360*1230fdc1SLionel Sambuc if (ps_parsing == XML_FINISHED)
3361*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
3362*1230fdc1SLionel Sambuc else
3363*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3364*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3365*1230fdc1SLionel Sambuc *eventPP = next;
3366*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3367*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3368*1230fdc1SLionel Sambuc if (haveMore) {
3369*1230fdc1SLionel Sambuc *nextPtr = s;
3370*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3371*1230fdc1SLionel Sambuc }
3372*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3373*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3374*1230fdc1SLionel Sambuc case XML_TOK_NONE:
3375*1230fdc1SLionel Sambuc if (haveMore) {
3376*1230fdc1SLionel Sambuc *nextPtr = s;
3377*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3378*1230fdc1SLionel Sambuc }
3379*1230fdc1SLionel Sambuc return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */
3380*1230fdc1SLionel Sambuc default:
3381*1230fdc1SLionel Sambuc *eventPP = next;
3382*1230fdc1SLionel Sambuc return XML_ERROR_UNEXPECTED_STATE;
3383*1230fdc1SLionel Sambuc }
3384*1230fdc1SLionel Sambuc /* not reached */
3385*1230fdc1SLionel Sambuc }
3386*1230fdc1SLionel Sambuc
3387*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3388*1230fdc1SLionel Sambuc
3389*1230fdc1SLionel Sambuc static enum XML_Error
initializeEncoding(XML_Parser parser)3390*1230fdc1SLionel Sambuc initializeEncoding(XML_Parser parser)
3391*1230fdc1SLionel Sambuc {
3392*1230fdc1SLionel Sambuc const char *s;
3393*1230fdc1SLionel Sambuc #ifdef XML_UNICODE
3394*1230fdc1SLionel Sambuc char encodingBuf[128];
3395*1230fdc1SLionel Sambuc if (!protocolEncodingName)
3396*1230fdc1SLionel Sambuc s = NULL;
3397*1230fdc1SLionel Sambuc else {
3398*1230fdc1SLionel Sambuc int i;
3399*1230fdc1SLionel Sambuc for (i = 0; protocolEncodingName[i]; i++) {
3400*1230fdc1SLionel Sambuc if (i == sizeof(encodingBuf) - 1
3401*1230fdc1SLionel Sambuc || (protocolEncodingName[i] & ~0x7f) != 0) {
3402*1230fdc1SLionel Sambuc encodingBuf[0] = '\0';
3403*1230fdc1SLionel Sambuc break;
3404*1230fdc1SLionel Sambuc }
3405*1230fdc1SLionel Sambuc encodingBuf[i] = (char)protocolEncodingName[i];
3406*1230fdc1SLionel Sambuc }
3407*1230fdc1SLionel Sambuc encodingBuf[i] = '\0';
3408*1230fdc1SLionel Sambuc s = encodingBuf;
3409*1230fdc1SLionel Sambuc }
3410*1230fdc1SLionel Sambuc #else
3411*1230fdc1SLionel Sambuc s = protocolEncodingName;
3412*1230fdc1SLionel Sambuc #endif
3413*1230fdc1SLionel Sambuc if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s))
3414*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3415*1230fdc1SLionel Sambuc return handleUnknownEncoding(parser, protocolEncodingName);
3416*1230fdc1SLionel Sambuc }
3417*1230fdc1SLionel Sambuc
3418*1230fdc1SLionel Sambuc static enum XML_Error
processXmlDecl(XML_Parser parser,int isGeneralTextEntity,const char * s,const char * next)3419*1230fdc1SLionel Sambuc processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
3420*1230fdc1SLionel Sambuc const char *s, const char *next)
3421*1230fdc1SLionel Sambuc {
3422*1230fdc1SLionel Sambuc const char *encodingName = NULL;
3423*1230fdc1SLionel Sambuc const XML_Char *storedEncName = NULL;
3424*1230fdc1SLionel Sambuc const ENCODING *newEncoding = NULL;
3425*1230fdc1SLionel Sambuc const char *version = NULL;
3426*1230fdc1SLionel Sambuc const char *versionend;
3427*1230fdc1SLionel Sambuc const XML_Char *storedversion = NULL;
3428*1230fdc1SLionel Sambuc int standalone = -1;
3429*1230fdc1SLionel Sambuc if (!(ns
3430*1230fdc1SLionel Sambuc ? XmlParseXmlDeclNS
3431*1230fdc1SLionel Sambuc : XmlParseXmlDecl)(isGeneralTextEntity,
3432*1230fdc1SLionel Sambuc encoding,
3433*1230fdc1SLionel Sambuc s,
3434*1230fdc1SLionel Sambuc next,
3435*1230fdc1SLionel Sambuc &eventPtr,
3436*1230fdc1SLionel Sambuc &version,
3437*1230fdc1SLionel Sambuc &versionend,
3438*1230fdc1SLionel Sambuc &encodingName,
3439*1230fdc1SLionel Sambuc &newEncoding,
3440*1230fdc1SLionel Sambuc &standalone)) {
3441*1230fdc1SLionel Sambuc if (isGeneralTextEntity)
3442*1230fdc1SLionel Sambuc return XML_ERROR_TEXT_DECL;
3443*1230fdc1SLionel Sambuc else
3444*1230fdc1SLionel Sambuc return XML_ERROR_XML_DECL;
3445*1230fdc1SLionel Sambuc }
3446*1230fdc1SLionel Sambuc if (!isGeneralTextEntity && standalone == 1) {
3447*1230fdc1SLionel Sambuc _dtd->standalone = XML_TRUE;
3448*1230fdc1SLionel Sambuc #ifdef XML_DTD
3449*1230fdc1SLionel Sambuc if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
3450*1230fdc1SLionel Sambuc paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
3451*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3452*1230fdc1SLionel Sambuc }
3453*1230fdc1SLionel Sambuc if (xmlDeclHandler) {
3454*1230fdc1SLionel Sambuc if (encodingName != NULL) {
3455*1230fdc1SLionel Sambuc storedEncName = poolStoreString(&temp2Pool,
3456*1230fdc1SLionel Sambuc encoding,
3457*1230fdc1SLionel Sambuc encodingName,
3458*1230fdc1SLionel Sambuc encodingName
3459*1230fdc1SLionel Sambuc + XmlNameLength(encoding, encodingName));
3460*1230fdc1SLionel Sambuc if (!storedEncName)
3461*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3462*1230fdc1SLionel Sambuc poolFinish(&temp2Pool);
3463*1230fdc1SLionel Sambuc }
3464*1230fdc1SLionel Sambuc if (version) {
3465*1230fdc1SLionel Sambuc storedversion = poolStoreString(&temp2Pool,
3466*1230fdc1SLionel Sambuc encoding,
3467*1230fdc1SLionel Sambuc version,
3468*1230fdc1SLionel Sambuc versionend - encoding->minBytesPerChar);
3469*1230fdc1SLionel Sambuc if (!storedversion)
3470*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3471*1230fdc1SLionel Sambuc }
3472*1230fdc1SLionel Sambuc xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone);
3473*1230fdc1SLionel Sambuc }
3474*1230fdc1SLionel Sambuc else if (defaultHandler)
3475*1230fdc1SLionel Sambuc reportDefault(parser, encoding, s, next);
3476*1230fdc1SLionel Sambuc if (protocolEncodingName == NULL) {
3477*1230fdc1SLionel Sambuc if (newEncoding) {
3478*1230fdc1SLionel Sambuc if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) {
3479*1230fdc1SLionel Sambuc eventPtr = encodingName;
3480*1230fdc1SLionel Sambuc return XML_ERROR_INCORRECT_ENCODING;
3481*1230fdc1SLionel Sambuc }
3482*1230fdc1SLionel Sambuc encoding = newEncoding;
3483*1230fdc1SLionel Sambuc }
3484*1230fdc1SLionel Sambuc else if (encodingName) {
3485*1230fdc1SLionel Sambuc enum XML_Error result;
3486*1230fdc1SLionel Sambuc if (!storedEncName) {
3487*1230fdc1SLionel Sambuc storedEncName = poolStoreString(
3488*1230fdc1SLionel Sambuc &temp2Pool, encoding, encodingName,
3489*1230fdc1SLionel Sambuc encodingName + XmlNameLength(encoding, encodingName));
3490*1230fdc1SLionel Sambuc if (!storedEncName)
3491*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3492*1230fdc1SLionel Sambuc }
3493*1230fdc1SLionel Sambuc result = handleUnknownEncoding(parser, storedEncName);
3494*1230fdc1SLionel Sambuc poolClear(&temp2Pool);
3495*1230fdc1SLionel Sambuc if (result == XML_ERROR_UNKNOWN_ENCODING)
3496*1230fdc1SLionel Sambuc eventPtr = encodingName;
3497*1230fdc1SLionel Sambuc return result;
3498*1230fdc1SLionel Sambuc }
3499*1230fdc1SLionel Sambuc }
3500*1230fdc1SLionel Sambuc
3501*1230fdc1SLionel Sambuc if (storedEncName || storedversion)
3502*1230fdc1SLionel Sambuc poolClear(&temp2Pool);
3503*1230fdc1SLionel Sambuc
3504*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3505*1230fdc1SLionel Sambuc }
3506*1230fdc1SLionel Sambuc
3507*1230fdc1SLionel Sambuc static enum XML_Error
handleUnknownEncoding(XML_Parser parser,const XML_Char * encodingName)3508*1230fdc1SLionel Sambuc handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName)
3509*1230fdc1SLionel Sambuc {
3510*1230fdc1SLionel Sambuc if (unknownEncodingHandler) {
3511*1230fdc1SLionel Sambuc XML_Encoding info;
3512*1230fdc1SLionel Sambuc int i;
3513*1230fdc1SLionel Sambuc for (i = 0; i < 256; i++)
3514*1230fdc1SLionel Sambuc info.map[i] = -1;
3515*1230fdc1SLionel Sambuc info.convert = NULL;
3516*1230fdc1SLionel Sambuc info.data = NULL;
3517*1230fdc1SLionel Sambuc info.release = NULL;
3518*1230fdc1SLionel Sambuc if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName,
3519*1230fdc1SLionel Sambuc &info)) {
3520*1230fdc1SLionel Sambuc ENCODING *enc;
3521*1230fdc1SLionel Sambuc unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding());
3522*1230fdc1SLionel Sambuc if (!unknownEncodingMem) {
3523*1230fdc1SLionel Sambuc if (info.release)
3524*1230fdc1SLionel Sambuc info.release(info.data);
3525*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3526*1230fdc1SLionel Sambuc }
3527*1230fdc1SLionel Sambuc enc = (ns
3528*1230fdc1SLionel Sambuc ? XmlInitUnknownEncodingNS
3529*1230fdc1SLionel Sambuc : XmlInitUnknownEncoding)(unknownEncodingMem,
3530*1230fdc1SLionel Sambuc info.map,
3531*1230fdc1SLionel Sambuc info.convert,
3532*1230fdc1SLionel Sambuc info.data);
3533*1230fdc1SLionel Sambuc if (enc) {
3534*1230fdc1SLionel Sambuc unknownEncodingData = info.data;
3535*1230fdc1SLionel Sambuc unknownEncodingRelease = info.release;
3536*1230fdc1SLionel Sambuc encoding = enc;
3537*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3538*1230fdc1SLionel Sambuc }
3539*1230fdc1SLionel Sambuc }
3540*1230fdc1SLionel Sambuc if (info.release != NULL)
3541*1230fdc1SLionel Sambuc info.release(info.data);
3542*1230fdc1SLionel Sambuc }
3543*1230fdc1SLionel Sambuc return XML_ERROR_UNKNOWN_ENCODING;
3544*1230fdc1SLionel Sambuc }
3545*1230fdc1SLionel Sambuc
3546*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
prologInitProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3547*1230fdc1SLionel Sambuc prologInitProcessor(XML_Parser parser,
3548*1230fdc1SLionel Sambuc const char *s,
3549*1230fdc1SLionel Sambuc const char *end,
3550*1230fdc1SLionel Sambuc const char **nextPtr)
3551*1230fdc1SLionel Sambuc {
3552*1230fdc1SLionel Sambuc enum XML_Error result = initializeEncoding(parser);
3553*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3554*1230fdc1SLionel Sambuc return result;
3555*1230fdc1SLionel Sambuc processor = prologProcessor;
3556*1230fdc1SLionel Sambuc return prologProcessor(parser, s, end, nextPtr);
3557*1230fdc1SLionel Sambuc }
3558*1230fdc1SLionel Sambuc
3559*1230fdc1SLionel Sambuc #ifdef XML_DTD
3560*1230fdc1SLionel Sambuc
3561*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalParEntInitProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3562*1230fdc1SLionel Sambuc externalParEntInitProcessor(XML_Parser parser,
3563*1230fdc1SLionel Sambuc const char *s,
3564*1230fdc1SLionel Sambuc const char *end,
3565*1230fdc1SLionel Sambuc const char **nextPtr)
3566*1230fdc1SLionel Sambuc {
3567*1230fdc1SLionel Sambuc enum XML_Error result = initializeEncoding(parser);
3568*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3569*1230fdc1SLionel Sambuc return result;
3570*1230fdc1SLionel Sambuc
3571*1230fdc1SLionel Sambuc /* we know now that XML_Parse(Buffer) has been called,
3572*1230fdc1SLionel Sambuc so we consider the external parameter entity read */
3573*1230fdc1SLionel Sambuc _dtd->paramEntityRead = XML_TRUE;
3574*1230fdc1SLionel Sambuc
3575*1230fdc1SLionel Sambuc if (prologState.inEntityValue) {
3576*1230fdc1SLionel Sambuc processor = entityValueInitProcessor;
3577*1230fdc1SLionel Sambuc return entityValueInitProcessor(parser, s, end, nextPtr);
3578*1230fdc1SLionel Sambuc }
3579*1230fdc1SLionel Sambuc else {
3580*1230fdc1SLionel Sambuc processor = externalParEntProcessor;
3581*1230fdc1SLionel Sambuc return externalParEntProcessor(parser, s, end, nextPtr);
3582*1230fdc1SLionel Sambuc }
3583*1230fdc1SLionel Sambuc }
3584*1230fdc1SLionel Sambuc
3585*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
entityValueInitProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3586*1230fdc1SLionel Sambuc entityValueInitProcessor(XML_Parser parser,
3587*1230fdc1SLionel Sambuc const char *s,
3588*1230fdc1SLionel Sambuc const char *end,
3589*1230fdc1SLionel Sambuc const char **nextPtr)
3590*1230fdc1SLionel Sambuc {
3591*1230fdc1SLionel Sambuc int tok;
3592*1230fdc1SLionel Sambuc const char *start = s;
3593*1230fdc1SLionel Sambuc const char *next = start;
3594*1230fdc1SLionel Sambuc eventPtr = start;
3595*1230fdc1SLionel Sambuc
3596*1230fdc1SLionel Sambuc for (;;) {
3597*1230fdc1SLionel Sambuc tok = XmlPrologTok(encoding, start, end, &next);
3598*1230fdc1SLionel Sambuc eventEndPtr = next;
3599*1230fdc1SLionel Sambuc if (tok <= 0) {
3600*1230fdc1SLionel Sambuc if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
3601*1230fdc1SLionel Sambuc *nextPtr = s;
3602*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3603*1230fdc1SLionel Sambuc }
3604*1230fdc1SLionel Sambuc switch (tok) {
3605*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3606*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3607*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3608*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
3609*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3610*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3611*1230fdc1SLionel Sambuc case XML_TOK_NONE: /* start == end */
3612*1230fdc1SLionel Sambuc default:
3613*1230fdc1SLionel Sambuc break;
3614*1230fdc1SLionel Sambuc }
3615*1230fdc1SLionel Sambuc /* found end of entity value - can store it now */
3616*1230fdc1SLionel Sambuc return storeEntityValue(parser, encoding, s, end);
3617*1230fdc1SLionel Sambuc }
3618*1230fdc1SLionel Sambuc else if (tok == XML_TOK_XML_DECL) {
3619*1230fdc1SLionel Sambuc enum XML_Error result;
3620*1230fdc1SLionel Sambuc result = processXmlDecl(parser, 0, start, next);
3621*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3622*1230fdc1SLionel Sambuc return result;
3623*1230fdc1SLionel Sambuc switch (ps_parsing) {
3624*1230fdc1SLionel Sambuc case XML_SUSPENDED:
3625*1230fdc1SLionel Sambuc *nextPtr = next;
3626*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3627*1230fdc1SLionel Sambuc case XML_FINISHED:
3628*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
3629*1230fdc1SLionel Sambuc default:
3630*1230fdc1SLionel Sambuc *nextPtr = next;
3631*1230fdc1SLionel Sambuc }
3632*1230fdc1SLionel Sambuc /* stop scanning for text declaration - we found one */
3633*1230fdc1SLionel Sambuc processor = entityValueProcessor;
3634*1230fdc1SLionel Sambuc return entityValueProcessor(parser, next, end, nextPtr);
3635*1230fdc1SLionel Sambuc }
3636*1230fdc1SLionel Sambuc /* If we are at the end of the buffer, this would cause XmlPrologTok to
3637*1230fdc1SLionel Sambuc return XML_TOK_NONE on the next call, which would then cause the
3638*1230fdc1SLionel Sambuc function to exit with *nextPtr set to s - that is what we want for other
3639*1230fdc1SLionel Sambuc tokens, but not for the BOM - we would rather like to skip it;
3640*1230fdc1SLionel Sambuc then, when this routine is entered the next time, XmlPrologTok will
3641*1230fdc1SLionel Sambuc return XML_TOK_INVALID, since the BOM is still in the buffer
3642*1230fdc1SLionel Sambuc */
3643*1230fdc1SLionel Sambuc else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) {
3644*1230fdc1SLionel Sambuc *nextPtr = next;
3645*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3646*1230fdc1SLionel Sambuc }
3647*1230fdc1SLionel Sambuc start = next;
3648*1230fdc1SLionel Sambuc eventPtr = start;
3649*1230fdc1SLionel Sambuc }
3650*1230fdc1SLionel Sambuc }
3651*1230fdc1SLionel Sambuc
3652*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
externalParEntProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3653*1230fdc1SLionel Sambuc externalParEntProcessor(XML_Parser parser,
3654*1230fdc1SLionel Sambuc const char *s,
3655*1230fdc1SLionel Sambuc const char *end,
3656*1230fdc1SLionel Sambuc const char **nextPtr)
3657*1230fdc1SLionel Sambuc {
3658*1230fdc1SLionel Sambuc const char *next = s;
3659*1230fdc1SLionel Sambuc int tok;
3660*1230fdc1SLionel Sambuc
3661*1230fdc1SLionel Sambuc tok = XmlPrologTok(encoding, s, end, &next);
3662*1230fdc1SLionel Sambuc if (tok <= 0) {
3663*1230fdc1SLionel Sambuc if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
3664*1230fdc1SLionel Sambuc *nextPtr = s;
3665*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3666*1230fdc1SLionel Sambuc }
3667*1230fdc1SLionel Sambuc switch (tok) {
3668*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3669*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3670*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3671*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
3672*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3673*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3674*1230fdc1SLionel Sambuc case XML_TOK_NONE: /* start == end */
3675*1230fdc1SLionel Sambuc default:
3676*1230fdc1SLionel Sambuc break;
3677*1230fdc1SLionel Sambuc }
3678*1230fdc1SLionel Sambuc }
3679*1230fdc1SLionel Sambuc /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM.
3680*1230fdc1SLionel Sambuc However, when parsing an external subset, doProlog will not accept a BOM
3681*1230fdc1SLionel Sambuc as valid, and report a syntax error, so we have to skip the BOM
3682*1230fdc1SLionel Sambuc */
3683*1230fdc1SLionel Sambuc else if (tok == XML_TOK_BOM) {
3684*1230fdc1SLionel Sambuc s = next;
3685*1230fdc1SLionel Sambuc tok = XmlPrologTok(encoding, s, end, &next);
3686*1230fdc1SLionel Sambuc }
3687*1230fdc1SLionel Sambuc
3688*1230fdc1SLionel Sambuc processor = prologProcessor;
3689*1230fdc1SLionel Sambuc return doProlog(parser, encoding, s, end, tok, next,
3690*1230fdc1SLionel Sambuc nextPtr, (XML_Bool)!ps_finalBuffer);
3691*1230fdc1SLionel Sambuc }
3692*1230fdc1SLionel Sambuc
3693*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
entityValueProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3694*1230fdc1SLionel Sambuc entityValueProcessor(XML_Parser parser,
3695*1230fdc1SLionel Sambuc const char *s,
3696*1230fdc1SLionel Sambuc const char *end,
3697*1230fdc1SLionel Sambuc const char **nextPtr)
3698*1230fdc1SLionel Sambuc {
3699*1230fdc1SLionel Sambuc const char *start = s;
3700*1230fdc1SLionel Sambuc const char *next = s;
3701*1230fdc1SLionel Sambuc const ENCODING *enc = encoding;
3702*1230fdc1SLionel Sambuc int tok;
3703*1230fdc1SLionel Sambuc
3704*1230fdc1SLionel Sambuc for (;;) {
3705*1230fdc1SLionel Sambuc tok = XmlPrologTok(enc, start, end, &next);
3706*1230fdc1SLionel Sambuc if (tok <= 0) {
3707*1230fdc1SLionel Sambuc if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
3708*1230fdc1SLionel Sambuc *nextPtr = s;
3709*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3710*1230fdc1SLionel Sambuc }
3711*1230fdc1SLionel Sambuc switch (tok) {
3712*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3713*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3714*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3715*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
3716*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3717*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3718*1230fdc1SLionel Sambuc case XML_TOK_NONE: /* start == end */
3719*1230fdc1SLionel Sambuc default:
3720*1230fdc1SLionel Sambuc break;
3721*1230fdc1SLionel Sambuc }
3722*1230fdc1SLionel Sambuc /* found end of entity value - can store it now */
3723*1230fdc1SLionel Sambuc return storeEntityValue(parser, enc, s, end);
3724*1230fdc1SLionel Sambuc }
3725*1230fdc1SLionel Sambuc start = next;
3726*1230fdc1SLionel Sambuc }
3727*1230fdc1SLionel Sambuc }
3728*1230fdc1SLionel Sambuc
3729*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3730*1230fdc1SLionel Sambuc
3731*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
prologProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)3732*1230fdc1SLionel Sambuc prologProcessor(XML_Parser parser,
3733*1230fdc1SLionel Sambuc const char *s,
3734*1230fdc1SLionel Sambuc const char *end,
3735*1230fdc1SLionel Sambuc const char **nextPtr)
3736*1230fdc1SLionel Sambuc {
3737*1230fdc1SLionel Sambuc const char *next = s;
3738*1230fdc1SLionel Sambuc int tok = XmlPrologTok(encoding, s, end, &next);
3739*1230fdc1SLionel Sambuc return doProlog(parser, encoding, s, end, tok, next,
3740*1230fdc1SLionel Sambuc nextPtr, (XML_Bool)!ps_finalBuffer);
3741*1230fdc1SLionel Sambuc }
3742*1230fdc1SLionel Sambuc
3743*1230fdc1SLionel Sambuc static enum XML_Error
doProlog(XML_Parser parser,const ENCODING * enc,const char * s,const char * end,int tok,const char * next,const char ** nextPtr,XML_Bool haveMore)3744*1230fdc1SLionel Sambuc doProlog(XML_Parser parser,
3745*1230fdc1SLionel Sambuc const ENCODING *enc,
3746*1230fdc1SLionel Sambuc const char *s,
3747*1230fdc1SLionel Sambuc const char *end,
3748*1230fdc1SLionel Sambuc int tok,
3749*1230fdc1SLionel Sambuc const char *next,
3750*1230fdc1SLionel Sambuc const char **nextPtr,
3751*1230fdc1SLionel Sambuc XML_Bool haveMore)
3752*1230fdc1SLionel Sambuc {
3753*1230fdc1SLionel Sambuc #ifdef XML_DTD
3754*1230fdc1SLionel Sambuc static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' };
3755*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3756*1230fdc1SLionel Sambuc static const XML_Char atypeCDATA[] =
3757*1230fdc1SLionel Sambuc { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
3758*1230fdc1SLionel Sambuc static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' };
3759*1230fdc1SLionel Sambuc static const XML_Char atypeIDREF[] =
3760*1230fdc1SLionel Sambuc { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' };
3761*1230fdc1SLionel Sambuc static const XML_Char atypeIDREFS[] =
3762*1230fdc1SLionel Sambuc { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' };
3763*1230fdc1SLionel Sambuc static const XML_Char atypeENTITY[] =
3764*1230fdc1SLionel Sambuc { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' };
3765*1230fdc1SLionel Sambuc static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N,
3766*1230fdc1SLionel Sambuc ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' };
3767*1230fdc1SLionel Sambuc static const XML_Char atypeNMTOKEN[] = {
3768*1230fdc1SLionel Sambuc ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' };
3769*1230fdc1SLionel Sambuc static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T,
3770*1230fdc1SLionel Sambuc ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' };
3771*1230fdc1SLionel Sambuc static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T,
3772*1230fdc1SLionel Sambuc ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' };
3773*1230fdc1SLionel Sambuc static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' };
3774*1230fdc1SLionel Sambuc static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' };
3775*1230fdc1SLionel Sambuc
3776*1230fdc1SLionel Sambuc /* save one level of indirection */
3777*1230fdc1SLionel Sambuc DTD * const dtd = _dtd;
3778*1230fdc1SLionel Sambuc
3779*1230fdc1SLionel Sambuc const char **eventPP;
3780*1230fdc1SLionel Sambuc const char **eventEndPP;
3781*1230fdc1SLionel Sambuc enum XML_Content_Quant quant;
3782*1230fdc1SLionel Sambuc
3783*1230fdc1SLionel Sambuc if (enc == encoding) {
3784*1230fdc1SLionel Sambuc eventPP = &eventPtr;
3785*1230fdc1SLionel Sambuc eventEndPP = &eventEndPtr;
3786*1230fdc1SLionel Sambuc }
3787*1230fdc1SLionel Sambuc else {
3788*1230fdc1SLionel Sambuc eventPP = &(openInternalEntities->internalEventPtr);
3789*1230fdc1SLionel Sambuc eventEndPP = &(openInternalEntities->internalEventEndPtr);
3790*1230fdc1SLionel Sambuc }
3791*1230fdc1SLionel Sambuc
3792*1230fdc1SLionel Sambuc for (;;) {
3793*1230fdc1SLionel Sambuc int role;
3794*1230fdc1SLionel Sambuc XML_Bool handleDefault = XML_TRUE;
3795*1230fdc1SLionel Sambuc *eventPP = s;
3796*1230fdc1SLionel Sambuc *eventEndPP = next;
3797*1230fdc1SLionel Sambuc if (tok <= 0) {
3798*1230fdc1SLionel Sambuc if (haveMore && tok != XML_TOK_INVALID) {
3799*1230fdc1SLionel Sambuc *nextPtr = s;
3800*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3801*1230fdc1SLionel Sambuc }
3802*1230fdc1SLionel Sambuc switch (tok) {
3803*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
3804*1230fdc1SLionel Sambuc *eventPP = next;
3805*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
3806*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
3807*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
3808*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
3809*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
3810*1230fdc1SLionel Sambuc case -XML_TOK_PROLOG_S:
3811*1230fdc1SLionel Sambuc tok = -tok;
3812*1230fdc1SLionel Sambuc break;
3813*1230fdc1SLionel Sambuc case XML_TOK_NONE:
3814*1230fdc1SLionel Sambuc #ifdef XML_DTD
3815*1230fdc1SLionel Sambuc /* for internal PE NOT referenced between declarations */
3816*1230fdc1SLionel Sambuc if (enc != encoding && !openInternalEntities->betweenDecl) {
3817*1230fdc1SLionel Sambuc *nextPtr = s;
3818*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3819*1230fdc1SLionel Sambuc }
3820*1230fdc1SLionel Sambuc /* WFC: PE Between Declarations - must check that PE contains
3821*1230fdc1SLionel Sambuc complete markup, not only for external PEs, but also for
3822*1230fdc1SLionel Sambuc internal PEs if the reference occurs between declarations.
3823*1230fdc1SLionel Sambuc */
3824*1230fdc1SLionel Sambuc if (isParamEntity || enc != encoding) {
3825*1230fdc1SLionel Sambuc if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc)
3826*1230fdc1SLionel Sambuc == XML_ROLE_ERROR)
3827*1230fdc1SLionel Sambuc return XML_ERROR_INCOMPLETE_PE;
3828*1230fdc1SLionel Sambuc *nextPtr = s;
3829*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
3830*1230fdc1SLionel Sambuc }
3831*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3832*1230fdc1SLionel Sambuc return XML_ERROR_NO_ELEMENTS;
3833*1230fdc1SLionel Sambuc default:
3834*1230fdc1SLionel Sambuc tok = -tok;
3835*1230fdc1SLionel Sambuc next = end;
3836*1230fdc1SLionel Sambuc break;
3837*1230fdc1SLionel Sambuc }
3838*1230fdc1SLionel Sambuc }
3839*1230fdc1SLionel Sambuc role = XmlTokenRole(&prologState, tok, s, next, enc);
3840*1230fdc1SLionel Sambuc switch (role) {
3841*1230fdc1SLionel Sambuc case XML_ROLE_XML_DECL:
3842*1230fdc1SLionel Sambuc {
3843*1230fdc1SLionel Sambuc enum XML_Error result = processXmlDecl(parser, 0, s, next);
3844*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3845*1230fdc1SLionel Sambuc return result;
3846*1230fdc1SLionel Sambuc enc = encoding;
3847*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3848*1230fdc1SLionel Sambuc }
3849*1230fdc1SLionel Sambuc break;
3850*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_NAME:
3851*1230fdc1SLionel Sambuc if (startDoctypeDeclHandler) {
3852*1230fdc1SLionel Sambuc doctypeName = poolStoreString(&tempPool, enc, s, next);
3853*1230fdc1SLionel Sambuc if (!doctypeName)
3854*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3855*1230fdc1SLionel Sambuc poolFinish(&tempPool);
3856*1230fdc1SLionel Sambuc doctypePubid = NULL;
3857*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3858*1230fdc1SLionel Sambuc }
3859*1230fdc1SLionel Sambuc doctypeSysid = NULL; /* always initialize to NULL */
3860*1230fdc1SLionel Sambuc break;
3861*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_INTERNAL_SUBSET:
3862*1230fdc1SLionel Sambuc if (startDoctypeDeclHandler) {
3863*1230fdc1SLionel Sambuc startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid,
3864*1230fdc1SLionel Sambuc doctypePubid, 1);
3865*1230fdc1SLionel Sambuc doctypeName = NULL;
3866*1230fdc1SLionel Sambuc poolClear(&tempPool);
3867*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3868*1230fdc1SLionel Sambuc }
3869*1230fdc1SLionel Sambuc break;
3870*1230fdc1SLionel Sambuc #ifdef XML_DTD
3871*1230fdc1SLionel Sambuc case XML_ROLE_TEXT_DECL:
3872*1230fdc1SLionel Sambuc {
3873*1230fdc1SLionel Sambuc enum XML_Error result = processXmlDecl(parser, 1, s, next);
3874*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
3875*1230fdc1SLionel Sambuc return result;
3876*1230fdc1SLionel Sambuc enc = encoding;
3877*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3878*1230fdc1SLionel Sambuc }
3879*1230fdc1SLionel Sambuc break;
3880*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3881*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_PUBLIC_ID:
3882*1230fdc1SLionel Sambuc #ifdef XML_DTD
3883*1230fdc1SLionel Sambuc useForeignDTD = XML_FALSE;
3884*1230fdc1SLionel Sambuc declEntity = (ENTITY *)lookup(parser,
3885*1230fdc1SLionel Sambuc &dtd->paramEntities,
3886*1230fdc1SLionel Sambuc externalSubsetName,
3887*1230fdc1SLionel Sambuc sizeof(ENTITY));
3888*1230fdc1SLionel Sambuc if (!declEntity)
3889*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3890*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3891*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = XML_TRUE;
3892*1230fdc1SLionel Sambuc if (startDoctypeDeclHandler) {
3893*1230fdc1SLionel Sambuc XML_Char *pubId;
3894*1230fdc1SLionel Sambuc if (!XmlIsPublicId(enc, s, next, eventPP))
3895*1230fdc1SLionel Sambuc return XML_ERROR_PUBLICID;
3896*1230fdc1SLionel Sambuc pubId = poolStoreString(&tempPool, enc,
3897*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
3898*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
3899*1230fdc1SLionel Sambuc if (!pubId)
3900*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3901*1230fdc1SLionel Sambuc normalizePublicId(pubId);
3902*1230fdc1SLionel Sambuc poolFinish(&tempPool);
3903*1230fdc1SLionel Sambuc doctypePubid = pubId;
3904*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3905*1230fdc1SLionel Sambuc goto alreadyChecked;
3906*1230fdc1SLionel Sambuc }
3907*1230fdc1SLionel Sambuc /* fall through */
3908*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_PUBLIC_ID:
3909*1230fdc1SLionel Sambuc if (!XmlIsPublicId(enc, s, next, eventPP))
3910*1230fdc1SLionel Sambuc return XML_ERROR_PUBLICID;
3911*1230fdc1SLionel Sambuc alreadyChecked:
3912*1230fdc1SLionel Sambuc if (dtd->keepProcessing && declEntity) {
3913*1230fdc1SLionel Sambuc XML_Char *tem = poolStoreString(&dtd->pool,
3914*1230fdc1SLionel Sambuc enc,
3915*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
3916*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
3917*1230fdc1SLionel Sambuc if (!tem)
3918*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3919*1230fdc1SLionel Sambuc normalizePublicId(tem);
3920*1230fdc1SLionel Sambuc declEntity->publicId = tem;
3921*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
3922*1230fdc1SLionel Sambuc if (entityDeclHandler)
3923*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3924*1230fdc1SLionel Sambuc }
3925*1230fdc1SLionel Sambuc break;
3926*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_CLOSE:
3927*1230fdc1SLionel Sambuc if (doctypeName) {
3928*1230fdc1SLionel Sambuc startDoctypeDeclHandler(handlerArg, doctypeName,
3929*1230fdc1SLionel Sambuc doctypeSysid, doctypePubid, 0);
3930*1230fdc1SLionel Sambuc poolClear(&tempPool);
3931*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3932*1230fdc1SLionel Sambuc }
3933*1230fdc1SLionel Sambuc /* doctypeSysid will be non-NULL in the case of a previous
3934*1230fdc1SLionel Sambuc XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler
3935*1230fdc1SLionel Sambuc was not set, indicating an external subset
3936*1230fdc1SLionel Sambuc */
3937*1230fdc1SLionel Sambuc #ifdef XML_DTD
3938*1230fdc1SLionel Sambuc if (doctypeSysid || useForeignDTD) {
3939*1230fdc1SLionel Sambuc XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3940*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = XML_TRUE;
3941*1230fdc1SLionel Sambuc if (paramEntityParsing && externalEntityRefHandler) {
3942*1230fdc1SLionel Sambuc ENTITY *entity = (ENTITY *)lookup(parser,
3943*1230fdc1SLionel Sambuc &dtd->paramEntities,
3944*1230fdc1SLionel Sambuc externalSubsetName,
3945*1230fdc1SLionel Sambuc sizeof(ENTITY));
3946*1230fdc1SLionel Sambuc if (!entity)
3947*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3948*1230fdc1SLionel Sambuc if (useForeignDTD)
3949*1230fdc1SLionel Sambuc entity->base = curBase;
3950*1230fdc1SLionel Sambuc dtd->paramEntityRead = XML_FALSE;
3951*1230fdc1SLionel Sambuc if (!externalEntityRefHandler(externalEntityRefHandlerArg,
3952*1230fdc1SLionel Sambuc 0,
3953*1230fdc1SLionel Sambuc entity->base,
3954*1230fdc1SLionel Sambuc entity->systemId,
3955*1230fdc1SLionel Sambuc entity->publicId))
3956*1230fdc1SLionel Sambuc return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
3957*1230fdc1SLionel Sambuc if (dtd->paramEntityRead) {
3958*1230fdc1SLionel Sambuc if (!dtd->standalone &&
3959*1230fdc1SLionel Sambuc notStandaloneHandler &&
3960*1230fdc1SLionel Sambuc !notStandaloneHandler(handlerArg))
3961*1230fdc1SLionel Sambuc return XML_ERROR_NOT_STANDALONE;
3962*1230fdc1SLionel Sambuc }
3963*1230fdc1SLionel Sambuc /* if we didn't read the foreign DTD then this means that there
3964*1230fdc1SLionel Sambuc is no external subset and we must reset dtd->hasParamEntityRefs
3965*1230fdc1SLionel Sambuc */
3966*1230fdc1SLionel Sambuc else if (!doctypeSysid)
3967*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = hadParamEntityRefs;
3968*1230fdc1SLionel Sambuc /* end of DTD - no need to update dtd->keepProcessing */
3969*1230fdc1SLionel Sambuc }
3970*1230fdc1SLionel Sambuc useForeignDTD = XML_FALSE;
3971*1230fdc1SLionel Sambuc }
3972*1230fdc1SLionel Sambuc #endif /* XML_DTD */
3973*1230fdc1SLionel Sambuc if (endDoctypeDeclHandler) {
3974*1230fdc1SLionel Sambuc endDoctypeDeclHandler(handlerArg);
3975*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
3976*1230fdc1SLionel Sambuc }
3977*1230fdc1SLionel Sambuc break;
3978*1230fdc1SLionel Sambuc case XML_ROLE_INSTANCE_START:
3979*1230fdc1SLionel Sambuc #ifdef XML_DTD
3980*1230fdc1SLionel Sambuc /* if there is no DOCTYPE declaration then now is the
3981*1230fdc1SLionel Sambuc last chance to read the foreign DTD
3982*1230fdc1SLionel Sambuc */
3983*1230fdc1SLionel Sambuc if (useForeignDTD) {
3984*1230fdc1SLionel Sambuc XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3985*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = XML_TRUE;
3986*1230fdc1SLionel Sambuc if (paramEntityParsing && externalEntityRefHandler) {
3987*1230fdc1SLionel Sambuc ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities,
3988*1230fdc1SLionel Sambuc externalSubsetName,
3989*1230fdc1SLionel Sambuc sizeof(ENTITY));
3990*1230fdc1SLionel Sambuc if (!entity)
3991*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
3992*1230fdc1SLionel Sambuc entity->base = curBase;
3993*1230fdc1SLionel Sambuc dtd->paramEntityRead = XML_FALSE;
3994*1230fdc1SLionel Sambuc if (!externalEntityRefHandler(externalEntityRefHandlerArg,
3995*1230fdc1SLionel Sambuc 0,
3996*1230fdc1SLionel Sambuc entity->base,
3997*1230fdc1SLionel Sambuc entity->systemId,
3998*1230fdc1SLionel Sambuc entity->publicId))
3999*1230fdc1SLionel Sambuc return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
4000*1230fdc1SLionel Sambuc if (dtd->paramEntityRead) {
4001*1230fdc1SLionel Sambuc if (!dtd->standalone &&
4002*1230fdc1SLionel Sambuc notStandaloneHandler &&
4003*1230fdc1SLionel Sambuc !notStandaloneHandler(handlerArg))
4004*1230fdc1SLionel Sambuc return XML_ERROR_NOT_STANDALONE;
4005*1230fdc1SLionel Sambuc }
4006*1230fdc1SLionel Sambuc /* if we didn't read the foreign DTD then this means that there
4007*1230fdc1SLionel Sambuc is no external subset and we must reset dtd->hasParamEntityRefs
4008*1230fdc1SLionel Sambuc */
4009*1230fdc1SLionel Sambuc else
4010*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = hadParamEntityRefs;
4011*1230fdc1SLionel Sambuc /* end of DTD - no need to update dtd->keepProcessing */
4012*1230fdc1SLionel Sambuc }
4013*1230fdc1SLionel Sambuc }
4014*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4015*1230fdc1SLionel Sambuc processor = contentProcessor;
4016*1230fdc1SLionel Sambuc return contentProcessor(parser, s, end, nextPtr);
4017*1230fdc1SLionel Sambuc case XML_ROLE_ATTLIST_ELEMENT_NAME:
4018*1230fdc1SLionel Sambuc declElementType = getElementType(parser, enc, s, next);
4019*1230fdc1SLionel Sambuc if (!declElementType)
4020*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4021*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4022*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_NAME:
4023*1230fdc1SLionel Sambuc declAttributeId = getAttributeId(parser, enc, s, next);
4024*1230fdc1SLionel Sambuc if (!declAttributeId)
4025*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4026*1230fdc1SLionel Sambuc declAttributeIsCdata = XML_FALSE;
4027*1230fdc1SLionel Sambuc declAttributeType = NULL;
4028*1230fdc1SLionel Sambuc declAttributeIsId = XML_FALSE;
4029*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4030*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_CDATA:
4031*1230fdc1SLionel Sambuc declAttributeIsCdata = XML_TRUE;
4032*1230fdc1SLionel Sambuc declAttributeType = atypeCDATA;
4033*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4034*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_ID:
4035*1230fdc1SLionel Sambuc declAttributeIsId = XML_TRUE;
4036*1230fdc1SLionel Sambuc declAttributeType = atypeID;
4037*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4038*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_IDREF:
4039*1230fdc1SLionel Sambuc declAttributeType = atypeIDREF;
4040*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4041*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_IDREFS:
4042*1230fdc1SLionel Sambuc declAttributeType = atypeIDREFS;
4043*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4044*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_ENTITY:
4045*1230fdc1SLionel Sambuc declAttributeType = atypeENTITY;
4046*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4047*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES:
4048*1230fdc1SLionel Sambuc declAttributeType = atypeENTITIES;
4049*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4050*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN:
4051*1230fdc1SLionel Sambuc declAttributeType = atypeNMTOKEN;
4052*1230fdc1SLionel Sambuc goto checkAttListDeclHandler;
4053*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS:
4054*1230fdc1SLionel Sambuc declAttributeType = atypeNMTOKENS;
4055*1230fdc1SLionel Sambuc checkAttListDeclHandler:
4056*1230fdc1SLionel Sambuc if (dtd->keepProcessing && attlistDeclHandler)
4057*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4058*1230fdc1SLionel Sambuc break;
4059*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_ENUM_VALUE:
4060*1230fdc1SLionel Sambuc case XML_ROLE_ATTRIBUTE_NOTATION_VALUE:
4061*1230fdc1SLionel Sambuc if (dtd->keepProcessing && attlistDeclHandler) {
4062*1230fdc1SLionel Sambuc const XML_Char *prefix;
4063*1230fdc1SLionel Sambuc if (declAttributeType) {
4064*1230fdc1SLionel Sambuc prefix = enumValueSep;
4065*1230fdc1SLionel Sambuc }
4066*1230fdc1SLionel Sambuc else {
4067*1230fdc1SLionel Sambuc prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE
4068*1230fdc1SLionel Sambuc ? notationPrefix
4069*1230fdc1SLionel Sambuc : enumValueStart);
4070*1230fdc1SLionel Sambuc }
4071*1230fdc1SLionel Sambuc if (!poolAppendString(&tempPool, prefix))
4072*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4073*1230fdc1SLionel Sambuc if (!poolAppend(&tempPool, enc, s, next))
4074*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4075*1230fdc1SLionel Sambuc declAttributeType = tempPool.start;
4076*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4077*1230fdc1SLionel Sambuc }
4078*1230fdc1SLionel Sambuc break;
4079*1230fdc1SLionel Sambuc case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE:
4080*1230fdc1SLionel Sambuc case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE:
4081*1230fdc1SLionel Sambuc if (dtd->keepProcessing) {
4082*1230fdc1SLionel Sambuc if (!defineAttribute(declElementType, declAttributeId,
4083*1230fdc1SLionel Sambuc declAttributeIsCdata, declAttributeIsId,
4084*1230fdc1SLionel Sambuc 0, parser))
4085*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4086*1230fdc1SLionel Sambuc if (attlistDeclHandler && declAttributeType) {
4087*1230fdc1SLionel Sambuc if (*declAttributeType == XML_T(ASCII_LPAREN)
4088*1230fdc1SLionel Sambuc || (*declAttributeType == XML_T(ASCII_N)
4089*1230fdc1SLionel Sambuc && declAttributeType[1] == XML_T(ASCII_O))) {
4090*1230fdc1SLionel Sambuc /* Enumerated or Notation type */
4091*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN))
4092*1230fdc1SLionel Sambuc || !poolAppendChar(&tempPool, XML_T('\0')))
4093*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4094*1230fdc1SLionel Sambuc declAttributeType = tempPool.start;
4095*1230fdc1SLionel Sambuc poolFinish(&tempPool);
4096*1230fdc1SLionel Sambuc }
4097*1230fdc1SLionel Sambuc *eventEndPP = s;
4098*1230fdc1SLionel Sambuc attlistDeclHandler(handlerArg, declElementType->name,
4099*1230fdc1SLionel Sambuc declAttributeId->name, declAttributeType,
4100*1230fdc1SLionel Sambuc 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE);
4101*1230fdc1SLionel Sambuc poolClear(&tempPool);
4102*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4103*1230fdc1SLionel Sambuc }
4104*1230fdc1SLionel Sambuc }
4105*1230fdc1SLionel Sambuc break;
4106*1230fdc1SLionel Sambuc case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE:
4107*1230fdc1SLionel Sambuc case XML_ROLE_FIXED_ATTRIBUTE_VALUE:
4108*1230fdc1SLionel Sambuc if (dtd->keepProcessing) {
4109*1230fdc1SLionel Sambuc const XML_Char *attVal;
4110*1230fdc1SLionel Sambuc enum XML_Error result =
4111*1230fdc1SLionel Sambuc storeAttributeValue(parser, enc, declAttributeIsCdata,
4112*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4113*1230fdc1SLionel Sambuc next - enc->minBytesPerChar,
4114*1230fdc1SLionel Sambuc &dtd->pool);
4115*1230fdc1SLionel Sambuc if (result)
4116*1230fdc1SLionel Sambuc return result;
4117*1230fdc1SLionel Sambuc attVal = poolStart(&dtd->pool);
4118*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
4119*1230fdc1SLionel Sambuc /* ID attributes aren't allowed to have a default */
4120*1230fdc1SLionel Sambuc if (!defineAttribute(declElementType, declAttributeId,
4121*1230fdc1SLionel Sambuc declAttributeIsCdata, XML_FALSE, attVal, parser))
4122*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4123*1230fdc1SLionel Sambuc if (attlistDeclHandler && declAttributeType) {
4124*1230fdc1SLionel Sambuc if (*declAttributeType == XML_T(ASCII_LPAREN)
4125*1230fdc1SLionel Sambuc || (*declAttributeType == XML_T(ASCII_N)
4126*1230fdc1SLionel Sambuc && declAttributeType[1] == XML_T(ASCII_O))) {
4127*1230fdc1SLionel Sambuc /* Enumerated or Notation type */
4128*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN))
4129*1230fdc1SLionel Sambuc || !poolAppendChar(&tempPool, XML_T('\0')))
4130*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4131*1230fdc1SLionel Sambuc declAttributeType = tempPool.start;
4132*1230fdc1SLionel Sambuc poolFinish(&tempPool);
4133*1230fdc1SLionel Sambuc }
4134*1230fdc1SLionel Sambuc *eventEndPP = s;
4135*1230fdc1SLionel Sambuc attlistDeclHandler(handlerArg, declElementType->name,
4136*1230fdc1SLionel Sambuc declAttributeId->name, declAttributeType,
4137*1230fdc1SLionel Sambuc attVal,
4138*1230fdc1SLionel Sambuc role == XML_ROLE_FIXED_ATTRIBUTE_VALUE);
4139*1230fdc1SLionel Sambuc poolClear(&tempPool);
4140*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4141*1230fdc1SLionel Sambuc }
4142*1230fdc1SLionel Sambuc }
4143*1230fdc1SLionel Sambuc break;
4144*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_VALUE:
4145*1230fdc1SLionel Sambuc if (dtd->keepProcessing) {
4146*1230fdc1SLionel Sambuc enum XML_Error result = storeEntityValue(parser, enc,
4147*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4148*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4149*1230fdc1SLionel Sambuc if (declEntity) {
4150*1230fdc1SLionel Sambuc declEntity->textPtr = poolStart(&dtd->entityValuePool);
4151*1230fdc1SLionel Sambuc declEntity->textLen = (int)(poolLength(&dtd->entityValuePool));
4152*1230fdc1SLionel Sambuc poolFinish(&dtd->entityValuePool);
4153*1230fdc1SLionel Sambuc if (entityDeclHandler) {
4154*1230fdc1SLionel Sambuc *eventEndPP = s;
4155*1230fdc1SLionel Sambuc entityDeclHandler(handlerArg,
4156*1230fdc1SLionel Sambuc declEntity->name,
4157*1230fdc1SLionel Sambuc declEntity->is_param,
4158*1230fdc1SLionel Sambuc declEntity->textPtr,
4159*1230fdc1SLionel Sambuc declEntity->textLen,
4160*1230fdc1SLionel Sambuc curBase, 0, 0, 0);
4161*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4162*1230fdc1SLionel Sambuc }
4163*1230fdc1SLionel Sambuc }
4164*1230fdc1SLionel Sambuc else
4165*1230fdc1SLionel Sambuc poolDiscard(&dtd->entityValuePool);
4166*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
4167*1230fdc1SLionel Sambuc return result;
4168*1230fdc1SLionel Sambuc }
4169*1230fdc1SLionel Sambuc break;
4170*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_SYSTEM_ID:
4171*1230fdc1SLionel Sambuc #ifdef XML_DTD
4172*1230fdc1SLionel Sambuc useForeignDTD = XML_FALSE;
4173*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4174*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = XML_TRUE;
4175*1230fdc1SLionel Sambuc if (startDoctypeDeclHandler) {
4176*1230fdc1SLionel Sambuc doctypeSysid = poolStoreString(&tempPool, enc,
4177*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4178*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4179*1230fdc1SLionel Sambuc if (doctypeSysid == NULL)
4180*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4181*1230fdc1SLionel Sambuc poolFinish(&tempPool);
4182*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4183*1230fdc1SLionel Sambuc }
4184*1230fdc1SLionel Sambuc #ifdef XML_DTD
4185*1230fdc1SLionel Sambuc else
4186*1230fdc1SLionel Sambuc /* use externalSubsetName to make doctypeSysid non-NULL
4187*1230fdc1SLionel Sambuc for the case where no startDoctypeDeclHandler is set */
4188*1230fdc1SLionel Sambuc doctypeSysid = externalSubsetName;
4189*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4190*1230fdc1SLionel Sambuc if (!dtd->standalone
4191*1230fdc1SLionel Sambuc #ifdef XML_DTD
4192*1230fdc1SLionel Sambuc && !paramEntityParsing
4193*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4194*1230fdc1SLionel Sambuc && notStandaloneHandler
4195*1230fdc1SLionel Sambuc && !notStandaloneHandler(handlerArg))
4196*1230fdc1SLionel Sambuc return XML_ERROR_NOT_STANDALONE;
4197*1230fdc1SLionel Sambuc #ifndef XML_DTD
4198*1230fdc1SLionel Sambuc break;
4199*1230fdc1SLionel Sambuc #else /* XML_DTD */
4200*1230fdc1SLionel Sambuc if (!declEntity) {
4201*1230fdc1SLionel Sambuc declEntity = (ENTITY *)lookup(parser,
4202*1230fdc1SLionel Sambuc &dtd->paramEntities,
4203*1230fdc1SLionel Sambuc externalSubsetName,
4204*1230fdc1SLionel Sambuc sizeof(ENTITY));
4205*1230fdc1SLionel Sambuc if (!declEntity)
4206*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4207*1230fdc1SLionel Sambuc declEntity->publicId = NULL;
4208*1230fdc1SLionel Sambuc }
4209*1230fdc1SLionel Sambuc /* fall through */
4210*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4211*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_SYSTEM_ID:
4212*1230fdc1SLionel Sambuc if (dtd->keepProcessing && declEntity) {
4213*1230fdc1SLionel Sambuc declEntity->systemId = poolStoreString(&dtd->pool, enc,
4214*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4215*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4216*1230fdc1SLionel Sambuc if (!declEntity->systemId)
4217*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4218*1230fdc1SLionel Sambuc declEntity->base = curBase;
4219*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
4220*1230fdc1SLionel Sambuc if (entityDeclHandler)
4221*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4222*1230fdc1SLionel Sambuc }
4223*1230fdc1SLionel Sambuc break;
4224*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_COMPLETE:
4225*1230fdc1SLionel Sambuc if (dtd->keepProcessing && declEntity && entityDeclHandler) {
4226*1230fdc1SLionel Sambuc *eventEndPP = s;
4227*1230fdc1SLionel Sambuc entityDeclHandler(handlerArg,
4228*1230fdc1SLionel Sambuc declEntity->name,
4229*1230fdc1SLionel Sambuc declEntity->is_param,
4230*1230fdc1SLionel Sambuc 0,0,
4231*1230fdc1SLionel Sambuc declEntity->base,
4232*1230fdc1SLionel Sambuc declEntity->systemId,
4233*1230fdc1SLionel Sambuc declEntity->publicId,
4234*1230fdc1SLionel Sambuc 0);
4235*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4236*1230fdc1SLionel Sambuc }
4237*1230fdc1SLionel Sambuc break;
4238*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_NOTATION_NAME:
4239*1230fdc1SLionel Sambuc if (dtd->keepProcessing && declEntity) {
4240*1230fdc1SLionel Sambuc declEntity->notation = poolStoreString(&dtd->pool, enc, s, next);
4241*1230fdc1SLionel Sambuc if (!declEntity->notation)
4242*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4243*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
4244*1230fdc1SLionel Sambuc if (unparsedEntityDeclHandler) {
4245*1230fdc1SLionel Sambuc *eventEndPP = s;
4246*1230fdc1SLionel Sambuc unparsedEntityDeclHandler(handlerArg,
4247*1230fdc1SLionel Sambuc declEntity->name,
4248*1230fdc1SLionel Sambuc declEntity->base,
4249*1230fdc1SLionel Sambuc declEntity->systemId,
4250*1230fdc1SLionel Sambuc declEntity->publicId,
4251*1230fdc1SLionel Sambuc declEntity->notation);
4252*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4253*1230fdc1SLionel Sambuc }
4254*1230fdc1SLionel Sambuc else if (entityDeclHandler) {
4255*1230fdc1SLionel Sambuc *eventEndPP = s;
4256*1230fdc1SLionel Sambuc entityDeclHandler(handlerArg,
4257*1230fdc1SLionel Sambuc declEntity->name,
4258*1230fdc1SLionel Sambuc 0,0,0,
4259*1230fdc1SLionel Sambuc declEntity->base,
4260*1230fdc1SLionel Sambuc declEntity->systemId,
4261*1230fdc1SLionel Sambuc declEntity->publicId,
4262*1230fdc1SLionel Sambuc declEntity->notation);
4263*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4264*1230fdc1SLionel Sambuc }
4265*1230fdc1SLionel Sambuc }
4266*1230fdc1SLionel Sambuc break;
4267*1230fdc1SLionel Sambuc case XML_ROLE_GENERAL_ENTITY_NAME:
4268*1230fdc1SLionel Sambuc {
4269*1230fdc1SLionel Sambuc if (XmlPredefinedEntityName(enc, s, next)) {
4270*1230fdc1SLionel Sambuc declEntity = NULL;
4271*1230fdc1SLionel Sambuc break;
4272*1230fdc1SLionel Sambuc }
4273*1230fdc1SLionel Sambuc if (dtd->keepProcessing) {
4274*1230fdc1SLionel Sambuc const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4275*1230fdc1SLionel Sambuc if (!name)
4276*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4277*1230fdc1SLionel Sambuc declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name,
4278*1230fdc1SLionel Sambuc sizeof(ENTITY));
4279*1230fdc1SLionel Sambuc if (!declEntity)
4280*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4281*1230fdc1SLionel Sambuc if (declEntity->name != name) {
4282*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
4283*1230fdc1SLionel Sambuc declEntity = NULL;
4284*1230fdc1SLionel Sambuc }
4285*1230fdc1SLionel Sambuc else {
4286*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
4287*1230fdc1SLionel Sambuc declEntity->publicId = NULL;
4288*1230fdc1SLionel Sambuc declEntity->is_param = XML_FALSE;
4289*1230fdc1SLionel Sambuc /* if we have a parent parser or are reading an internal parameter
4290*1230fdc1SLionel Sambuc entity, then the entity declaration is not considered "internal"
4291*1230fdc1SLionel Sambuc */
4292*1230fdc1SLionel Sambuc declEntity->is_internal = !(parentParser || openInternalEntities);
4293*1230fdc1SLionel Sambuc if (entityDeclHandler)
4294*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4295*1230fdc1SLionel Sambuc }
4296*1230fdc1SLionel Sambuc }
4297*1230fdc1SLionel Sambuc else {
4298*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
4299*1230fdc1SLionel Sambuc declEntity = NULL;
4300*1230fdc1SLionel Sambuc }
4301*1230fdc1SLionel Sambuc }
4302*1230fdc1SLionel Sambuc break;
4303*1230fdc1SLionel Sambuc case XML_ROLE_PARAM_ENTITY_NAME:
4304*1230fdc1SLionel Sambuc #ifdef XML_DTD
4305*1230fdc1SLionel Sambuc if (dtd->keepProcessing) {
4306*1230fdc1SLionel Sambuc const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4307*1230fdc1SLionel Sambuc if (!name)
4308*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4309*1230fdc1SLionel Sambuc declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities,
4310*1230fdc1SLionel Sambuc name, sizeof(ENTITY));
4311*1230fdc1SLionel Sambuc if (!declEntity)
4312*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4313*1230fdc1SLionel Sambuc if (declEntity->name != name) {
4314*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
4315*1230fdc1SLionel Sambuc declEntity = NULL;
4316*1230fdc1SLionel Sambuc }
4317*1230fdc1SLionel Sambuc else {
4318*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
4319*1230fdc1SLionel Sambuc declEntity->publicId = NULL;
4320*1230fdc1SLionel Sambuc declEntity->is_param = XML_TRUE;
4321*1230fdc1SLionel Sambuc /* if we have a parent parser or are reading an internal parameter
4322*1230fdc1SLionel Sambuc entity, then the entity declaration is not considered "internal"
4323*1230fdc1SLionel Sambuc */
4324*1230fdc1SLionel Sambuc declEntity->is_internal = !(parentParser || openInternalEntities);
4325*1230fdc1SLionel Sambuc if (entityDeclHandler)
4326*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4327*1230fdc1SLionel Sambuc }
4328*1230fdc1SLionel Sambuc }
4329*1230fdc1SLionel Sambuc else {
4330*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
4331*1230fdc1SLionel Sambuc declEntity = NULL;
4332*1230fdc1SLionel Sambuc }
4333*1230fdc1SLionel Sambuc #else /* not XML_DTD */
4334*1230fdc1SLionel Sambuc declEntity = NULL;
4335*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4336*1230fdc1SLionel Sambuc break;
4337*1230fdc1SLionel Sambuc case XML_ROLE_NOTATION_NAME:
4338*1230fdc1SLionel Sambuc declNotationPublicId = NULL;
4339*1230fdc1SLionel Sambuc declNotationName = NULL;
4340*1230fdc1SLionel Sambuc if (notationDeclHandler) {
4341*1230fdc1SLionel Sambuc declNotationName = poolStoreString(&tempPool, enc, s, next);
4342*1230fdc1SLionel Sambuc if (!declNotationName)
4343*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4344*1230fdc1SLionel Sambuc poolFinish(&tempPool);
4345*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4346*1230fdc1SLionel Sambuc }
4347*1230fdc1SLionel Sambuc break;
4348*1230fdc1SLionel Sambuc case XML_ROLE_NOTATION_PUBLIC_ID:
4349*1230fdc1SLionel Sambuc if (!XmlIsPublicId(enc, s, next, eventPP))
4350*1230fdc1SLionel Sambuc return XML_ERROR_PUBLICID;
4351*1230fdc1SLionel Sambuc if (declNotationName) { /* means notationDeclHandler != NULL */
4352*1230fdc1SLionel Sambuc XML_Char *tem = poolStoreString(&tempPool,
4353*1230fdc1SLionel Sambuc enc,
4354*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4355*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4356*1230fdc1SLionel Sambuc if (!tem)
4357*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4358*1230fdc1SLionel Sambuc normalizePublicId(tem);
4359*1230fdc1SLionel Sambuc declNotationPublicId = tem;
4360*1230fdc1SLionel Sambuc poolFinish(&tempPool);
4361*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4362*1230fdc1SLionel Sambuc }
4363*1230fdc1SLionel Sambuc break;
4364*1230fdc1SLionel Sambuc case XML_ROLE_NOTATION_SYSTEM_ID:
4365*1230fdc1SLionel Sambuc if (declNotationName && notationDeclHandler) {
4366*1230fdc1SLionel Sambuc const XML_Char *systemId
4367*1230fdc1SLionel Sambuc = poolStoreString(&tempPool, enc,
4368*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4369*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4370*1230fdc1SLionel Sambuc if (!systemId)
4371*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4372*1230fdc1SLionel Sambuc *eventEndPP = s;
4373*1230fdc1SLionel Sambuc notationDeclHandler(handlerArg,
4374*1230fdc1SLionel Sambuc declNotationName,
4375*1230fdc1SLionel Sambuc curBase,
4376*1230fdc1SLionel Sambuc systemId,
4377*1230fdc1SLionel Sambuc declNotationPublicId);
4378*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4379*1230fdc1SLionel Sambuc }
4380*1230fdc1SLionel Sambuc poolClear(&tempPool);
4381*1230fdc1SLionel Sambuc break;
4382*1230fdc1SLionel Sambuc case XML_ROLE_NOTATION_NO_SYSTEM_ID:
4383*1230fdc1SLionel Sambuc if (declNotationPublicId && notationDeclHandler) {
4384*1230fdc1SLionel Sambuc *eventEndPP = s;
4385*1230fdc1SLionel Sambuc notationDeclHandler(handlerArg,
4386*1230fdc1SLionel Sambuc declNotationName,
4387*1230fdc1SLionel Sambuc curBase,
4388*1230fdc1SLionel Sambuc 0,
4389*1230fdc1SLionel Sambuc declNotationPublicId);
4390*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4391*1230fdc1SLionel Sambuc }
4392*1230fdc1SLionel Sambuc poolClear(&tempPool);
4393*1230fdc1SLionel Sambuc break;
4394*1230fdc1SLionel Sambuc case XML_ROLE_ERROR:
4395*1230fdc1SLionel Sambuc switch (tok) {
4396*1230fdc1SLionel Sambuc case XML_TOK_PARAM_ENTITY_REF:
4397*1230fdc1SLionel Sambuc /* PE references in internal subset are
4398*1230fdc1SLionel Sambuc not allowed within declarations. */
4399*1230fdc1SLionel Sambuc return XML_ERROR_PARAM_ENTITY_REF;
4400*1230fdc1SLionel Sambuc case XML_TOK_XML_DECL:
4401*1230fdc1SLionel Sambuc return XML_ERROR_MISPLACED_XML_PI;
4402*1230fdc1SLionel Sambuc default:
4403*1230fdc1SLionel Sambuc return XML_ERROR_SYNTAX;
4404*1230fdc1SLionel Sambuc }
4405*1230fdc1SLionel Sambuc #ifdef XML_DTD
4406*1230fdc1SLionel Sambuc case XML_ROLE_IGNORE_SECT:
4407*1230fdc1SLionel Sambuc {
4408*1230fdc1SLionel Sambuc enum XML_Error result;
4409*1230fdc1SLionel Sambuc if (defaultHandler)
4410*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
4411*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4412*1230fdc1SLionel Sambuc result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore);
4413*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
4414*1230fdc1SLionel Sambuc return result;
4415*1230fdc1SLionel Sambuc else if (!next) {
4416*1230fdc1SLionel Sambuc processor = ignoreSectionProcessor;
4417*1230fdc1SLionel Sambuc return result;
4418*1230fdc1SLionel Sambuc }
4419*1230fdc1SLionel Sambuc }
4420*1230fdc1SLionel Sambuc break;
4421*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4422*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_OPEN:
4423*1230fdc1SLionel Sambuc if (prologState.level >= groupSize) {
4424*1230fdc1SLionel Sambuc if (groupSize) {
4425*1230fdc1SLionel Sambuc char *temp = (char *)REALLOC(groupConnector, groupSize *= 2);
4426*1230fdc1SLionel Sambuc if (temp == NULL)
4427*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4428*1230fdc1SLionel Sambuc groupConnector = temp;
4429*1230fdc1SLionel Sambuc if (dtd->scaffIndex) {
4430*1230fdc1SLionel Sambuc int *temp = (int *)REALLOC(dtd->scaffIndex,
4431*1230fdc1SLionel Sambuc groupSize * sizeof(int));
4432*1230fdc1SLionel Sambuc if (temp == NULL)
4433*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4434*1230fdc1SLionel Sambuc dtd->scaffIndex = temp;
4435*1230fdc1SLionel Sambuc }
4436*1230fdc1SLionel Sambuc }
4437*1230fdc1SLionel Sambuc else {
4438*1230fdc1SLionel Sambuc groupConnector = (char *)MALLOC(groupSize = 32);
4439*1230fdc1SLionel Sambuc if (!groupConnector)
4440*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4441*1230fdc1SLionel Sambuc }
4442*1230fdc1SLionel Sambuc }
4443*1230fdc1SLionel Sambuc groupConnector[prologState.level] = 0;
4444*1230fdc1SLionel Sambuc if (dtd->in_eldecl) {
4445*1230fdc1SLionel Sambuc int myindex = nextScaffoldPart(parser);
4446*1230fdc1SLionel Sambuc if (myindex < 0)
4447*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4448*1230fdc1SLionel Sambuc dtd->scaffIndex[dtd->scaffLevel] = myindex;
4449*1230fdc1SLionel Sambuc dtd->scaffLevel++;
4450*1230fdc1SLionel Sambuc dtd->scaffold[myindex].type = XML_CTYPE_SEQ;
4451*1230fdc1SLionel Sambuc if (elementDeclHandler)
4452*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4453*1230fdc1SLionel Sambuc }
4454*1230fdc1SLionel Sambuc break;
4455*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_SEQUENCE:
4456*1230fdc1SLionel Sambuc if (groupConnector[prologState.level] == ASCII_PIPE)
4457*1230fdc1SLionel Sambuc return XML_ERROR_SYNTAX;
4458*1230fdc1SLionel Sambuc groupConnector[prologState.level] = ASCII_COMMA;
4459*1230fdc1SLionel Sambuc if (dtd->in_eldecl && elementDeclHandler)
4460*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4461*1230fdc1SLionel Sambuc break;
4462*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_CHOICE:
4463*1230fdc1SLionel Sambuc if (groupConnector[prologState.level] == ASCII_COMMA)
4464*1230fdc1SLionel Sambuc return XML_ERROR_SYNTAX;
4465*1230fdc1SLionel Sambuc if (dtd->in_eldecl
4466*1230fdc1SLionel Sambuc && !groupConnector[prologState.level]
4467*1230fdc1SLionel Sambuc && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
4468*1230fdc1SLionel Sambuc != XML_CTYPE_MIXED)
4469*1230fdc1SLionel Sambuc ) {
4470*1230fdc1SLionel Sambuc dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
4471*1230fdc1SLionel Sambuc = XML_CTYPE_CHOICE;
4472*1230fdc1SLionel Sambuc if (elementDeclHandler)
4473*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4474*1230fdc1SLionel Sambuc }
4475*1230fdc1SLionel Sambuc groupConnector[prologState.level] = ASCII_PIPE;
4476*1230fdc1SLionel Sambuc break;
4477*1230fdc1SLionel Sambuc case XML_ROLE_PARAM_ENTITY_REF:
4478*1230fdc1SLionel Sambuc #ifdef XML_DTD
4479*1230fdc1SLionel Sambuc case XML_ROLE_INNER_PARAM_ENTITY_REF:
4480*1230fdc1SLionel Sambuc dtd->hasParamEntityRefs = XML_TRUE;
4481*1230fdc1SLionel Sambuc if (!paramEntityParsing)
4482*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
4483*1230fdc1SLionel Sambuc else {
4484*1230fdc1SLionel Sambuc const XML_Char *name;
4485*1230fdc1SLionel Sambuc ENTITY *entity;
4486*1230fdc1SLionel Sambuc name = poolStoreString(&dtd->pool, enc,
4487*1230fdc1SLionel Sambuc s + enc->minBytesPerChar,
4488*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
4489*1230fdc1SLionel Sambuc if (!name)
4490*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4491*1230fdc1SLionel Sambuc entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
4492*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
4493*1230fdc1SLionel Sambuc /* first, determine if a check for an existing declaration is needed;
4494*1230fdc1SLionel Sambuc if yes, check that the entity exists, and that it is internal,
4495*1230fdc1SLionel Sambuc otherwise call the skipped entity handler
4496*1230fdc1SLionel Sambuc */
4497*1230fdc1SLionel Sambuc if (prologState.documentEntity &&
4498*1230fdc1SLionel Sambuc (dtd->standalone
4499*1230fdc1SLionel Sambuc ? !openInternalEntities
4500*1230fdc1SLionel Sambuc : !dtd->hasParamEntityRefs)) {
4501*1230fdc1SLionel Sambuc if (!entity)
4502*1230fdc1SLionel Sambuc return XML_ERROR_UNDEFINED_ENTITY;
4503*1230fdc1SLionel Sambuc else if (!entity->is_internal)
4504*1230fdc1SLionel Sambuc return XML_ERROR_ENTITY_DECLARED_IN_PE;
4505*1230fdc1SLionel Sambuc }
4506*1230fdc1SLionel Sambuc else if (!entity) {
4507*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
4508*1230fdc1SLionel Sambuc /* cannot report skipped entities in declarations */
4509*1230fdc1SLionel Sambuc if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) {
4510*1230fdc1SLionel Sambuc skippedEntityHandler(handlerArg, name, 1);
4511*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4512*1230fdc1SLionel Sambuc }
4513*1230fdc1SLionel Sambuc break;
4514*1230fdc1SLionel Sambuc }
4515*1230fdc1SLionel Sambuc if (entity->open)
4516*1230fdc1SLionel Sambuc return XML_ERROR_RECURSIVE_ENTITY_REF;
4517*1230fdc1SLionel Sambuc if (entity->textPtr) {
4518*1230fdc1SLionel Sambuc enum XML_Error result;
4519*1230fdc1SLionel Sambuc XML_Bool betweenDecl =
4520*1230fdc1SLionel Sambuc (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE);
4521*1230fdc1SLionel Sambuc result = processInternalEntity(parser, entity, betweenDecl);
4522*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
4523*1230fdc1SLionel Sambuc return result;
4524*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4525*1230fdc1SLionel Sambuc break;
4526*1230fdc1SLionel Sambuc }
4527*1230fdc1SLionel Sambuc if (externalEntityRefHandler) {
4528*1230fdc1SLionel Sambuc dtd->paramEntityRead = XML_FALSE;
4529*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
4530*1230fdc1SLionel Sambuc if (!externalEntityRefHandler(externalEntityRefHandlerArg,
4531*1230fdc1SLionel Sambuc 0,
4532*1230fdc1SLionel Sambuc entity->base,
4533*1230fdc1SLionel Sambuc entity->systemId,
4534*1230fdc1SLionel Sambuc entity->publicId)) {
4535*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
4536*1230fdc1SLionel Sambuc return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
4537*1230fdc1SLionel Sambuc }
4538*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
4539*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4540*1230fdc1SLionel Sambuc if (!dtd->paramEntityRead) {
4541*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
4542*1230fdc1SLionel Sambuc break;
4543*1230fdc1SLionel Sambuc }
4544*1230fdc1SLionel Sambuc }
4545*1230fdc1SLionel Sambuc else {
4546*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
4547*1230fdc1SLionel Sambuc break;
4548*1230fdc1SLionel Sambuc }
4549*1230fdc1SLionel Sambuc }
4550*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4551*1230fdc1SLionel Sambuc if (!dtd->standalone &&
4552*1230fdc1SLionel Sambuc notStandaloneHandler &&
4553*1230fdc1SLionel Sambuc !notStandaloneHandler(handlerArg))
4554*1230fdc1SLionel Sambuc return XML_ERROR_NOT_STANDALONE;
4555*1230fdc1SLionel Sambuc break;
4556*1230fdc1SLionel Sambuc
4557*1230fdc1SLionel Sambuc /* Element declaration stuff */
4558*1230fdc1SLionel Sambuc
4559*1230fdc1SLionel Sambuc case XML_ROLE_ELEMENT_NAME:
4560*1230fdc1SLionel Sambuc if (elementDeclHandler) {
4561*1230fdc1SLionel Sambuc declElementType = getElementType(parser, enc, s, next);
4562*1230fdc1SLionel Sambuc if (!declElementType)
4563*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4564*1230fdc1SLionel Sambuc dtd->scaffLevel = 0;
4565*1230fdc1SLionel Sambuc dtd->scaffCount = 0;
4566*1230fdc1SLionel Sambuc dtd->in_eldecl = XML_TRUE;
4567*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4568*1230fdc1SLionel Sambuc }
4569*1230fdc1SLionel Sambuc break;
4570*1230fdc1SLionel Sambuc
4571*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_ANY:
4572*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_EMPTY:
4573*1230fdc1SLionel Sambuc if (dtd->in_eldecl) {
4574*1230fdc1SLionel Sambuc if (elementDeclHandler) {
4575*1230fdc1SLionel Sambuc XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content));
4576*1230fdc1SLionel Sambuc if (!content)
4577*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4578*1230fdc1SLionel Sambuc content->quant = XML_CQUANT_NONE;
4579*1230fdc1SLionel Sambuc content->name = NULL;
4580*1230fdc1SLionel Sambuc content->numchildren = 0;
4581*1230fdc1SLionel Sambuc content->children = NULL;
4582*1230fdc1SLionel Sambuc content->type = ((role == XML_ROLE_CONTENT_ANY) ?
4583*1230fdc1SLionel Sambuc XML_CTYPE_ANY :
4584*1230fdc1SLionel Sambuc XML_CTYPE_EMPTY);
4585*1230fdc1SLionel Sambuc *eventEndPP = s;
4586*1230fdc1SLionel Sambuc elementDeclHandler(handlerArg, declElementType->name, content);
4587*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4588*1230fdc1SLionel Sambuc }
4589*1230fdc1SLionel Sambuc dtd->in_eldecl = XML_FALSE;
4590*1230fdc1SLionel Sambuc }
4591*1230fdc1SLionel Sambuc break;
4592*1230fdc1SLionel Sambuc
4593*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_PCDATA:
4594*1230fdc1SLionel Sambuc if (dtd->in_eldecl) {
4595*1230fdc1SLionel Sambuc dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
4596*1230fdc1SLionel Sambuc = XML_CTYPE_MIXED;
4597*1230fdc1SLionel Sambuc if (elementDeclHandler)
4598*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4599*1230fdc1SLionel Sambuc }
4600*1230fdc1SLionel Sambuc break;
4601*1230fdc1SLionel Sambuc
4602*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_ELEMENT:
4603*1230fdc1SLionel Sambuc quant = XML_CQUANT_NONE;
4604*1230fdc1SLionel Sambuc goto elementContent;
4605*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_ELEMENT_OPT:
4606*1230fdc1SLionel Sambuc quant = XML_CQUANT_OPT;
4607*1230fdc1SLionel Sambuc goto elementContent;
4608*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_ELEMENT_REP:
4609*1230fdc1SLionel Sambuc quant = XML_CQUANT_REP;
4610*1230fdc1SLionel Sambuc goto elementContent;
4611*1230fdc1SLionel Sambuc case XML_ROLE_CONTENT_ELEMENT_PLUS:
4612*1230fdc1SLionel Sambuc quant = XML_CQUANT_PLUS;
4613*1230fdc1SLionel Sambuc elementContent:
4614*1230fdc1SLionel Sambuc if (dtd->in_eldecl) {
4615*1230fdc1SLionel Sambuc ELEMENT_TYPE *el;
4616*1230fdc1SLionel Sambuc const XML_Char *name;
4617*1230fdc1SLionel Sambuc int nameLen;
4618*1230fdc1SLionel Sambuc const char *nxt = (quant == XML_CQUANT_NONE
4619*1230fdc1SLionel Sambuc ? next
4620*1230fdc1SLionel Sambuc : next - enc->minBytesPerChar);
4621*1230fdc1SLionel Sambuc int myindex = nextScaffoldPart(parser);
4622*1230fdc1SLionel Sambuc if (myindex < 0)
4623*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4624*1230fdc1SLionel Sambuc dtd->scaffold[myindex].type = XML_CTYPE_NAME;
4625*1230fdc1SLionel Sambuc dtd->scaffold[myindex].quant = quant;
4626*1230fdc1SLionel Sambuc el = getElementType(parser, enc, s, nxt);
4627*1230fdc1SLionel Sambuc if (!el)
4628*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4629*1230fdc1SLionel Sambuc name = el->name;
4630*1230fdc1SLionel Sambuc dtd->scaffold[myindex].name = name;
4631*1230fdc1SLionel Sambuc nameLen = 0;
4632*1230fdc1SLionel Sambuc for (; name[nameLen++]; );
4633*1230fdc1SLionel Sambuc dtd->contentStringLen += nameLen;
4634*1230fdc1SLionel Sambuc if (elementDeclHandler)
4635*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4636*1230fdc1SLionel Sambuc }
4637*1230fdc1SLionel Sambuc break;
4638*1230fdc1SLionel Sambuc
4639*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_CLOSE:
4640*1230fdc1SLionel Sambuc quant = XML_CQUANT_NONE;
4641*1230fdc1SLionel Sambuc goto closeGroup;
4642*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_CLOSE_OPT:
4643*1230fdc1SLionel Sambuc quant = XML_CQUANT_OPT;
4644*1230fdc1SLionel Sambuc goto closeGroup;
4645*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_CLOSE_REP:
4646*1230fdc1SLionel Sambuc quant = XML_CQUANT_REP;
4647*1230fdc1SLionel Sambuc goto closeGroup;
4648*1230fdc1SLionel Sambuc case XML_ROLE_GROUP_CLOSE_PLUS:
4649*1230fdc1SLionel Sambuc quant = XML_CQUANT_PLUS;
4650*1230fdc1SLionel Sambuc closeGroup:
4651*1230fdc1SLionel Sambuc if (dtd->in_eldecl) {
4652*1230fdc1SLionel Sambuc if (elementDeclHandler)
4653*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4654*1230fdc1SLionel Sambuc dtd->scaffLevel--;
4655*1230fdc1SLionel Sambuc dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant;
4656*1230fdc1SLionel Sambuc if (dtd->scaffLevel == 0) {
4657*1230fdc1SLionel Sambuc if (!handleDefault) {
4658*1230fdc1SLionel Sambuc XML_Content *model = build_model(parser);
4659*1230fdc1SLionel Sambuc if (!model)
4660*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4661*1230fdc1SLionel Sambuc *eventEndPP = s;
4662*1230fdc1SLionel Sambuc elementDeclHandler(handlerArg, declElementType->name, model);
4663*1230fdc1SLionel Sambuc }
4664*1230fdc1SLionel Sambuc dtd->in_eldecl = XML_FALSE;
4665*1230fdc1SLionel Sambuc dtd->contentStringLen = 0;
4666*1230fdc1SLionel Sambuc }
4667*1230fdc1SLionel Sambuc }
4668*1230fdc1SLionel Sambuc break;
4669*1230fdc1SLionel Sambuc /* End element declaration stuff */
4670*1230fdc1SLionel Sambuc
4671*1230fdc1SLionel Sambuc case XML_ROLE_PI:
4672*1230fdc1SLionel Sambuc if (!reportProcessingInstruction(parser, enc, s, next))
4673*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4674*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4675*1230fdc1SLionel Sambuc break;
4676*1230fdc1SLionel Sambuc case XML_ROLE_COMMENT:
4677*1230fdc1SLionel Sambuc if (!reportComment(parser, enc, s, next))
4678*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4679*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4680*1230fdc1SLionel Sambuc break;
4681*1230fdc1SLionel Sambuc case XML_ROLE_NONE:
4682*1230fdc1SLionel Sambuc switch (tok) {
4683*1230fdc1SLionel Sambuc case XML_TOK_BOM:
4684*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4685*1230fdc1SLionel Sambuc break;
4686*1230fdc1SLionel Sambuc }
4687*1230fdc1SLionel Sambuc break;
4688*1230fdc1SLionel Sambuc case XML_ROLE_DOCTYPE_NONE:
4689*1230fdc1SLionel Sambuc if (startDoctypeDeclHandler)
4690*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4691*1230fdc1SLionel Sambuc break;
4692*1230fdc1SLionel Sambuc case XML_ROLE_ENTITY_NONE:
4693*1230fdc1SLionel Sambuc if (dtd->keepProcessing && entityDeclHandler)
4694*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4695*1230fdc1SLionel Sambuc break;
4696*1230fdc1SLionel Sambuc case XML_ROLE_NOTATION_NONE:
4697*1230fdc1SLionel Sambuc if (notationDeclHandler)
4698*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4699*1230fdc1SLionel Sambuc break;
4700*1230fdc1SLionel Sambuc case XML_ROLE_ATTLIST_NONE:
4701*1230fdc1SLionel Sambuc if (dtd->keepProcessing && attlistDeclHandler)
4702*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4703*1230fdc1SLionel Sambuc break;
4704*1230fdc1SLionel Sambuc case XML_ROLE_ELEMENT_NONE:
4705*1230fdc1SLionel Sambuc if (elementDeclHandler)
4706*1230fdc1SLionel Sambuc handleDefault = XML_FALSE;
4707*1230fdc1SLionel Sambuc break;
4708*1230fdc1SLionel Sambuc } /* end of big switch */
4709*1230fdc1SLionel Sambuc
4710*1230fdc1SLionel Sambuc if (handleDefault && defaultHandler)
4711*1230fdc1SLionel Sambuc reportDefault(parser, enc, s, next);
4712*1230fdc1SLionel Sambuc
4713*1230fdc1SLionel Sambuc switch (ps_parsing) {
4714*1230fdc1SLionel Sambuc case XML_SUSPENDED:
4715*1230fdc1SLionel Sambuc *nextPtr = next;
4716*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4717*1230fdc1SLionel Sambuc case XML_FINISHED:
4718*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
4719*1230fdc1SLionel Sambuc default:
4720*1230fdc1SLionel Sambuc s = next;
4721*1230fdc1SLionel Sambuc tok = XmlPrologTok(enc, s, end, &next);
4722*1230fdc1SLionel Sambuc }
4723*1230fdc1SLionel Sambuc }
4724*1230fdc1SLionel Sambuc /* not reached */
4725*1230fdc1SLionel Sambuc }
4726*1230fdc1SLionel Sambuc
4727*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
epilogProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)4728*1230fdc1SLionel Sambuc epilogProcessor(XML_Parser parser,
4729*1230fdc1SLionel Sambuc const char *s,
4730*1230fdc1SLionel Sambuc const char *end,
4731*1230fdc1SLionel Sambuc const char **nextPtr)
4732*1230fdc1SLionel Sambuc {
4733*1230fdc1SLionel Sambuc processor = epilogProcessor;
4734*1230fdc1SLionel Sambuc eventPtr = s;
4735*1230fdc1SLionel Sambuc for (;;) {
4736*1230fdc1SLionel Sambuc const char *next = NULL;
4737*1230fdc1SLionel Sambuc int tok = XmlPrologTok(encoding, s, end, &next);
4738*1230fdc1SLionel Sambuc eventEndPtr = next;
4739*1230fdc1SLionel Sambuc switch (tok) {
4740*1230fdc1SLionel Sambuc /* report partial linebreak - it might be the last token */
4741*1230fdc1SLionel Sambuc case -XML_TOK_PROLOG_S:
4742*1230fdc1SLionel Sambuc if (defaultHandler) {
4743*1230fdc1SLionel Sambuc reportDefault(parser, encoding, s, next);
4744*1230fdc1SLionel Sambuc if (ps_parsing == XML_FINISHED)
4745*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
4746*1230fdc1SLionel Sambuc }
4747*1230fdc1SLionel Sambuc *nextPtr = next;
4748*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4749*1230fdc1SLionel Sambuc case XML_TOK_NONE:
4750*1230fdc1SLionel Sambuc *nextPtr = s;
4751*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4752*1230fdc1SLionel Sambuc case XML_TOK_PROLOG_S:
4753*1230fdc1SLionel Sambuc if (defaultHandler)
4754*1230fdc1SLionel Sambuc reportDefault(parser, encoding, s, next);
4755*1230fdc1SLionel Sambuc break;
4756*1230fdc1SLionel Sambuc case XML_TOK_PI:
4757*1230fdc1SLionel Sambuc if (!reportProcessingInstruction(parser, encoding, s, next))
4758*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4759*1230fdc1SLionel Sambuc break;
4760*1230fdc1SLionel Sambuc case XML_TOK_COMMENT:
4761*1230fdc1SLionel Sambuc if (!reportComment(parser, encoding, s, next))
4762*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4763*1230fdc1SLionel Sambuc break;
4764*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
4765*1230fdc1SLionel Sambuc eventPtr = next;
4766*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
4767*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
4768*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
4769*1230fdc1SLionel Sambuc *nextPtr = s;
4770*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4771*1230fdc1SLionel Sambuc }
4772*1230fdc1SLionel Sambuc return XML_ERROR_UNCLOSED_TOKEN;
4773*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL_CHAR:
4774*1230fdc1SLionel Sambuc if (!ps_finalBuffer) {
4775*1230fdc1SLionel Sambuc *nextPtr = s;
4776*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4777*1230fdc1SLionel Sambuc }
4778*1230fdc1SLionel Sambuc return XML_ERROR_PARTIAL_CHAR;
4779*1230fdc1SLionel Sambuc default:
4780*1230fdc1SLionel Sambuc return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
4781*1230fdc1SLionel Sambuc }
4782*1230fdc1SLionel Sambuc eventPtr = s = next;
4783*1230fdc1SLionel Sambuc switch (ps_parsing) {
4784*1230fdc1SLionel Sambuc case XML_SUSPENDED:
4785*1230fdc1SLionel Sambuc *nextPtr = next;
4786*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4787*1230fdc1SLionel Sambuc case XML_FINISHED:
4788*1230fdc1SLionel Sambuc return XML_ERROR_ABORTED;
4789*1230fdc1SLionel Sambuc default: ;
4790*1230fdc1SLionel Sambuc }
4791*1230fdc1SLionel Sambuc }
4792*1230fdc1SLionel Sambuc }
4793*1230fdc1SLionel Sambuc
4794*1230fdc1SLionel Sambuc static enum XML_Error
processInternalEntity(XML_Parser parser,ENTITY * entity,XML_Bool betweenDecl)4795*1230fdc1SLionel Sambuc processInternalEntity(XML_Parser parser, ENTITY *entity,
4796*1230fdc1SLionel Sambuc XML_Bool betweenDecl)
4797*1230fdc1SLionel Sambuc {
4798*1230fdc1SLionel Sambuc const char *textStart, *textEnd;
4799*1230fdc1SLionel Sambuc const char *next;
4800*1230fdc1SLionel Sambuc enum XML_Error result;
4801*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *openEntity;
4802*1230fdc1SLionel Sambuc
4803*1230fdc1SLionel Sambuc if (freeInternalEntities) {
4804*1230fdc1SLionel Sambuc openEntity = freeInternalEntities;
4805*1230fdc1SLionel Sambuc freeInternalEntities = openEntity->next;
4806*1230fdc1SLionel Sambuc }
4807*1230fdc1SLionel Sambuc else {
4808*1230fdc1SLionel Sambuc openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY));
4809*1230fdc1SLionel Sambuc if (!openEntity)
4810*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4811*1230fdc1SLionel Sambuc }
4812*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
4813*1230fdc1SLionel Sambuc entity->processed = 0;
4814*1230fdc1SLionel Sambuc openEntity->next = openInternalEntities;
4815*1230fdc1SLionel Sambuc openInternalEntities = openEntity;
4816*1230fdc1SLionel Sambuc openEntity->entity = entity;
4817*1230fdc1SLionel Sambuc openEntity->startTagLevel = tagLevel;
4818*1230fdc1SLionel Sambuc openEntity->betweenDecl = betweenDecl;
4819*1230fdc1SLionel Sambuc openEntity->internalEventPtr = NULL;
4820*1230fdc1SLionel Sambuc openEntity->internalEventEndPtr = NULL;
4821*1230fdc1SLionel Sambuc textStart = (char *)entity->textPtr;
4822*1230fdc1SLionel Sambuc textEnd = (char *)(entity->textPtr + entity->textLen);
4823*1230fdc1SLionel Sambuc
4824*1230fdc1SLionel Sambuc #ifdef XML_DTD
4825*1230fdc1SLionel Sambuc if (entity->is_param) {
4826*1230fdc1SLionel Sambuc int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
4827*1230fdc1SLionel Sambuc result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
4828*1230fdc1SLionel Sambuc next, &next, XML_FALSE);
4829*1230fdc1SLionel Sambuc }
4830*1230fdc1SLionel Sambuc else
4831*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4832*1230fdc1SLionel Sambuc result = doContent(parser, tagLevel, internalEncoding, textStart,
4833*1230fdc1SLionel Sambuc textEnd, &next, XML_FALSE);
4834*1230fdc1SLionel Sambuc
4835*1230fdc1SLionel Sambuc if (result == XML_ERROR_NONE) {
4836*1230fdc1SLionel Sambuc if (textEnd != next && ps_parsing == XML_SUSPENDED) {
4837*1230fdc1SLionel Sambuc entity->processed = (int)(next - textStart);
4838*1230fdc1SLionel Sambuc processor = internalEntityProcessor;
4839*1230fdc1SLionel Sambuc }
4840*1230fdc1SLionel Sambuc else {
4841*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
4842*1230fdc1SLionel Sambuc openInternalEntities = openEntity->next;
4843*1230fdc1SLionel Sambuc /* put openEntity back in list of free instances */
4844*1230fdc1SLionel Sambuc openEntity->next = freeInternalEntities;
4845*1230fdc1SLionel Sambuc freeInternalEntities = openEntity;
4846*1230fdc1SLionel Sambuc }
4847*1230fdc1SLionel Sambuc }
4848*1230fdc1SLionel Sambuc return result;
4849*1230fdc1SLionel Sambuc }
4850*1230fdc1SLionel Sambuc
4851*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
internalEntityProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)4852*1230fdc1SLionel Sambuc internalEntityProcessor(XML_Parser parser,
4853*1230fdc1SLionel Sambuc const char *s,
4854*1230fdc1SLionel Sambuc const char *end,
4855*1230fdc1SLionel Sambuc const char **nextPtr)
4856*1230fdc1SLionel Sambuc {
4857*1230fdc1SLionel Sambuc ENTITY *entity;
4858*1230fdc1SLionel Sambuc const char *textStart, *textEnd;
4859*1230fdc1SLionel Sambuc const char *next;
4860*1230fdc1SLionel Sambuc enum XML_Error result;
4861*1230fdc1SLionel Sambuc OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities;
4862*1230fdc1SLionel Sambuc if (!openEntity)
4863*1230fdc1SLionel Sambuc return XML_ERROR_UNEXPECTED_STATE;
4864*1230fdc1SLionel Sambuc
4865*1230fdc1SLionel Sambuc entity = openEntity->entity;
4866*1230fdc1SLionel Sambuc textStart = ((char *)entity->textPtr) + entity->processed;
4867*1230fdc1SLionel Sambuc textEnd = (char *)(entity->textPtr + entity->textLen);
4868*1230fdc1SLionel Sambuc
4869*1230fdc1SLionel Sambuc #ifdef XML_DTD
4870*1230fdc1SLionel Sambuc if (entity->is_param) {
4871*1230fdc1SLionel Sambuc int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
4872*1230fdc1SLionel Sambuc result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
4873*1230fdc1SLionel Sambuc next, &next, XML_FALSE);
4874*1230fdc1SLionel Sambuc }
4875*1230fdc1SLionel Sambuc else
4876*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4877*1230fdc1SLionel Sambuc result = doContent(parser, openEntity->startTagLevel, internalEncoding,
4878*1230fdc1SLionel Sambuc textStart, textEnd, &next, XML_FALSE);
4879*1230fdc1SLionel Sambuc
4880*1230fdc1SLionel Sambuc if (result != XML_ERROR_NONE)
4881*1230fdc1SLionel Sambuc return result;
4882*1230fdc1SLionel Sambuc else if (textEnd != next && ps_parsing == XML_SUSPENDED) {
4883*1230fdc1SLionel Sambuc entity->processed = (int)(next - (char *)entity->textPtr);
4884*1230fdc1SLionel Sambuc return result;
4885*1230fdc1SLionel Sambuc }
4886*1230fdc1SLionel Sambuc else {
4887*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
4888*1230fdc1SLionel Sambuc openInternalEntities = openEntity->next;
4889*1230fdc1SLionel Sambuc /* put openEntity back in list of free instances */
4890*1230fdc1SLionel Sambuc openEntity->next = freeInternalEntities;
4891*1230fdc1SLionel Sambuc freeInternalEntities = openEntity;
4892*1230fdc1SLionel Sambuc }
4893*1230fdc1SLionel Sambuc
4894*1230fdc1SLionel Sambuc #ifdef XML_DTD
4895*1230fdc1SLionel Sambuc if (entity->is_param) {
4896*1230fdc1SLionel Sambuc int tok;
4897*1230fdc1SLionel Sambuc processor = prologProcessor;
4898*1230fdc1SLionel Sambuc tok = XmlPrologTok(encoding, s, end, &next);
4899*1230fdc1SLionel Sambuc return doProlog(parser, encoding, s, end, tok, next, nextPtr,
4900*1230fdc1SLionel Sambuc (XML_Bool)!ps_finalBuffer);
4901*1230fdc1SLionel Sambuc }
4902*1230fdc1SLionel Sambuc else
4903*1230fdc1SLionel Sambuc #endif /* XML_DTD */
4904*1230fdc1SLionel Sambuc {
4905*1230fdc1SLionel Sambuc processor = contentProcessor;
4906*1230fdc1SLionel Sambuc /* see externalEntityContentProcessor vs contentProcessor */
4907*1230fdc1SLionel Sambuc return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
4908*1230fdc1SLionel Sambuc nextPtr, (XML_Bool)!ps_finalBuffer);
4909*1230fdc1SLionel Sambuc }
4910*1230fdc1SLionel Sambuc }
4911*1230fdc1SLionel Sambuc
4912*1230fdc1SLionel Sambuc static enum XML_Error PTRCALL
errorProcessor(XML_Parser parser,const char * s,const char * end,const char ** nextPtr)4913*1230fdc1SLionel Sambuc errorProcessor(XML_Parser parser,
4914*1230fdc1SLionel Sambuc const char *s,
4915*1230fdc1SLionel Sambuc const char *end,
4916*1230fdc1SLionel Sambuc const char **nextPtr)
4917*1230fdc1SLionel Sambuc {
4918*1230fdc1SLionel Sambuc return errorCode;
4919*1230fdc1SLionel Sambuc }
4920*1230fdc1SLionel Sambuc
4921*1230fdc1SLionel Sambuc static enum XML_Error
storeAttributeValue(XML_Parser parser,const ENCODING * enc,XML_Bool isCdata,const char * ptr,const char * end,STRING_POOL * pool)4922*1230fdc1SLionel Sambuc storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
4923*1230fdc1SLionel Sambuc const char *ptr, const char *end,
4924*1230fdc1SLionel Sambuc STRING_POOL *pool)
4925*1230fdc1SLionel Sambuc {
4926*1230fdc1SLionel Sambuc enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr,
4927*1230fdc1SLionel Sambuc end, pool);
4928*1230fdc1SLionel Sambuc if (result)
4929*1230fdc1SLionel Sambuc return result;
4930*1230fdc1SLionel Sambuc if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20)
4931*1230fdc1SLionel Sambuc poolChop(pool);
4932*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, XML_T('\0')))
4933*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4934*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4935*1230fdc1SLionel Sambuc }
4936*1230fdc1SLionel Sambuc
4937*1230fdc1SLionel Sambuc static enum XML_Error
appendAttributeValue(XML_Parser parser,const ENCODING * enc,XML_Bool isCdata,const char * ptr,const char * end,STRING_POOL * pool)4938*1230fdc1SLionel Sambuc appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
4939*1230fdc1SLionel Sambuc const char *ptr, const char *end,
4940*1230fdc1SLionel Sambuc STRING_POOL *pool)
4941*1230fdc1SLionel Sambuc {
4942*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
4943*1230fdc1SLionel Sambuc for (;;) {
4944*1230fdc1SLionel Sambuc const char *next;
4945*1230fdc1SLionel Sambuc int tok = XmlAttributeValueTok(enc, ptr, end, &next);
4946*1230fdc1SLionel Sambuc switch (tok) {
4947*1230fdc1SLionel Sambuc case XML_TOK_NONE:
4948*1230fdc1SLionel Sambuc return XML_ERROR_NONE;
4949*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
4950*1230fdc1SLionel Sambuc if (enc == encoding)
4951*1230fdc1SLionel Sambuc eventPtr = next;
4952*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
4953*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
4954*1230fdc1SLionel Sambuc if (enc == encoding)
4955*1230fdc1SLionel Sambuc eventPtr = ptr;
4956*1230fdc1SLionel Sambuc return XML_ERROR_INVALID_TOKEN;
4957*1230fdc1SLionel Sambuc case XML_TOK_CHAR_REF:
4958*1230fdc1SLionel Sambuc {
4959*1230fdc1SLionel Sambuc XML_Char buf[XML_ENCODE_MAX];
4960*1230fdc1SLionel Sambuc int i;
4961*1230fdc1SLionel Sambuc int n = XmlCharRefNumber(enc, ptr);
4962*1230fdc1SLionel Sambuc if (n < 0) {
4963*1230fdc1SLionel Sambuc if (enc == encoding)
4964*1230fdc1SLionel Sambuc eventPtr = ptr;
4965*1230fdc1SLionel Sambuc return XML_ERROR_BAD_CHAR_REF;
4966*1230fdc1SLionel Sambuc }
4967*1230fdc1SLionel Sambuc if (!isCdata
4968*1230fdc1SLionel Sambuc && n == 0x20 /* space */
4969*1230fdc1SLionel Sambuc && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20))
4970*1230fdc1SLionel Sambuc break;
4971*1230fdc1SLionel Sambuc n = XmlEncode(n, (ICHAR *)buf);
4972*1230fdc1SLionel Sambuc if (!n) {
4973*1230fdc1SLionel Sambuc if (enc == encoding)
4974*1230fdc1SLionel Sambuc eventPtr = ptr;
4975*1230fdc1SLionel Sambuc return XML_ERROR_BAD_CHAR_REF;
4976*1230fdc1SLionel Sambuc }
4977*1230fdc1SLionel Sambuc for (i = 0; i < n; i++) {
4978*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, buf[i]))
4979*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4980*1230fdc1SLionel Sambuc }
4981*1230fdc1SLionel Sambuc }
4982*1230fdc1SLionel Sambuc break;
4983*1230fdc1SLionel Sambuc case XML_TOK_DATA_CHARS:
4984*1230fdc1SLionel Sambuc if (!poolAppend(pool, enc, ptr, next))
4985*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4986*1230fdc1SLionel Sambuc break;
4987*1230fdc1SLionel Sambuc case XML_TOK_TRAILING_CR:
4988*1230fdc1SLionel Sambuc next = ptr + enc->minBytesPerChar;
4989*1230fdc1SLionel Sambuc /* fall through */
4990*1230fdc1SLionel Sambuc case XML_TOK_ATTRIBUTE_VALUE_S:
4991*1230fdc1SLionel Sambuc case XML_TOK_DATA_NEWLINE:
4992*1230fdc1SLionel Sambuc if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20))
4993*1230fdc1SLionel Sambuc break;
4994*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, 0x20))
4995*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
4996*1230fdc1SLionel Sambuc break;
4997*1230fdc1SLionel Sambuc case XML_TOK_ENTITY_REF:
4998*1230fdc1SLionel Sambuc {
4999*1230fdc1SLionel Sambuc const XML_Char *name;
5000*1230fdc1SLionel Sambuc ENTITY *entity;
5001*1230fdc1SLionel Sambuc char checkEntityDecl;
5002*1230fdc1SLionel Sambuc XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc,
5003*1230fdc1SLionel Sambuc ptr + enc->minBytesPerChar,
5004*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
5005*1230fdc1SLionel Sambuc if (ch) {
5006*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, ch))
5007*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
5008*1230fdc1SLionel Sambuc break;
5009*1230fdc1SLionel Sambuc }
5010*1230fdc1SLionel Sambuc name = poolStoreString(&temp2Pool, enc,
5011*1230fdc1SLionel Sambuc ptr + enc->minBytesPerChar,
5012*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
5013*1230fdc1SLionel Sambuc if (!name)
5014*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
5015*1230fdc1SLionel Sambuc entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
5016*1230fdc1SLionel Sambuc poolDiscard(&temp2Pool);
5017*1230fdc1SLionel Sambuc /* First, determine if a check for an existing declaration is needed;
5018*1230fdc1SLionel Sambuc if yes, check that the entity exists, and that it is internal.
5019*1230fdc1SLionel Sambuc */
5020*1230fdc1SLionel Sambuc if (pool == &dtd->pool) /* are we called from prolog? */
5021*1230fdc1SLionel Sambuc checkEntityDecl =
5022*1230fdc1SLionel Sambuc #ifdef XML_DTD
5023*1230fdc1SLionel Sambuc prologState.documentEntity &&
5024*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5025*1230fdc1SLionel Sambuc (dtd->standalone
5026*1230fdc1SLionel Sambuc ? !openInternalEntities
5027*1230fdc1SLionel Sambuc : !dtd->hasParamEntityRefs);
5028*1230fdc1SLionel Sambuc else /* if (pool == &tempPool): we are called from content */
5029*1230fdc1SLionel Sambuc checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone;
5030*1230fdc1SLionel Sambuc if (checkEntityDecl) {
5031*1230fdc1SLionel Sambuc if (!entity)
5032*1230fdc1SLionel Sambuc return XML_ERROR_UNDEFINED_ENTITY;
5033*1230fdc1SLionel Sambuc else if (!entity->is_internal)
5034*1230fdc1SLionel Sambuc return XML_ERROR_ENTITY_DECLARED_IN_PE;
5035*1230fdc1SLionel Sambuc }
5036*1230fdc1SLionel Sambuc else if (!entity) {
5037*1230fdc1SLionel Sambuc /* Cannot report skipped entity here - see comments on
5038*1230fdc1SLionel Sambuc skippedEntityHandler.
5039*1230fdc1SLionel Sambuc if (skippedEntityHandler)
5040*1230fdc1SLionel Sambuc skippedEntityHandler(handlerArg, name, 0);
5041*1230fdc1SLionel Sambuc */
5042*1230fdc1SLionel Sambuc /* Cannot call the default handler because this would be
5043*1230fdc1SLionel Sambuc out of sync with the call to the startElementHandler.
5044*1230fdc1SLionel Sambuc if ((pool == &tempPool) && defaultHandler)
5045*1230fdc1SLionel Sambuc reportDefault(parser, enc, ptr, next);
5046*1230fdc1SLionel Sambuc */
5047*1230fdc1SLionel Sambuc break;
5048*1230fdc1SLionel Sambuc }
5049*1230fdc1SLionel Sambuc if (entity->open) {
5050*1230fdc1SLionel Sambuc if (enc == encoding)
5051*1230fdc1SLionel Sambuc eventPtr = ptr;
5052*1230fdc1SLionel Sambuc return XML_ERROR_RECURSIVE_ENTITY_REF;
5053*1230fdc1SLionel Sambuc }
5054*1230fdc1SLionel Sambuc if (entity->notation) {
5055*1230fdc1SLionel Sambuc if (enc == encoding)
5056*1230fdc1SLionel Sambuc eventPtr = ptr;
5057*1230fdc1SLionel Sambuc return XML_ERROR_BINARY_ENTITY_REF;
5058*1230fdc1SLionel Sambuc }
5059*1230fdc1SLionel Sambuc if (!entity->textPtr) {
5060*1230fdc1SLionel Sambuc if (enc == encoding)
5061*1230fdc1SLionel Sambuc eventPtr = ptr;
5062*1230fdc1SLionel Sambuc return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
5063*1230fdc1SLionel Sambuc }
5064*1230fdc1SLionel Sambuc else {
5065*1230fdc1SLionel Sambuc enum XML_Error result;
5066*1230fdc1SLionel Sambuc const XML_Char *textEnd = entity->textPtr + entity->textLen;
5067*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
5068*1230fdc1SLionel Sambuc result = appendAttributeValue(parser, internalEncoding, isCdata,
5069*1230fdc1SLionel Sambuc (char *)entity->textPtr,
5070*1230fdc1SLionel Sambuc (char *)textEnd, pool);
5071*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
5072*1230fdc1SLionel Sambuc if (result)
5073*1230fdc1SLionel Sambuc return result;
5074*1230fdc1SLionel Sambuc }
5075*1230fdc1SLionel Sambuc }
5076*1230fdc1SLionel Sambuc break;
5077*1230fdc1SLionel Sambuc default:
5078*1230fdc1SLionel Sambuc if (enc == encoding)
5079*1230fdc1SLionel Sambuc eventPtr = ptr;
5080*1230fdc1SLionel Sambuc return XML_ERROR_UNEXPECTED_STATE;
5081*1230fdc1SLionel Sambuc }
5082*1230fdc1SLionel Sambuc ptr = next;
5083*1230fdc1SLionel Sambuc }
5084*1230fdc1SLionel Sambuc /* not reached */
5085*1230fdc1SLionel Sambuc }
5086*1230fdc1SLionel Sambuc
5087*1230fdc1SLionel Sambuc static enum XML_Error
storeEntityValue(XML_Parser parser,const ENCODING * enc,const char * entityTextPtr,const char * entityTextEnd)5088*1230fdc1SLionel Sambuc storeEntityValue(XML_Parser parser,
5089*1230fdc1SLionel Sambuc const ENCODING *enc,
5090*1230fdc1SLionel Sambuc const char *entityTextPtr,
5091*1230fdc1SLionel Sambuc const char *entityTextEnd)
5092*1230fdc1SLionel Sambuc {
5093*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
5094*1230fdc1SLionel Sambuc STRING_POOL *pool = &(dtd->entityValuePool);
5095*1230fdc1SLionel Sambuc enum XML_Error result = XML_ERROR_NONE;
5096*1230fdc1SLionel Sambuc #ifdef XML_DTD
5097*1230fdc1SLionel Sambuc int oldInEntityValue = prologState.inEntityValue;
5098*1230fdc1SLionel Sambuc prologState.inEntityValue = 1;
5099*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5100*1230fdc1SLionel Sambuc /* never return Null for the value argument in EntityDeclHandler,
5101*1230fdc1SLionel Sambuc since this would indicate an external entity; therefore we
5102*1230fdc1SLionel Sambuc have to make sure that entityValuePool.start is not null */
5103*1230fdc1SLionel Sambuc if (!pool->blocks) {
5104*1230fdc1SLionel Sambuc if (!poolGrow(pool))
5105*1230fdc1SLionel Sambuc return XML_ERROR_NO_MEMORY;
5106*1230fdc1SLionel Sambuc }
5107*1230fdc1SLionel Sambuc
5108*1230fdc1SLionel Sambuc for (;;) {
5109*1230fdc1SLionel Sambuc const char *next;
5110*1230fdc1SLionel Sambuc int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next);
5111*1230fdc1SLionel Sambuc switch (tok) {
5112*1230fdc1SLionel Sambuc case XML_TOK_PARAM_ENTITY_REF:
5113*1230fdc1SLionel Sambuc #ifdef XML_DTD
5114*1230fdc1SLionel Sambuc if (isParamEntity || enc != encoding) {
5115*1230fdc1SLionel Sambuc const XML_Char *name;
5116*1230fdc1SLionel Sambuc ENTITY *entity;
5117*1230fdc1SLionel Sambuc name = poolStoreString(&tempPool, enc,
5118*1230fdc1SLionel Sambuc entityTextPtr + enc->minBytesPerChar,
5119*1230fdc1SLionel Sambuc next - enc->minBytesPerChar);
5120*1230fdc1SLionel Sambuc if (!name) {
5121*1230fdc1SLionel Sambuc result = XML_ERROR_NO_MEMORY;
5122*1230fdc1SLionel Sambuc goto endEntityValue;
5123*1230fdc1SLionel Sambuc }
5124*1230fdc1SLionel Sambuc entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
5125*1230fdc1SLionel Sambuc poolDiscard(&tempPool);
5126*1230fdc1SLionel Sambuc if (!entity) {
5127*1230fdc1SLionel Sambuc /* not a well-formedness error - see XML 1.0: WFC Entity Declared */
5128*1230fdc1SLionel Sambuc /* cannot report skipped entity here - see comments on
5129*1230fdc1SLionel Sambuc skippedEntityHandler
5130*1230fdc1SLionel Sambuc if (skippedEntityHandler)
5131*1230fdc1SLionel Sambuc skippedEntityHandler(handlerArg, name, 0);
5132*1230fdc1SLionel Sambuc */
5133*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
5134*1230fdc1SLionel Sambuc goto endEntityValue;
5135*1230fdc1SLionel Sambuc }
5136*1230fdc1SLionel Sambuc if (entity->open) {
5137*1230fdc1SLionel Sambuc if (enc == encoding)
5138*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5139*1230fdc1SLionel Sambuc result = XML_ERROR_RECURSIVE_ENTITY_REF;
5140*1230fdc1SLionel Sambuc goto endEntityValue;
5141*1230fdc1SLionel Sambuc }
5142*1230fdc1SLionel Sambuc if (entity->systemId) {
5143*1230fdc1SLionel Sambuc if (externalEntityRefHandler) {
5144*1230fdc1SLionel Sambuc dtd->paramEntityRead = XML_FALSE;
5145*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
5146*1230fdc1SLionel Sambuc if (!externalEntityRefHandler(externalEntityRefHandlerArg,
5147*1230fdc1SLionel Sambuc 0,
5148*1230fdc1SLionel Sambuc entity->base,
5149*1230fdc1SLionel Sambuc entity->systemId,
5150*1230fdc1SLionel Sambuc entity->publicId)) {
5151*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
5152*1230fdc1SLionel Sambuc result = XML_ERROR_EXTERNAL_ENTITY_HANDLING;
5153*1230fdc1SLionel Sambuc goto endEntityValue;
5154*1230fdc1SLionel Sambuc }
5155*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
5156*1230fdc1SLionel Sambuc if (!dtd->paramEntityRead)
5157*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
5158*1230fdc1SLionel Sambuc }
5159*1230fdc1SLionel Sambuc else
5160*1230fdc1SLionel Sambuc dtd->keepProcessing = dtd->standalone;
5161*1230fdc1SLionel Sambuc }
5162*1230fdc1SLionel Sambuc else {
5163*1230fdc1SLionel Sambuc entity->open = XML_TRUE;
5164*1230fdc1SLionel Sambuc result = storeEntityValue(parser,
5165*1230fdc1SLionel Sambuc internalEncoding,
5166*1230fdc1SLionel Sambuc (char *)entity->textPtr,
5167*1230fdc1SLionel Sambuc (char *)(entity->textPtr
5168*1230fdc1SLionel Sambuc + entity->textLen));
5169*1230fdc1SLionel Sambuc entity->open = XML_FALSE;
5170*1230fdc1SLionel Sambuc if (result)
5171*1230fdc1SLionel Sambuc goto endEntityValue;
5172*1230fdc1SLionel Sambuc }
5173*1230fdc1SLionel Sambuc break;
5174*1230fdc1SLionel Sambuc }
5175*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5176*1230fdc1SLionel Sambuc /* In the internal subset, PE references are not legal
5177*1230fdc1SLionel Sambuc within markup declarations, e.g entity values in this case. */
5178*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5179*1230fdc1SLionel Sambuc result = XML_ERROR_PARAM_ENTITY_REF;
5180*1230fdc1SLionel Sambuc goto endEntityValue;
5181*1230fdc1SLionel Sambuc case XML_TOK_NONE:
5182*1230fdc1SLionel Sambuc result = XML_ERROR_NONE;
5183*1230fdc1SLionel Sambuc goto endEntityValue;
5184*1230fdc1SLionel Sambuc case XML_TOK_ENTITY_REF:
5185*1230fdc1SLionel Sambuc case XML_TOK_DATA_CHARS:
5186*1230fdc1SLionel Sambuc if (!poolAppend(pool, enc, entityTextPtr, next)) {
5187*1230fdc1SLionel Sambuc result = XML_ERROR_NO_MEMORY;
5188*1230fdc1SLionel Sambuc goto endEntityValue;
5189*1230fdc1SLionel Sambuc }
5190*1230fdc1SLionel Sambuc break;
5191*1230fdc1SLionel Sambuc case XML_TOK_TRAILING_CR:
5192*1230fdc1SLionel Sambuc next = entityTextPtr + enc->minBytesPerChar;
5193*1230fdc1SLionel Sambuc /* fall through */
5194*1230fdc1SLionel Sambuc case XML_TOK_DATA_NEWLINE:
5195*1230fdc1SLionel Sambuc if (pool->end == pool->ptr && !poolGrow(pool)) {
5196*1230fdc1SLionel Sambuc result = XML_ERROR_NO_MEMORY;
5197*1230fdc1SLionel Sambuc goto endEntityValue;
5198*1230fdc1SLionel Sambuc }
5199*1230fdc1SLionel Sambuc *(pool->ptr)++ = 0xA;
5200*1230fdc1SLionel Sambuc break;
5201*1230fdc1SLionel Sambuc case XML_TOK_CHAR_REF:
5202*1230fdc1SLionel Sambuc {
5203*1230fdc1SLionel Sambuc XML_Char buf[XML_ENCODE_MAX];
5204*1230fdc1SLionel Sambuc int i;
5205*1230fdc1SLionel Sambuc int n = XmlCharRefNumber(enc, entityTextPtr);
5206*1230fdc1SLionel Sambuc if (n < 0) {
5207*1230fdc1SLionel Sambuc if (enc == encoding)
5208*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5209*1230fdc1SLionel Sambuc result = XML_ERROR_BAD_CHAR_REF;
5210*1230fdc1SLionel Sambuc goto endEntityValue;
5211*1230fdc1SLionel Sambuc }
5212*1230fdc1SLionel Sambuc n = XmlEncode(n, (ICHAR *)buf);
5213*1230fdc1SLionel Sambuc if (!n) {
5214*1230fdc1SLionel Sambuc if (enc == encoding)
5215*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5216*1230fdc1SLionel Sambuc result = XML_ERROR_BAD_CHAR_REF;
5217*1230fdc1SLionel Sambuc goto endEntityValue;
5218*1230fdc1SLionel Sambuc }
5219*1230fdc1SLionel Sambuc for (i = 0; i < n; i++) {
5220*1230fdc1SLionel Sambuc if (pool->end == pool->ptr && !poolGrow(pool)) {
5221*1230fdc1SLionel Sambuc result = XML_ERROR_NO_MEMORY;
5222*1230fdc1SLionel Sambuc goto endEntityValue;
5223*1230fdc1SLionel Sambuc }
5224*1230fdc1SLionel Sambuc *(pool->ptr)++ = buf[i];
5225*1230fdc1SLionel Sambuc }
5226*1230fdc1SLionel Sambuc }
5227*1230fdc1SLionel Sambuc break;
5228*1230fdc1SLionel Sambuc case XML_TOK_PARTIAL:
5229*1230fdc1SLionel Sambuc if (enc == encoding)
5230*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5231*1230fdc1SLionel Sambuc result = XML_ERROR_INVALID_TOKEN;
5232*1230fdc1SLionel Sambuc goto endEntityValue;
5233*1230fdc1SLionel Sambuc case XML_TOK_INVALID:
5234*1230fdc1SLionel Sambuc if (enc == encoding)
5235*1230fdc1SLionel Sambuc eventPtr = next;
5236*1230fdc1SLionel Sambuc result = XML_ERROR_INVALID_TOKEN;
5237*1230fdc1SLionel Sambuc goto endEntityValue;
5238*1230fdc1SLionel Sambuc default:
5239*1230fdc1SLionel Sambuc if (enc == encoding)
5240*1230fdc1SLionel Sambuc eventPtr = entityTextPtr;
5241*1230fdc1SLionel Sambuc result = XML_ERROR_UNEXPECTED_STATE;
5242*1230fdc1SLionel Sambuc goto endEntityValue;
5243*1230fdc1SLionel Sambuc }
5244*1230fdc1SLionel Sambuc entityTextPtr = next;
5245*1230fdc1SLionel Sambuc }
5246*1230fdc1SLionel Sambuc endEntityValue:
5247*1230fdc1SLionel Sambuc #ifdef XML_DTD
5248*1230fdc1SLionel Sambuc prologState.inEntityValue = oldInEntityValue;
5249*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5250*1230fdc1SLionel Sambuc return result;
5251*1230fdc1SLionel Sambuc }
5252*1230fdc1SLionel Sambuc
5253*1230fdc1SLionel Sambuc static void FASTCALL
normalizeLines(XML_Char * s)5254*1230fdc1SLionel Sambuc normalizeLines(XML_Char *s)
5255*1230fdc1SLionel Sambuc {
5256*1230fdc1SLionel Sambuc XML_Char *p;
5257*1230fdc1SLionel Sambuc for (;; s++) {
5258*1230fdc1SLionel Sambuc if (*s == XML_T('\0'))
5259*1230fdc1SLionel Sambuc return;
5260*1230fdc1SLionel Sambuc if (*s == 0xD)
5261*1230fdc1SLionel Sambuc break;
5262*1230fdc1SLionel Sambuc }
5263*1230fdc1SLionel Sambuc p = s;
5264*1230fdc1SLionel Sambuc do {
5265*1230fdc1SLionel Sambuc if (*s == 0xD) {
5266*1230fdc1SLionel Sambuc *p++ = 0xA;
5267*1230fdc1SLionel Sambuc if (*++s == 0xA)
5268*1230fdc1SLionel Sambuc s++;
5269*1230fdc1SLionel Sambuc }
5270*1230fdc1SLionel Sambuc else
5271*1230fdc1SLionel Sambuc *p++ = *s++;
5272*1230fdc1SLionel Sambuc } while (*s);
5273*1230fdc1SLionel Sambuc *p = XML_T('\0');
5274*1230fdc1SLionel Sambuc }
5275*1230fdc1SLionel Sambuc
5276*1230fdc1SLionel Sambuc static int
reportProcessingInstruction(XML_Parser parser,const ENCODING * enc,const char * start,const char * end)5277*1230fdc1SLionel Sambuc reportProcessingInstruction(XML_Parser parser, const ENCODING *enc,
5278*1230fdc1SLionel Sambuc const char *start, const char *end)
5279*1230fdc1SLionel Sambuc {
5280*1230fdc1SLionel Sambuc const XML_Char *target;
5281*1230fdc1SLionel Sambuc XML_Char *data;
5282*1230fdc1SLionel Sambuc const char *tem;
5283*1230fdc1SLionel Sambuc if (!processingInstructionHandler) {
5284*1230fdc1SLionel Sambuc if (defaultHandler)
5285*1230fdc1SLionel Sambuc reportDefault(parser, enc, start, end);
5286*1230fdc1SLionel Sambuc return 1;
5287*1230fdc1SLionel Sambuc }
5288*1230fdc1SLionel Sambuc start += enc->minBytesPerChar * 2;
5289*1230fdc1SLionel Sambuc tem = start + XmlNameLength(enc, start);
5290*1230fdc1SLionel Sambuc target = poolStoreString(&tempPool, enc, start, tem);
5291*1230fdc1SLionel Sambuc if (!target)
5292*1230fdc1SLionel Sambuc return 0;
5293*1230fdc1SLionel Sambuc poolFinish(&tempPool);
5294*1230fdc1SLionel Sambuc data = poolStoreString(&tempPool, enc,
5295*1230fdc1SLionel Sambuc XmlSkipS(enc, tem),
5296*1230fdc1SLionel Sambuc end - enc->minBytesPerChar*2);
5297*1230fdc1SLionel Sambuc if (!data)
5298*1230fdc1SLionel Sambuc return 0;
5299*1230fdc1SLionel Sambuc normalizeLines(data);
5300*1230fdc1SLionel Sambuc processingInstructionHandler(handlerArg, target, data);
5301*1230fdc1SLionel Sambuc poolClear(&tempPool);
5302*1230fdc1SLionel Sambuc return 1;
5303*1230fdc1SLionel Sambuc }
5304*1230fdc1SLionel Sambuc
5305*1230fdc1SLionel Sambuc static int
reportComment(XML_Parser parser,const ENCODING * enc,const char * start,const char * end)5306*1230fdc1SLionel Sambuc reportComment(XML_Parser parser, const ENCODING *enc,
5307*1230fdc1SLionel Sambuc const char *start, const char *end)
5308*1230fdc1SLionel Sambuc {
5309*1230fdc1SLionel Sambuc XML_Char *data;
5310*1230fdc1SLionel Sambuc if (!commentHandler) {
5311*1230fdc1SLionel Sambuc if (defaultHandler)
5312*1230fdc1SLionel Sambuc reportDefault(parser, enc, start, end);
5313*1230fdc1SLionel Sambuc return 1;
5314*1230fdc1SLionel Sambuc }
5315*1230fdc1SLionel Sambuc data = poolStoreString(&tempPool,
5316*1230fdc1SLionel Sambuc enc,
5317*1230fdc1SLionel Sambuc start + enc->minBytesPerChar * 4,
5318*1230fdc1SLionel Sambuc end - enc->minBytesPerChar * 3);
5319*1230fdc1SLionel Sambuc if (!data)
5320*1230fdc1SLionel Sambuc return 0;
5321*1230fdc1SLionel Sambuc normalizeLines(data);
5322*1230fdc1SLionel Sambuc commentHandler(handlerArg, data);
5323*1230fdc1SLionel Sambuc poolClear(&tempPool);
5324*1230fdc1SLionel Sambuc return 1;
5325*1230fdc1SLionel Sambuc }
5326*1230fdc1SLionel Sambuc
5327*1230fdc1SLionel Sambuc static void
reportDefault(XML_Parser parser,const ENCODING * enc,const char * s,const char * end)5328*1230fdc1SLionel Sambuc reportDefault(XML_Parser parser, const ENCODING *enc,
5329*1230fdc1SLionel Sambuc const char *s, const char *end)
5330*1230fdc1SLionel Sambuc {
5331*1230fdc1SLionel Sambuc if (MUST_CONVERT(enc, s)) {
5332*1230fdc1SLionel Sambuc const char **eventPP;
5333*1230fdc1SLionel Sambuc const char **eventEndPP;
5334*1230fdc1SLionel Sambuc if (enc == encoding) {
5335*1230fdc1SLionel Sambuc eventPP = &eventPtr;
5336*1230fdc1SLionel Sambuc eventEndPP = &eventEndPtr;
5337*1230fdc1SLionel Sambuc }
5338*1230fdc1SLionel Sambuc else {
5339*1230fdc1SLionel Sambuc eventPP = &(openInternalEntities->internalEventPtr);
5340*1230fdc1SLionel Sambuc eventEndPP = &(openInternalEntities->internalEventEndPtr);
5341*1230fdc1SLionel Sambuc }
5342*1230fdc1SLionel Sambuc do {
5343*1230fdc1SLionel Sambuc ICHAR *dataPtr = (ICHAR *)dataBuf;
5344*1230fdc1SLionel Sambuc XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
5345*1230fdc1SLionel Sambuc *eventEndPP = s;
5346*1230fdc1SLionel Sambuc defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
5347*1230fdc1SLionel Sambuc *eventPP = s;
5348*1230fdc1SLionel Sambuc } while (s != end);
5349*1230fdc1SLionel Sambuc }
5350*1230fdc1SLionel Sambuc else
5351*1230fdc1SLionel Sambuc defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
5352*1230fdc1SLionel Sambuc }
5353*1230fdc1SLionel Sambuc
5354*1230fdc1SLionel Sambuc
5355*1230fdc1SLionel Sambuc static int
defineAttribute(ELEMENT_TYPE * type,ATTRIBUTE_ID * attId,XML_Bool isCdata,XML_Bool isId,const XML_Char * value,XML_Parser parser)5356*1230fdc1SLionel Sambuc defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
5357*1230fdc1SLionel Sambuc XML_Bool isId, const XML_Char *value, XML_Parser parser)
5358*1230fdc1SLionel Sambuc {
5359*1230fdc1SLionel Sambuc DEFAULT_ATTRIBUTE *att;
5360*1230fdc1SLionel Sambuc if (value || isId) {
5361*1230fdc1SLionel Sambuc /* The handling of default attributes gets messed up if we have
5362*1230fdc1SLionel Sambuc a default which duplicates a non-default. */
5363*1230fdc1SLionel Sambuc int i;
5364*1230fdc1SLionel Sambuc for (i = 0; i < type->nDefaultAtts; i++)
5365*1230fdc1SLionel Sambuc if (attId == type->defaultAtts[i].id)
5366*1230fdc1SLionel Sambuc return 1;
5367*1230fdc1SLionel Sambuc if (isId && !type->idAtt && !attId->xmlns)
5368*1230fdc1SLionel Sambuc type->idAtt = attId;
5369*1230fdc1SLionel Sambuc }
5370*1230fdc1SLionel Sambuc if (type->nDefaultAtts == type->allocDefaultAtts) {
5371*1230fdc1SLionel Sambuc if (type->allocDefaultAtts == 0) {
5372*1230fdc1SLionel Sambuc type->allocDefaultAtts = 8;
5373*1230fdc1SLionel Sambuc type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts
5374*1230fdc1SLionel Sambuc * sizeof(DEFAULT_ATTRIBUTE));
5375*1230fdc1SLionel Sambuc if (!type->defaultAtts)
5376*1230fdc1SLionel Sambuc return 0;
5377*1230fdc1SLionel Sambuc }
5378*1230fdc1SLionel Sambuc else {
5379*1230fdc1SLionel Sambuc DEFAULT_ATTRIBUTE *temp;
5380*1230fdc1SLionel Sambuc int count = type->allocDefaultAtts * 2;
5381*1230fdc1SLionel Sambuc temp = (DEFAULT_ATTRIBUTE *)
5382*1230fdc1SLionel Sambuc REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE)));
5383*1230fdc1SLionel Sambuc if (temp == NULL)
5384*1230fdc1SLionel Sambuc return 0;
5385*1230fdc1SLionel Sambuc type->allocDefaultAtts = count;
5386*1230fdc1SLionel Sambuc type->defaultAtts = temp;
5387*1230fdc1SLionel Sambuc }
5388*1230fdc1SLionel Sambuc }
5389*1230fdc1SLionel Sambuc att = type->defaultAtts + type->nDefaultAtts;
5390*1230fdc1SLionel Sambuc att->id = attId;
5391*1230fdc1SLionel Sambuc att->value = value;
5392*1230fdc1SLionel Sambuc att->isCdata = isCdata;
5393*1230fdc1SLionel Sambuc if (!isCdata)
5394*1230fdc1SLionel Sambuc attId->maybeTokenized = XML_TRUE;
5395*1230fdc1SLionel Sambuc type->nDefaultAtts += 1;
5396*1230fdc1SLionel Sambuc return 1;
5397*1230fdc1SLionel Sambuc }
5398*1230fdc1SLionel Sambuc
5399*1230fdc1SLionel Sambuc static int
setElementTypePrefix(XML_Parser parser,ELEMENT_TYPE * elementType)5400*1230fdc1SLionel Sambuc setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType)
5401*1230fdc1SLionel Sambuc {
5402*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
5403*1230fdc1SLionel Sambuc const XML_Char *name;
5404*1230fdc1SLionel Sambuc for (name = elementType->name; *name; name++) {
5405*1230fdc1SLionel Sambuc if (*name == XML_T(ASCII_COLON)) {
5406*1230fdc1SLionel Sambuc PREFIX *prefix;
5407*1230fdc1SLionel Sambuc const XML_Char *s;
5408*1230fdc1SLionel Sambuc for (s = elementType->name; s != name; s++) {
5409*1230fdc1SLionel Sambuc if (!poolAppendChar(&dtd->pool, *s))
5410*1230fdc1SLionel Sambuc return 0;
5411*1230fdc1SLionel Sambuc }
5412*1230fdc1SLionel Sambuc if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5413*1230fdc1SLionel Sambuc return 0;
5414*1230fdc1SLionel Sambuc prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool),
5415*1230fdc1SLionel Sambuc sizeof(PREFIX));
5416*1230fdc1SLionel Sambuc if (!prefix)
5417*1230fdc1SLionel Sambuc return 0;
5418*1230fdc1SLionel Sambuc if (prefix->name == poolStart(&dtd->pool))
5419*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
5420*1230fdc1SLionel Sambuc else
5421*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
5422*1230fdc1SLionel Sambuc elementType->prefix = prefix;
5423*1230fdc1SLionel Sambuc
5424*1230fdc1SLionel Sambuc }
5425*1230fdc1SLionel Sambuc }
5426*1230fdc1SLionel Sambuc return 1;
5427*1230fdc1SLionel Sambuc }
5428*1230fdc1SLionel Sambuc
5429*1230fdc1SLionel Sambuc static ATTRIBUTE_ID *
getAttributeId(XML_Parser parser,const ENCODING * enc,const char * start,const char * end)5430*1230fdc1SLionel Sambuc getAttributeId(XML_Parser parser, const ENCODING *enc,
5431*1230fdc1SLionel Sambuc const char *start, const char *end)
5432*1230fdc1SLionel Sambuc {
5433*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
5434*1230fdc1SLionel Sambuc ATTRIBUTE_ID *id;
5435*1230fdc1SLionel Sambuc const XML_Char *name;
5436*1230fdc1SLionel Sambuc if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5437*1230fdc1SLionel Sambuc return NULL;
5438*1230fdc1SLionel Sambuc name = poolStoreString(&dtd->pool, enc, start, end);
5439*1230fdc1SLionel Sambuc if (!name)
5440*1230fdc1SLionel Sambuc return NULL;
5441*1230fdc1SLionel Sambuc /* skip quotation mark - its storage will be re-used (like in name[-1]) */
5442*1230fdc1SLionel Sambuc ++name;
5443*1230fdc1SLionel Sambuc id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID));
5444*1230fdc1SLionel Sambuc if (!id)
5445*1230fdc1SLionel Sambuc return NULL;
5446*1230fdc1SLionel Sambuc if (id->name != name)
5447*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
5448*1230fdc1SLionel Sambuc else {
5449*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
5450*1230fdc1SLionel Sambuc if (!ns)
5451*1230fdc1SLionel Sambuc ;
5452*1230fdc1SLionel Sambuc else if (name[0] == XML_T(ASCII_x)
5453*1230fdc1SLionel Sambuc && name[1] == XML_T(ASCII_m)
5454*1230fdc1SLionel Sambuc && name[2] == XML_T(ASCII_l)
5455*1230fdc1SLionel Sambuc && name[3] == XML_T(ASCII_n)
5456*1230fdc1SLionel Sambuc && name[4] == XML_T(ASCII_s)
5457*1230fdc1SLionel Sambuc && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) {
5458*1230fdc1SLionel Sambuc if (name[5] == XML_T('\0'))
5459*1230fdc1SLionel Sambuc id->prefix = &dtd->defaultPrefix;
5460*1230fdc1SLionel Sambuc else
5461*1230fdc1SLionel Sambuc id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX));
5462*1230fdc1SLionel Sambuc id->xmlns = XML_TRUE;
5463*1230fdc1SLionel Sambuc }
5464*1230fdc1SLionel Sambuc else {
5465*1230fdc1SLionel Sambuc int i;
5466*1230fdc1SLionel Sambuc for (i = 0; name[i]; i++) {
5467*1230fdc1SLionel Sambuc /* attributes without prefix are *not* in the default namespace */
5468*1230fdc1SLionel Sambuc if (name[i] == XML_T(ASCII_COLON)) {
5469*1230fdc1SLionel Sambuc int j;
5470*1230fdc1SLionel Sambuc for (j = 0; j < i; j++) {
5471*1230fdc1SLionel Sambuc if (!poolAppendChar(&dtd->pool, name[j]))
5472*1230fdc1SLionel Sambuc return NULL;
5473*1230fdc1SLionel Sambuc }
5474*1230fdc1SLionel Sambuc if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5475*1230fdc1SLionel Sambuc return NULL;
5476*1230fdc1SLionel Sambuc id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool),
5477*1230fdc1SLionel Sambuc sizeof(PREFIX));
5478*1230fdc1SLionel Sambuc if (id->prefix->name == poolStart(&dtd->pool))
5479*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
5480*1230fdc1SLionel Sambuc else
5481*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
5482*1230fdc1SLionel Sambuc break;
5483*1230fdc1SLionel Sambuc }
5484*1230fdc1SLionel Sambuc }
5485*1230fdc1SLionel Sambuc }
5486*1230fdc1SLionel Sambuc }
5487*1230fdc1SLionel Sambuc return id;
5488*1230fdc1SLionel Sambuc }
5489*1230fdc1SLionel Sambuc
5490*1230fdc1SLionel Sambuc #define CONTEXT_SEP XML_T(ASCII_FF)
5491*1230fdc1SLionel Sambuc
5492*1230fdc1SLionel Sambuc static const XML_Char *
getContext(XML_Parser parser)5493*1230fdc1SLionel Sambuc getContext(XML_Parser parser)
5494*1230fdc1SLionel Sambuc {
5495*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
5496*1230fdc1SLionel Sambuc HASH_TABLE_ITER iter;
5497*1230fdc1SLionel Sambuc XML_Bool needSep = XML_FALSE;
5498*1230fdc1SLionel Sambuc
5499*1230fdc1SLionel Sambuc if (dtd->defaultPrefix.binding) {
5500*1230fdc1SLionel Sambuc int i;
5501*1230fdc1SLionel Sambuc int len;
5502*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS)))
5503*1230fdc1SLionel Sambuc return NULL;
5504*1230fdc1SLionel Sambuc len = dtd->defaultPrefix.binding->uriLen;
5505*1230fdc1SLionel Sambuc if (namespaceSeparator)
5506*1230fdc1SLionel Sambuc len--;
5507*1230fdc1SLionel Sambuc for (i = 0; i < len; i++)
5508*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i]))
5509*1230fdc1SLionel Sambuc return NULL;
5510*1230fdc1SLionel Sambuc needSep = XML_TRUE;
5511*1230fdc1SLionel Sambuc }
5512*1230fdc1SLionel Sambuc
5513*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(dtd->prefixes));
5514*1230fdc1SLionel Sambuc for (;;) {
5515*1230fdc1SLionel Sambuc int i;
5516*1230fdc1SLionel Sambuc int len;
5517*1230fdc1SLionel Sambuc const XML_Char *s;
5518*1230fdc1SLionel Sambuc PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter);
5519*1230fdc1SLionel Sambuc if (!prefix)
5520*1230fdc1SLionel Sambuc break;
5521*1230fdc1SLionel Sambuc if (!prefix->binding)
5522*1230fdc1SLionel Sambuc continue;
5523*1230fdc1SLionel Sambuc if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
5524*1230fdc1SLionel Sambuc return NULL;
5525*1230fdc1SLionel Sambuc for (s = prefix->name; *s; s++)
5526*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *s))
5527*1230fdc1SLionel Sambuc return NULL;
5528*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS)))
5529*1230fdc1SLionel Sambuc return NULL;
5530*1230fdc1SLionel Sambuc len = prefix->binding->uriLen;
5531*1230fdc1SLionel Sambuc if (namespaceSeparator)
5532*1230fdc1SLionel Sambuc len--;
5533*1230fdc1SLionel Sambuc for (i = 0; i < len; i++)
5534*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, prefix->binding->uri[i]))
5535*1230fdc1SLionel Sambuc return NULL;
5536*1230fdc1SLionel Sambuc needSep = XML_TRUE;
5537*1230fdc1SLionel Sambuc }
5538*1230fdc1SLionel Sambuc
5539*1230fdc1SLionel Sambuc
5540*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(dtd->generalEntities));
5541*1230fdc1SLionel Sambuc for (;;) {
5542*1230fdc1SLionel Sambuc const XML_Char *s;
5543*1230fdc1SLionel Sambuc ENTITY *e = (ENTITY *)hashTableIterNext(&iter);
5544*1230fdc1SLionel Sambuc if (!e)
5545*1230fdc1SLionel Sambuc break;
5546*1230fdc1SLionel Sambuc if (!e->open)
5547*1230fdc1SLionel Sambuc continue;
5548*1230fdc1SLionel Sambuc if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
5549*1230fdc1SLionel Sambuc return NULL;
5550*1230fdc1SLionel Sambuc for (s = e->name; *s; s++)
5551*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *s))
5552*1230fdc1SLionel Sambuc return 0;
5553*1230fdc1SLionel Sambuc needSep = XML_TRUE;
5554*1230fdc1SLionel Sambuc }
5555*1230fdc1SLionel Sambuc
5556*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T('\0')))
5557*1230fdc1SLionel Sambuc return NULL;
5558*1230fdc1SLionel Sambuc return tempPool.start;
5559*1230fdc1SLionel Sambuc }
5560*1230fdc1SLionel Sambuc
5561*1230fdc1SLionel Sambuc static XML_Bool
setContext(XML_Parser parser,const XML_Char * context)5562*1230fdc1SLionel Sambuc setContext(XML_Parser parser, const XML_Char *context)
5563*1230fdc1SLionel Sambuc {
5564*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
5565*1230fdc1SLionel Sambuc const XML_Char *s = context;
5566*1230fdc1SLionel Sambuc
5567*1230fdc1SLionel Sambuc while (*context != XML_T('\0')) {
5568*1230fdc1SLionel Sambuc if (*s == CONTEXT_SEP || *s == XML_T('\0')) {
5569*1230fdc1SLionel Sambuc ENTITY *e;
5570*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T('\0')))
5571*1230fdc1SLionel Sambuc return XML_FALSE;
5572*1230fdc1SLionel Sambuc e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0);
5573*1230fdc1SLionel Sambuc if (e)
5574*1230fdc1SLionel Sambuc e->open = XML_TRUE;
5575*1230fdc1SLionel Sambuc if (*s != XML_T('\0'))
5576*1230fdc1SLionel Sambuc s++;
5577*1230fdc1SLionel Sambuc context = s;
5578*1230fdc1SLionel Sambuc poolDiscard(&tempPool);
5579*1230fdc1SLionel Sambuc }
5580*1230fdc1SLionel Sambuc else if (*s == XML_T(ASCII_EQUALS)) {
5581*1230fdc1SLionel Sambuc PREFIX *prefix;
5582*1230fdc1SLionel Sambuc if (poolLength(&tempPool) == 0)
5583*1230fdc1SLionel Sambuc prefix = &dtd->defaultPrefix;
5584*1230fdc1SLionel Sambuc else {
5585*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T('\0')))
5586*1230fdc1SLionel Sambuc return XML_FALSE;
5587*1230fdc1SLionel Sambuc prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool),
5588*1230fdc1SLionel Sambuc sizeof(PREFIX));
5589*1230fdc1SLionel Sambuc if (!prefix)
5590*1230fdc1SLionel Sambuc return XML_FALSE;
5591*1230fdc1SLionel Sambuc if (prefix->name == poolStart(&tempPool)) {
5592*1230fdc1SLionel Sambuc prefix->name = poolCopyString(&dtd->pool, prefix->name);
5593*1230fdc1SLionel Sambuc if (!prefix->name)
5594*1230fdc1SLionel Sambuc return XML_FALSE;
5595*1230fdc1SLionel Sambuc }
5596*1230fdc1SLionel Sambuc poolDiscard(&tempPool);
5597*1230fdc1SLionel Sambuc }
5598*1230fdc1SLionel Sambuc for (context = s + 1;
5599*1230fdc1SLionel Sambuc *context != CONTEXT_SEP && *context != XML_T('\0');
5600*1230fdc1SLionel Sambuc context++)
5601*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *context))
5602*1230fdc1SLionel Sambuc return XML_FALSE;
5603*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, XML_T('\0')))
5604*1230fdc1SLionel Sambuc return XML_FALSE;
5605*1230fdc1SLionel Sambuc if (addBinding(parser, prefix, NULL, poolStart(&tempPool),
5606*1230fdc1SLionel Sambuc &inheritedBindings) != XML_ERROR_NONE)
5607*1230fdc1SLionel Sambuc return XML_FALSE;
5608*1230fdc1SLionel Sambuc poolDiscard(&tempPool);
5609*1230fdc1SLionel Sambuc if (*context != XML_T('\0'))
5610*1230fdc1SLionel Sambuc ++context;
5611*1230fdc1SLionel Sambuc s = context;
5612*1230fdc1SLionel Sambuc }
5613*1230fdc1SLionel Sambuc else {
5614*1230fdc1SLionel Sambuc if (!poolAppendChar(&tempPool, *s))
5615*1230fdc1SLionel Sambuc return XML_FALSE;
5616*1230fdc1SLionel Sambuc s++;
5617*1230fdc1SLionel Sambuc }
5618*1230fdc1SLionel Sambuc }
5619*1230fdc1SLionel Sambuc return XML_TRUE;
5620*1230fdc1SLionel Sambuc }
5621*1230fdc1SLionel Sambuc
5622*1230fdc1SLionel Sambuc static void FASTCALL
normalizePublicId(XML_Char * publicId)5623*1230fdc1SLionel Sambuc normalizePublicId(XML_Char *publicId)
5624*1230fdc1SLionel Sambuc {
5625*1230fdc1SLionel Sambuc XML_Char *p = publicId;
5626*1230fdc1SLionel Sambuc XML_Char *s;
5627*1230fdc1SLionel Sambuc for (s = publicId; *s; s++) {
5628*1230fdc1SLionel Sambuc switch (*s) {
5629*1230fdc1SLionel Sambuc case 0x20:
5630*1230fdc1SLionel Sambuc case 0xD:
5631*1230fdc1SLionel Sambuc case 0xA:
5632*1230fdc1SLionel Sambuc if (p != publicId && p[-1] != 0x20)
5633*1230fdc1SLionel Sambuc *p++ = 0x20;
5634*1230fdc1SLionel Sambuc break;
5635*1230fdc1SLionel Sambuc default:
5636*1230fdc1SLionel Sambuc *p++ = *s;
5637*1230fdc1SLionel Sambuc }
5638*1230fdc1SLionel Sambuc }
5639*1230fdc1SLionel Sambuc if (p != publicId && p[-1] == 0x20)
5640*1230fdc1SLionel Sambuc --p;
5641*1230fdc1SLionel Sambuc *p = XML_T('\0');
5642*1230fdc1SLionel Sambuc }
5643*1230fdc1SLionel Sambuc
5644*1230fdc1SLionel Sambuc static DTD *
dtdCreate(const XML_Memory_Handling_Suite * ms)5645*1230fdc1SLionel Sambuc dtdCreate(const XML_Memory_Handling_Suite *ms)
5646*1230fdc1SLionel Sambuc {
5647*1230fdc1SLionel Sambuc DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD));
5648*1230fdc1SLionel Sambuc if (p == NULL)
5649*1230fdc1SLionel Sambuc return p;
5650*1230fdc1SLionel Sambuc poolInit(&(p->pool), ms);
5651*1230fdc1SLionel Sambuc poolInit(&(p->entityValuePool), ms);
5652*1230fdc1SLionel Sambuc hashTableInit(&(p->generalEntities), ms);
5653*1230fdc1SLionel Sambuc hashTableInit(&(p->elementTypes), ms);
5654*1230fdc1SLionel Sambuc hashTableInit(&(p->attributeIds), ms);
5655*1230fdc1SLionel Sambuc hashTableInit(&(p->prefixes), ms);
5656*1230fdc1SLionel Sambuc #ifdef XML_DTD
5657*1230fdc1SLionel Sambuc p->paramEntityRead = XML_FALSE;
5658*1230fdc1SLionel Sambuc hashTableInit(&(p->paramEntities), ms);
5659*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5660*1230fdc1SLionel Sambuc p->defaultPrefix.name = NULL;
5661*1230fdc1SLionel Sambuc p->defaultPrefix.binding = NULL;
5662*1230fdc1SLionel Sambuc
5663*1230fdc1SLionel Sambuc p->in_eldecl = XML_FALSE;
5664*1230fdc1SLionel Sambuc p->scaffIndex = NULL;
5665*1230fdc1SLionel Sambuc p->scaffold = NULL;
5666*1230fdc1SLionel Sambuc p->scaffLevel = 0;
5667*1230fdc1SLionel Sambuc p->scaffSize = 0;
5668*1230fdc1SLionel Sambuc p->scaffCount = 0;
5669*1230fdc1SLionel Sambuc p->contentStringLen = 0;
5670*1230fdc1SLionel Sambuc
5671*1230fdc1SLionel Sambuc p->keepProcessing = XML_TRUE;
5672*1230fdc1SLionel Sambuc p->hasParamEntityRefs = XML_FALSE;
5673*1230fdc1SLionel Sambuc p->standalone = XML_FALSE;
5674*1230fdc1SLionel Sambuc return p;
5675*1230fdc1SLionel Sambuc }
5676*1230fdc1SLionel Sambuc
5677*1230fdc1SLionel Sambuc static void
dtdReset(DTD * p,const XML_Memory_Handling_Suite * ms)5678*1230fdc1SLionel Sambuc dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms)
5679*1230fdc1SLionel Sambuc {
5680*1230fdc1SLionel Sambuc HASH_TABLE_ITER iter;
5681*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(p->elementTypes));
5682*1230fdc1SLionel Sambuc for (;;) {
5683*1230fdc1SLionel Sambuc ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter);
5684*1230fdc1SLionel Sambuc if (!e)
5685*1230fdc1SLionel Sambuc break;
5686*1230fdc1SLionel Sambuc if (e->allocDefaultAtts != 0)
5687*1230fdc1SLionel Sambuc ms->free_fcn(e->defaultAtts);
5688*1230fdc1SLionel Sambuc }
5689*1230fdc1SLionel Sambuc hashTableClear(&(p->generalEntities));
5690*1230fdc1SLionel Sambuc #ifdef XML_DTD
5691*1230fdc1SLionel Sambuc p->paramEntityRead = XML_FALSE;
5692*1230fdc1SLionel Sambuc hashTableClear(&(p->paramEntities));
5693*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5694*1230fdc1SLionel Sambuc hashTableClear(&(p->elementTypes));
5695*1230fdc1SLionel Sambuc hashTableClear(&(p->attributeIds));
5696*1230fdc1SLionel Sambuc hashTableClear(&(p->prefixes));
5697*1230fdc1SLionel Sambuc poolClear(&(p->pool));
5698*1230fdc1SLionel Sambuc poolClear(&(p->entityValuePool));
5699*1230fdc1SLionel Sambuc p->defaultPrefix.name = NULL;
5700*1230fdc1SLionel Sambuc p->defaultPrefix.binding = NULL;
5701*1230fdc1SLionel Sambuc
5702*1230fdc1SLionel Sambuc p->in_eldecl = XML_FALSE;
5703*1230fdc1SLionel Sambuc
5704*1230fdc1SLionel Sambuc ms->free_fcn(p->scaffIndex);
5705*1230fdc1SLionel Sambuc p->scaffIndex = NULL;
5706*1230fdc1SLionel Sambuc ms->free_fcn(p->scaffold);
5707*1230fdc1SLionel Sambuc p->scaffold = NULL;
5708*1230fdc1SLionel Sambuc
5709*1230fdc1SLionel Sambuc p->scaffLevel = 0;
5710*1230fdc1SLionel Sambuc p->scaffSize = 0;
5711*1230fdc1SLionel Sambuc p->scaffCount = 0;
5712*1230fdc1SLionel Sambuc p->contentStringLen = 0;
5713*1230fdc1SLionel Sambuc
5714*1230fdc1SLionel Sambuc p->keepProcessing = XML_TRUE;
5715*1230fdc1SLionel Sambuc p->hasParamEntityRefs = XML_FALSE;
5716*1230fdc1SLionel Sambuc p->standalone = XML_FALSE;
5717*1230fdc1SLionel Sambuc }
5718*1230fdc1SLionel Sambuc
5719*1230fdc1SLionel Sambuc static void
dtdDestroy(DTD * p,XML_Bool isDocEntity,const XML_Memory_Handling_Suite * ms)5720*1230fdc1SLionel Sambuc dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms)
5721*1230fdc1SLionel Sambuc {
5722*1230fdc1SLionel Sambuc HASH_TABLE_ITER iter;
5723*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(p->elementTypes));
5724*1230fdc1SLionel Sambuc for (;;) {
5725*1230fdc1SLionel Sambuc ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter);
5726*1230fdc1SLionel Sambuc if (!e)
5727*1230fdc1SLionel Sambuc break;
5728*1230fdc1SLionel Sambuc if (e->allocDefaultAtts != 0)
5729*1230fdc1SLionel Sambuc ms->free_fcn(e->defaultAtts);
5730*1230fdc1SLionel Sambuc }
5731*1230fdc1SLionel Sambuc hashTableDestroy(&(p->generalEntities));
5732*1230fdc1SLionel Sambuc #ifdef XML_DTD
5733*1230fdc1SLionel Sambuc hashTableDestroy(&(p->paramEntities));
5734*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5735*1230fdc1SLionel Sambuc hashTableDestroy(&(p->elementTypes));
5736*1230fdc1SLionel Sambuc hashTableDestroy(&(p->attributeIds));
5737*1230fdc1SLionel Sambuc hashTableDestroy(&(p->prefixes));
5738*1230fdc1SLionel Sambuc poolDestroy(&(p->pool));
5739*1230fdc1SLionel Sambuc poolDestroy(&(p->entityValuePool));
5740*1230fdc1SLionel Sambuc if (isDocEntity) {
5741*1230fdc1SLionel Sambuc ms->free_fcn(p->scaffIndex);
5742*1230fdc1SLionel Sambuc ms->free_fcn(p->scaffold);
5743*1230fdc1SLionel Sambuc }
5744*1230fdc1SLionel Sambuc ms->free_fcn(p);
5745*1230fdc1SLionel Sambuc }
5746*1230fdc1SLionel Sambuc
5747*1230fdc1SLionel Sambuc /* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise.
5748*1230fdc1SLionel Sambuc The new DTD has already been initialized.
5749*1230fdc1SLionel Sambuc */
5750*1230fdc1SLionel Sambuc static int
dtdCopy(XML_Parser oldParser,DTD * newDtd,const DTD * oldDtd,const XML_Memory_Handling_Suite * ms)5751*1230fdc1SLionel Sambuc dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms)
5752*1230fdc1SLionel Sambuc {
5753*1230fdc1SLionel Sambuc HASH_TABLE_ITER iter;
5754*1230fdc1SLionel Sambuc
5755*1230fdc1SLionel Sambuc /* Copy the prefix table. */
5756*1230fdc1SLionel Sambuc
5757*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(oldDtd->prefixes));
5758*1230fdc1SLionel Sambuc for (;;) {
5759*1230fdc1SLionel Sambuc const XML_Char *name;
5760*1230fdc1SLionel Sambuc const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter);
5761*1230fdc1SLionel Sambuc if (!oldP)
5762*1230fdc1SLionel Sambuc break;
5763*1230fdc1SLionel Sambuc name = poolCopyString(&(newDtd->pool), oldP->name);
5764*1230fdc1SLionel Sambuc if (!name)
5765*1230fdc1SLionel Sambuc return 0;
5766*1230fdc1SLionel Sambuc if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX)))
5767*1230fdc1SLionel Sambuc return 0;
5768*1230fdc1SLionel Sambuc }
5769*1230fdc1SLionel Sambuc
5770*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(oldDtd->attributeIds));
5771*1230fdc1SLionel Sambuc
5772*1230fdc1SLionel Sambuc /* Copy the attribute id table. */
5773*1230fdc1SLionel Sambuc
5774*1230fdc1SLionel Sambuc for (;;) {
5775*1230fdc1SLionel Sambuc ATTRIBUTE_ID *newA;
5776*1230fdc1SLionel Sambuc const XML_Char *name;
5777*1230fdc1SLionel Sambuc const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);
5778*1230fdc1SLionel Sambuc
5779*1230fdc1SLionel Sambuc if (!oldA)
5780*1230fdc1SLionel Sambuc break;
5781*1230fdc1SLionel Sambuc /* Remember to allocate the scratch byte before the name. */
5782*1230fdc1SLionel Sambuc if (!poolAppendChar(&(newDtd->pool), XML_T('\0')))
5783*1230fdc1SLionel Sambuc return 0;
5784*1230fdc1SLionel Sambuc name = poolCopyString(&(newDtd->pool), oldA->name);
5785*1230fdc1SLionel Sambuc if (!name)
5786*1230fdc1SLionel Sambuc return 0;
5787*1230fdc1SLionel Sambuc ++name;
5788*1230fdc1SLionel Sambuc newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name,
5789*1230fdc1SLionel Sambuc sizeof(ATTRIBUTE_ID));
5790*1230fdc1SLionel Sambuc if (!newA)
5791*1230fdc1SLionel Sambuc return 0;
5792*1230fdc1SLionel Sambuc newA->maybeTokenized = oldA->maybeTokenized;
5793*1230fdc1SLionel Sambuc if (oldA->prefix) {
5794*1230fdc1SLionel Sambuc newA->xmlns = oldA->xmlns;
5795*1230fdc1SLionel Sambuc if (oldA->prefix == &oldDtd->defaultPrefix)
5796*1230fdc1SLionel Sambuc newA->prefix = &newDtd->defaultPrefix;
5797*1230fdc1SLionel Sambuc else
5798*1230fdc1SLionel Sambuc newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5799*1230fdc1SLionel Sambuc oldA->prefix->name, 0);
5800*1230fdc1SLionel Sambuc }
5801*1230fdc1SLionel Sambuc }
5802*1230fdc1SLionel Sambuc
5803*1230fdc1SLionel Sambuc /* Copy the element type table. */
5804*1230fdc1SLionel Sambuc
5805*1230fdc1SLionel Sambuc hashTableIterInit(&iter, &(oldDtd->elementTypes));
5806*1230fdc1SLionel Sambuc
5807*1230fdc1SLionel Sambuc for (;;) {
5808*1230fdc1SLionel Sambuc int i;
5809*1230fdc1SLionel Sambuc ELEMENT_TYPE *newE;
5810*1230fdc1SLionel Sambuc const XML_Char *name;
5811*1230fdc1SLionel Sambuc const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);
5812*1230fdc1SLionel Sambuc if (!oldE)
5813*1230fdc1SLionel Sambuc break;
5814*1230fdc1SLionel Sambuc name = poolCopyString(&(newDtd->pool), oldE->name);
5815*1230fdc1SLionel Sambuc if (!name)
5816*1230fdc1SLionel Sambuc return 0;
5817*1230fdc1SLionel Sambuc newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name,
5818*1230fdc1SLionel Sambuc sizeof(ELEMENT_TYPE));
5819*1230fdc1SLionel Sambuc if (!newE)
5820*1230fdc1SLionel Sambuc return 0;
5821*1230fdc1SLionel Sambuc if (oldE->nDefaultAtts) {
5822*1230fdc1SLionel Sambuc newE->defaultAtts = (DEFAULT_ATTRIBUTE *)
5823*1230fdc1SLionel Sambuc ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
5824*1230fdc1SLionel Sambuc if (!newE->defaultAtts) {
5825*1230fdc1SLionel Sambuc ms->free_fcn(newE);
5826*1230fdc1SLionel Sambuc return 0;
5827*1230fdc1SLionel Sambuc }
5828*1230fdc1SLionel Sambuc }
5829*1230fdc1SLionel Sambuc if (oldE->idAtt)
5830*1230fdc1SLionel Sambuc newE->idAtt = (ATTRIBUTE_ID *)
5831*1230fdc1SLionel Sambuc lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0);
5832*1230fdc1SLionel Sambuc newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
5833*1230fdc1SLionel Sambuc if (oldE->prefix)
5834*1230fdc1SLionel Sambuc newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5835*1230fdc1SLionel Sambuc oldE->prefix->name, 0);
5836*1230fdc1SLionel Sambuc for (i = 0; i < newE->nDefaultAtts; i++) {
5837*1230fdc1SLionel Sambuc newE->defaultAtts[i].id = (ATTRIBUTE_ID *)
5838*1230fdc1SLionel Sambuc lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
5839*1230fdc1SLionel Sambuc newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
5840*1230fdc1SLionel Sambuc if (oldE->defaultAtts[i].value) {
5841*1230fdc1SLionel Sambuc newE->defaultAtts[i].value
5842*1230fdc1SLionel Sambuc = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value);
5843*1230fdc1SLionel Sambuc if (!newE->defaultAtts[i].value)
5844*1230fdc1SLionel Sambuc return 0;
5845*1230fdc1SLionel Sambuc }
5846*1230fdc1SLionel Sambuc else
5847*1230fdc1SLionel Sambuc newE->defaultAtts[i].value = NULL;
5848*1230fdc1SLionel Sambuc }
5849*1230fdc1SLionel Sambuc }
5850*1230fdc1SLionel Sambuc
5851*1230fdc1SLionel Sambuc /* Copy the entity tables. */
5852*1230fdc1SLionel Sambuc if (!copyEntityTable(oldParser,
5853*1230fdc1SLionel Sambuc &(newDtd->generalEntities),
5854*1230fdc1SLionel Sambuc &(newDtd->pool),
5855*1230fdc1SLionel Sambuc &(oldDtd->generalEntities)))
5856*1230fdc1SLionel Sambuc return 0;
5857*1230fdc1SLionel Sambuc
5858*1230fdc1SLionel Sambuc #ifdef XML_DTD
5859*1230fdc1SLionel Sambuc if (!copyEntityTable(oldParser,
5860*1230fdc1SLionel Sambuc &(newDtd->paramEntities),
5861*1230fdc1SLionel Sambuc &(newDtd->pool),
5862*1230fdc1SLionel Sambuc &(oldDtd->paramEntities)))
5863*1230fdc1SLionel Sambuc return 0;
5864*1230fdc1SLionel Sambuc newDtd->paramEntityRead = oldDtd->paramEntityRead;
5865*1230fdc1SLionel Sambuc #endif /* XML_DTD */
5866*1230fdc1SLionel Sambuc
5867*1230fdc1SLionel Sambuc newDtd->keepProcessing = oldDtd->keepProcessing;
5868*1230fdc1SLionel Sambuc newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs;
5869*1230fdc1SLionel Sambuc newDtd->standalone = oldDtd->standalone;
5870*1230fdc1SLionel Sambuc
5871*1230fdc1SLionel Sambuc /* Don't want deep copying for scaffolding */
5872*1230fdc1SLionel Sambuc newDtd->in_eldecl = oldDtd->in_eldecl;
5873*1230fdc1SLionel Sambuc newDtd->scaffold = oldDtd->scaffold;
5874*1230fdc1SLionel Sambuc newDtd->contentStringLen = oldDtd->contentStringLen;
5875*1230fdc1SLionel Sambuc newDtd->scaffSize = oldDtd->scaffSize;
5876*1230fdc1SLionel Sambuc newDtd->scaffLevel = oldDtd->scaffLevel;
5877*1230fdc1SLionel Sambuc newDtd->scaffIndex = oldDtd->scaffIndex;
5878*1230fdc1SLionel Sambuc
5879*1230fdc1SLionel Sambuc return 1;
5880*1230fdc1SLionel Sambuc } /* End dtdCopy */
5881*1230fdc1SLionel Sambuc
5882*1230fdc1SLionel Sambuc static int
copyEntityTable(XML_Parser oldParser,HASH_TABLE * newTable,STRING_POOL * newPool,const HASH_TABLE * oldTable)5883*1230fdc1SLionel Sambuc copyEntityTable(XML_Parser oldParser,
5884*1230fdc1SLionel Sambuc HASH_TABLE *newTable,
5885*1230fdc1SLionel Sambuc STRING_POOL *newPool,
5886*1230fdc1SLionel Sambuc const HASH_TABLE *oldTable)
5887*1230fdc1SLionel Sambuc {
5888*1230fdc1SLionel Sambuc HASH_TABLE_ITER iter;
5889*1230fdc1SLionel Sambuc const XML_Char *cachedOldBase = NULL;
5890*1230fdc1SLionel Sambuc const XML_Char *cachedNewBase = NULL;
5891*1230fdc1SLionel Sambuc
5892*1230fdc1SLionel Sambuc hashTableIterInit(&iter, oldTable);
5893*1230fdc1SLionel Sambuc
5894*1230fdc1SLionel Sambuc for (;;) {
5895*1230fdc1SLionel Sambuc ENTITY *newE;
5896*1230fdc1SLionel Sambuc const XML_Char *name;
5897*1230fdc1SLionel Sambuc const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);
5898*1230fdc1SLionel Sambuc if (!oldE)
5899*1230fdc1SLionel Sambuc break;
5900*1230fdc1SLionel Sambuc name = poolCopyString(newPool, oldE->name);
5901*1230fdc1SLionel Sambuc if (!name)
5902*1230fdc1SLionel Sambuc return 0;
5903*1230fdc1SLionel Sambuc newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY));
5904*1230fdc1SLionel Sambuc if (!newE)
5905*1230fdc1SLionel Sambuc return 0;
5906*1230fdc1SLionel Sambuc if (oldE->systemId) {
5907*1230fdc1SLionel Sambuc const XML_Char *tem = poolCopyString(newPool, oldE->systemId);
5908*1230fdc1SLionel Sambuc if (!tem)
5909*1230fdc1SLionel Sambuc return 0;
5910*1230fdc1SLionel Sambuc newE->systemId = tem;
5911*1230fdc1SLionel Sambuc if (oldE->base) {
5912*1230fdc1SLionel Sambuc if (oldE->base == cachedOldBase)
5913*1230fdc1SLionel Sambuc newE->base = cachedNewBase;
5914*1230fdc1SLionel Sambuc else {
5915*1230fdc1SLionel Sambuc cachedOldBase = oldE->base;
5916*1230fdc1SLionel Sambuc tem = poolCopyString(newPool, cachedOldBase);
5917*1230fdc1SLionel Sambuc if (!tem)
5918*1230fdc1SLionel Sambuc return 0;
5919*1230fdc1SLionel Sambuc cachedNewBase = newE->base = tem;
5920*1230fdc1SLionel Sambuc }
5921*1230fdc1SLionel Sambuc }
5922*1230fdc1SLionel Sambuc if (oldE->publicId) {
5923*1230fdc1SLionel Sambuc tem = poolCopyString(newPool, oldE->publicId);
5924*1230fdc1SLionel Sambuc if (!tem)
5925*1230fdc1SLionel Sambuc return 0;
5926*1230fdc1SLionel Sambuc newE->publicId = tem;
5927*1230fdc1SLionel Sambuc }
5928*1230fdc1SLionel Sambuc }
5929*1230fdc1SLionel Sambuc else {
5930*1230fdc1SLionel Sambuc const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr,
5931*1230fdc1SLionel Sambuc oldE->textLen);
5932*1230fdc1SLionel Sambuc if (!tem)
5933*1230fdc1SLionel Sambuc return 0;
5934*1230fdc1SLionel Sambuc newE->textPtr = tem;
5935*1230fdc1SLionel Sambuc newE->textLen = oldE->textLen;
5936*1230fdc1SLionel Sambuc }
5937*1230fdc1SLionel Sambuc if (oldE->notation) {
5938*1230fdc1SLionel Sambuc const XML_Char *tem = poolCopyString(newPool, oldE->notation);
5939*1230fdc1SLionel Sambuc if (!tem)
5940*1230fdc1SLionel Sambuc return 0;
5941*1230fdc1SLionel Sambuc newE->notation = tem;
5942*1230fdc1SLionel Sambuc }
5943*1230fdc1SLionel Sambuc newE->is_param = oldE->is_param;
5944*1230fdc1SLionel Sambuc newE->is_internal = oldE->is_internal;
5945*1230fdc1SLionel Sambuc }
5946*1230fdc1SLionel Sambuc return 1;
5947*1230fdc1SLionel Sambuc }
5948*1230fdc1SLionel Sambuc
5949*1230fdc1SLionel Sambuc #define INIT_POWER 6
5950*1230fdc1SLionel Sambuc
5951*1230fdc1SLionel Sambuc static XML_Bool FASTCALL
keyeq(KEY s1,KEY s2)5952*1230fdc1SLionel Sambuc keyeq(KEY s1, KEY s2)
5953*1230fdc1SLionel Sambuc {
5954*1230fdc1SLionel Sambuc for (; *s1 == *s2; s1++, s2++)
5955*1230fdc1SLionel Sambuc if (*s1 == 0)
5956*1230fdc1SLionel Sambuc return XML_TRUE;
5957*1230fdc1SLionel Sambuc return XML_FALSE;
5958*1230fdc1SLionel Sambuc }
5959*1230fdc1SLionel Sambuc
5960*1230fdc1SLionel Sambuc static unsigned long FASTCALL
hash(XML_Parser parser,KEY s)5961*1230fdc1SLionel Sambuc hash(XML_Parser parser, KEY s)
5962*1230fdc1SLionel Sambuc {
5963*1230fdc1SLionel Sambuc unsigned long h = hash_secret_salt;
5964*1230fdc1SLionel Sambuc while (*s)
5965*1230fdc1SLionel Sambuc h = CHAR_HASH(h, *s++);
5966*1230fdc1SLionel Sambuc return h;
5967*1230fdc1SLionel Sambuc }
5968*1230fdc1SLionel Sambuc
5969*1230fdc1SLionel Sambuc static NAMED *
lookup(XML_Parser parser,HASH_TABLE * table,KEY name,size_t createSize)5970*1230fdc1SLionel Sambuc lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize)
5971*1230fdc1SLionel Sambuc {
5972*1230fdc1SLionel Sambuc size_t i;
5973*1230fdc1SLionel Sambuc if (table->size == 0) {
5974*1230fdc1SLionel Sambuc size_t tsize;
5975*1230fdc1SLionel Sambuc if (!createSize)
5976*1230fdc1SLionel Sambuc return NULL;
5977*1230fdc1SLionel Sambuc table->power = INIT_POWER;
5978*1230fdc1SLionel Sambuc /* table->size is a power of 2 */
5979*1230fdc1SLionel Sambuc table->size = (size_t)1 << INIT_POWER;
5980*1230fdc1SLionel Sambuc tsize = table->size * sizeof(NAMED *);
5981*1230fdc1SLionel Sambuc table->v = (NAMED **)table->mem->malloc_fcn(tsize);
5982*1230fdc1SLionel Sambuc if (!table->v) {
5983*1230fdc1SLionel Sambuc table->size = 0;
5984*1230fdc1SLionel Sambuc return NULL;
5985*1230fdc1SLionel Sambuc }
5986*1230fdc1SLionel Sambuc memset(table->v, 0, tsize);
5987*1230fdc1SLionel Sambuc i = hash(parser, name) & ((unsigned long)table->size - 1);
5988*1230fdc1SLionel Sambuc }
5989*1230fdc1SLionel Sambuc else {
5990*1230fdc1SLionel Sambuc unsigned long h = hash(parser, name);
5991*1230fdc1SLionel Sambuc unsigned long mask = (unsigned long)table->size - 1;
5992*1230fdc1SLionel Sambuc unsigned char step = 0;
5993*1230fdc1SLionel Sambuc i = h & mask;
5994*1230fdc1SLionel Sambuc while (table->v[i]) {
5995*1230fdc1SLionel Sambuc if (keyeq(name, table->v[i]->name))
5996*1230fdc1SLionel Sambuc return table->v[i];
5997*1230fdc1SLionel Sambuc if (!step)
5998*1230fdc1SLionel Sambuc step = PROBE_STEP(h, mask, table->power);
5999*1230fdc1SLionel Sambuc i < step ? (i += table->size - step) : (i -= step);
6000*1230fdc1SLionel Sambuc }
6001*1230fdc1SLionel Sambuc if (!createSize)
6002*1230fdc1SLionel Sambuc return NULL;
6003*1230fdc1SLionel Sambuc
6004*1230fdc1SLionel Sambuc /* check for overflow (table is half full) */
6005*1230fdc1SLionel Sambuc if (table->used >> (table->power - 1)) {
6006*1230fdc1SLionel Sambuc unsigned char newPower = table->power + 1;
6007*1230fdc1SLionel Sambuc size_t newSize = (size_t)1 << newPower;
6008*1230fdc1SLionel Sambuc unsigned long newMask = (unsigned long)newSize - 1;
6009*1230fdc1SLionel Sambuc size_t tsize = newSize * sizeof(NAMED *);
6010*1230fdc1SLionel Sambuc NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize);
6011*1230fdc1SLionel Sambuc if (!newV)
6012*1230fdc1SLionel Sambuc return NULL;
6013*1230fdc1SLionel Sambuc memset(newV, 0, tsize);
6014*1230fdc1SLionel Sambuc for (i = 0; i < table->size; i++)
6015*1230fdc1SLionel Sambuc if (table->v[i]) {
6016*1230fdc1SLionel Sambuc unsigned long newHash = hash(parser, table->v[i]->name);
6017*1230fdc1SLionel Sambuc size_t j = newHash & newMask;
6018*1230fdc1SLionel Sambuc step = 0;
6019*1230fdc1SLionel Sambuc while (newV[j]) {
6020*1230fdc1SLionel Sambuc if (!step)
6021*1230fdc1SLionel Sambuc step = PROBE_STEP(newHash, newMask, newPower);
6022*1230fdc1SLionel Sambuc j < step ? (j += newSize - step) : (j -= step);
6023*1230fdc1SLionel Sambuc }
6024*1230fdc1SLionel Sambuc newV[j] = table->v[i];
6025*1230fdc1SLionel Sambuc }
6026*1230fdc1SLionel Sambuc table->mem->free_fcn(table->v);
6027*1230fdc1SLionel Sambuc table->v = newV;
6028*1230fdc1SLionel Sambuc table->power = newPower;
6029*1230fdc1SLionel Sambuc table->size = newSize;
6030*1230fdc1SLionel Sambuc i = h & newMask;
6031*1230fdc1SLionel Sambuc step = 0;
6032*1230fdc1SLionel Sambuc while (table->v[i]) {
6033*1230fdc1SLionel Sambuc if (!step)
6034*1230fdc1SLionel Sambuc step = PROBE_STEP(h, newMask, newPower);
6035*1230fdc1SLionel Sambuc i < step ? (i += newSize - step) : (i -= step);
6036*1230fdc1SLionel Sambuc }
6037*1230fdc1SLionel Sambuc }
6038*1230fdc1SLionel Sambuc }
6039*1230fdc1SLionel Sambuc table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize);
6040*1230fdc1SLionel Sambuc if (!table->v[i])
6041*1230fdc1SLionel Sambuc return NULL;
6042*1230fdc1SLionel Sambuc memset(table->v[i], 0, createSize);
6043*1230fdc1SLionel Sambuc table->v[i]->name = name;
6044*1230fdc1SLionel Sambuc (table->used)++;
6045*1230fdc1SLionel Sambuc return table->v[i];
6046*1230fdc1SLionel Sambuc }
6047*1230fdc1SLionel Sambuc
6048*1230fdc1SLionel Sambuc static void FASTCALL
hashTableClear(HASH_TABLE * table)6049*1230fdc1SLionel Sambuc hashTableClear(HASH_TABLE *table)
6050*1230fdc1SLionel Sambuc {
6051*1230fdc1SLionel Sambuc size_t i;
6052*1230fdc1SLionel Sambuc for (i = 0; i < table->size; i++) {
6053*1230fdc1SLionel Sambuc table->mem->free_fcn(table->v[i]);
6054*1230fdc1SLionel Sambuc table->v[i] = NULL;
6055*1230fdc1SLionel Sambuc }
6056*1230fdc1SLionel Sambuc table->used = 0;
6057*1230fdc1SLionel Sambuc }
6058*1230fdc1SLionel Sambuc
6059*1230fdc1SLionel Sambuc static void FASTCALL
hashTableDestroy(HASH_TABLE * table)6060*1230fdc1SLionel Sambuc hashTableDestroy(HASH_TABLE *table)
6061*1230fdc1SLionel Sambuc {
6062*1230fdc1SLionel Sambuc size_t i;
6063*1230fdc1SLionel Sambuc for (i = 0; i < table->size; i++)
6064*1230fdc1SLionel Sambuc table->mem->free_fcn(table->v[i]);
6065*1230fdc1SLionel Sambuc table->mem->free_fcn(table->v);
6066*1230fdc1SLionel Sambuc }
6067*1230fdc1SLionel Sambuc
6068*1230fdc1SLionel Sambuc static void FASTCALL
hashTableInit(HASH_TABLE * p,const XML_Memory_Handling_Suite * ms)6069*1230fdc1SLionel Sambuc hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms)
6070*1230fdc1SLionel Sambuc {
6071*1230fdc1SLionel Sambuc p->power = 0;
6072*1230fdc1SLionel Sambuc p->size = 0;
6073*1230fdc1SLionel Sambuc p->used = 0;
6074*1230fdc1SLionel Sambuc p->v = NULL;
6075*1230fdc1SLionel Sambuc p->mem = ms;
6076*1230fdc1SLionel Sambuc }
6077*1230fdc1SLionel Sambuc
6078*1230fdc1SLionel Sambuc static void FASTCALL
hashTableIterInit(HASH_TABLE_ITER * iter,const HASH_TABLE * table)6079*1230fdc1SLionel Sambuc hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table)
6080*1230fdc1SLionel Sambuc {
6081*1230fdc1SLionel Sambuc iter->p = table->v;
6082*1230fdc1SLionel Sambuc iter->end = iter->p + table->size;
6083*1230fdc1SLionel Sambuc }
6084*1230fdc1SLionel Sambuc
6085*1230fdc1SLionel Sambuc static NAMED * FASTCALL
hashTableIterNext(HASH_TABLE_ITER * iter)6086*1230fdc1SLionel Sambuc hashTableIterNext(HASH_TABLE_ITER *iter)
6087*1230fdc1SLionel Sambuc {
6088*1230fdc1SLionel Sambuc while (iter->p != iter->end) {
6089*1230fdc1SLionel Sambuc NAMED *tem = *(iter->p)++;
6090*1230fdc1SLionel Sambuc if (tem)
6091*1230fdc1SLionel Sambuc return tem;
6092*1230fdc1SLionel Sambuc }
6093*1230fdc1SLionel Sambuc return NULL;
6094*1230fdc1SLionel Sambuc }
6095*1230fdc1SLionel Sambuc
6096*1230fdc1SLionel Sambuc static void FASTCALL
poolInit(STRING_POOL * pool,const XML_Memory_Handling_Suite * ms)6097*1230fdc1SLionel Sambuc poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms)
6098*1230fdc1SLionel Sambuc {
6099*1230fdc1SLionel Sambuc pool->blocks = NULL;
6100*1230fdc1SLionel Sambuc pool->freeBlocks = NULL;
6101*1230fdc1SLionel Sambuc pool->start = NULL;
6102*1230fdc1SLionel Sambuc pool->ptr = NULL;
6103*1230fdc1SLionel Sambuc pool->end = NULL;
6104*1230fdc1SLionel Sambuc pool->mem = ms;
6105*1230fdc1SLionel Sambuc }
6106*1230fdc1SLionel Sambuc
6107*1230fdc1SLionel Sambuc static void FASTCALL
poolClear(STRING_POOL * pool)6108*1230fdc1SLionel Sambuc poolClear(STRING_POOL *pool)
6109*1230fdc1SLionel Sambuc {
6110*1230fdc1SLionel Sambuc if (!pool->freeBlocks)
6111*1230fdc1SLionel Sambuc pool->freeBlocks = pool->blocks;
6112*1230fdc1SLionel Sambuc else {
6113*1230fdc1SLionel Sambuc BLOCK *p = pool->blocks;
6114*1230fdc1SLionel Sambuc while (p) {
6115*1230fdc1SLionel Sambuc BLOCK *tem = p->next;
6116*1230fdc1SLionel Sambuc p->next = pool->freeBlocks;
6117*1230fdc1SLionel Sambuc pool->freeBlocks = p;
6118*1230fdc1SLionel Sambuc p = tem;
6119*1230fdc1SLionel Sambuc }
6120*1230fdc1SLionel Sambuc }
6121*1230fdc1SLionel Sambuc pool->blocks = NULL;
6122*1230fdc1SLionel Sambuc pool->start = NULL;
6123*1230fdc1SLionel Sambuc pool->ptr = NULL;
6124*1230fdc1SLionel Sambuc pool->end = NULL;
6125*1230fdc1SLionel Sambuc }
6126*1230fdc1SLionel Sambuc
6127*1230fdc1SLionel Sambuc static void FASTCALL
poolDestroy(STRING_POOL * pool)6128*1230fdc1SLionel Sambuc poolDestroy(STRING_POOL *pool)
6129*1230fdc1SLionel Sambuc {
6130*1230fdc1SLionel Sambuc BLOCK *p = pool->blocks;
6131*1230fdc1SLionel Sambuc while (p) {
6132*1230fdc1SLionel Sambuc BLOCK *tem = p->next;
6133*1230fdc1SLionel Sambuc pool->mem->free_fcn(p);
6134*1230fdc1SLionel Sambuc p = tem;
6135*1230fdc1SLionel Sambuc }
6136*1230fdc1SLionel Sambuc p = pool->freeBlocks;
6137*1230fdc1SLionel Sambuc while (p) {
6138*1230fdc1SLionel Sambuc BLOCK *tem = p->next;
6139*1230fdc1SLionel Sambuc pool->mem->free_fcn(p);
6140*1230fdc1SLionel Sambuc p = tem;
6141*1230fdc1SLionel Sambuc }
6142*1230fdc1SLionel Sambuc }
6143*1230fdc1SLionel Sambuc
6144*1230fdc1SLionel Sambuc static XML_Char *
poolAppend(STRING_POOL * pool,const ENCODING * enc,const char * ptr,const char * end)6145*1230fdc1SLionel Sambuc poolAppend(STRING_POOL *pool, const ENCODING *enc,
6146*1230fdc1SLionel Sambuc const char *ptr, const char *end)
6147*1230fdc1SLionel Sambuc {
6148*1230fdc1SLionel Sambuc if (!pool->ptr && !poolGrow(pool))
6149*1230fdc1SLionel Sambuc return NULL;
6150*1230fdc1SLionel Sambuc for (;;) {
6151*1230fdc1SLionel Sambuc XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end);
6152*1230fdc1SLionel Sambuc if (ptr == end)
6153*1230fdc1SLionel Sambuc break;
6154*1230fdc1SLionel Sambuc if (!poolGrow(pool))
6155*1230fdc1SLionel Sambuc return NULL;
6156*1230fdc1SLionel Sambuc }
6157*1230fdc1SLionel Sambuc return pool->start;
6158*1230fdc1SLionel Sambuc }
6159*1230fdc1SLionel Sambuc
6160*1230fdc1SLionel Sambuc static const XML_Char * FASTCALL
poolCopyString(STRING_POOL * pool,const XML_Char * s)6161*1230fdc1SLionel Sambuc poolCopyString(STRING_POOL *pool, const XML_Char *s)
6162*1230fdc1SLionel Sambuc {
6163*1230fdc1SLionel Sambuc do {
6164*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, *s))
6165*1230fdc1SLionel Sambuc return NULL;
6166*1230fdc1SLionel Sambuc } while (*s++);
6167*1230fdc1SLionel Sambuc s = pool->start;
6168*1230fdc1SLionel Sambuc poolFinish(pool);
6169*1230fdc1SLionel Sambuc return s;
6170*1230fdc1SLionel Sambuc }
6171*1230fdc1SLionel Sambuc
6172*1230fdc1SLionel Sambuc static const XML_Char *
poolCopyStringN(STRING_POOL * pool,const XML_Char * s,int n)6173*1230fdc1SLionel Sambuc poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n)
6174*1230fdc1SLionel Sambuc {
6175*1230fdc1SLionel Sambuc if (!pool->ptr && !poolGrow(pool))
6176*1230fdc1SLionel Sambuc return NULL;
6177*1230fdc1SLionel Sambuc for (; n > 0; --n, s++) {
6178*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, *s))
6179*1230fdc1SLionel Sambuc return NULL;
6180*1230fdc1SLionel Sambuc }
6181*1230fdc1SLionel Sambuc s = pool->start;
6182*1230fdc1SLionel Sambuc poolFinish(pool);
6183*1230fdc1SLionel Sambuc return s;
6184*1230fdc1SLionel Sambuc }
6185*1230fdc1SLionel Sambuc
6186*1230fdc1SLionel Sambuc static const XML_Char * FASTCALL
poolAppendString(STRING_POOL * pool,const XML_Char * s)6187*1230fdc1SLionel Sambuc poolAppendString(STRING_POOL *pool, const XML_Char *s)
6188*1230fdc1SLionel Sambuc {
6189*1230fdc1SLionel Sambuc while (*s) {
6190*1230fdc1SLionel Sambuc if (!poolAppendChar(pool, *s))
6191*1230fdc1SLionel Sambuc return NULL;
6192*1230fdc1SLionel Sambuc s++;
6193*1230fdc1SLionel Sambuc }
6194*1230fdc1SLionel Sambuc return pool->start;
6195*1230fdc1SLionel Sambuc }
6196*1230fdc1SLionel Sambuc
6197*1230fdc1SLionel Sambuc static XML_Char *
poolStoreString(STRING_POOL * pool,const ENCODING * enc,const char * ptr,const char * end)6198*1230fdc1SLionel Sambuc poolStoreString(STRING_POOL *pool, const ENCODING *enc,
6199*1230fdc1SLionel Sambuc const char *ptr, const char *end)
6200*1230fdc1SLionel Sambuc {
6201*1230fdc1SLionel Sambuc if (!poolAppend(pool, enc, ptr, end))
6202*1230fdc1SLionel Sambuc return NULL;
6203*1230fdc1SLionel Sambuc if (pool->ptr == pool->end && !poolGrow(pool))
6204*1230fdc1SLionel Sambuc return NULL;
6205*1230fdc1SLionel Sambuc *(pool->ptr)++ = 0;
6206*1230fdc1SLionel Sambuc return pool->start;
6207*1230fdc1SLionel Sambuc }
6208*1230fdc1SLionel Sambuc
6209*1230fdc1SLionel Sambuc static XML_Bool FASTCALL
poolGrow(STRING_POOL * pool)6210*1230fdc1SLionel Sambuc poolGrow(STRING_POOL *pool)
6211*1230fdc1SLionel Sambuc {
6212*1230fdc1SLionel Sambuc if (pool->freeBlocks) {
6213*1230fdc1SLionel Sambuc if (pool->start == 0) {
6214*1230fdc1SLionel Sambuc pool->blocks = pool->freeBlocks;
6215*1230fdc1SLionel Sambuc pool->freeBlocks = pool->freeBlocks->next;
6216*1230fdc1SLionel Sambuc pool->blocks->next = NULL;
6217*1230fdc1SLionel Sambuc pool->start = pool->blocks->s;
6218*1230fdc1SLionel Sambuc pool->end = pool->start + pool->blocks->size;
6219*1230fdc1SLionel Sambuc pool->ptr = pool->start;
6220*1230fdc1SLionel Sambuc return XML_TRUE;
6221*1230fdc1SLionel Sambuc }
6222*1230fdc1SLionel Sambuc if (pool->end - pool->start < pool->freeBlocks->size) {
6223*1230fdc1SLionel Sambuc BLOCK *tem = pool->freeBlocks->next;
6224*1230fdc1SLionel Sambuc pool->freeBlocks->next = pool->blocks;
6225*1230fdc1SLionel Sambuc pool->blocks = pool->freeBlocks;
6226*1230fdc1SLionel Sambuc pool->freeBlocks = tem;
6227*1230fdc1SLionel Sambuc memcpy(pool->blocks->s, pool->start,
6228*1230fdc1SLionel Sambuc (pool->end - pool->start) * sizeof(XML_Char));
6229*1230fdc1SLionel Sambuc pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6230*1230fdc1SLionel Sambuc pool->start = pool->blocks->s;
6231*1230fdc1SLionel Sambuc pool->end = pool->start + pool->blocks->size;
6232*1230fdc1SLionel Sambuc return XML_TRUE;
6233*1230fdc1SLionel Sambuc }
6234*1230fdc1SLionel Sambuc }
6235*1230fdc1SLionel Sambuc if (pool->blocks && pool->start == pool->blocks->s) {
6236*1230fdc1SLionel Sambuc int blockSize = (int)(pool->end - pool->start)*2;
6237*1230fdc1SLionel Sambuc BLOCK *temp = (BLOCK *)
6238*1230fdc1SLionel Sambuc pool->mem->realloc_fcn(pool->blocks,
6239*1230fdc1SLionel Sambuc (offsetof(BLOCK, s)
6240*1230fdc1SLionel Sambuc + blockSize * sizeof(XML_Char)));
6241*1230fdc1SLionel Sambuc if (temp == NULL)
6242*1230fdc1SLionel Sambuc return XML_FALSE;
6243*1230fdc1SLionel Sambuc pool->blocks = temp;
6244*1230fdc1SLionel Sambuc pool->blocks->size = blockSize;
6245*1230fdc1SLionel Sambuc pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
6246*1230fdc1SLionel Sambuc pool->start = pool->blocks->s;
6247*1230fdc1SLionel Sambuc pool->end = pool->start + blockSize;
6248*1230fdc1SLionel Sambuc }
6249*1230fdc1SLionel Sambuc else {
6250*1230fdc1SLionel Sambuc BLOCK *tem;
6251*1230fdc1SLionel Sambuc int blockSize = (int)(pool->end - pool->start);
6252*1230fdc1SLionel Sambuc if (blockSize < INIT_BLOCK_SIZE)
6253*1230fdc1SLionel Sambuc blockSize = INIT_BLOCK_SIZE;
6254*1230fdc1SLionel Sambuc else
6255*1230fdc1SLionel Sambuc blockSize *= 2;
6256*1230fdc1SLionel Sambuc tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s)
6257*1230fdc1SLionel Sambuc + blockSize * sizeof(XML_Char));
6258*1230fdc1SLionel Sambuc if (!tem)
6259*1230fdc1SLionel Sambuc return XML_FALSE;
6260*1230fdc1SLionel Sambuc tem->size = blockSize;
6261*1230fdc1SLionel Sambuc tem->next = pool->blocks;
6262*1230fdc1SLionel Sambuc pool->blocks = tem;
6263*1230fdc1SLionel Sambuc if (pool->ptr != pool->start)
6264*1230fdc1SLionel Sambuc memcpy(tem->s, pool->start,
6265*1230fdc1SLionel Sambuc (pool->ptr - pool->start) * sizeof(XML_Char));
6266*1230fdc1SLionel Sambuc pool->ptr = tem->s + (pool->ptr - pool->start);
6267*1230fdc1SLionel Sambuc pool->start = tem->s;
6268*1230fdc1SLionel Sambuc pool->end = tem->s + blockSize;
6269*1230fdc1SLionel Sambuc }
6270*1230fdc1SLionel Sambuc return XML_TRUE;
6271*1230fdc1SLionel Sambuc }
6272*1230fdc1SLionel Sambuc
6273*1230fdc1SLionel Sambuc static int FASTCALL
nextScaffoldPart(XML_Parser parser)6274*1230fdc1SLionel Sambuc nextScaffoldPart(XML_Parser parser)
6275*1230fdc1SLionel Sambuc {
6276*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
6277*1230fdc1SLionel Sambuc CONTENT_SCAFFOLD * me;
6278*1230fdc1SLionel Sambuc int next;
6279*1230fdc1SLionel Sambuc
6280*1230fdc1SLionel Sambuc if (!dtd->scaffIndex) {
6281*1230fdc1SLionel Sambuc dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int));
6282*1230fdc1SLionel Sambuc if (!dtd->scaffIndex)
6283*1230fdc1SLionel Sambuc return -1;
6284*1230fdc1SLionel Sambuc dtd->scaffIndex[0] = 0;
6285*1230fdc1SLionel Sambuc }
6286*1230fdc1SLionel Sambuc
6287*1230fdc1SLionel Sambuc if (dtd->scaffCount >= dtd->scaffSize) {
6288*1230fdc1SLionel Sambuc CONTENT_SCAFFOLD *temp;
6289*1230fdc1SLionel Sambuc if (dtd->scaffold) {
6290*1230fdc1SLionel Sambuc temp = (CONTENT_SCAFFOLD *)
6291*1230fdc1SLionel Sambuc REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD));
6292*1230fdc1SLionel Sambuc if (temp == NULL)
6293*1230fdc1SLionel Sambuc return -1;
6294*1230fdc1SLionel Sambuc dtd->scaffSize *= 2;
6295*1230fdc1SLionel Sambuc }
6296*1230fdc1SLionel Sambuc else {
6297*1230fdc1SLionel Sambuc temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS
6298*1230fdc1SLionel Sambuc * sizeof(CONTENT_SCAFFOLD));
6299*1230fdc1SLionel Sambuc if (temp == NULL)
6300*1230fdc1SLionel Sambuc return -1;
6301*1230fdc1SLionel Sambuc dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS;
6302*1230fdc1SLionel Sambuc }
6303*1230fdc1SLionel Sambuc dtd->scaffold = temp;
6304*1230fdc1SLionel Sambuc }
6305*1230fdc1SLionel Sambuc next = dtd->scaffCount++;
6306*1230fdc1SLionel Sambuc me = &dtd->scaffold[next];
6307*1230fdc1SLionel Sambuc if (dtd->scaffLevel) {
6308*1230fdc1SLionel Sambuc CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]];
6309*1230fdc1SLionel Sambuc if (parent->lastchild) {
6310*1230fdc1SLionel Sambuc dtd->scaffold[parent->lastchild].nextsib = next;
6311*1230fdc1SLionel Sambuc }
6312*1230fdc1SLionel Sambuc if (!parent->childcnt)
6313*1230fdc1SLionel Sambuc parent->firstchild = next;
6314*1230fdc1SLionel Sambuc parent->lastchild = next;
6315*1230fdc1SLionel Sambuc parent->childcnt++;
6316*1230fdc1SLionel Sambuc }
6317*1230fdc1SLionel Sambuc me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0;
6318*1230fdc1SLionel Sambuc return next;
6319*1230fdc1SLionel Sambuc }
6320*1230fdc1SLionel Sambuc
6321*1230fdc1SLionel Sambuc static void
build_node(XML_Parser parser,int src_node,XML_Content * dest,XML_Content ** contpos,XML_Char ** strpos)6322*1230fdc1SLionel Sambuc build_node(XML_Parser parser,
6323*1230fdc1SLionel Sambuc int src_node,
6324*1230fdc1SLionel Sambuc XML_Content *dest,
6325*1230fdc1SLionel Sambuc XML_Content **contpos,
6326*1230fdc1SLionel Sambuc XML_Char **strpos)
6327*1230fdc1SLionel Sambuc {
6328*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
6329*1230fdc1SLionel Sambuc dest->type = dtd->scaffold[src_node].type;
6330*1230fdc1SLionel Sambuc dest->quant = dtd->scaffold[src_node].quant;
6331*1230fdc1SLionel Sambuc if (dest->type == XML_CTYPE_NAME) {
6332*1230fdc1SLionel Sambuc const XML_Char *src;
6333*1230fdc1SLionel Sambuc dest->name = *strpos;
6334*1230fdc1SLionel Sambuc src = dtd->scaffold[src_node].name;
6335*1230fdc1SLionel Sambuc for (;;) {
6336*1230fdc1SLionel Sambuc *(*strpos)++ = *src;
6337*1230fdc1SLionel Sambuc if (!*src)
6338*1230fdc1SLionel Sambuc break;
6339*1230fdc1SLionel Sambuc src++;
6340*1230fdc1SLionel Sambuc }
6341*1230fdc1SLionel Sambuc dest->numchildren = 0;
6342*1230fdc1SLionel Sambuc dest->children = NULL;
6343*1230fdc1SLionel Sambuc }
6344*1230fdc1SLionel Sambuc else {
6345*1230fdc1SLionel Sambuc unsigned int i;
6346*1230fdc1SLionel Sambuc int cn;
6347*1230fdc1SLionel Sambuc dest->numchildren = dtd->scaffold[src_node].childcnt;
6348*1230fdc1SLionel Sambuc dest->children = *contpos;
6349*1230fdc1SLionel Sambuc *contpos += dest->numchildren;
6350*1230fdc1SLionel Sambuc for (i = 0, cn = dtd->scaffold[src_node].firstchild;
6351*1230fdc1SLionel Sambuc i < dest->numchildren;
6352*1230fdc1SLionel Sambuc i++, cn = dtd->scaffold[cn].nextsib) {
6353*1230fdc1SLionel Sambuc build_node(parser, cn, &(dest->children[i]), contpos, strpos);
6354*1230fdc1SLionel Sambuc }
6355*1230fdc1SLionel Sambuc dest->name = NULL;
6356*1230fdc1SLionel Sambuc }
6357*1230fdc1SLionel Sambuc }
6358*1230fdc1SLionel Sambuc
6359*1230fdc1SLionel Sambuc static XML_Content *
build_model(XML_Parser parser)6360*1230fdc1SLionel Sambuc build_model (XML_Parser parser)
6361*1230fdc1SLionel Sambuc {
6362*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
6363*1230fdc1SLionel Sambuc XML_Content *ret;
6364*1230fdc1SLionel Sambuc XML_Content *cpos;
6365*1230fdc1SLionel Sambuc XML_Char * str;
6366*1230fdc1SLionel Sambuc int allocsize = (dtd->scaffCount * sizeof(XML_Content)
6367*1230fdc1SLionel Sambuc + (dtd->contentStringLen * sizeof(XML_Char)));
6368*1230fdc1SLionel Sambuc
6369*1230fdc1SLionel Sambuc ret = (XML_Content *)MALLOC(allocsize);
6370*1230fdc1SLionel Sambuc if (!ret)
6371*1230fdc1SLionel Sambuc return NULL;
6372*1230fdc1SLionel Sambuc
6373*1230fdc1SLionel Sambuc str = (XML_Char *) (&ret[dtd->scaffCount]);
6374*1230fdc1SLionel Sambuc cpos = &ret[1];
6375*1230fdc1SLionel Sambuc
6376*1230fdc1SLionel Sambuc build_node(parser, 0, ret, &cpos, &str);
6377*1230fdc1SLionel Sambuc return ret;
6378*1230fdc1SLionel Sambuc }
6379*1230fdc1SLionel Sambuc
6380*1230fdc1SLionel Sambuc static ELEMENT_TYPE *
getElementType(XML_Parser parser,const ENCODING * enc,const char * ptr,const char * end)6381*1230fdc1SLionel Sambuc getElementType(XML_Parser parser,
6382*1230fdc1SLionel Sambuc const ENCODING *enc,
6383*1230fdc1SLionel Sambuc const char *ptr,
6384*1230fdc1SLionel Sambuc const char *end)
6385*1230fdc1SLionel Sambuc {
6386*1230fdc1SLionel Sambuc DTD * const dtd = _dtd; /* save one level of indirection */
6387*1230fdc1SLionel Sambuc const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end);
6388*1230fdc1SLionel Sambuc ELEMENT_TYPE *ret;
6389*1230fdc1SLionel Sambuc
6390*1230fdc1SLionel Sambuc if (!name)
6391*1230fdc1SLionel Sambuc return NULL;
6392*1230fdc1SLionel Sambuc ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE));
6393*1230fdc1SLionel Sambuc if (!ret)
6394*1230fdc1SLionel Sambuc return NULL;
6395*1230fdc1SLionel Sambuc if (ret->name != name)
6396*1230fdc1SLionel Sambuc poolDiscard(&dtd->pool);
6397*1230fdc1SLionel Sambuc else {
6398*1230fdc1SLionel Sambuc poolFinish(&dtd->pool);
6399*1230fdc1SLionel Sambuc if (!setElementTypePrefix(parser, ret))
6400*1230fdc1SLionel Sambuc return NULL;
6401*1230fdc1SLionel Sambuc }
6402*1230fdc1SLionel Sambuc return ret;
6403*1230fdc1SLionel Sambuc }
6404