Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: third_party/libxml/src/parser.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove suppressions, have landed in blink now Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly 2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly
3 * implemented on top of the SAX interfaces 3 * implemented on top of the SAX interfaces
4 * 4 *
5 * References: 5 * References:
6 * The XML specification: 6 * The XML specification:
7 * http://www.w3.org/TR/REC-xml 7 * http://www.w3.org/TR/REC-xml
8 * Original 1.0 version: 8 * Original 1.0 version:
9 * http://www.w3.org/TR/1998/REC-xml-19980210 9 * http://www.w3.org/TR/1998/REC-xml-19980210
10 * XML second edition working draft 10 * XML second edition working draft
11 * http://www.w3.org/TR/2000/WD-xml-2e-20000814 11 * http://www.w3.org/TR/2000/WD-xml-2e-20000814
12 * 12 *
13 * Okay this is a big file, the parser core is around 7000 lines, then it 13 * Okay this is a big file, the parser core is around 7000 lines, then it
14 * is followed by the progressive parser top routines, then the various 14 * is followed by the progressive parser top routines, then the various
15 * high level APIs to call the parser and a few miscellaneous functions. 15 * high level APIs to call the parser and a few miscellaneous functions.
16 * A number of helper functions and deprecated ones have been moved to 16 * A number of helper functions and deprecated ones have been moved to
17 * parserInternals.c to reduce this file size. 17 * parserInternals.c to reduce this file size.
18 * As much as possible the functions are associated with their relative 18 * As much as possible the functions are associated with their relative
19 * production in the XML specification. A few productions defining the 19 * production in the XML specification. A few productions defining the
20 * different ranges of character are actually implanted either in 20 * different ranges of character are actually implanted either in
21 * parserInternals.h or parserInternals.c 21 * parserInternals.h or parserInternals.c
22 * The DOM tree build is realized from the default SAX callbacks in 22 * The DOM tree build is realized from the default SAX callbacks in
23 * the module SAX.c. 23 * the module SAX.c.
24 * The routines doing the validation checks are in valid.c and called either 24 * The routines doing the validation checks are in valid.c and called either
25 * from the SAX callbacks or as standalone functions using a preparsed 25 * from the SAX callbacks or as standalone functions using a preparsed
26 * document. 26 * document.
27 * 27 *
28 * See Copyright for the status of this software. 28 * See Copyright for the status of this software.
29 * 29 *
30 * daniel@veillard.com 30 * daniel@veillard.com
31 */ 31 */
32 32
33 #define IN_LIBXML 33 #define IN_LIBXML
34 #include "libxml.h" 34 #include "libxml.h"
35 35
36 #if defined(WIN32) && !defined (__CYGWIN__) 36 #if defined(WIN32) && !defined (__CYGWIN__)
37 #define XML_DIR_SEP '\\' 37 #define XML_DIR_SEP '\\'
38 #else 38 #else
39 #define XML_DIR_SEP '/' 39 #define XML_DIR_SEP '/'
40 #endif 40 #endif
41 41
42 #include <stdlib.h> 42 #include <stdlib.h>
43 #include <limits.h>
43 #include <string.h> 44 #include <string.h>
44 #include <stdarg.h> 45 #include <stdarg.h>
45 #include <libxml/xmlmemory.h> 46 #include <libxml/xmlmemory.h>
46 #include <libxml/threads.h> 47 #include <libxml/threads.h>
47 #include <libxml/globals.h> 48 #include <libxml/globals.h>
48 #include <libxml/tree.h> 49 #include <libxml/tree.h>
49 #include <libxml/parser.h> 50 #include <libxml/parser.h>
50 #include <libxml/parserInternals.h> 51 #include <libxml/parserInternals.h>
51 #include <libxml/valid.h> 52 #include <libxml/valid.h>
52 #include <libxml/entities.h> 53 #include <libxml/entities.h>
(...skipping 19 matching lines...) Expand all
72 #endif 73 #endif
73 #ifdef HAVE_FCNTL_H 74 #ifdef HAVE_FCNTL_H
74 #include <fcntl.h> 75 #include <fcntl.h>
75 #endif 76 #endif
76 #ifdef HAVE_UNISTD_H 77 #ifdef HAVE_UNISTD_H
77 #include <unistd.h> 78 #include <unistd.h>
78 #endif 79 #endif
79 #ifdef HAVE_ZLIB_H 80 #ifdef HAVE_ZLIB_H
80 #include <zlib.h> 81 #include <zlib.h>
81 #endif 82 #endif
83 #ifdef HAVE_LZMA_H
84 #include <lzma.h>
85 #endif
86
87 #include "buf.h"
88 #include "enc.h"
82 89
83 static void 90 static void
84 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info); 91 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info);
85 92
86 static xmlParserCtxtPtr 93 static xmlParserCtxtPtr
87 xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, 94 xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID,
88 const xmlChar *base, xmlParserCtxtPtr pctx); 95 const xmlChar *base, xmlParserCtxtPtr pctx);
89 96
90 /************************************************************************ 97 /************************************************************************
91 * * 98 * *
(...skipping 15 matching lines...) Expand all
107 /* 114 /*
108 * xmlParserEntityCheck 115 * xmlParserEntityCheck
109 * 116 *
110 * Function to check non-linear entity expansion behaviour 117 * Function to check non-linear entity expansion behaviour
111 * This is here to detect and stop exponential linear entity expansion 118 * This is here to detect and stop exponential linear entity expansion
112 * This is not a limitation of the parser but a safety 119 * This is not a limitation of the parser but a safety
113 * boundary feature. It can be disabled with the XML_PARSE_HUGE 120 * boundary feature. It can be disabled with the XML_PARSE_HUGE
114 * parser option. 121 * parser option.
115 */ 122 */
116 static int 123 static int
117 xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned long size, 124 xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
118 xmlEntityPtr ent) 125 xmlEntityPtr ent, size_t replacement)
119 { 126 {
120 unsigned long consumed = 0; 127 size_t consumed = 0;
121 128
122 if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE)) 129 if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
123 return (0); 130 return (0);
124 if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP) 131 if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
125 return (1); 132 return (1);
126 if (size != 0) { 133
134 /*
135 * This may look absurd but is needed to detect
136 * entities problems
137 */
138 if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
139 » (ent->content != NULL) && (ent->checked == 0)) {
140 » unsigned long oldnbent = ctxt->nbentities;
141 » xmlChar *rep;
142
143 » ent->checked = 1;
144
145 » rep = xmlStringDecodeEntities(ctxt, ent->content,
146 » » » » XML_SUBSTITUTE_REF, 0, 0, 0);
147
148 » ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
149 » if (rep != NULL) {
150 » if (xmlStrchr(rep, '<'))
151 » » ent->checked |= 1;
152 » xmlFree(rep);
153 » rep = NULL;
154 » }
155 }
156 if (replacement != 0) {
157 » if (replacement < XML_MAX_TEXT_LENGTH)
158 » return(0);
159
160 /*
161 » * If the volume of entity copy reaches 10 times the
162 » * amount of parsed data and over the large text threshold
163 » * then that's very likely to be an abuse.
164 » */
165 if (ctxt->input != NULL) {
166 » consumed = ctxt->input->consumed +
167 » (ctxt->input->cur - ctxt->input->base);
168 » }
169 consumed += ctxt->sizeentities;
170
171 if (replacement < XML_PARSER_NON_LINEAR * consumed)
172 » return(0);
173 } else if (size != 0) {
127 /* 174 /*
128 * Do the check based on the replacement size of the entity 175 * Do the check based on the replacement size of the entity
129 */ 176 */
130 if (size < XML_PARSER_BIG_ENTITY) 177 if (size < XML_PARSER_BIG_ENTITY)
131 return(0); 178 return(0);
132 179
133 /* 180 /*
134 * A limit on the amount of text data reasonably used 181 * A limit on the amount of text data reasonably used
135 */ 182 */
136 if (ctxt->input != NULL) { 183 if (ctxt->input != NULL) {
137 consumed = ctxt->input->consumed + 184 consumed = ctxt->input->consumed +
138 (ctxt->input->cur - ctxt->input->base); 185 (ctxt->input->cur - ctxt->input->base);
139 } 186 }
140 consumed += ctxt->sizeentities; 187 consumed += ctxt->sizeentities;
141 188
142 if ((size < XML_PARSER_NON_LINEAR * consumed) && 189 if ((size < XML_PARSER_NON_LINEAR * consumed) &&
143 (ctxt->nbentities * 3 < XML_PARSER_NON_LINEAR * consumed)) 190 (ctxt->nbentities * 3 < XML_PARSER_NON_LINEAR * consumed))
144 return (0); 191 return (0);
145 } else if (ent != NULL) { 192 } else if (ent != NULL) {
146 /* 193 /*
147 * use the number of parsed entities in the replacement 194 * use the number of parsed entities in the replacement
148 */ 195 */
149 size = ent->checked; 196 size = ent->checked / 2;
150 197
151 /* 198 /*
152 * The amount of data parsed counting entities size only once 199 * The amount of data parsed counting entities size only once
153 */ 200 */
154 if (ctxt->input != NULL) { 201 if (ctxt->input != NULL) {
155 consumed = ctxt->input->consumed + 202 consumed = ctxt->input->consumed +
156 (ctxt->input->cur - ctxt->input->base); 203 (ctxt->input->cur - ctxt->input->base);
157 } 204 }
158 consumed += ctxt->sizeentities; 205 consumed += ctxt->sizeentities;
159 206
160 /* 207 /*
161 * Check the density of entities for the amount of data 208 * Check the density of entities for the amount of data
162 * knowing an entity reference will take at least 3 bytes 209 * knowing an entity reference will take at least 3 bytes
163 */ 210 */
164 if (size * 3 < consumed * XML_PARSER_NON_LINEAR) 211 if (size * 3 < consumed * XML_PARSER_NON_LINEAR)
165 return (0); 212 return (0);
166 } else { 213 } else {
167 /* 214 /*
168 * strange we got no data for checking just return 215 * strange we got no data for checking
169 */ 216 */
170 return (0); 217 » if (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&
218 » (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||
219 » (ctxt->nbentities <= 10000))
220 » return (0);
171 } 221 }
172
173 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); 222 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
174 return (1); 223 return (1);
175 } 224 }
176 225
177 /** 226 /**
178 * xmlParserMaxDepth: 227 * xmlParserMaxDepth:
179 * 228 *
180 * arbitrary depth limit for the XML documents that we allow to 229 * arbitrary depth limit for the XML documents that we allow to
181 * process. This is not a limitation of the parser but a safety 230 * process. This is not a limitation of the parser but a safety
182 * boundary feature. It can be disabled with the XML_PARSE_HUGE 231 * boundary feature. It can be disabled with the XML_PARSE_HUGE
183 * parser option. 232 * parser option.
184 */ 233 */
185 unsigned int xmlParserMaxDepth = 256; 234 unsigned int xmlParserMaxDepth = 256;
186 235
187 236
188 237
189 #define SAX2 1 238 #define SAX2 1
190 #define XML_PARSER_BIG_BUFFER_SIZE 300 239 #define XML_PARSER_BIG_BUFFER_SIZE 300
191 #define XML_PARSER_BUFFER_SIZE 100 240 #define XML_PARSER_BUFFER_SIZE 100
192 #define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document" 241 #define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document"
193 242
243 /**
244 * XML_PARSER_CHUNK_SIZE
245 *
246 * When calling GROW that's the minimal amount of data
247 * the parser expected to have received. It is not a hard
248 * limit but an optimization when reading strings like Names
249 * It is not strictly needed as long as inputs available characters
250 * are followed by 0, which should be provided by the I/O level
251 */
252 #define XML_PARSER_CHUNK_SIZE 100
253
194 /* 254 /*
195 * List of XML prefixed PI allowed by W3C specs 255 * List of XML prefixed PI allowed by W3C specs
196 */ 256 */
197 257
198 static const char *xmlW3CPIs[] = { 258 static const char *xmlW3CPIs[] = {
199 "xml-stylesheet", 259 "xml-stylesheet",
260 "xml-model",
200 NULL 261 NULL
201 }; 262 };
202 263
203 264
204 /* DEPR void xmlParserHandleReference(xmlParserCtxtPtr ctxt); */ 265 /* DEPR void xmlParserHandleReference(xmlParserCtxtPtr ctxt); */
205 static xmlEntityPtr xmlParseStringPEReference(xmlParserCtxtPtr ctxt, 266 static xmlEntityPtr xmlParseStringPEReference(xmlParserCtxtPtr ctxt,
206 const xmlChar **str); 267 const xmlChar **str);
207 268
208 static xmlParserErrors 269 static xmlParserErrors
209 xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, 270 xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
(...skipping 12 matching lines...) Expand all
222 283
223 static xmlParserErrors 284 static xmlParserErrors
224 xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, 285 xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
225 const xmlChar *string, void *user_data, xmlNodePtr *lst); 286 const xmlChar *string, void *user_data, xmlNodePtr *lst);
226 287
227 static int 288 static int
228 xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); 289 xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity);
229 290
230 /************************************************************************ 291 /************************************************************************
231 * * 292 * *
232 * » » Some factorized error routines» » » » * 293 *» » Some factorized error routines» » » » *
233 * * 294 * *
234 ************************************************************************/ 295 ************************************************************************/
235 296
236 /** 297 /**
237 * xmlErrAttributeDup: 298 * xmlErrAttributeDup:
238 * @ctxt: an XML parser context 299 * @ctxt: an XML parser context
239 * @prefix: the attribute prefix 300 * @prefix: the attribute prefix
240 * @localname: the attribute localname 301 * @localname: the attribute localname
241 * 302 *
242 * Handle a redefinition of attribute error 303 * Handle a redefinition of attribute error
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 * @ctxt: an XML parser context 335 * @ctxt: an XML parser context
275 * @error: the error number 336 * @error: the error number
276 * @extra: extra information string 337 * @extra: extra information string
277 * 338 *
278 * Handle a fatal parser error, i.e. violating Well-Formedness constraints 339 * Handle a fatal parser error, i.e. violating Well-Formedness constraints
279 */ 340 */
280 static void 341 static void
281 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info) 342 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
282 { 343 {
283 const char *errmsg; 344 const char *errmsg;
345 char errstr[129] = "";
284 346
285 if ((ctxt != NULL) && (ctxt->disableSAX != 0) && 347 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
286 (ctxt->instate == XML_PARSER_EOF)) 348 (ctxt->instate == XML_PARSER_EOF))
287 return; 349 return;
288 switch (error) { 350 switch (error) {
289 case XML_ERR_INVALID_HEX_CHARREF: 351 case XML_ERR_INVALID_HEX_CHARREF:
290 errmsg = "CharRef: invalid hexadecimal value\n"; 352 errmsg = "CharRef: invalid hexadecimal value";
291 break; 353 break;
292 case XML_ERR_INVALID_DEC_CHARREF: 354 case XML_ERR_INVALID_DEC_CHARREF:
293 errmsg = "CharRef: invalid decimal value\n"; 355 errmsg = "CharRef: invalid decimal value";
294 break; 356 break;
295 case XML_ERR_INVALID_CHARREF: 357 case XML_ERR_INVALID_CHARREF:
296 errmsg = "CharRef: invalid value\n"; 358 errmsg = "CharRef: invalid value";
297 break; 359 break;
298 case XML_ERR_INTERNAL_ERROR: 360 case XML_ERR_INTERNAL_ERROR:
299 errmsg = "internal error"; 361 errmsg = "internal error";
300 break; 362 break;
301 case XML_ERR_PEREF_AT_EOF: 363 case XML_ERR_PEREF_AT_EOF:
302 errmsg = "PEReference at end of document\n"; 364 errmsg = "PEReference at end of document";
303 break; 365 break;
304 case XML_ERR_PEREF_IN_PROLOG: 366 case XML_ERR_PEREF_IN_PROLOG:
305 errmsg = "PEReference in prolog\n"; 367 errmsg = "PEReference in prolog";
306 break; 368 break;
307 case XML_ERR_PEREF_IN_EPILOG: 369 case XML_ERR_PEREF_IN_EPILOG:
308 errmsg = "PEReference in epilog\n"; 370 errmsg = "PEReference in epilog";
309 break; 371 break;
310 case XML_ERR_PEREF_NO_NAME: 372 case XML_ERR_PEREF_NO_NAME:
311 errmsg = "PEReference: no name\n"; 373 errmsg = "PEReference: no name";
312 break; 374 break;
313 case XML_ERR_PEREF_SEMICOL_MISSING: 375 case XML_ERR_PEREF_SEMICOL_MISSING:
314 errmsg = "PEReference: expecting ';'\n"; 376 errmsg = "PEReference: expecting ';'";
315 break; 377 break;
316 case XML_ERR_ENTITY_LOOP: 378 case XML_ERR_ENTITY_LOOP:
317 errmsg = "Detected an entity reference loop\n"; 379 errmsg = "Detected an entity reference loop";
318 break; 380 break;
319 case XML_ERR_ENTITY_NOT_STARTED: 381 case XML_ERR_ENTITY_NOT_STARTED:
320 errmsg = "EntityValue: \" or ' expected\n"; 382 errmsg = "EntityValue: \" or ' expected";
321 break; 383 break;
322 case XML_ERR_ENTITY_PE_INTERNAL: 384 case XML_ERR_ENTITY_PE_INTERNAL:
323 errmsg = "PEReferences forbidden in internal subset\n"; 385 errmsg = "PEReferences forbidden in internal subset";
324 break; 386 break;
325 case XML_ERR_ENTITY_NOT_FINISHED: 387 case XML_ERR_ENTITY_NOT_FINISHED:
326 errmsg = "EntityValue: \" or ' expected\n"; 388 errmsg = "EntityValue: \" or ' expected";
327 break; 389 break;
328 case XML_ERR_ATTRIBUTE_NOT_STARTED: 390 case XML_ERR_ATTRIBUTE_NOT_STARTED:
329 errmsg = "AttValue: \" or ' expected\n"; 391 errmsg = "AttValue: \" or ' expected";
330 break; 392 break;
331 case XML_ERR_LT_IN_ATTRIBUTE: 393 case XML_ERR_LT_IN_ATTRIBUTE:
332 errmsg = "Unescaped '<' not allowed in attributes values\n"; 394 errmsg = "Unescaped '<' not allowed in attributes values";
333 break; 395 break;
334 case XML_ERR_LITERAL_NOT_STARTED: 396 case XML_ERR_LITERAL_NOT_STARTED:
335 errmsg = "SystemLiteral \" or ' expected\n"; 397 errmsg = "SystemLiteral \" or ' expected";
336 break; 398 break;
337 case XML_ERR_LITERAL_NOT_FINISHED: 399 case XML_ERR_LITERAL_NOT_FINISHED:
338 errmsg = "Unfinished System or Public ID \" or ' expected\n"; 400 errmsg = "Unfinished System or Public ID \" or ' expected";
339 break; 401 break;
340 case XML_ERR_MISPLACED_CDATA_END: 402 case XML_ERR_MISPLACED_CDATA_END:
341 errmsg = "Sequence ']]>' not allowed in content\n"; 403 errmsg = "Sequence ']]>' not allowed in content";
342 break; 404 break;
343 case XML_ERR_URI_REQUIRED: 405 case XML_ERR_URI_REQUIRED:
344 errmsg = "SYSTEM or PUBLIC, the URI is missing\n"; 406 errmsg = "SYSTEM or PUBLIC, the URI is missing";
345 break; 407 break;
346 case XML_ERR_PUBID_REQUIRED: 408 case XML_ERR_PUBID_REQUIRED:
347 errmsg = "PUBLIC, the Public Identifier is missing\n"; 409 errmsg = "PUBLIC, the Public Identifier is missing";
348 break; 410 break;
349 case XML_ERR_HYPHEN_IN_COMMENT: 411 case XML_ERR_HYPHEN_IN_COMMENT:
350 errmsg = "Comment must not contain '--' (double-hyphen)\n"; 412 errmsg = "Comment must not contain '--' (double-hyphen)";
351 break; 413 break;
352 case XML_ERR_PI_NOT_STARTED: 414 case XML_ERR_PI_NOT_STARTED:
353 errmsg = "xmlParsePI : no target name\n"; 415 errmsg = "xmlParsePI : no target name";
354 break; 416 break;
355 case XML_ERR_RESERVED_XML_NAME: 417 case XML_ERR_RESERVED_XML_NAME:
356 errmsg = "Invalid PI name\n"; 418 errmsg = "Invalid PI name";
357 break; 419 break;
358 case XML_ERR_NOTATION_NOT_STARTED: 420 case XML_ERR_NOTATION_NOT_STARTED:
359 errmsg = "NOTATION: Name expected here\n"; 421 errmsg = "NOTATION: Name expected here";
360 break; 422 break;
361 case XML_ERR_NOTATION_NOT_FINISHED: 423 case XML_ERR_NOTATION_NOT_FINISHED:
362 errmsg = "'>' required to close NOTATION declaration\n"; 424 errmsg = "'>' required to close NOTATION declaration";
363 break; 425 break;
364 case XML_ERR_VALUE_REQUIRED: 426 case XML_ERR_VALUE_REQUIRED:
365 errmsg = "Entity value required\n"; 427 errmsg = "Entity value required";
366 break; 428 break;
367 case XML_ERR_URI_FRAGMENT: 429 case XML_ERR_URI_FRAGMENT:
368 errmsg = "Fragment not allowed"; 430 errmsg = "Fragment not allowed";
369 break; 431 break;
370 case XML_ERR_ATTLIST_NOT_STARTED: 432 case XML_ERR_ATTLIST_NOT_STARTED:
371 errmsg = "'(' required to start ATTLIST enumeration\n"; 433 errmsg = "'(' required to start ATTLIST enumeration";
372 break; 434 break;
373 case XML_ERR_NMTOKEN_REQUIRED: 435 case XML_ERR_NMTOKEN_REQUIRED:
374 errmsg = "NmToken expected in ATTLIST enumeration\n"; 436 errmsg = "NmToken expected in ATTLIST enumeration";
375 break; 437 break;
376 case XML_ERR_ATTLIST_NOT_FINISHED: 438 case XML_ERR_ATTLIST_NOT_FINISHED:
377 errmsg = "')' required to finish ATTLIST enumeration\n"; 439 errmsg = "')' required to finish ATTLIST enumeration";
378 break; 440 break;
379 case XML_ERR_MIXED_NOT_STARTED: 441 case XML_ERR_MIXED_NOT_STARTED:
380 errmsg = "MixedContentDecl : '|' or ')*' expected\n"; 442 errmsg = "MixedContentDecl : '|' or ')*' expected";
381 break; 443 break;
382 case XML_ERR_PCDATA_REQUIRED: 444 case XML_ERR_PCDATA_REQUIRED:
383 errmsg = "MixedContentDecl : '#PCDATA' expected\n"; 445 errmsg = "MixedContentDecl : '#PCDATA' expected";
384 break; 446 break;
385 case XML_ERR_ELEMCONTENT_NOT_STARTED: 447 case XML_ERR_ELEMCONTENT_NOT_STARTED:
386 errmsg = "ContentDecl : Name or '(' expected\n"; 448 errmsg = "ContentDecl : Name or '(' expected";
387 break; 449 break;
388 case XML_ERR_ELEMCONTENT_NOT_FINISHED: 450 case XML_ERR_ELEMCONTENT_NOT_FINISHED:
389 errmsg = "ContentDecl : ',' '|' or ')' expected\n"; 451 errmsg = "ContentDecl : ',' '|' or ')' expected";
390 break; 452 break;
391 case XML_ERR_PEREF_IN_INT_SUBSET: 453 case XML_ERR_PEREF_IN_INT_SUBSET:
392 errmsg = 454 errmsg =
393 "PEReference: forbidden within markup decl in internal subset\n" ; 455 "PEReference: forbidden within markup decl in internal subset";
394 break; 456 break;
395 case XML_ERR_GT_REQUIRED: 457 case XML_ERR_GT_REQUIRED:
396 errmsg = "expected '>'\n"; 458 errmsg = "expected '>'";
397 break; 459 break;
398 case XML_ERR_CONDSEC_INVALID: 460 case XML_ERR_CONDSEC_INVALID:
399 errmsg = "XML conditional section '[' expected\n"; 461 errmsg = "XML conditional section '[' expected";
400 break; 462 break;
401 case XML_ERR_EXT_SUBSET_NOT_FINISHED: 463 case XML_ERR_EXT_SUBSET_NOT_FINISHED:
402 errmsg = "Content error in the external subset\n"; 464 errmsg = "Content error in the external subset";
403 break; 465 break;
404 case XML_ERR_CONDSEC_INVALID_KEYWORD: 466 case XML_ERR_CONDSEC_INVALID_KEYWORD:
405 errmsg = 467 errmsg =
406 "conditional section INCLUDE or IGNORE keyword expected\n"; 468 "conditional section INCLUDE or IGNORE keyword expected";
407 break; 469 break;
408 case XML_ERR_CONDSEC_NOT_FINISHED: 470 case XML_ERR_CONDSEC_NOT_FINISHED:
409 errmsg = "XML conditional section not closed\n"; 471 errmsg = "XML conditional section not closed";
410 break; 472 break;
411 case XML_ERR_XMLDECL_NOT_STARTED: 473 case XML_ERR_XMLDECL_NOT_STARTED:
412 errmsg = "Text declaration '<?xml' required\n"; 474 errmsg = "Text declaration '<?xml' required";
413 break; 475 break;
414 case XML_ERR_XMLDECL_NOT_FINISHED: 476 case XML_ERR_XMLDECL_NOT_FINISHED:
415 errmsg = "parsing XML declaration: '?>' expected\n"; 477 errmsg = "parsing XML declaration: '?>' expected";
416 break; 478 break;
417 case XML_ERR_EXT_ENTITY_STANDALONE: 479 case XML_ERR_EXT_ENTITY_STANDALONE:
418 errmsg = "external parsed entities cannot be standalone\n"; 480 errmsg = "external parsed entities cannot be standalone";
419 break; 481 break;
420 case XML_ERR_ENTITYREF_SEMICOL_MISSING: 482 case XML_ERR_ENTITYREF_SEMICOL_MISSING:
421 errmsg = "EntityRef: expecting ';'\n"; 483 errmsg = "EntityRef: expecting ';'";
422 break; 484 break;
423 case XML_ERR_DOCTYPE_NOT_FINISHED: 485 case XML_ERR_DOCTYPE_NOT_FINISHED:
424 errmsg = "DOCTYPE improperly terminated\n"; 486 errmsg = "DOCTYPE improperly terminated";
425 break; 487 break;
426 case XML_ERR_LTSLASH_REQUIRED: 488 case XML_ERR_LTSLASH_REQUIRED:
427 errmsg = "EndTag: '</' not found\n"; 489 errmsg = "EndTag: '</' not found";
428 break; 490 break;
429 case XML_ERR_EQUAL_REQUIRED: 491 case XML_ERR_EQUAL_REQUIRED:
430 errmsg = "expected '='\n"; 492 errmsg = "expected '='";
431 break; 493 break;
432 case XML_ERR_STRING_NOT_CLOSED: 494 case XML_ERR_STRING_NOT_CLOSED:
433 errmsg = "String not closed expecting \" or '\n"; 495 errmsg = "String not closed expecting \" or '";
434 break; 496 break;
435 case XML_ERR_STRING_NOT_STARTED: 497 case XML_ERR_STRING_NOT_STARTED:
436 errmsg = "String not started expecting ' or \"\n"; 498 errmsg = "String not started expecting ' or \"";
437 break; 499 break;
438 case XML_ERR_ENCODING_NAME: 500 case XML_ERR_ENCODING_NAME:
439 errmsg = "Invalid XML encoding name\n"; 501 errmsg = "Invalid XML encoding name";
440 break; 502 break;
441 case XML_ERR_STANDALONE_VALUE: 503 case XML_ERR_STANDALONE_VALUE:
442 errmsg = "standalone accepts only 'yes' or 'no'\n"; 504 errmsg = "standalone accepts only 'yes' or 'no'";
443 break; 505 break;
444 case XML_ERR_DOCUMENT_EMPTY: 506 case XML_ERR_DOCUMENT_EMPTY:
445 errmsg = "Document is empty\n"; 507 errmsg = "Document is empty";
446 break; 508 break;
447 case XML_ERR_DOCUMENT_END: 509 case XML_ERR_DOCUMENT_END:
448 errmsg = "Extra content at the end of the document\n"; 510 errmsg = "Extra content at the end of the document";
449 break; 511 break;
450 case XML_ERR_NOT_WELL_BALANCED: 512 case XML_ERR_NOT_WELL_BALANCED:
451 errmsg = "chunk is not well balanced\n"; 513 errmsg = "chunk is not well balanced";
452 break; 514 break;
453 case XML_ERR_EXTRA_CONTENT: 515 case XML_ERR_EXTRA_CONTENT:
454 errmsg = "extra content at the end of well balanced chunk\n"; 516 errmsg = "extra content at the end of well balanced chunk";
455 break; 517 break;
456 case XML_ERR_VERSION_MISSING: 518 case XML_ERR_VERSION_MISSING:
457 errmsg = "Malformed declaration expecting version\n"; 519 errmsg = "Malformed declaration expecting version";
520 break;
521 case XML_ERR_NAME_TOO_LONG:
522 errmsg = "Name too long use XML_PARSE_HUGE option";
458 break; 523 break;
459 #if 0 524 #if 0
460 case: 525 case:
461 errmsg = "\n"; 526 errmsg = "";
462 break; 527 break;
463 #endif 528 #endif
464 default: 529 default:
465 errmsg = "Unregistered error message\n"; 530 errmsg = "Unregistered error message";
466 } 531 }
532 if (info == NULL)
533 snprintf(errstr, 128, "%s\n", errmsg);
534 else
535 snprintf(errstr, 128, "%s: %%s\n", errmsg);
467 if (ctxt != NULL) 536 if (ctxt != NULL)
468 ctxt->errNo = error; 537 ctxt->errNo = error;
469 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, 538 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
470 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg, 539 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, &errstr[0],
471 info); 540 info);
472 if (ctxt != NULL) { 541 if (ctxt != NULL) {
473 ctxt->wellFormed = 0; 542 ctxt->wellFormed = 0;
474 if (ctxt->recovery == 0) 543 if (ctxt->recovery == 0)
475 ctxt->disableSAX = 1; 544 ctxt->disableSAX = 1;
476 } 545 }
477 } 546 }
478 547
479 /** 548 /**
480 * xmlFatalErrMsg: 549 * xmlFatalErrMsg:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 * @error: the error number 684 * @error: the error number
616 * @msg: the error message 685 * @msg: the error message
617 * @str1: an string info 686 * @str1: an string info
618 * @val: an integer value 687 * @val: an integer value
619 * @str2: an string info 688 * @str2: an string info
620 * 689 *
621 * Handle a fatal parser error, i.e. violating Well-Formedness constraints 690 * Handle a fatal parser error, i.e. violating Well-Formedness constraints
622 */ 691 */
623 static void 692 static void
624 xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, 693 xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
625 const char *msg, const xmlChar *str1, int val, 694 const char *msg, const xmlChar *str1, int val,
626 const xmlChar *str2) 695 const xmlChar *str2)
627 { 696 {
628 if ((ctxt != NULL) && (ctxt->disableSAX != 0) && 697 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
629 (ctxt->instate == XML_PARSER_EOF)) 698 (ctxt->instate == XML_PARSER_EOF))
630 return; 699 return;
631 if (ctxt != NULL) 700 if (ctxt != NULL)
632 ctxt->errNo = error; 701 ctxt->errNo = error;
633 __xmlRaiseError(NULL, NULL, NULL, 702 __xmlRaiseError(NULL, NULL, NULL,
634 ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, 703 ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
635 NULL, 0, (const char *) str1, (const char *) str2, 704 NULL, 0, (const char *) str1, (const char *) str2,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 793 }
725 794
726 /** 795 /**
727 * xmlNsWarn 796 * xmlNsWarn
728 * @ctxt: an XML parser context 797 * @ctxt: an XML parser context
729 * @error: the error number 798 * @error: the error number
730 * @msg: the message 799 * @msg: the message
731 * @info1: extra information string 800 * @info1: extra information string
732 * @info2: extra information string 801 * @info2: extra information string
733 * 802 *
734 * Handle a fatal parser error, i.e. violating Well-Formedness constraints 803 * Handle a namespace warning error
735 */ 804 */
736 static void 805 static void
737 xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error, 806 xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error,
738 const char *msg, 807 const char *msg,
739 const xmlChar * info1, const xmlChar * info2, 808 const xmlChar * info1, const xmlChar * info2,
740 const xmlChar * info3) 809 const xmlChar * info3)
741 { 810 {
742 if ((ctxt != NULL) && (ctxt->disableSAX != 0) && 811 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
743 (ctxt->instate == XML_PARSER_EOF)) 812 (ctxt->instate == XML_PARSER_EOF))
744 return; 813 return;
745 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, 814 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
746 XML_ERR_WARNING, NULL, 0, (const char *) info1, 815 XML_ERR_WARNING, NULL, 0, (const char *) info1,
747 (const char *) info2, (const char *) info3, 0, 0, msg, 816 (const char *) info2, (const char *) info3, 0, 0, msg,
748 info1, info2, info3); 817 info1, info2, info3);
749 } 818 }
750 819
751 /************************************************************************ 820 /************************************************************************
752 * * 821 * *
753 * » » Library wide options» » » » » * 822 *» » Library wide options» » » » » *
754 * * 823 * *
755 ************************************************************************/ 824 ************************************************************************/
756 825
757 /** 826 /**
758 * xmlHasFeature: 827 * xmlHasFeature:
759 * @feature: the feature to be examined 828 * @feature: the feature to be examined
760 * 829 *
761 * Examines if the library has been compiled with a given feature. 830 * Examines if the library has been compiled with a given feature.
762 * 831 *
763 * Returns a non-zero value if the feature exist, otherwise zero. 832 * Returns a non-zero value if the feature exist, otherwise zero.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return(1); 1016 return(1);
948 #else 1017 #else
949 return(0); 1018 return(0);
950 #endif 1019 #endif
951 case XML_WITH_ZLIB: 1020 case XML_WITH_ZLIB:
952 #ifdef LIBXML_ZLIB_ENABLED 1021 #ifdef LIBXML_ZLIB_ENABLED
953 return(1); 1022 return(1);
954 #else 1023 #else
955 return(0); 1024 return(0);
956 #endif 1025 #endif
1026 case XML_WITH_LZMA:
1027 #ifdef LIBXML_LZMA_ENABLED
1028 return(1);
1029 #else
1030 return(0);
1031 #endif
957 case XML_WITH_ICU: 1032 case XML_WITH_ICU:
958 #ifdef LIBXML_ICU_ENABLED 1033 #ifdef LIBXML_ICU_ENABLED
959 return(1); 1034 return(1);
960 #else 1035 #else
961 return(0); 1036 return(0);
962 #endif 1037 #endif
963 default: 1038 default:
964 break; 1039 break;
965 } 1040 }
966 return(0); 1041 return(0);
967 } 1042 }
968 1043
969 /************************************************************************ 1044 /************************************************************************
970 * * 1045 * *
971 * » » SAX2 defaulted attributes handling» » » * 1046 *» » SAX2 defaulted attributes handling» » » *
972 * * 1047 * *
973 ************************************************************************/ 1048 ************************************************************************/
974 1049
975 /** 1050 /**
976 * xmlDetectSAX2: 1051 * xmlDetectSAX2:
977 * @ctxt: an XML parser context 1052 * @ctxt: an XML parser context
978 * 1053 *
979 * Do the SAX2 detection and specific intialization 1054 * Do the SAX2 detection and specific intialization
980 */ 1055 */
981 static void 1056 static void
982 xmlDetectSAX2(xmlParserCtxtPtr ctxt) { 1057 xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
983 if (ctxt == NULL) return; 1058 if (ctxt == NULL) return;
984 #ifdef LIBXML_SAX1_ENABLED 1059 #ifdef LIBXML_SAX1_ENABLED
985 if ((ctxt->sax) && (ctxt->sax->initialized == XML_SAX2_MAGIC) && 1060 if ((ctxt->sax) && (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
986 ((ctxt->sax->startElementNs != NULL) || 1061 ((ctxt->sax->startElementNs != NULL) ||
987 (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1; 1062 (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1;
988 #else 1063 #else
989 ctxt->sax2 = 1; 1064 ctxt->sax2 = 1;
990 #endif /* LIBXML_SAX1_ENABLED */ 1065 #endif /* LIBXML_SAX1_ENABLED */
991 1066
992 ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3); 1067 ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
993 ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5); 1068 ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
994 ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36); 1069 ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
995 if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) || 1070 if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||
996 » » (ctxt->str_xml_ns == NULL)) { 1071 » » (ctxt->str_xml_ns == NULL)) {
997 xmlErrMemory(ctxt, NULL); 1072 xmlErrMemory(ctxt, NULL);
998 } 1073 }
999 } 1074 }
1000 1075
1001 typedef struct _xmlDefAttrs xmlDefAttrs; 1076 typedef struct _xmlDefAttrs xmlDefAttrs;
1002 typedef xmlDefAttrs *xmlDefAttrsPtr; 1077 typedef xmlDefAttrs *xmlDefAttrsPtr;
1003 struct _xmlDefAttrs { 1078 struct _xmlDefAttrs {
1004 int nbAttrs; /* number of defaulted attributes on that element */ 1079 int nbAttrs; /* number of defaulted attributes on that element */
1005 int maxAttrs; /* the size of the array */ 1080 int maxAttrs; /* the size of the array */
1006 const xmlChar *values[5]; /* array of localname/prefix/values/external */ 1081 const xmlChar *values[5]; /* array of localname/prefix/values/external */
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 * NOTE: this is somewhat deprecated, those productions were removed from 1371 * NOTE: this is somewhat deprecated, those productions were removed from
1297 * the XML Second edition. 1372 * the XML Second edition.
1298 * 1373 *
1299 * [33] LanguageID ::= Langcode ('-' Subcode)* 1374 * [33] LanguageID ::= Langcode ('-' Subcode)*
1300 * [34] Langcode ::= ISO639Code | IanaCode | UserCode 1375 * [34] Langcode ::= ISO639Code | IanaCode | UserCode
1301 * [35] ISO639Code ::= ([a-z] | [A-Z]) ([a-z] | [A-Z]) 1376 * [35] ISO639Code ::= ([a-z] | [A-Z]) ([a-z] | [A-Z])
1302 * [36] IanaCode ::= ('i' | 'I') '-' ([a-z] | [A-Z])+ 1377 * [36] IanaCode ::= ('i' | 'I') '-' ([a-z] | [A-Z])+
1303 * [37] UserCode ::= ('x' | 'X') '-' ([a-z] | [A-Z])+ 1378 * [37] UserCode ::= ('x' | 'X') '-' ([a-z] | [A-Z])+
1304 * [38] Subcode ::= ([a-z] | [A-Z])+ 1379 * [38] Subcode ::= ([a-z] | [A-Z])+
1305 * 1380 *
1381 * The current REC reference the sucessors of RFC 1766, currently 5646
1382 *
1383 * http://www.rfc-editor.org/rfc/rfc5646.txt
1384 * langtag = language
1385 * ["-" script]
1386 * ["-" region]
1387 * *("-" variant)
1388 * *("-" extension)
1389 * ["-" privateuse]
1390 * language = 2*3ALPHA ; shortest ISO 639 code
1391 * ["-" extlang] ; sometimes followed by
1392 * ; extended language subtags
1393 * / 4ALPHA ; or reserved for future use
1394 * / 5*8ALPHA ; or registered language subtag
1395 *
1396 * extlang = 3ALPHA ; selected ISO 639 codes
1397 * *2("-" 3ALPHA) ; permanently reserved
1398 *
1399 * script = 4ALPHA ; ISO 15924 code
1400 *
1401 * region = 2ALPHA ; ISO 3166-1 code
1402 * / 3DIGIT ; UN M.49 code
1403 *
1404 * variant = 5*8alphanum ; registered variants
1405 * / (DIGIT 3alphanum)
1406 *
1407 * extension = singleton 1*("-" (2*8alphanum))
1408 *
1409 * ; Single alphanumerics
1410 * ; "x" reserved for private use
1411 * singleton = DIGIT ; 0 - 9
1412 * / %x41-57 ; A - W
1413 * / %x59-5A ; Y - Z
1414 * / %x61-77 ; a - w
1415 * / %x79-7A ; y - z
1416 *
1417 * it sounds right to still allow Irregular i-xxx IANA and user codes too
1418 * The parser below doesn't try to cope with extension or privateuse
1419 * that could be added but that's not interoperable anyway
1420 *
1306 * Returns 1 if correct 0 otherwise 1421 * Returns 1 if correct 0 otherwise
1307 **/ 1422 **/
1308 int 1423 int
1309 xmlCheckLanguageID(const xmlChar * lang) 1424 xmlCheckLanguageID(const xmlChar * lang)
1310 { 1425 {
1311 const xmlChar *cur = lang; 1426 const xmlChar *cur = lang, *nxt;
1312 1427
1313 if (cur == NULL) 1428 if (cur == NULL)
1314 return (0); 1429 return (0);
1315 if (((cur[0] == 'i') && (cur[1] == '-')) || 1430 if (((cur[0] == 'i') && (cur[1] == '-')) ||
1316 ((cur[0] == 'I') && (cur[1] == '-'))) { 1431 ((cur[0] == 'I') && (cur[1] == '-')) ||
1432 ((cur[0] == 'x') && (cur[1] == '-')) ||
1433 ((cur[0] == 'X') && (cur[1] == '-'))) {
1317 /* 1434 /*
1318 * IANA code 1435 * Still allow IANA code and user code which were coming
1436 * from the previous version of the XML-1.0 specification
1437 * it's deprecated but we should not fail
1319 */ 1438 */
1320 cur += 2; 1439 cur += 2;
1321 while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming * / 1440 while (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
1322 ((cur[0] >= 'a') && (cur[0] <= 'z'))) 1441 ((cur[0] >= 'a') && (cur[0] <= 'z')))
1323 cur++; 1442 cur++;
1324 } else if (((cur[0] == 'x') && (cur[1] == '-')) || 1443 return(cur[0] == 0);
1325 ((cur[0] == 'X') && (cur[1] == '-'))) { 1444 }
1445 nxt = cur;
1446 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1447 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1448 nxt++;
1449 if (nxt - cur >= 4) {
1326 /* 1450 /*
1327 * User code 1451 * Reserved
1328 */ 1452 */
1329 cur += 2; 1453 if ((nxt - cur > 8) || (nxt[0] != 0))
1330 while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming * / 1454 return(0);
1331 ((cur[0] >= 'a') && (cur[0] <= 'z'))) 1455 return(1);
1332 cur++;
1333 } else if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
1334 ((cur[0] >= 'a') && (cur[0] <= 'z'))) {
1335 /*
1336 * ISO639
1337 */
1338 cur++;
1339 if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
1340 ((cur[0] >= 'a') && (cur[0] <= 'z')))
1341 cur++;
1342 else
1343 return (0);
1344 } else
1345 return (0);
1346 while (cur[0] != 0) { /* non input consuming */
1347 if (cur[0] != '-')
1348 return (0);
1349 cur++;
1350 if (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
1351 ((cur[0] >= 'a') && (cur[0] <= 'z')))
1352 cur++;
1353 else
1354 return (0);
1355 while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || /* non input consuming * /
1356 ((cur[0] >= 'a') && (cur[0] <= 'z')))
1357 cur++;
1358 } 1456 }
1457 if (nxt - cur < 2)
1458 return(0);
1459 /* we got an ISO 639 code */
1460 if (nxt[0] == 0)
1461 return(1);
1462 if (nxt[0] != '-')
1463 return(0);
1464
1465 nxt++;
1466 cur = nxt;
1467 /* now we can have extlang or script or region or variant */
1468 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1469 goto region_m49;
1470
1471 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1472 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1473 nxt++;
1474 if (nxt - cur == 4)
1475 goto script;
1476 if (nxt - cur == 2)
1477 goto region;
1478 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1479 goto variant;
1480 if (nxt - cur != 3)
1481 return(0);
1482 /* we parsed an extlang */
1483 if (nxt[0] == 0)
1484 return(1);
1485 if (nxt[0] != '-')
1486 return(0);
1487
1488 nxt++;
1489 cur = nxt;
1490 /* now we can have script or region or variant */
1491 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1492 goto region_m49;
1493
1494 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1495 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1496 nxt++;
1497 if (nxt - cur == 2)
1498 goto region;
1499 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1500 goto variant;
1501 if (nxt - cur != 4)
1502 return(0);
1503 /* we parsed a script */
1504 script:
1505 if (nxt[0] == 0)
1506 return(1);
1507 if (nxt[0] != '-')
1508 return(0);
1509
1510 nxt++;
1511 cur = nxt;
1512 /* now we can have region or variant */
1513 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1514 goto region_m49;
1515
1516 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1517 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1518 nxt++;
1519
1520 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1521 goto variant;
1522 if (nxt - cur != 2)
1523 return(0);
1524 /* we parsed a region */
1525 region:
1526 if (nxt[0] == 0)
1527 return(1);
1528 if (nxt[0] != '-')
1529 return(0);
1530
1531 nxt++;
1532 cur = nxt;
1533 /* now we can just have a variant */
1534 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1535 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1536 nxt++;
1537
1538 if ((nxt - cur < 5) || (nxt - cur > 8))
1539 return(0);
1540
1541 /* we parsed a variant */
1542 variant:
1543 if (nxt[0] == 0)
1544 return(1);
1545 if (nxt[0] != '-')
1546 return(0);
1547 /* extensions and private use subtags not checked */
1359 return (1); 1548 return (1);
1549
1550 region_m49:
1551 if (((nxt[1] >= '0') && (nxt[1] <= '9')) &&
1552 ((nxt[2] >= '0') && (nxt[2] <= '9'))) {
1553 nxt += 3;
1554 goto region;
1555 }
1556 return(0);
1360 } 1557 }
1361 1558
1362 /************************************************************************ 1559 /************************************************************************
1363 * * 1560 * *
1364 * Parser stacks related functions and macros * 1561 * Parser stacks related functions and macros *
1365 * * 1562 * *
1366 ************************************************************************/ 1563 ************************************************************************/
1367 1564
1368 static xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, 1565 static xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt,
1369 const xmlChar ** str); 1566 const xmlChar ** str);
1370 1567
1371 #ifdef SAX2 1568 #ifdef SAX2
1372 /** 1569 /**
1373 * nsPush: 1570 * nsPush:
1374 * @ctxt: an XML parser context 1571 * @ctxt: an XML parser context
1375 * @prefix: the namespace prefix or NULL 1572 * @prefix: the namespace prefix or NULL
1376 * @URL: the namespace name 1573 * @URL: the namespace name
1377 * 1574 *
1378 * Pushes a new parser namespace on top of the ns stack 1575 * Pushes a new parser namespace on top of the ns stack
1379 * 1576 *
1380 * Returns -1 in case of error, -2 if the namespace should be discarded 1577 * Returns -1 in case of error, -2 if the namespace should be discarded
1381 * and the index in the stack otherwise. 1578 * and the index in the stack otherwise.
1382 */ 1579 */
1383 static int 1580 static int
1384 nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *URL) 1581 nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *URL)
1385 { 1582 {
1386 if (ctxt->options & XML_PARSE_NSCLEAN) { 1583 if (ctxt->options & XML_PARSE_NSCLEAN) {
1387 int i; 1584 int i;
1388 » for (i = 0;i < ctxt->nsNr;i += 2) { 1585 » for (i = ctxt->nsNr - 2;i >= 0;i -= 2) {
1389 if (ctxt->nsTab[i] == prefix) { 1586 if (ctxt->nsTab[i] == prefix) {
1390 /* in scope */ 1587 /* in scope */
1391 if (ctxt->nsTab[i + 1] == URL) 1588 if (ctxt->nsTab[i + 1] == URL)
1392 return(-2); 1589 return(-2);
1393 /* out of scope keep it */ 1590 /* out of scope keep it */
1394 break; 1591 break;
1395 } 1592 }
1396 } 1593 }
1397 } 1594 }
1398 if ((ctxt->nsMax == 0) || (ctxt->nsTab == NULL)) { 1595 if ((ctxt->nsMax == 0) || (ctxt->nsTab == NULL)) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 * 1887 *
1691 * Returns -1 in case of error, the index in the stack otherwise 1888 * Returns -1 in case of error, the index in the stack otherwise
1692 */ 1889 */
1693 int 1890 int
1694 namePush(xmlParserCtxtPtr ctxt, const xmlChar * value) 1891 namePush(xmlParserCtxtPtr ctxt, const xmlChar * value)
1695 { 1892 {
1696 if (ctxt == NULL) return (-1); 1893 if (ctxt == NULL) return (-1);
1697 1894
1698 if (ctxt->nameNr >= ctxt->nameMax) { 1895 if (ctxt->nameNr >= ctxt->nameMax) {
1699 const xmlChar * *tmp; 1896 const xmlChar * *tmp;
1700 ctxt->nameMax *= 2;
1701 tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab, 1897 tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab,
1702 ctxt->nameMax * 1898 ctxt->nameMax * 2 *
1703 sizeof(ctxt->nameTab[0])); 1899 sizeof(ctxt->nameTab[0]));
1704 if (tmp == NULL) { 1900 if (tmp == NULL) {
1705 ctxt->nameMax /= 2;
1706 goto mem_error; 1901 goto mem_error;
1707 } 1902 }
1708 ctxt->nameTab = tmp; 1903 ctxt->nameTab = tmp;
1904 ctxt->nameMax *= 2;
1709 } 1905 }
1710 ctxt->nameTab[ctxt->nameNr] = value; 1906 ctxt->nameTab[ctxt->nameNr] = value;
1711 ctxt->name = value; 1907 ctxt->name = value;
1712 return (ctxt->nameNr++); 1908 return (ctxt->nameNr++);
1713 mem_error: 1909 mem_error:
1714 xmlErrMemory(ctxt, NULL); 1910 xmlErrMemory(ctxt, NULL);
1715 return (-1); 1911 return (-1);
1716 } 1912 }
1717 /** 1913 /**
1718 * namePop: 1914 * namePop:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled 1980 * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled
1785 * This should be used internally by the parser 1981 * This should be used internally by the parser
1786 * only to compare to ASCII values otherwise it would break when 1982 * only to compare to ASCII values otherwise it would break when
1787 * running with UTF-8 encoding. 1983 * running with UTF-8 encoding.
1788 * RAW same as CUR but in the input buffer, bypass any token 1984 * RAW same as CUR but in the input buffer, bypass any token
1789 * extraction that may have been done 1985 * extraction that may have been done
1790 * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only 1986 * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only
1791 * to compare on ASCII based substring. 1987 * to compare on ASCII based substring.
1792 * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined 1988 * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined
1793 * strings without newlines within the parser. 1989 * strings without newlines within the parser.
1794 * NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline A SCII 1990 * NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline A SCII
1795 * defined char within the parser. 1991 * defined char within the parser.
1796 * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding 1992 * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding
1797 * 1993 *
1798 * NEXT Skip to the next character, this does the proper decoding 1994 * NEXT Skip to the next character, this does the proper decoding
1799 * in UTF-8 mode. It also pop-up unfinished entities on the fly. 1995 * in UTF-8 mode. It also pop-up unfinished entities on the fly.
1800 * NEXTL(l) Skip the current unicode character of l xmlChars long. 1996 * NEXTL(l) Skip the current unicode character of l xmlChars long.
1801 * CUR_CHAR(l) returns the current unicode character (int), set l 1997 * CUR_CHAR(l) returns the current unicode character (int), set l
1802 * to the number of xmlChars used for the encoding [0-5]. 1998 * to the number of xmlChars used for the encoding [0-5].
1803 * CUR_SCHAR same but operate on a string instead of the context 1999 * CUR_SCHAR same but operate on a string instead of the context
1804 * COPY_BUF copy the current unicode char to the target buffer, increment 2000 * COPY_BUF copy the current unicode char to the target buffer, increment
(...skipping 28 matching lines...) Expand all
1833 ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val); \ 2029 ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val); \
1834 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ 2030 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
1835 if ((*ctxt->input->cur == 0) && \ 2031 if ((*ctxt->input->cur == 0) && \
1836 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ 2032 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
1837 xmlPopInput(ctxt); \ 2033 xmlPopInput(ctxt); \
1838 } while (0) 2034 } while (0)
1839 2035
1840 #define SKIPL(val) do { \ 2036 #define SKIPL(val) do { \
1841 int skipl; \ 2037 int skipl; \
1842 for(skipl=0; skipl<val; skipl++) { \ 2038 for(skipl=0; skipl<val; skipl++) { \
1843 » if (*(ctxt->input->cur) == '\n') {» » » » \ 2039 » if (*(ctxt->input->cur) == '\n') {» » » » \
1844 ctxt->input->line++; ctxt->input->col = 1; \ 2040 ctxt->input->line++; ctxt->input->col = 1; \
1845 » } else ctxt->input->col++;» » » » » \ 2041 » } else ctxt->input->col++;» » » » » \
1846 » ctxt->nbChars++;» » » » » » \ 2042 » ctxt->nbChars++;» » » » » » \
1847 ctxt->input->cur++; \ 2043 ctxt->input->cur++; \
1848 } \ 2044 } \
1849 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ 2045 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
1850 if ((*ctxt->input->cur == 0) && \ 2046 if ((*ctxt->input->cur == 0) && \
1851 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ 2047 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \
1852 xmlPopInput(ctxt); \ 2048 xmlPopInput(ctxt); \
1853 } while (0) 2049 } while (0)
1854 2050
1855 #define SHRINK if ((ctxt->progressive == 0) && \ 2051 #define SHRINK if ((ctxt->progressive == 0) && \
1856 (ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \ 2052 (ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \
1857 (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \ 2053 (ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \
1858 xmlSHRINK (ctxt); 2054 xmlSHRINK (ctxt);
1859 2055
1860 static void xmlSHRINK (xmlParserCtxtPtr ctxt) { 2056 static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
1861 xmlParserInputShrink(ctxt->input); 2057 xmlParserInputShrink(ctxt->input);
1862 if ((*ctxt->input->cur == 0) && 2058 if ((*ctxt->input->cur == 0) &&
1863 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) 2059 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
1864 xmlPopInput(ctxt); 2060 xmlPopInput(ctxt);
1865 } 2061 }
1866 2062
1867 #define GROW if ((ctxt->progressive == 0) && \ 2063 #define GROW if ((ctxt->progressive == 0) && \
1868 (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \ 2064 (ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \
1869 xmlGROW (ctxt); 2065 xmlGROW (ctxt);
1870 2066
1871 static void xmlGROW (xmlParserCtxtPtr ctxt) { 2067 static void xmlGROW (xmlParserCtxtPtr ctxt) {
2068 unsigned long curEnd = ctxt->input->end - ctxt->input->cur;
2069 unsigned long curBase = ctxt->input->cur - ctxt->input->base;
2070
2071 if (((curEnd > (unsigned long) XML_MAX_LOOKUP_LIMIT) ||
2072 (curBase > (unsigned long) XML_MAX_LOOKUP_LIMIT)) &&
2073 ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputRead Callback) xmlNop)) &&
2074 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
2075 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
2076 ctxt->instate = XML_PARSER_EOF;
2077 }
1872 xmlParserInputGrow(ctxt->input, INPUT_CHUNK); 2078 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
1873 if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) && 2079 if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) &&
1874 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) 2080 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
1875 xmlPopInput(ctxt); 2081 xmlPopInput(ctxt);
1876 } 2082 }
1877 2083
1878 #define SKIP_BLANKS xmlSkipBlankChars(ctxt) 2084 #define SKIP_BLANKS xmlSkipBlankChars(ctxt)
1879 2085
1880 #define NEXT xmlNextChar(ctxt) 2086 #define NEXT xmlNextChar(ctxt)
1881 2087
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 */ 2128 */
1923 if ((ctxt->inputNr == 1) && (ctxt->instate != XML_PARSER_DTD)) { 2129 if ((ctxt->inputNr == 1) && (ctxt->instate != XML_PARSER_DTD)) {
1924 const xmlChar *cur; 2130 const xmlChar *cur;
1925 /* 2131 /*
1926 * if we are in the document content, go really fast 2132 * if we are in the document content, go really fast
1927 */ 2133 */
1928 cur = ctxt->input->cur; 2134 cur = ctxt->input->cur;
1929 while (IS_BLANK_CH(*cur)) { 2135 while (IS_BLANK_CH(*cur)) {
1930 if (*cur == '\n') { 2136 if (*cur == '\n') {
1931 ctxt->input->line++; ctxt->input->col = 1; 2137 ctxt->input->line++; ctxt->input->col = 1;
2138 } else {
2139 ctxt->input->col++;
1932 } 2140 }
1933 cur++; 2141 cur++;
1934 res++; 2142 res++;
1935 if (*cur == 0) { 2143 if (*cur == 0) {
1936 ctxt->input->cur = cur; 2144 ctxt->input->cur = cur;
1937 xmlParserInputGrow(ctxt->input, INPUT_CHUNK); 2145 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
1938 cur = ctxt->input->cur; 2146 cur = ctxt->input->cur;
1939 } 2147 }
1940 } 2148 }
1941 ctxt->input->cur = cur; 2149 ctxt->input->cur = cur;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 * xmlParseCharRef: 2231 * xmlParseCharRef:
2024 * @ctxt: an XML parser context 2232 * @ctxt: an XML parser context
2025 * 2233 *
2026 * parse Reference declarations 2234 * parse Reference declarations
2027 * 2235 *
2028 * [66] CharRef ::= '&#' [0-9]+ ';' | 2236 * [66] CharRef ::= '&#' [0-9]+ ';' |
2029 * '&#x' [0-9a-fA-F]+ ';' 2237 * '&#x' [0-9a-fA-F]+ ';'
2030 * 2238 *
2031 * [ WFC: Legal Character ] 2239 * [ WFC: Legal Character ]
2032 * Characters referred to using character references must match the 2240 * Characters referred to using character references must match the
2033 * production for Char. 2241 * production for Char.
2034 * 2242 *
2035 * Returns the value parsed (as an int), 0 in case of error 2243 * Returns the value parsed (as an int), 0 in case of error
2036 */ 2244 */
2037 int 2245 int
2038 xmlParseCharRef(xmlParserCtxtPtr ctxt) { 2246 xmlParseCharRef(xmlParserCtxtPtr ctxt) {
2039 unsigned int val = 0; 2247 unsigned int val = 0;
2040 int count = 0; 2248 int count = 0;
2041 unsigned int outofrange = 0; 2249 unsigned int outofrange = 0;
2042 2250
2043 /* 2251 /*
2044 * Using RAW/CUR/NEXT is okay since we are working on ASCII range here 2252 * Using RAW/CUR/NEXT is okay since we are working on ASCII range here
2045 */ 2253 */
2046 if ((RAW == '&') && (NXT(1) == '#') && 2254 if ((RAW == '&') && (NXT(1) == '#') &&
2047 (NXT(2) == 'x')) { 2255 (NXT(2) == 'x')) {
2048 SKIP(3); 2256 SKIP(3);
2049 GROW; 2257 GROW;
2050 while (RAW != ';') { /* loop blocked by count */ 2258 while (RAW != ';') { /* loop blocked by count */
2051 if (count++ > 20) { 2259 if (count++ > 20) {
2052 count = 0; 2260 count = 0;
2053 GROW; 2261 GROW;
2054 if (ctxt->instate == XML_PARSER_EOF) 2262 if (ctxt->instate == XML_PARSER_EOF)
2055 return(0); 2263 return(0);
2056 } 2264 }
2057 » if ((RAW >= '0') && (RAW <= '9')) 2265 » if ((RAW >= '0') && (RAW <= '9'))
2058 val = val * 16 + (CUR - '0'); 2266 val = val * 16 + (CUR - '0');
2059 else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20)) 2267 else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20))
2060 val = val * 16 + (CUR - 'a') + 10; 2268 val = val * 16 + (CUR - 'a') + 10;
2061 else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20)) 2269 else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20))
2062 val = val * 16 + (CUR - 'A') + 10; 2270 val = val * 16 + (CUR - 'A') + 10;
2063 else { 2271 else {
2064 xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL); 2272 xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL);
2065 val = 0; 2273 val = 0;
2066 break; 2274 break;
2067 } 2275 }
(...skipping 12 matching lines...) Expand all
2080 } else if ((RAW == '&') && (NXT(1) == '#')) { 2288 } else if ((RAW == '&') && (NXT(1) == '#')) {
2081 SKIP(2); 2289 SKIP(2);
2082 GROW; 2290 GROW;
2083 while (RAW != ';') { /* loop blocked by count */ 2291 while (RAW != ';') { /* loop blocked by count */
2084 if (count++ > 20) { 2292 if (count++ > 20) {
2085 count = 0; 2293 count = 0;
2086 GROW; 2294 GROW;
2087 if (ctxt->instate == XML_PARSER_EOF) 2295 if (ctxt->instate == XML_PARSER_EOF)
2088 return(0); 2296 return(0);
2089 } 2297 }
2090 » if ((RAW >= '0') && (RAW <= '9')) 2298 » if ((RAW >= '0') && (RAW <= '9'))
2091 val = val * 10 + (CUR - '0'); 2299 val = val * 10 + (CUR - '0');
2092 else { 2300 else {
2093 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL); 2301 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);
2094 val = 0; 2302 val = 0;
2095 break; 2303 break;
2096 } 2304 }
2097 if (val > 0x10FFFF) 2305 if (val > 0x10FFFF)
2098 outofrange = val; 2306 outofrange = val;
2099 2307
2100 NEXT; 2308 NEXT;
2101 count++; 2309 count++;
2102 } 2310 }
2103 if (RAW == ';') { 2311 if (RAW == ';') {
2104 /* on purpose to avoid reentrancy problems with NEXT and SKIP */ 2312 /* on purpose to avoid reentrancy problems with NEXT and SKIP */
2105 ctxt->input->col++; 2313 ctxt->input->col++;
2106 ctxt->nbChars ++; 2314 ctxt->nbChars ++;
2107 ctxt->input->cur++; 2315 ctxt->input->cur++;
2108 } 2316 }
2109 } else { 2317 } else {
2110 xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL); 2318 xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL);
2111 } 2319 }
2112 2320
2113 /* 2321 /*
2114 * [ WFC: Legal Character ] 2322 * [ WFC: Legal Character ]
2115 * Characters referred to using character references must match the 2323 * Characters referred to using character references must match the
2116 * production for Char. 2324 * production for Char.
2117 */ 2325 */
2118 if ((IS_CHAR(val) && (outofrange == 0))) { 2326 if ((IS_CHAR(val) && (outofrange == 0))) {
2119 return(val); 2327 return(val);
2120 } else { 2328 } else {
2121 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, 2329 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2122 "xmlParseCharRef: invalid xmlChar value %d\n", 2330 "xmlParseCharRef: invalid xmlChar value %d\n",
2123 val); 2331 val);
2124 } 2332 }
2125 return(0); 2333 return(0);
2126 } 2334 }
2127 2335
2128 /** 2336 /**
2129 * xmlParseStringCharRef: 2337 * xmlParseStringCharRef:
2130 * @ctxt: an XML parser context 2338 * @ctxt: an XML parser context
2131 * @str: a pointer to an index in the string 2339 * @str: a pointer to an index in the string
2132 * 2340 *
2133 * parse Reference declarations, variant parsing from a string rather 2341 * parse Reference declarations, variant parsing from a string rather
2134 * than an an input flow. 2342 * than an an input flow.
2135 * 2343 *
2136 * [66] CharRef ::= '&#' [0-9]+ ';' | 2344 * [66] CharRef ::= '&#' [0-9]+ ';' |
2137 * '&#x' [0-9a-fA-F]+ ';' 2345 * '&#x' [0-9a-fA-F]+ ';'
2138 * 2346 *
2139 * [ WFC: Legal Character ] 2347 * [ WFC: Legal Character ]
2140 * Characters referred to using character references must match the 2348 * Characters referred to using character references must match the
2141 * production for Char. 2349 * production for Char.
2142 * 2350 *
2143 * Returns the value parsed (as an int), 0 in case of error, str will be 2351 * Returns the value parsed (as an int), 0 in case of error, str will be
2144 * updated to the current value of the index 2352 * updated to the current value of the index
2145 */ 2353 */
2146 static int 2354 static int
2147 xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str) { 2355 xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str) {
2148 const xmlChar *ptr; 2356 const xmlChar *ptr;
2149 xmlChar cur; 2357 xmlChar cur;
2150 unsigned int val = 0; 2358 unsigned int val = 0;
2151 unsigned int outofrange = 0; 2359 unsigned int outofrange = 0;
2152 2360
2153 if ((str == NULL) || (*str == NULL)) return(0); 2361 if ((str == NULL) || (*str == NULL)) return(0);
2154 ptr = *str; 2362 ptr = *str;
2155 cur = *ptr; 2363 cur = *ptr;
2156 if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) { 2364 if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) {
2157 ptr += 3; 2365 ptr += 3;
2158 cur = *ptr; 2366 cur = *ptr;
2159 while (cur != ';') { /* Non input consuming loop */ 2367 while (cur != ';') { /* Non input consuming loop */
2160 » if ((cur >= '0') && (cur <= '9')) 2368 » if ((cur >= '0') && (cur <= '9'))
2161 val = val * 16 + (cur - '0'); 2369 val = val * 16 + (cur - '0');
2162 else if ((cur >= 'a') && (cur <= 'f')) 2370 else if ((cur >= 'a') && (cur <= 'f'))
2163 val = val * 16 + (cur - 'a') + 10; 2371 val = val * 16 + (cur - 'a') + 10;
2164 else if ((cur >= 'A') && (cur <= 'F')) 2372 else if ((cur >= 'A') && (cur <= 'F'))
2165 val = val * 16 + (cur - 'A') + 10; 2373 val = val * 16 + (cur - 'A') + 10;
2166 else { 2374 else {
2167 xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL); 2375 xmlFatalErr(ctxt, XML_ERR_INVALID_HEX_CHARREF, NULL);
2168 val = 0; 2376 val = 0;
2169 break; 2377 break;
2170 } 2378 }
2171 if (val > 0x10FFFF) 2379 if (val > 0x10FFFF)
2172 outofrange = val; 2380 outofrange = val;
2173 2381
2174 ptr++; 2382 ptr++;
2175 cur = *ptr; 2383 cur = *ptr;
2176 } 2384 }
2177 if (cur == ';') 2385 if (cur == ';')
2178 ptr++; 2386 ptr++;
2179 } else if ((cur == '&') && (ptr[1] == '#')){ 2387 } else if ((cur == '&') && (ptr[1] == '#')){
2180 ptr += 2; 2388 ptr += 2;
2181 cur = *ptr; 2389 cur = *ptr;
2182 while (cur != ';') { /* Non input consuming loops */ 2390 while (cur != ';') { /* Non input consuming loops */
2183 » if ((cur >= '0') && (cur <= '9')) 2391 » if ((cur >= '0') && (cur <= '9'))
2184 val = val * 10 + (cur - '0'); 2392 val = val * 10 + (cur - '0');
2185 else { 2393 else {
2186 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL); 2394 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);
2187 val = 0; 2395 val = 0;
2188 break; 2396 break;
2189 } 2397 }
2190 if (val > 0x10FFFF) 2398 if (val > 0x10FFFF)
2191 outofrange = val; 2399 outofrange = val;
2192 2400
2193 ptr++; 2401 ptr++;
2194 cur = *ptr; 2402 cur = *ptr;
2195 } 2403 }
2196 if (cur == ';') 2404 if (cur == ';')
2197 ptr++; 2405 ptr++;
2198 } else { 2406 } else {
2199 xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL); 2407 xmlFatalErr(ctxt, XML_ERR_INVALID_CHARREF, NULL);
2200 return(0); 2408 return(0);
2201 } 2409 }
2202 *str = ptr; 2410 *str = ptr;
2203 2411
2204 /* 2412 /*
2205 * [ WFC: Legal Character ] 2413 * [ WFC: Legal Character ]
2206 * Characters referred to using character references must match the 2414 * Characters referred to using character references must match the
2207 * production for Char. 2415 * production for Char.
2208 */ 2416 */
2209 if ((IS_CHAR(val) && (outofrange == 0))) { 2417 if ((IS_CHAR(val) && (outofrange == 0))) {
2210 return(val); 2418 return(val);
2211 } else { 2419 } else {
2212 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, 2420 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2213 "xmlParseStringCharRef: invalid xmlChar value %d\n", 2421 "xmlParseStringCharRef: invalid xmlChar value %d\n",
2214 val); 2422 val);
2215 } 2423 }
2216 return(0); 2424 return(0);
2217 } 2425 }
2218 2426
2219 /** 2427 /**
2220 * xmlNewBlanksWrapperInputStream: 2428 * xmlNewBlanksWrapperInputStream:
2221 * @ctxt: an XML parser context 2429 * @ctxt: an XML parser context
2222 * @entity: an Entity pointer 2430 * @entity: an Entity pointer
2223 * 2431 *
2224 * Create a new input stream for wrapping 2432 * Create a new input stream for wrapping
2225 * blanks around a PEReference 2433 * blanks around a PEReference
2226 * 2434 *
2227 * Returns the new input stream or NULL 2435 * Returns the new input stream or NULL
2228 */ 2436 */
2229 2437
2230 static void deallocblankswrapper (xmlChar *str) {xmlFree(str);} 2438 static void deallocblankswrapper (xmlChar *str) {xmlFree(str);}
2231 2439
2232 static xmlParserInputPtr 2440 static xmlParserInputPtr
2233 xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { 2441 xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
2234 xmlParserInputPtr input; 2442 xmlParserInputPtr input;
2235 xmlChar *buffer; 2443 xmlChar *buffer;
2236 size_t length; 2444 size_t length;
2237 if (entity == NULL) { 2445 if (entity == NULL) {
2238 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 2446 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
2239 "xmlNewBlanksWrapperInputStream entity\n"); 2447 "xmlNewBlanksWrapperInputStream entity\n");
2240 return(NULL); 2448 return(NULL);
2241 } 2449 }
2242 if (xmlParserDebugEntities) 2450 if (xmlParserDebugEntities)
2243 xmlGenericError(xmlGenericErrorContext, 2451 xmlGenericError(xmlGenericErrorContext,
2244 "new blanks wrapper for entity: %s\n", entity->name); 2452 "new blanks wrapper for entity: %s\n", entity->name);
2245 input = xmlNewInputStream(ctxt); 2453 input = xmlNewInputStream(ctxt);
2246 if (input == NULL) { 2454 if (input == NULL) {
2247 return(NULL); 2455 return(NULL);
2248 } 2456 }
2249 length = xmlStrlen(entity->name) + 5; 2457 length = xmlStrlen(entity->name) + 5;
2250 buffer = xmlMallocAtomic(length); 2458 buffer = xmlMallocAtomic(length);
2251 if (buffer == NULL) { 2459 if (buffer == NULL) {
2252 xmlErrMemory(ctxt, NULL); 2460 xmlErrMemory(ctxt, NULL);
2253 xmlFree(input); 2461 xmlFree(input);
2254 » return(NULL); 2462 » return(NULL);
2255 } 2463 }
2256 buffer [0] = ' '; 2464 buffer [0] = ' ';
2257 buffer [1] = '%'; 2465 buffer [1] = '%';
2258 buffer [length-3] = ';'; 2466 buffer [length-3] = ';';
2259 buffer [length-2] = ' '; 2467 buffer [length-2] = ' ';
2260 buffer [length-1] = 0; 2468 buffer [length-1] = 0;
2261 memcpy(buffer + 2, entity->name, length - 5); 2469 memcpy(buffer + 2, entity->name, length - 5);
2262 input->free = deallocblankswrapper; 2470 input->free = deallocblankswrapper;
2263 input->base = buffer; 2471 input->base = buffer;
2264 input->cur = buffer; 2472 input->cur = buffer;
2265 input->length = length; 2473 input->length = length;
2266 input->end = &buffer[length]; 2474 input->end = &buffer[length];
2267 return(input); 2475 return(input);
2268 } 2476 }
2269 2477
2270 /** 2478 /**
2271 * xmlParserHandlePEReference: 2479 * xmlParserHandlePEReference:
2272 * @ctxt: the parser context 2480 * @ctxt: the parser context
2273 * 2481 *
2274 * [69] PEReference ::= '%' Name ';' 2482 * [69] PEReference ::= '%' Name ';'
2275 * 2483 *
2276 * [ WFC: No Recursion ] 2484 * [ WFC: No Recursion ]
2277 * A parsed entity must not contain a recursive 2485 * A parsed entity must not contain a recursive
2278 * reference to itself, either directly or indirectly. 2486 * reference to itself, either directly or indirectly.
2279 * 2487 *
2280 * [ WFC: Entity Declared ] 2488 * [ WFC: Entity Declared ]
2281 * In a document without any DTD, a document with only an internal DTD 2489 * In a document without any DTD, a document with only an internal DTD
2282 * subset which contains no parameter entity references, or a document 2490 * subset which contains no parameter entity references, or a document
2283 * with "standalone='yes'", ... ... The declaration of a parameter 2491 * with "standalone='yes'", ... ... The declaration of a parameter
2284 * entity must precede any reference to it... 2492 * entity must precede any reference to it...
2285 * 2493 *
2286 * [ VC: Entity Declared ] 2494 * [ VC: Entity Declared ]
2287 * In a document with an external subset or external parameter entities 2495 * In a document with an external subset or external parameter entities
2288 * with "standalone='no'", ... ... The declaration of a parameter entity 2496 * with "standalone='no'", ... ... The declaration of a parameter entity
2289 * must precede any reference to it... 2497 * must precede any reference to it...
2290 * 2498 *
2291 * [ WFC: In DTD ] 2499 * [ WFC: In DTD ]
2292 * Parameter-entity references may only appear in the DTD. 2500 * Parameter-entity references may only appear in the DTD.
2293 * NOTE: misleading but this is handled. 2501 * NOTE: misleading but this is handled.
2294 * 2502 *
2295 * A PEReference may have been detected in the current input stream 2503 * A PEReference may have been detected in the current input stream
2296 * the handling is done accordingly to 2504 * the handling is done accordingly to
2297 * http://www.w3.org/TR/REC-xml#entproc 2505 * http://www.w3.org/TR/REC-xml#entproc
2298 * i.e. 2506 * i.e.
2299 * - Included in literal in entity values 2507 * - Included in literal in entity values
2300 * - Included as Parameter Entity reference within DTDs 2508 * - Included as Parameter Entity reference within DTDs
2301 */ 2509 */
2302 void 2510 void
2303 xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { 2511 xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
2304 const xmlChar *name; 2512 const xmlChar *name;
2305 xmlEntityPtr entity = NULL; 2513 xmlEntityPtr entity = NULL;
2306 xmlParserInputPtr input; 2514 xmlParserInputPtr input;
2307 2515
2308 if (RAW != '%') return; 2516 if (RAW != '%') return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 if (name == NULL) { 2576 if (name == NULL) {
2369 xmlFatalErr(ctxt, XML_ERR_PEREF_NO_NAME, NULL); 2577 xmlFatalErr(ctxt, XML_ERR_PEREF_NO_NAME, NULL);
2370 } else { 2578 } else {
2371 if (RAW == ';') { 2579 if (RAW == ';') {
2372 NEXT; 2580 NEXT;
2373 if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL)) 2581 if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL))
2374 entity = ctxt->sax->getParameterEntity(ctxt->userData, name); 2582 entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
2375 if (ctxt->instate == XML_PARSER_EOF) 2583 if (ctxt->instate == XML_PARSER_EOF)
2376 return; 2584 return;
2377 if (entity == NULL) { 2585 if (entity == NULL) {
2378 » 2586
2379 /* 2587 /*
2380 * [ WFC: Entity Declared ] 2588 * [ WFC: Entity Declared ]
2381 * In a document without any DTD, a document with only an 2589 * In a document without any DTD, a document with only an
2382 * internal DTD subset which contains no parameter entity 2590 * internal DTD subset which contains no parameter entity
2383 * references, or a document with "standalone='yes'", ... 2591 * references, or a document with "standalone='yes'", ...
2384 * ... The declaration of a parameter entity must precede 2592 * ... The declaration of a parameter entity must precede
2385 * any reference to it... 2593 * any reference to it...
2386 */ 2594 */
2387 if ((ctxt->standalone == 1) || 2595 if ((ctxt->standalone == 1) ||
2388 ((ctxt->hasExternalSubset == 0) && 2596 ((ctxt->hasExternalSubset == 0) &&
2389 (ctxt->hasPErefs == 0))) { 2597 (ctxt->hasPErefs == 0))) {
2390 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, 2598 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
2391 "PEReference: %%%s; not found\n", name); 2599 "PEReference: %%%s; not found\n", name);
2392 } else { 2600 } else {
2393 /* 2601 /*
2394 * [ VC: Entity Declared ] 2602 * [ VC: Entity Declared ]
2395 * In a document with an external subset or external 2603 * In a document with an external subset or external
2396 * parameter entities with "standalone='no'", ... 2604 * parameter entities with "standalone='no'", ...
2397 * ... The declaration of a parameter entity must precede 2605 * ... The declaration of a parameter entity must precede
2398 * any reference to it... 2606 * any reference to it...
2399 */ 2607 */
2400 if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) { 2608 if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
2401 xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY, 2609 xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
2402 "PEReference: %%%s; not found\n", 2610 "PEReference: %%%s; not found\n",
2403 name, NULL); 2611 name, NULL);
2404 » » } else 2612 » » } else
2405 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 2613 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
2406 "PEReference: %%%s; not found\n", 2614 "PEReference: %%%s; not found\n",
2407 name, NULL); 2615 name, NULL);
2408 ctxt->valid = 0; 2616 ctxt->valid = 0;
2409 } 2617 }
2618 xmlParserEntityCheck(ctxt, 0, NULL, 0);
2410 } else if (ctxt->input->free != deallocblankswrapper) { 2619 } else if (ctxt->input->free != deallocblankswrapper) {
2411 input = xmlNewBlanksWrapperInputStream(ctxt, entity); 2620 input = xmlNewBlanksWrapperInputStream(ctxt, entity);
2412 if (xmlPushInput(ctxt, input) < 0) 2621 if (xmlPushInput(ctxt, input) < 0)
2413 return; 2622 return;
2414 } else { 2623 } else {
2415 if ((entity->etype == XML_INTERNAL_PARAMETER_ENTITY) || 2624 if ((entity->etype == XML_INTERNAL_PARAMETER_ENTITY) ||
2416 (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY)) { 2625 (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY)) {
2417 xmlChar start[4]; 2626 xmlChar start[4];
2418 xmlCharEncoding enc; 2627 xmlCharEncoding enc;
2419 2628
2420 /* 2629 /*
2630 * Note: external parameter entities will not be loaded, it
2631 * is not required for a non-validating parser, unless the
2632 * option of validating, or substituting entities were
2633 * given. Doing so is far more secure as the parser will
2634 * only process data coming from the document entity by
2635 * default.
2636 */
2637 if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
2638 ((ctxt->options & XML_PARSE_NOENT) == 0) &&
2639 ((ctxt->options & XML_PARSE_DTDVALID) == 0) &&
2640 ((ctxt->options & XML_PARSE_DTDLOAD) == 0) &&
2641 ((ctxt->options & XML_PARSE_DTDATTR) == 0) &&
2642 (ctxt->replaceEntities == 0) &&
2643 (ctxt->validate == 0))
2644 return;
2645
2646 /*
2421 * handle the extra spaces added before and after 2647 * handle the extra spaces added before and after
2422 * c.f. http://www.w3.org/TR/REC-xml#as-PE 2648 * c.f. http://www.w3.org/TR/REC-xml#as-PE
2423 * this is done independently. 2649 * this is done independently.
2424 */ 2650 */
2425 input = xmlNewEntityInputStream(ctxt, entity); 2651 input = xmlNewEntityInputStream(ctxt, entity);
2426 if (xmlPushInput(ctxt, input) < 0) 2652 if (xmlPushInput(ctxt, input) < 0)
2427 return; 2653 return;
2428 2654
2429 » » /* 2655 » » /*
2430 * Get the 4 first bytes and decode the charset 2656 * Get the 4 first bytes and decode the charset
2431 * if enc != XML_CHAR_ENCODING_NONE 2657 * if enc != XML_CHAR_ENCODING_NONE
2432 * plug some encoding conversion routines. 2658 * plug some encoding conversion routines.
2433 * Note that, since we may have some non-UTF8 2659 * Note that, since we may have some non-UTF8
2434 * encoding (like UTF16, bug 135229), the 'length' 2660 * encoding (like UTF16, bug 135229), the 'length'
2435 * is not known, but we can calculate based upon 2661 * is not known, but we can calculate based upon
2436 * the amount of data in the buffer. 2662 * the amount of data in the buffer.
2437 */ 2663 */
2438 GROW 2664 GROW
2439 if (ctxt->instate == XML_PARSER_EOF) 2665 if (ctxt->instate == XML_PARSER_EOF)
(...skipping 21 matching lines...) Expand all
2461 } 2687 }
2462 } 2688 }
2463 } else { 2689 } else {
2464 xmlFatalErr(ctxt, XML_ERR_PEREF_SEMICOL_MISSING, NULL); 2690 xmlFatalErr(ctxt, XML_ERR_PEREF_SEMICOL_MISSING, NULL);
2465 } 2691 }
2466 } 2692 }
2467 } 2693 }
2468 2694
2469 /* 2695 /*
2470 * Macro used to grow the current buffer. 2696 * Macro used to grow the current buffer.
2697 * buffer##_size is expected to be a size_t
2698 * mem_error: is expected to handle memory allocation failures
2471 */ 2699 */
2472 #define growBuffer(buffer, n) { \ 2700 #define growBuffer(buffer, n) { \
2473 xmlChar *tmp; \ 2701 xmlChar *tmp; \
2474 buffer##_size *= 2;»» » » » » » \ 2702 size_t new_size = buffer##_size * 2 + n; \
2475 buffer##_size += n;»» » » » » » \ 2703 if (new_size < buffer##_size) goto mem_error; \
2476 tmp = (xmlChar *)» » » » » » » \ 2704 tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
2477 » » xmlRealloc(buffer, buffer##_size * sizeof(xmlChar));» \
2478 if (tmp == NULL) goto mem_error; \ 2705 if (tmp == NULL) goto mem_error; \
2479 buffer = tmp; \ 2706 buffer = tmp; \
2707 buffer##_size = new_size; \
2480 } 2708 }
2481 2709
2482 /** 2710 /**
2483 * xmlStringLenDecodeEntities: 2711 * xmlStringLenDecodeEntities:
2484 * @ctxt: the parser context 2712 * @ctxt: the parser context
2485 * @str: the input string 2713 * @str: the input string
2486 * @len: the string length 2714 * @len: the string length
2487 * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF 2715 * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF
2488 * @end: an end marker xmlChar, 0 if none 2716 * @end: an end marker xmlChar, 0 if none
2489 * @end2: an end marker xmlChar, 0 if none 2717 * @end2: an end marker xmlChar, 0 if none
2490 * @end3: an end marker xmlChar, 0 if none 2718 * @end3: an end marker xmlChar, 0 if none
2491 * 2719 *
2492 * Takes a entity string content and process to do the adequate substitutions. 2720 * Takes a entity string content and process to do the adequate substitutions.
2493 * 2721 *
2494 * [67] Reference ::= EntityRef | CharRef 2722 * [67] Reference ::= EntityRef | CharRef
2495 * 2723 *
2496 * [69] PEReference ::= '%' Name ';' 2724 * [69] PEReference ::= '%' Name ';'
2497 * 2725 *
2498 * Returns A newly allocated string with the substitution done. The caller 2726 * Returns A newly allocated string with the substitution done. The caller
2499 * must deallocate it ! 2727 * must deallocate it !
2500 */ 2728 */
2501 xmlChar * 2729 xmlChar *
2502 xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, 2730 xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
2503 int what, xmlChar end, xmlChar end2, xmlChar end3) { 2731 int what, xmlChar end, xmlChar end2, xmlChar end3) {
2504 xmlChar *buffer = NULL; 2732 xmlChar *buffer = NULL;
2505 int buffer_size = 0; 2733 size_t buffer_size = 0;
2734 size_t nbchars = 0;
2506 2735
2507 xmlChar *current = NULL; 2736 xmlChar *current = NULL;
2508 xmlChar *rep = NULL; 2737 xmlChar *rep = NULL;
2509 const xmlChar *last; 2738 const xmlChar *last;
2510 xmlEntityPtr ent; 2739 xmlEntityPtr ent;
2511 int c,l; 2740 int c,l;
2512 int nbchars = 0;
2513 2741
2514 if ((ctxt == NULL) || (str == NULL) || (len < 0)) 2742 if ((ctxt == NULL) || (str == NULL) || (len < 0))
2515 return(NULL); 2743 return(NULL);
2516 last = str + len; 2744 last = str + len;
2517 2745
2518 if (((ctxt->depth > 40) && 2746 if (((ctxt->depth > 40) &&
2519 ((ctxt->options & XML_PARSE_HUGE) == 0)) || 2747 ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
2520 (ctxt->depth > 1024)) { 2748 (ctxt->depth > 1024)) {
2521 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); 2749 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
2522 return(NULL); 2750 return(NULL);
2523 } 2751 }
2524 2752
2525 /* 2753 /*
2526 * allocate a translation buffer. 2754 * allocate a translation buffer.
2527 */ 2755 */
2528 buffer_size = XML_PARSER_BIG_BUFFER_SIZE; 2756 buffer_size = XML_PARSER_BIG_BUFFER_SIZE;
2529 buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar)); 2757 buffer = (xmlChar *) xmlMallocAtomic(buffer_size);
2530 if (buffer == NULL) goto mem_error; 2758 if (buffer == NULL) goto mem_error;
2531 2759
2532 /* 2760 /*
2533 * OK loop until we reach one of the ending char or a size limit. 2761 * OK loop until we reach one of the ending char or a size limit.
2534 * we are operating on already parsed values. 2762 * we are operating on already parsed values.
2535 */ 2763 */
2536 if (str < last) 2764 if (str < last)
2537 c = CUR_SCHAR(str, l); 2765 c = CUR_SCHAR(str, l);
2538 else 2766 else
2539 c = 0; 2767 c = 0;
2540 while ((c != 0) && (c != end) && /* non input consuming loop */ 2768 while ((c != 0) && (c != end) && /* non input consuming loop */
2541 (c != end2) && (c != end3)) { 2769 (c != end2) && (c != end3)) {
2542 2770
2543 if (c == 0) break; 2771 if (c == 0) break;
2544 if ((c == '&') && (str[1] == '#')) { 2772 if ((c == '&') && (str[1] == '#')) {
2545 int val = xmlParseStringCharRef(ctxt, &str); 2773 int val = xmlParseStringCharRef(ctxt, &str);
2546 if (val != 0) { 2774 if (val != 0) {
2547 COPY_BUF(0,buffer,nbchars,val); 2775 COPY_BUF(0,buffer,nbchars,val);
2548 } 2776 }
2549 » if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { 2777 » if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2550 growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2778 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2551 } 2779 }
2552 } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) { 2780 } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {
2553 if (xmlParserDebugEntities) 2781 if (xmlParserDebugEntities)
2554 xmlGenericError(xmlGenericErrorContext, 2782 xmlGenericError(xmlGenericErrorContext,
2555 "String decoding Entity Reference: %.30s\n", 2783 "String decoding Entity Reference: %.30s\n",
2556 str); 2784 str);
2557 ent = xmlParseStringEntityRef(ctxt, &str); 2785 ent = xmlParseStringEntityRef(ctxt, &str);
2558 if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) || 2786 if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
2559 (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR)) 2787 (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
2560 goto int_error; 2788 goto int_error;
2789 xmlParserEntityCheck(ctxt, 0, ent, 0);
2561 if (ent != NULL) 2790 if (ent != NULL)
2562 » ctxt->nbentities += ent->checked; 2791 » ctxt->nbentities += ent->checked / 2;
2563 if ((ent != NULL) && 2792 if ((ent != NULL) &&
2564 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { 2793 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
2565 if (ent->content != NULL) { 2794 if (ent->content != NULL) {
2566 COPY_BUF(0,buffer,nbchars,ent->content[0]); 2795 COPY_BUF(0,buffer,nbchars,ent->content[0]);
2567 » » if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { 2796 » » if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2568 growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2797 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2569 } 2798 }
2570 } else { 2799 } else {
2571 xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, 2800 xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
2572 "predefined entity has no content\n"); 2801 "predefined entity has no content\n");
2573 } 2802 }
2574 } else if ((ent != NULL) && (ent->content != NULL)) { 2803 } else if ((ent != NULL) && (ent->content != NULL)) {
2575 ctxt->depth++; 2804 ctxt->depth++;
2576 rep = xmlStringDecodeEntities(ctxt, ent->content, what, 2805 rep = xmlStringDecodeEntities(ctxt, ent->content, what,
2577 0, 0, 0); 2806 0, 0, 0);
2578 ctxt->depth--; 2807 ctxt->depth--;
2579 2808
2580 if (rep != NULL) { 2809 if (rep != NULL) {
2581 current = rep; 2810 current = rep;
2582 while (*current != 0) { /* non input consuming loop */ 2811 while (*current != 0) { /* non input consuming loop */
2583 buffer[nbchars++] = *current++; 2812 buffer[nbchars++] = *current++;
2584 » » » if (nbchars > 2813 » » » if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2585 » » buffer_size - XML_PARSER_BUFFER_SIZE) { 2814 » » » if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
2586 » » » if (xmlParserEntityCheck(ctxt, nbchars, ent))
2587 goto int_error; 2815 goto int_error;
2588 growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2816 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2589 } 2817 }
2590 } 2818 }
2591 xmlFree(rep); 2819 xmlFree(rep);
2592 rep = NULL; 2820 rep = NULL;
2593 } 2821 }
2594 } else if (ent != NULL) { 2822 } else if (ent != NULL) {
2595 int i = xmlStrlen(ent->name); 2823 int i = xmlStrlen(ent->name);
2596 const xmlChar *cur = ent->name; 2824 const xmlChar *cur = ent->name;
2597 2825
2598 buffer[nbchars++] = '&'; 2826 buffer[nbchars++] = '&';
2599 » » if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) { 2827 » » if (nbchars + i + XML_PARSER_BUFFER_SIZE > buffer_size) {
2600 growBuffer(buffer, i + XML_PARSER_BUFFER_SIZE); 2828 growBuffer(buffer, i + XML_PARSER_BUFFER_SIZE);
2601 } 2829 }
2602 for (;i > 0;i--) 2830 for (;i > 0;i--)
2603 buffer[nbchars++] = *cur++; 2831 buffer[nbchars++] = *cur++;
2604 buffer[nbchars++] = ';'; 2832 buffer[nbchars++] = ';';
2605 } 2833 }
2606 } else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) { 2834 } else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) {
2607 if (xmlParserDebugEntities) 2835 if (xmlParserDebugEntities)
2608 xmlGenericError(xmlGenericErrorContext, 2836 xmlGenericError(xmlGenericErrorContext,
2609 "String decoding PE Reference: %.30s\n", str); 2837 "String decoding PE Reference: %.30s\n", str);
2610 ent = xmlParseStringPEReference(ctxt, &str); 2838 ent = xmlParseStringPEReference(ctxt, &str);
2611 if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP) 2839 if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
2612 goto int_error; 2840 goto int_error;
2841 xmlParserEntityCheck(ctxt, 0, ent, 0);
2613 if (ent != NULL) 2842 if (ent != NULL)
2614 » ctxt->nbentities += ent->checked; 2843 » ctxt->nbentities += ent->checked / 2;
2615 if (ent != NULL) { 2844 if (ent != NULL) {
2616 if (ent->content == NULL) { 2845 if (ent->content == NULL) {
2617 xmlLoadEntityContent(ctxt, ent); 2846 xmlLoadEntityContent(ctxt, ent);
2618 } 2847 }
2619 ctxt->depth++; 2848 ctxt->depth++;
2620 rep = xmlStringDecodeEntities(ctxt, ent->content, what, 2849 rep = xmlStringDecodeEntities(ctxt, ent->content, what,
2621 0, 0, 0); 2850 0, 0, 0);
2622 ctxt->depth--; 2851 ctxt->depth--;
2623 if (rep != NULL) { 2852 if (rep != NULL) {
2624 current = rep; 2853 current = rep;
2625 while (*current != 0) { /* non input consuming loop */ 2854 while (*current != 0) { /* non input consuming loop */
2626 buffer[nbchars++] = *current++; 2855 buffer[nbchars++] = *current++;
2627 » » » if (nbchars > 2856 » » » if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2628 » » buffer_size - XML_PARSER_BUFFER_SIZE) { 2857 » » » if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
2629 » » » if (xmlParserEntityCheck(ctxt, nbchars, ent))
2630 goto int_error; 2858 goto int_error;
2631 growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2859 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2632 } 2860 }
2633 } 2861 }
2634 xmlFree(rep); 2862 xmlFree(rep);
2635 rep = NULL; 2863 rep = NULL;
2636 } 2864 }
2637 } 2865 }
2638 } else { 2866 } else {
2639 COPY_BUF(l,buffer,nbchars,c); 2867 COPY_BUF(l,buffer,nbchars,c);
2640 str += l; 2868 str += l;
2641 » if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { 2869 » if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2642 » growBuffer(buffer, XML_PARSER_BUFFER_SIZE); 2870 » growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
2643 } 2871 }
2644 } 2872 }
2645 if (str < last) 2873 if (str < last)
2646 c = CUR_SCHAR(str, l); 2874 c = CUR_SCHAR(str, l);
2647 else 2875 else
2648 c = 0; 2876 c = 0;
2649 } 2877 }
2650 buffer[nbchars] = 0; 2878 buffer[nbchars] = 0;
2651 return(buffer); 2879 return(buffer);
2652 2880
2653 mem_error: 2881 mem_error:
2654 xmlErrMemory(ctxt, NULL); 2882 xmlErrMemory(ctxt, NULL);
2655 int_error: 2883 int_error:
2656 if (rep != NULL) 2884 if (rep != NULL)
2657 xmlFree(rep); 2885 xmlFree(rep);
2658 if (buffer != NULL) 2886 if (buffer != NULL)
2659 xmlFree(buffer); 2887 xmlFree(buffer);
2660 return(NULL); 2888 return(NULL);
2661 } 2889 }
2662 2890
2663 /** 2891 /**
2664 * xmlStringDecodeEntities: 2892 * xmlStringDecodeEntities:
2665 * @ctxt: the parser context 2893 * @ctxt: the parser context
2666 * @str: the input string 2894 * @str: the input string
2667 * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF 2895 * @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF
2668 * @end: an end marker xmlChar, 0 if none 2896 * @end: an end marker xmlChar, 0 if none
2669 * @end2: an end marker xmlChar, 0 if none 2897 * @end2: an end marker xmlChar, 0 if none
2670 * @end3: an end marker xmlChar, 0 if none 2898 * @end3: an end marker xmlChar, 0 if none
2671 * 2899 *
2672 * Takes a entity string content and process to do the adequate substitutions. 2900 * Takes a entity string content and process to do the adequate substitutions.
2673 * 2901 *
2674 * [67] Reference ::= EntityRef | CharRef 2902 * [67] Reference ::= EntityRef | CharRef
2675 * 2903 *
2676 * [69] PEReference ::= '%' Name ';' 2904 * [69] PEReference ::= '%' Name ';'
2677 * 2905 *
2678 * Returns A newly allocated string with the substitution done. The caller 2906 * Returns A newly allocated string with the substitution done. The caller
2679 * must deallocate it ! 2907 * must deallocate it !
2680 */ 2908 */
2681 xmlChar * 2909 xmlChar *
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 ((c >= 0x2070) && (c <= 0x218F)) || 3252 ((c >= 0x2070) && (c <= 0x218F)) ||
3025 ((c >= 0x2C00) && (c <= 0x2FEF)) || 3253 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3026 ((c >= 0x3001) && (c <= 0xD7FF)) || 3254 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3027 ((c >= 0xF900) && (c <= 0xFDCF)) || 3255 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3028 ((c >= 0xFDF0) && (c <= 0xFFFD)) || 3256 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3029 ((c >= 0x10000) && (c <= 0xEFFFF)))) 3257 ((c >= 0x10000) && (c <= 0xEFFFF))))
3030 return(1); 3258 return(1);
3031 } else { 3259 } else {
3032 if ((IS_LETTER(c)) || (IS_DIGIT(c)) || 3260 if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
3033 (c == '.') || (c == '-') || 3261 (c == '.') || (c == '-') ||
3034 » (c == '_') || (c == ':') || 3262 » (c == '_') || (c == ':') ||
3035 (IS_COMBINING(c)) || 3263 (IS_COMBINING(c)) ||
3036 (IS_EXTENDER(c))) 3264 (IS_EXTENDER(c)))
3037 return(1); 3265 return(1);
3038 } 3266 }
3039 return(0); 3267 return(0);
3040 } 3268 }
3041 3269
3042 static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, 3270 static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt,
3043 int *len, int *alloc, int normalize); 3271 int *len, int *alloc, int normalize);
3044 3272
3045 static const xmlChar * 3273 static const xmlChar *
3046 xmlParseNameComplex(xmlParserCtxtPtr ctxt) { 3274 xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
3047 int len = 0, l; 3275 int len = 0, l;
3048 int c; 3276 int c;
3049 int count = 0; 3277 int count = 0;
3050 3278
3051 #ifdef DEBUG 3279 #ifdef DEBUG
3052 nbParseNameComplex++; 3280 nbParseNameComplex++;
3053 #endif 3281 #endif
3054 3282
3055 /* 3283 /*
3056 * Handler for more complex cases 3284 * Handler for more complex cases
3057 */ 3285 */
3058 GROW; 3286 GROW;
3059 if (ctxt->instate == XML_PARSER_EOF) 3287 if (ctxt->instate == XML_PARSER_EOF)
3060 » return(NULL); 3288 return(NULL);
3061 c = CUR_CHAR(l); 3289 c = CUR_CHAR(l);
3062 if ((ctxt->options & XML_PARSE_OLD10) == 0) { 3290 if ((ctxt->options & XML_PARSE_OLD10) == 0) {
3063 /* 3291 /*
3064 * Use the new checks of production [4] [4a] amd [5] of the 3292 * Use the new checks of production [4] [4a] amd [5] of the
3065 * Update 5 of XML-1.0 3293 * Update 5 of XML-1.0
3066 */ 3294 */
3067 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ 3295 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3068 (!(((c >= 'a') && (c <= 'z')) || 3296 (!(((c >= 'a') && (c <= 'z')) ||
3069 ((c >= 'A') && (c <= 'Z')) || 3297 ((c >= 'A') && (c <= 'Z')) ||
3070 (c == '_') || (c == ':') || 3298 (c == '_') || (c == ':') ||
(...skipping 28 matching lines...) Expand all
3099 ((c >= 0x37F) && (c <= 0x1FFF)) || 3327 ((c >= 0x37F) && (c <= 0x1FFF)) ||
3100 ((c >= 0x200C) && (c <= 0x200D)) || 3328 ((c >= 0x200C) && (c <= 0x200D)) ||
3101 ((c >= 0x203F) && (c <= 0x2040)) || /* !start */ 3329 ((c >= 0x203F) && (c <= 0x2040)) || /* !start */
3102 ((c >= 0x2070) && (c <= 0x218F)) || 3330 ((c >= 0x2070) && (c <= 0x218F)) ||
3103 ((c >= 0x2C00) && (c <= 0x2FEF)) || 3331 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3104 ((c >= 0x3001) && (c <= 0xD7FF)) || 3332 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3105 ((c >= 0xF900) && (c <= 0xFDCF)) || 3333 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3106 ((c >= 0xFDF0) && (c <= 0xFFFD)) || 3334 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3107 ((c >= 0x10000) && (c <= 0xEFFFF)) 3335 ((c >= 0x10000) && (c <= 0xEFFFF))
3108 )) { 3336 )) {
3109 » if (count++ > 100) { 3337 » if (count++ > XML_PARSER_CHUNK_SIZE) {
3110 count = 0; 3338 count = 0;
3111 GROW; 3339 GROW;
3112 if (ctxt->instate == XML_PARSER_EOF) 3340 if (ctxt->instate == XML_PARSER_EOF)
3113 return(NULL); 3341 return(NULL);
3114 } 3342 }
3115 len += l; 3343 len += l;
3116 NEXTL(l); 3344 NEXTL(l);
3117 c = CUR_CHAR(l); 3345 c = CUR_CHAR(l);
3118 } 3346 }
3119 } else { 3347 } else {
3120 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ 3348 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3121 (!IS_LETTER(c) && (c != '_') && 3349 (!IS_LETTER(c) && (c != '_') &&
3122 (c != ':'))) { 3350 (c != ':'))) {
3123 return(NULL); 3351 return(NULL);
3124 } 3352 }
3125 len += l; 3353 len += l;
3126 NEXTL(l); 3354 NEXTL(l);
3127 c = CUR_CHAR(l); 3355 c = CUR_CHAR(l);
3128 3356
3129 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ 3357 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
3130 ((IS_LETTER(c)) || (IS_DIGIT(c)) || 3358 ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
3131 (c == '.') || (c == '-') || 3359 (c == '.') || (c == '-') ||
3132 » » (c == '_') || (c == ':') || 3360 » » (c == '_') || (c == ':') ||
3133 (IS_COMBINING(c)) || 3361 (IS_COMBINING(c)) ||
3134 (IS_EXTENDER(c)))) { 3362 (IS_EXTENDER(c)))) {
3135 » if (count++ > 100) { 3363 » if (count++ > XML_PARSER_CHUNK_SIZE) {
3136 count = 0; 3364 count = 0;
3137 GROW; 3365 GROW;
3138 if (ctxt->instate == XML_PARSER_EOF) 3366 if (ctxt->instate == XML_PARSER_EOF)
3139 return(NULL); 3367 return(NULL);
3140 } 3368 }
3141 len += l; 3369 len += l;
3142 NEXTL(l); 3370 NEXTL(l);
3143 c = CUR_CHAR(l); 3371 c = CUR_CHAR(l);
3372 if (c == 0) {
3373 count = 0;
3374 GROW;
3375 if (ctxt->instate == XML_PARSER_EOF)
3376 return(NULL);
3377 c = CUR_CHAR(l);
3378 }
3144 } 3379 }
3145 } 3380 }
3381 if ((len > XML_MAX_NAME_LENGTH) &&
3382 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3383 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
3384 return(NULL);
3385 }
3146 if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r')) 3386 if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r'))
3147 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len)); 3387 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len));
3148 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); 3388 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
3149 } 3389 }
3150 3390
3151 /** 3391 /**
3152 * xmlParseName: 3392 * xmlParseName:
3153 * @ctxt: an XML parser context 3393 * @ctxt: an XML parser context
3154 * 3394 *
3155 * parse an XML name. 3395 * parse an XML name.
(...skipping 29 matching lines...) Expand all
3185 (*in == '_') || (*in == ':')) { 3425 (*in == '_') || (*in == ':')) {
3186 in++; 3426 in++;
3187 while (((*in >= 0x61) && (*in <= 0x7A)) || 3427 while (((*in >= 0x61) && (*in <= 0x7A)) ||
3188 ((*in >= 0x41) && (*in <= 0x5A)) || 3428 ((*in >= 0x41) && (*in <= 0x5A)) ||
3189 ((*in >= 0x30) && (*in <= 0x39)) || 3429 ((*in >= 0x30) && (*in <= 0x39)) ||
3190 (*in == '_') || (*in == '-') || 3430 (*in == '_') || (*in == '-') ||
3191 (*in == ':') || (*in == '.')) 3431 (*in == ':') || (*in == '.'))
3192 in++; 3432 in++;
3193 if ((*in > 0) && (*in < 0x80)) { 3433 if ((*in > 0) && (*in < 0x80)) {
3194 count = in - ctxt->input->cur; 3434 count = in - ctxt->input->cur;
3435 if ((count > XML_MAX_NAME_LENGTH) &&
3436 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3437 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
3438 return(NULL);
3439 }
3195 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count); 3440 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
3196 ctxt->input->cur = in; 3441 ctxt->input->cur = in;
3197 ctxt->nbChars += count; 3442 ctxt->nbChars += count;
3198 ctxt->input->col += count; 3443 ctxt->input->col += count;
3199 if (ret == NULL) 3444 if (ret == NULL)
3200 xmlErrMemory(ctxt, NULL); 3445 xmlErrMemory(ctxt, NULL);
3201 return(ret); 3446 return(ret);
3202 } 3447 }
3203 } 3448 }
3204 /* accelerator for special cases */ 3449 /* accelerator for special cases */
3205 return(xmlParseNameComplex(ctxt)); 3450 return(xmlParseNameComplex(ctxt));
3206 } 3451 }
3207 3452
3208 static const xmlChar * 3453 static const xmlChar *
3209 xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { 3454 xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
3210 int len = 0, l; 3455 int len = 0, l;
3211 int c; 3456 int c;
3212 int count = 0; 3457 int count = 0;
3458 const xmlChar *end; /* needed because CUR_CHAR() can move cur on \r\n */
3213 3459
3214 #ifdef DEBUG 3460 #ifdef DEBUG
3215 nbParseNCNameComplex++; 3461 nbParseNCNameComplex++;
3216 #endif 3462 #endif
3217 3463
3218 /* 3464 /*
3219 * Handler for more complex cases 3465 * Handler for more complex cases
3220 */ 3466 */
3221 GROW; 3467 GROW;
3468 end = ctxt->input->cur;
3222 c = CUR_CHAR(l); 3469 c = CUR_CHAR(l);
3223 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */ 3470 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3224 (!xmlIsNameStartChar(ctxt, c) || (c == ':'))) { 3471 (!xmlIsNameStartChar(ctxt, c) || (c == ':'))) {
3225 return(NULL); 3472 return(NULL);
3226 } 3473 }
3227 3474
3228 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ 3475 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
3229 (xmlIsNameChar(ctxt, c) && (c != ':'))) { 3476 (xmlIsNameChar(ctxt, c) && (c != ':'))) {
3230 » if (count++ > 100) { 3477 » if (count++ > XML_PARSER_CHUNK_SIZE) {
3478 if ((len > XML_MAX_NAME_LENGTH) &&
3479 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3480 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3481 return(NULL);
3482 }
3231 count = 0; 3483 count = 0;
3232 GROW; 3484 GROW;
3233 if (ctxt->instate == XML_PARSER_EOF) 3485 if (ctxt->instate == XML_PARSER_EOF)
3234 return(NULL); 3486 return(NULL);
3235 } 3487 }
3236 len += l; 3488 len += l;
3237 NEXTL(l); 3489 NEXTL(l);
3490 end = ctxt->input->cur;
3238 c = CUR_CHAR(l); 3491 c = CUR_CHAR(l);
3492 if (c == 0) {
3493 count = 0;
3494 GROW;
3495 if (ctxt->instate == XML_PARSER_EOF)
3496 return(NULL);
3497 end = ctxt->input->cur;
3498 c = CUR_CHAR(l);
3499 }
3239 } 3500 }
3240 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); 3501 if ((len > XML_MAX_NAME_LENGTH) &&
3502 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3503 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3504 return(NULL);
3505 }
3506 return(xmlDictLookup(ctxt->dict, end - len, len));
3241 } 3507 }
3242 3508
3243 /** 3509 /**
3244 * xmlParseNCName: 3510 * xmlParseNCName:
3245 * @ctxt: an XML parser context 3511 * @ctxt: an XML parser context
3246 * @len: lenght of the string parsed 3512 * @len: length of the string parsed
3247 * 3513 *
3248 * parse an XML name. 3514 * parse an XML name.
3249 * 3515 *
3250 * [4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | 3516 * [4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
3251 * CombiningChar | Extender 3517 * CombiningChar | Extender
3252 * 3518 *
3253 * [5NS] NCName ::= (Letter | '_') (NCNameChar)* 3519 * [5NS] NCName ::= (Letter | '_') (NCNameChar)*
3254 * 3520 *
3255 * Returns the Name parsed or NULL 3521 * Returns the Name parsed or NULL
3256 */ 3522 */
(...skipping 17 matching lines...) Expand all
3274 (*in == '_')) { 3540 (*in == '_')) {
3275 in++; 3541 in++;
3276 while (((*in >= 0x61) && (*in <= 0x7A)) || 3542 while (((*in >= 0x61) && (*in <= 0x7A)) ||
3277 ((*in >= 0x41) && (*in <= 0x5A)) || 3543 ((*in >= 0x41) && (*in <= 0x5A)) ||
3278 ((*in >= 0x30) && (*in <= 0x39)) || 3544 ((*in >= 0x30) && (*in <= 0x39)) ||
3279 (*in == '_') || (*in == '-') || 3545 (*in == '_') || (*in == '-') ||
3280 (*in == '.')) 3546 (*in == '.'))
3281 in++; 3547 in++;
3282 if ((*in > 0) && (*in < 0x80)) { 3548 if ((*in > 0) && (*in < 0x80)) {
3283 count = in - ctxt->input->cur; 3549 count = in - ctxt->input->cur;
3550 if ((count > XML_MAX_NAME_LENGTH) &&
3551 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3552 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3553 return(NULL);
3554 }
3284 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count); 3555 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
3285 ctxt->input->cur = in; 3556 ctxt->input->cur = in;
3286 ctxt->nbChars += count; 3557 ctxt->nbChars += count;
3287 ctxt->input->col += count; 3558 ctxt->input->col += count;
3288 if (ret == NULL) { 3559 if (ret == NULL) {
3289 xmlErrMemory(ctxt, NULL); 3560 xmlErrMemory(ctxt, NULL);
3290 } 3561 }
3291 return(ret); 3562 return(ret);
3292 } 3563 }
3293 } 3564 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 * 3613 *
3343 * parse an XML name. 3614 * parse an XML name.
3344 * 3615 *
3345 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | 3616 * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' |
3346 * CombiningChar | Extender 3617 * CombiningChar | Extender
3347 * 3618 *
3348 * [5] Name ::= (Letter | '_' | ':') (NameChar)* 3619 * [5] Name ::= (Letter | '_' | ':') (NameChar)*
3349 * 3620 *
3350 * [6] Names ::= Name (#x20 Name)* 3621 * [6] Names ::= Name (#x20 Name)*
3351 * 3622 *
3352 * Returns the Name parsed or NULL. The @str pointer 3623 * Returns the Name parsed or NULL. The @str pointer
3353 * is updated to the current location in the string. 3624 * is updated to the current location in the string.
3354 */ 3625 */
3355 3626
3356 static xmlChar * 3627 static xmlChar *
3357 xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { 3628 xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) {
3358 xmlChar buf[XML_MAX_NAMELEN + 5]; 3629 xmlChar buf[XML_MAX_NAMELEN + 5];
3359 const xmlChar *cur = *str; 3630 const xmlChar *cur = *str;
3360 int len = 0, l; 3631 int len = 0, l;
3361 int c; 3632 int c;
3362 3633
(...skipping 23 matching lines...) Expand all
3386 3657
3387 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); 3658 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
3388 if (buffer == NULL) { 3659 if (buffer == NULL) {
3389 xmlErrMemory(ctxt, NULL); 3660 xmlErrMemory(ctxt, NULL);
3390 return(NULL); 3661 return(NULL);
3391 } 3662 }
3392 memcpy(buffer, buf, len); 3663 memcpy(buffer, buf, len);
3393 while (xmlIsNameChar(ctxt, c)) { 3664 while (xmlIsNameChar(ctxt, c)) {
3394 if (len + 10 > max) { 3665 if (len + 10 > max) {
3395 xmlChar *tmp; 3666 xmlChar *tmp;
3667
3668 if ((len > XML_MAX_NAME_LENGTH) &&
3669 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3670 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3671 xmlFree(buffer);
3672 return(NULL);
3673 }
3396 max *= 2; 3674 max *= 2;
3397 tmp = (xmlChar *) xmlRealloc(buffer, 3675 tmp = (xmlChar *) xmlRealloc(buffer,
3398 max * sizeof(xmlChar)); 3676 max * sizeof(xmlChar));
3399 if (tmp == NULL) { 3677 if (tmp == NULL) {
3400 xmlErrMemory(ctxt, NULL); 3678 xmlErrMemory(ctxt, NULL);
3401 xmlFree(buffer); 3679 xmlFree(buffer);
3402 return(NULL); 3680 return(NULL);
3403 } 3681 }
3404 buffer = tmp; 3682 buffer = tmp;
3405 } 3683 }
3406 COPY_BUF(l,buffer,len,c); 3684 COPY_BUF(l,buffer,len,c);
3407 cur += l; 3685 cur += l;
3408 c = CUR_SCHAR(cur, l); 3686 c = CUR_SCHAR(cur, l);
3409 } 3687 }
3410 buffer[len] = 0; 3688 buffer[len] = 0;
3411 *str = cur; 3689 *str = cur;
3412 return(buffer); 3690 return(buffer);
3413 } 3691 }
3414 } 3692 }
3693 if ((len > XML_MAX_NAME_LENGTH) &&
3694 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3695 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3696 return(NULL);
3697 }
3415 *str = cur; 3698 *str = cur;
3416 return(xmlStrndup(buf, len)); 3699 return(xmlStrndup(buf, len));
3417 } 3700 }
3418 3701
3419 /** 3702 /**
3420 * xmlParseNmtoken: 3703 * xmlParseNmtoken:
3421 * @ctxt: an XML parser context 3704 * @ctxt: an XML parser context
3422 * 3705 *
3423 * parse an XML Nmtoken. 3706 * parse an XML Nmtoken.
3424 * 3707 *
(...skipping 14 matching lines...) Expand all
3439 #ifdef DEBUG 3722 #ifdef DEBUG
3440 nbParseNmToken++; 3723 nbParseNmToken++;
3441 #endif 3724 #endif
3442 3725
3443 GROW; 3726 GROW;
3444 if (ctxt->instate == XML_PARSER_EOF) 3727 if (ctxt->instate == XML_PARSER_EOF)
3445 return(NULL); 3728 return(NULL);
3446 c = CUR_CHAR(l); 3729 c = CUR_CHAR(l);
3447 3730
3448 while (xmlIsNameChar(ctxt, c)) { 3731 while (xmlIsNameChar(ctxt, c)) {
3449 » if (count++ > 100) { 3732 » if (count++ > XML_PARSER_CHUNK_SIZE) {
3450 count = 0; 3733 count = 0;
3451 GROW; 3734 GROW;
3452 } 3735 }
3453 COPY_BUF(l,buf,len,c); 3736 COPY_BUF(l,buf,len,c);
3454 NEXTL(l); 3737 NEXTL(l);
3455 c = CUR_CHAR(l); 3738 c = CUR_CHAR(l);
3739 if (c == 0) {
3740 count = 0;
3741 GROW;
3742 if (ctxt->instate == XML_PARSER_EOF)
3743 return(NULL);
3744 c = CUR_CHAR(l);
3745 }
3456 if (len >= XML_MAX_NAMELEN) { 3746 if (len >= XML_MAX_NAMELEN) {
3457 /* 3747 /*
3458 * Okay someone managed to make a huge token, so he's ready to pay 3748 * Okay someone managed to make a huge token, so he's ready to pay
3459 * for the processing speed. 3749 * for the processing speed.
3460 */ 3750 */
3461 xmlChar *buffer; 3751 xmlChar *buffer;
3462 int max = len * 2; 3752 int max = len * 2;
3463 3753
3464 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); 3754 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
3465 if (buffer == NULL) { 3755 if (buffer == NULL) {
3466 xmlErrMemory(ctxt, NULL); 3756 xmlErrMemory(ctxt, NULL);
3467 return(NULL); 3757 return(NULL);
3468 } 3758 }
3469 memcpy(buffer, buf, len); 3759 memcpy(buffer, buf, len);
3470 while (xmlIsNameChar(ctxt, c)) { 3760 while (xmlIsNameChar(ctxt, c)) {
3471 » » if (count++ > 100) { 3761 » » if (count++ > XML_PARSER_CHUNK_SIZE) {
3472 count = 0; 3762 count = 0;
3473 GROW; 3763 GROW;
3474 if (ctxt->instate == XML_PARSER_EOF) { 3764 if (ctxt->instate == XML_PARSER_EOF) {
3475 xmlFree(buffer); 3765 xmlFree(buffer);
3476 return(NULL); 3766 return(NULL);
3477 } 3767 }
3478 } 3768 }
3479 if (len + 10 > max) { 3769 if (len + 10 > max) {
3480 xmlChar *tmp; 3770 xmlChar *tmp;
3481 3771
3772 if ((max > XML_MAX_NAME_LENGTH) &&
3773 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3774 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
3775 xmlFree(buffer);
3776 return(NULL);
3777 }
3482 max *= 2; 3778 max *= 2;
3483 tmp = (xmlChar *) xmlRealloc(buffer, 3779 tmp = (xmlChar *) xmlRealloc(buffer,
3484 max * sizeof(xmlChar)); 3780 max * sizeof(xmlChar));
3485 if (tmp == NULL) { 3781 if (tmp == NULL) {
3486 xmlErrMemory(ctxt, NULL); 3782 xmlErrMemory(ctxt, NULL);
3487 xmlFree(buffer); 3783 xmlFree(buffer);
3488 return(NULL); 3784 return(NULL);
3489 } 3785 }
3490 buffer = tmp; 3786 buffer = tmp;
3491 } 3787 }
3492 COPY_BUF(l,buffer,len,c); 3788 COPY_BUF(l,buffer,len,c);
3493 NEXTL(l); 3789 NEXTL(l);
3494 c = CUR_CHAR(l); 3790 c = CUR_CHAR(l);
3495 } 3791 }
3496 buffer[len] = 0; 3792 buffer[len] = 0;
3497 return(buffer); 3793 return(buffer);
3498 } 3794 }
3499 } 3795 }
3500 if (len == 0) 3796 if (len == 0)
3501 return(NULL); 3797 return(NULL);
3798 if ((len > XML_MAX_NAME_LENGTH) &&
3799 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
3800 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
3801 return(NULL);
3802 }
3502 return(xmlStrndup(buf, len)); 3803 return(xmlStrndup(buf, len));
3503 } 3804 }
3504 3805
3505 /** 3806 /**
3506 * xmlParseEntityValue: 3807 * xmlParseEntityValue:
3507 * @ctxt: an XML parser context 3808 * @ctxt: an XML parser context
3508 * @orig: if non-NULL store a copy of the original entity value 3809 * @orig: if non-NULL store a copy of the original entity value
3509 * 3810 *
3510 * parse a value for ENTITY declarations 3811 * parse a value for ENTITY declarations
3511 * 3812 *
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 xmlFree(buf); 3850 xmlFree(buf);
3550 return(NULL); 3851 return(NULL);
3551 } 3852 }
3552 NEXT; 3853 NEXT;
3553 c = CUR_CHAR(l); 3854 c = CUR_CHAR(l);
3554 /* 3855 /*
3555 * NOTE: 4.4.5 Included in Literal 3856 * NOTE: 4.4.5 Included in Literal
3556 * When a parameter entity reference appears in a literal entity 3857 * When a parameter entity reference appears in a literal entity
3557 * value, ... a single or double quote character in the replacement 3858 * value, ... a single or double quote character in the replacement
3558 * text is always treated as a normal data character and will not 3859 * text is always treated as a normal data character and will not
3559 * terminate the literal. 3860 * terminate the literal.
3560 * In practice it means we stop the loop only when back at parsing 3861 * In practice it means we stop the loop only when back at parsing
3561 * the initial entity and the quote is found 3862 * the initial entity and the quote is found
3562 */ 3863 */
3563 while (((IS_CHAR(c)) && ((c != stop) || /* checked */ 3864 while (((IS_CHAR(c)) && ((c != stop) || /* checked */
3564 (ctxt->input != input))) && (ctxt->instate != XML_PARSER_EOF)) { 3865 (ctxt->input != input))) && (ctxt->instate != XML_PARSER_EOF)) {
3565 if (len + 5 >= size) { 3866 if (len + 5 >= size) {
3566 xmlChar *tmp; 3867 xmlChar *tmp;
3567 3868
3568 size *= 2; 3869 size *= 2;
3569 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 3870 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3660 * of xmlParseAttValue() when the attribute parsing requires handling 3961 * of xmlParseAttValue() when the attribute parsing requires handling
3661 * of non-ASCII characters, or normalization compaction. 3962 * of non-ASCII characters, or normalization compaction.
3662 * 3963 *
3663 * Returns the AttValue parsed or NULL. The value has to be freed by the caller. 3964 * Returns the AttValue parsed or NULL. The value has to be freed by the caller.
3664 */ 3965 */
3665 static xmlChar * 3966 static xmlChar *
3666 xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { 3967 xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
3667 xmlChar limit = 0; 3968 xmlChar limit = 0;
3668 xmlChar *buf = NULL; 3969 xmlChar *buf = NULL;
3669 xmlChar *rep = NULL; 3970 xmlChar *rep = NULL;
3670 int len = 0; 3971 size_t len = 0;
3671 int buf_size = 0; 3972 size_t buf_size = 0;
3672 int c, l, in_space = 0; 3973 int c, l, in_space = 0;
3673 xmlChar *current = NULL; 3974 xmlChar *current = NULL;
3674 xmlEntityPtr ent; 3975 xmlEntityPtr ent;
3675 3976
3676 if (NXT(0) == '"') { 3977 if (NXT(0) == '"') {
3677 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; 3978 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE;
3678 limit = '"'; 3979 limit = '"';
3679 NEXT; 3980 NEXT;
3680 } else if (NXT(0) == '\'') { 3981 } else if (NXT(0) == '\'') {
3681 limit = '\''; 3982 limit = '\'';
3682 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; 3983 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE;
3683 NEXT; 3984 NEXT;
3684 } else { 3985 } else {
3685 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL); 3986 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL);
3686 return(NULL); 3987 return(NULL);
3687 } 3988 }
3688 3989
3689 /* 3990 /*
3690 * allocate a translation buffer. 3991 * allocate a translation buffer.
3691 */ 3992 */
3692 buf_size = XML_PARSER_BUFFER_SIZE; 3993 buf_size = XML_PARSER_BUFFER_SIZE;
3693 buf = (xmlChar *) xmlMallocAtomic(buf_size * sizeof(xmlChar)); 3994 buf = (xmlChar *) xmlMallocAtomic(buf_size);
3694 if (buf == NULL) goto mem_error; 3995 if (buf == NULL) goto mem_error;
3695 3996
3696 /* 3997 /*
3697 * OK loop until we reach one of the ending char or a size limit. 3998 * OK loop until we reach one of the ending char or a size limit.
3698 */ 3999 */
3699 c = CUR_CHAR(l); 4000 c = CUR_CHAR(l);
3700 while (((NXT(0) != limit) && /* checked */ 4001 while (((NXT(0) != limit) && /* checked */
3701 (IS_CHAR(c)) && (c != '<')) && 4002 (IS_CHAR(c)) && (c != '<')) &&
3702 (ctxt->instate != XML_PARSER_EOF)) { 4003 (ctxt->instate != XML_PARSER_EOF)) {
4004 /*
4005 * Impose a reasonable limit on attribute size, unless XML_PARSE_HUGE
4006 * special option is given
4007 */
4008 if ((len > XML_MAX_TEXT_LENGTH) &&
4009 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
4010 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
4011 "AttValue length too long\n");
4012 goto mem_error;
4013 }
3703 if (c == 0) break; 4014 if (c == 0) break;
3704 if (c == '&') { 4015 if (c == '&') {
3705 in_space = 0; 4016 in_space = 0;
3706 if (NXT(1) == '#') { 4017 if (NXT(1) == '#') {
3707 int val = xmlParseCharRef(ctxt); 4018 int val = xmlParseCharRef(ctxt);
3708 4019
3709 if (val == '&') { 4020 if (val == '&') {
3710 if (ctxt->replaceEntities) { 4021 if (ctxt->replaceEntities) {
3711 » » » if (len > buf_size - 10) { 4022 » » » if (len + 10 > buf_size) {
3712 growBuffer(buf, 10); 4023 growBuffer(buf, 10);
3713 } 4024 }
3714 buf[len++] = '&'; 4025 buf[len++] = '&';
3715 } else { 4026 } else {
3716 /* 4027 /*
3717 * The reparsing will be done in xmlStringGetNodeList() 4028 * The reparsing will be done in xmlStringGetNodeList()
3718 * called by the attribute() function in SAX.c 4029 * called by the attribute() function in SAX.c
3719 */ 4030 */
3720 » » » if (len > buf_size - 10) { 4031 » » » if (len + 10 > buf_size) {
3721 growBuffer(buf, 10); 4032 growBuffer(buf, 10);
3722 } 4033 }
3723 buf[len++] = '&'; 4034 buf[len++] = '&';
3724 buf[len++] = '#'; 4035 buf[len++] = '#';
3725 buf[len++] = '3'; 4036 buf[len++] = '3';
3726 buf[len++] = '8'; 4037 buf[len++] = '8';
3727 buf[len++] = ';'; 4038 buf[len++] = ';';
3728 } 4039 }
3729 } else if (val != 0) { 4040 } else if (val != 0) {
3730 » » if (len > buf_size - 10) { 4041 » » if (len + 10 > buf_size) {
3731 growBuffer(buf, 10); 4042 growBuffer(buf, 10);
3732 } 4043 }
3733 len += xmlCopyChar(0, &buf[len], val); 4044 len += xmlCopyChar(0, &buf[len], val);
3734 } 4045 }
3735 } else { 4046 } else {
3736 ent = xmlParseEntityRef(ctxt); 4047 ent = xmlParseEntityRef(ctxt);
3737 ctxt->nbentities++; 4048 ctxt->nbentities++;
3738 if (ent != NULL) 4049 if (ent != NULL)
3739 ctxt->nbentities += ent->owner; 4050 ctxt->nbentities += ent->owner;
3740 if ((ent != NULL) && 4051 if ((ent != NULL) &&
3741 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { 4052 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
3742 » » if (len > buf_size - 10) { 4053 » » if (len + 10 > buf_size) {
3743 growBuffer(buf, 10); 4054 growBuffer(buf, 10);
3744 } 4055 }
3745 if ((ctxt->replaceEntities == 0) && 4056 if ((ctxt->replaceEntities == 0) &&
3746 (ent->content[0] == '&')) { 4057 (ent->content[0] == '&')) {
3747 buf[len++] = '&'; 4058 buf[len++] = '&';
3748 buf[len++] = '#'; 4059 buf[len++] = '#';
3749 buf[len++] = '3'; 4060 buf[len++] = '3';
3750 buf[len++] = '8'; 4061 buf[len++] = '8';
3751 buf[len++] = ';'; 4062 buf[len++] = ';';
3752 } else { 4063 } else {
3753 buf[len++] = ent->content[0]; 4064 buf[len++] = ent->content[0];
3754 } 4065 }
3755 » » } else if ((ent != NULL) && 4066 » » } else if ((ent != NULL) &&
3756 (ctxt->replaceEntities != 0)) { 4067 (ctxt->replaceEntities != 0)) {
3757 if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) { 4068 if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) {
3758 rep = xmlStringDecodeEntities(ctxt, ent->content, 4069 rep = xmlStringDecodeEntities(ctxt, ent->content,
3759 XML_SUBSTITUTE_REF, 4070 XML_SUBSTITUTE_REF,
3760 0, 0, 0); 4071 0, 0, 0);
3761 if (rep != NULL) { 4072 if (rep != NULL) {
3762 current = rep; 4073 current = rep;
3763 while (*current != 0) { /* non input consuming */ 4074 while (*current != 0) { /* non input consuming */
3764 if ((*current == 0xD) || (*current == 0xA) || 4075 if ((*current == 0xD) || (*current == 0xA) ||
3765 (*current == 0x9)) { 4076 (*current == 0x9)) {
3766 buf[len++] = 0x20; 4077 buf[len++] = 0x20;
3767 current++; 4078 current++;
3768 } else 4079 } else
3769 buf[len++] = *current++; 4080 buf[len++] = *current++;
3770 » » » » if (len > buf_size - 10) { 4081 » » » » if (len + 10 > buf_size) {
3771 growBuffer(buf, 10); 4082 growBuffer(buf, 10);
3772 } 4083 }
3773 } 4084 }
3774 xmlFree(rep); 4085 xmlFree(rep);
3775 rep = NULL; 4086 rep = NULL;
3776 } 4087 }
3777 } else { 4088 } else {
3778 » » » if (len > buf_size - 10) { 4089 » » » if (len + 10 > buf_size) {
3779 growBuffer(buf, 10); 4090 growBuffer(buf, 10);
3780 } 4091 }
3781 if (ent->content != NULL) 4092 if (ent->content != NULL)
3782 buf[len++] = ent->content[0]; 4093 buf[len++] = ent->content[0];
3783 } 4094 }
3784 } else if (ent != NULL) { 4095 } else if (ent != NULL) {
3785 int i = xmlStrlen(ent->name); 4096 int i = xmlStrlen(ent->name);
3786 const xmlChar *cur = ent->name; 4097 const xmlChar *cur = ent->name;
3787 4098
3788 /* 4099 /*
3789 * This may look absurd but is needed to detect 4100 * This may look absurd but is needed to detect
3790 * entities problems 4101 * entities problems
3791 */ 4102 */
3792 if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) && 4103 if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
3793 » » » (ent->content != NULL)) { 4104 » » » (ent->content != NULL) && (ent->checked == 0)) {
4105 » » » unsigned long oldnbent = ctxt->nbentities;
4106
3794 rep = xmlStringDecodeEntities(ctxt, ent->content, 4107 rep = xmlStringDecodeEntities(ctxt, ent->content,
3795 XML_SUBSTITUTE_REF, 0, 0, 0); 4108 XML_SUBSTITUTE_REF, 0, 0, 0);
4109
4110 ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
3796 if (rep != NULL) { 4111 if (rep != NULL) {
4112 if (xmlStrchr(rep, '<'))
4113 ent->checked |= 1;
3797 xmlFree(rep); 4114 xmlFree(rep);
3798 rep = NULL; 4115 rep = NULL;
3799 } 4116 }
3800 } 4117 }
3801 4118
3802 /* 4119 /*
3803 * Just output the reference 4120 * Just output the reference
3804 */ 4121 */
3805 buf[len++] = '&'; 4122 buf[len++] = '&';
3806 » » while (len > buf_size - i - 10) { 4123 » » while (len + i + 10 > buf_size) {
3807 growBuffer(buf, i + 10); 4124 growBuffer(buf, i + 10);
3808 } 4125 }
3809 for (;i > 0;i--) 4126 for (;i > 0;i--)
3810 buf[len++] = *cur++; 4127 buf[len++] = *cur++;
3811 buf[len++] = ';'; 4128 buf[len++] = ';';
3812 } 4129 }
3813 } 4130 }
3814 } else { 4131 } else {
3815 if ((c == 0x20) || (c == 0xD) || (c == 0xA) || (c == 0x9)) { 4132 if ((c == 0x20) || (c == 0xD) || (c == 0xA) || (c == 0x9)) {
3816 if ((len != 0) || (!normalize)) { 4133 if ((len != 0) || (!normalize)) {
3817 if ((!normalize) || (!in_space)) { 4134 if ((!normalize) || (!in_space)) {
3818 COPY_BUF(l,buf,len,0x20); 4135 COPY_BUF(l,buf,len,0x20);
3819 » » » while (len > buf_size - 10) { 4136 » » » while (len + 10 > buf_size) {
3820 growBuffer(buf, 10); 4137 growBuffer(buf, 10);
3821 } 4138 }
3822 } 4139 }
3823 in_space = 1; 4140 in_space = 1;
3824 } 4141 }
3825 } else { 4142 } else {
3826 in_space = 0; 4143 in_space = 0;
3827 COPY_BUF(l,buf,len,c); 4144 COPY_BUF(l,buf,len,c);
3828 » » if (len > buf_size - 10) { 4145 » » if (len + 10 > buf_size) {
3829 growBuffer(buf, 10); 4146 growBuffer(buf, 10);
3830 } 4147 }
3831 } 4148 }
3832 NEXTL(l); 4149 NEXTL(l);
3833 } 4150 }
3834 GROW; 4151 GROW;
3835 c = CUR_CHAR(l); 4152 c = CUR_CHAR(l);
3836 } 4153 }
3837 if (ctxt->instate == XML_PARSER_EOF) 4154 if (ctxt->instate == XML_PARSER_EOF)
3838 goto error; 4155 goto error;
3839 4156
3840 if ((in_space) && (normalize)) { 4157 if ((in_space) && (normalize)) {
3841 while ((len > 0) && (buf[len - 1] == 0x20)) len--; 4158 while ((len > 0) && (buf[len - 1] == 0x20)) len--;
3842 } 4159 }
3843 buf[len] = 0; 4160 buf[len] = 0;
3844 if (RAW == '<') { 4161 if (RAW == '<') {
3845 xmlFatalErr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, NULL); 4162 xmlFatalErr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, NULL);
3846 } else if (RAW != limit) { 4163 } else if (RAW != limit) {
3847 if ((c != 0) && (!IS_CHAR(c))) { 4164 if ((c != 0) && (!IS_CHAR(c))) {
3848 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_CHAR, 4165 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_CHAR,
3849 "invalid character in attribute value\n"); 4166 "invalid character in attribute value\n");
3850 } else { 4167 } else {
3851 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, 4168 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
3852 "AttValue: ' expected\n"); 4169 "AttValue: ' expected\n");
3853 } 4170 }
3854 } else 4171 } else
3855 NEXT; 4172 NEXT;
3856 if (attlen != NULL) *attlen = len; 4173
4174 /*
4175 * There we potentially risk an overflow, don't allow attribute value of
4176 * length more than INT_MAX it is a very reasonnable assumption !
4177 */
4178 if (len >= INT_MAX) {
4179 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
4180 "AttValue length too long\n");
4181 goto mem_error;
4182 }
4183
4184 if (attlen != NULL) *attlen = (int) len;
3857 return(buf); 4185 return(buf);
3858 4186
3859 mem_error: 4187 mem_error:
3860 xmlErrMemory(ctxt, NULL); 4188 xmlErrMemory(ctxt, NULL);
3861 error: 4189 error:
3862 if (buf != NULL) 4190 if (buf != NULL)
3863 xmlFree(buf); 4191 xmlFree(buf);
3864 if (rep != NULL) 4192 if (rep != NULL)
3865 xmlFree(rep); 4193 xmlFree(rep);
3866 return(NULL); 4194 return(NULL);
3867 } 4195 }
3868 4196
3869 /** 4197 /**
3870 * xmlParseAttValue: 4198 * xmlParseAttValue:
3871 * @ctxt: an XML parser context 4199 * @ctxt: an XML parser context
3872 * 4200 *
3873 * parse a value for an attribute 4201 * parse a value for an attribute
3874 * Note: the parser won't do substitution of entities here, this 4202 * Note: the parser won't do substitution of entities here, this
3875 * will be handled later in xmlStringGetNodeList 4203 * will be handled later in xmlStringGetNodeList
3876 * 4204 *
3877 * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | 4205 * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' |
3878 * "'" ([^<&'] | Reference)* "'" 4206 * "'" ([^<&'] | Reference)* "'"
3879 * 4207 *
3880 * 3.3.3 Attribute-Value Normalization: 4208 * 3.3.3 Attribute-Value Normalization:
3881 * Before the value of an attribute is passed to the application or 4209 * Before the value of an attribute is passed to the application or
3882 * checked for validity, the XML processor must normalize it as follows: 4210 * checked for validity, the XML processor must normalize it as follows:
3883 * - a character reference is processed by appending the referenced 4211 * - a character reference is processed by appending the referenced
3884 * character to the attribute value 4212 * character to the attribute value
3885 * - an entity reference is processed by recursively processing the 4213 * - an entity reference is processed by recursively processing the
3886 * replacement text of the entity 4214 * replacement text of the entity
3887 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by 4215 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by
3888 * appending #x20 to the normalized value, except that only a single 4216 * appending #x20 to the normalized value, except that only a single
3889 * #x20 is appended for a "#xD#xA" sequence that is part of an external 4217 * #x20 is appended for a "#xD#xA" sequence that is part of an external
3890 * parsed entity or the literal entity value of an internal parsed entity 4218 * parsed entity or the literal entity value of an internal parsed entity
3891 * - other characters are processed by appending them to the normalized value 4219 * - other characters are processed by appending them to the normalized value
3892 * If the declared value is not CDATA, then the XML processor must further 4220 * If the declared value is not CDATA, then the XML processor must further
3893 * process the normalized attribute value by discarding any leading and 4221 * process the normalized attribute value by discarding any leading and
3894 * trailing space (#x20) characters, and by replacing sequences of space 4222 * trailing space (#x20) characters, and by replacing sequences of space
3895 * (#x20) characters by a single space (#x20) character. 4223 * (#x20) characters by a single space (#x20) character.
3896 * All attributes for which no declaration has been read should be treated 4224 * All attributes for which no declaration has been read should be treated
3897 * by a non-validating parser as if declared CDATA. 4225 * by a non-validating parser as if declared CDATA.
3898 * 4226 *
3899 * Returns the AttValue parsed or NULL. The value has to be freed by the caller. 4227 * Returns the AttValue parsed or NULL. The value has to be freed by the caller.
3900 */ 4228 */
3901 4229
3902 4230
3903 xmlChar * 4231 xmlChar *
3904 xmlParseAttValue(xmlParserCtxtPtr ctxt) { 4232 xmlParseAttValue(xmlParserCtxtPtr ctxt) {
3905 if ((ctxt == NULL) || (ctxt->input == NULL)) return(NULL); 4233 if ((ctxt == NULL) || (ctxt->input == NULL)) return(NULL);
3906 return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0)); 4234 return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0));
3907 } 4235 }
3908 4236
3909 /** 4237 /**
3910 * xmlParseSystemLiteral: 4238 * xmlParseSystemLiteral:
3911 * @ctxt: an XML parser context 4239 * @ctxt: an XML parser context
3912 * 4240 *
3913 * parse an XML Literal 4241 * parse an XML Literal
3914 * 4242 *
3915 * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") 4243 * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
3916 * 4244 *
3917 * Returns the SystemLiteral parsed or NULL 4245 * Returns the SystemLiteral parsed or NULL
3918 */ 4246 */
3919 4247
3920 xmlChar * 4248 xmlChar *
3921 xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { 4249 xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) {
3922 xmlChar *buf = NULL; 4250 xmlChar *buf = NULL;
3923 int len = 0; 4251 int len = 0;
3924 int size = XML_PARSER_BUFFER_SIZE; 4252 int size = XML_PARSER_BUFFER_SIZE;
3925 int cur, l; 4253 int cur, l;
3926 xmlChar stop; 4254 xmlChar stop;
3927 int state = ctxt->instate; 4255 int state = ctxt->instate;
3928 int count = 0; 4256 int count = 0;
3929 4257
3930 SHRINK; 4258 SHRINK;
3931 if (RAW == '"') { 4259 if (RAW == '"') {
3932 NEXT; 4260 NEXT;
3933 stop = '"'; 4261 stop = '"';
3934 } else if (RAW == '\'') { 4262 } else if (RAW == '\'') {
3935 NEXT; 4263 NEXT;
3936 stop = '\''; 4264 stop = '\'';
3937 } else { 4265 } else {
3938 xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL); 4266 xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL);
3939 return(NULL); 4267 return(NULL);
3940 } 4268 }
3941 4269
3942 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); 4270 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
3943 if (buf == NULL) { 4271 if (buf == NULL) {
3944 xmlErrMemory(ctxt, NULL); 4272 xmlErrMemory(ctxt, NULL);
3945 return(NULL); 4273 return(NULL);
3946 } 4274 }
3947 ctxt->instate = XML_PARSER_SYSTEM_LITERAL; 4275 ctxt->instate = XML_PARSER_SYSTEM_LITERAL;
3948 cur = CUR_CHAR(l); 4276 cur = CUR_CHAR(l);
3949 while ((IS_CHAR(cur)) && (cur != stop)) { /* checked */ 4277 while ((IS_CHAR(cur)) && (cur != stop)) { /* checked */
3950 if (len + 5 >= size) { 4278 if (len + 5 >= size) {
3951 xmlChar *tmp; 4279 xmlChar *tmp;
3952 4280
4281 if ((size > XML_MAX_NAME_LENGTH) &&
4282 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
4283 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "SystemLiteral");
4284 xmlFree(buf);
4285 ctxt->instate = (xmlParserInputState) state;
4286 return(NULL);
4287 }
3953 size *= 2; 4288 size *= 2;
3954 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 4289 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3955 if (tmp == NULL) { 4290 if (tmp == NULL) {
3956 xmlFree(buf); 4291 xmlFree(buf);
3957 xmlErrMemory(ctxt, NULL); 4292 xmlErrMemory(ctxt, NULL);
3958 ctxt->instate = (xmlParserInputState) state; 4293 ctxt->instate = (xmlParserInputState) state;
3959 return(NULL); 4294 return(NULL);
3960 } 4295 }
3961 buf = tmp; 4296 buf = tmp;
3962 } 4297 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4024 if (buf == NULL) { 4359 if (buf == NULL) {
4025 xmlErrMemory(ctxt, NULL); 4360 xmlErrMemory(ctxt, NULL);
4026 return(NULL); 4361 return(NULL);
4027 } 4362 }
4028 ctxt->instate = XML_PARSER_PUBLIC_LITERAL; 4363 ctxt->instate = XML_PARSER_PUBLIC_LITERAL;
4029 cur = CUR; 4364 cur = CUR;
4030 while ((IS_PUBIDCHAR_CH(cur)) && (cur != stop)) { /* checked */ 4365 while ((IS_PUBIDCHAR_CH(cur)) && (cur != stop)) { /* checked */
4031 if (len + 1 >= size) { 4366 if (len + 1 >= size) {
4032 xmlChar *tmp; 4367 xmlChar *tmp;
4033 4368
4369 if ((size > XML_MAX_NAME_LENGTH) &&
4370 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
4371 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Public ID");
4372 xmlFree(buf);
4373 return(NULL);
4374 }
4034 size *= 2; 4375 size *= 2;
4035 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 4376 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
4036 if (tmp == NULL) { 4377 if (tmp == NULL) {
4037 xmlErrMemory(ctxt, NULL); 4378 xmlErrMemory(ctxt, NULL);
4038 xmlFree(buf); 4379 xmlFree(buf);
4039 return(NULL); 4380 return(NULL);
4040 } 4381 }
4041 buf = tmp; 4382 buf = tmp;
4042 } 4383 }
4043 buf[len++] = cur; 4384 buf[len++] = cur;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4112 * xmlParseCharData: 4453 * xmlParseCharData:
4113 * @ctxt: an XML parser context 4454 * @ctxt: an XML parser context
4114 * @cdata: int indicating whether we are within a CDATA section 4455 * @cdata: int indicating whether we are within a CDATA section
4115 * 4456 *
4116 * parse a CharData section. 4457 * parse a CharData section.
4117 * if we are within a CDATA section ']]>' marks an end of section. 4458 * if we are within a CDATA section ']]>' marks an end of section.
4118 * 4459 *
4119 * The right angle bracket (>) may be represented using the string "&gt;", 4460 * The right angle bracket (>) may be represented using the string "&gt;",
4120 * and must, for compatibility, be escaped using "&gt;" or a character 4461 * and must, for compatibility, be escaped using "&gt;" or a character
4121 * reference when it appears in the string "]]>" in content, when that 4462 * reference when it appears in the string "]]>" in content, when that
4122 * string is not marking the end of a CDATA section. 4463 * string is not marking the end of a CDATA section.
4123 * 4464 *
4124 * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) 4465 * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
4125 */ 4466 */
4126 4467
4127 void 4468 void
4128 xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { 4469 xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) {
4129 const xmlChar *in; 4470 const xmlChar *in;
4130 int nbchar = 0; 4471 int nbchar = 0;
4131 int line = ctxt->input->line; 4472 int line = ctxt->input->line;
4132 int col = ctxt->input->col; 4473 int col = ctxt->input->col;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { 4620 xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) {
4280 xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5]; 4621 xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5];
4281 int nbchar = 0; 4622 int nbchar = 0;
4282 int cur, l; 4623 int cur, l;
4283 int count = 0; 4624 int count = 0;
4284 4625
4285 SHRINK; 4626 SHRINK;
4286 GROW; 4627 GROW;
4287 cur = CUR_CHAR(l); 4628 cur = CUR_CHAR(l);
4288 while ((cur != '<') && /* checked */ 4629 while ((cur != '<') && /* checked */
4289 (cur != '&') && 4630 (cur != '&') &&
4290 (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ { 4631 (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ {
4291 if ((cur == ']') && (NXT(1) == ']') && 4632 if ((cur == ']') && (NXT(1) == ']') &&
4292 (NXT(2) == '>')) { 4633 (NXT(2) == '>')) {
4293 if (cdata) break; 4634 if (cdata) break;
4294 else { 4635 else {
4295 xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL); 4636 xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
4296 } 4637 }
4297 } 4638 }
4298 COPY_BUF(l,buf,nbchar,cur); 4639 COPY_BUF(l,buf,nbchar,cur);
4299 if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) { 4640 if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4412 if (strict) { 4753 if (strict) {
4413 /* 4754 /*
4414 * We don't handle [83] so "S SystemLiteral" is required. 4755 * We don't handle [83] so "S SystemLiteral" is required.
4415 */ 4756 */
4416 if (!IS_BLANK_CH(CUR)) { 4757 if (!IS_BLANK_CH(CUR)) {
4417 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 4758 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
4418 "Space required after the Public Identifier\n"); 4759 "Space required after the Public Identifier\n");
4419 } 4760 }
4420 } else { 4761 } else {
4421 /* 4762 /*
4422 » * We handle [83] so we return immediately, if 4763 » * We handle [83] so we return immediately, if
4423 * "S SystemLiteral" is not detected. From a purely parsing 4764 * "S SystemLiteral" is not detected. From a purely parsing
4424 * point of view that's a nice mess. 4765 * point of view that's a nice mess.
4425 */ 4766 */
4426 const xmlChar *ptr; 4767 const xmlChar *ptr;
4427 GROW; 4768 GROW;
4428 4769
4429 ptr = CUR_PTR; 4770 ptr = CUR_PTR;
4430 if (!IS_BLANK_CH(*ptr)) return(NULL); 4771 if (!IS_BLANK_CH(*ptr)) return(NULL);
4431 » 4772
4432 while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */ 4773 while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */
4433 if ((*ptr != '\'') && (*ptr != '"')) return(NULL); 4774 if ((*ptr != '\'') && (*ptr != '"')) return(NULL);
4434 } 4775 }
4435 SKIP_BLANKS; 4776 SKIP_BLANKS;
4436 URI = xmlParseSystemLiteral(ctxt); 4777 URI = xmlParseSystemLiteral(ctxt);
4437 if (URI == NULL) { 4778 if (URI == NULL) {
4438 xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL); 4779 xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL);
4439 } 4780 }
4440 } 4781 }
4441 return(URI); 4782 return(URI);
4442 } 4783 }
4443 4784
4444 /** 4785 /**
4445 * xmlParseCommentComplex: 4786 * xmlParseCommentComplex:
4446 * @ctxt: an XML parser context 4787 * @ctxt: an XML parser context
4447 * @buf: the already parsed part of the buffer 4788 * @buf: the already parsed part of the buffer
4448 * @len: number of bytes filles in the buffer 4789 * @len: number of bytes filles in the buffer
4449 * @size: allocated size of the buffer 4790 * @size: allocated size of the buffer
4450 * 4791 *
4451 * Skip an XML (SGML) comment <!-- .... --> 4792 * Skip an XML (SGML) comment <!-- .... -->
4452 * The spec says that "For compatibility, the string "--" (double-hyphen) 4793 * The spec says that "For compatibility, the string "--" (double-hyphen)
4453 * must not occur within comments. " 4794 * must not occur within comments. "
4454 * This is the slow routine in case the accelerator for ascii didn't work 4795 * This is the slow routine in case the accelerator for ascii didn't work
4455 * 4796 *
4456 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' 4797 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
4457 */ 4798 */
4458 static void 4799 static void
4459 xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) { 4800 xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf,
4801 size_t len, size_t size) {
4460 int q, ql; 4802 int q, ql;
4461 int r, rl; 4803 int r, rl;
4462 int cur, l; 4804 int cur, l;
4463 int count = 0; 4805 size_t count = 0;
4464 int inputid; 4806 int inputid;
4465 4807
4466 inputid = ctxt->input->id; 4808 inputid = ctxt->input->id;
4467 4809
4468 if (buf == NULL) { 4810 if (buf == NULL) {
4469 len = 0; 4811 len = 0;
4470 size = XML_PARSER_BUFFER_SIZE; 4812 size = XML_PARSER_BUFFER_SIZE;
4471 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); 4813 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
4472 if (buf == NULL) { 4814 if (buf == NULL) {
4473 xmlErrMemory(ctxt, NULL); 4815 xmlErrMemory(ctxt, NULL);
(...skipping 25 matching lines...) Expand all
4499 NEXTL(rl); 4841 NEXTL(rl);
4500 cur = CUR_CHAR(l); 4842 cur = CUR_CHAR(l);
4501 if (cur == 0) 4843 if (cur == 0)
4502 goto not_terminated; 4844 goto not_terminated;
4503 while (IS_CHAR(cur) && /* checked */ 4845 while (IS_CHAR(cur) && /* checked */
4504 ((cur != '>') || 4846 ((cur != '>') ||
4505 (r != '-') || (q != '-'))) { 4847 (r != '-') || (q != '-'))) {
4506 if ((r == '-') && (q == '-')) { 4848 if ((r == '-') && (q == '-')) {
4507 xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL); 4849 xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL);
4508 } 4850 }
4851 if ((len > XML_MAX_TEXT_LENGTH) &&
4852 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
4853 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
4854 "Comment too big found", NULL);
4855 xmlFree (buf);
4856 return;
4857 }
4509 if (len + 5 >= size) { 4858 if (len + 5 >= size) {
4510 xmlChar *new_buf; 4859 xmlChar *new_buf;
4511 » size *= 2; 4860 size_t new_size;
4512 » new_buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 4861
4862 » new_size = size * 2;
4863 » new_buf = (xmlChar *) xmlRealloc(buf, new_size);
4513 if (new_buf == NULL) { 4864 if (new_buf == NULL) {
4514 xmlFree (buf); 4865 xmlFree (buf);
4515 xmlErrMemory(ctxt, NULL); 4866 xmlErrMemory(ctxt, NULL);
4516 return; 4867 return;
4517 } 4868 }
4518 buf = new_buf; 4869 buf = new_buf;
4870 size = new_size;
4519 } 4871 }
4520 COPY_BUF(ql,buf,len,q); 4872 COPY_BUF(ql,buf,len,q);
4521 q = r; 4873 q = r;
4522 ql = rl; 4874 ql = rl;
4523 r = cur; 4875 r = cur;
4524 rl = l; 4876 rl = l;
4525 4877
4526 count++; 4878 count++;
4527 if (count > 50) { 4879 if (count > 50) {
4528 GROW; 4880 GROW;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 * 4925 *
4574 * Skip an XML (SGML) comment <!-- .... --> 4926 * Skip an XML (SGML) comment <!-- .... -->
4575 * The spec says that "For compatibility, the string "--" (double-hyphen) 4927 * The spec says that "For compatibility, the string "--" (double-hyphen)
4576 * must not occur within comments. " 4928 * must not occur within comments. "
4577 * 4929 *
4578 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' 4930 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
4579 */ 4931 */
4580 void 4932 void
4581 xmlParseComment(xmlParserCtxtPtr ctxt) { 4933 xmlParseComment(xmlParserCtxtPtr ctxt) {
4582 xmlChar *buf = NULL; 4934 xmlChar *buf = NULL;
4583 int size = XML_PARSER_BUFFER_SIZE; 4935 size_t size = XML_PARSER_BUFFER_SIZE;
4584 int len = 0; 4936 size_t len = 0;
4585 xmlParserInputState state; 4937 xmlParserInputState state;
4586 const xmlChar *in; 4938 const xmlChar *in;
4587 int nbchar = 0, ccol; 4939 size_t nbchar = 0;
4940 int ccol;
4588 int inputid; 4941 int inputid;
4589 4942
4590 /* 4943 /*
4591 * Check that there is a comment right here. 4944 * Check that there is a comment right here.
4592 */ 4945 */
4593 if ((RAW != '<') || (NXT(1) != '!') || 4946 if ((RAW != '<') || (NXT(1) != '!') ||
4594 (NXT(2) != '-') || (NXT(3) != '-')) return; 4947 (NXT(2) != '-') || (NXT(3) != '-')) return;
4595 state = ctxt->instate; 4948 state = ctxt->instate;
4596 ctxt->instate = XML_PARSER_COMMENT; 4949 ctxt->instate = XML_PARSER_COMMENT;
4597 inputid = ctxt->input->id; 4950 inputid = ctxt->input->id;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 ctxt->instate = state; 5010 ctxt->instate = state;
4658 return; 5011 return;
4659 } 5012 }
4660 buf = new_buf; 5013 buf = new_buf;
4661 } 5014 }
4662 memcpy(&buf[len], ctxt->input->cur, nbchar); 5015 memcpy(&buf[len], ctxt->input->cur, nbchar);
4663 len += nbchar; 5016 len += nbchar;
4664 buf[len] = 0; 5017 buf[len] = 0;
4665 } 5018 }
4666 } 5019 }
5020 if ((len > XML_MAX_TEXT_LENGTH) &&
5021 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
5022 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
5023 "Comment too big found", NULL);
5024 xmlFree (buf);
5025 return;
5026 }
4667 ctxt->input->cur = in; 5027 ctxt->input->cur = in;
4668 if (*in == 0xA) { 5028 if (*in == 0xA) {
4669 in++; 5029 in++;
4670 ctxt->input->line++; ctxt->input->col = 1; 5030 ctxt->input->line++; ctxt->input->col = 1;
4671 } 5031 }
4672 if (*in == 0xD) { 5032 if (*in == 0xD) {
4673 in++; 5033 in++;
4674 if (*in == 0xA) { 5034 if (*in == 0xA) {
4675 ctxt->input->cur = in; 5035 ctxt->input->cur = in;
4676 in++; 5036 in++;
4677 ctxt->input->line++; ctxt->input->col = 1; 5037 ctxt->input->line++; ctxt->input->col = 1;
4678 continue; /* while */ 5038 continue; /* while */
4679 } 5039 }
4680 in--; 5040 in--;
4681 } 5041 }
4682 SHRINK; 5042 SHRINK;
4683 GROW; 5043 GROW;
4684 if (ctxt->instate == XML_PARSER_EOF) { 5044 if (ctxt->instate == XML_PARSER_EOF) {
4685 xmlFree(buf); 5045 xmlFree(buf);
4686 return; 5046 return;
4687 » } 5047 }
4688 in = ctxt->input->cur; 5048 in = ctxt->input->cur;
4689 if (*in == '-') { 5049 if (*in == '-') {
4690 if (in[1] == '-') { 5050 if (in[1] == '-') {
4691 if (in[2] == '>') { 5051 if (in[2] == '>') {
4692 if (ctxt->input->id != inputid) { 5052 if (ctxt->input->id != inputid) {
4693 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, 5053 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
4694 "comment doesn't start and stop in the same entity\n"); 5054 "comment doesn't start and stop in the same entity\n");
4695 } 5055 }
4696 SKIP(3); 5056 SKIP(3);
4697 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && 5057 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
4698 (!ctxt->disableSAX)) { 5058 (!ctxt->disableSAX)) {
4699 if (buf != NULL) 5059 if (buf != NULL)
4700 ctxt->sax->comment(ctxt->userData, buf); 5060 ctxt->sax->comment(ctxt->userData, buf);
4701 else 5061 else
4702 ctxt->sax->comment(ctxt->userData, BAD_CAST ""); 5062 ctxt->sax->comment(ctxt->userData, BAD_CAST "");
4703 } 5063 }
4704 if (buf != NULL) 5064 if (buf != NULL)
4705 xmlFree(buf); 5065 xmlFree(buf);
4706 if (ctxt->instate != XML_PARSER_EOF) 5066 if (ctxt->instate != XML_PARSER_EOF)
4707 ctxt->instate = state; 5067 ctxt->instate = state;
4708 return; 5068 return;
4709 } 5069 }
4710 » » if (buf != NULL) 5070 » » if (buf != NULL) {
4711 » » xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, 5071 » » xmlFatalErrMsgStr(ctxt, XML_ERR_HYPHEN_IN_COMMENT,
4712 » » "Comment not terminated \n<!--%.50s\n", 5072 » » "Double hyphen within comment: "
5073 "<!--%.50s\n",
4713 buf); 5074 buf);
4714 » » else 5075 » » } else
4715 » » xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, 5076 » » xmlFatalErrMsgStr(ctxt, XML_ERR_HYPHEN_IN_COMMENT,
4716 » » "Comment not terminated \n", NULL); 5077 » » "Double hyphen within comment\n", NULL);
4717 in++; 5078 in++;
4718 ctxt->input->col++; 5079 ctxt->input->col++;
4719 } 5080 }
4720 in++; 5081 in++;
4721 ctxt->input->col++; 5082 ctxt->input->col++;
4722 goto get_more; 5083 goto get_more;
4723 } 5084 }
4724 } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09)); 5085 } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09));
4725 xmlParseCommentComplex(ctxt, buf, len, size); 5086 xmlParseCommentComplex(ctxt, buf, len, size);
4726 ctxt->instate = state; 5087 ctxt->instate = state;
4727 return; 5088 return;
4728 } 5089 }
4729 5090
4730 5091
4731 /** 5092 /**
4732 * xmlParsePITarget: 5093 * xmlParsePITarget:
4733 * @ctxt: an XML parser context 5094 * @ctxt: an XML parser context
4734 * 5095 *
4735 * parse the name of a PI 5096 * parse the name of a PI
4736 * 5097 *
4737 * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) 5098 * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
4738 * 5099 *
4739 * Returns the PITarget name or NULL 5100 * Returns the PITarget name or NULL
4740 */ 5101 */
4741 5102
4742 const xmlChar * 5103 const xmlChar *
4743 xmlParsePITarget(xmlParserCtxtPtr ctxt) { 5104 xmlParsePITarget(xmlParserCtxtPtr ctxt) {
4744 const xmlChar *name; 5105 const xmlChar *name;
(...skipping 16 matching lines...) Expand all
4761 for (i = 0;;i++) { 5122 for (i = 0;;i++) {
4762 if (xmlW3CPIs[i] == NULL) break; 5123 if (xmlW3CPIs[i] == NULL) break;
4763 if (xmlStrEqual(name, (const xmlChar *)xmlW3CPIs[i])) 5124 if (xmlStrEqual(name, (const xmlChar *)xmlW3CPIs[i]))
4764 return(name); 5125 return(name);
4765 } 5126 }
4766 xmlWarningMsg(ctxt, XML_ERR_RESERVED_XML_NAME, 5127 xmlWarningMsg(ctxt, XML_ERR_RESERVED_XML_NAME,
4767 "xmlParsePITarget: invalid name prefix 'xml'\n", 5128 "xmlParsePITarget: invalid name prefix 'xml'\n",
4768 NULL, NULL); 5129 NULL, NULL);
4769 } 5130 }
4770 if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) { 5131 if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) {
4771 » xmlNsErr(ctxt, XML_NS_ERR_COLON, 5132 » xmlNsErr(ctxt, XML_NS_ERR_COLON,
4772 » » "colon are forbidden from PI names '%s'\n", name, NULL, NULL); 5133 » » "colons are forbidden from PI names '%s'\n", name, NULL, NULL);
4773 } 5134 }
4774 return(name); 5135 return(name);
4775 } 5136 }
4776 5137
4777 #ifdef LIBXML_CATALOG_ENABLED 5138 #ifdef LIBXML_CATALOG_ENABLED
4778 /** 5139 /**
4779 * xmlParseCatalogPI: 5140 * xmlParseCatalogPI:
4780 * @ctxt: an XML parser context 5141 * @ctxt: an XML parser context
4781 * @catalog: the PI value string 5142 * @catalog: the PI value string
4782 * 5143 *
4783 * parse an XML Catalog Processing Instruction. 5144 * parse an XML Catalog Processing Instruction.
4784 * 5145 *
4785 * <?oasis-xml-catalog catalog="http://example.com/catalog.xml"?> 5146 * <?oasis-xml-catalog catalog="http://example.com/catalog.xml"?>
4786 * 5147 *
4787 * Occurs only if allowed by the user and if happening in the Misc 5148 * Occurs only if allowed by the user and if happening in the Misc
4788 * part of the document before any doctype informations 5149 * part of the document before any doctype informations
4789 * This will add the given catalog to the parsing context in order 5150 * This will add the given catalog to the parsing context in order
4790 * to be used if there is a resolution need further down in the document 5151 * to be used if there is a resolution need further down in the document
4791 */ 5152 */
4792 5153
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4832 "Catalog PI syntax error: %s\n", 5193 "Catalog PI syntax error: %s\n",
4833 catalog, NULL); 5194 catalog, NULL);
4834 if (URL != NULL) 5195 if (URL != NULL)
4835 xmlFree(URL); 5196 xmlFree(URL);
4836 } 5197 }
4837 #endif 5198 #endif
4838 5199
4839 /** 5200 /**
4840 * xmlParsePI: 5201 * xmlParsePI:
4841 * @ctxt: an XML parser context 5202 * @ctxt: an XML parser context
4842 * 5203 *
4843 * parse an XML Processing Instruction. 5204 * parse an XML Processing Instruction.
4844 * 5205 *
4845 * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' 5206 * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
4846 * 5207 *
4847 * The processing is transfered to SAX once parsed. 5208 * The processing is transfered to SAX once parsed.
4848 */ 5209 */
4849 5210
4850 void 5211 void
4851 xmlParsePI(xmlParserCtxtPtr ctxt) { 5212 xmlParsePI(xmlParserCtxtPtr ctxt) {
4852 xmlChar *buf = NULL; 5213 xmlChar *buf = NULL;
4853 int len = 0; 5214 size_t len = 0;
4854 int size = XML_PARSER_BUFFER_SIZE; 5215 size_t size = XML_PARSER_BUFFER_SIZE;
4855 int cur, l; 5216 int cur, l;
4856 const xmlChar *target; 5217 const xmlChar *target;
4857 xmlParserInputState state; 5218 xmlParserInputState state;
4858 int count = 0; 5219 int count = 0;
4859 5220
4860 if ((RAW == '<') && (NXT(1) == '?')) { 5221 if ((RAW == '<') && (NXT(1) == '?')) {
4861 xmlParserInputPtr input = ctxt->input; 5222 xmlParserInputPtr input = ctxt->input;
4862 state = ctxt->instate; 5223 state = ctxt->instate;
4863 ctxt->instate = XML_PARSER_PI; 5224 ctxt->instate = XML_PARSER_PI;
4864 /* 5225 /*
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 if (!IS_BLANK(cur)) { 5262 if (!IS_BLANK(cur)) {
4902 xmlFatalErrMsgStr(ctxt, XML_ERR_SPACE_REQUIRED, 5263 xmlFatalErrMsgStr(ctxt, XML_ERR_SPACE_REQUIRED,
4903 "ParsePI: PI %s space expected\n", target); 5264 "ParsePI: PI %s space expected\n", target);
4904 } 5265 }
4905 SKIP_BLANKS; 5266 SKIP_BLANKS;
4906 cur = CUR_CHAR(l); 5267 cur = CUR_CHAR(l);
4907 while (IS_CHAR(cur) && /* checked */ 5268 while (IS_CHAR(cur) && /* checked */
4908 ((cur != '?') || (NXT(1) != '>'))) { 5269 ((cur != '?') || (NXT(1) != '>'))) {
4909 if (len + 5 >= size) { 5270 if (len + 5 >= size) {
4910 xmlChar *tmp; 5271 xmlChar *tmp;
4911 5272 size_t new_size = size * 2;
4912 » » size *= 2; 5273 » » tmp = (xmlChar *) xmlRealloc(buf, new_size);
4913 » » tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
4914 if (tmp == NULL) { 5274 if (tmp == NULL) {
4915 xmlErrMemory(ctxt, NULL); 5275 xmlErrMemory(ctxt, NULL);
4916 xmlFree(buf); 5276 xmlFree(buf);
4917 ctxt->instate = state; 5277 ctxt->instate = state;
4918 return; 5278 return;
4919 } 5279 }
4920 buf = tmp; 5280 buf = tmp;
5281 size = new_size;
4921 } 5282 }
4922 count++; 5283 count++;
4923 if (count > 50) { 5284 if (count > 50) {
4924 GROW; 5285 GROW;
4925 if (ctxt->instate == XML_PARSER_EOF) { 5286 if (ctxt->instate == XML_PARSER_EOF) {
4926 xmlFree(buf); 5287 xmlFree(buf);
4927 return; 5288 return;
4928 } 5289 }
4929 count = 0; 5290 count = 0;
5291 if ((len > XML_MAX_TEXT_LENGTH) &&
5292 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
5293 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
5294 "PI %s too big found", target);
5295 xmlFree(buf);
5296 ctxt->instate = state;
5297 return;
5298 }
4930 } 5299 }
4931 COPY_BUF(l,buf,len,cur); 5300 COPY_BUF(l,buf,len,cur);
4932 NEXTL(l); 5301 NEXTL(l);
4933 cur = CUR_CHAR(l); 5302 cur = CUR_CHAR(l);
4934 if (cur == 0) { 5303 if (cur == 0) {
4935 SHRINK; 5304 SHRINK;
4936 GROW; 5305 GROW;
4937 cur = CUR_CHAR(l); 5306 cur = CUR_CHAR(l);
4938 } 5307 }
4939 } 5308 }
5309 if ((len > XML_MAX_TEXT_LENGTH) &&
5310 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
5311 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
5312 "PI %s too big found", target);
5313 xmlFree(buf);
5314 ctxt->instate = state;
5315 return;
5316 }
4940 buf[len] = 0; 5317 buf[len] = 0;
4941 if (cur != '?') { 5318 if (cur != '?') {
4942 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, 5319 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
4943 "ParsePI: PI %s never end ...\n", target); 5320 "ParsePI: PI %s never end ...\n", target);
4944 } else { 5321 } else {
4945 if (input != ctxt->input) { 5322 if (input != ctxt->input) {
4946 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5323 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
4947 "PI declaration doesn't start and stop in the same entity\n"); 5324 "PI declaration doesn't start and stop in the same entity\n");
4948 } 5325 }
4949 SKIP(2); 5326 SKIP(2);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4991 * and 'SYSTEM' S SystemLiteral 5368 * and 'SYSTEM' S SystemLiteral
4992 * 5369 *
4993 * See the NOTE on xmlParseExternalID(). 5370 * See the NOTE on xmlParseExternalID().
4994 */ 5371 */
4995 5372
4996 void 5373 void
4997 xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { 5374 xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
4998 const xmlChar *name; 5375 const xmlChar *name;
4999 xmlChar *Pubid; 5376 xmlChar *Pubid;
5000 xmlChar *Systemid; 5377 xmlChar *Systemid;
5001 5378
5002 if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) { 5379 if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) {
5003 xmlParserInputPtr input = ctxt->input; 5380 xmlParserInputPtr input = ctxt->input;
5004 SHRINK; 5381 SHRINK;
5005 SKIP(10); 5382 SKIP(10);
5006 if (!IS_BLANK_CH(CUR)) { 5383 if (!IS_BLANK_CH(CUR)) {
5007 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5384 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5008 "Space required after '<!NOTATION'\n"); 5385 "Space required after '<!NOTATION'\n");
5009 return; 5386 return;
5010 } 5387 }
5011 SKIP_BLANKS; 5388 SKIP_BLANKS;
5012 5389
5013 name = xmlParseName(ctxt); 5390 name = xmlParseName(ctxt);
5014 if (name == NULL) { 5391 if (name == NULL) {
5015 xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_STARTED, NULL); 5392 xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_STARTED, NULL);
5016 return; 5393 return;
5017 } 5394 }
5018 if (!IS_BLANK_CH(CUR)) { 5395 if (!IS_BLANK_CH(CUR)) {
5019 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5396 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5020 "Space required after the NOTATION name'\n"); 5397 "Space required after the NOTATION name'\n");
5021 return; 5398 return;
5022 } 5399 }
5023 if (xmlStrchr(name, ':') != NULL) { 5400 if (xmlStrchr(name, ':') != NULL) {
5024 » xmlNsErr(ctxt, XML_NS_ERR_COLON, 5401 » xmlNsErr(ctxt, XML_NS_ERR_COLON,
5025 » » "colon are forbidden from notation names '%s'\n", 5402 » » "colons are forbidden from notation names '%s'\n",
5026 name, NULL, NULL); 5403 name, NULL, NULL);
5027 } 5404 }
5028 SKIP_BLANKS; 5405 SKIP_BLANKS;
5029 5406
5030 /* 5407 /*
5031 * Parse the IDs. 5408 * Parse the IDs.
5032 */ 5409 */
5033 Systemid = xmlParseExternalID(ctxt, &Pubid, 0); 5410 Systemid = xmlParseExternalID(ctxt, &Pubid, 0);
5034 SKIP_BLANKS; 5411 SKIP_BLANKS;
5035 5412
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5074 5451
5075 void 5452 void
5076 xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { 5453 xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
5077 const xmlChar *name = NULL; 5454 const xmlChar *name = NULL;
5078 xmlChar *value = NULL; 5455 xmlChar *value = NULL;
5079 xmlChar *URI = NULL, *literal = NULL; 5456 xmlChar *URI = NULL, *literal = NULL;
5080 const xmlChar *ndata = NULL; 5457 const xmlChar *ndata = NULL;
5081 int isParameter = 0; 5458 int isParameter = 0;
5082 xmlChar *orig = NULL; 5459 xmlChar *orig = NULL;
5083 int skipped; 5460 int skipped;
5084 5461
5085 /* GROW; done in the caller */ 5462 /* GROW; done in the caller */
5086 if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) { 5463 if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) {
5087 xmlParserInputPtr input = ctxt->input; 5464 xmlParserInputPtr input = ctxt->input;
5088 SHRINK; 5465 SHRINK;
5089 SKIP(8); 5466 SKIP(8);
5090 skipped = SKIP_BLANKS; 5467 skipped = SKIP_BLANKS;
5091 if (skipped == 0) { 5468 if (skipped == 0) {
5092 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5469 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5093 "Space required after '<!ENTITY'\n"); 5470 "Space required after '<!ENTITY'\n");
5094 } 5471 }
5095 5472
5096 if (RAW == '%') { 5473 if (RAW == '%') {
5097 NEXT; 5474 NEXT;
5098 skipped = SKIP_BLANKS; 5475 skipped = SKIP_BLANKS;
5099 if (skipped == 0) { 5476 if (skipped == 0) {
5100 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5477 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5101 "Space required after '%'\n"); 5478 "Space required after '%'\n");
5102 } 5479 }
5103 isParameter = 1; 5480 isParameter = 1;
5104 } 5481 }
5105 5482
5106 name = xmlParseName(ctxt); 5483 name = xmlParseName(ctxt);
5107 if (name == NULL) { 5484 if (name == NULL) {
5108 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED, 5485 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
5109 "xmlParseEntityDecl: no name\n"); 5486 "xmlParseEntityDecl: no name\n");
5110 return; 5487 return;
5111 } 5488 }
5112 if (xmlStrchr(name, ':') != NULL) { 5489 if (xmlStrchr(name, ':') != NULL) {
5113 » xmlNsErr(ctxt, XML_NS_ERR_COLON, 5490 » xmlNsErr(ctxt, XML_NS_ERR_COLON,
5114 » » "colon are forbidden from entities names '%s'\n", 5491 » » "colons are forbidden from entities names '%s'\n",
5115 name, NULL, NULL); 5492 name, NULL, NULL);
5116 } 5493 }
5117 skipped = SKIP_BLANKS; 5494 skipped = SKIP_BLANKS;
5118 if (skipped == 0) { 5495 if (skipped == 0) {
5119 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 5496 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5120 "Space required after the entity name\n"); 5497 "Space required after the entity name\n");
5121 } 5498 }
5122 5499
5123 ctxt->instate = XML_PARSER_ENTITY_DECL; 5500 ctxt->instate = XML_PARSER_ENTITY_DECL;
5124 /* 5501 /*
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
5274 } 5651 }
5275 } 5652 }
5276 } 5653 }
5277 } 5654 }
5278 if (ctxt->instate == XML_PARSER_EOF) 5655 if (ctxt->instate == XML_PARSER_EOF)
5279 return; 5656 return;
5280 SKIP_BLANKS; 5657 SKIP_BLANKS;
5281 if (RAW != '>') { 5658 if (RAW != '>') {
5282 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, 5659 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
5283 "xmlParseEntityDecl: entity %s not terminated\n", name); 5660 "xmlParseEntityDecl: entity %s not terminated\n", name);
5661 xmlStopParser(ctxt);
5284 } else { 5662 } else {
5285 if (input != ctxt->input) { 5663 if (input != ctxt->input) {
5286 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, 5664 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5287 "Entity declaration doesn't start and stop in the same entity\n"); 5665 "Entity declaration doesn't start and stop in the same entity\n");
5288 } 5666 }
5289 NEXT; 5667 NEXT;
5290 } 5668 }
5291 if (orig != NULL) { 5669 if (orig != NULL) {
5292 /* 5670 /*
5293 * Ugly mechanism to save the raw entity value. 5671 * Ugly mechanism to save the raw entity value.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5333 * if the default declaration is the keyword #REQUIRED, then the 5711 * if the default declaration is the keyword #REQUIRED, then the
5334 * attribute must be specified for all elements of the type in the 5712 * attribute must be specified for all elements of the type in the
5335 * attribute-list declaration. 5713 * attribute-list declaration.
5336 * 5714 *
5337 * [ VC: Attribute Default Legal ] 5715 * [ VC: Attribute Default Legal ]
5338 * The declared default value must meet the lexical constraints of 5716 * The declared default value must meet the lexical constraints of
5339 * the declared attribute type c.f. xmlValidateAttributeDecl() 5717 * the declared attribute type c.f. xmlValidateAttributeDecl()
5340 * 5718 *
5341 * [ VC: Fixed Attribute Default ] 5719 * [ VC: Fixed Attribute Default ]
5342 * if an attribute has a default value declared with the #FIXED 5720 * if an attribute has a default value declared with the #FIXED
5343 * keyword, instances of that attribute must match the default value. 5721 * keyword, instances of that attribute must match the default value.
5344 * 5722 *
5345 * [ WFC: No < in Attribute Values ] 5723 * [ WFC: No < in Attribute Values ]
5346 * handled in xmlParseAttValue() 5724 * handled in xmlParseAttValue()
5347 * 5725 *
5348 * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED 5726 * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED
5349 * or XML_ATTRIBUTE_FIXED. 5727 * or XML_ATTRIBUTE_FIXED.
5350 */ 5728 */
5351 5729
5352 int 5730 int
5353 xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { 5731 xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) {
5354 int val; 5732 int val;
5355 xmlChar *ret; 5733 xmlChar *ret;
5356 5734
5357 *value = NULL; 5735 *value = NULL;
5358 if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) { 5736 if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) {
5359 SKIP(9); 5737 SKIP(9);
(...skipping 28 matching lines...) Expand all
5388 * @ctxt: an XML parser context 5766 * @ctxt: an XML parser context
5389 * 5767 *
5390 * parse an Notation attribute type. 5768 * parse an Notation attribute type.
5391 * 5769 *
5392 * Note: the leading 'NOTATION' S part has already being parsed... 5770 * Note: the leading 'NOTATION' S part has already being parsed...
5393 * 5771 *
5394 * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' 5772 * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
5395 * 5773 *
5396 * [ VC: Notation Attributes ] 5774 * [ VC: Notation Attributes ]
5397 * Values of this type must match one of the notation names included 5775 * Values of this type must match one of the notation names included
5398 * in the declaration; all notation names in the declaration must be declared. 5776 * in the declaration; all notation names in the declaration must be declared.
5399 * 5777 *
5400 * Returns: the notation attribute tree built while parsing 5778 * Returns: the notation attribute tree built while parsing
5401 */ 5779 */
5402 5780
5403 xmlEnumerationPtr 5781 xmlEnumerationPtr
5404 xmlParseNotationType(xmlParserCtxtPtr ctxt) { 5782 xmlParseNotationType(xmlParserCtxtPtr ctxt) {
5405 const xmlChar *name; 5783 const xmlChar *name;
5406 xmlEnumerationPtr ret = NULL, last = NULL, cur, tmp; 5784 xmlEnumerationPtr ret = NULL, last = NULL, cur, tmp;
5407 5785
5408 if (RAW != '(') { 5786 if (RAW != '(') {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 * 5966 *
5589 * [ VC: IDREF ] 5967 * [ VC: IDREF ]
5590 * Values of type IDREF must match the Name production, and values 5968 * Values of type IDREF must match the Name production, and values
5591 * of type IDREFS must match Names; each IDREF Name must match the value 5969 * of type IDREFS must match Names; each IDREF Name must match the value
5592 * of an ID attribute on some element in the XML document; i.e. IDREF 5970 * of an ID attribute on some element in the XML document; i.e. IDREF
5593 * values must match the value of some ID attribute. 5971 * values must match the value of some ID attribute.
5594 * 5972 *
5595 * [ VC: Entity Name ] 5973 * [ VC: Entity Name ]
5596 * Values of type ENTITY must match the Name production, values 5974 * Values of type ENTITY must match the Name production, values
5597 * of type ENTITIES must match Names; each Entity Name must match the 5975 * of type ENTITIES must match Names; each Entity Name must match the
5598 * name of an unparsed entity declared in the DTD. 5976 * name of an unparsed entity declared in the DTD.
5599 * 5977 *
5600 * [ VC: Name Token ] 5978 * [ VC: Name Token ]
5601 * Values of type NMTOKEN must match the Nmtoken production; values 5979 * Values of type NMTOKEN must match the Nmtoken production; values
5602 * of type NMTOKENS must match Nmtokens. 5980 * of type NMTOKENS must match Nmtokens.
5603 * 5981 *
5604 * Returns the attribute type 5982 * Returns the attribute type
5605 */ 5983 */
5606 int 5984 int
5607 xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { 5985 xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
5608 SHRINK; 5986 SHRINK;
5609 if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) { 5987 if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) {
5610 SKIP(5); 5988 SKIP(5);
5611 return(XML_ATTRIBUTE_CDATA); 5989 return(XML_ATTRIBUTE_CDATA);
5612 } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) { 5990 } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) {
5613 SKIP(6); 5991 SKIP(6);
5614 return(XML_ATTRIBUTE_IDREFS); 5992 return(XML_ATTRIBUTE_IDREFS);
5615 } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) { 5993 } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) {
5616 SKIP(5); 5994 SKIP(5);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5739 break; 6117 break;
5740 } 6118 }
5741 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 6119 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
5742 (ctxt->sax->attributeDecl != NULL)) 6120 (ctxt->sax->attributeDecl != NULL))
5743 ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName, 6121 ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName,
5744 type, def, defaultValue, tree); 6122 type, def, defaultValue, tree);
5745 else if (tree != NULL) 6123 else if (tree != NULL)
5746 xmlFreeEnumeration(tree); 6124 xmlFreeEnumeration(tree);
5747 6125
5748 if ((ctxt->sax2) && (defaultValue != NULL) && 6126 if ((ctxt->sax2) && (defaultValue != NULL) &&
5749 » (def != XML_ATTRIBUTE_IMPLIED) && 6127 » (def != XML_ATTRIBUTE_IMPLIED) &&
5750 (def != XML_ATTRIBUTE_REQUIRED)) { 6128 (def != XML_ATTRIBUTE_REQUIRED)) {
5751 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue); 6129 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue);
5752 } 6130 }
5753 if (ctxt->sax2) { 6131 if (ctxt->sax2) {
5754 xmlAddSpecialAttr(ctxt, elemName, attrName, type); 6132 xmlAddSpecialAttr(ctxt, elemName, attrName, type);
5755 } 6133 }
5756 if (defaultValue != NULL) 6134 if (defaultValue != NULL)
5757 xmlFree(defaultValue); 6135 xmlFree(defaultValue);
5758 GROW; 6136 GROW;
5759 } 6137 }
5760 if (RAW == '>') { 6138 if (RAW == '>') {
5761 if (input != ctxt->input) { 6139 if (input != ctxt->input) {
5762 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6140 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
5763 "Attribute list declaration doesn't start and stop in the same entity\n", 6141 "Attribute list declaration doesn't start and stop in the same entity\n",
5764 NULL, NULL); 6142 NULL, NULL);
5765 } 6143 }
5766 NEXT; 6144 NEXT;
5767 } 6145 }
5768 } 6146 }
5769 } 6147 }
5770 6148
5771 /** 6149 /**
5772 * xmlParseElementMixedContentDecl: 6150 * xmlParseElementMixedContentDecl:
5773 * @ctxt: an XML parser context 6151 * @ctxt: an XML parser context
5774 * @inputchk: the input used for the current entity, needed for boundary checks 6152 * @inputchk: the input used for the current entity, needed for boundary checks
5775 * 6153 *
5776 * parse the declaration for a Mixed Element content 6154 * parse the declaration for a Mixed Element content
5777 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl 6155 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
5778 * 6156 *
5779 * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | 6157 * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' |
5780 * '(' S? '#PCDATA' S? ')' 6158 * '(' S? '#PCDATA' S? ')'
5781 * 6159 *
5782 * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) 6160 * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49])
5783 * 6161 *
5784 * [ VC: No Duplicate Types ] 6162 * [ VC: No Duplicate Types ]
5785 * The same name must not appear more than once in a single 6163 * The same name must not appear more than once in a single
5786 * mixed-content declaration. 6164 * mixed-content declaration.
5787 * 6165 *
5788 * returns: the list of the xmlElementContentPtr describing the element choices 6166 * returns: the list of the xmlElementContentPtr describing the element choices
5789 */ 6167 */
5790 xmlElementContentPtr 6168 xmlElementContentPtr
5791 xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) { 6169 xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
5792 xmlElementContentPtr ret = NULL, cur = NULL, n; 6170 xmlElementContentPtr ret = NULL, cur = NULL, n;
5793 const xmlChar *elem = NULL; 6171 const xmlChar *elem = NULL;
5794 6172
5795 GROW; 6173 GROW;
5796 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) { 6174 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 } 6254 }
5877 6255
5878 /** 6256 /**
5879 * xmlParseElementChildrenContentDeclPriv: 6257 * xmlParseElementChildrenContentDeclPriv:
5880 * @ctxt: an XML parser context 6258 * @ctxt: an XML parser context
5881 * @inputchk: the input used for the current entity, needed for boundary checks 6259 * @inputchk: the input used for the current entity, needed for boundary checks
5882 * @depth: the level of recursion 6260 * @depth: the level of recursion
5883 * 6261 *
5884 * parse the declaration for a Mixed Element content 6262 * parse the declaration for a Mixed Element content
5885 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl 6263 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
5886 * 6264 *
5887 * 6265 *
5888 * [47] children ::= (choice | seq) ('?' | '*' | '+')? 6266 * [47] children ::= (choice | seq) ('?' | '*' | '+')?
5889 * 6267 *
5890 * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? 6268 * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
5891 * 6269 *
5892 * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' 6270 * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'
5893 * 6271 *
5894 * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' 6272 * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
5895 * 6273 *
5896 * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] 6274 * [ VC: Proper Group/PE Nesting ] applies to [49] and [50]
5897 * TODO Parameter-entity replacement text must be properly nested 6275 * TODO Parameter-entity replacement text must be properly nested
5898 * with parenthesized groups. That is to say, if either of the 6276 * with parenthesized groups. That is to say, if either of the
5899 * opening or closing parentheses in a choice, seq, or Mixed 6277 * opening or closing parentheses in a choice, seq, or Mixed
5900 * construct is contained in the replacement text for a parameter 6278 * construct is contained in the replacement text for a parameter
5901 * entity, both must be contained in the same replacement text. For 6279 * entity, both must be contained in the same replacement text. For
5902 * interoperability, if a parameter-entity reference appears in a 6280 * interoperability, if a parameter-entity reference appears in a
5903 * choice, seq, or Mixed construct, its replacement text should not 6281 * choice, seq, or Mixed construct, its replacement text should not
5904 * be empty, and neither the first nor last non-blank character of 6282 * be empty, and neither the first nor last non-blank character of
5905 * the replacement text should be a connector (| or ,). 6283 * the replacement text should be a connector (| or ,).
5906 * 6284 *
5907 * Returns the tree of xmlElementContentPtr describing the element 6285 * Returns the tree of xmlElementContentPtr describing the element
5908 * hierarchy. 6286 * hierarchy.
5909 */ 6287 */
5910 static xmlElementContentPtr 6288 static xmlElementContentPtr
5911 xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk, 6289 xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk,
5912 int depth) { 6290 int depth) {
5913 xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL; 6291 xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL;
5914 const xmlChar *elem; 6292 const xmlChar *elem;
5915 xmlChar type = 0; 6293 xmlChar type = 0;
5916 6294
5917 if (((depth > 128) && ((ctxt->options & XML_PARSE_HUGE) == 0)) || 6295 if (((depth > 128) && ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
6210 } 6588 }
6211 6589
6212 /** 6590 /**
6213 * xmlParseElementContentDecl: 6591 * xmlParseElementContentDecl:
6214 * @ctxt: an XML parser context 6592 * @ctxt: an XML parser context
6215 * @name: the name of the element being defined. 6593 * @name: the name of the element being defined.
6216 * @result: the Element Content pointer will be stored here if any 6594 * @result: the Element Content pointer will be stored here if any
6217 * 6595 *
6218 * parse the declaration for an Element content either Mixed or Children, 6596 * parse the declaration for an Element content either Mixed or Children,
6219 * the cases EMPTY and ANY are handled directly in xmlParseElementDecl 6597 * the cases EMPTY and ANY are handled directly in xmlParseElementDecl
6220 * 6598 *
6221 * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children 6599 * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
6222 * 6600 *
6223 * returns: the type of element content XML_ELEMENT_TYPE_xxx 6601 * returns: the type of element content XML_ELEMENT_TYPE_xxx
6224 */ 6602 */
6225 6603
6226 int 6604 int
6227 xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name, 6605 xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name,
6228 xmlElementContentPtr *result) { 6606 xmlElementContentPtr *result) {
6229 6607
6230 xmlElementContentPtr tree = NULL; 6608 xmlElementContentPtr tree = NULL;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
6338 if (RAW != '>') { 6716 if (RAW != '>') {
6339 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 6717 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
6340 if (content != NULL) { 6718 if (content != NULL) {
6341 xmlFreeDocElementContent(ctxt->myDoc, content); 6719 xmlFreeDocElementContent(ctxt->myDoc, content);
6342 } 6720 }
6343 } else { 6721 } else {
6344 if (input != ctxt->input) { 6722 if (input != ctxt->input) {
6345 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, 6723 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6346 "Element declaration doesn't start and stop in the same entity\n"); 6724 "Element declaration doesn't start and stop in the same entity\n");
6347 } 6725 }
6348 » » 6726
6349 NEXT; 6727 NEXT;
6350 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 6728 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
6351 (ctxt->sax->elementDecl != NULL)) { 6729 (ctxt->sax->elementDecl != NULL)) {
6352 if (content != NULL) 6730 if (content != NULL)
6353 content->parent = NULL; 6731 content->parent = NULL;
6354 ctxt->sax->elementDecl(ctxt->userData, name, ret, 6732 ctxt->sax->elementDecl(ctxt->userData, name, ret,
6355 content); 6733 content);
6356 if ((content != NULL) && (content->parent == NULL)) { 6734 if ((content != NULL) && (content->parent == NULL)) {
6357 /* 6735 /*
6358 * this is a trick: if xmlAddElementDecl is called, 6736 * this is a trick: if xmlAddElementDecl is called,
6359 * instead of copying the full tree it is plugged directly 6737 * instead of copying the full tree it is plugged directly
6360 » » * if called from the parser. Avoid duplicating the 6738 » » * if called from the parser. Avoid duplicating the
6361 * interfaces or change the API/ABI 6739 * interfaces or change the API/ABI
6362 */ 6740 */
6363 xmlFreeDocElementContent(ctxt->myDoc, content); 6741 xmlFreeDocElementContent(ctxt->myDoc, content);
6364 } 6742 }
6365 } else if (content != NULL) { 6743 } else if (content != NULL) {
6366 xmlFreeDocElementContent(ctxt->myDoc, content); 6744 xmlFreeDocElementContent(ctxt->myDoc, content);
6367 } 6745 }
6368 } 6746 }
6369 } 6747 }
6370 return(ret); 6748 return(ret);
6371 } 6749 }
6372 6750
6373 /** 6751 /**
6374 * xmlParseConditionalSections 6752 * xmlParseConditionalSections
6375 * @ctxt: an XML parser context 6753 * @ctxt: an XML parser context
6376 * 6754 *
6377 * [61] conditionalSect ::= includeSect | ignoreSect 6755 * [61] conditionalSect ::= includeSect | ignoreSect
6378 * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' 6756 * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
6379 * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' 6757 * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
6380 * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* 6758 * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
6381 * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) 6759 * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
6382 */ 6760 */
6383 6761
6384 static void 6762 static void
6385 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { 6763 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
6386 int id = ctxt->input->id; 6764 int id = ctxt->input->id;
6387 6765
6388 SKIP(3); 6766 SKIP(3);
6389 SKIP_BLANKS; 6767 SKIP_BLANKS;
6390 if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) { 6768 if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) {
6391 SKIP(7); 6769 SKIP(7);
6392 SKIP_BLANKS; 6770 SKIP_BLANKS;
6393 if (RAW != '[') { 6771 if (RAW != '[') {
6394 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); 6772 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
6773 xmlStopParser(ctxt);
6774 return;
6395 } else { 6775 } else {
6396 if (ctxt->input->id != id) { 6776 if (ctxt->input->id != id) {
6397 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6777 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6398 "All markup of the conditional section is not in the same entity\n", 6778 "All markup of the conditional section is not in the same entity\n",
6399 NULL, NULL); 6779 NULL, NULL);
6400 } 6780 }
6401 NEXT; 6781 NEXT;
6402 } 6782 }
6403 if (xmlParserDebugEntities) { 6783 if (xmlParserDebugEntities) {
6404 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6784 if ((ctxt->input != NULL) && (ctxt->input->filename))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6445 6825
6446 } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) { 6826 } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) {
6447 int state; 6827 int state;
6448 xmlParserInputState instate; 6828 xmlParserInputState instate;
6449 int depth = 0; 6829 int depth = 0;
6450 6830
6451 SKIP(6); 6831 SKIP(6);
6452 SKIP_BLANKS; 6832 SKIP_BLANKS;
6453 if (RAW != '[') { 6833 if (RAW != '[') {
6454 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL); 6834 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
6835 xmlStopParser(ctxt);
6836 return;
6455 } else { 6837 } else {
6456 if (ctxt->input->id != id) { 6838 if (ctxt->input->id != id) {
6457 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6839 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6458 "All markup of the conditional section is not in the same entity\n", 6840 "All markup of the conditional section is not in the same entity\n",
6459 NULL, NULL); 6841 NULL, NULL);
6460 } 6842 }
6461 NEXT; 6843 NEXT;
6462 } 6844 }
6463 if (xmlParserDebugEntities) { 6845 if (xmlParserDebugEntities) {
6464 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6846 if ((ctxt->input != NULL) && (ctxt->input->filename))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
6500 if ((ctxt->input != NULL) && (ctxt->input->filename)) 6882 if ((ctxt->input != NULL) && (ctxt->input->filename))
6501 xmlGenericError(xmlGenericErrorContext, 6883 xmlGenericError(xmlGenericErrorContext,
6502 "%s(%d): ", ctxt->input->filename, 6884 "%s(%d): ", ctxt->input->filename,
6503 ctxt->input->line); 6885 ctxt->input->line);
6504 xmlGenericError(xmlGenericErrorContext, 6886 xmlGenericError(xmlGenericErrorContext,
6505 "Leaving IGNORE Conditional Section\n"); 6887 "Leaving IGNORE Conditional Section\n");
6506 } 6888 }
6507 6889
6508 } else { 6890 } else {
6509 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL); 6891 xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL);
6892 xmlStopParser(ctxt);
6893 return;
6510 } 6894 }
6511 6895
6512 if (RAW == 0) 6896 if (RAW == 0)
6513 SHRINK; 6897 SHRINK;
6514 6898
6515 if (RAW == 0) { 6899 if (RAW == 0) {
6516 xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL); 6900 xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL);
6517 } else { 6901 } else {
6518 if (ctxt->input->id != id) { 6902 if (ctxt->input->id != id) {
6519 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6903 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
6520 "All markup of the conditional section is not in the same entity\n", 6904 "All markup of the conditional section is not in the same entity\n",
6521 NULL, NULL); 6905 NULL, NULL);
6522 } 6906 }
6523 SKIP(3); 6907 SKIP(3);
6524 } 6908 }
6525 } 6909 }
6526 6910
6527 /** 6911 /**
6528 * xmlParseMarkupDecl: 6912 * xmlParseMarkupDecl:
6529 * @ctxt: an XML parser context 6913 * @ctxt: an XML parser context
6530 * 6914 *
6531 * parse Markup declarations 6915 * parse Markup declarations
6532 * 6916 *
6533 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | 6917 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
6534 * NotationDecl | PI | Comment 6918 * NotationDecl | PI | Comment
6535 * 6919 *
6536 * [ VC: Proper Declaration/PE Nesting ] 6920 * [ VC: Proper Declaration/PE Nesting ]
6537 * Parameter-entity replacement text must be properly nested with 6921 * Parameter-entity replacement text must be properly nested with
6538 * markup declarations. That is to say, if either the first character 6922 * markup declarations. That is to say, if either the first character
6539 * or the last character of a markup declaration (markupdecl above) is 6923 * or the last character of a markup declaration (markupdecl above) is
6540 * contained in the replacement text for a parameter-entity reference, 6924 * contained in the replacement text for a parameter-entity reference,
6541 * both must be contained in the same replacement text. 6925 * both must be contained in the same replacement text.
6542 * 6926 *
6543 * [ WFC: PEs in Internal Subset ] 6927 * [ WFC: PEs in Internal Subset ]
6544 * In the internal DTD subset, parameter-entity references can occur 6928 * In the internal DTD subset, parameter-entity references can occur
6545 * only where markup declarations can occur, not within markup declarations. 6929 * only where markup declarations can occur, not within markup declarations.
6546 * (This does not apply to references that occur in external parameter 6930 * (This does not apply to references that occur in external parameter
6547 * entities or to the external subset.) 6931 * entities or to the external subset.)
6548 */ 6932 */
6549 void 6933 void
6550 xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { 6934 xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
6551 GROW; 6935 GROW;
6552 if (CUR == '<') { 6936 if (CUR == '<') {
6553 if (NXT(1) == '!') { 6937 if (NXT(1) == '!') {
6554 switch (NXT(2)) { 6938 switch (NXT(2)) {
6555 case 'E': 6939 case 'E':
6556 if (NXT(3) == 'L') 6940 if (NXT(3) == 'L')
6557 xmlParseElementDecl(ctxt); 6941 xmlParseElementDecl(ctxt);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
6666 MOVETO_ENDTAG(CUR_PTR); 7050 MOVETO_ENDTAG(CUR_PTR);
6667 NEXT; 7051 NEXT;
6668 } 7052 }
6669 } 7053 }
6670 7054
6671 /** 7055 /**
6672 * xmlParseExternalSubset: 7056 * xmlParseExternalSubset:
6673 * @ctxt: an XML parser context 7057 * @ctxt: an XML parser context
6674 * @ExternalID: the external identifier 7058 * @ExternalID: the external identifier
6675 * @SystemID: the system identifier (or URL) 7059 * @SystemID: the system identifier (or URL)
6676 * 7060 *
6677 * parse Markup declarations from an external subset 7061 * parse Markup declarations from an external subset
6678 * 7062 *
6679 * [30] extSubset ::= textDecl? extSubsetDecl 7063 * [30] extSubset ::= textDecl? extSubsetDecl
6680 * 7064 *
6681 * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) * 7065 * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) *
6682 */ 7066 */
6683 void 7067 void
6684 xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, 7068 xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
6685 const xmlChar *SystemID) { 7069 const xmlChar *SystemID) {
6686 xmlDetectSAX2(ctxt); 7070 xmlDetectSAX2(ctxt);
6687 GROW; 7071 GROW;
6688 7072
6689 if ((ctxt->encoding == (const xmlChar *)XML_CHAR_ENCODING_NONE) && 7073 if ((ctxt->encoding == NULL) &&
6690 (ctxt->input->end - ctxt->input->cur >= 4)) { 7074 (ctxt->input->end - ctxt->input->cur >= 4)) {
6691 xmlChar start[4]; 7075 xmlChar start[4];
6692 xmlCharEncoding enc; 7076 xmlCharEncoding enc;
6693 7077
6694 start[0] = RAW; 7078 start[0] = RAW;
6695 start[1] = NXT(1); 7079 start[1] = NXT(1);
6696 start[2] = NXT(2); 7080 start[2] = NXT(2);
6697 start[3] = NXT(3); 7081 start[3] = NXT(3);
6698 enc = xmlDetectCharEncoding(start, 4); 7082 enc = xmlDetectCharEncoding(start, 4);
6699 if (enc != XML_CHAR_ENCODING_NONE) 7083 if (enc != XML_CHAR_ENCODING_NONE)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
6845 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && 7229 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
6846 (!ctxt->disableSAX)) 7230 (!ctxt->disableSAX))
6847 ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); 7231 ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val));
6848 return; 7232 return;
6849 } 7233 }
6850 7234
6851 /* 7235 /*
6852 * The first reference to the entity trigger a parsing phase 7236 * The first reference to the entity trigger a parsing phase
6853 * where the ent->children is filled with the result from 7237 * where the ent->children is filled with the result from
6854 * the parsing. 7238 * the parsing.
7239 * Note: external parsed entities will not be loaded, it is not
7240 * required for a non-validating parser, unless the parsing option
7241 * of validating, or substituting entities were given. Doing so is
7242 * far more secure as the parser will only process data coming from
7243 * the document entity by default.
6855 */ 7244 */
6856 if (ent->checked == 0) { 7245 if (((ent->checked == 0) ||
7246 ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&
7247 ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||
7248 (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {
6857 unsigned long oldnbent = ctxt->nbentities; 7249 unsigned long oldnbent = ctxt->nbentities;
6858 7250
6859 /* 7251 /*
6860 * This is a bit hackish but this seems the best 7252 * This is a bit hackish but this seems the best
6861 * way to make sure both SAX and DOM entity support 7253 * way to make sure both SAX and DOM entity support
6862 * behaves okay. 7254 * behaves okay.
6863 */ 7255 */
6864 void *user_data; 7256 void *user_data;
6865 if (ctxt->userData == ctxt) 7257 if (ctxt->userData == ctxt)
6866 user_data = NULL; 7258 user_data = NULL;
(...skipping 21 matching lines...) Expand all
6888 } else { 7280 } else {
6889 ret = XML_ERR_ENTITY_PE_INTERNAL; 7281 ret = XML_ERR_ENTITY_PE_INTERNAL;
6890 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR, 7282 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR,
6891 "invalid entity type found\n", NULL); 7283 "invalid entity type found\n", NULL);
6892 } 7284 }
6893 7285
6894 /* 7286 /*
6895 * Store the number of entities needing parsing for this entity 7287 * Store the number of entities needing parsing for this entity
6896 * content and do checkings 7288 * content and do checkings
6897 */ 7289 */
6898 » ent->checked = ctxt->nbentities - oldnbent; 7290 » ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
7291 » if ((ent->content != NULL) && (xmlStrchr(ent->content, '<')))
7292 » ent->checked |= 1;
6899 if (ret == XML_ERR_ENTITY_LOOP) { 7293 if (ret == XML_ERR_ENTITY_LOOP) {
6900 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); 7294 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
6901 xmlFreeNodeList(list); 7295 xmlFreeNodeList(list);
6902 return; 7296 return;
6903 } 7297 }
6904 » if (xmlParserEntityCheck(ctxt, 0, ent)) { 7298 » if (xmlParserEntityCheck(ctxt, 0, ent, 0)) {
6905 xmlFreeNodeList(list); 7299 xmlFreeNodeList(list);
6906 return; 7300 return;
6907 } 7301 }
6908 7302
6909 if ((ret == XML_ERR_OK) && (list != NULL)) { 7303 if ((ret == XML_ERR_OK) && (list != NULL)) {
6910 if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) || 7304 if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) ||
6911 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&& 7305 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&&
6912 (ent->children == NULL)) { 7306 (ent->children == NULL)) {
6913 ent->children = list; 7307 ent->children = list;
6914 if (ctxt->replaceEntities) { 7308 if (ctxt->replaceEntities) {
(...skipping 19 matching lines...) Expand all
6934 list = ent->children; 7328 list = ent->children;
6935 #ifdef LIBXML_LEGACY_ENABLED 7329 #ifdef LIBXML_LEGACY_ENABLED
6936 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) 7330 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
6937 xmlAddEntityReference(ent, list, NULL); 7331 xmlAddEntityReference(ent, list, NULL);
6938 #endif /* LIBXML_LEGACY_ENABLED */ 7332 #endif /* LIBXML_LEGACY_ENABLED */
6939 } 7333 }
6940 } else { 7334 } else {
6941 ent->owner = 1; 7335 ent->owner = 1;
6942 while (list != NULL) { 7336 while (list != NULL) {
6943 list->parent = (xmlNodePtr) ent; 7337 list->parent = (xmlNodePtr) ent;
7338 xmlSetTreeDoc(list, ent->doc);
6944 if (list->next == NULL) 7339 if (list->next == NULL)
6945 ent->last = list; 7340 ent->last = list;
6946 list = list->next; 7341 list = list->next;
6947 } 7342 }
6948 } 7343 }
6949 } else { 7344 } else {
6950 xmlFreeNodeList(list); 7345 xmlFreeNodeList(list);
6951 list = NULL; 7346 list = NULL;
6952 } 7347 }
6953 } else if ((ret != XML_ERR_OK) && 7348 } else if ((ret != XML_ERR_OK) &&
6954 (ret != XML_WAR_UNDECLARED_ENTITY)) { 7349 (ret != XML_WAR_UNDECLARED_ENTITY)) {
6955 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, 7350 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
6956 "Entity '%s' failed to parse\n", ent->name); 7351 "Entity '%s' failed to parse\n", ent->name);
7352 xmlParserEntityCheck(ctxt, 0, ent, 0);
6957 } else if (list != NULL) { 7353 } else if (list != NULL) {
6958 xmlFreeNodeList(list); 7354 xmlFreeNodeList(list);
6959 list = NULL; 7355 list = NULL;
6960 } 7356 }
6961 if (ent->checked == 0) 7357 if (ent->checked == 0)
6962 » ent->checked = 1; 7358 » ent->checked = 2;
6963 } else if (ent->checked != 1) { 7359 } else if (ent->checked != 1) {
6964 » ctxt->nbentities += ent->checked; 7360 » ctxt->nbentities += ent->checked / 2;
6965 } 7361 }
6966 7362
6967 /* 7363 /*
6968 * Now that the entity content has been gathered 7364 * Now that the entity content has been gathered
6969 * provide it to the application, this can take different forms based 7365 * provide it to the application, this can take different forms based
6970 * on the parsing modes. 7366 * on the parsing modes.
6971 */ 7367 */
6972 if (ent->children == NULL) { 7368 if (ent->children == NULL) {
6973 /* 7369 /*
6974 * Probably running in SAX mode and the callbacks don't 7370 * Probably running in SAX mode and the callbacks don't
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
7045 * and, if it's NULL, we copy in whatever was in the entity. 7441 * and, if it's NULL, we copy in whatever was in the entity.
7046 * If it's not NULL we leave it alone. This is somewhat of a 7442 * If it's not NULL we leave it alone. This is somewhat of a
7047 * hack - maybe we should have further tests to determine 7443 * hack - maybe we should have further tests to determine
7048 * what to do. 7444 * what to do.
7049 */ 7445 */
7050 if ((ctxt->node != NULL) && (ent->children != NULL)) { 7446 if ((ctxt->node != NULL) && (ent->children != NULL)) {
7051 /* 7447 /*
7052 * Seems we are generating the DOM content, do 7448 * Seems we are generating the DOM content, do
7053 * a simple tree copy for all references except the first 7449 * a simple tree copy for all references except the first
7054 * In the first occurrence list contains the replacement. 7450 * In the first occurrence list contains the replacement.
7055 * progressive == 2 means we are operating on the Reader
7056 * and since nodes are discarded we must copy all the time.
7057 */ 7451 */
7058 if (((list == NULL) && (ent->owner == 0)) || 7452 if (((list == NULL) && (ent->owner == 0)) ||
7059 (ctxt->parseMode == XML_PARSE_READER)) { 7453 (ctxt->parseMode == XML_PARSE_READER)) {
7060 xmlNodePtr nw = NULL, cur, firstChild = NULL; 7454 xmlNodePtr nw = NULL, cur, firstChild = NULL;
7061 7455
7062 /* 7456 /*
7457 * We are copying here, make sure there is no abuse
7458 */
7459 ctxt->sizeentcopy += ent->length + 5;
7460 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7461 return;
7462
7463 /*
7063 * when operating on a reader, the entities definitions 7464 * when operating on a reader, the entities definitions
7064 * are always owning the entities subtree. 7465 * are always owning the entities subtree.
7065 if (ctxt->parseMode == XML_PARSE_READER) 7466 if (ctxt->parseMode == XML_PARSE_READER)
7066 ent->owner = 1; 7467 ent->owner = 1;
7067 */ 7468 */
7068 7469
7069 cur = ent->children; 7470 cur = ent->children;
7070 while (cur != NULL) { 7471 while (cur != NULL) {
7071 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1); 7472 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
7072 if (nw != NULL) { 7473 if (nw != NULL) {
(...skipping 16 matching lines...) Expand all
7089 nw->extra = 1; 7490 nw->extra = 1;
7090 7491
7091 break; 7492 break;
7092 } 7493 }
7093 cur = cur->next; 7494 cur = cur->next;
7094 } 7495 }
7095 #ifdef LIBXML_LEGACY_ENABLED 7496 #ifdef LIBXML_LEGACY_ENABLED
7096 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) 7497 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
7097 xmlAddEntityReference(ent, firstChild, nw); 7498 xmlAddEntityReference(ent, firstChild, nw);
7098 #endif /* LIBXML_LEGACY_ENABLED */ 7499 #endif /* LIBXML_LEGACY_ENABLED */
7099 » } else if (list == NULL) { 7500 » } else if ((list == NULL) || (ctxt->inputNr > 0)) {
7100 xmlNodePtr nw = NULL, cur, next, last, 7501 xmlNodePtr nw = NULL, cur, next, last,
7101 firstChild = NULL; 7502 firstChild = NULL;
7503
7504 /*
7505 * We are copying here, make sure there is no abuse
7506 */
7507 ctxt->sizeentcopy += ent->length + 5;
7508 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7509 return;
7510
7102 /* 7511 /*
7103 * Copy the entity child list and make it the new 7512 * Copy the entity child list and make it the new
7104 * entity child list. The goal is to make sure any 7513 * entity child list. The goal is to make sure any
7105 * ID or REF referenced will be the one from the 7514 * ID or REF referenced will be the one from the
7106 * document content and not the entity copy. 7515 * document content and not the entity copy.
7107 */ 7516 */
7108 cur = ent->children; 7517 cur = ent->children;
7109 ent->children = NULL; 7518 ent->children = NULL;
7110 last = ent->last; 7519 last = ent->last;
7111 ent->last = NULL; 7520 ent->last = NULL;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
7208 "xmlParseEntityRef: no name\n"); 7617 "xmlParseEntityRef: no name\n");
7209 return(NULL); 7618 return(NULL);
7210 } 7619 }
7211 if (RAW != ';') { 7620 if (RAW != ';') {
7212 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); 7621 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
7213 return(NULL); 7622 return(NULL);
7214 } 7623 }
7215 NEXT; 7624 NEXT;
7216 7625
7217 /* 7626 /*
7218 * Predefined entites override any extra definition 7627 * Predefined entities override any extra definition
7219 */ 7628 */
7220 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) { 7629 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7221 ent = xmlGetPredefinedEntity(name); 7630 ent = xmlGetPredefinedEntity(name);
7222 if (ent != NULL) 7631 if (ent != NULL)
7223 return(ent); 7632 return(ent);
7224 } 7633 }
7225 7634
7226 /* 7635 /*
7227 * Increate the number of entity references parsed 7636 * Increase the number of entity references parsed
7228 */ 7637 */
7229 ctxt->nbentities++; 7638 ctxt->nbentities++;
7230 7639
7231 /* 7640 /*
7232 * Ask first SAX for entity resolution, otherwise try the 7641 * Ask first SAX for entity resolution, otherwise try the
7233 * entities which may have stored in the parser context. 7642 * entities which may have stored in the parser context.
7234 */ 7643 */
7235 if (ctxt->sax != NULL) { 7644 if (ctxt->sax != NULL) {
7236 if (ctxt->sax->getEntity != NULL) 7645 if (ctxt->sax->getEntity != NULL)
7237 ent = ctxt->sax->getEntity(ctxt->userData, name); 7646 ent = ctxt->sax->getEntity(ctxt->userData, name);
7238 » if ((ctxt->wellFormed == 1 ) && (ent == NULL) && 7647 » if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7239 (ctxt->options & XML_PARSE_OLDSAX)) 7648 (ctxt->options & XML_PARSE_OLDSAX))
7240 ent = xmlGetPredefinedEntity(name); 7649 ent = xmlGetPredefinedEntity(name);
7241 if ((ctxt->wellFormed == 1 ) && (ent == NULL) && 7650 if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7242 (ctxt->userData==ctxt)) { 7651 (ctxt->userData==ctxt)) {
7243 ent = xmlSAX2GetEntity(ctxt, name); 7652 ent = xmlSAX2GetEntity(ctxt, name);
7244 } 7653 }
7245 } 7654 }
7246 if (ctxt->instate == XML_PARSER_EOF) 7655 if (ctxt->instate == XML_PARSER_EOF)
7247 return(NULL); 7656 return(NULL);
7248 /* 7657 /*
(...skipping 25 matching lines...) Expand all
7274 "Entity '%s' not defined\n", name); 7683 "Entity '%s' not defined\n", name);
7275 } else { 7684 } else {
7276 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, 7685 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7277 "Entity '%s' not defined\n", name); 7686 "Entity '%s' not defined\n", name);
7278 if ((ctxt->inSubset == 0) && 7687 if ((ctxt->inSubset == 0) &&
7279 (ctxt->sax != NULL) && 7688 (ctxt->sax != NULL) &&
7280 (ctxt->sax->reference != NULL)) { 7689 (ctxt->sax->reference != NULL)) {
7281 ctxt->sax->reference(ctxt->userData, name); 7690 ctxt->sax->reference(ctxt->userData, name);
7282 } 7691 }
7283 } 7692 }
7693 xmlParserEntityCheck(ctxt, 0, ent, 0);
7284 ctxt->valid = 0; 7694 ctxt->valid = 0;
7285 } 7695 }
7286 7696
7287 /* 7697 /*
7288 * [ WFC: Parsed Entity ] 7698 * [ WFC: Parsed Entity ]
7289 * An entity reference must not contain the name of an 7699 * An entity reference must not contain the name of an
7290 * unparsed entity 7700 * unparsed entity
7291 */ 7701 */
7292 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { 7702 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
7293 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, 7703 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
7294 "Entity reference to unparsed entity %s\n", name); 7704 "Entity reference to unparsed entity %s\n", name);
7295 } 7705 }
7296 7706
7297 /* 7707 /*
7298 * [ WFC: No External Entity References ] 7708 * [ WFC: No External Entity References ]
7299 * Attribute values cannot contain direct or indirect 7709 * Attribute values cannot contain direct or indirect
7300 * entity references to external entities. 7710 * entity references to external entities.
7301 */ 7711 */
7302 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && 7712 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7303 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { 7713 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
7304 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL, 7714 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL,
7305 "Attribute references external entity '%s'\n", name); 7715 "Attribute references external entity '%s'\n", name);
7306 } 7716 }
7307 /* 7717 /*
7308 * [ WFC: No < in Attribute Values ] 7718 * [ WFC: No < in Attribute Values ]
7309 * The replacement text of any entity referred to directly or 7719 * The replacement text of any entity referred to directly or
7310 * indirectly in an attribute value (other than "&lt;") must 7720 * indirectly in an attribute value (other than "&lt;") must
7311 * not contain a <. 7721 * not contain a <.
7312 */ 7722 */
7313 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && 7723 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7314 » (ent != NULL) && (ent->content != NULL) && 7724 » (ent != NULL) &&
7315 » (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) && 7725 » (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) {
7316 » (xmlStrchr(ent->content, '<'))) { 7726 » if (((ent->checked & 1) || (ent->checked == 0)) &&
7317 » xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, 7727 » (ent->content != NULL) && (xmlStrchr(ent->content, '<'))) {
7318 "'<' in entity '%s' is not allowed in attributes values\n", name); 7728 » xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
7729 » "'<' in entity '%s' is not allowed in attributes values\n", name);
7730 }
7319 } 7731 }
7320 7732
7321 /* 7733 /*
7322 * Internal check, no parameter entities here ... 7734 * Internal check, no parameter entities here ...
7323 */ 7735 */
7324 else { 7736 else {
7325 switch (ent->etype) { 7737 switch (ent->etype) {
7326 case XML_INTERNAL_PARAMETER_ENTITY: 7738 case XML_INTERNAL_PARAMETER_ENTITY:
7327 case XML_EXTERNAL_PARAMETER_ENTITY: 7739 case XML_EXTERNAL_PARAMETER_ENTITY:
7328 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, 7740 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER,
7329 "Attempt to reference the parameter entity '%s'\n", 7741 "Attempt to reference the parameter entity '%s'\n",
7330 name); 7742 name);
7331 break; 7743 break;
7332 default: 7744 default:
7333 break; 7745 break;
7334 } 7746 }
7335 } 7747 }
7336 7748
7337 /* 7749 /*
7338 * [ WFC: No Recursion ] 7750 * [ WFC: No Recursion ]
7339 * A parsed entity must not contain a recursive reference 7751 * A parsed entity must not contain a recursive reference
7340 * to itself, either directly or indirectly. 7752 * to itself, either directly or indirectly.
7341 * Done somewhere else 7753 * Done somewhere else
7342 */ 7754 */
7343 return(ent); 7755 return(ent);
7344 } 7756 }
7345 7757
7346 /** 7758 /**
7347 * xmlParseStringEntityRef: 7759 * xmlParseStringEntityRef:
7348 * @ctxt: an XML parser context 7760 * @ctxt: an XML parser context
7349 * @str: a pointer to an index in the string 7761 * @str: a pointer to an index in the string
7350 * 7762 *
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7399 if (*ptr != ';') { 7811 if (*ptr != ';') {
7400 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); 7812 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
7401 xmlFree(name); 7813 xmlFree(name);
7402 *str = ptr; 7814 *str = ptr;
7403 return(NULL); 7815 return(NULL);
7404 } 7816 }
7405 ptr++; 7817 ptr++;
7406 7818
7407 7819
7408 /* 7820 /*
7409 * Predefined entites override any extra definition 7821 * Predefined entities override any extra definition
7410 */ 7822 */
7411 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) { 7823 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7412 ent = xmlGetPredefinedEntity(name); 7824 ent = xmlGetPredefinedEntity(name);
7413 if (ent != NULL) { 7825 if (ent != NULL) {
7414 xmlFree(name); 7826 xmlFree(name);
7415 *str = ptr; 7827 *str = ptr;
7416 return(ent); 7828 return(ent);
7417 } 7829 }
7418 } 7830 }
7419 7831
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7452 * The declaration of a parameter entity must precede any 7864 * The declaration of a parameter entity must precede any
7453 * reference to it. 7865 * reference to it.
7454 * Similarly, the declaration of a general entity must 7866 * Similarly, the declaration of a general entity must
7455 * precede any reference to it which appears in a default 7867 * precede any reference to it which appears in a default
7456 * value in an attribute-list declaration. Note that if 7868 * value in an attribute-list declaration. Note that if
7457 * entities are declared in the external subset or in 7869 * entities are declared in the external subset or in
7458 * external parameter entities, a non-validating processor 7870 * external parameter entities, a non-validating processor
7459 * is not obligated to read and process their declarations; 7871 * is not obligated to read and process their declarations;
7460 * for such documents, the rule that an entity must be 7872 * for such documents, the rule that an entity must be
7461 * declared is a well-formedness constraint only if 7873 * declared is a well-formedness constraint only if
7462 * standalone='yes'. 7874 * standalone='yes'.
7463 */ 7875 */
7464 if (ent == NULL) { 7876 if (ent == NULL) {
7465 if ((ctxt->standalone == 1) || 7877 if ((ctxt->standalone == 1) ||
7466 ((ctxt->hasExternalSubset == 0) && 7878 ((ctxt->hasExternalSubset == 0) &&
7467 (ctxt->hasPErefs == 0))) { 7879 (ctxt->hasPErefs == 0))) {
7468 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, 7880 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7469 "Entity '%s' not defined\n", name); 7881 "Entity '%s' not defined\n", name);
7470 } else { 7882 } else {
7471 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, 7883 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7472 "Entity '%s' not defined\n", 7884 "Entity '%s' not defined\n",
7473 name); 7885 name);
7474 } 7886 }
7887 xmlParserEntityCheck(ctxt, 0, ent, 0);
7475 /* TODO ? check regressions ctxt->valid = 0; */ 7888 /* TODO ? check regressions ctxt->valid = 0; */
7476 } 7889 }
7477 7890
7478 /* 7891 /*
7479 * [ WFC: Parsed Entity ] 7892 * [ WFC: Parsed Entity ]
7480 * An entity reference must not contain the name of an 7893 * An entity reference must not contain the name of an
7481 * unparsed entity 7894 * unparsed entity
7482 */ 7895 */
7483 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { 7896 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
7484 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, 7897 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7543 * @ctxt: an XML parser context 7956 * @ctxt: an XML parser context
7544 * 7957 *
7545 * parse PEReference declarations 7958 * parse PEReference declarations
7546 * The entity content is handled directly by pushing it's content as 7959 * The entity content is handled directly by pushing it's content as
7547 * a new input stream. 7960 * a new input stream.
7548 * 7961 *
7549 * [69] PEReference ::= '%' Name ';' 7962 * [69] PEReference ::= '%' Name ';'
7550 * 7963 *
7551 * [ WFC: No Recursion ] 7964 * [ WFC: No Recursion ]
7552 * A parsed entity must not contain a recursive 7965 * A parsed entity must not contain a recursive
7553 * reference to itself, either directly or indirectly. 7966 * reference to itself, either directly or indirectly.
7554 * 7967 *
7555 * [ WFC: Entity Declared ] 7968 * [ WFC: Entity Declared ]
7556 * In a document without any DTD, a document with only an internal DTD 7969 * In a document without any DTD, a document with only an internal DTD
7557 * subset which contains no parameter entity references, or a document 7970 * subset which contains no parameter entity references, or a document
7558 * with "standalone='yes'", ... ... The declaration of a parameter 7971 * with "standalone='yes'", ... ... The declaration of a parameter
7559 * entity must precede any reference to it... 7972 * entity must precede any reference to it...
7560 * 7973 *
7561 * [ VC: Entity Declared ] 7974 * [ VC: Entity Declared ]
7562 * In a document with an external subset or external parameter entities 7975 * In a document with an external subset or external parameter entities
7563 * with "standalone='no'", ... ... The declaration of a parameter entity 7976 * with "standalone='no'", ... ... The declaration of a parameter entity
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7624 * In a document with an external subset or external 8037 * In a document with an external subset or external
7625 * parameter entities with "standalone='no'", ... 8038 * parameter entities with "standalone='no'", ...
7626 * ... The declaration of a parameter entity must 8039 * ... The declaration of a parameter entity must
7627 * precede any reference to it... 8040 * precede any reference to it...
7628 */ 8041 */
7629 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8042 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7630 "PEReference: %%%s; not found\n", 8043 "PEReference: %%%s; not found\n",
7631 name, NULL); 8044 name, NULL);
7632 ctxt->valid = 0; 8045 ctxt->valid = 0;
7633 } 8046 }
8047 xmlParserEntityCheck(ctxt, 0, NULL, 0);
7634 } else { 8048 } else {
7635 /* 8049 /*
7636 * Internal checking in case the entity quest barfed 8050 * Internal checking in case the entity quest barfed
7637 */ 8051 */
7638 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && 8052 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
7639 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { 8053 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) {
7640 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8054 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7641 "Internal: %%%s; is not a parameter entity\n", 8055 "Internal: %%%s; is not a parameter entity\n",
7642 name, NULL); 8056 name, NULL);
7643 } else if (ctxt->input->free != deallocblankswrapper) { 8057 } else if (ctxt->input->free != deallocblankswrapper) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7725 if (xmlPushInput(ctxt, input) < 0) { 8139 if (xmlPushInput(ctxt, input) < 0) {
7726 xmlBufferFree(buf); 8140 xmlBufferFree(buf);
7727 return(-1); 8141 return(-1);
7728 } 8142 }
7729 8143
7730 GROW; 8144 GROW;
7731 c = CUR_CHAR(l); 8145 c = CUR_CHAR(l);
7732 while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) && 8146 while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) &&
7733 (IS_CHAR(c))) { 8147 (IS_CHAR(c))) {
7734 xmlBufferAdd(buf, ctxt->input->cur, l); 8148 xmlBufferAdd(buf, ctxt->input->cur, l);
7735 » if (count++ > 100) { 8149 » if (count++ > XML_PARSER_CHUNK_SIZE) {
7736 count = 0; 8150 count = 0;
7737 GROW; 8151 GROW;
7738 if (ctxt->instate == XML_PARSER_EOF) { 8152 if (ctxt->instate == XML_PARSER_EOF) {
7739 xmlBufferFree(buf); 8153 xmlBufferFree(buf);
7740 return(-1); 8154 return(-1);
7741 } 8155 }
7742 } 8156 }
7743 NEXTL(l); 8157 NEXTL(l);
7744 c = CUR_CHAR(l); 8158 c = CUR_CHAR(l);
8159 if (c == 0) {
8160 count = 0;
8161 GROW;
8162 if (ctxt->instate == XML_PARSER_EOF) {
8163 xmlBufferFree(buf);
8164 return(-1);
8165 }
8166 c = CUR_CHAR(l);
8167 }
7745 } 8168 }
7746 8169
7747 if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) { 8170 if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) {
7748 xmlPopInput(ctxt); 8171 xmlPopInput(ctxt);
7749 } else if (!IS_CHAR(c)) { 8172 } else if (!IS_CHAR(c)) {
7750 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, 8173 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
7751 "xmlLoadEntityContent: invalid char value %d\n", 8174 "xmlLoadEntityContent: invalid char value %d\n",
7752 c); 8175 c);
7753 xmlBufferFree(buf); 8176 xmlBufferFree(buf);
7754 return(-1); 8177 return(-1);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
7854 * In a document with an external subset or external 8277 * In a document with an external subset or external
7855 * parameter entities with "standalone='no'", ... 8278 * parameter entities with "standalone='no'", ...
7856 * ... The declaration of a parameter entity must 8279 * ... The declaration of a parameter entity must
7857 * precede any reference to it... 8280 * precede any reference to it...
7858 */ 8281 */
7859 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8282 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7860 "PEReference: %%%s; not found\n", 8283 "PEReference: %%%s; not found\n",
7861 name, NULL); 8284 name, NULL);
7862 ctxt->valid = 0; 8285 ctxt->valid = 0;
7863 } 8286 }
8287 xmlParserEntityCheck(ctxt, 0, NULL, 0);
7864 } else { 8288 } else {
7865 /* 8289 /*
7866 * Internal checking in case the entity quest barfed 8290 * Internal checking in case the entity quest barfed
7867 */ 8291 */
7868 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && 8292 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
7869 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { 8293 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) {
7870 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8294 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7871 "%%%s; is not a parameter entity\n", 8295 "%%%s; is not a parameter entity\n",
7872 name, NULL); 8296 name, NULL);
7873 } 8297 }
7874 } 8298 }
7875 ctxt->hasPErefs = 1; 8299 ctxt->hasPErefs = 1;
7876 xmlFree(name); 8300 xmlFree(name);
7877 *str = ptr; 8301 *str = ptr;
7878 return(entity); 8302 return(entity);
7879 } 8303 }
7880 8304
7881 /** 8305 /**
7882 * xmlParseDocTypeDecl: 8306 * xmlParseDocTypeDecl:
7883 * @ctxt: an XML parser context 8307 * @ctxt: an XML parser context
7884 * 8308 *
7885 * parse a DOCTYPE declaration 8309 * parse a DOCTYPE declaration
7886 * 8310 *
7887 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? 8311 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
7888 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>' 8312 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
7889 * 8313 *
7890 * [ VC: Root Element Type ] 8314 * [ VC: Root Element Type ]
7891 * The Name in the document type declaration must match the element 8315 * The Name in the document type declaration must match the element
7892 * type of the root element. 8316 * type of the root element.
7893 */ 8317 */
7894 8318
7895 void 8319 void
7896 xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { 8320 xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) {
7897 const xmlChar *name = NULL; 8321 const xmlChar *name = NULL;
7898 xmlChar *ExternalID = NULL; 8322 xmlChar *ExternalID = NULL;
7899 xmlChar *URI = NULL; 8323 xmlChar *URI = NULL;
7900 8324
7901 /* 8325 /*
7902 * We know that '<!DOCTYPE' has been detected. 8326 * We know that '<!DOCTYPE' has been detected.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
7966 8390
7967 static void 8391 static void
7968 xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { 8392 xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
7969 /* 8393 /*
7970 * Is there any DTD definition ? 8394 * Is there any DTD definition ?
7971 */ 8395 */
7972 if (RAW == '[') { 8396 if (RAW == '[') {
7973 ctxt->instate = XML_PARSER_DTD; 8397 ctxt->instate = XML_PARSER_DTD;
7974 NEXT; 8398 NEXT;
7975 /* 8399 /*
7976 » * Parse the succession of Markup declarations and 8400 » * Parse the succession of Markup declarations and
7977 * PEReferences. 8401 * PEReferences.
7978 * Subsequence (markupdecl | PEReference | S)* 8402 * Subsequence (markupdecl | PEReference | S)*
7979 */ 8403 */
7980 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) { 8404 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
7981 const xmlChar *check = CUR_PTR; 8405 const xmlChar *check = CUR_PTR;
7982 unsigned int cons = ctxt->input->consumed; 8406 unsigned int cons = ctxt->input->consumed;
7983 8407
7984 SKIP_BLANKS; 8408 SKIP_BLANKS;
7985 xmlParseMarkupDecl(ctxt); 8409 xmlParseMarkupDecl(ctxt);
7986 xmlParsePEReference(ctxt); 8410 xmlParsePEReference(ctxt);
7987 8411
7988 /* 8412 /*
7989 * Pop-up of finished entities. 8413 * Pop-up of finished entities.
7990 */ 8414 */
7991 while ((RAW == 0) && (ctxt->inputNr > 1)) 8415 while ((RAW == 0) && (ctxt->inputNr > 1))
7992 xmlPopInput(ctxt); 8416 xmlPopInput(ctxt);
7993 8417
7994 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { 8418 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
7995 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 8419 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
7996 "xmlParseInternalSubset: error detected in Markup declaration\n"); 8420 "xmlParseInternalSubset: error detected in Markup declaration\n");
7997 break; 8421 break;
7998 } 8422 }
7999 } 8423 }
8000 » if (RAW == ']') { 8424 » if (RAW == ']') {
8001 NEXT; 8425 NEXT;
8002 SKIP_BLANKS; 8426 SKIP_BLANKS;
8003 } 8427 }
8004 } 8428 }
8005 8429
8006 /* 8430 /*
8007 * We should be at the end of the DOCTYPE declaration. 8431 * We should be at the end of the DOCTYPE declaration.
8008 */ 8432 */
8009 if (RAW != '>') { 8433 if (RAW != '>') {
8010 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL); 8434 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
(...skipping 10 matching lines...) Expand all
8021 * parse an attribute 8445 * parse an attribute
8022 * 8446 *
8023 * [41] Attribute ::= Name Eq AttValue 8447 * [41] Attribute ::= Name Eq AttValue
8024 * 8448 *
8025 * [ WFC: No External Entity References ] 8449 * [ WFC: No External Entity References ]
8026 * Attribute values cannot contain direct or indirect entity references 8450 * Attribute values cannot contain direct or indirect entity references
8027 * to external entities. 8451 * to external entities.
8028 * 8452 *
8029 * [ WFC: No < in Attribute Values ] 8453 * [ WFC: No < in Attribute Values ]
8030 * The replacement text of any entity referred to directly or indirectly in 8454 * The replacement text of any entity referred to directly or indirectly in
8031 * an attribute value (other than "&lt;") must not contain a <. 8455 * an attribute value (other than "&lt;") must not contain a <.
8032 * 8456 *
8033 * [ VC: Attribute Value Type ] 8457 * [ VC: Attribute Value Type ]
8034 * The attribute must have been declared; the value must be of the type 8458 * The attribute must have been declared; the value must be of the type
8035 * declared for it. 8459 * declared for it.
8036 * 8460 *
8037 * [25] Eq ::= S? '=' S? 8461 * [25] Eq ::= S? '=' S?
8038 * 8462 *
8039 * With namespace: 8463 * With namespace:
8040 * 8464 *
8041 * [NS 11] Attribute ::= QName Eq AttValue 8465 * [NS 11] Attribute ::= QName Eq AttValue
8042 * 8466 *
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8103 } 8527 }
8104 } 8528 }
8105 8529
8106 *value = val; 8530 *value = val;
8107 return(name); 8531 return(name);
8108 } 8532 }
8109 8533
8110 /** 8534 /**
8111 * xmlParseStartTag: 8535 * xmlParseStartTag:
8112 * @ctxt: an XML parser context 8536 * @ctxt: an XML parser context
8113 * 8537 *
8114 * parse a start of tag either for rule element or 8538 * parse a start of tag either for rule element or
8115 * EmptyElement. In both case we don't parse the tag closing chars. 8539 * EmptyElement. In both case we don't parse the tag closing chars.
8116 * 8540 *
8117 * [40] STag ::= '<' Name (S Attribute)* S? '>' 8541 * [40] STag ::= '<' Name (S Attribute)* S? '>'
8118 * 8542 *
8119 * [ WFC: Unique Att Spec ] 8543 * [ WFC: Unique Att Spec ]
8120 * No attribute name may appear more than once in the same start-tag or 8544 * No attribute name may appear more than once in the same start-tag or
8121 * empty-element tag. 8545 * empty-element tag.
8122 * 8546 *
8123 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' 8547 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
8124 * 8548 *
8125 * [ WFC: Unique Att Spec ] 8549 * [ WFC: Unique Att Spec ]
8126 * No attribute name may appear more than once in the same start-tag or 8550 * No attribute name may appear more than once in the same start-tag or
8127 * empty-element tag. 8551 * empty-element tag.
8128 * 8552 *
8129 * With namespace: 8553 * With namespace:
8130 * 8554 *
8131 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' 8555 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
8132 * 8556 *
8133 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' 8557 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
8134 * 8558 *
8135 * Returns the element name parsed 8559 * Returns the element name parsed
8136 */ 8560 */
8137 8561
(...skipping 18 matching lines...) Expand all
8156 } 8580 }
8157 8581
8158 /* 8582 /*
8159 * Now parse the attributes, it ends up with the ending 8583 * Now parse the attributes, it ends up with the ending
8160 * 8584 *
8161 * (S Attribute)* S? 8585 * (S Attribute)* S?
8162 */ 8586 */
8163 SKIP_BLANKS; 8587 SKIP_BLANKS;
8164 GROW; 8588 GROW;
8165 8589
8166 while (((RAW != '>') && 8590 while (((RAW != '>') &&
8167 ((RAW != '/') || (NXT(1) != '>')) && 8591 ((RAW != '/') || (NXT(1) != '>')) &&
8168 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { 8592 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
8169 const xmlChar *q = CUR_PTR; 8593 const xmlChar *q = CUR_PTR;
8170 unsigned int cons = ctxt->input->consumed; 8594 unsigned int cons = ctxt->input->consumed;
8171 8595
8172 attname = xmlParseAttribute(ctxt, &attvalue); 8596 attname = xmlParseAttribute(ctxt, &attvalue);
8173 if ((attname != NULL) && (attvalue != NULL)) { 8597 if ((attname != NULL) && (attvalue != NULL)) {
8174 /* 8598 /*
8175 * [ WFC: Unique Att Spec ] 8599 * [ WFC: Unique Att Spec ]
8176 * No attribute name may appear more than once in the same 8600 * No attribute name may appear more than once in the same
8177 » * start-tag or empty-element tag. 8601 » * start-tag or empty-element tag.
8178 */ 8602 */
8179 for (i = 0; i < nbatts;i += 2) { 8603 for (i = 0; i < nbatts;i += 2) {
8180 if (xmlStrEqual(atts[i], attname)) { 8604 if (xmlStrEqual(atts[i], attname)) {
8181 xmlErrAttributeDup(ctxt, NULL, attname); 8605 xmlErrAttributeDup(ctxt, NULL, attname);
8182 xmlFree(attvalue); 8606 xmlFree(attvalue);
8183 goto failed; 8607 goto failed;
8184 } 8608 }
8185 } 8609 }
8186 /* 8610 /*
8187 * Add the pair to atts 8611 * Add the pair to atts
(...skipping 28 matching lines...) Expand all
8216 } 8640 }
8217 atts[nbatts++] = attname; 8641 atts[nbatts++] = attname;
8218 atts[nbatts++] = attvalue; 8642 atts[nbatts++] = attvalue;
8219 atts[nbatts] = NULL; 8643 atts[nbatts] = NULL;
8220 atts[nbatts + 1] = NULL; 8644 atts[nbatts + 1] = NULL;
8221 } else { 8645 } else {
8222 if (attvalue != NULL) 8646 if (attvalue != NULL)
8223 xmlFree(attvalue); 8647 xmlFree(attvalue);
8224 } 8648 }
8225 8649
8226 failed: 8650 failed:
8227 8651
8228 GROW 8652 GROW
8229 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) 8653 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
8230 break; 8654 break;
8231 if (!IS_BLANK_CH(RAW)) { 8655 if (!IS_BLANK_CH(RAW)) {
8232 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 8656 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
8233 "attributes construct error\n"); 8657 "attributes construct error\n");
8234 } 8658 }
8235 SKIP_BLANKS; 8659 SKIP_BLANKS;
8236 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && 8660 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) &&
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
8298 GROW; 8722 GROW;
8299 SKIP_BLANKS; 8723 SKIP_BLANKS;
8300 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { 8724 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
8301 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 8725 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
8302 } else 8726 } else
8303 NEXT1; 8727 NEXT1;
8304 8728
8305 /* 8729 /*
8306 * [ WFC: Element Type Match ] 8730 * [ WFC: Element Type Match ]
8307 * The Name in an element's end-tag must match the element type in the 8731 * The Name in an element's end-tag must match the element type in the
8308 * start-tag. 8732 * start-tag.
8309 * 8733 *
8310 */ 8734 */
8311 if (name != (xmlChar*)1) { 8735 if (name != (xmlChar*)1) {
8312 if (name == NULL) name = BAD_CAST "unparseable"; 8736 if (name == NULL) name = BAD_CAST "unparseable";
8313 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, 8737 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH,
8314 "Opening and ending tag mismatch: %s line %d and %s\n", 8738 "Opening and ending tag mismatch: %s line %d and %s\n",
8315 ctxt->name, line, name); 8739 ctxt->name, line, name);
8316 } 8740 }
8317 8741
8318 /* 8742 /*
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
8394 xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) { 8818 xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) {
8395 const xmlChar *l, *p; 8819 const xmlChar *l, *p;
8396 8820
8397 GROW; 8821 GROW;
8398 8822
8399 l = xmlParseNCName(ctxt); 8823 l = xmlParseNCName(ctxt);
8400 if (l == NULL) { 8824 if (l == NULL) {
8401 if (CUR == ':') { 8825 if (CUR == ':') {
8402 l = xmlParseName(ctxt); 8826 l = xmlParseName(ctxt);
8403 if (l != NULL) { 8827 if (l != NULL) {
8404 » xmlNsErr(ctxt, XML_NS_ERR_QNAME, 8828 » xmlNsErr(ctxt, XML_NS_ERR_QNAME,
8405 "Failed to parse QName '%s'\n", l, NULL, NULL); 8829 "Failed to parse QName '%s'\n", l, NULL, NULL);
8406 *prefix = NULL; 8830 *prefix = NULL;
8407 return(l); 8831 return(l);
8408 } 8832 }
8409 } 8833 }
8410 return(NULL); 8834 return(NULL);
8411 } 8835 }
8412 if (CUR == ':') { 8836 if (CUR == ':') {
8413 NEXT; 8837 NEXT;
8414 p = l; 8838 p = l;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
8477 const xmlChar *ret; 8901 const xmlChar *ret;
8478 const xmlChar *prefix2; 8902 const xmlChar *prefix2;
8479 8903
8480 if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name)); 8904 if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name));
8481 8905
8482 GROW; 8906 GROW;
8483 in = ctxt->input->cur; 8907 in = ctxt->input->cur;
8484 8908
8485 cmp = prefix; 8909 cmp = prefix;
8486 while (*in != 0 && *in == *cmp) { 8910 while (*in != 0 && *in == *cmp) {
8487 » ++in; 8911 » ++in;
8488 ++cmp; 8912 ++cmp;
8489 } 8913 }
8490 if ((*cmp == 0) && (*in == ':')) { 8914 if ((*cmp == 0) && (*in == ':')) {
8491 in++; 8915 in++;
8492 cmp = name; 8916 cmp = name;
8493 while (*in != 0 && *in == *cmp) { 8917 while (*in != 0 && *in == *cmp) {
8494 ++in; 8918 ++in;
8495 ++cmp; 8919 ++cmp;
8496 } 8920 }
8497 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { 8921 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
(...skipping 17 matching lines...) Expand all
8515 * @len: attribute len result 8939 * @len: attribute len result
8516 * @alloc: whether the attribute was reallocated as a new string 8940 * @alloc: whether the attribute was reallocated as a new string
8517 * @normalize: if 1 then further non-CDATA normalization must be done 8941 * @normalize: if 1 then further non-CDATA normalization must be done
8518 * 8942 *
8519 * parse a value for an attribute. 8943 * parse a value for an attribute.
8520 * NOTE: if no normalization is needed, the routine will return pointers 8944 * NOTE: if no normalization is needed, the routine will return pointers
8521 * directly from the data buffer. 8945 * directly from the data buffer.
8522 * 8946 *
8523 * 3.3.3 Attribute-Value Normalization: 8947 * 3.3.3 Attribute-Value Normalization:
8524 * Before the value of an attribute is passed to the application or 8948 * Before the value of an attribute is passed to the application or
8525 * checked for validity, the XML processor must normalize it as follows: 8949 * checked for validity, the XML processor must normalize it as follows:
8526 * - a character reference is processed by appending the referenced 8950 * - a character reference is processed by appending the referenced
8527 * character to the attribute value 8951 * character to the attribute value
8528 * - an entity reference is processed by recursively processing the 8952 * - an entity reference is processed by recursively processing the
8529 * replacement text of the entity 8953 * replacement text of the entity
8530 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by 8954 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by
8531 * appending #x20 to the normalized value, except that only a single 8955 * appending #x20 to the normalized value, except that only a single
8532 * #x20 is appended for a "#xD#xA" sequence that is part of an external 8956 * #x20 is appended for a "#xD#xA" sequence that is part of an external
8533 * parsed entity or the literal entity value of an internal parsed entity 8957 * parsed entity or the literal entity value of an internal parsed entity
8534 * - other characters are processed by appending them to the normalized value 8958 * - other characters are processed by appending them to the normalized value
8535 * If the declared value is not CDATA, then the XML processor must further 8959 * If the declared value is not CDATA, then the XML processor must further
8536 * process the normalized attribute value by discarding any leading and 8960 * process the normalized attribute value by discarding any leading and
8537 * trailing space (#x20) characters, and by replacing sequences of space 8961 * trailing space (#x20) characters, and by replacing sequences of space
8538 * (#x20) characters by a single space (#x20) character. 8962 * (#x20) characters by a single space (#x20) character.
8539 * All attributes for which no declaration has been read should be treated 8963 * All attributes for which no declaration has been read should be treated
8540 * by a non-validating parser as if declared CDATA. 8964 * by a non-validating parser as if declared CDATA.
8541 * 8965 *
8542 * Returns the AttValue parsed or NULL. The value has to be freed by the 8966 * Returns the AttValue parsed or NULL. The value has to be freed by the
8543 * caller if it was copied, this can be detected by val[*len] == 0. 8967 * caller if it was copied, this can be detected by val[*len] == 0.
8544 */ 8968 */
8545 8969
8546 static xmlChar * 8970 static xmlChar *
8547 xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, 8971 xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
8548 int normalize) 8972 int normalize)
8549 { 8973 {
8550 xmlChar limit = 0; 8974 xmlChar limit = 0;
8551 const xmlChar *in = NULL, *start, *end, *last; 8975 const xmlChar *in = NULL, *start, *end, *last;
8552 xmlChar *ret = NULL; 8976 xmlChar *ret = NULL;
8977 int line, col;
8553 8978
8554 GROW; 8979 GROW;
8555 in = (xmlChar *) CUR_PTR; 8980 in = (xmlChar *) CUR_PTR;
8981 line = ctxt->input->line;
8982 col = ctxt->input->col;
8556 if (*in != '"' && *in != '\'') { 8983 if (*in != '"' && *in != '\'') {
8557 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL); 8984 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL);
8558 return (NULL); 8985 return (NULL);
8559 } 8986 }
8560 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; 8987 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE;
8561 8988
8562 /* 8989 /*
8563 * try to handle in this routine the most common case where no 8990 * try to handle in this routine the most common case where no
8564 * allocation of a new string is required and where content is 8991 * allocation of a new string is required and where content is
8565 * pure ASCII. 8992 * pure ASCII.
8566 */ 8993 */
8567 limit = *in++; 8994 limit = *in++;
8995 col++;
8568 end = ctxt->input->end; 8996 end = ctxt->input->end;
8569 start = in; 8997 start = in;
8570 if (in >= end) { 8998 if (in >= end) {
8571 const xmlChar *oldbase = ctxt->input->base; 8999 const xmlChar *oldbase = ctxt->input->base;
8572 GROW; 9000 GROW;
8573 if (oldbase != ctxt->input->base) { 9001 if (oldbase != ctxt->input->base) {
8574 long delta = ctxt->input->base - oldbase; 9002 long delta = ctxt->input->base - oldbase;
8575 start = start + delta; 9003 start = start + delta;
8576 in = in + delta; 9004 in = in + delta;
8577 } 9005 }
8578 end = ctxt->input->end; 9006 end = ctxt->input->end;
8579 } 9007 }
8580 if (normalize) { 9008 if (normalize) {
8581 /* 9009 /*
8582 * Skip any leading spaces 9010 * Skip any leading spaces
8583 */ 9011 */
8584 » while ((in < end) && (*in != limit) && 9012 » while ((in < end) && (*in != limit) &&
8585 ((*in == 0x20) || (*in == 0x9) || 9013 ((*in == 0x20) || (*in == 0x9) ||
8586 (*in == 0xA) || (*in == 0xD))) { 9014 (*in == 0xA) || (*in == 0xD))) {
9015 if (*in == 0xA) {
9016 line++; col = 1;
9017 } else {
9018 col++;
9019 }
8587 in++; 9020 in++;
8588 start = in; 9021 start = in;
8589 if (in >= end) { 9022 if (in >= end) {
8590 const xmlChar *oldbase = ctxt->input->base; 9023 const xmlChar *oldbase = ctxt->input->base;
8591 GROW; 9024 GROW;
8592 if (ctxt->instate == XML_PARSER_EOF) 9025 if (ctxt->instate == XML_PARSER_EOF)
8593 return(NULL); 9026 return(NULL);
8594 if (oldbase != ctxt->input->base) { 9027 if (oldbase != ctxt->input->base) {
8595 long delta = ctxt->input->base - oldbase; 9028 long delta = ctxt->input->base - oldbase;
8596 start = start + delta; 9029 start = start + delta;
8597 in = in + delta; 9030 in = in + delta;
8598 } 9031 }
8599 end = ctxt->input->end; 9032 end = ctxt->input->end;
9033 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9034 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9035 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9036 "AttValue length too long\n");
9037 return(NULL);
9038 }
8600 } 9039 }
8601 } 9040 }
8602 while ((in < end) && (*in != limit) && (*in >= 0x20) && 9041 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
8603 (*in <= 0x7f) && (*in != '&') && (*in != '<')) { 9042 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
9043 col++;
8604 if ((*in++ == 0x20) && (*in == 0x20)) break; 9044 if ((*in++ == 0x20) && (*in == 0x20)) break;
8605 if (in >= end) { 9045 if (in >= end) {
8606 const xmlChar *oldbase = ctxt->input->base; 9046 const xmlChar *oldbase = ctxt->input->base;
8607 GROW; 9047 GROW;
8608 if (ctxt->instate == XML_PARSER_EOF) 9048 if (ctxt->instate == XML_PARSER_EOF)
8609 return(NULL); 9049 return(NULL);
8610 if (oldbase != ctxt->input->base) { 9050 if (oldbase != ctxt->input->base) {
8611 long delta = ctxt->input->base - oldbase; 9051 long delta = ctxt->input->base - oldbase;
8612 start = start + delta; 9052 start = start + delta;
8613 in = in + delta; 9053 in = in + delta;
8614 } 9054 }
8615 end = ctxt->input->end; 9055 end = ctxt->input->end;
9056 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9057 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9058 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9059 "AttValue length too long\n");
9060 return(NULL);
9061 }
8616 } 9062 }
8617 } 9063 }
8618 last = in; 9064 last = in;
8619 /* 9065 /*
8620 * skip the trailing blanks 9066 * skip the trailing blanks
8621 */ 9067 */
8622 while ((last[-1] == 0x20) && (last > start)) last--; 9068 while ((last[-1] == 0x20) && (last > start)) last--;
8623 » while ((in < end) && (*in != limit) && 9069 » while ((in < end) && (*in != limit) &&
8624 ((*in == 0x20) || (*in == 0x9) || 9070 ((*in == 0x20) || (*in == 0x9) ||
8625 (*in == 0xA) || (*in == 0xD))) { 9071 (*in == 0xA) || (*in == 0xD))) {
9072 if (*in == 0xA) {
9073 line++, col = 1;
9074 } else {
9075 col++;
9076 }
8626 in++; 9077 in++;
8627 if (in >= end) { 9078 if (in >= end) {
8628 const xmlChar *oldbase = ctxt->input->base; 9079 const xmlChar *oldbase = ctxt->input->base;
8629 GROW; 9080 GROW;
8630 if (ctxt->instate == XML_PARSER_EOF) 9081 if (ctxt->instate == XML_PARSER_EOF)
8631 return(NULL); 9082 return(NULL);
8632 if (oldbase != ctxt->input->base) { 9083 if (oldbase != ctxt->input->base) {
8633 long delta = ctxt->input->base - oldbase; 9084 long delta = ctxt->input->base - oldbase;
8634 start = start + delta; 9085 start = start + delta;
8635 in = in + delta; 9086 in = in + delta;
8636 last = last + delta; 9087 last = last + delta;
8637 } 9088 }
8638 end = ctxt->input->end; 9089 end = ctxt->input->end;
9090 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9091 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9092 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9093 "AttValue length too long\n");
9094 return(NULL);
9095 }
8639 } 9096 }
8640 } 9097 }
9098 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9099 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9100 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9101 "AttValue length too long\n");
9102 return(NULL);
9103 }
8641 if (*in != limit) goto need_complex; 9104 if (*in != limit) goto need_complex;
8642 } else { 9105 } else {
8643 while ((in < end) && (*in != limit) && (*in >= 0x20) && 9106 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
8644 (*in <= 0x7f) && (*in != '&') && (*in != '<')) { 9107 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
8645 in++; 9108 in++;
9109 col++;
8646 if (in >= end) { 9110 if (in >= end) {
8647 const xmlChar *oldbase = ctxt->input->base; 9111 const xmlChar *oldbase = ctxt->input->base;
8648 GROW; 9112 GROW;
8649 if (ctxt->instate == XML_PARSER_EOF) 9113 if (ctxt->instate == XML_PARSER_EOF)
8650 return(NULL); 9114 return(NULL);
8651 if (oldbase != ctxt->input->base) { 9115 if (oldbase != ctxt->input->base) {
8652 long delta = ctxt->input->base - oldbase; 9116 long delta = ctxt->input->base - oldbase;
8653 start = start + delta; 9117 start = start + delta;
8654 in = in + delta; 9118 in = in + delta;
8655 } 9119 }
8656 end = ctxt->input->end; 9120 end = ctxt->input->end;
9121 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9122 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9123 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9124 "AttValue length too long\n");
9125 return(NULL);
9126 }
8657 } 9127 }
8658 } 9128 }
8659 last = in; 9129 last = in;
9130 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9131 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9132 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9133 "AttValue length too long\n");
9134 return(NULL);
9135 }
8660 if (*in != limit) goto need_complex; 9136 if (*in != limit) goto need_complex;
8661 } 9137 }
8662 in++; 9138 in++;
9139 col++;
8663 if (len != NULL) { 9140 if (len != NULL) {
8664 *len = last - start; 9141 *len = last - start;
8665 ret = (xmlChar *) start; 9142 ret = (xmlChar *) start;
8666 } else { 9143 } else {
8667 if (alloc) *alloc = 1; 9144 if (alloc) *alloc = 1;
8668 ret = xmlStrndup(start, last - start); 9145 ret = xmlStrndup(start, last - start);
8669 } 9146 }
8670 CUR_PTR = in; 9147 CUR_PTR = in;
9148 ctxt->input->line = line;
9149 ctxt->input->col = col;
8671 if (alloc) *alloc = 0; 9150 if (alloc) *alloc = 0;
8672 return ret; 9151 return ret;
8673 need_complex: 9152 need_complex:
8674 if (alloc) *alloc = 1; 9153 if (alloc) *alloc = 1;
8675 return xmlParseAttValueComplex(ctxt, len, normalize); 9154 return xmlParseAttValueComplex(ctxt, len, normalize);
8676 } 9155 }
8677 9156
8678 /** 9157 /**
8679 * xmlParseAttribute2: 9158 * xmlParseAttribute2:
8680 * @ctxt: an XML parser context 9159 * @ctxt: an XML parser context
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
8788 xmlFree(internal_val); 9267 xmlFree(internal_val);
8789 } 9268 }
8790 } 9269 }
8791 9270
8792 *value = val; 9271 *value = val;
8793 return (name); 9272 return (name);
8794 } 9273 }
8795 /** 9274 /**
8796 * xmlParseStartTag2: 9275 * xmlParseStartTag2:
8797 * @ctxt: an XML parser context 9276 * @ctxt: an XML parser context
8798 * 9277 *
8799 * parse a start of tag either for rule element or 9278 * parse a start of tag either for rule element or
8800 * EmptyElement. In both case we don't parse the tag closing chars. 9279 * EmptyElement. In both case we don't parse the tag closing chars.
8801 * This routine is called when running SAX2 parsing 9280 * This routine is called when running SAX2 parsing
8802 * 9281 *
8803 * [40] STag ::= '<' Name (S Attribute)* S? '>' 9282 * [40] STag ::= '<' Name (S Attribute)* S? '>'
8804 * 9283 *
8805 * [ WFC: Unique Att Spec ] 9284 * [ WFC: Unique Att Spec ]
8806 * No attribute name may appear more than once in the same start-tag or 9285 * No attribute name may appear more than once in the same start-tag or
8807 * empty-element tag. 9286 * empty-element tag.
8808 * 9287 *
8809 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' 9288 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
8810 * 9289 *
8811 * [ WFC: Unique Att Spec ] 9290 * [ WFC: Unique Att Spec ]
8812 * No attribute name may appear more than once in the same start-tag or 9291 * No attribute name may appear more than once in the same start-tag or
8813 * empty-element tag. 9292 * empty-element tag.
8814 * 9293 *
8815 * With namespace: 9294 * With namespace:
8816 * 9295 *
8817 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' 9296 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
8818 * 9297 *
8819 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' 9298 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
8820 * 9299 *
8821 * Returns the element name parsed 9300 * Returns the element name parsed
8822 */ 9301 */
8823 9302
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8872 9351
8873 /* 9352 /*
8874 * Now parse the attributes, it ends up with the ending 9353 * Now parse the attributes, it ends up with the ending
8875 * 9354 *
8876 * (S Attribute)* S? 9355 * (S Attribute)* S?
8877 */ 9356 */
8878 SKIP_BLANKS; 9357 SKIP_BLANKS;
8879 GROW; 9358 GROW;
8880 if (ctxt->input->base != base) goto base_changed; 9359 if (ctxt->input->base != base) goto base_changed;
8881 9360
8882 while (((RAW != '>') && 9361 while (((RAW != '>') &&
8883 ((RAW != '/') || (NXT(1) != '>')) && 9362 ((RAW != '/') || (NXT(1) != '>')) &&
8884 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { 9363 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
8885 const xmlChar *q = CUR_PTR; 9364 const xmlChar *q = CUR_PTR;
8886 unsigned int cons = ctxt->input->consumed; 9365 unsigned int cons = ctxt->input->consumed;
8887 int len = -1, alloc = 0; 9366 int len = -1, alloc = 0;
8888 9367
8889 attname = xmlParseAttribute2(ctxt, prefix, localname, 9368 attname = xmlParseAttribute2(ctxt, prefix, localname,
8890 &aprefix, &attvalue, &len, &alloc); 9369 &aprefix, &attvalue, &len, &alloc);
8891 if (ctxt->input->base != base) { 9370 if (ctxt->input->base != base) {
8892 if ((attvalue != NULL) && (alloc != 0)) 9371 if ((attvalue != NULL) && (alloc != 0))
8893 xmlFree(attvalue); 9372 xmlFree(attvalue);
8894 attvalue = NULL; 9373 attvalue = NULL;
8895 goto base_changed; 9374 goto base_changed;
8896 } 9375 }
8897 if ((attname != NULL) && (attvalue != NULL)) { 9376 if ((attname != NULL) && (attvalue != NULL)) {
8898 if (len < 0) len = xmlStrlen(attvalue); 9377 if (len < 0) len = xmlStrlen(attvalue);
8899 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { 9378 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
8900 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); 9379 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
8901 xmlURIPtr uri; 9380 xmlURIPtr uri;
8902 9381
9382 if (URL == NULL) {
9383 xmlErrMemory(ctxt, "dictionary allocation failure");
9384 if ((attvalue != NULL) && (alloc != 0))
9385 xmlFree(attvalue);
9386 return(NULL);
9387 }
8903 if (*URL != 0) { 9388 if (*URL != 0) {
8904 uri = xmlParseURI((const char *) URL); 9389 uri = xmlParseURI((const char *) URL);
8905 if (uri == NULL) { 9390 if (uri == NULL) {
8906 xmlNsErr(ctxt, XML_WAR_NS_URI, 9391 xmlNsErr(ctxt, XML_WAR_NS_URI,
8907 "xmlns: '%s' is not a valid URI\n", 9392 "xmlns: '%s' is not a valid URI\n",
8908 URL, NULL, NULL); 9393 URL, NULL, NULL);
8909 } else { 9394 } else {
8910 if (uri->scheme == NULL) { 9395 if (uri->scheme == NULL) {
8911 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE, 9396 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
8912 "xmlns: URI %s is not absolute\n", 9397 "xmlns: URI %s is not absolute\n",
(...skipping 23 matching lines...) Expand all
8936 */ 9421 */
8937 for (j = 1;j <= nbNs;j++) 9422 for (j = 1;j <= nbNs;j++)
8938 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL) 9423 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
8939 break; 9424 break;
8940 if (j <= nbNs) 9425 if (j <= nbNs)
8941 xmlErrAttributeDup(ctxt, NULL, attname); 9426 xmlErrAttributeDup(ctxt, NULL, attname);
8942 else 9427 else
8943 if (nsPush(ctxt, NULL, URL) > 0) nbNs++; 9428 if (nsPush(ctxt, NULL, URL) > 0) nbNs++;
8944 skip_default_ns: 9429 skip_default_ns:
8945 if (alloc != 0) xmlFree(attvalue); 9430 if (alloc != 0) xmlFree(attvalue);
9431 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9432 break;
9433 if (!IS_BLANK_CH(RAW)) {
9434 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9435 "attributes construct error\n");
9436 break;
9437 }
8946 SKIP_BLANKS; 9438 SKIP_BLANKS;
8947 continue; 9439 continue;
8948 } 9440 }
8949 if (aprefix == ctxt->str_xmlns) { 9441 if (aprefix == ctxt->str_xmlns) {
8950 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); 9442 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
8951 xmlURIPtr uri; 9443 xmlURIPtr uri;
8952 9444
8953 if (attname == ctxt->str_xml) { 9445 if (attname == ctxt->str_xml) {
8954 if (URL != ctxt->str_xml_ns) { 9446 if (URL != ctxt->str_xml_ns) {
8955 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE, 9447 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
9009 */ 9501 */
9010 for (j = 1;j <= nbNs;j++) 9502 for (j = 1;j <= nbNs;j++)
9011 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname) 9503 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
9012 break; 9504 break;
9013 if (j <= nbNs) 9505 if (j <= nbNs)
9014 xmlErrAttributeDup(ctxt, aprefix, attname); 9506 xmlErrAttributeDup(ctxt, aprefix, attname);
9015 else 9507 else
9016 if (nsPush(ctxt, attname, URL) > 0) nbNs++; 9508 if (nsPush(ctxt, attname, URL) > 0) nbNs++;
9017 skip_ns: 9509 skip_ns:
9018 if (alloc != 0) xmlFree(attvalue); 9510 if (alloc != 0) xmlFree(attvalue);
9511 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9512 break;
9513 if (!IS_BLANK_CH(RAW)) {
9514 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9515 "attributes construct error\n");
9516 break;
9517 }
9019 SKIP_BLANKS; 9518 SKIP_BLANKS;
9020 if (ctxt->input->base != base) goto base_changed; 9519 if (ctxt->input->base != base) goto base_changed;
9021 continue; 9520 continue;
9022 } 9521 }
9023 9522
9024 /* 9523 /*
9025 * Add the pair to atts 9524 * Add the pair to atts
9026 */ 9525 */
9027 if ((atts == NULL) || (nbatts + 5 > maxatts)) { 9526 if ((atts == NULL) || (nbatts + 5 > maxatts)) {
9028 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) { 9527 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
9138 atts[nbatts++] = attname; 9637 atts[nbatts++] = attname;
9139 atts[nbatts++] = aprefix; 9638 atts[nbatts++] = aprefix;
9140 if (aprefix == NULL) 9639 if (aprefix == NULL)
9141 atts[nbatts++] = NULL; 9640 atts[nbatts++] = NULL;
9142 else 9641 else
9143 atts[nbatts++] = xmlGetNamespace(ctxt, aprefix); 9642 atts[nbatts++] = xmlGetNamespace(ctxt, aprefix);
9144 atts[nbatts++] = defaults->values[5 * i + 2]; 9643 atts[nbatts++] = defaults->values[5 * i + 2];
9145 atts[nbatts++] = defaults->values[5 * i + 3]; 9644 atts[nbatts++] = defaults->values[5 * i + 3];
9146 if ((ctxt->standalone == 1) && 9645 if ((ctxt->standalone == 1) &&
9147 (defaults->values[5 * i + 4] != NULL)) { 9646 (defaults->values[5 * i + 4] != NULL)) {
9148 » » » xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED, 9647 » » » xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
9149 "standalone: attribute %s on %s defaulted from external subset\n", 9648 "standalone: attribute %s on %s defaulted from external subset\n",
9150 attname, localname); 9649 attname, localname);
9151 } 9650 }
9152 nbdef++; 9651 nbdef++;
9153 } 9652 }
9154 } 9653 }
9155 } 9654 }
9156 } 9655 }
9157 9656
9158 /* 9657 /*
9159 * The attributes checkings 9658 * The attributes checkings
9160 */ 9659 */
9161 for (i = 0; i < nbatts;i += 5) { 9660 for (i = 0; i < nbatts;i += 5) {
9162 /* 9661 /*
9163 * The default namespace does not apply to attribute names. 9662 * The default namespace does not apply to attribute names.
9164 */ 9663 */
9165 if (atts[i + 1] != NULL) { 9664 if (atts[i + 1] != NULL) {
9166 nsname = xmlGetNamespace(ctxt, atts[i + 1]); 9665 nsname = xmlGetNamespace(ctxt, atts[i + 1]);
9167 if (nsname == NULL) { 9666 if (nsname == NULL) {
9168 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, 9667 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
9169 "Namespace prefix %s for %s on %s is not defined\n", 9668 "Namespace prefix %s for %s on %s is not defined\n",
9170 atts[i + 1], atts[i], localname); 9669 atts[i + 1], atts[i], localname);
9171 } 9670 }
9172 atts[i + 2] = nsname; 9671 atts[i + 2] = nsname;
9173 } else 9672 } else
9174 nsname = NULL; 9673 nsname = NULL;
9175 /* 9674 /*
9176 * [ WFC: Unique Att Spec ] 9675 * [ WFC: Unique Att Spec ]
9177 * No attribute name may appear more than once in the same 9676 * No attribute name may appear more than once in the same
9178 » * start-tag or empty-element tag. 9677 » * start-tag or empty-element tag.
9179 * As extended by the Namespace in XML REC. 9678 * As extended by the Namespace in XML REC.
9180 */ 9679 */
9181 for (j = 0; j < i;j += 5) { 9680 for (j = 0; j < i;j += 5) {
9182 if (atts[i] == atts[j]) { 9681 if (atts[i] == atts[j]) {
9183 if (atts[i+1] == atts[j+1]) { 9682 if (atts[i+1] == atts[j+1]) {
9184 xmlErrAttributeDup(ctxt, atts[i+1], atts[i]); 9683 xmlErrAttributeDup(ctxt, atts[i+1], atts[i]);
9185 break; 9684 break;
9186 } 9685 }
9187 if ((nsname != NULL) && (atts[j + 2] == nsname)) { 9686 if ((nsname != NULL) && (atts[j + 2] == nsname)) {
9188 xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED, 9687 xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
9269 GROW; 9768 GROW;
9270 if ((RAW != '<') || (NXT(1) != '/')) { 9769 if ((RAW != '<') || (NXT(1) != '/')) {
9271 xmlFatalErr(ctxt, XML_ERR_LTSLASH_REQUIRED, NULL); 9770 xmlFatalErr(ctxt, XML_ERR_LTSLASH_REQUIRED, NULL);
9272 return; 9771 return;
9273 } 9772 }
9274 SKIP(2); 9773 SKIP(2);
9275 9774
9276 if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) { 9775 if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) {
9277 if (ctxt->input->cur[tlen] == '>') { 9776 if (ctxt->input->cur[tlen] == '>') {
9278 ctxt->input->cur += tlen + 1; 9777 ctxt->input->cur += tlen + 1;
9778 ctxt->input->col += tlen + 1;
9279 goto done; 9779 goto done;
9280 } 9780 }
9281 ctxt->input->cur += tlen; 9781 ctxt->input->cur += tlen;
9782 ctxt->input->col += tlen;
9282 name = (xmlChar*)1; 9783 name = (xmlChar*)1;
9283 } else { 9784 } else {
9284 if (prefix == NULL) 9785 if (prefix == NULL)
9285 name = xmlParseNameAndCompare(ctxt, ctxt->name); 9786 name = xmlParseNameAndCompare(ctxt, ctxt->name);
9286 else 9787 else
9287 name = xmlParseQNameAndCompare(ctxt, ctxt->name, prefix); 9788 name = xmlParseQNameAndCompare(ctxt, ctxt->name, prefix);
9288 } 9789 }
9289 9790
9290 /* 9791 /*
9291 * We should definitely be at the ending "S? '>'" part 9792 * We should definitely be at the ending "S? '>'" part
9292 */ 9793 */
9293 GROW; 9794 GROW;
9294 if (ctxt->instate == XML_PARSER_EOF) 9795 if (ctxt->instate == XML_PARSER_EOF)
9295 return; 9796 return;
9296 SKIP_BLANKS; 9797 SKIP_BLANKS;
9297 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { 9798 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
9298 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 9799 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
9299 } else 9800 } else
9300 NEXT1; 9801 NEXT1;
9301 9802
9302 /* 9803 /*
9303 * [ WFC: Element Type Match ] 9804 * [ WFC: Element Type Match ]
9304 * The Name in an element's end-tag must match the element type in the 9805 * The Name in an element's end-tag must match the element type in the
9305 * start-tag. 9806 * start-tag.
9306 * 9807 *
9307 */ 9808 */
9308 if (name != (xmlChar*)1) { 9809 if (name != (xmlChar*)1) {
9309 if (name == NULL) name = BAD_CAST "unparseable"; 9810 if (name == NULL) name = BAD_CAST "unparseable";
9310 if ((line == 0) && (ctxt->node != NULL)) 9811 if ((line == 0) && (ctxt->node != NULL))
9311 line = ctxt->node->line; 9812 line = ctxt->node->line;
9312 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, 9813 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH,
9313 "Opening and ending tag mismatch: %s line %d and %s\n", 9814 "Opening and ending tag mismatch: %s line %d and %s\n",
9314 ctxt->name, line, name); 9815 ctxt->name, line, name);
9315 } 9816 }
9316 9817
9317 /* 9818 /*
9318 * SAX: End of Tag 9819 * SAX: End of Tag
9319 */ 9820 */
9320 done: 9821 done:
9321 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) && 9822 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) &&
9322 (!ctxt->disableSAX)) 9823 (!ctxt->disableSAX))
9323 ctxt->sax->endElementNs(ctxt->userData, ctxt->name, prefix, URI); 9824 ctxt->sax->endElementNs(ctxt->userData, ctxt->name, prefix, URI);
9324 9825
9325 spacePop(ctxt); 9826 spacePop(ctxt);
9326 if (nsNr != 0) 9827 if (nsNr != 0)
9327 nsPop(ctxt, nsNr); 9828 nsPop(ctxt, nsNr);
9328 return; 9829 return;
9329 } 9830 }
9330 9831
9331 /** 9832 /**
9332 * xmlParseCDSect: 9833 * xmlParseCDSect:
9333 * @ctxt: an XML parser context 9834 * @ctxt: an XML parser context
9334 * 9835 *
9335 * Parse escaped pure raw content. 9836 * Parse escaped pure raw content.
9336 * 9837 *
9337 * [18] CDSect ::= CDStart CData CDEnd 9838 * [18] CDSect ::= CDStart CData CDEnd
9338 * 9839 *
9339 * [19] CDStart ::= '<![CDATA[' 9840 * [19] CDStart ::= '<![CDATA['
9340 * 9841 *
9341 * [20] Data ::= (Char* - (Char* ']]>' Char*)) 9842 * [20] Data ::= (Char* - (Char* ']]>' Char*))
9342 * 9843 *
9343 * [21] CDEnd ::= ']]>' 9844 * [21] CDEnd ::= ']]>'
9344 */ 9845 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
9377 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); 9878 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
9378 if (buf == NULL) { 9879 if (buf == NULL) {
9379 xmlErrMemory(ctxt, NULL); 9880 xmlErrMemory(ctxt, NULL);
9380 return; 9881 return;
9381 } 9882 }
9382 while (IS_CHAR(cur) && 9883 while (IS_CHAR(cur) &&
9383 ((r != ']') || (s != ']') || (cur != '>'))) { 9884 ((r != ']') || (s != ']') || (cur != '>'))) {
9384 if (len + 5 >= size) { 9885 if (len + 5 >= size) {
9385 xmlChar *tmp; 9886 xmlChar *tmp;
9386 9887
9387 » size *= 2; 9888 if ((size > XML_MAX_TEXT_LENGTH) &&
9388 » tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 9889 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9890 xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED,
9891 "CData section too big found", NULL);
9892 xmlFree (buf);
9893 return;
9894 }
9895 » tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar));
9389 if (tmp == NULL) { 9896 if (tmp == NULL) {
9390 xmlFree(buf); 9897 xmlFree(buf);
9391 xmlErrMemory(ctxt, NULL); 9898 xmlErrMemory(ctxt, NULL);
9392 return; 9899 return;
9393 } 9900 }
9394 buf = tmp; 9901 buf = tmp;
9902 size *= 2;
9395 } 9903 }
9396 COPY_BUF(rl,buf,len,r); 9904 COPY_BUF(rl,buf,len,r);
9397 r = s; 9905 r = s;
9398 rl = sl; 9906 rl = sl;
9399 s = cur; 9907 s = cur;
9400 sl = l; 9908 sl = l;
9401 count++; 9909 count++;
9402 if (count > 50) { 9910 if (count > 50) {
9403 GROW; 9911 GROW;
9404 if (ctxt->instate == XML_PARSER_EOF) { 9912 if (ctxt->instate == XML_PARSER_EOF) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
9477 9985
9478 /* 9986 /*
9479 * Fourth case : a sub-element. 9987 * Fourth case : a sub-element.
9480 */ 9988 */
9481 else if (*cur == '<') { 9989 else if (*cur == '<') {
9482 xmlParseElement(ctxt); 9990 xmlParseElement(ctxt);
9483 } 9991 }
9484 9992
9485 /* 9993 /*
9486 * Fifth case : a reference. If if has not been resolved, 9994 * Fifth case : a reference. If if has not been resolved,
9487 » * parsing returns it's Name, create the node 9995 » * parsing returns it's Name, create the node
9488 */ 9996 */
9489 9997
9490 else if (*cur == '&') { 9998 else if (*cur == '&') {
9491 xmlParseReference(ctxt); 9999 xmlParseReference(ctxt);
9492 } 10000 }
9493 10001
9494 /* 10002 /*
9495 * Last case, text. Note that References are handled directly. 10003 * Last case, text. Note that References are handled directly.
9496 */ 10004 */
9497 else { 10005 else {
(...skipping 20 matching lines...) Expand all
9518 /** 10026 /**
9519 * xmlParseElement: 10027 * xmlParseElement:
9520 * @ctxt: an XML parser context 10028 * @ctxt: an XML parser context
9521 * 10029 *
9522 * parse an XML element, this is highly recursive 10030 * parse an XML element, this is highly recursive
9523 * 10031 *
9524 * [39] element ::= EmptyElemTag | STag content ETag 10032 * [39] element ::= EmptyElemTag | STag content ETag
9525 * 10033 *
9526 * [ WFC: Element Type Match ] 10034 * [ WFC: Element Type Match ]
9527 * The Name in an element's end-tag must match the element type in the 10035 * The Name in an element's end-tag must match the element type in the
9528 * start-tag. 10036 * start-tag.
9529 * 10037 *
9530 */ 10038 */
9531 10039
9532 void 10040 void
9533 xmlParseElement(xmlParserCtxtPtr ctxt) { 10041 xmlParseElement(xmlParserCtxtPtr ctxt) {
9534 const xmlChar *name; 10042 const xmlChar *name;
9535 const xmlChar *prefix = NULL; 10043 const xmlChar *prefix = NULL;
9536 const xmlChar *URI = NULL; 10044 const xmlChar *URI = NULL;
9537 xmlParserNodeInfo node_info; 10045 xmlParserNodeInfo node_info;
9538 int line, tlen; 10046 int line, tlen = 0;
9539 xmlNodePtr ret; 10047 xmlNodePtr ret;
9540 int nsNr = ctxt->nsNr; 10048 int nsNr = ctxt->nsNr;
9541 10049
9542 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) && 10050 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) &&
9543 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 10051 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9544 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, 10052 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
9545 "Excessive depth in document: %d use XML_PARSE_HUGE option\n", 10053 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
9546 xmlParserMaxDepth); 10054 xmlParserMaxDepth);
9547 ctxt->instate = XML_PARSER_EOF; 10055 ctxt->instate = XML_PARSER_EOF;
9548 return; 10056 return;
(...skipping 28 matching lines...) Expand all
9577 spacePop(ctxt); 10085 spacePop(ctxt);
9578 return; 10086 return;
9579 } 10087 }
9580 namePush(ctxt, name); 10088 namePush(ctxt, name);
9581 ret = ctxt->node; 10089 ret = ctxt->node;
9582 10090
9583 #ifdef LIBXML_VALID_ENABLED 10091 #ifdef LIBXML_VALID_ENABLED
9584 /* 10092 /*
9585 * [ VC: Root Element Type ] 10093 * [ VC: Root Element Type ]
9586 * The Name in the document type declaration must match the element 10094 * The Name in the document type declaration must match the element
9587 * type of the root element. 10095 * type of the root element.
9588 */ 10096 */
9589 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && 10097 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
9590 ctxt->node && (ctxt->node == ctxt->myDoc->children)) 10098 ctxt->node && (ctxt->node == ctxt->myDoc->children))
9591 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); 10099 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
9592 #endif /* LIBXML_VALID_ENABLED */ 10100 #endif /* LIBXML_VALID_ENABLED */
9593 10101
9594 /* 10102 /*
9595 * Check for an Empty Element. 10103 * Check for an Empty Element.
9596 */ 10104 */
9597 if ((RAW == '/') && (NXT(1) == '>')) { 10105 if ((RAW == '/') && (NXT(1) == '>')) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
9860 buf[len] = 0; 10368 buf[len] = 0;
9861 } else { 10369 } else {
9862 xmlFatalErr(ctxt, XML_ERR_ENCODING_NAME, NULL); 10370 xmlFatalErr(ctxt, XML_ERR_ENCODING_NAME, NULL);
9863 } 10371 }
9864 return(buf); 10372 return(buf);
9865 } 10373 }
9866 10374
9867 /** 10375 /**
9868 * xmlParseEncodingDecl: 10376 * xmlParseEncodingDecl:
9869 * @ctxt: an XML parser context 10377 * @ctxt: an XML parser context
9870 * 10378 *
9871 * parse the XML encoding declaration 10379 * parse the XML encoding declaration
9872 * 10380 *
9873 * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'") 10381 * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'")
9874 * 10382 *
9875 * this setups the conversion filters. 10383 * this setups the conversion filters.
9876 * 10384 *
9877 * Returns the encoding value or NULL 10385 * Returns the encoding value or NULL
9878 */ 10386 */
9879 10387
9880 const xmlChar * 10388 const xmlChar *
(...skipping 20 matching lines...) Expand all
9901 } else if (RAW == '\''){ 10409 } else if (RAW == '\''){
9902 NEXT; 10410 NEXT;
9903 encoding = xmlParseEncName(ctxt); 10411 encoding = xmlParseEncName(ctxt);
9904 if (RAW != '\'') { 10412 if (RAW != '\'') {
9905 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); 10413 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
9906 } else 10414 } else
9907 NEXT; 10415 NEXT;
9908 } else { 10416 } else {
9909 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); 10417 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL);
9910 } 10418 }
10419
10420 /*
10421 * Non standard parsing, allowing the user to ignore encoding
10422 */
10423 if (ctxt->options & XML_PARSE_IGNORE_ENC) {
10424 xmlFree((xmlChar *) encoding);
10425 return(NULL);
10426 }
10427
9911 /* 10428 /*
9912 * UTF-16 encoding stwich has already taken place at this stage, 10429 * UTF-16 encoding stwich has already taken place at this stage,
9913 * more over the little-endian/big-endian selection is already done 10430 * more over the little-endian/big-endian selection is already done
9914 */ 10431 */
9915 if ((encoding != NULL) && 10432 if ((encoding != NULL) &&
9916 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) || 10433 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) ||
9917 (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) { 10434 (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) {
9918 /* 10435 /*
9919 * If no encoding was passed to the parser, that we are 10436 * If no encoding was passed to the parser, that we are
9920 » * using UTF-16 and no decoder is present i.e. the 10437 » * using UTF-16 and no decoder is present i.e. the
9921 * document is apparently UTF-8 compatible, then raise an 10438 * document is apparently UTF-8 compatible, then raise an
9922 * encoding mismatch fatal error 10439 * encoding mismatch fatal error
9923 */ 10440 */
9924 if ((ctxt->encoding == NULL) && 10441 if ((ctxt->encoding == NULL) &&
9925 (ctxt->input->buf != NULL) && 10442 (ctxt->input->buf != NULL) &&
9926 (ctxt->input->buf->encoder == NULL)) { 10443 (ctxt->input->buf->encoder == NULL)) {
9927 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_ENCODING, 10444 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_ENCODING,
9928 "Document labelled UTF-16 but has UTF-8 content\n"); 10445 "Document labelled UTF-16 but has UTF-8 content\n");
9929 } 10446 }
9930 if (ctxt->encoding != NULL) 10447 if (ctxt->encoding != NULL)
(...skipping 30 matching lines...) Expand all
9961 return(encoding); 10478 return(encoding);
9962 } 10479 }
9963 10480
9964 /** 10481 /**
9965 * xmlParseSDDecl: 10482 * xmlParseSDDecl:
9966 * @ctxt: an XML parser context 10483 * @ctxt: an XML parser context
9967 * 10484 *
9968 * parse the XML standalone declaration 10485 * parse the XML standalone declaration
9969 * 10486 *
9970 * [32] SDDecl ::= S 'standalone' Eq 10487 * [32] SDDecl ::= S 'standalone' Eq
9971 * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) 10488 * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))
9972 * 10489 *
9973 * [ VC: Standalone Document Declaration ] 10490 * [ VC: Standalone Document Declaration ]
9974 * TODO The standalone document declaration must have the value "no" 10491 * TODO The standalone document declaration must have the value "no"
9975 * if any external markup declarations contain declarations of: 10492 * if any external markup declarations contain declarations of:
9976 * - attributes with default values, if elements to which these 10493 * - attributes with default values, if elements to which these
9977 * attributes apply appear in the document without specifications 10494 * attributes apply appear in the document without specifications
9978 * of values for these attributes, or 10495 * of values for these attributes, or
9979 * - entities (other than amp, lt, gt, apos, quot), if references 10496 * - entities (other than amp, lt, gt, apos, quot), if references
9980 * to those entities appear in the document, or 10497 * to those entities appear in the document, or
9981 * - attributes with values subject to normalization, where the 10498 * - attributes with values subject to normalization, where the
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
10041 } else { 10558 } else {
10042 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); 10559 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL);
10043 } 10560 }
10044 } 10561 }
10045 return(standalone); 10562 return(standalone);
10046 } 10563 }
10047 10564
10048 /** 10565 /**
10049 * xmlParseXMLDecl: 10566 * xmlParseXMLDecl:
10050 * @ctxt: an XML parser context 10567 * @ctxt: an XML parser context
10051 * 10568 *
10052 * parse an XML declaration header 10569 * parse an XML declaration header
10053 * 10570 *
10054 * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' 10571 * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
10055 */ 10572 */
10056 10573
10057 void 10574 void
10058 xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { 10575 xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
10059 xmlChar *version; 10576 xmlChar *version;
10060 10577
10061 /* 10578 /*
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
10155 } else { 10672 } else {
10156 xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); 10673 xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL);
10157 MOVETO_ENDTAG(CUR_PTR); 10674 MOVETO_ENDTAG(CUR_PTR);
10158 NEXT; 10675 NEXT;
10159 } 10676 }
10160 } 10677 }
10161 10678
10162 /** 10679 /**
10163 * xmlParseMisc: 10680 * xmlParseMisc:
10164 * @ctxt: an XML parser context 10681 * @ctxt: an XML parser context
10165 * 10682 *
10166 * parse an XML Misc* optional field. 10683 * parse an XML Misc* optional field.
10167 * 10684 *
10168 * [27] Misc ::= Comment | PI | S 10685 * [27] Misc ::= Comment | PI | S
10169 */ 10686 */
10170 10687
10171 void 10688 void
10172 xmlParseMisc(xmlParserCtxtPtr ctxt) { 10689 xmlParseMisc(xmlParserCtxtPtr ctxt) {
10173 while ((ctxt->instate != XML_PARSER_EOF) && 10690 while ((ctxt->instate != XML_PARSER_EOF) &&
10174 (((RAW == '<') && (NXT(1) == '?')) || 10691 (((RAW == '<') && (NXT(1) == '?')) ||
10175 (CMP4(CUR_PTR, '<', '!', '-', '-')) || 10692 (CMP4(CUR_PTR, '<', '!', '-', '-')) ||
10176 IS_BLANK_CH(CUR))) { 10693 IS_BLANK_CH(CUR))) {
10177 if ((RAW == '<') && (NXT(1) == '?')) { 10694 if ((RAW == '<') && (NXT(1) == '?')) {
10178 xmlParsePI(ctxt); 10695 xmlParsePI(ctxt);
10179 } else if (IS_BLANK_CH(CUR)) { 10696 } else if (IS_BLANK_CH(CUR)) {
10180 NEXT; 10697 NEXT;
10181 } else 10698 } else
10182 xmlParseComment(ctxt); 10699 xmlParseComment(ctxt);
10183 } 10700 }
10184 } 10701 }
10185 10702
10186 /** 10703 /**
10187 * xmlParseDocument: 10704 * xmlParseDocument:
10188 * @ctxt: an XML parser context 10705 * @ctxt: an XML parser context
10189 * 10706 *
10190 * parse an XML document (and build a tree if using the standard SAX 10707 * parse an XML document (and build a tree if using the standard SAX
10191 * interface). 10708 * interface).
10192 * 10709 *
10193 * [1] document ::= prolog element Misc* 10710 * [1] document ::= prolog element Misc*
10194 * 10711 *
10195 * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? 10712 * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
10196 * 10713 *
10197 * Returns 0, -1 in case of error. the parser context is augmented 10714 * Returns 0, -1 in case of error. the parser context is augmented
10198 * as a result of the parsing. 10715 * as a result of the parsing.
10199 */ 10716 */
(...skipping 16 matching lines...) Expand all
10216 xmlDetectSAX2(ctxt); 10733 xmlDetectSAX2(ctxt);
10217 10734
10218 /* 10735 /*
10219 * SAX: beginning of the document processing. 10736 * SAX: beginning of the document processing.
10220 */ 10737 */
10221 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) 10738 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10222 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); 10739 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10223 if (ctxt->instate == XML_PARSER_EOF) 10740 if (ctxt->instate == XML_PARSER_EOF)
10224 return(-1); 10741 return(-1);
10225 10742
10226 if ((ctxt->encoding == (const xmlChar *)XML_CHAR_ENCODING_NONE) && 10743 if ((ctxt->encoding == NULL) &&
10227 ((ctxt->input->end - ctxt->input->cur) >= 4)) { 10744 ((ctxt->input->end - ctxt->input->cur) >= 4)) {
10228 » /* 10745 » /*
10229 * Get the 4 first bytes and decode the charset 10746 * Get the 4 first bytes and decode the charset
10230 * if enc != XML_CHAR_ENCODING_NONE 10747 * if enc != XML_CHAR_ENCODING_NONE
10231 * plug some encoding conversion routines. 10748 * plug some encoding conversion routines.
10232 */ 10749 */
10233 start[0] = RAW; 10750 start[0] = RAW;
10234 start[1] = NXT(1); 10751 start[1] = NXT(1);
10235 start[2] = NXT(2); 10752 start[2] = NXT(2);
10236 start[3] = NXT(3); 10753 start[3] = NXT(3);
10237 enc = xmlDetectCharEncoding(&start[0], 4); 10754 enc = xmlDetectCharEncoding(&start[0], 4);
10238 if (enc != XML_CHAR_ENCODING_NONE) { 10755 if (enc != XML_CHAR_ENCODING_NONE) {
(...skipping 29 matching lines...) Expand all
10268 } 10785 }
10269 ctxt->standalone = ctxt->input->standalone; 10786 ctxt->standalone = ctxt->input->standalone;
10270 SKIP_BLANKS; 10787 SKIP_BLANKS;
10271 } else { 10788 } else {
10272 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); 10789 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION);
10273 } 10790 }
10274 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) 10791 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
10275 ctxt->sax->startDocument(ctxt->userData); 10792 ctxt->sax->startDocument(ctxt->userData);
10276 if (ctxt->instate == XML_PARSER_EOF) 10793 if (ctxt->instate == XML_PARSER_EOF)
10277 return(-1); 10794 return(-1);
10795 if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
10796 (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
10797 ctxt->myDoc->compression = ctxt->input->buf->compressed;
10798 }
10278 10799
10279 /* 10800 /*
10280 * The Misc part of the Prolog 10801 * The Misc part of the Prolog
10281 */ 10802 */
10282 GROW; 10803 GROW;
10283 xmlParseMisc(ctxt); 10804 xmlParseMisc(ctxt);
10284 10805
10285 /* 10806 /*
10286 * Then possibly doc type declaration(s) and more Misc 10807 * Then possibly doc type declaration(s) and more Misc
10287 * (doctypedecl Misc*)? 10808 * (doctypedecl Misc*)?
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
10367 if (! ctxt->wellFormed) { 10888 if (! ctxt->wellFormed) {
10368 ctxt->valid = 0; 10889 ctxt->valid = 0;
10369 return(-1); 10890 return(-1);
10370 } 10891 }
10371 return(0); 10892 return(0);
10372 } 10893 }
10373 10894
10374 /** 10895 /**
10375 * xmlParseExtParsedEnt: 10896 * xmlParseExtParsedEnt:
10376 * @ctxt: an XML parser context 10897 * @ctxt: an XML parser context
10377 * 10898 *
10378 * parse a general parsed entity 10899 * parse a general parsed entity
10379 * An external general parsed entity is well-formed if it matches the 10900 * An external general parsed entity is well-formed if it matches the
10380 * production labeled extParsedEnt. 10901 * production labeled extParsedEnt.
10381 * 10902 *
10382 * [78] extParsedEnt ::= TextDecl? content 10903 * [78] extParsedEnt ::= TextDecl? content
10383 * 10904 *
10384 * Returns 0, -1 in case of error. the parser context is augmented 10905 * Returns 0, -1 in case of error. the parser context is augmented
10385 * as a result of the parsing. 10906 * as a result of the parsing.
10386 */ 10907 */
10387 10908
(...skipping 10 matching lines...) Expand all
10398 xmlDetectSAX2(ctxt); 10919 xmlDetectSAX2(ctxt);
10399 10920
10400 GROW; 10921 GROW;
10401 10922
10402 /* 10923 /*
10403 * SAX: beginning of the document processing. 10924 * SAX: beginning of the document processing.
10404 */ 10925 */
10405 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) 10926 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10406 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); 10927 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10407 10928
10408 /* 10929 /*
10409 * Get the 4 first bytes and decode the charset 10930 * Get the 4 first bytes and decode the charset
10410 * if enc != XML_CHAR_ENCODING_NONE 10931 * if enc != XML_CHAR_ENCODING_NONE
10411 * plug some encoding conversion routines. 10932 * plug some encoding conversion routines.
10412 */ 10933 */
10413 if ((ctxt->input->end - ctxt->input->cur) >= 4) { 10934 if ((ctxt->input->end - ctxt->input->cur) >= 4) {
10414 start[0] = RAW; 10935 start[0] = RAW;
10415 start[1] = NXT(1); 10936 start[1] = NXT(1);
10416 start[2] = NXT(2); 10937 start[2] = NXT(2);
10417 start[3] = NXT(3); 10938 start[3] = NXT(3);
10418 enc = xmlDetectCharEncoding(start, 4); 10939 enc = xmlDetectCharEncoding(start, 4);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
10455 * Doing validity checking on chunk doesn't make sense 10976 * Doing validity checking on chunk doesn't make sense
10456 */ 10977 */
10457 ctxt->instate = XML_PARSER_CONTENT; 10978 ctxt->instate = XML_PARSER_CONTENT;
10458 ctxt->validate = 0; 10979 ctxt->validate = 0;
10459 ctxt->loadsubset = 0; 10980 ctxt->loadsubset = 0;
10460 ctxt->depth = 0; 10981 ctxt->depth = 0;
10461 10982
10462 xmlParseContent(ctxt); 10983 xmlParseContent(ctxt);
10463 if (ctxt->instate == XML_PARSER_EOF) 10984 if (ctxt->instate == XML_PARSER_EOF)
10464 return(-1); 10985 return(-1);
10465 10986
10466 if ((RAW == '<') && (NXT(1) == '/')) { 10987 if ((RAW == '<') && (NXT(1) == '/')) {
10467 xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); 10988 xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL);
10468 } else if (RAW != 0) { 10989 } else if (RAW != 0) {
10469 xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); 10990 xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL);
10470 } 10991 }
10471 10992
10472 /* 10993 /*
10473 * SAX: end of the document processing. 10994 * SAX: end of the document processing.
10474 */ 10995 */
10475 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 10996 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10476 ctxt->sax->endDocument(ctxt->userData); 10997 ctxt->sax->endDocument(ctxt->userData);
10477 10998
10478 if (! ctxt->wellFormed) return(-1); 10999 if (! ctxt->wellFormed) return(-1);
10479 return(0); 11000 return(0);
10480 } 11001 }
10481 11002
10482 #ifdef LIBXML_PUSH_ENABLED 11003 #ifdef LIBXML_PUSH_ENABLED
10483 /************************************************************************ 11004 /************************************************************************
10484 * * 11005 * *
10485 * » » Progressive parsing interfaces» » » » * 11006 *» » Progressive parsing interfaces» » » » *
10486 * * 11007 * *
10487 ************************************************************************/ 11008 ************************************************************************/
10488 11009
10489 /** 11010 /**
10490 * xmlParseLookupSequence: 11011 * xmlParseLookupSequence:
10491 * @ctxt: an XML parser context 11012 * @ctxt: an XML parser context
10492 * @first: the first char to lookup 11013 * @first: the first char to lookup
10493 * @next: the next char to lookup or zero 11014 * @next: the next char to lookup or zero
10494 * @third: the next char to lookup or zero 11015 * @third: the next char to lookup or zero
10495 * 11016 *
(...skipping 16 matching lines...) Expand all
10512 in = ctxt->input; 11033 in = ctxt->input;
10513 if (in == NULL) return(-1); 11034 if (in == NULL) return(-1);
10514 base = in->cur - in->base; 11035 base = in->cur - in->base;
10515 if (base < 0) return(-1); 11036 if (base < 0) return(-1);
10516 if (ctxt->checkIndex > base) 11037 if (ctxt->checkIndex > base)
10517 base = ctxt->checkIndex; 11038 base = ctxt->checkIndex;
10518 if (in->buf == NULL) { 11039 if (in->buf == NULL) {
10519 buf = in->base; 11040 buf = in->base;
10520 len = in->length; 11041 len = in->length;
10521 } else { 11042 } else {
10522 » buf = in->buf->buffer->content; 11043 » buf = xmlBufContent(in->buf->buffer);
10523 » len = in->buf->buffer->use; 11044 » len = xmlBufUse(in->buf->buffer);
10524 } 11045 }
10525 /* take into account the sequence length */ 11046 /* take into account the sequence length */
10526 if (third) len -= 2; 11047 if (third) len -= 2;
10527 else if (next) len --; 11048 else if (next) len --;
10528 for (;base < len;base++) { 11049 for (;base < len;base++) {
10529 if (buf[base] == first) { 11050 if (buf[base] == first) {
10530 if (third != 0) { 11051 if (third != 0) {
10531 if ((buf[base + 1] != next) || 11052 if ((buf[base + 1] != next) ||
10532 (buf[base + 2] != third)) continue; 11053 (buf[base + 2] != third)) continue;
10533 } else if (next != 0) { 11054 } else if (next != 0) {
10534 if (buf[base + 1] != next) continue; 11055 if (buf[base + 1] != next) continue;
10535 } 11056 }
10536 ctxt->checkIndex = 0; 11057 ctxt->checkIndex = 0;
10537 #ifdef DEBUG_PUSH 11058 #ifdef DEBUG_PUSH
10538 if (next == 0) 11059 if (next == 0)
10539 xmlGenericError(xmlGenericErrorContext, 11060 xmlGenericError(xmlGenericErrorContext,
10540 "PP: lookup '%c' found at %d\n", 11061 "PP: lookup '%c' found at %d\n",
10541 first, base); 11062 first, base);
10542 else if (third == 0) 11063 else if (third == 0)
10543 xmlGenericError(xmlGenericErrorContext, 11064 xmlGenericError(xmlGenericErrorContext,
10544 "PP: lookup '%c%c' found at %d\n", 11065 "PP: lookup '%c%c' found at %d\n",
10545 first, next, base); 11066 first, next, base);
10546 » else 11067 » else
10547 xmlGenericError(xmlGenericErrorContext, 11068 xmlGenericError(xmlGenericErrorContext,
10548 "PP: lookup '%c%c%c' found at %d\n", 11069 "PP: lookup '%c%c%c' found at %d\n",
10549 first, next, third, base); 11070 first, next, third, base);
10550 #endif 11071 #endif
10551 return(base - (in->cur - in->base)); 11072 return(base - (in->cur - in->base));
10552 } 11073 }
10553 } 11074 }
10554 ctxt->checkIndex = base; 11075 ctxt->checkIndex = base;
10555 #ifdef DEBUG_PUSH 11076 #ifdef DEBUG_PUSH
10556 if (next == 0) 11077 if (next == 0)
10557 xmlGenericError(xmlGenericErrorContext, 11078 xmlGenericError(xmlGenericErrorContext,
10558 "PP: lookup '%c' failed\n", first); 11079 "PP: lookup '%c' failed\n", first);
10559 else if (third == 0) 11080 else if (third == 0)
10560 xmlGenericError(xmlGenericErrorContext, 11081 xmlGenericError(xmlGenericErrorContext,
10561 "PP: lookup '%c%c' failed\n", first, next); 11082 "PP: lookup '%c%c' failed\n", first, next);
10562 else» 11083 else
10563 xmlGenericError(xmlGenericErrorContext, 11084 xmlGenericError(xmlGenericErrorContext,
10564 "PP: lookup '%c%c%c' failed\n", first, next, third); 11085 "PP: lookup '%c%c%c' failed\n", first, next, third);
10565 #endif 11086 #endif
10566 return(-1); 11087 return(-1);
10567 } 11088 }
10568 11089
10569 /** 11090 /**
10570 * xmlParseGetLasts: 11091 * xmlParseGetLasts:
10571 * @ctxt: an XML parser context 11092 * @ctxt: an XML parser context
10572 * @lastlt: pointer to store the last '<' from the input 11093 * @lastlt: pointer to store the last '<' from the input
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
10634 * UTF-8 error occured otherwise 11155 * UTF-8 error occured otherwise
10635 */ 11156 */
10636 static int 11157 static int
10637 xmlCheckCdataPush(const xmlChar *utf, int len) { 11158 xmlCheckCdataPush(const xmlChar *utf, int len) {
10638 int ix; 11159 int ix;
10639 unsigned char c; 11160 unsigned char c;
10640 int codepoint; 11161 int codepoint;
10641 11162
10642 if ((utf == NULL) || (len <= 0)) 11163 if ((utf == NULL) || (len <= 0))
10643 return(0); 11164 return(0);
10644 11165
10645 for (ix = 0; ix < len;) { /* string is 0-terminated */ 11166 for (ix = 0; ix < len;) { /* string is 0-terminated */
10646 c = utf[ix]; 11167 c = utf[ix];
10647 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */ 11168 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */
10648 if (c >= 0x20) 11169 if (c >= 0x20)
10649 ix++; 11170 ix++;
10650 else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) 11171 else if ((c == 0xA) || (c == 0xD) || (c == 0x9))
10651 ix++; 11172 ix++;
10652 else 11173 else
10653 return(-ix); 11174 return(-ix);
10654 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ 11175 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
10766 (ctxt->input->cur - ctxt->input->base > 4096)) { 11287 (ctxt->input->cur - ctxt->input->base > 4096)) {
10767 xmlSHRINK(ctxt); 11288 xmlSHRINK(ctxt);
10768 ctxt->checkIndex = 0; 11289 ctxt->checkIndex = 0;
10769 } 11290 }
10770 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11291 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
10771 11292
10772 while (ctxt->instate != XML_PARSER_EOF) { 11293 while (ctxt->instate != XML_PARSER_EOF) {
10773 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 11294 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
10774 return(0); 11295 return(0);
10775 11296
10776 11297
10777 /* 11298 /*
10778 * Pop-up of finished entities. 11299 * Pop-up of finished entities.
10779 */ 11300 */
10780 while ((RAW == 0) && (ctxt->inputNr > 1)) 11301 while ((RAW == 0) && (ctxt->inputNr > 1))
10781 xmlPopInput(ctxt); 11302 xmlPopInput(ctxt);
10782 11303
10783 if (ctxt->input == NULL) break; 11304 if (ctxt->input == NULL) break;
10784 if (ctxt->input->buf == NULL) 11305 if (ctxt->input->buf == NULL)
10785 avail = ctxt->input->length - 11306 avail = ctxt->input->length -
10786 (ctxt->input->cur - ctxt->input->base); 11307 (ctxt->input->cur - ctxt->input->base);
10787 else { 11308 else {
10788 /* 11309 /*
10789 * If we are operating on converted input, try to flush 11310 * If we are operating on converted input, try to flush
10790 * remainng chars to avoid them stalling in the non-converted 11311 * remainng chars to avoid them stalling in the non-converted
10791 » * buffer. 11312 » * buffer. But do not do this in document start where
11313 » * encoding="..." may not have been read and we work on a
11314 » * guessed encoding.
10792 */ 11315 */
10793 » if ((ctxt->input->buf->raw != NULL) && 11316 » if ((ctxt->instate != XML_PARSER_START) &&
10794 » » (ctxt->input->buf->raw->use > 0)) { 11317 » (ctxt->input->buf->raw != NULL) &&
10795 » » int base = ctxt->input->base - 11318 » » (xmlBufIsEmpty(ctxt->input->buf->raw) == 0)) {
10796 » » ctxt->input->buf->buffer->content; 11319 size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
10797 » » int current = ctxt->input->cur - ctxt->input->base; 11320 ctxt->input);
11321 » » size_t current = ctxt->input->cur - ctxt->input->base;
10798 11322
10799 xmlParserInputBufferPush(ctxt->input->buf, 0, ""); 11323 xmlParserInputBufferPush(ctxt->input->buf, 0, "");
10800 » » ctxt->input->base = ctxt->input->buf->buffer->content + base; 11324 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
10801 » » ctxt->input->cur = ctxt->input->base + current; 11325 base, current);
10802 » » ctxt->input->end =
10803 » » &ctxt->input->buf->buffer->content[
10804 » » ctxt->input->buf->buffer->use];
10805 } 11326 }
10806 » avail = ctxt->input->buf->buffer->use - 11327 » avail = xmlBufUse(ctxt->input->buf->buffer) -
10807 (ctxt->input->cur - ctxt->input->base); 11328 (ctxt->input->cur - ctxt->input->base);
10808 } 11329 }
10809 if (avail < 1) 11330 if (avail < 1)
10810 goto done; 11331 goto done;
10811 switch (ctxt->instate) { 11332 switch (ctxt->instate) {
10812 case XML_PARSER_EOF: 11333 case XML_PARSER_EOF:
10813 /* 11334 /*
10814 * Document parsing is done ! 11335 * Document parsing is done !
10815 */ 11336 */
10816 goto done; 11337 goto done;
10817 case XML_PARSER_START: 11338 case XML_PARSER_START:
10818 if (ctxt->charset == XML_CHAR_ENCODING_NONE) { 11339 if (ctxt->charset == XML_CHAR_ENCODING_NONE) {
10819 xmlChar start[4]; 11340 xmlChar start[4];
10820 xmlCharEncoding enc; 11341 xmlCharEncoding enc;
10821 11342
10822 /* 11343 /*
10823 * Very first chars read from the document flow. 11344 * Very first chars read from the document flow.
10824 */ 11345 */
10825 if (avail < 4) 11346 if (avail < 4)
10826 goto done; 11347 goto done;
10827 11348
10828 » » /* 11349 » » /*
10829 * Get the 4 first bytes and decode the charset 11350 * Get the 4 first bytes and decode the charset
10830 * if enc != XML_CHAR_ENCODING_NONE 11351 * if enc != XML_CHAR_ENCODING_NONE
10831 * plug some encoding conversion routines, 11352 * plug some encoding conversion routines,
10832 * else xmlSwitchEncoding will set to (default) 11353 * else xmlSwitchEncoding will set to (default)
10833 * UTF8. 11354 * UTF8.
10834 */ 11355 */
10835 start[0] = RAW; 11356 start[0] = RAW;
10836 start[1] = NXT(1); 11357 start[1] = NXT(1);
10837 start[2] = NXT(2); 11358 start[2] = NXT(2);
10838 start[3] = NXT(3); 11359 start[3] = NXT(3);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
10973 spacePop(ctxt); 11494 spacePop(ctxt);
10974 ctxt->instate = XML_PARSER_EOF; 11495 ctxt->instate = XML_PARSER_EOF;
10975 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11496 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10976 ctxt->sax->endDocument(ctxt->userData); 11497 ctxt->sax->endDocument(ctxt->userData);
10977 goto done; 11498 goto done;
10978 } 11499 }
10979 #ifdef LIBXML_VALID_ENABLED 11500 #ifdef LIBXML_VALID_ENABLED
10980 /* 11501 /*
10981 * [ VC: Root Element Type ] 11502 * [ VC: Root Element Type ]
10982 * The Name in the document type declaration must match 11503 * The Name in the document type declaration must match
10983 » » * the element type of the root element. 11504 » » * the element type of the root element.
10984 */ 11505 */
10985 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && 11506 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
10986 ctxt->node && (ctxt->node == ctxt->myDoc->children)) 11507 ctxt->node && (ctxt->node == ctxt->myDoc->children))
10987 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); 11508 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
10988 #endif /* LIBXML_VALID_ENABLED */ 11509 #endif /* LIBXML_VALID_ENABLED */
10989 11510
10990 /* 11511 /*
10991 * Check for an Empty Element. 11512 * Check for an Empty Element.
10992 */ 11513 */
10993 if ((RAW == '/') && (NXT(1) == '>')) { 11514 if ((RAW == '/') && (NXT(1) == '>')) {
(...skipping 16 matching lines...) Expand all
11010 #endif /* LIBXML_SAX1_ENABLED */ 11531 #endif /* LIBXML_SAX1_ENABLED */
11011 } 11532 }
11012 if (ctxt->instate == XML_PARSER_EOF) 11533 if (ctxt->instate == XML_PARSER_EOF)
11013 goto done; 11534 goto done;
11014 spacePop(ctxt); 11535 spacePop(ctxt);
11015 if (ctxt->nameNr == 0) { 11536 if (ctxt->nameNr == 0) {
11016 ctxt->instate = XML_PARSER_EPILOG; 11537 ctxt->instate = XML_PARSER_EPILOG;
11017 } else { 11538 } else {
11018 ctxt->instate = XML_PARSER_CONTENT; 11539 ctxt->instate = XML_PARSER_CONTENT;
11019 } 11540 }
11541 ctxt->progressive = 1;
11020 break; 11542 break;
11021 } 11543 }
11022 if (RAW == '>') { 11544 if (RAW == '>') {
11023 NEXT; 11545 NEXT;
11024 } else { 11546 } else {
11025 xmlFatalErrMsgStr(ctxt, XML_ERR_GT_REQUIRED, 11547 xmlFatalErrMsgStr(ctxt, XML_ERR_GT_REQUIRED,
11026 "Couldn't find end of Start Tag %s\n", 11548 "Couldn't find end of Start Tag %s\n",
11027 name); 11549 name);
11028 nodePop(ctxt); 11550 nodePop(ctxt);
11029 spacePop(ctxt); 11551 spacePop(ctxt);
11030 } 11552 }
11031 if (ctxt->sax2) 11553 if (ctxt->sax2)
11032 nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr); 11554 nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr);
11033 #ifdef LIBXML_SAX1_ENABLED 11555 #ifdef LIBXML_SAX1_ENABLED
11034 else 11556 else
11035 namePush(ctxt, name); 11557 namePush(ctxt, name);
11036 #endif /* LIBXML_SAX1_ENABLED */ 11558 #endif /* LIBXML_SAX1_ENABLED */
11037 11559
11038 ctxt->instate = XML_PARSER_CONTENT; 11560 ctxt->instate = XML_PARSER_CONTENT;
11561 ctxt->progressive = 1;
11039 break; 11562 break;
11040 } 11563 }
11041 case XML_PARSER_CONTENT: { 11564 case XML_PARSER_CONTENT: {
11042 const xmlChar *test; 11565 const xmlChar *test;
11043 unsigned int cons; 11566 unsigned int cons;
11044 if ((avail < 2) && (ctxt->inputNr == 1)) 11567 if ((avail < 2) && (ctxt->inputNr == 1))
11045 goto done; 11568 goto done;
11046 cur = ctxt->input->cur[0]; 11569 cur = ctxt->input->cur[0];
11047 next = ctxt->input->cur[1]; 11570 next = ctxt->input->cur[1];
11048 11571
11049 test = CUR_PTR; 11572 test = CUR_PTR;
11050 cons = ctxt->input->consumed; 11573 cons = ctxt->input->consumed;
11051 if ((cur == '<') && (next == '/')) { 11574 if ((cur == '<') && (next == '/')) {
11052 ctxt->instate = XML_PARSER_END_TAG; 11575 ctxt->instate = XML_PARSER_END_TAG;
11053 break; 11576 break;
11054 } else if ((cur == '<') && (next == '?')) { 11577 } else if ((cur == '<') && (next == '?')) {
11055 if ((!terminate) && 11578 if ((!terminate) &&
11056 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11579 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11580 ctxt->progressive = XML_PARSER_PI;
11057 goto done; 11581 goto done;
11582 }
11058 xmlParsePI(ctxt); 11583 xmlParsePI(ctxt);
11584 ctxt->instate = XML_PARSER_CONTENT;
11585 ctxt->progressive = 1;
11059 } else if ((cur == '<') && (next != '!')) { 11586 } else if ((cur == '<') && (next != '!')) {
11060 ctxt->instate = XML_PARSER_START_TAG; 11587 ctxt->instate = XML_PARSER_START_TAG;
11061 break; 11588 break;
11062 } else if ((cur == '<') && (next == '!') && 11589 } else if ((cur == '<') && (next == '!') &&
11063 (ctxt->input->cur[2] == '-') && 11590 (ctxt->input->cur[2] == '-') &&
11064 (ctxt->input->cur[3] == '-')) { 11591 (ctxt->input->cur[3] == '-')) {
11065 int term; 11592 int term;
11066 11593
11067 if (avail < 4) 11594 if (avail < 4)
11068 goto done; 11595 goto done;
11069 ctxt->input->cur += 4; 11596 ctxt->input->cur += 4;
11070 term = xmlParseLookupSequence(ctxt, '-', '-', '>'); 11597 term = xmlParseLookupSequence(ctxt, '-', '-', '>');
11071 ctxt->input->cur -= 4; 11598 ctxt->input->cur -= 4;
11072 » » if ((!terminate) && (term < 0)) 11599 » » if ((!terminate) && (term < 0)) {
11600 ctxt->progressive = XML_PARSER_COMMENT;
11073 goto done; 11601 goto done;
11602 }
11074 xmlParseComment(ctxt); 11603 xmlParseComment(ctxt);
11075 ctxt->instate = XML_PARSER_CONTENT; 11604 ctxt->instate = XML_PARSER_CONTENT;
11605 ctxt->progressive = 1;
11076 } else if ((cur == '<') && (ctxt->input->cur[1] == '!') && 11606 } else if ((cur == '<') && (ctxt->input->cur[1] == '!') &&
11077 (ctxt->input->cur[2] == '[') && 11607 (ctxt->input->cur[2] == '[') &&
11078 (ctxt->input->cur[3] == 'C') && 11608 (ctxt->input->cur[3] == 'C') &&
11079 (ctxt->input->cur[4] == 'D') && 11609 (ctxt->input->cur[4] == 'D') &&
11080 (ctxt->input->cur[5] == 'A') && 11610 (ctxt->input->cur[5] == 'A') &&
11081 (ctxt->input->cur[6] == 'T') && 11611 (ctxt->input->cur[6] == 'T') &&
11082 (ctxt->input->cur[7] == 'A') && 11612 (ctxt->input->cur[7] == 'A') &&
11083 (ctxt->input->cur[8] == '[')) { 11613 (ctxt->input->cur[8] == '[')) {
11084 SKIP(9); 11614 SKIP(9);
11085 ctxt->instate = XML_PARSER_CDATA_SECTION; 11615 ctxt->instate = XML_PARSER_CDATA_SECTION;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
11160 if (ctxt->instate == XML_PARSER_EOF) { 11690 if (ctxt->instate == XML_PARSER_EOF) {
11161 /* Nothing */ 11691 /* Nothing */
11162 } else if (ctxt->nameNr == 0) { 11692 } else if (ctxt->nameNr == 0) {
11163 ctxt->instate = XML_PARSER_EPILOG; 11693 ctxt->instate = XML_PARSER_EPILOG;
11164 } else { 11694 } else {
11165 ctxt->instate = XML_PARSER_CONTENT; 11695 ctxt->instate = XML_PARSER_CONTENT;
11166 } 11696 }
11167 break; 11697 break;
11168 case XML_PARSER_CDATA_SECTION: { 11698 case XML_PARSER_CDATA_SECTION: {
11169 /* 11699 /*
11170 » » * The Push mode need to have the SAX callback for 11700 » » * The Push mode need to have the SAX callback for
11171 * cdataBlock merge back contiguous callbacks. 11701 * cdataBlock merge back contiguous callbacks.
11172 */ 11702 */
11173 int base; 11703 int base;
11174 11704
11175 base = xmlParseLookupSequence(ctxt, ']', ']', '>'); 11705 base = xmlParseLookupSequence(ctxt, ']', ']', '>');
11176 if (base < 0) { 11706 if (base < 0) {
11177 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { 11707 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) {
11178 int tmp; 11708 int tmp;
11179 11709
11180 » » » tmp = xmlCheckCdataPush(ctxt->input->cur, 11710 » » » tmp = xmlCheckCdataPush(ctxt->input->cur,
11181 XML_PARSER_BIG_BUFFER_SIZE); 11711 XML_PARSER_BIG_BUFFER_SIZE);
11182 if (tmp < 0) { 11712 if (tmp < 0) {
11183 tmp = -tmp; 11713 tmp = -tmp;
11184 ctxt->input->cur += tmp; 11714 ctxt->input->cur += tmp;
11185 goto encoding_error; 11715 goto encoding_error;
11186 } 11716 }
11187 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { 11717 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
11188 if (ctxt->sax->cdataBlock != NULL) 11718 if (ctxt->sax->cdataBlock != NULL)
11189 ctxt->sax->cdataBlock(ctxt->userData, 11719 ctxt->sax->cdataBlock(ctxt->userData,
11190 ctxt->input->cur, tmp); 11720 ctxt->input->cur, tmp);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
11240 #endif 11770 #endif
11241 } 11771 }
11242 break; 11772 break;
11243 } 11773 }
11244 case XML_PARSER_MISC: 11774 case XML_PARSER_MISC:
11245 SKIP_BLANKS; 11775 SKIP_BLANKS;
11246 if (ctxt->input->buf == NULL) 11776 if (ctxt->input->buf == NULL)
11247 avail = ctxt->input->length - 11777 avail = ctxt->input->length -
11248 (ctxt->input->cur - ctxt->input->base); 11778 (ctxt->input->cur - ctxt->input->base);
11249 else 11779 else
11250 » » avail = ctxt->input->buf->buffer->use - 11780 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11251 (ctxt->input->cur - ctxt->input->base); 11781 (ctxt->input->cur - ctxt->input->base);
11252 if (avail < 2) 11782 if (avail < 2)
11253 goto done; 11783 goto done;
11254 cur = ctxt->input->cur[0]; 11784 cur = ctxt->input->cur[0];
11255 next = ctxt->input->cur[1]; 11785 next = ctxt->input->cur[1];
11256 if ((cur == '<') && (next == '?')) { 11786 if ((cur == '<') && (next == '?')) {
11257 if ((!terminate) && 11787 if ((!terminate) &&
11258 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11788 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11789 ctxt->progressive = XML_PARSER_PI;
11259 goto done; 11790 goto done;
11791 }
11260 #ifdef DEBUG_PUSH 11792 #ifdef DEBUG_PUSH
11261 xmlGenericError(xmlGenericErrorContext, 11793 xmlGenericError(xmlGenericErrorContext,
11262 "PP: Parsing PI\n"); 11794 "PP: Parsing PI\n");
11263 #endif 11795 #endif
11264 xmlParsePI(ctxt); 11796 xmlParsePI(ctxt);
11265 if (ctxt->instate == XML_PARSER_EOF) 11797 if (ctxt->instate == XML_PARSER_EOF)
11266 goto done; 11798 goto done;
11799 ctxt->instate = XML_PARSER_MISC;
11800 ctxt->progressive = 1;
11267 ctxt->checkIndex = 0; 11801 ctxt->checkIndex = 0;
11268 } else if ((cur == '<') && (next == '!') && 11802 } else if ((cur == '<') && (next == '!') &&
11269 (ctxt->input->cur[2] == '-') && 11803 (ctxt->input->cur[2] == '-') &&
11270 (ctxt->input->cur[3] == '-')) { 11804 (ctxt->input->cur[3] == '-')) {
11271 if ((!terminate) && 11805 if ((!terminate) &&
11272 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11806 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11807 ctxt->progressive = XML_PARSER_COMMENT;
11273 goto done; 11808 goto done;
11809 }
11274 #ifdef DEBUG_PUSH 11810 #ifdef DEBUG_PUSH
11275 xmlGenericError(xmlGenericErrorContext, 11811 xmlGenericError(xmlGenericErrorContext,
11276 "PP: Parsing Comment\n"); 11812 "PP: Parsing Comment\n");
11277 #endif 11813 #endif
11278 xmlParseComment(ctxt); 11814 xmlParseComment(ctxt);
11279 if (ctxt->instate == XML_PARSER_EOF) 11815 if (ctxt->instate == XML_PARSER_EOF)
11280 goto done; 11816 goto done;
11281 ctxt->instate = XML_PARSER_MISC; 11817 ctxt->instate = XML_PARSER_MISC;
11818 ctxt->progressive = 1;
11282 ctxt->checkIndex = 0; 11819 ctxt->checkIndex = 0;
11283 } else if ((cur == '<') && (next == '!') && 11820 } else if ((cur == '<') && (next == '!') &&
11284 (ctxt->input->cur[2] == 'D') && 11821 (ctxt->input->cur[2] == 'D') &&
11285 (ctxt->input->cur[3] == 'O') && 11822 (ctxt->input->cur[3] == 'O') &&
11286 (ctxt->input->cur[4] == 'C') && 11823 (ctxt->input->cur[4] == 'C') &&
11287 (ctxt->input->cur[5] == 'T') && 11824 (ctxt->input->cur[5] == 'T') &&
11288 (ctxt->input->cur[6] == 'Y') && 11825 (ctxt->input->cur[6] == 'Y') &&
11289 (ctxt->input->cur[7] == 'P') && 11826 (ctxt->input->cur[7] == 'P') &&
11290 (ctxt->input->cur[8] == 'E')) { 11827 (ctxt->input->cur[8] == 'E')) {
11291 if ((!terminate) && 11828 if ((!terminate) &&
11292 » » (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) 11829 » » (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) {
11830 ctxt->progressive = XML_PARSER_DTD;
11293 goto done; 11831 goto done;
11832 }
11294 #ifdef DEBUG_PUSH 11833 #ifdef DEBUG_PUSH
11295 xmlGenericError(xmlGenericErrorContext, 11834 xmlGenericError(xmlGenericErrorContext,
11296 "PP: Parsing internal subset\n"); 11835 "PP: Parsing internal subset\n");
11297 #endif 11836 #endif
11298 ctxt->inSubset = 1; 11837 ctxt->inSubset = 1;
11838 ctxt->progressive = 0;
11839 ctxt->checkIndex = 0;
11299 xmlParseDocTypeDecl(ctxt); 11840 xmlParseDocTypeDecl(ctxt);
11300 if (ctxt->instate == XML_PARSER_EOF) 11841 if (ctxt->instate == XML_PARSER_EOF)
11301 goto done; 11842 goto done;
11302 if (RAW == '[') { 11843 if (RAW == '[') {
11303 ctxt->instate = XML_PARSER_DTD; 11844 ctxt->instate = XML_PARSER_DTD;
11304 #ifdef DEBUG_PUSH 11845 #ifdef DEBUG_PUSH
11305 xmlGenericError(xmlGenericErrorContext, 11846 xmlGenericError(xmlGenericErrorContext,
11306 "PP: entering DTD\n"); 11847 "PP: entering DTD\n");
11307 #endif 11848 #endif
11308 } else { 11849 } else {
(...skipping 12 matching lines...) Expand all
11321 #ifdef DEBUG_PUSH 11862 #ifdef DEBUG_PUSH
11322 xmlGenericError(xmlGenericErrorContext, 11863 xmlGenericError(xmlGenericErrorContext,
11323 "PP: entering PROLOG\n"); 11864 "PP: entering PROLOG\n");
11324 #endif 11865 #endif
11325 } 11866 }
11326 } else if ((cur == '<') && (next == '!') && 11867 } else if ((cur == '<') && (next == '!') &&
11327 (avail < 9)) { 11868 (avail < 9)) {
11328 goto done; 11869 goto done;
11329 } else { 11870 } else {
11330 ctxt->instate = XML_PARSER_START_TAG; 11871 ctxt->instate = XML_PARSER_START_TAG;
11331 » » ctxt->progressive = 1; 11872 » » ctxt->progressive = XML_PARSER_START_TAG;
11332 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11873 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
11333 #ifdef DEBUG_PUSH 11874 #ifdef DEBUG_PUSH
11334 xmlGenericError(xmlGenericErrorContext, 11875 xmlGenericError(xmlGenericErrorContext,
11335 "PP: entering START_TAG\n"); 11876 "PP: entering START_TAG\n");
11336 #endif 11877 #endif
11337 } 11878 }
11338 break; 11879 break;
11339 case XML_PARSER_PROLOG: 11880 case XML_PARSER_PROLOG:
11340 SKIP_BLANKS; 11881 SKIP_BLANKS;
11341 if (ctxt->input->buf == NULL) 11882 if (ctxt->input->buf == NULL)
11342 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base); 11883 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base);
11343 else 11884 else
11344 » » avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); 11885 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11345 » » if (avail < 2) 11886 (ctxt->input->cur - ctxt->input->base);
11887 » » if (avail < 2)
11346 goto done; 11888 goto done;
11347 cur = ctxt->input->cur[0]; 11889 cur = ctxt->input->cur[0];
11348 next = ctxt->input->cur[1]; 11890 next = ctxt->input->cur[1];
11349 if ((cur == '<') && (next == '?')) { 11891 if ((cur == '<') && (next == '?')) {
11350 if ((!terminate) && 11892 if ((!terminate) &&
11351 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11893 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11894 ctxt->progressive = XML_PARSER_PI;
11352 goto done; 11895 goto done;
11896 }
11353 #ifdef DEBUG_PUSH 11897 #ifdef DEBUG_PUSH
11354 xmlGenericError(xmlGenericErrorContext, 11898 xmlGenericError(xmlGenericErrorContext,
11355 "PP: Parsing PI\n"); 11899 "PP: Parsing PI\n");
11356 #endif 11900 #endif
11357 xmlParsePI(ctxt); 11901 xmlParsePI(ctxt);
11358 if (ctxt->instate == XML_PARSER_EOF) 11902 if (ctxt->instate == XML_PARSER_EOF)
11359 goto done; 11903 goto done;
11904 ctxt->instate = XML_PARSER_PROLOG;
11905 ctxt->progressive = 1;
11360 } else if ((cur == '<') && (next == '!') && 11906 } else if ((cur == '<') && (next == '!') &&
11361 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) { 11907 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) {
11362 if ((!terminate) && 11908 if ((!terminate) &&
11363 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11909 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11910 ctxt->progressive = XML_PARSER_COMMENT;
11364 goto done; 11911 goto done;
11912 }
11365 #ifdef DEBUG_PUSH 11913 #ifdef DEBUG_PUSH
11366 xmlGenericError(xmlGenericErrorContext, 11914 xmlGenericError(xmlGenericErrorContext,
11367 "PP: Parsing Comment\n"); 11915 "PP: Parsing Comment\n");
11368 #endif 11916 #endif
11369 xmlParseComment(ctxt); 11917 xmlParseComment(ctxt);
11370 if (ctxt->instate == XML_PARSER_EOF) 11918 if (ctxt->instate == XML_PARSER_EOF)
11371 goto done; 11919 goto done;
11372 ctxt->instate = XML_PARSER_PROLOG; 11920 ctxt->instate = XML_PARSER_PROLOG;
11921 ctxt->progressive = 1;
11373 } else if ((cur == '<') && (next == '!') && 11922 } else if ((cur == '<') && (next == '!') &&
11374 (avail < 4)) { 11923 (avail < 4)) {
11375 goto done; 11924 goto done;
11376 } else { 11925 } else {
11377 ctxt->instate = XML_PARSER_START_TAG; 11926 ctxt->instate = XML_PARSER_START_TAG;
11378 if (ctxt->progressive == 0) 11927 if (ctxt->progressive == 0)
11379 » » » ctxt->progressive = 1; 11928 » » » ctxt->progressive = XML_PARSER_START_TAG;
11380 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11929 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
11381 #ifdef DEBUG_PUSH 11930 #ifdef DEBUG_PUSH
11382 xmlGenericError(xmlGenericErrorContext, 11931 xmlGenericError(xmlGenericErrorContext,
11383 "PP: entering START_TAG\n"); 11932 "PP: entering START_TAG\n");
11384 #endif 11933 #endif
11385 } 11934 }
11386 break; 11935 break;
11387 case XML_PARSER_EPILOG: 11936 case XML_PARSER_EPILOG:
11388 SKIP_BLANKS; 11937 SKIP_BLANKS;
11389 if (ctxt->input->buf == NULL) 11938 if (ctxt->input->buf == NULL)
11390 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base); 11939 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base);
11391 else 11940 else
11392 » » avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); 11941 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11942 (ctxt->input->cur - ctxt->input->base);
11393 if (avail < 2) 11943 if (avail < 2)
11394 goto done; 11944 goto done;
11395 cur = ctxt->input->cur[0]; 11945 cur = ctxt->input->cur[0];
11396 next = ctxt->input->cur[1]; 11946 next = ctxt->input->cur[1];
11397 if ((cur == '<') && (next == '?')) { 11947 if ((cur == '<') && (next == '?')) {
11398 if ((!terminate) && 11948 if ((!terminate) &&
11399 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11949 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11950 ctxt->progressive = XML_PARSER_PI;
11400 goto done; 11951 goto done;
11952 }
11401 #ifdef DEBUG_PUSH 11953 #ifdef DEBUG_PUSH
11402 xmlGenericError(xmlGenericErrorContext, 11954 xmlGenericError(xmlGenericErrorContext,
11403 "PP: Parsing PI\n"); 11955 "PP: Parsing PI\n");
11404 #endif 11956 #endif
11405 xmlParsePI(ctxt); 11957 xmlParsePI(ctxt);
11406 if (ctxt->instate == XML_PARSER_EOF) 11958 if (ctxt->instate == XML_PARSER_EOF)
11407 goto done; 11959 goto done;
11408 ctxt->instate = XML_PARSER_EPILOG; 11960 ctxt->instate = XML_PARSER_EPILOG;
11961 ctxt->progressive = 1;
11409 } else if ((cur == '<') && (next == '!') && 11962 } else if ((cur == '<') && (next == '!') &&
11410 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) { 11963 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) {
11411 if ((!terminate) && 11964 if ((!terminate) &&
11412 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11965 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11966 ctxt->progressive = XML_PARSER_COMMENT;
11413 goto done; 11967 goto done;
11968 }
11414 #ifdef DEBUG_PUSH 11969 #ifdef DEBUG_PUSH
11415 xmlGenericError(xmlGenericErrorContext, 11970 xmlGenericError(xmlGenericErrorContext,
11416 "PP: Parsing Comment\n"); 11971 "PP: Parsing Comment\n");
11417 #endif 11972 #endif
11418 xmlParseComment(ctxt); 11973 xmlParseComment(ctxt);
11419 if (ctxt->instate == XML_PARSER_EOF) 11974 if (ctxt->instate == XML_PARSER_EOF)
11420 goto done; 11975 goto done;
11421 ctxt->instate = XML_PARSER_EPILOG; 11976 ctxt->instate = XML_PARSER_EPILOG;
11977 ctxt->progressive = 1;
11422 } else if ((cur == '<') && (next == '!') && 11978 } else if ((cur == '<') && (next == '!') &&
11423 (avail < 4)) { 11979 (avail < 4)) {
11424 goto done; 11980 goto done;
11425 } else { 11981 } else {
11426 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 11982 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11427 ctxt->instate = XML_PARSER_EOF; 11983 ctxt->instate = XML_PARSER_EOF;
11428 #ifdef DEBUG_PUSH 11984 #ifdef DEBUG_PUSH
11429 xmlGenericError(xmlGenericErrorContext, 11985 xmlGenericError(xmlGenericErrorContext,
11430 "PP: entering EOF\n"); 11986 "PP: entering EOF\n");
11431 #endif 11987 #endif
11432 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11988 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11433 ctxt->sax->endDocument(ctxt->userData); 11989 ctxt->sax->endDocument(ctxt->userData);
11434 goto done; 11990 goto done;
11435 } 11991 }
11436 break; 11992 break;
11437 case XML_PARSER_DTD: { 11993 case XML_PARSER_DTD: {
11438 /* 11994 /*
11439 * Sorry but progressive parsing of the internal subset 11995 * Sorry but progressive parsing of the internal subset
11440 * is not expected to be supported. We first check that 11996 * is not expected to be supported. We first check that
11441 * the full content of the internal subset is available and 11997 * the full content of the internal subset is available and
11442 * the parsing is launched only at that point. 11998 * the parsing is launched only at that point.
11443 * Internal subset ends up with "']' S? '>'" in an unescaped 11999 * Internal subset ends up with "']' S? '>'" in an unescaped
11444 * section and not in a ']]>' sequence which are conditional 12000 * section and not in a ']]>' sequence which are conditional
11445 * sections (whoever argued to keep that crap in XML deserve 12001 * sections (whoever argued to keep that crap in XML deserve
11446 * a place in hell !). 12002 * a place in hell !).
11447 */ 12003 */
11448 int base, i; 12004 int base, i;
11449 xmlChar *buf; 12005 xmlChar *buf;
11450 xmlChar quote = 0; 12006 xmlChar quote = 0;
12007 size_t use;
11451 12008
11452 base = ctxt->input->cur - ctxt->input->base; 12009 base = ctxt->input->cur - ctxt->input->base;
11453 if (base < 0) return(0); 12010 if (base < 0) return(0);
11454 if (ctxt->checkIndex > base) 12011 if (ctxt->checkIndex > base)
11455 base = ctxt->checkIndex; 12012 base = ctxt->checkIndex;
11456 » » buf = ctxt->input->buf->buffer->content; 12013 » » buf = xmlBufContent(ctxt->input->buf->buffer);
11457 » » for (;(unsigned int) base < ctxt->input->buf->buffer->use; 12014 use = xmlBufUse(ctxt->input->buf->buffer);
11458 » » base++) { 12015 » » for (;(unsigned int) base < use; base++) {
11459 if (quote != 0) { 12016 if (quote != 0) {
11460 if (buf[base] == quote) 12017 if (buf[base] == quote)
11461 quote = 0; 12018 quote = 0;
11462 » » » continue; 12019 » » » continue;
11463 } 12020 }
11464 if ((quote == 0) && (buf[base] == '<')) { 12021 if ((quote == 0) && (buf[base] == '<')) {
11465 int found = 0; 12022 int found = 0;
11466 /* special handling of comments */ 12023 /* special handling of comments */
11467 » » if (((unsigned int) base + 4 < 12024 » » if (((unsigned int) base + 4 < use) &&
11468 » » » ctxt->input->buf->buffer->use) &&
11469 (buf[base + 1] == '!') && 12025 (buf[base + 1] == '!') &&
11470 (buf[base + 2] == '-') && 12026 (buf[base + 2] == '-') &&
11471 (buf[base + 3] == '-')) { 12027 (buf[base + 3] == '-')) {
11472 » » » for (;(unsigned int) base + 3 < 12028 » » » for (;(unsigned int) base + 3 < use; base++) {
11473 » » » ctxt->input->buf->buffer->use; base++) {
11474 if ((buf[base] == '-') && 12029 if ((buf[base] == '-') &&
11475 (buf[base + 1] == '-') && 12030 (buf[base + 1] == '-') &&
11476 (buf[base + 2] == '>')) { 12031 (buf[base + 2] == '>')) {
11477 found = 1; 12032 found = 1;
11478 base += 2; 12033 base += 2;
11479 break; 12034 break;
11480 } 12035 }
11481 } 12036 }
11482 if (!found) { 12037 if (!found) {
11483 #if 0 12038 #if 0
(...skipping 10 matching lines...) Expand all
11494 } 12049 }
11495 if (buf[base] == '\'') { 12050 if (buf[base] == '\'') {
11496 quote = '\''; 12051 quote = '\'';
11497 continue; 12052 continue;
11498 } 12053 }
11499 if (buf[base] == ']') { 12054 if (buf[base] == ']') {
11500 #if 0 12055 #if 0
11501 fprintf(stderr, "%c%c%c%c: ", buf[base], 12056 fprintf(stderr, "%c%c%c%c: ", buf[base],
11502 buf[base + 1], buf[base + 2], buf[base + 3]); 12057 buf[base + 1], buf[base + 2], buf[base + 3]);
11503 #endif 12058 #endif
11504 » » if ((unsigned int) base +1 >= 12059 » » if ((unsigned int) base +1 >= use)
11505 » » ctxt->input->buf->buffer->use)
11506 break; 12060 break;
11507 if (buf[base + 1] == ']') { 12061 if (buf[base + 1] == ']') {
11508 /* conditional crap, skip both ']' ! */ 12062 /* conditional crap, skip both ']' ! */
11509 base++; 12063 base++;
11510 continue; 12064 continue;
11511 } 12065 }
11512 » » for (i = 1; 12066 » » for (i = 1; (unsigned int) base + i < use; i++) {
11513 » » (unsigned int) base + i < ctxt->input->buf->buffer->use;
11514 » » i++) {
11515 if (buf[base + i] == '>') { 12067 if (buf[base + i] == '>') {
11516 #if 0 12068 #if 0
11517 fprintf(stderr, "found\n"); 12069 fprintf(stderr, "found\n");
11518 #endif 12070 #endif
11519 goto found_end_int_subset; 12071 goto found_end_int_subset;
11520 } 12072 }
11521 if (!IS_BLANK_CH(buf[base + i])) { 12073 if (!IS_BLANK_CH(buf[base + i])) {
11522 #if 0 12074 #if 0
11523 fprintf(stderr, "not found\n"); 12075 fprintf(stderr, "not found\n");
11524 #endif 12076 #endif
11525 goto not_end_of_int_subset; 12077 goto not_end_of_int_subset;
11526 } 12078 }
11527 } 12079 }
11528 #if 0 12080 #if 0
11529 fprintf(stderr, "end of stream\n"); 12081 fprintf(stderr, "end of stream\n");
11530 #endif 12082 #endif
11531 break; 12083 break;
11532 12084
11533 } 12085 }
11534 not_end_of_int_subset: 12086 not_end_of_int_subset:
11535 continue; /* for */ 12087 continue; /* for */
11536 } 12088 }
11537 /* 12089 /*
11538 * We didn't found the end of the Internal subset 12090 * We didn't found the end of the Internal subset
11539 */ 12091 */
12092 if (quote == 0)
12093 ctxt->checkIndex = base;
12094 else
12095 ctxt->checkIndex = 0;
11540 #ifdef DEBUG_PUSH 12096 #ifdef DEBUG_PUSH
11541 if (next == 0) 12097 if (next == 0)
11542 xmlGenericError(xmlGenericErrorContext, 12098 xmlGenericError(xmlGenericErrorContext,
11543 "PP: lookup of int subset end filed\n"); 12099 "PP: lookup of int subset end filed\n");
11544 #endif 12100 #endif
11545 goto done; 12101 goto done;
11546 12102
11547 found_end_int_subset: 12103 found_end_int_subset:
12104 ctxt->checkIndex = 0;
11548 xmlParseInternalSubset(ctxt); 12105 xmlParseInternalSubset(ctxt);
11549 if (ctxt->instate == XML_PARSER_EOF) 12106 if (ctxt->instate == XML_PARSER_EOF)
11550 goto done; 12107 goto done;
11551 ctxt->inSubset = 2; 12108 ctxt->inSubset = 2;
11552 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 12109 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
11553 (ctxt->sax->externalSubset != NULL)) 12110 (ctxt->sax->externalSubset != NULL))
11554 ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, 12111 ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName,
11555 ctxt->extSubSystem, ctxt->extSubURI); 12112 ctxt->extSubSystem, ctxt->extSubURI);
11556 ctxt->inSubset = 0; 12113 ctxt->inSubset = 0;
11557 xmlCleanSpecialAttr(ctxt); 12114 xmlCleanSpecialAttr(ctxt);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
11632 xmlGenericError(xmlGenericErrorContext, 12189 xmlGenericError(xmlGenericErrorContext,
11633 "PP: internal error, state == PUBLIC_LITERAL\n"); 12190 "PP: internal error, state == PUBLIC_LITERAL\n");
11634 ctxt->instate = XML_PARSER_START_TAG; 12191 ctxt->instate = XML_PARSER_START_TAG;
11635 #ifdef DEBUG_PUSH 12192 #ifdef DEBUG_PUSH
11636 xmlGenericError(xmlGenericErrorContext, 12193 xmlGenericError(xmlGenericErrorContext,
11637 "PP: entering START_TAG\n"); 12194 "PP: entering START_TAG\n");
11638 #endif 12195 #endif
11639 break; 12196 break;
11640 } 12197 }
11641 } 12198 }
11642 done: 12199 done:
11643 #ifdef DEBUG_PUSH 12200 #ifdef DEBUG_PUSH
11644 xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret); 12201 xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret);
11645 #endif 12202 #endif
11646 return(ret); 12203 return(ret);
11647 encoding_error: 12204 encoding_error:
11648 { 12205 {
11649 char buffer[150]; 12206 char buffer[150];
11650 12207
11651 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", 12208 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
11652 ctxt->input->cur[0], ctxt->input->cur[1], 12209 ctxt->input->cur[0], ctxt->input->cur[1],
11653 ctxt->input->cur[2], ctxt->input->cur[3]); 12210 ctxt->input->cur[2], ctxt->input->cur[3]);
11654 __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR, 12211 __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
11655 "Input is not proper UTF-8, indicate encoding !\n%s", 12212 "Input is not proper UTF-8, indicate encoding !\n%s",
11656 BAD_CAST buffer, NULL); 12213 BAD_CAST buffer, NULL);
11657 } 12214 }
11658 return(0); 12215 return(0);
11659 } 12216 }
11660 12217
11661 /** 12218 /**
12219 * xmlParseCheckTransition:
12220 * @ctxt: an XML parser context
12221 * @chunk: a char array
12222 * @size: the size in byte of the chunk
12223 *
12224 * Check depending on the current parser state if the chunk given must be
12225 * processed immediately or one need more data to advance on parsing.
12226 *
12227 * Returns -1 in case of error, 0 if the push is not needed and 1 if needed
12228 */
12229 static int
12230 xmlParseCheckTransition(xmlParserCtxtPtr ctxt, const char *chunk, int size) {
12231 if ((ctxt == NULL) || (chunk == NULL) || (size < 0))
12232 return(-1);
12233 if (ctxt->instate == XML_PARSER_START_TAG) {
12234 if (memchr(chunk, '>', size) != NULL)
12235 return(1);
12236 return(0);
12237 }
12238 if (ctxt->progressive == XML_PARSER_COMMENT) {
12239 if (memchr(chunk, '>', size) != NULL)
12240 return(1);
12241 return(0);
12242 }
12243 if (ctxt->instate == XML_PARSER_CDATA_SECTION) {
12244 if (memchr(chunk, '>', size) != NULL)
12245 return(1);
12246 return(0);
12247 }
12248 if (ctxt->progressive == XML_PARSER_PI) {
12249 if (memchr(chunk, '>', size) != NULL)
12250 return(1);
12251 return(0);
12252 }
12253 if (ctxt->instate == XML_PARSER_END_TAG) {
12254 if (memchr(chunk, '>', size) != NULL)
12255 return(1);
12256 return(0);
12257 }
12258 if ((ctxt->progressive == XML_PARSER_DTD) ||
12259 (ctxt->instate == XML_PARSER_DTD)) {
12260 if (memchr(chunk, '>', size) != NULL)
12261 return(1);
12262 return(0);
12263 }
12264 return(1);
12265 }
12266
12267 /**
11662 * xmlParseChunk: 12268 * xmlParseChunk:
11663 * @ctxt: an XML parser context 12269 * @ctxt: an XML parser context
11664 * @chunk: an char array 12270 * @chunk: an char array
11665 * @size: the size in byte of the chunk 12271 * @size: the size in byte of the chunk
11666 * @terminate: last chunk indicator 12272 * @terminate: last chunk indicator
11667 * 12273 *
11668 * Parse a Chunk of memory 12274 * Parse a Chunk of memory
11669 * 12275 *
11670 * Returns zero if no error, the xmlParserErrors otherwise. 12276 * Returns zero if no error, the xmlParserErrors otherwise.
11671 */ 12277 */
11672 int 12278 int
11673 xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, 12279 xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
11674 int terminate) { 12280 int terminate) {
11675 int end_in_lf = 0; 12281 int end_in_lf = 0;
11676 int remain = 0; 12282 int remain = 0;
12283 size_t old_avail = 0;
12284 size_t avail = 0;
11677 12285
11678 if (ctxt == NULL) 12286 if (ctxt == NULL)
11679 return(XML_ERR_INTERNAL_ERROR); 12287 return(XML_ERR_INTERNAL_ERROR);
11680 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 12288 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
11681 return(ctxt->errNo); 12289 return(ctxt->errNo);
11682 if (ctxt->instate == XML_PARSER_EOF) 12290 if (ctxt->instate == XML_PARSER_EOF)
11683 return(-1); 12291 return(-1);
11684 if (ctxt->instate == XML_PARSER_START) 12292 if (ctxt->instate == XML_PARSER_START)
11685 xmlDetectSAX2(ctxt); 12293 xmlDetectSAX2(ctxt);
11686 if ((size > 0) && (chunk != NULL) && (!terminate) && 12294 if ((size > 0) && (chunk != NULL) && (!terminate) &&
11687 (chunk[size - 1] == '\r')) { 12295 (chunk[size - 1] == '\r')) {
11688 end_in_lf = 1; 12296 end_in_lf = 1;
11689 size--; 12297 size--;
11690 } 12298 }
11691 12299
11692 xmldecl_done: 12300 xmldecl_done:
11693 12301
11694 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && 12302 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
11695 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { 12303 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
11696 » int base = ctxt->input->base - ctxt->input->buf->buffer->content; 12304 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
11697 » int cur = ctxt->input->cur - ctxt->input->base; 12305 » size_t cur = ctxt->input->cur - ctxt->input->base;
11698 int res; 12306 int res;
11699 12307
12308 old_avail = xmlBufUse(ctxt->input->buf->buffer);
11700 /* 12309 /*
11701 * Specific handling if we autodetected an encoding, we should not 12310 * Specific handling if we autodetected an encoding, we should not
11702 * push more than the first line ... which depend on the encoding 12311 * push more than the first line ... which depend on the encoding
11703 * And only push the rest once the final encoding was detected 12312 * And only push the rest once the final encoding was detected
11704 */ 12313 */
11705 if ((ctxt->instate == XML_PARSER_START) && (ctxt->input != NULL) && 12314 if ((ctxt->instate == XML_PARSER_START) && (ctxt->input != NULL) &&
11706 (ctxt->input->buf != NULL) && (ctxt->input->buf->encoder != NULL)) { 12315 (ctxt->input->buf != NULL) && (ctxt->input->buf->encoder != NULL)) {
11707 unsigned int len = 45; 12316 unsigned int len = 45;
11708 12317
11709 if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12318 if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11710 BAD_CAST "UTF-16")) || 12319 BAD_CAST "UTF-16")) ||
11711 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12320 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11712 BAD_CAST "UTF16"))) 12321 BAD_CAST "UTF16")))
11713 len = 90; 12322 len = 90;
11714 else if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12323 else if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11715 BAD_CAST "UCS-4")) || 12324 BAD_CAST "UCS-4")) ||
11716 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12325 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11717 BAD_CAST "UCS4"))) 12326 BAD_CAST "UCS4")))
11718 len = 180; 12327 len = 180;
11719 12328
11720 if (ctxt->input->buf->rawconsumed < len) 12329 if (ctxt->input->buf->rawconsumed < len)
11721 len -= ctxt->input->buf->rawconsumed; 12330 len -= ctxt->input->buf->rawconsumed;
11722 12331
11723 /* 12332 /*
11724 * Change size for reading the initial declaration only 12333 * Change size for reading the initial declaration only
11725 * if size is greater than len. Otherwise, memmove in xmlBufferAdd 12334 * if size is greater than len. Otherwise, memmove in xmlBufferAdd
11726 * will blindly copy extra bytes from memory. 12335 * will blindly copy extra bytes from memory.
11727 */ 12336 */
11728 if (size > len) { 12337 if ((unsigned int) size > len) {
11729 remain = size - len; 12338 remain = size - len;
11730 size = len; 12339 size = len;
11731 } else { 12340 } else {
11732 remain = 0; 12341 remain = 0;
11733 } 12342 }
11734 } 12343 }
11735 » res =xmlParserInputBufferPush(ctxt->input->buf, size, chunk); 12344 » res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
11736 if (res < 0) { 12345 if (res < 0) {
11737 ctxt->errNo = XML_PARSER_EOF; 12346 ctxt->errNo = XML_PARSER_EOF;
11738 ctxt->disableSAX = 1; 12347 ctxt->disableSAX = 1;
11739 return (XML_PARSER_EOF); 12348 return (XML_PARSER_EOF);
11740 } 12349 }
11741 » ctxt->input->base = ctxt->input->buf->buffer->content + base; 12350 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
11742 » ctxt->input->cur = ctxt->input->base + cur;
11743 » ctxt->input->end =
11744 » &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use];
11745 #ifdef DEBUG_PUSH 12351 #ifdef DEBUG_PUSH
11746 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 12352 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
11747 #endif 12353 #endif
11748 12354
11749 } else if (ctxt->instate != XML_PARSER_EOF) { 12355 } else if (ctxt->instate != XML_PARSER_EOF) {
11750 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) { 12356 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
11751 xmlParserInputBufferPtr in = ctxt->input->buf; 12357 xmlParserInputBufferPtr in = ctxt->input->buf;
11752 if ((in->encoder != NULL) && (in->buffer != NULL) && 12358 if ((in->encoder != NULL) && (in->buffer != NULL) &&
11753 (in->raw != NULL)) { 12359 (in->raw != NULL)) {
11754 int nbchars; 12360 int nbchars;
12361 size_t base = xmlBufGetInputBase(in->buffer, ctxt->input);
12362 size_t current = ctxt->input->cur - ctxt->input->base;
11755 12363
11756 » » nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); 12364 » » nbchars = xmlCharEncInput(in, terminate);
11757 if (nbchars < 0) { 12365 if (nbchars < 0) {
11758 /* TODO 2.6.0 */ 12366 /* TODO 2.6.0 */
11759 xmlGenericError(xmlGenericErrorContext, 12367 xmlGenericError(xmlGenericErrorContext,
11760 "xmlParseChunk: encoder error\n"); 12368 "xmlParseChunk: encoder error\n");
11761 return(XML_ERR_INVALID_ENCODING); 12369 return(XML_ERR_INVALID_ENCODING);
11762 } 12370 }
12371 xmlBufSetInputBaseCur(in->buffer, ctxt->input, base, current);
11763 } 12372 }
11764 } 12373 }
11765 } 12374 }
11766 if (remain != 0) 12375 if (remain != 0) {
11767 xmlParseTryOrFinish(ctxt, 0); 12376 xmlParseTryOrFinish(ctxt, 0);
11768 else 12377 } else {
11769 xmlParseTryOrFinish(ctxt, terminate); 12378 if ((ctxt->input != NULL) && (ctxt->input->buf != NULL))
12379 avail = xmlBufUse(ctxt->input->buf->buffer);
12380 /*
12381 * Depending on the current state it may not be such
12382 * a good idea to try parsing if there is nothing in the chunk
12383 * which would be worth doing a parser state transition and we
12384 * need to wait for more data
12385 */
12386 if ((terminate) || (avail > XML_MAX_TEXT_LENGTH) ||
12387 (old_avail == 0) || (avail == 0) ||
12388 (xmlParseCheckTransition(ctxt,
12389 (const char *)&ctxt->input->base[old_avail],
12390 avail - old_avail)))
12391 xmlParseTryOrFinish(ctxt, terminate);
12392 }
11770 if (ctxt->instate == XML_PARSER_EOF) 12393 if (ctxt->instate == XML_PARSER_EOF)
11771 return(ctxt->errNo); 12394 return(ctxt->errNo);
12395
12396 if ((ctxt->input != NULL) &&
12397 (((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
12398 ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
12399 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
12400 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
12401 ctxt->instate = XML_PARSER_EOF;
12402 }
11772 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 12403 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
11773 return(ctxt->errNo); 12404 return(ctxt->errNo);
11774 12405
11775 if (remain != 0) { 12406 if (remain != 0) {
11776 chunk += size; 12407 chunk += size;
11777 size = remain; 12408 size = remain;
11778 remain = 0; 12409 remain = 0;
11779 goto xmldecl_done; 12410 goto xmldecl_done;
11780 } 12411 }
11781 if ((end_in_lf == 1) && (ctxt->input != NULL) && 12412 if ((end_in_lf == 1) && (ctxt->input != NULL) &&
11782 (ctxt->input->buf != NULL)) { 12413 (ctxt->input->buf != NULL)) {
12414 size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
12415 ctxt->input);
12416 size_t current = ctxt->input->cur - ctxt->input->base;
12417
11783 xmlParserInputBufferPush(ctxt->input->buf, 1, "\r"); 12418 xmlParserInputBufferPush(ctxt->input->buf, 1, "\r");
12419
12420 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
12421 base, current);
11784 } 12422 }
11785 if (terminate) { 12423 if (terminate) {
11786 /* 12424 /*
11787 * Check for termination 12425 * Check for termination
11788 */ 12426 */
11789 » int avail = 0; 12427 » int cur_avail = 0;
11790 12428
11791 if (ctxt->input != NULL) { 12429 if (ctxt->input != NULL) {
11792 if (ctxt->input->buf == NULL) 12430 if (ctxt->input->buf == NULL)
11793 » » avail = ctxt->input->length - 12431 » » cur_avail = ctxt->input->length -
11794 » » » (ctxt->input->cur - ctxt->input->base); 12432 » » » (ctxt->input->cur - ctxt->input->base);
11795 else 12433 else
11796 » » avail = ctxt->input->buf->buffer->use - 12434 » » cur_avail = xmlBufUse(ctxt->input->buf->buffer) -
11797 » » » (ctxt->input->cur - ctxt->input->base); 12435 » » » (ctxt->input->cur - ctxt->input->base);
11798 } 12436 }
11799 » » » 12437
11800 if ((ctxt->instate != XML_PARSER_EOF) && 12438 if ((ctxt->instate != XML_PARSER_EOF) &&
11801 (ctxt->instate != XML_PARSER_EPILOG)) { 12439 (ctxt->instate != XML_PARSER_EPILOG)) {
11802 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 12440 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11803 » } 12441 » }
11804 » if ((ctxt->instate == XML_PARSER_EPILOG) && (avail > 0)) { 12442 » if ((ctxt->instate == XML_PARSER_EPILOG) && (cur_avail > 0)) {
11805 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 12443 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11806 } 12444 }
11807 if (ctxt->instate != XML_PARSER_EOF) { 12445 if (ctxt->instate != XML_PARSER_EOF) {
11808 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 12446 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11809 ctxt->sax->endDocument(ctxt->userData); 12447 ctxt->sax->endDocument(ctxt->userData);
11810 } 12448 }
11811 ctxt->instate = XML_PARSER_EOF; 12449 ctxt->instate = XML_PARSER_EOF;
11812 } 12450 }
11813 return((xmlParserErrors) ctxt->errNo);» 12451 if (ctxt->wellFormed == 0)
12452 » return((xmlParserErrors) ctxt->errNo);
12453 else
12454 return(0);
11814 } 12455 }
11815 12456
11816 /************************************************************************ 12457 /************************************************************************
11817 * * 12458 * *
11818 * » » I/O front end functions to the parser» » » * 12459 *» » I/O front end functions to the parser» » » *
11819 * * 12460 * *
11820 ************************************************************************/ 12461 ************************************************************************/
11821 12462
11822 /** 12463 /**
11823 * xmlCreatePushParserCtxt: 12464 * xmlCreatePushParserCtxt:
11824 * @sax: a SAX handler 12465 * @sax: a SAX handler
11825 * @user_data: The user data returned on SAX callbacks 12466 * @user_data: The user data returned on SAX callbacks
11826 * @chunk: a pointer to an array of chars 12467 * @chunk: a pointer to an array of chars
11827 * @size: number of chars in the array 12468 * @size: number of chars in the array
11828 * @filename: an optional file name or URI 12469 * @filename: an optional file name or URI
11829 * 12470 *
11830 * Create a parser context for using the XML parser in push mode. 12471 * Create a parser context for using the XML parser in push mode.
11831 * If @buffer and @size are non-NULL, the data is used to detect 12472 * If @buffer and @size are non-NULL, the data is used to detect
11832 * the encoding. The remaining characters will be parsed so they 12473 * the encoding. The remaining characters will be parsed so they
11833 * don't need to be fed in again through xmlParseChunk. 12474 * don't need to be fed in again through xmlParseChunk.
11834 * To allow content encoding detection, @size should be >= 4 12475 * To allow content encoding detection, @size should be >= 4
11835 * The value of @filename is used for fetching external entities 12476 * The value of @filename is used for fetching external entities
11836 * and error/warning reports. 12477 * and error/warning reports.
11837 * 12478 *
11838 * Returns the new parser context or NULL 12479 * Returns the new parser context or NULL
11839 */ 12480 */
11840 12481
11841 xmlParserCtxtPtr 12482 xmlParserCtxtPtr
11842 xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, 12483 xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
11843 const char *chunk, int size, const char *filename) { 12484 const char *chunk, int size, const char *filename) {
11844 xmlParserCtxtPtr ctxt; 12485 xmlParserCtxtPtr ctxt;
11845 xmlParserInputPtr inputStream; 12486 xmlParserInputPtr inputStream;
11846 xmlParserInputBufferPtr buf; 12487 xmlParserInputBufferPtr buf;
11847 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; 12488 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
11848 12489
11849 /* 12490 /*
11850 * plug some encoding conversion routines 12491 * plug some encoding conversion routines
11851 */ 12492 */
11852 if ((chunk != NULL) && (size >= 4)) 12493 if ((chunk != NULL) && (size >= 4))
(...skipping 28 matching lines...) Expand all
11881 xmlFreeParserCtxt(ctxt); 12522 xmlFreeParserCtxt(ctxt);
11882 return(NULL); 12523 return(NULL);
11883 } 12524 }
11884 memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); 12525 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
11885 if (sax->initialized == XML_SAX2_MAGIC) 12526 if (sax->initialized == XML_SAX2_MAGIC)
11886 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); 12527 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
11887 else 12528 else
11888 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); 12529 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
11889 if (user_data != NULL) 12530 if (user_data != NULL)
11890 ctxt->userData = user_data; 12531 ctxt->userData = user_data;
11891 }» 12532 }
11892 if (filename == NULL) { 12533 if (filename == NULL) {
11893 ctxt->directory = NULL; 12534 ctxt->directory = NULL;
11894 } else { 12535 } else {
11895 ctxt->directory = xmlParserGetDirectory(filename); 12536 ctxt->directory = xmlParserGetDirectory(filename);
11896 } 12537 }
11897 12538
11898 inputStream = xmlNewInputStream(ctxt); 12539 inputStream = xmlNewInputStream(ctxt);
11899 if (inputStream == NULL) { 12540 if (inputStream == NULL) {
11900 xmlFreeParserCtxt(ctxt); 12541 xmlFreeParserCtxt(ctxt);
11901 xmlFreeParserInputBuffer(buf); 12542 xmlFreeParserInputBuffer(buf);
11902 return(NULL); 12543 return(NULL);
11903 } 12544 }
11904 12545
11905 if (filename == NULL) 12546 if (filename == NULL)
11906 inputStream->filename = NULL; 12547 inputStream->filename = NULL;
11907 else { 12548 else {
11908 inputStream->filename = (char *) 12549 inputStream->filename = (char *)
11909 xmlCanonicPath((const xmlChar *) filename); 12550 xmlCanonicPath((const xmlChar *) filename);
11910 if (inputStream->filename == NULL) { 12551 if (inputStream->filename == NULL) {
11911 xmlFreeParserCtxt(ctxt); 12552 xmlFreeParserCtxt(ctxt);
11912 xmlFreeParserInputBuffer(buf); 12553 xmlFreeParserInputBuffer(buf);
11913 return(NULL); 12554 return(NULL);
11914 } 12555 }
11915 } 12556 }
11916 inputStream->buf = buf; 12557 inputStream->buf = buf;
11917 inputStream->base = inputStream->buf->buffer->content; 12558 xmlBufResetInput(inputStream->buf->buffer, inputStream);
11918 inputStream->cur = inputStream->buf->buffer->content;
11919 inputStream->end =
11920 » &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
11921
11922 inputPush(ctxt, inputStream); 12559 inputPush(ctxt, inputStream);
11923 12560
11924 /* 12561 /*
11925 * If the caller didn't provide an initial 'chunk' for determining 12562 * If the caller didn't provide an initial 'chunk' for determining
11926 * the encoding, we set the context to XML_CHAR_ENCODING_NONE so 12563 * the encoding, we set the context to XML_CHAR_ENCODING_NONE so
11927 * that it can be automatically determined later 12564 * that it can be automatically determined later
11928 */ 12565 */
11929 if ((size == 0) || (chunk == NULL)) { 12566 if ((size == 0) || (chunk == NULL)) {
11930 ctxt->charset = XML_CHAR_ENCODING_NONE; 12567 ctxt->charset = XML_CHAR_ENCODING_NONE;
11931 } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) { 12568 } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) {
11932 » int base = ctxt->input->base - ctxt->input->buf->buffer->content; 12569 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
11933 » int cur = ctxt->input->cur - ctxt->input->base; 12570 » size_t cur = ctxt->input->cur - ctxt->input->base;
11934 12571
11935 » xmlParserInputBufferPush(ctxt->input->buf, size, chunk);» 12572 » xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
11936 12573
11937 » ctxt->input->base = ctxt->input->buf->buffer->content + base; 12574 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
11938 » ctxt->input->cur = ctxt->input->base + cur;
11939 » ctxt->input->end =
11940 » &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use];
11941 #ifdef DEBUG_PUSH 12575 #ifdef DEBUG_PUSH
11942 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 12576 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
11943 #endif 12577 #endif
11944 } 12578 }
11945 12579
11946 if (enc != XML_CHAR_ENCODING_NONE) { 12580 if (enc != XML_CHAR_ENCODING_NONE) {
11947 xmlSwitchEncoding(ctxt, enc); 12581 xmlSwitchEncoding(ctxt, enc);
11948 } 12582 }
11949 12583
11950 return(ctxt); 12584 return(ctxt);
11951 } 12585 }
11952 #endif /* LIBXML_PUSH_ENABLED */ 12586 #endif /* LIBXML_PUSH_ENABLED */
11953 12587
11954 /** 12588 /**
11955 * xmlStopParser: 12589 * xmlStopParser:
11956 * @ctxt: an XML parser context 12590 * @ctxt: an XML parser context
11957 * 12591 *
11958 * Blocks further parser processing 12592 * Blocks further parser processing
11959 */ 12593 */
11960 void 12594 void
11961 xmlStopParser(xmlParserCtxtPtr ctxt) { 12595 xmlStopParser(xmlParserCtxtPtr ctxt) {
11962 if (ctxt == NULL) 12596 if (ctxt == NULL)
11963 return; 12597 return;
11964 ctxt->instate = XML_PARSER_EOF; 12598 ctxt->instate = XML_PARSER_EOF;
11965 ctxt->errNo = XML_ERR_USER_STOP; 12599 ctxt->errNo = XML_ERR_USER_STOP;
11966 ctxt->disableSAX = 1; 12600 ctxt->disableSAX = 1;
11967 if (ctxt->input != NULL) { 12601 if (ctxt->input != NULL) {
11968 ctxt->input->cur = BAD_CAST""; 12602 ctxt->input->cur = BAD_CAST"";
11969 ctxt->input->base = ctxt->input->cur; 12603 ctxt->input->base = ctxt->input->cur;
11970 } 12604 }
(...skipping 13 matching lines...) Expand all
11984 * 12618 *
11985 * Returns the new parser context or NULL 12619 * Returns the new parser context or NULL
11986 */ 12620 */
11987 xmlParserCtxtPtr 12621 xmlParserCtxtPtr
11988 xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, 12622 xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
11989 xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, 12623 xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
11990 void *ioctx, xmlCharEncoding enc) { 12624 void *ioctx, xmlCharEncoding enc) {
11991 xmlParserCtxtPtr ctxt; 12625 xmlParserCtxtPtr ctxt;
11992 xmlParserInputPtr inputStream; 12626 xmlParserInputPtr inputStream;
11993 xmlParserInputBufferPtr buf; 12627 xmlParserInputBufferPtr buf;
11994 12628
11995 if (ioread == NULL) return(NULL); 12629 if (ioread == NULL) return(NULL);
11996 12630
11997 buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc); 12631 buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
11998 if (buf == NULL) return(NULL); 12632 if (buf == NULL) {
12633 if (ioclose != NULL)
12634 ioclose(ioctx);
12635 return (NULL);
12636 }
11999 12637
12000 ctxt = xmlNewParserCtxt(); 12638 ctxt = xmlNewParserCtxt();
12001 if (ctxt == NULL) { 12639 if (ctxt == NULL) {
12002 xmlFreeParserInputBuffer(buf); 12640 xmlFreeParserInputBuffer(buf);
12003 return(NULL); 12641 return(NULL);
12004 } 12642 }
12005 if (sax != NULL) { 12643 if (sax != NULL) {
12006 #ifdef LIBXML_SAX1_ENABLED 12644 #ifdef LIBXML_SAX1_ENABLED
12007 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 12645 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
12008 #endif /* LIBXML_SAX1_ENABLED */ 12646 #endif /* LIBXML_SAX1_ENABLED */
12009 xmlFree(ctxt->sax); 12647 xmlFree(ctxt->sax);
12010 ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); 12648 ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
12011 if (ctxt->sax == NULL) { 12649 if (ctxt->sax == NULL) {
12012 xmlErrMemory(ctxt, NULL); 12650 xmlErrMemory(ctxt, NULL);
12013 xmlFreeParserCtxt(ctxt); 12651 xmlFreeParserCtxt(ctxt);
12014 return(NULL); 12652 return(NULL);
12015 } 12653 }
12016 memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); 12654 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
12017 if (sax->initialized == XML_SAX2_MAGIC) 12655 if (sax->initialized == XML_SAX2_MAGIC)
12018 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); 12656 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
12019 else 12657 else
12020 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); 12658 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
12021 if (user_data != NULL) 12659 if (user_data != NULL)
12022 ctxt->userData = user_data; 12660 ctxt->userData = user_data;
12023 }» 12661 }
12024 12662
12025 inputStream = xmlNewIOInputStream(ctxt, buf, enc); 12663 inputStream = xmlNewIOInputStream(ctxt, buf, enc);
12026 if (inputStream == NULL) { 12664 if (inputStream == NULL) {
12027 xmlFreeParserCtxt(ctxt); 12665 xmlFreeParserCtxt(ctxt);
12028 return(NULL); 12666 return(NULL);
12029 } 12667 }
12030 inputPush(ctxt, inputStream); 12668 inputPush(ctxt, inputStream);
12031 12669
12032 return(ctxt); 12670 return(ctxt);
12033 } 12671 }
12034 12672
12035 #ifdef LIBXML_VALID_ENABLED 12673 #ifdef LIBXML_VALID_ENABLED
12036 /************************************************************************ 12674 /************************************************************************
12037 * * 12675 * *
12038 * » » Front ends when parsing a DTD» » » » * 12676 *» » Front ends when parsing a DTD» » » » *
12039 * * 12677 * *
12040 ************************************************************************/ 12678 ************************************************************************/
12041 12679
12042 /** 12680 /**
12043 * xmlIOParseDTD: 12681 * xmlIOParseDTD:
12044 * @sax: the SAX handler block or NULL 12682 * @sax: the SAX handler block or NULL
12045 * @input: an Input Buffer 12683 * @input: an Input Buffer
12046 * @enc: the charset encoding if known 12684 * @enc: the charset encoding if known
12047 * 12685 *
12048 * Load and parse a DTD 12686 * Load and parse a DTD
12049 * 12687 *
12050 * Returns the resulting xmlDtdPtr or NULL in case of error. 12688 * Returns the resulting xmlDtdPtr or NULL in case of error.
12051 * @input will be freed by the function in any case. 12689 * @input will be freed by the function in any case.
12052 */ 12690 */
12053 12691
12054 xmlDtdPtr 12692 xmlDtdPtr
12055 xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, 12693 xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input,
12056 xmlCharEncoding enc) { 12694 xmlCharEncoding enc) {
12057 xmlDtdPtr ret = NULL; 12695 xmlDtdPtr ret = NULL;
12058 xmlParserCtxtPtr ctxt; 12696 xmlParserCtxtPtr ctxt;
12059 xmlParserInputPtr pinput = NULL; 12697 xmlParserInputPtr pinput = NULL;
12060 xmlChar start[4]; 12698 xmlChar start[4];
12061 12699
12062 if (input == NULL) 12700 if (input == NULL)
12063 return(NULL); 12701 return(NULL);
12064 12702
12065 ctxt = xmlNewParserCtxt(); 12703 ctxt = xmlNewParserCtxt();
12066 if (ctxt == NULL) { 12704 if (ctxt == NULL) {
12067 xmlFreeParserInputBuffer(input); 12705 xmlFreeParserInputBuffer(input);
12068 return(NULL); 12706 return(NULL);
12069 } 12707 }
12070 12708
12709 /* We are loading a DTD */
12710 ctxt->options |= XML_PARSE_DTDLOAD;
12711
12071 /* 12712 /*
12072 * Set-up the SAX context 12713 * Set-up the SAX context
12073 */ 12714 */
12074 if (sax != NULL) { 12715 if (sax != NULL) {
12075 if (ctxt->sax != NULL) 12716 if (ctxt->sax != NULL)
12076 xmlFree(ctxt->sax); 12717 xmlFree(ctxt->sax);
12077 ctxt->sax = sax; 12718 ctxt->sax = sax;
12078 ctxt->userData = ctxt; 12719 ctxt->userData = ctxt;
12079 } 12720 }
12080 xmlDetectSAX2(ctxt); 12721 xmlDetectSAX2(ctxt);
12081 12722
12082 /* 12723 /*
12083 * generate a parser input from the I/O handler 12724 * generate a parser input from the I/O handler
12084 */ 12725 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
12118 if (ctxt->myDoc == NULL) { 12759 if (ctxt->myDoc == NULL) {
12119 xmlErrMemory(ctxt, "New Doc failed"); 12760 xmlErrMemory(ctxt, "New Doc failed");
12120 return(NULL); 12761 return(NULL);
12121 } 12762 }
12122 ctxt->myDoc->properties = XML_DOC_INTERNAL; 12763 ctxt->myDoc->properties = XML_DOC_INTERNAL;
12123 ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", 12764 ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none",
12124 BAD_CAST "none", BAD_CAST "none"); 12765 BAD_CAST "none", BAD_CAST "none");
12125 12766
12126 if ((enc == XML_CHAR_ENCODING_NONE) && 12767 if ((enc == XML_CHAR_ENCODING_NONE) &&
12127 ((ctxt->input->end - ctxt->input->cur) >= 4)) { 12768 ((ctxt->input->end - ctxt->input->cur) >= 4)) {
12128 » /* 12769 » /*
12129 * Get the 4 first bytes and decode the charset 12770 * Get the 4 first bytes and decode the charset
12130 * if enc != XML_CHAR_ENCODING_NONE 12771 * if enc != XML_CHAR_ENCODING_NONE
12131 * plug some encoding conversion routines. 12772 * plug some encoding conversion routines.
12132 */ 12773 */
12133 start[0] = RAW; 12774 start[0] = RAW;
12134 start[1] = NXT(1); 12775 start[1] = NXT(1);
12135 start[2] = NXT(2); 12776 start[2] = NXT(2);
12136 start[3] = NXT(3); 12777 start[3] = NXT(3);
12137 enc = xmlDetectCharEncoding(start, 4); 12778 enc = xmlDetectCharEncoding(start, 4);
12138 if (enc != XML_CHAR_ENCODING_NONE) { 12779 if (enc != XML_CHAR_ENCODING_NONE) {
(...skipping 18 matching lines...) Expand all
12157 } 12798 }
12158 } 12799 }
12159 } else { 12800 } else {
12160 ret = NULL; 12801 ret = NULL;
12161 } 12802 }
12162 xmlFreeDoc(ctxt->myDoc); 12803 xmlFreeDoc(ctxt->myDoc);
12163 ctxt->myDoc = NULL; 12804 ctxt->myDoc = NULL;
12164 } 12805 }
12165 if (sax != NULL) ctxt->sax = NULL; 12806 if (sax != NULL) ctxt->sax = NULL;
12166 xmlFreeParserCtxt(ctxt); 12807 xmlFreeParserCtxt(ctxt);
12167 12808
12168 return(ret); 12809 return(ret);
12169 } 12810 }
12170 12811
12171 /** 12812 /**
12172 * xmlSAXParseDTD: 12813 * xmlSAXParseDTD:
12173 * @sax: the SAX handler block 12814 * @sax: the SAX handler block
12174 * @ExternalID: a NAME* containing the External ID of the DTD 12815 * @ExternalID: a NAME* containing the External ID of the DTD
12175 * @SystemID: a NAME* containing the URL to the DTD 12816 * @SystemID: a NAME* containing the URL to the DTD
12176 * 12817 *
12177 * Load and parse an external subset. 12818 * Load and parse an external subset.
12178 * 12819 *
12179 * Returns the resulting xmlDtdPtr or NULL in case of error. 12820 * Returns the resulting xmlDtdPtr or NULL in case of error.
12180 */ 12821 */
12181 12822
12182 xmlDtdPtr 12823 xmlDtdPtr
12183 xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, 12824 xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID,
12184 const xmlChar *SystemID) { 12825 const xmlChar *SystemID) {
12185 xmlDtdPtr ret = NULL; 12826 xmlDtdPtr ret = NULL;
12186 xmlParserCtxtPtr ctxt; 12827 xmlParserCtxtPtr ctxt;
12187 xmlParserInputPtr input = NULL; 12828 xmlParserInputPtr input = NULL;
12188 xmlCharEncoding enc; 12829 xmlCharEncoding enc;
12189 xmlChar* systemIdCanonic; 12830 xmlChar* systemIdCanonic;
12190 12831
12191 if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); 12832 if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL);
12192 12833
12193 ctxt = xmlNewParserCtxt(); 12834 ctxt = xmlNewParserCtxt();
12194 if (ctxt == NULL) { 12835 if (ctxt == NULL) {
12195 return(NULL); 12836 return(NULL);
12196 } 12837 }
12197 12838
12839 /* We are loading a DTD */
12840 ctxt->options |= XML_PARSE_DTDLOAD;
12841
12198 /* 12842 /*
12199 * Set-up the SAX context 12843 * Set-up the SAX context
12200 */ 12844 */
12201 if (sax != NULL) { 12845 if (sax != NULL) {
12202 if (ctxt->sax != NULL) 12846 if (ctxt->sax != NULL)
12203 xmlFree(ctxt->sax); 12847 xmlFree(ctxt->sax);
12204 ctxt->sax = sax; 12848 ctxt->sax = sax;
12205 ctxt->userData = ctxt; 12849 ctxt->userData = ctxt;
12206 } 12850 }
12207 12851
12208 /* 12852 /*
12209 * Canonicalise the system ID 12853 * Canonicalise the system ID
12210 */ 12854 */
12211 systemIdCanonic = xmlCanonicPath(SystemID); 12855 systemIdCanonic = xmlCanonicPath(SystemID);
12212 if ((SystemID != NULL) && (systemIdCanonic == NULL)) { 12856 if ((SystemID != NULL) && (systemIdCanonic == NULL)) {
12213 xmlFreeParserCtxt(ctxt); 12857 xmlFreeParserCtxt(ctxt);
12214 return(NULL); 12858 return(NULL);
12215 } 12859 }
12216 12860
12217 /* 12861 /*
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
12308 */ 12952 */
12309 12953
12310 xmlDtdPtr 12954 xmlDtdPtr
12311 xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { 12955 xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) {
12312 return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); 12956 return(xmlSAXParseDTD(NULL, ExternalID, SystemID));
12313 } 12957 }
12314 #endif /* LIBXML_VALID_ENABLED */ 12958 #endif /* LIBXML_VALID_ENABLED */
12315 12959
12316 /************************************************************************ 12960 /************************************************************************
12317 * * 12961 * *
12318 * » » Front ends when parsing an Entity» » » * 12962 *» » Front ends when parsing an Entity» » » *
12319 * * 12963 * *
12320 ************************************************************************/ 12964 ************************************************************************/
12321 12965
12322 /** 12966 /**
12323 * xmlParseCtxtExternalEntity: 12967 * xmlParseCtxtExternalEntity:
12324 * @ctx: the existing parsing context 12968 * @ctx: the existing parsing context
12325 * @URL: the URL for the entity to load 12969 * @URL: the URL for the entity to load
12326 * @ID: the System ID for the entity to load 12970 * @ID: the System ID for the entity to load
12327 * @lst: the return value for the set of parsed nodes 12971 * @lst: the return value for the set of parsed nodes
12328 * 12972 *
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
12424 /* 13068 /*
12425 * Parse a possible text declaration first 13069 * Parse a possible text declaration first
12426 */ 13070 */
12427 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { 13071 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
12428 xmlParseTextDecl(ctxt); 13072 xmlParseTextDecl(ctxt);
12429 /* 13073 /*
12430 * An XML-1.0 document can't reference an entity not XML-1.0 13074 * An XML-1.0 document can't reference an entity not XML-1.0
12431 */ 13075 */
12432 if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) && 13076 if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) &&
12433 (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) { 13077 (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) {
12434 » xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH, 13078 » xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH,
12435 "Version mismatch between document and entity\n"); 13079 "Version mismatch between document and entity\n");
12436 } 13080 }
12437 } 13081 }
12438 13082
12439 /* 13083 /*
13084 * If the user provided its own SAX callbacks then reuse the
13085 * useData callback field, otherwise the expected setup in a
13086 * DOM builder is to have userData == ctxt
13087 */
13088 if (ctx->userData == ctx)
13089 ctxt->userData = ctxt;
13090 else
13091 ctxt->userData = ctx->userData;
13092
13093 /*
12440 * Doing validity checking on chunk doesn't make sense 13094 * Doing validity checking on chunk doesn't make sense
12441 */ 13095 */
12442 ctxt->instate = XML_PARSER_CONTENT; 13096 ctxt->instate = XML_PARSER_CONTENT;
12443 ctxt->validate = ctx->validate; 13097 ctxt->validate = ctx->validate;
12444 ctxt->valid = ctx->valid; 13098 ctxt->valid = ctx->valid;
12445 ctxt->loadsubset = ctx->loadsubset; 13099 ctxt->loadsubset = ctx->loadsubset;
12446 ctxt->depth = ctx->depth + 1; 13100 ctxt->depth = ctx->depth + 1;
12447 ctxt->replaceEntities = ctx->replaceEntities; 13101 ctxt->replaceEntities = ctx->replaceEntities;
12448 if (ctxt->validate) { 13102 if (ctxt->validate) {
12449 ctxt->vctxt.error = ctx->vctxt.error; 13103 ctxt->vctxt.error = ctx->vctxt.error;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
12697 if (ctxt->input != NULL) { 13351 if (ctxt->input != NULL) {
12698 oldctxt->sizeentities += ctxt->input->consumed; 13352 oldctxt->sizeentities += ctxt->input->consumed;
12699 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base); 13353 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base);
12700 } 13354 }
12701 /* 13355 /*
12702 * And record the last error if any 13356 * And record the last error if any
12703 */ 13357 */
12704 if (ctxt->lastError.code != XML_ERR_OK) 13358 if (ctxt->lastError.code != XML_ERR_OK)
12705 xmlCopyError(&ctxt->lastError, &oldctxt->lastError); 13359 xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
12706 13360
12707 if (sax != NULL) 13361 if (sax != NULL)
12708 ctxt->sax = oldsax; 13362 ctxt->sax = oldsax;
12709 oldctxt->node_seq.maximum = ctxt->node_seq.maximum; 13363 oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
12710 oldctxt->node_seq.length = ctxt->node_seq.length; 13364 oldctxt->node_seq.length = ctxt->node_seq.length;
12711 oldctxt->node_seq.buffer = ctxt->node_seq.buffer; 13365 oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
12712 ctxt->node_seq.maximum = 0; 13366 ctxt->node_seq.maximum = 0;
12713 ctxt->node_seq.length = 0; 13367 ctxt->node_seq.length = 0;
12714 ctxt->node_seq.buffer = NULL; 13368 ctxt->node_seq.buffer = NULL;
12715 xmlFreeParserCtxt(ctxt); 13369 xmlFreeParserCtxt(ctxt);
12716 newDoc->intSubset = NULL; 13370 newDoc->intSubset = NULL;
12717 newDoc->extSubset = NULL; 13371 newDoc->extSubset = NULL;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
13067 } else 13721 } else
13068 options |= XML_PARSE_NODICT; 13722 options |= XML_PARSE_NODICT;
13069 13723
13070 if (doc->encoding != NULL) { 13724 if (doc->encoding != NULL) {
13071 xmlCharEncodingHandlerPtr hdlr; 13725 xmlCharEncodingHandlerPtr hdlr;
13072 13726
13073 if (ctxt->encoding != NULL) 13727 if (ctxt->encoding != NULL)
13074 xmlFree((xmlChar *) ctxt->encoding); 13728 xmlFree((xmlChar *) ctxt->encoding);
13075 ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding); 13729 ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding);
13076 13730
13077 hdlr = xmlFindCharEncodingHandler(doc->encoding); 13731 hdlr = xmlFindCharEncodingHandler((const char *) doc->encoding);
13078 if (hdlr != NULL) { 13732 if (hdlr != NULL) {
13079 xmlSwitchToEncoding(ctxt, hdlr); 13733 xmlSwitchToEncoding(ctxt, hdlr);
13080 } else { 13734 } else {
13081 return(XML_ERR_UNSUPPORTED_ENCODING); 13735 return(XML_ERR_UNSUPPORTED_ENCODING);
13082 } 13736 }
13083 } 13737 }
13084 13738
13085 xmlCtxtUseOptionsInternal(ctxt, options, NULL); 13739 xmlCtxtUseOptionsInternal(ctxt, options, NULL);
13086 xmlDetectSAX2(ctxt); 13740 xmlDetectSAX2(ctxt);
13087 ctxt->myDoc = doc; 13741 ctxt->myDoc = doc;
13742 /* parsing in context, i.e. as within existing content */
13743 ctxt->instate = XML_PARSER_CONTENT;
13088 13744
13089 fake = xmlNewComment(NULL); 13745 fake = xmlNewComment(NULL);
13090 if (fake == NULL) { 13746 if (fake == NULL) {
13091 xmlFreeParserCtxt(ctxt); 13747 xmlFreeParserCtxt(ctxt);
13092 return(XML_ERR_NO_MEMORY); 13748 return(XML_ERR_NO_MEMORY);
13093 } 13749 }
13094 xmlAddChild(node, fake); 13750 xmlAddChild(node, fake);
13095 13751
13096 if (node->type == XML_ELEMENT_NODE) { 13752 if (node->type == XML_ELEMENT_NODE) {
13097 nodePush(ctxt, node); 13753 nodePush(ctxt, node);
(...skipping 15 matching lines...) Expand all
13113 } 13769 }
13114 13770
13115 if (xmlGetNamespace(ctxt, iprefix) == NULL) { 13771 if (xmlGetNamespace(ctxt, iprefix) == NULL) {
13116 nsPush(ctxt, iprefix, ihref); 13772 nsPush(ctxt, iprefix, ihref);
13117 nsnr++; 13773 nsnr++;
13118 } 13774 }
13119 ns = ns->next; 13775 ns = ns->next;
13120 } 13776 }
13121 cur = cur->parent; 13777 cur = cur->parent;
13122 } 13778 }
13123 ctxt->instate = XML_PARSER_CONTENT;
13124 } 13779 }
13125 13780
13126 if ((ctxt->validate) || (ctxt->replaceEntities != 0)) { 13781 if ((ctxt->validate) || (ctxt->replaceEntities != 0)) {
13127 /* 13782 /*
13128 * ID/IDREF registration will be done in xmlValidateElement below 13783 * ID/IDREF registration will be done in xmlValidateElement below
13129 */ 13784 */
13130 ctxt->loadsubset |= XML_SKIP_IDS; 13785 ctxt->loadsubset |= XML_SKIP_IDS;
13131 } 13786 }
13132 13787
13133 #ifdef LIBXML_HTML_ENABLED 13788 #ifdef LIBXML_HTML_ENABLED
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
13516 * * 14171 * *
13517 * Front ends when parsing from a file * 14172 * Front ends when parsing from a file *
13518 * * 14173 * *
13519 ************************************************************************/ 14174 ************************************************************************/
13520 14175
13521 /** 14176 /**
13522 * xmlCreateURLParserCtxt: 14177 * xmlCreateURLParserCtxt:
13523 * @filename: the filename or URL 14178 * @filename: the filename or URL
13524 * @options: a combination of xmlParserOption 14179 * @options: a combination of xmlParserOption
13525 * 14180 *
13526 * Create a parser context for a file or URL content. 14181 * Create a parser context for a file or URL content.
13527 * Automatic support for ZLIB/Compress compressed document is provided 14182 * Automatic support for ZLIB/Compress compressed document is provided
13528 * by default if found at compile-time and for file accesses 14183 * by default if found at compile-time and for file accesses
13529 * 14184 *
13530 * Returns the new parser context or NULL 14185 * Returns the new parser context or NULL
13531 */ 14186 */
13532 xmlParserCtxtPtr 14187 xmlParserCtxtPtr
13533 xmlCreateURLParserCtxt(const char *filename, int options) 14188 xmlCreateURLParserCtxt(const char *filename, int options)
13534 { 14189 {
13535 xmlParserCtxtPtr ctxt; 14190 xmlParserCtxtPtr ctxt;
13536 xmlParserInputPtr inputStream; 14191 xmlParserInputPtr inputStream;
(...skipping 21 matching lines...) Expand all
13558 if ((ctxt->directory == NULL) && (directory != NULL)) 14213 if ((ctxt->directory == NULL) && (directory != NULL))
13559 ctxt->directory = directory; 14214 ctxt->directory = directory;
13560 14215
13561 return(ctxt); 14216 return(ctxt);
13562 } 14217 }
13563 14218
13564 /** 14219 /**
13565 * xmlCreateFileParserCtxt: 14220 * xmlCreateFileParserCtxt:
13566 * @filename: the filename 14221 * @filename: the filename
13567 * 14222 *
13568 * Create a parser context for a file content. 14223 * Create a parser context for a file content.
13569 * Automatic support for ZLIB/Compress compressed document is provided 14224 * Automatic support for ZLIB/Compress compressed document is provided
13570 * by default if found at compile-time. 14225 * by default if found at compile-time.
13571 * 14226 *
13572 * Returns the new parser context or NULL 14227 * Returns the new parser context or NULL
13573 */ 14228 */
13574 xmlParserCtxtPtr 14229 xmlParserCtxtPtr
13575 xmlCreateFileParserCtxt(const char *filename) 14230 xmlCreateFileParserCtxt(const char *filename)
13576 { 14231 {
13577 return(xmlCreateURLParserCtxt(filename, 0)); 14232 return(xmlCreateURLParserCtxt(filename, 0));
13578 } 14233 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
13636 } 14291 }
13637 } 14292 }
13638 else { 14293 else {
13639 ret = NULL; 14294 ret = NULL;
13640 xmlFreeDoc(ctxt->myDoc); 14295 xmlFreeDoc(ctxt->myDoc);
13641 ctxt->myDoc = NULL; 14296 ctxt->myDoc = NULL;
13642 } 14297 }
13643 if (sax != NULL) 14298 if (sax != NULL)
13644 ctxt->sax = NULL; 14299 ctxt->sax = NULL;
13645 xmlFreeParserCtxt(ctxt); 14300 xmlFreeParserCtxt(ctxt);
13646 14301
13647 return(ret); 14302 return(ret);
13648 } 14303 }
13649 14304
13650 /** 14305 /**
13651 * xmlSAXParseFile: 14306 * xmlSAXParseFile:
13652 * @sax: the SAX handler block 14307 * @sax: the SAX handler block
13653 * @filename: the filename 14308 * @filename: the filename
13654 * @recovery: work in recovery mode, i.e. tries to read no Well Formed 14309 * @recovery: work in recovery mode, i.e. tries to read no Well Formed
13655 * documents 14310 * documents
13656 * 14311 *
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
13736 14391
13737 if ((ctxt == NULL) || (buffer == NULL)) 14392 if ((ctxt == NULL) || (buffer == NULL))
13738 return; 14393 return;
13739 14394
13740 input = xmlNewInputStream(ctxt); 14395 input = xmlNewInputStream(ctxt);
13741 if (input == NULL) { 14396 if (input == NULL) {
13742 xmlErrMemory(NULL, "parsing new buffer: out of memory\n"); 14397 xmlErrMemory(NULL, "parsing new buffer: out of memory\n");
13743 xmlClearParserCtxt(ctxt); 14398 xmlClearParserCtxt(ctxt);
13744 return; 14399 return;
13745 } 14400 }
13746 14401
13747 xmlClearParserCtxt(ctxt); 14402 xmlClearParserCtxt(ctxt);
13748 if (filename != NULL) 14403 if (filename != NULL)
13749 input->filename = (char *) xmlCanonicPath((const xmlChar *)filename); 14404 input->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
13750 input->base = buffer; 14405 input->base = buffer;
13751 input->cur = buffer; 14406 input->cur = buffer;
13752 input->end = &buffer[xmlStrlen(buffer)]; 14407 input->end = &buffer[xmlStrlen(buffer)];
13753 inputPush(ctxt, input); 14408 inputPush(ctxt, input);
13754 } 14409 }
13755 14410
13756 /** 14411 /**
13757 * xmlSAXUserParseFile: 14412 * xmlSAXUserParseFile:
13758 * @sax: a SAX handler 14413 * @sax: a SAX handler
13759 * @user_data: The user data returned on SAX callbacks 14414 * @user_data: The user data returned on SAX callbacks
13760 * @filename: a file name 14415 * @filename: a file name
13761 * 14416 *
13762 * parse an XML file and call the given SAX handler routines. 14417 * parse an XML file and call the given SAX handler routines.
13763 * Automatic support for ZLIB/Compress compressed document is provided 14418 * Automatic support for ZLIB/Compress compressed document is provided
13764 * 14419 *
13765 * Returns 0 in case of success or a error number otherwise 14420 * Returns 0 in case of success or a error number otherwise
13766 */ 14421 */
13767 int 14422 int
13768 xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, 14423 xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
13769 const char *filename) { 14424 const char *filename) {
13770 int ret = 0; 14425 int ret = 0;
13771 xmlParserCtxtPtr ctxt; 14426 xmlParserCtxtPtr ctxt;
13772 14427
13773 ctxt = xmlCreateFileParserCtxt(filename); 14428 ctxt = xmlCreateFileParserCtxt(filename);
13774 if (ctxt == NULL) return -1; 14429 if (ctxt == NULL) return -1;
13775 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 14430 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
13776 xmlFree(ctxt->sax); 14431 xmlFree(ctxt->sax);
13777 ctxt->sax = sax; 14432 ctxt->sax = sax;
13778 xmlDetectSAX2(ctxt); 14433 xmlDetectSAX2(ctxt);
13779 14434
13780 if (user_data != NULL) 14435 if (user_data != NULL)
13781 ctxt->userData = user_data; 14436 ctxt->userData = user_data;
13782 14437
13783 xmlParseDocument(ctxt); 14438 xmlParseDocument(ctxt);
13784 14439
13785 if (ctxt->wellFormed) 14440 if (ctxt->wellFormed)
13786 ret = 0; 14441 ret = 0;
13787 else { 14442 else {
13788 if (ctxt->errNo != 0) 14443 if (ctxt->errNo != 0)
13789 ret = ctxt->errNo; 14444 ret = ctxt->errNo;
13790 else 14445 else
13791 ret = -1; 14446 ret = -1;
13792 } 14447 }
13793 if (sax != NULL) 14448 if (sax != NULL)
13794 ctxt->sax = NULL; 14449 ctxt->sax = NULL;
13795 if (ctxt->myDoc != NULL) { 14450 if (ctxt->myDoc != NULL) {
13796 xmlFreeDoc(ctxt->myDoc); 14451 xmlFreeDoc(ctxt->myDoc);
13797 ctxt->myDoc = NULL; 14452 ctxt->myDoc = NULL;
13798 } 14453 }
13799 xmlFreeParserCtxt(ctxt); 14454 xmlFreeParserCtxt(ctxt);
13800 14455
13801 return ret; 14456 return ret;
13802 } 14457 }
13803 #endif /* LIBXML_SAX1_ENABLED */ 14458 #endif /* LIBXML_SAX1_ENABLED */
13804 14459
13805 /************************************************************************ 14460 /************************************************************************
13806 * * 14461 * *
13807 * » » Front ends when parsing from memory» » » * 14462 *» » Front ends when parsing from memory» » » *
13808 * * 14463 * *
13809 ************************************************************************/ 14464 ************************************************************************/
13810 14465
13811 /** 14466 /**
13812 * xmlCreateMemoryParserCtxt: 14467 * xmlCreateMemoryParserCtxt:
13813 * @buffer: a pointer to a char array 14468 * @buffer: a pointer to a char array
13814 * @size: the size of the array 14469 * @size: the size of the array
13815 * 14470 *
13816 * Create a parser context for an XML in-memory document. 14471 * Create a parser context for an XML in-memory document.
13817 * 14472 *
(...skipping 23 matching lines...) Expand all
13841 14496
13842 input = xmlNewInputStream(ctxt); 14497 input = xmlNewInputStream(ctxt);
13843 if (input == NULL) { 14498 if (input == NULL) {
13844 xmlFreeParserInputBuffer(buf); 14499 xmlFreeParserInputBuffer(buf);
13845 xmlFreeParserCtxt(ctxt); 14500 xmlFreeParserCtxt(ctxt);
13846 return(NULL); 14501 return(NULL);
13847 } 14502 }
13848 14503
13849 input->filename = NULL; 14504 input->filename = NULL;
13850 input->buf = buf; 14505 input->buf = buf;
13851 input->base = input->buf->buffer->content; 14506 xmlBufResetInput(input->buf->buffer, input);
13852 input->cur = input->buf->buffer->content;
13853 input->end = &input->buf->buffer->content[input->buf->buffer->use];
13854 14507
13855 inputPush(ctxt, input); 14508 inputPush(ctxt, input);
13856 return(ctxt); 14509 return(ctxt);
13857 } 14510 }
13858 14511
13859 #ifdef LIBXML_SAX1_ENABLED 14512 #ifdef LIBXML_SAX1_ENABLED
13860 /** 14513 /**
13861 * xmlSAXParseMemoryWithData: 14514 * xmlSAXParseMemoryWithData:
13862 * @sax: the SAX handler block 14515 * @sax: the SAX handler block
13863 * @buffer: an pointer to a char array 14516 * @buffer: an pointer to a char array
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
13899 ctxt->recovery = recovery; 14552 ctxt->recovery = recovery;
13900 14553
13901 xmlParseDocument(ctxt); 14554 xmlParseDocument(ctxt);
13902 14555
13903 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; 14556 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
13904 else { 14557 else {
13905 ret = NULL; 14558 ret = NULL;
13906 xmlFreeDoc(ctxt->myDoc); 14559 xmlFreeDoc(ctxt->myDoc);
13907 ctxt->myDoc = NULL; 14560 ctxt->myDoc = NULL;
13908 } 14561 }
13909 if (sax != NULL) 14562 if (sax != NULL)
13910 ctxt->sax = NULL; 14563 ctxt->sax = NULL;
13911 xmlFreeParserCtxt(ctxt); 14564 xmlFreeParserCtxt(ctxt);
13912 14565
13913 return(ret); 14566 return(ret);
13914 } 14567 }
13915 14568
13916 /** 14569 /**
13917 * xmlSAXParseMemory: 14570 * xmlSAXParseMemory:
13918 * @sax: the SAX handler block 14571 * @sax: the SAX handler block
13919 * @buffer: an pointer to a char array 14572 * @buffer: an pointer to a char array
13920 * @size: the size of the array 14573 * @size: the size of the array
13921 * @recovery: work in recovery mode, i.e. tries to read not Well Formed 14574 * @recovery: work in recovery mode, i.e. tries to read not Well Formed
13922 * documents 14575 * documents
13923 * 14576 *
13924 * parse an XML in-memory block and use the given SAX function block 14577 * parse an XML in-memory block and use the given SAX function block
13925 * to handle the parsing callback. If sax is NULL, fallback to the default 14578 * to handle the parsing callback. If sax is NULL, fallback to the default
13926 * DOM tree building routines. 14579 * DOM tree building routines.
13927 * 14580 *
13928 * Returns the resulting document tree 14581 * Returns the resulting document tree
13929 */ 14582 */
13930 xmlDocPtr 14583 xmlDocPtr
13931 xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, 14584 xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer,
13932 int size, int recovery) { 14585 int size, int recovery) {
13933 return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL); 14586 return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL);
13934 } 14587 }
13935 14588
13936 /** 14589 /**
13937 * xmlParseMemory: 14590 * xmlParseMemory:
13938 * @buffer: an pointer to a char array 14591 * @buffer: an pointer to a char array
13939 * @size: the size of the array 14592 * @size: the size of the array
13940 * 14593 *
13941 * parse an XML in-memory block and build a tree. 14594 * parse an XML in-memory block and build a tree.
13942 * 14595 *
13943 * Returns the resulting document tree 14596 * Returns the resulting document tree
13944 */ 14597 */
13945 14598
13946 xmlDocPtr xmlParseMemory(const char *buffer, int size) { 14599 xmlDocPtr xmlParseMemory(const char *buffer, int size) {
13947 return(xmlSAXParseMemory(NULL, buffer, size, 0)); 14600 return(xmlSAXParseMemory(NULL, buffer, size, 0));
13948 } 14601 }
13949 14602
13950 /** 14603 /**
13951 * xmlRecoverMemory: 14604 * xmlRecoverMemory:
13952 * @buffer: an pointer to a char array 14605 * @buffer: an pointer to a char array
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
13986 if (ctxt == NULL) return -1; 14639 if (ctxt == NULL) return -1;
13987 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 14640 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
13988 xmlFree(ctxt->sax); 14641 xmlFree(ctxt->sax);
13989 ctxt->sax = sax; 14642 ctxt->sax = sax;
13990 xmlDetectSAX2(ctxt); 14643 xmlDetectSAX2(ctxt);
13991 14644
13992 if (user_data != NULL) 14645 if (user_data != NULL)
13993 ctxt->userData = user_data; 14646 ctxt->userData = user_data;
13994 14647
13995 xmlParseDocument(ctxt); 14648 xmlParseDocument(ctxt);
13996 14649
13997 if (ctxt->wellFormed) 14650 if (ctxt->wellFormed)
13998 ret = 0; 14651 ret = 0;
13999 else { 14652 else {
14000 if (ctxt->errNo != 0) 14653 if (ctxt->errNo != 0)
14001 ret = ctxt->errNo; 14654 ret = ctxt->errNo;
14002 else 14655 else
14003 ret = -1; 14656 ret = -1;
14004 } 14657 }
14005 if (sax != NULL) 14658 if (sax != NULL)
14006 ctxt->sax = NULL; 14659 ctxt->sax = NULL;
14007 if (ctxt->myDoc != NULL) { 14660 if (ctxt->myDoc != NULL) {
14008 xmlFreeDoc(ctxt->myDoc); 14661 xmlFreeDoc(ctxt->myDoc);
14009 ctxt->myDoc = NULL; 14662 ctxt->myDoc = NULL;
14010 } 14663 }
14011 xmlFreeParserCtxt(ctxt); 14664 xmlFreeParserCtxt(ctxt);
14012 14665
14013 return ret; 14666 return ret;
14014 } 14667 }
14015 #endif /* LIBXML_SAX1_ENABLED */ 14668 #endif /* LIBXML_SAX1_ENABLED */
14016 14669
14017 /** 14670 /**
14018 * xmlCreateDocParserCtxt: 14671 * xmlCreateDocParserCtxt:
14019 * @cur: a pointer to an array of xmlChar 14672 * @cur: a pointer to an array of xmlChar
14020 * 14673 *
14021 * Creates a parser context for an XML in-memory document. 14674 * Creates a parser context for an XML in-memory document.
14022 * 14675 *
(...skipping 13 matching lines...) Expand all
14036 /** 14689 /**
14037 * xmlSAXParseDoc: 14690 * xmlSAXParseDoc:
14038 * @sax: the SAX handler block 14691 * @sax: the SAX handler block
14039 * @cur: a pointer to an array of xmlChar 14692 * @cur: a pointer to an array of xmlChar
14040 * @recovery: work in recovery mode, i.e. tries to read no Well Formed 14693 * @recovery: work in recovery mode, i.e. tries to read no Well Formed
14041 * documents 14694 * documents
14042 * 14695 *
14043 * parse an XML in-memory document and build a tree. 14696 * parse an XML in-memory document and build a tree.
14044 * It use the given SAX function block to handle the parsing callback. 14697 * It use the given SAX function block to handle the parsing callback.
14045 * If sax is NULL, fallback to the default DOM tree building routines. 14698 * If sax is NULL, fallback to the default DOM tree building routines.
14046 * 14699 *
14047 * Returns the resulting document tree 14700 * Returns the resulting document tree
14048 */ 14701 */
14049 14702
14050 xmlDocPtr 14703 xmlDocPtr
14051 xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) { 14704 xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) {
14052 xmlDocPtr ret; 14705 xmlDocPtr ret;
14053 xmlParserCtxtPtr ctxt; 14706 xmlParserCtxtPtr ctxt;
14054 xmlSAXHandlerPtr oldsax = NULL; 14707 xmlSAXHandlerPtr oldsax = NULL;
14055 14708
14056 if (cur == NULL) return(NULL); 14709 if (cur == NULL) return(NULL);
14057 14710
14058 14711
14059 ctxt = xmlCreateDocParserCtxt(cur); 14712 ctxt = xmlCreateDocParserCtxt(cur);
14060 if (ctxt == NULL) return(NULL); 14713 if (ctxt == NULL) return(NULL);
14061 if (sax != NULL) { 14714 if (sax != NULL) {
14062 oldsax = ctxt->sax; 14715 oldsax = ctxt->sax;
14063 ctxt->sax = sax; 14716 ctxt->sax = sax;
14064 ctxt->userData = NULL; 14717 ctxt->userData = NULL;
14065 } 14718 }
14066 xmlDetectSAX2(ctxt); 14719 xmlDetectSAX2(ctxt);
14067 14720
14068 xmlParseDocument(ctxt); 14721 xmlParseDocument(ctxt);
14069 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; 14722 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
14070 else { 14723 else {
14071 ret = NULL; 14724 ret = NULL;
14072 xmlFreeDoc(ctxt->myDoc); 14725 xmlFreeDoc(ctxt->myDoc);
14073 ctxt->myDoc = NULL; 14726 ctxt->myDoc = NULL;
14074 } 14727 }
14075 if (sax != NULL) 14728 if (sax != NULL)
14076 ctxt->sax = oldsax; 14729 ctxt->sax = oldsax;
14077 xmlFreeParserCtxt(ctxt); 14730 xmlFreeParserCtxt(ctxt);
14078 14731
14079 return(ret); 14732 return(ret);
14080 } 14733 }
14081 14734
14082 /** 14735 /**
14083 * xmlParseDoc: 14736 * xmlParseDoc:
14084 * @cur: a pointer to an array of xmlChar 14737 * @cur: a pointer to an array of xmlChar
14085 * 14738 *
14086 * parse an XML in-memory document and build a tree. 14739 * parse an XML in-memory document and build a tree.
14087 * 14740 *
14088 * Returns the resulting document tree 14741 * Returns the resulting document tree
14089 */ 14742 */
14090 14743
14091 xmlDocPtr 14744 xmlDocPtr
14092 xmlParseDoc(const xmlChar *cur) { 14745 xmlParseDoc(const xmlChar *cur) {
14093 return(xmlSAXParseDoc(NULL, cur, 0)); 14746 return(xmlSAXParseDoc(NULL, cur, 0));
14094 } 14747 }
14095 #endif /* LIBXML_SAX1_ENABLED */ 14748 #endif /* LIBXML_SAX1_ENABLED */
14096 14749
14097 #ifdef LIBXML_LEGACY_ENABLED 14750 #ifdef LIBXML_LEGACY_ENABLED
14098 /************************************************************************ 14751 /************************************************************************
14099 * * 14752 * *
14100 * » Specific function to keep track of entities references» » * 14753 *» Specific function to keep track of entities references» » *
14101 * » and used by the XSLT debugger» » » » » * 14754 *» and used by the XSLT debugger» » » » » *
14102 * * 14755 * *
14103 ************************************************************************/ 14756 ************************************************************************/
14104 14757
14105 static xmlEntityReferenceFunc xmlEntityRefFunc = NULL; 14758 static xmlEntityReferenceFunc xmlEntityRefFunc = NULL;
14106 14759
14107 /** 14760 /**
14108 * xmlAddEntityReference: 14761 * xmlAddEntityReference:
14109 * @ent : A valid entity 14762 * @ent : A valid entity
14110 * @firstNode : A valid first node for children of entity 14763 * @firstNode : A valid first node for children of entity
14111 * @lastNode : A valid last node of children entity 14764 * @lastNode : A valid last node of children entity
14112 * 14765 *
14113 * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY 14766 * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY
14114 */ 14767 */
14115 static void 14768 static void
14116 xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode, 14769 xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode,
14117 xmlNodePtr lastNode) 14770 xmlNodePtr lastNode)
14118 { 14771 {
14119 if (xmlEntityRefFunc != NULL) { 14772 if (xmlEntityRefFunc != NULL) {
14120 (*xmlEntityRefFunc) (ent, firstNode, lastNode); 14773 (*xmlEntityRefFunc) (ent, firstNode, lastNode);
14121 } 14774 }
14122 } 14775 }
14123 14776
14124 14777
14125 /** 14778 /**
14126 * xmlSetEntityReferenceFunc: 14779 * xmlSetEntityReferenceFunc:
14127 * @func: A valid function 14780 * @func: A valid function
14128 * 14781 *
14129 * Set the function to call call back when a xml reference has been made 14782 * Set the function to call call back when a xml reference has been made
14130 */ 14783 */
14131 void 14784 void
14132 xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) 14785 xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func)
14133 { 14786 {
14134 xmlEntityRefFunc = func; 14787 xmlEntityRefFunc = func;
14135 } 14788 }
14136 #endif /* LIBXML_LEGACY_ENABLED */ 14789 #endif /* LIBXML_LEGACY_ENABLED */
14137 14790
14138 /************************************************************************ 14791 /************************************************************************
14139 * * 14792 * *
14140 * » » » » Miscellaneous» » » » * 14793 *» » » » Miscellaneous» » » » *
14141 * * 14794 * *
14142 ************************************************************************/ 14795 ************************************************************************/
14143 14796
14144 #ifdef LIBXML_XPATH_ENABLED 14797 #ifdef LIBXML_XPATH_ENABLED
14145 #include <libxml/xpath.h> 14798 #include <libxml/xpath.h>
14146 #endif 14799 #endif
14147 14800
14148 extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...) ; 14801 extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...) ;
14149 static int xmlParserInitialized = 0; 14802 static int xmlParserInitialized = 0;
14150 14803
14151 /** 14804 /**
14152 * xmlInitParser: 14805 * xmlInitParser:
14153 * 14806 *
14154 * Initialization function for the XML parser. 14807 * Initialization function for the XML parser.
14155 * This is not reentrant. Call once before processing in case of 14808 * This is not reentrant. Call once before processing in case of
14156 * use in multithreaded programs. 14809 * use in multithreaded programs.
14157 */ 14810 */
14158 14811
14159 void 14812 void
14160 xmlInitParser(void) { 14813 xmlInitParser(void) {
14161 if (xmlParserInitialized != 0) 14814 if (xmlParserInitialized != 0)
14162 return; 14815 return;
14163 14816
14164 #ifdef LIBXML_THREAD_ENABLED 14817 #ifdef LIBXML_THREAD_ENABLED
14165 __xmlGlobalInitMutexLock(); 14818 __xmlGlobalInitMutexLock();
14166 if (xmlParserInitialized == 0) { 14819 if (xmlParserInitialized == 0) {
14167 #endif 14820 #endif
14821 xmlInitThreads();
14168 xmlInitGlobals(); 14822 xmlInitGlobals();
14169 xmlInitThreads();
14170 if ((xmlGenericError == xmlGenericErrorDefaultFunc) || 14823 if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
14171 (xmlGenericError == NULL)) 14824 (xmlGenericError == NULL))
14172 initGenericErrorDefaultFunc(NULL); 14825 initGenericErrorDefaultFunc(NULL);
14173 xmlInitMemory(); 14826 xmlInitMemory();
14827 xmlInitializeDict();
14174 xmlInitCharEncodingHandlers(); 14828 xmlInitCharEncodingHandlers();
14175 xmlDefaultSAXHandlerInit(); 14829 xmlDefaultSAXHandlerInit();
14176 xmlRegisterDefaultInputCallbacks(); 14830 xmlRegisterDefaultInputCallbacks();
14177 #ifdef LIBXML_OUTPUT_ENABLED 14831 #ifdef LIBXML_OUTPUT_ENABLED
14178 xmlRegisterDefaultOutputCallbacks(); 14832 xmlRegisterDefaultOutputCallbacks();
14179 #endif /* LIBXML_OUTPUT_ENABLED */ 14833 #endif /* LIBXML_OUTPUT_ENABLED */
14180 #ifdef LIBXML_HTML_ENABLED 14834 #ifdef LIBXML_HTML_ENABLED
14181 htmlInitAutoClose(); 14835 htmlInitAutoClose();
14182 htmlDefaultSAXHandlerInit(); 14836 htmlDefaultSAXHandlerInit();
14183 #endif 14837 #endif
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
14224 #endif 14878 #endif
14225 xmlDictCleanup(); 14879 xmlDictCleanup();
14226 xmlCleanupInputCallbacks(); 14880 xmlCleanupInputCallbacks();
14227 #ifdef LIBXML_OUTPUT_ENABLED 14881 #ifdef LIBXML_OUTPUT_ENABLED
14228 xmlCleanupOutputCallbacks(); 14882 xmlCleanupOutputCallbacks();
14229 #endif 14883 #endif
14230 #ifdef LIBXML_SCHEMAS_ENABLED 14884 #ifdef LIBXML_SCHEMAS_ENABLED
14231 xmlSchemaCleanupTypes(); 14885 xmlSchemaCleanupTypes();
14232 xmlRelaxNGCleanupTypes(); 14886 xmlRelaxNGCleanupTypes();
14233 #endif 14887 #endif
14888 xmlResetLastError();
14234 xmlCleanupGlobals(); 14889 xmlCleanupGlobals();
14235 xmlResetLastError();
14236 xmlCleanupThreads(); /* must be last if called not from the main thread */ 14890 xmlCleanupThreads(); /* must be last if called not from the main thread */
14237 xmlCleanupMemory(); 14891 xmlCleanupMemory();
14238 xmlParserInitialized = 0; 14892 xmlParserInitialized = 0;
14239 } 14893 }
14240 14894
14241 /************************************************************************ 14895 /************************************************************************
14242 * * 14896 * *
14243 * New set (2.6.0) of simpler and more flexible APIs * 14897 * New set (2.6.0) of simpler and more flexible APIs *
14244 * * 14898 * *
14245 ************************************************************************/ 14899 ************************************************************************/
14246 14900
14247 /** 14901 /**
14248 * DICT_FREE: 14902 * DICT_FREE:
14249 * @str: a string 14903 * @str: a string
14250 * 14904 *
14251 * Free a string if it is not owned by the "dict" dictionnary in the 14905 * Free a string if it is not owned by the "dict" dictionnary in the
14252 * current scope 14906 * current scope
14253 */ 14907 */
14254 #define DICT_FREE(str) \ 14908 #define DICT_FREE(str) \
14255 » if ((str) && ((!dict) || » » » » \ 14909 » if ((str) && ((!dict) ||» » » » \
14256 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ 14910 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
14257 xmlFree((char *)(str)); 14911 xmlFree((char *)(str));
14258 14912
14259 /** 14913 /**
14260 * xmlCtxtReset: 14914 * xmlCtxtReset:
14261 * @ctxt: an XML parser context 14915 * @ctxt: an XML parser context
14262 * 14916 *
14263 * Reset a parser context 14917 * Reset a parser context
14264 */ 14918 */
14265 void 14919 void
14266 xmlCtxtReset(xmlParserCtxtPtr ctxt) 14920 xmlCtxtReset(xmlParserCtxtPtr ctxt)
14267 { 14921 {
14268 xmlParserInputPtr input; 14922 xmlParserInputPtr input;
14269 xmlDictPtr dict; 14923 xmlDictPtr dict;
14270 14924
14271 if (ctxt == NULL) 14925 if (ctxt == NULL)
14272 return; 14926 return;
14273 14927
14274 dict = ctxt->dict; 14928 dict = ctxt->dict;
14275 14929
14276 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */ 14930 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
14277 xmlFreeInputStream(input); 14931 xmlFreeInputStream(input);
14278 } 14932 }
14279 ctxt->inputNr = 0; 14933 ctxt->inputNr = 0;
14280 ctxt->input = NULL; 14934 ctxt->input = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
14328 ctxt->record_info = 0; 14982 ctxt->record_info = 0;
14329 ctxt->nbChars = 0; 14983 ctxt->nbChars = 0;
14330 ctxt->checkIndex = 0; 14984 ctxt->checkIndex = 0;
14331 ctxt->inSubset = 0; 14985 ctxt->inSubset = 0;
14332 ctxt->errNo = XML_ERR_OK; 14986 ctxt->errNo = XML_ERR_OK;
14333 ctxt->depth = 0; 14987 ctxt->depth = 0;
14334 ctxt->charset = XML_CHAR_ENCODING_UTF8; 14988 ctxt->charset = XML_CHAR_ENCODING_UTF8;
14335 ctxt->catalogs = NULL; 14989 ctxt->catalogs = NULL;
14336 ctxt->nbentities = 0; 14990 ctxt->nbentities = 0;
14337 ctxt->sizeentities = 0; 14991 ctxt->sizeentities = 0;
14992 ctxt->sizeentcopy = 0;
14338 xmlInitNodeInfoSeq(&ctxt->node_seq); 14993 xmlInitNodeInfoSeq(&ctxt->node_seq);
14339 14994
14340 if (ctxt->attsDefault != NULL) { 14995 if (ctxt->attsDefault != NULL) {
14341 xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree); 14996 xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree);
14342 ctxt->attsDefault = NULL; 14997 ctxt->attsDefault = NULL;
14343 } 14998 }
14344 if (ctxt->attsSpecial != NULL) { 14999 if (ctxt->attsSpecial != NULL) {
14345 xmlHashFree(ctxt->attsSpecial, NULL); 15000 xmlHashFree(ctxt->attsSpecial, NULL);
14346 ctxt->attsSpecial = NULL; 15001 ctxt->attsSpecial = NULL;
14347 } 15002 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
14412 xmlFreeParserInputBuffer(buf); 15067 xmlFreeParserInputBuffer(buf);
14413 return(1); 15068 return(1);
14414 } 15069 }
14415 15070
14416 if (filename == NULL) 15071 if (filename == NULL)
14417 inputStream->filename = NULL; 15072 inputStream->filename = NULL;
14418 else 15073 else
14419 inputStream->filename = (char *) 15074 inputStream->filename = (char *)
14420 xmlCanonicPath((const xmlChar *) filename); 15075 xmlCanonicPath((const xmlChar *) filename);
14421 inputStream->buf = buf; 15076 inputStream->buf = buf;
14422 inputStream->base = inputStream->buf->buffer->content; 15077 xmlBufResetInput(buf->buffer, inputStream);
14423 inputStream->cur = inputStream->buf->buffer->content;
14424 inputStream->end =
14425 &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
14426 15078
14427 inputPush(ctxt, inputStream); 15079 inputPush(ctxt, inputStream);
14428 15080
14429 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && 15081 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
14430 (ctxt->input->buf != NULL)) { 15082 (ctxt->input->buf != NULL)) {
14431 int base = ctxt->input->base - ctxt->input->buf->buffer->content; 15083 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
14432 int cur = ctxt->input->cur - ctxt->input->base; 15084 size_t cur = ctxt->input->cur - ctxt->input->base;
14433 15085
14434 xmlParserInputBufferPush(ctxt->input->buf, size, chunk); 15086 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
14435 15087
14436 ctxt->input->base = ctxt->input->buf->buffer->content + base; 15088 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
14437 ctxt->input->cur = ctxt->input->base + cur;
14438 ctxt->input->end =
14439 &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->
14440 use];
14441 #ifdef DEBUG_PUSH 15089 #ifdef DEBUG_PUSH
14442 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 15090 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
14443 #endif 15091 #endif
14444 } 15092 }
14445 15093
14446 if (encoding != NULL) { 15094 if (encoding != NULL) {
14447 xmlCharEncodingHandlerPtr hdlr; 15095 xmlCharEncodingHandlerPtr hdlr;
14448 15096
14449 if (ctxt->encoding != NULL) 15097 if (ctxt->encoding != NULL)
14450 xmlFree((xmlChar *) ctxt->encoding); 15098 xmlFree((xmlChar *) ctxt->encoding);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
14581 ctxt->options |= XML_PARSE_OLD10; 15229 ctxt->options |= XML_PARSE_OLD10;
14582 options -= XML_PARSE_OLD10; 15230 options -= XML_PARSE_OLD10;
14583 } 15231 }
14584 if (options & XML_PARSE_NOBASEFIX) { 15232 if (options & XML_PARSE_NOBASEFIX) {
14585 ctxt->options |= XML_PARSE_NOBASEFIX; 15233 ctxt->options |= XML_PARSE_NOBASEFIX;
14586 options -= XML_PARSE_NOBASEFIX; 15234 options -= XML_PARSE_NOBASEFIX;
14587 } 15235 }
14588 if (options & XML_PARSE_HUGE) { 15236 if (options & XML_PARSE_HUGE) {
14589 ctxt->options |= XML_PARSE_HUGE; 15237 ctxt->options |= XML_PARSE_HUGE;
14590 options -= XML_PARSE_HUGE; 15238 options -= XML_PARSE_HUGE;
15239 if (ctxt->dict != NULL)
15240 xmlDictSetLimit(ctxt->dict, 0);
14591 } 15241 }
14592 if (options & XML_PARSE_OLDSAX) { 15242 if (options & XML_PARSE_OLDSAX) {
14593 ctxt->options |= XML_PARSE_OLDSAX; 15243 ctxt->options |= XML_PARSE_OLDSAX;
14594 options -= XML_PARSE_OLDSAX; 15244 options -= XML_PARSE_OLDSAX;
14595 } 15245 }
15246 if (options & XML_PARSE_IGNORE_ENC) {
15247 ctxt->options |= XML_PARSE_IGNORE_ENC;
15248 options -= XML_PARSE_IGNORE_ENC;
15249 }
15250 if (options & XML_PARSE_BIG_LINES) {
15251 ctxt->options |= XML_PARSE_BIG_LINES;
15252 options -= XML_PARSE_BIG_LINES;
15253 }
14596 ctxt->linenumbers = 1; 15254 ctxt->linenumbers = 1;
14597 return (options); 15255 return (options);
14598 } 15256 }
14599 15257
14600 /** 15258 /**
14601 * xmlCtxtUseOptions: 15259 * xmlCtxtUseOptions:
14602 * @ctxt: an XML parser context 15260 * @ctxt: an XML parser context
14603 * @options: a combination of xmlParserOption 15261 * @options: a combination of xmlParserOption
14604 * 15262 *
14605 * Applies the options to the parser context 15263 * Applies the options to the parser context
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
14660 } 15318 }
14661 15319
14662 /** 15320 /**
14663 * xmlReadDoc: 15321 * xmlReadDoc:
14664 * @cur: a pointer to a zero terminated string 15322 * @cur: a pointer to a zero terminated string
14665 * @URL: the base URL to use for the document 15323 * @URL: the base URL to use for the document
14666 * @encoding: the document encoding, or NULL 15324 * @encoding: the document encoding, or NULL
14667 * @options: a combination of xmlParserOption 15325 * @options: a combination of xmlParserOption
14668 * 15326 *
14669 * parse an XML in-memory document and build a tree. 15327 * parse an XML in-memory document and build a tree.
14670 * 15328 *
14671 * Returns the resulting document tree 15329 * Returns the resulting document tree
14672 */ 15330 */
14673 xmlDocPtr 15331 xmlDocPtr
14674 xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int optio ns) 15332 xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int optio ns)
14675 { 15333 {
14676 xmlParserCtxtPtr ctxt; 15334 xmlParserCtxtPtr ctxt;
14677 15335
14678 if (cur == NULL) 15336 if (cur == NULL)
14679 return (NULL); 15337 return (NULL);
15338 xmlInitParser();
14680 15339
14681 ctxt = xmlCreateDocParserCtxt(cur); 15340 ctxt = xmlCreateDocParserCtxt(cur);
14682 if (ctxt == NULL) 15341 if (ctxt == NULL)
14683 return (NULL); 15342 return (NULL);
14684 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15343 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14685 } 15344 }
14686 15345
14687 /** 15346 /**
14688 * xmlReadFile: 15347 * xmlReadFile:
14689 * @filename: a file or URL 15348 * @filename: a file or URL
14690 * @encoding: the document encoding, or NULL 15349 * @encoding: the document encoding, or NULL
14691 * @options: a combination of xmlParserOption 15350 * @options: a combination of xmlParserOption
14692 * 15351 *
14693 * parse an XML file from the filesystem or the network. 15352 * parse an XML file from the filesystem or the network.
14694 * 15353 *
14695 * Returns the resulting document tree 15354 * Returns the resulting document tree
14696 */ 15355 */
14697 xmlDocPtr 15356 xmlDocPtr
14698 xmlReadFile(const char *filename, const char *encoding, int options) 15357 xmlReadFile(const char *filename, const char *encoding, int options)
14699 { 15358 {
14700 xmlParserCtxtPtr ctxt; 15359 xmlParserCtxtPtr ctxt;
14701 15360
15361 xmlInitParser();
14702 ctxt = xmlCreateURLParserCtxt(filename, options); 15362 ctxt = xmlCreateURLParserCtxt(filename, options);
14703 if (ctxt == NULL) 15363 if (ctxt == NULL)
14704 return (NULL); 15364 return (NULL);
14705 return (xmlDoRead(ctxt, NULL, encoding, options, 0)); 15365 return (xmlDoRead(ctxt, NULL, encoding, options, 0));
14706 } 15366 }
14707 15367
14708 /** 15368 /**
14709 * xmlReadMemory: 15369 * xmlReadMemory:
14710 * @buffer: a pointer to a char array 15370 * @buffer: a pointer to a char array
14711 * @size: the size of the array 15371 * @size: the size of the array
14712 * @URL: the base URL to use for the document 15372 * @URL: the base URL to use for the document
14713 * @encoding: the document encoding, or NULL 15373 * @encoding: the document encoding, or NULL
14714 * @options: a combination of xmlParserOption 15374 * @options: a combination of xmlParserOption
14715 * 15375 *
14716 * parse an XML in-memory document and build a tree. 15376 * parse an XML in-memory document and build a tree.
14717 * 15377 *
14718 * Returns the resulting document tree 15378 * Returns the resulting document tree
14719 */ 15379 */
14720 xmlDocPtr 15380 xmlDocPtr
14721 xmlReadMemory(const char *buffer, int size, const char *URL, const char *encodin g, int options) 15381 xmlReadMemory(const char *buffer, int size, const char *URL, const char *encodin g, int options)
14722 { 15382 {
14723 xmlParserCtxtPtr ctxt; 15383 xmlParserCtxtPtr ctxt;
14724 15384
15385 xmlInitParser();
14725 ctxt = xmlCreateMemoryParserCtxt(buffer, size); 15386 ctxt = xmlCreateMemoryParserCtxt(buffer, size);
14726 if (ctxt == NULL) 15387 if (ctxt == NULL)
14727 return (NULL); 15388 return (NULL);
14728 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15389 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14729 } 15390 }
14730 15391
14731 /** 15392 /**
14732 * xmlReadFd: 15393 * xmlReadFd:
14733 * @fd: an open file descriptor 15394 * @fd: an open file descriptor
14734 * @URL: the base URL to use for the document 15395 * @URL: the base URL to use for the document
14735 * @encoding: the document encoding, or NULL 15396 * @encoding: the document encoding, or NULL
14736 * @options: a combination of xmlParserOption 15397 * @options: a combination of xmlParserOption
14737 * 15398 *
14738 * parse an XML from a file descriptor and build a tree. 15399 * parse an XML from a file descriptor and build a tree.
14739 * NOTE that the file descriptor will not be closed when the 15400 * NOTE that the file descriptor will not be closed when the
14740 * reader is closed or reset. 15401 * reader is closed or reset.
14741 * 15402 *
14742 * Returns the resulting document tree 15403 * Returns the resulting document tree
14743 */ 15404 */
14744 xmlDocPtr 15405 xmlDocPtr
14745 xmlReadFd(int fd, const char *URL, const char *encoding, int options) 15406 xmlReadFd(int fd, const char *URL, const char *encoding, int options)
14746 { 15407 {
14747 xmlParserCtxtPtr ctxt; 15408 xmlParserCtxtPtr ctxt;
14748 xmlParserInputBufferPtr input; 15409 xmlParserInputBufferPtr input;
14749 xmlParserInputPtr stream; 15410 xmlParserInputPtr stream;
14750 15411
14751 if (fd < 0) 15412 if (fd < 0)
14752 return (NULL); 15413 return (NULL);
15414 xmlInitParser();
14753 15415
14754 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); 15416 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
14755 if (input == NULL) 15417 if (input == NULL)
14756 return (NULL); 15418 return (NULL);
14757 input->closecallback = NULL; 15419 input->closecallback = NULL;
14758 ctxt = xmlNewParserCtxt(); 15420 ctxt = xmlNewParserCtxt();
14759 if (ctxt == NULL) { 15421 if (ctxt == NULL) {
14760 xmlFreeParserInputBuffer(input); 15422 xmlFreeParserInputBuffer(input);
14761 return (NULL); 15423 return (NULL);
14762 } 15424 }
(...skipping 10 matching lines...) Expand all
14773 /** 15435 /**
14774 * xmlReadIO: 15436 * xmlReadIO:
14775 * @ioread: an I/O read function 15437 * @ioread: an I/O read function
14776 * @ioclose: an I/O close function 15438 * @ioclose: an I/O close function
14777 * @ioctx: an I/O handler 15439 * @ioctx: an I/O handler
14778 * @URL: the base URL to use for the document 15440 * @URL: the base URL to use for the document
14779 * @encoding: the document encoding, or NULL 15441 * @encoding: the document encoding, or NULL
14780 * @options: a combination of xmlParserOption 15442 * @options: a combination of xmlParserOption
14781 * 15443 *
14782 * parse an XML document from I/O functions and source and build a tree. 15444 * parse an XML document from I/O functions and source and build a tree.
14783 * 15445 *
14784 * Returns the resulting document tree 15446 * Returns the resulting document tree
14785 */ 15447 */
14786 xmlDocPtr 15448 xmlDocPtr
14787 xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, 15449 xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
14788 void *ioctx, const char *URL, const char *encoding, int options) 15450 void *ioctx, const char *URL, const char *encoding, int options)
14789 { 15451 {
14790 xmlParserCtxtPtr ctxt; 15452 xmlParserCtxtPtr ctxt;
14791 xmlParserInputBufferPtr input; 15453 xmlParserInputBufferPtr input;
14792 xmlParserInputPtr stream; 15454 xmlParserInputPtr stream;
14793 15455
14794 if (ioread == NULL) 15456 if (ioread == NULL)
14795 return (NULL); 15457 return (NULL);
15458 xmlInitParser();
14796 15459
14797 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 15460 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
14798 XML_CHAR_ENCODING_NONE); 15461 XML_CHAR_ENCODING_NONE);
14799 if (input == NULL) 15462 if (input == NULL) {
15463 if (ioclose != NULL)
15464 ioclose(ioctx);
14800 return (NULL); 15465 return (NULL);
15466 }
14801 ctxt = xmlNewParserCtxt(); 15467 ctxt = xmlNewParserCtxt();
14802 if (ctxt == NULL) { 15468 if (ctxt == NULL) {
14803 xmlFreeParserInputBuffer(input); 15469 xmlFreeParserInputBuffer(input);
14804 return (NULL); 15470 return (NULL);
14805 } 15471 }
14806 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15472 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14807 if (stream == NULL) { 15473 if (stream == NULL) {
14808 xmlFreeParserInputBuffer(input); 15474 xmlFreeParserInputBuffer(input);
14809 xmlFreeParserCtxt(ctxt); 15475 xmlFreeParserCtxt(ctxt);
14810 return (NULL); 15476 return (NULL);
14811 } 15477 }
14812 inputPush(ctxt, stream); 15478 inputPush(ctxt, stream);
14813 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15479 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14814 } 15480 }
14815 15481
14816 /** 15482 /**
14817 * xmlCtxtReadDoc: 15483 * xmlCtxtReadDoc:
14818 * @ctxt: an XML parser context 15484 * @ctxt: an XML parser context
14819 * @cur: a pointer to a zero terminated string 15485 * @cur: a pointer to a zero terminated string
14820 * @URL: the base URL to use for the document 15486 * @URL: the base URL to use for the document
14821 * @encoding: the document encoding, or NULL 15487 * @encoding: the document encoding, or NULL
14822 * @options: a combination of xmlParserOption 15488 * @options: a combination of xmlParserOption
14823 * 15489 *
14824 * parse an XML in-memory document and build a tree. 15490 * parse an XML in-memory document and build a tree.
14825 * This reuses the existing @ctxt parser context 15491 * This reuses the existing @ctxt parser context
14826 * 15492 *
14827 * Returns the resulting document tree 15493 * Returns the resulting document tree
14828 */ 15494 */
14829 xmlDocPtr 15495 xmlDocPtr
14830 xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur, 15496 xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
14831 const char *URL, const char *encoding, int options) 15497 const char *URL, const char *encoding, int options)
14832 { 15498 {
14833 xmlParserInputPtr stream; 15499 xmlParserInputPtr stream;
14834 15500
14835 if (cur == NULL) 15501 if (cur == NULL)
14836 return (NULL); 15502 return (NULL);
14837 if (ctxt == NULL) 15503 if (ctxt == NULL)
14838 return (NULL); 15504 return (NULL);
15505 xmlInitParser();
14839 15506
14840 xmlCtxtReset(ctxt); 15507 xmlCtxtReset(ctxt);
14841 15508
14842 stream = xmlNewStringInputStream(ctxt, cur); 15509 stream = xmlNewStringInputStream(ctxt, cur);
14843 if (stream == NULL) { 15510 if (stream == NULL) {
14844 return (NULL); 15511 return (NULL);
14845 } 15512 }
14846 inputPush(ctxt, stream); 15513 inputPush(ctxt, stream);
14847 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15514 return (xmlDoRead(ctxt, URL, encoding, options, 1));
14848 } 15515 }
14849 15516
14850 /** 15517 /**
14851 * xmlCtxtReadFile: 15518 * xmlCtxtReadFile:
14852 * @ctxt: an XML parser context 15519 * @ctxt: an XML parser context
14853 * @filename: a file or URL 15520 * @filename: a file or URL
14854 * @encoding: the document encoding, or NULL 15521 * @encoding: the document encoding, or NULL
14855 * @options: a combination of xmlParserOption 15522 * @options: a combination of xmlParserOption
14856 * 15523 *
14857 * parse an XML file from the filesystem or the network. 15524 * parse an XML file from the filesystem or the network.
14858 * This reuses the existing @ctxt parser context 15525 * This reuses the existing @ctxt parser context
14859 * 15526 *
14860 * Returns the resulting document tree 15527 * Returns the resulting document tree
14861 */ 15528 */
14862 xmlDocPtr 15529 xmlDocPtr
14863 xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename, 15530 xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename,
14864 const char *encoding, int options) 15531 const char *encoding, int options)
14865 { 15532 {
14866 xmlParserInputPtr stream; 15533 xmlParserInputPtr stream;
14867 15534
14868 if (filename == NULL) 15535 if (filename == NULL)
14869 return (NULL); 15536 return (NULL);
14870 if (ctxt == NULL) 15537 if (ctxt == NULL)
14871 return (NULL); 15538 return (NULL);
15539 xmlInitParser();
14872 15540
14873 xmlCtxtReset(ctxt); 15541 xmlCtxtReset(ctxt);
14874 15542
14875 stream = xmlLoadExternalEntity(filename, NULL, ctxt); 15543 stream = xmlLoadExternalEntity(filename, NULL, ctxt);
14876 if (stream == NULL) { 15544 if (stream == NULL) {
14877 return (NULL); 15545 return (NULL);
14878 } 15546 }
14879 inputPush(ctxt, stream); 15547 inputPush(ctxt, stream);
14880 return (xmlDoRead(ctxt, NULL, encoding, options, 1)); 15548 return (xmlDoRead(ctxt, NULL, encoding, options, 1));
14881 } 15549 }
14882 15550
14883 /** 15551 /**
14884 * xmlCtxtReadMemory: 15552 * xmlCtxtReadMemory:
14885 * @ctxt: an XML parser context 15553 * @ctxt: an XML parser context
14886 * @buffer: a pointer to a char array 15554 * @buffer: a pointer to a char array
14887 * @size: the size of the array 15555 * @size: the size of the array
14888 * @URL: the base URL to use for the document 15556 * @URL: the base URL to use for the document
14889 * @encoding: the document encoding, or NULL 15557 * @encoding: the document encoding, or NULL
14890 * @options: a combination of xmlParserOption 15558 * @options: a combination of xmlParserOption
14891 * 15559 *
14892 * parse an XML in-memory document and build a tree. 15560 * parse an XML in-memory document and build a tree.
14893 * This reuses the existing @ctxt parser context 15561 * This reuses the existing @ctxt parser context
14894 * 15562 *
14895 * Returns the resulting document tree 15563 * Returns the resulting document tree
14896 */ 15564 */
14897 xmlDocPtr 15565 xmlDocPtr
14898 xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size, 15566 xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size,
14899 const char *URL, const char *encoding, int options) 15567 const char *URL, const char *encoding, int options)
14900 { 15568 {
14901 xmlParserInputBufferPtr input; 15569 xmlParserInputBufferPtr input;
14902 xmlParserInputPtr stream; 15570 xmlParserInputPtr stream;
14903 15571
14904 if (ctxt == NULL) 15572 if (ctxt == NULL)
14905 return (NULL); 15573 return (NULL);
14906 if (buffer == NULL) 15574 if (buffer == NULL)
14907 return (NULL); 15575 return (NULL);
15576 xmlInitParser();
14908 15577
14909 xmlCtxtReset(ctxt); 15578 xmlCtxtReset(ctxt);
14910 15579
14911 input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE); 15580 input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE);
14912 if (input == NULL) { 15581 if (input == NULL) {
14913 return(NULL); 15582 return(NULL);
14914 } 15583 }
14915 15584
14916 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15585 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14917 if (stream == NULL) { 15586 if (stream == NULL) {
(...skipping 10 matching lines...) Expand all
14928 * @ctxt: an XML parser context 15597 * @ctxt: an XML parser context
14929 * @fd: an open file descriptor 15598 * @fd: an open file descriptor
14930 * @URL: the base URL to use for the document 15599 * @URL: the base URL to use for the document
14931 * @encoding: the document encoding, or NULL 15600 * @encoding: the document encoding, or NULL
14932 * @options: a combination of xmlParserOption 15601 * @options: a combination of xmlParserOption
14933 * 15602 *
14934 * parse an XML from a file descriptor and build a tree. 15603 * parse an XML from a file descriptor and build a tree.
14935 * This reuses the existing @ctxt parser context 15604 * This reuses the existing @ctxt parser context
14936 * NOTE that the file descriptor will not be closed when the 15605 * NOTE that the file descriptor will not be closed when the
14937 * reader is closed or reset. 15606 * reader is closed or reset.
14938 * 15607 *
14939 * Returns the resulting document tree 15608 * Returns the resulting document tree
14940 */ 15609 */
14941 xmlDocPtr 15610 xmlDocPtr
14942 xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd, 15611 xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
14943 const char *URL, const char *encoding, int options) 15612 const char *URL, const char *encoding, int options)
14944 { 15613 {
14945 xmlParserInputBufferPtr input; 15614 xmlParserInputBufferPtr input;
14946 xmlParserInputPtr stream; 15615 xmlParserInputPtr stream;
14947 15616
14948 if (fd < 0) 15617 if (fd < 0)
14949 return (NULL); 15618 return (NULL);
14950 if (ctxt == NULL) 15619 if (ctxt == NULL)
14951 return (NULL); 15620 return (NULL);
15621 xmlInitParser();
14952 15622
14953 xmlCtxtReset(ctxt); 15623 xmlCtxtReset(ctxt);
14954 15624
14955 15625
14956 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); 15626 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
14957 if (input == NULL) 15627 if (input == NULL)
14958 return (NULL); 15628 return (NULL);
14959 input->closecallback = NULL; 15629 input->closecallback = NULL;
14960 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15630 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14961 if (stream == NULL) { 15631 if (stream == NULL) {
14962 xmlFreeParserInputBuffer(input); 15632 xmlFreeParserInputBuffer(input);
14963 return (NULL); 15633 return (NULL);
14964 } 15634 }
14965 inputPush(ctxt, stream); 15635 inputPush(ctxt, stream);
14966 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15636 return (xmlDoRead(ctxt, URL, encoding, options, 1));
14967 } 15637 }
14968 15638
14969 /** 15639 /**
14970 * xmlCtxtReadIO: 15640 * xmlCtxtReadIO:
14971 * @ctxt: an XML parser context 15641 * @ctxt: an XML parser context
14972 * @ioread: an I/O read function 15642 * @ioread: an I/O read function
14973 * @ioclose: an I/O close function 15643 * @ioclose: an I/O close function
14974 * @ioctx: an I/O handler 15644 * @ioctx: an I/O handler
14975 * @URL: the base URL to use for the document 15645 * @URL: the base URL to use for the document
14976 * @encoding: the document encoding, or NULL 15646 * @encoding: the document encoding, or NULL
14977 * @options: a combination of xmlParserOption 15647 * @options: a combination of xmlParserOption
14978 * 15648 *
14979 * parse an XML document from I/O functions and source and build a tree. 15649 * parse an XML document from I/O functions and source and build a tree.
14980 * This reuses the existing @ctxt parser context 15650 * This reuses the existing @ctxt parser context
14981 * 15651 *
14982 * Returns the resulting document tree 15652 * Returns the resulting document tree
14983 */ 15653 */
14984 xmlDocPtr 15654 xmlDocPtr
14985 xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread, 15655 xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
14986 xmlInputCloseCallback ioclose, void *ioctx, 15656 xmlInputCloseCallback ioclose, void *ioctx,
14987 const char *URL, 15657 const char *URL,
14988 const char *encoding, int options) 15658 const char *encoding, int options)
14989 { 15659 {
14990 xmlParserInputBufferPtr input; 15660 xmlParserInputBufferPtr input;
14991 xmlParserInputPtr stream; 15661 xmlParserInputPtr stream;
14992 15662
14993 if (ioread == NULL) 15663 if (ioread == NULL)
14994 return (NULL); 15664 return (NULL);
14995 if (ctxt == NULL) 15665 if (ctxt == NULL)
14996 return (NULL); 15666 return (NULL);
15667 xmlInitParser();
14997 15668
14998 xmlCtxtReset(ctxt); 15669 xmlCtxtReset(ctxt);
14999 15670
15000 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 15671 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
15001 XML_CHAR_ENCODING_NONE); 15672 XML_CHAR_ENCODING_NONE);
15002 if (input == NULL) 15673 if (input == NULL) {
15674 if (ioclose != NULL)
15675 ioclose(ioctx);
15003 return (NULL); 15676 return (NULL);
15677 }
15004 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15678 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
15005 if (stream == NULL) { 15679 if (stream == NULL) {
15006 xmlFreeParserInputBuffer(input); 15680 xmlFreeParserInputBuffer(input);
15007 return (NULL); 15681 return (NULL);
15008 } 15682 }
15009 inputPush(ctxt, stream); 15683 inputPush(ctxt, stream);
15010 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15684 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15011 } 15685 }
15012 15686
15013 #define bottom_parser 15687 #define bottom_parser
15014 #include "elfgcchack.h" 15688 #include "elfgcchack.h"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698