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

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: no iconv 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
« no previous file with comments | « third_party/libxml/src/nanohttp.c ('k') | third_party/libxml/src/parserInternals.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
5333 * if the default declaration is the keyword #REQUIRED, then the 5710 * if the default declaration is the keyword #REQUIRED, then the
5334 * attribute must be specified for all elements of the type in the 5711 * attribute must be specified for all elements of the type in the
5335 * attribute-list declaration. 5712 * attribute-list declaration.
5336 * 5713 *
5337 * [ VC: Attribute Default Legal ] 5714 * [ VC: Attribute Default Legal ]
5338 * The declared default value must meet the lexical constraints of 5715 * The declared default value must meet the lexical constraints of
5339 * the declared attribute type c.f. xmlValidateAttributeDecl() 5716 * the declared attribute type c.f. xmlValidateAttributeDecl()
5340 * 5717 *
5341 * [ VC: Fixed Attribute Default ] 5718 * [ VC: Fixed Attribute Default ]
5342 * if an attribute has a default value declared with the #FIXED 5719 * if an attribute has a default value declared with the #FIXED
5343 * keyword, instances of that attribute must match the default value. 5720 * keyword, instances of that attribute must match the default value.
5344 * 5721 *
5345 * [ WFC: No < in Attribute Values ] 5722 * [ WFC: No < in Attribute Values ]
5346 * handled in xmlParseAttValue() 5723 * handled in xmlParseAttValue()
5347 * 5724 *
5348 * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED 5725 * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED
5349 * or XML_ATTRIBUTE_FIXED. 5726 * or XML_ATTRIBUTE_FIXED.
5350 */ 5727 */
5351 5728
5352 int 5729 int
5353 xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { 5730 xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) {
5354 int val; 5731 int val;
5355 xmlChar *ret; 5732 xmlChar *ret;
5356 5733
5357 *value = NULL; 5734 *value = NULL;
5358 if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) { 5735 if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) {
5359 SKIP(9); 5736 SKIP(9);
(...skipping 28 matching lines...) Expand all
5388 * @ctxt: an XML parser context 5765 * @ctxt: an XML parser context
5389 * 5766 *
5390 * parse an Notation attribute type. 5767 * parse an Notation attribute type.
5391 * 5768 *
5392 * Note: the leading 'NOTATION' S part has already being parsed... 5769 * Note: the leading 'NOTATION' S part has already being parsed...
5393 * 5770 *
5394 * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' 5771 * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
5395 * 5772 *
5396 * [ VC: Notation Attributes ] 5773 * [ VC: Notation Attributes ]
5397 * Values of this type must match one of the notation names included 5774 * 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. 5775 * in the declaration; all notation names in the declaration must be declared.
5399 * 5776 *
5400 * Returns: the notation attribute tree built while parsing 5777 * Returns: the notation attribute tree built while parsing
5401 */ 5778 */
5402 5779
5403 xmlEnumerationPtr 5780 xmlEnumerationPtr
5404 xmlParseNotationType(xmlParserCtxtPtr ctxt) { 5781 xmlParseNotationType(xmlParserCtxtPtr ctxt) {
5405 const xmlChar *name; 5782 const xmlChar *name;
5406 xmlEnumerationPtr ret = NULL, last = NULL, cur, tmp; 5783 xmlEnumerationPtr ret = NULL, last = NULL, cur, tmp;
5407 5784
5408 if (RAW != '(') { 5785 if (RAW != '(') {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 * 5965 *
5589 * [ VC: IDREF ] 5966 * [ VC: IDREF ]
5590 * Values of type IDREF must match the Name production, and values 5967 * 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 5968 * 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 5969 * of an ID attribute on some element in the XML document; i.e. IDREF
5593 * values must match the value of some ID attribute. 5970 * values must match the value of some ID attribute.
5594 * 5971 *
5595 * [ VC: Entity Name ] 5972 * [ VC: Entity Name ]
5596 * Values of type ENTITY must match the Name production, values 5973 * Values of type ENTITY must match the Name production, values
5597 * of type ENTITIES must match Names; each Entity Name must match the 5974 * of type ENTITIES must match Names; each Entity Name must match the
5598 * name of an unparsed entity declared in the DTD. 5975 * name of an unparsed entity declared in the DTD.
5599 * 5976 *
5600 * [ VC: Name Token ] 5977 * [ VC: Name Token ]
5601 * Values of type NMTOKEN must match the Nmtoken production; values 5978 * Values of type NMTOKEN must match the Nmtoken production; values
5602 * of type NMTOKENS must match Nmtokens. 5979 * of type NMTOKENS must match Nmtokens.
5603 * 5980 *
5604 * Returns the attribute type 5981 * Returns the attribute type
5605 */ 5982 */
5606 int 5983 int
5607 xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { 5984 xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
5608 SHRINK; 5985 SHRINK;
5609 if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) { 5986 if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) {
5610 SKIP(5); 5987 SKIP(5);
5611 return(XML_ATTRIBUTE_CDATA); 5988 return(XML_ATTRIBUTE_CDATA);
5612 } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) { 5989 } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) {
5613 SKIP(6); 5990 SKIP(6);
5614 return(XML_ATTRIBUTE_IDREFS); 5991 return(XML_ATTRIBUTE_IDREFS);
5615 } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) { 5992 } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) {
5616 SKIP(5); 5993 SKIP(5);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
5739 break; 6116 break;
5740 } 6117 }
5741 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 6118 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
5742 (ctxt->sax->attributeDecl != NULL)) 6119 (ctxt->sax->attributeDecl != NULL))
5743 ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName, 6120 ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName,
5744 type, def, defaultValue, tree); 6121 type, def, defaultValue, tree);
5745 else if (tree != NULL) 6122 else if (tree != NULL)
5746 xmlFreeEnumeration(tree); 6123 xmlFreeEnumeration(tree);
5747 6124
5748 if ((ctxt->sax2) && (defaultValue != NULL) && 6125 if ((ctxt->sax2) && (defaultValue != NULL) &&
5749 » (def != XML_ATTRIBUTE_IMPLIED) && 6126 » (def != XML_ATTRIBUTE_IMPLIED) &&
5750 (def != XML_ATTRIBUTE_REQUIRED)) { 6127 (def != XML_ATTRIBUTE_REQUIRED)) {
5751 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue); 6128 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue);
5752 } 6129 }
5753 if (ctxt->sax2) { 6130 if (ctxt->sax2) {
5754 xmlAddSpecialAttr(ctxt, elemName, attrName, type); 6131 xmlAddSpecialAttr(ctxt, elemName, attrName, type);
5755 } 6132 }
5756 if (defaultValue != NULL) 6133 if (defaultValue != NULL)
5757 xmlFree(defaultValue); 6134 xmlFree(defaultValue);
5758 GROW; 6135 GROW;
5759 } 6136 }
5760 if (RAW == '>') { 6137 if (RAW == '>') {
5761 if (input != ctxt->input) { 6138 if (input != ctxt->input) {
5762 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY, 6139 xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
5763 "Attribute list declaration doesn't start and stop in the same entity\n", 6140 "Attribute list declaration doesn't start and stop in the same entity\n",
5764 NULL, NULL); 6141 NULL, NULL);
5765 } 6142 }
5766 NEXT; 6143 NEXT;
5767 } 6144 }
5768 } 6145 }
5769 } 6146 }
5770 6147
5771 /** 6148 /**
5772 * xmlParseElementMixedContentDecl: 6149 * xmlParseElementMixedContentDecl:
5773 * @ctxt: an XML parser context 6150 * @ctxt: an XML parser context
5774 * @inputchk: the input used for the current entity, needed for boundary checks 6151 * @inputchk: the input used for the current entity, needed for boundary checks
5775 * 6152 *
5776 * parse the declaration for a Mixed Element content 6153 * parse the declaration for a Mixed Element content
5777 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl 6154 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
5778 * 6155 *
5779 * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | 6156 * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' |
5780 * '(' S? '#PCDATA' S? ')' 6157 * '(' S? '#PCDATA' S? ')'
5781 * 6158 *
5782 * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) 6159 * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49])
5783 * 6160 *
5784 * [ VC: No Duplicate Types ] 6161 * [ VC: No Duplicate Types ]
5785 * The same name must not appear more than once in a single 6162 * The same name must not appear more than once in a single
5786 * mixed-content declaration. 6163 * mixed-content declaration.
5787 * 6164 *
5788 * returns: the list of the xmlElementContentPtr describing the element choices 6165 * returns: the list of the xmlElementContentPtr describing the element choices
5789 */ 6166 */
5790 xmlElementContentPtr 6167 xmlElementContentPtr
5791 xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) { 6168 xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk) {
5792 xmlElementContentPtr ret = NULL, cur = NULL, n; 6169 xmlElementContentPtr ret = NULL, cur = NULL, n;
5793 const xmlChar *elem = NULL; 6170 const xmlChar *elem = NULL;
5794 6171
5795 GROW; 6172 GROW;
5796 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) { 6173 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 } 6253 }
5877 6254
5878 /** 6255 /**
5879 * xmlParseElementChildrenContentDeclPriv: 6256 * xmlParseElementChildrenContentDeclPriv:
5880 * @ctxt: an XML parser context 6257 * @ctxt: an XML parser context
5881 * @inputchk: the input used for the current entity, needed for boundary checks 6258 * @inputchk: the input used for the current entity, needed for boundary checks
5882 * @depth: the level of recursion 6259 * @depth: the level of recursion
5883 * 6260 *
5884 * parse the declaration for a Mixed Element content 6261 * parse the declaration for a Mixed Element content
5885 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl 6262 * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
5886 * 6263 *
5887 * 6264 *
5888 * [47] children ::= (choice | seq) ('?' | '*' | '+')? 6265 * [47] children ::= (choice | seq) ('?' | '*' | '+')?
5889 * 6266 *
5890 * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? 6267 * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
5891 * 6268 *
5892 * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' 6269 * [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'
5893 * 6270 *
5894 * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' 6271 * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
5895 * 6272 *
5896 * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] 6273 * [ VC: Proper Group/PE Nesting ] applies to [49] and [50]
5897 * TODO Parameter-entity replacement text must be properly nested 6274 * TODO Parameter-entity replacement text must be properly nested
5898 * with parenthesized groups. That is to say, if either of the 6275 * with parenthesized groups. That is to say, if either of the
5899 * opening or closing parentheses in a choice, seq, or Mixed 6276 * opening or closing parentheses in a choice, seq, or Mixed
5900 * construct is contained in the replacement text for a parameter 6277 * construct is contained in the replacement text for a parameter
5901 * entity, both must be contained in the same replacement text. For 6278 * entity, both must be contained in the same replacement text. For
5902 * interoperability, if a parameter-entity reference appears in a 6279 * interoperability, if a parameter-entity reference appears in a
5903 * choice, seq, or Mixed construct, its replacement text should not 6280 * choice, seq, or Mixed construct, its replacement text should not
5904 * be empty, and neither the first nor last non-blank character of 6281 * be empty, and neither the first nor last non-blank character of
5905 * the replacement text should be a connector (| or ,). 6282 * the replacement text should be a connector (| or ,).
5906 * 6283 *
5907 * Returns the tree of xmlElementContentPtr describing the element 6284 * Returns the tree of xmlElementContentPtr describing the element
5908 * hierarchy. 6285 * hierarchy.
5909 */ 6286 */
5910 static xmlElementContentPtr 6287 static xmlElementContentPtr
5911 xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk, 6288 xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk,
5912 int depth) { 6289 int depth) {
5913 xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL; 6290 xmlElementContentPtr ret = NULL, cur = NULL, last = NULL, op = NULL;
5914 const xmlChar *elem; 6291 const xmlChar *elem;
5915 xmlChar type = 0; 6292 xmlChar type = 0;
5916 6293
5917 if (((depth > 128) && ((ctxt->options & XML_PARSE_HUGE) == 0)) || 6294 if (((depth > 128) && ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
6210 } 6587 }
6211 6588
6212 /** 6589 /**
6213 * xmlParseElementContentDecl: 6590 * xmlParseElementContentDecl:
6214 * @ctxt: an XML parser context 6591 * @ctxt: an XML parser context
6215 * @name: the name of the element being defined. 6592 * @name: the name of the element being defined.
6216 * @result: the Element Content pointer will be stored here if any 6593 * @result: the Element Content pointer will be stored here if any
6217 * 6594 *
6218 * parse the declaration for an Element content either Mixed or Children, 6595 * parse the declaration for an Element content either Mixed or Children,
6219 * the cases EMPTY and ANY are handled directly in xmlParseElementDecl 6596 * the cases EMPTY and ANY are handled directly in xmlParseElementDecl
6220 * 6597 *
6221 * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children 6598 * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
6222 * 6599 *
6223 * returns: the type of element content XML_ELEMENT_TYPE_xxx 6600 * returns: the type of element content XML_ELEMENT_TYPE_xxx
6224 */ 6601 */
6225 6602
6226 int 6603 int
6227 xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name, 6604 xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name,
6228 xmlElementContentPtr *result) { 6605 xmlElementContentPtr *result) {
6229 6606
6230 xmlElementContentPtr tree = NULL; 6607 xmlElementContentPtr tree = NULL;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
6338 if (RAW != '>') { 6715 if (RAW != '>') {
6339 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 6716 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
6340 if (content != NULL) { 6717 if (content != NULL) {
6341 xmlFreeDocElementContent(ctxt->myDoc, content); 6718 xmlFreeDocElementContent(ctxt->myDoc, content);
6342 } 6719 }
6343 } else { 6720 } else {
6344 if (input != ctxt->input) { 6721 if (input != ctxt->input) {
6345 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY, 6722 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6346 "Element declaration doesn't start and stop in the same entity\n"); 6723 "Element declaration doesn't start and stop in the same entity\n");
6347 } 6724 }
6348 » » 6725
6349 NEXT; 6726 NEXT;
6350 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 6727 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
6351 (ctxt->sax->elementDecl != NULL)) { 6728 (ctxt->sax->elementDecl != NULL)) {
6352 if (content != NULL) 6729 if (content != NULL)
6353 content->parent = NULL; 6730 content->parent = NULL;
6354 ctxt->sax->elementDecl(ctxt->userData, name, ret, 6731 ctxt->sax->elementDecl(ctxt->userData, name, ret,
6355 content); 6732 content);
6356 if ((content != NULL) && (content->parent == NULL)) { 6733 if ((content != NULL) && (content->parent == NULL)) {
6357 /* 6734 /*
6358 * this is a trick: if xmlAddElementDecl is called, 6735 * this is a trick: if xmlAddElementDecl is called,
6359 * instead of copying the full tree it is plugged directly 6736 * instead of copying the full tree it is plugged directly
6360 » » * if called from the parser. Avoid duplicating the 6737 » » * if called from the parser. Avoid duplicating the
6361 * interfaces or change the API/ABI 6738 * interfaces or change the API/ABI
6362 */ 6739 */
6363 xmlFreeDocElementContent(ctxt->myDoc, content); 6740 xmlFreeDocElementContent(ctxt->myDoc, content);
6364 } 6741 }
6365 } else if (content != NULL) { 6742 } else if (content != NULL) {
6366 xmlFreeDocElementContent(ctxt->myDoc, content); 6743 xmlFreeDocElementContent(ctxt->myDoc, content);
6367 } 6744 }
6368 } 6745 }
6369 } 6746 }
6370 return(ret); 6747 return(ret);
6371 } 6748 }
6372 6749
6373 /** 6750 /**
6374 * xmlParseConditionalSections 6751 * xmlParseConditionalSections
6375 * @ctxt: an XML parser context 6752 * @ctxt: an XML parser context
6376 * 6753 *
6377 * [61] conditionalSect ::= includeSect | ignoreSect 6754 * [61] conditionalSect ::= includeSect | ignoreSect
6378 * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' 6755 * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
6379 * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' 6756 * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
6380 * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* 6757 * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
6381 * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) 6758 * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
6382 */ 6759 */
6383 6760
6384 static void 6761 static void
6385 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { 6762 xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
6386 int id = ctxt->input->id; 6763 int id = ctxt->input->id;
6387 6764
6388 SKIP(3); 6765 SKIP(3);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
6520 "All markup of the conditional section is not in the same entity\n", 6897 "All markup of the conditional section is not in the same entity\n",
6521 NULL, NULL); 6898 NULL, NULL);
6522 } 6899 }
6523 SKIP(3); 6900 SKIP(3);
6524 } 6901 }
6525 } 6902 }
6526 6903
6527 /** 6904 /**
6528 * xmlParseMarkupDecl: 6905 * xmlParseMarkupDecl:
6529 * @ctxt: an XML parser context 6906 * @ctxt: an XML parser context
6530 * 6907 *
6531 * parse Markup declarations 6908 * parse Markup declarations
6532 * 6909 *
6533 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | 6910 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
6534 * NotationDecl | PI | Comment 6911 * NotationDecl | PI | Comment
6535 * 6912 *
6536 * [ VC: Proper Declaration/PE Nesting ] 6913 * [ VC: Proper Declaration/PE Nesting ]
6537 * Parameter-entity replacement text must be properly nested with 6914 * Parameter-entity replacement text must be properly nested with
6538 * markup declarations. That is to say, if either the first character 6915 * markup declarations. That is to say, if either the first character
6539 * or the last character of a markup declaration (markupdecl above) is 6916 * or the last character of a markup declaration (markupdecl above) is
6540 * contained in the replacement text for a parameter-entity reference, 6917 * contained in the replacement text for a parameter-entity reference,
6541 * both must be contained in the same replacement text. 6918 * both must be contained in the same replacement text.
6542 * 6919 *
6543 * [ WFC: PEs in Internal Subset ] 6920 * [ WFC: PEs in Internal Subset ]
6544 * In the internal DTD subset, parameter-entity references can occur 6921 * In the internal DTD subset, parameter-entity references can occur
6545 * only where markup declarations can occur, not within markup declarations. 6922 * only where markup declarations can occur, not within markup declarations.
6546 * (This does not apply to references that occur in external parameter 6923 * (This does not apply to references that occur in external parameter
6547 * entities or to the external subset.) 6924 * entities or to the external subset.)
6548 */ 6925 */
6549 void 6926 void
6550 xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { 6927 xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
6551 GROW; 6928 GROW;
6552 if (CUR == '<') { 6929 if (CUR == '<') {
6553 if (NXT(1) == '!') { 6930 if (NXT(1) == '!') {
6554 switch (NXT(2)) { 6931 switch (NXT(2)) {
6555 case 'E': 6932 case 'E':
6556 if (NXT(3) == 'L') 6933 if (NXT(3) == 'L')
6557 xmlParseElementDecl(ctxt); 6934 xmlParseElementDecl(ctxt);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
6666 MOVETO_ENDTAG(CUR_PTR); 7043 MOVETO_ENDTAG(CUR_PTR);
6667 NEXT; 7044 NEXT;
6668 } 7045 }
6669 } 7046 }
6670 7047
6671 /** 7048 /**
6672 * xmlParseExternalSubset: 7049 * xmlParseExternalSubset:
6673 * @ctxt: an XML parser context 7050 * @ctxt: an XML parser context
6674 * @ExternalID: the external identifier 7051 * @ExternalID: the external identifier
6675 * @SystemID: the system identifier (or URL) 7052 * @SystemID: the system identifier (or URL)
6676 * 7053 *
6677 * parse Markup declarations from an external subset 7054 * parse Markup declarations from an external subset
6678 * 7055 *
6679 * [30] extSubset ::= textDecl? extSubsetDecl 7056 * [30] extSubset ::= textDecl? extSubsetDecl
6680 * 7057 *
6681 * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) * 7058 * [31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) *
6682 */ 7059 */
6683 void 7060 void
6684 xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, 7061 xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
6685 const xmlChar *SystemID) { 7062 const xmlChar *SystemID) {
6686 xmlDetectSAX2(ctxt); 7063 xmlDetectSAX2(ctxt);
6687 GROW; 7064 GROW;
6688 7065
6689 if ((ctxt->encoding == (const xmlChar *)XML_CHAR_ENCODING_NONE) && 7066 if ((ctxt->encoding == NULL) &&
6690 (ctxt->input->end - ctxt->input->cur >= 4)) { 7067 (ctxt->input->end - ctxt->input->cur >= 4)) {
6691 xmlChar start[4]; 7068 xmlChar start[4];
6692 xmlCharEncoding enc; 7069 xmlCharEncoding enc;
6693 7070
6694 start[0] = RAW; 7071 start[0] = RAW;
6695 start[1] = NXT(1); 7072 start[1] = NXT(1);
6696 start[2] = NXT(2); 7073 start[2] = NXT(2);
6697 start[3] = NXT(3); 7074 start[3] = NXT(3);
6698 enc = xmlDetectCharEncoding(start, 4); 7075 enc = xmlDetectCharEncoding(start, 4);
6699 if (enc != XML_CHAR_ENCODING_NONE) 7076 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) && 7222 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
6846 (!ctxt->disableSAX)) 7223 (!ctxt->disableSAX))
6847 ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); 7224 ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val));
6848 return; 7225 return;
6849 } 7226 }
6850 7227
6851 /* 7228 /*
6852 * The first reference to the entity trigger a parsing phase 7229 * The first reference to the entity trigger a parsing phase
6853 * where the ent->children is filled with the result from 7230 * where the ent->children is filled with the result from
6854 * the parsing. 7231 * the parsing.
7232 * Note: external parsed entities will not be loaded, it is not
7233 * required for a non-validating parser, unless the parsing option
7234 * of validating, or substituting entities were given. Doing so is
7235 * far more secure as the parser will only process data coming from
7236 * the document entity by default.
6855 */ 7237 */
6856 if (ent->checked == 0) { 7238 if ((ent->checked == 0) &&
7239 ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||
7240 (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {
6857 unsigned long oldnbent = ctxt->nbentities; 7241 unsigned long oldnbent = ctxt->nbentities;
6858 7242
6859 /* 7243 /*
6860 * This is a bit hackish but this seems the best 7244 * This is a bit hackish but this seems the best
6861 * way to make sure both SAX and DOM entity support 7245 * way to make sure both SAX and DOM entity support
6862 * behaves okay. 7246 * behaves okay.
6863 */ 7247 */
6864 void *user_data; 7248 void *user_data;
6865 if (ctxt->userData == ctxt) 7249 if (ctxt->userData == ctxt)
6866 user_data = NULL; 7250 user_data = NULL;
(...skipping 21 matching lines...) Expand all
6888 } else { 7272 } else {
6889 ret = XML_ERR_ENTITY_PE_INTERNAL; 7273 ret = XML_ERR_ENTITY_PE_INTERNAL;
6890 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR, 7274 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR,
6891 "invalid entity type found\n", NULL); 7275 "invalid entity type found\n", NULL);
6892 } 7276 }
6893 7277
6894 /* 7278 /*
6895 * Store the number of entities needing parsing for this entity 7279 * Store the number of entities needing parsing for this entity
6896 * content and do checkings 7280 * content and do checkings
6897 */ 7281 */
6898 » ent->checked = ctxt->nbentities - oldnbent; 7282 » ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
7283 » if ((ent->content != NULL) && (xmlStrchr(ent->content, '<')))
7284 » ent->checked |= 1;
6899 if (ret == XML_ERR_ENTITY_LOOP) { 7285 if (ret == XML_ERR_ENTITY_LOOP) {
6900 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL); 7286 xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
6901 xmlFreeNodeList(list); 7287 xmlFreeNodeList(list);
6902 return; 7288 return;
6903 } 7289 }
6904 » if (xmlParserEntityCheck(ctxt, 0, ent)) { 7290 » if (xmlParserEntityCheck(ctxt, 0, ent, 0)) {
6905 xmlFreeNodeList(list); 7291 xmlFreeNodeList(list);
6906 return; 7292 return;
6907 } 7293 }
6908 7294
6909 if ((ret == XML_ERR_OK) && (list != NULL)) { 7295 if ((ret == XML_ERR_OK) && (list != NULL)) {
6910 if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) || 7296 if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) ||
6911 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&& 7297 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&&
6912 (ent->children == NULL)) { 7298 (ent->children == NULL)) {
6913 ent->children = list; 7299 ent->children = list;
6914 if (ctxt->replaceEntities) { 7300 if (ctxt->replaceEntities) {
(...skipping 19 matching lines...) Expand all
6934 list = ent->children; 7320 list = ent->children;
6935 #ifdef LIBXML_LEGACY_ENABLED 7321 #ifdef LIBXML_LEGACY_ENABLED
6936 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) 7322 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
6937 xmlAddEntityReference(ent, list, NULL); 7323 xmlAddEntityReference(ent, list, NULL);
6938 #endif /* LIBXML_LEGACY_ENABLED */ 7324 #endif /* LIBXML_LEGACY_ENABLED */
6939 } 7325 }
6940 } else { 7326 } else {
6941 ent->owner = 1; 7327 ent->owner = 1;
6942 while (list != NULL) { 7328 while (list != NULL) {
6943 list->parent = (xmlNodePtr) ent; 7329 list->parent = (xmlNodePtr) ent;
7330 xmlSetTreeDoc(list, ent->doc);
6944 if (list->next == NULL) 7331 if (list->next == NULL)
6945 ent->last = list; 7332 ent->last = list;
6946 list = list->next; 7333 list = list->next;
6947 } 7334 }
6948 } 7335 }
6949 } else { 7336 } else {
6950 xmlFreeNodeList(list); 7337 xmlFreeNodeList(list);
6951 list = NULL; 7338 list = NULL;
6952 } 7339 }
6953 } else if ((ret != XML_ERR_OK) && 7340 } else if ((ret != XML_ERR_OK) &&
6954 (ret != XML_WAR_UNDECLARED_ENTITY)) { 7341 (ret != XML_WAR_UNDECLARED_ENTITY)) {
6955 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, 7342 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
6956 "Entity '%s' failed to parse\n", ent->name); 7343 "Entity '%s' failed to parse\n", ent->name);
7344 xmlParserEntityCheck(ctxt, 0, ent, 0);
6957 } else if (list != NULL) { 7345 } else if (list != NULL) {
6958 xmlFreeNodeList(list); 7346 xmlFreeNodeList(list);
6959 list = NULL; 7347 list = NULL;
6960 } 7348 }
6961 if (ent->checked == 0) 7349 if (ent->checked == 0)
6962 » ent->checked = 1; 7350 » ent->checked = 2;
6963 } else if (ent->checked != 1) { 7351 } else if (ent->checked != 1) {
6964 » ctxt->nbentities += ent->checked; 7352 » ctxt->nbentities += ent->checked / 2;
6965 } 7353 }
6966 7354
6967 /* 7355 /*
6968 * Now that the entity content has been gathered 7356 * Now that the entity content has been gathered
6969 * provide it to the application, this can take different forms based 7357 * provide it to the application, this can take different forms based
6970 * on the parsing modes. 7358 * on the parsing modes.
6971 */ 7359 */
6972 if (ent->children == NULL) { 7360 if (ent->children == NULL) {
6973 /* 7361 /*
6974 * Probably running in SAX mode and the callbacks don't 7362 * 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. 7433 * 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 7434 * If it's not NULL we leave it alone. This is somewhat of a
7047 * hack - maybe we should have further tests to determine 7435 * hack - maybe we should have further tests to determine
7048 * what to do. 7436 * what to do.
7049 */ 7437 */
7050 if ((ctxt->node != NULL) && (ent->children != NULL)) { 7438 if ((ctxt->node != NULL) && (ent->children != NULL)) {
7051 /* 7439 /*
7052 * Seems we are generating the DOM content, do 7440 * Seems we are generating the DOM content, do
7053 * a simple tree copy for all references except the first 7441 * a simple tree copy for all references except the first
7054 * In the first occurrence list contains the replacement. 7442 * 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 */ 7443 */
7058 if (((list == NULL) && (ent->owner == 0)) || 7444 if (((list == NULL) && (ent->owner == 0)) ||
7059 (ctxt->parseMode == XML_PARSE_READER)) { 7445 (ctxt->parseMode == XML_PARSE_READER)) {
7060 xmlNodePtr nw = NULL, cur, firstChild = NULL; 7446 xmlNodePtr nw = NULL, cur, firstChild = NULL;
7061 7447
7062 /* 7448 /*
7449 * We are copying here, make sure there is no abuse
7450 */
7451 ctxt->sizeentcopy += ent->length + 5;
7452 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7453 return;
7454
7455 /*
7063 * when operating on a reader, the entities definitions 7456 * when operating on a reader, the entities definitions
7064 * are always owning the entities subtree. 7457 * are always owning the entities subtree.
7065 if (ctxt->parseMode == XML_PARSE_READER) 7458 if (ctxt->parseMode == XML_PARSE_READER)
7066 ent->owner = 1; 7459 ent->owner = 1;
7067 */ 7460 */
7068 7461
7069 cur = ent->children; 7462 cur = ent->children;
7070 while (cur != NULL) { 7463 while (cur != NULL) {
7071 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1); 7464 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
7072 if (nw != NULL) { 7465 if (nw != NULL) {
(...skipping 16 matching lines...) Expand all
7089 nw->extra = 1; 7482 nw->extra = 1;
7090 7483
7091 break; 7484 break;
7092 } 7485 }
7093 cur = cur->next; 7486 cur = cur->next;
7094 } 7487 }
7095 #ifdef LIBXML_LEGACY_ENABLED 7488 #ifdef LIBXML_LEGACY_ENABLED
7096 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) 7489 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
7097 xmlAddEntityReference(ent, firstChild, nw); 7490 xmlAddEntityReference(ent, firstChild, nw);
7098 #endif /* LIBXML_LEGACY_ENABLED */ 7491 #endif /* LIBXML_LEGACY_ENABLED */
7099 » } else if (list == NULL) { 7492 » } else if ((list == NULL) || (ctxt->inputNr > 0)) {
7100 xmlNodePtr nw = NULL, cur, next, last, 7493 xmlNodePtr nw = NULL, cur, next, last,
7101 firstChild = NULL; 7494 firstChild = NULL;
7495
7496 /*
7497 * We are copying here, make sure there is no abuse
7498 */
7499 ctxt->sizeentcopy += ent->length + 5;
7500 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7501 return;
7502
7102 /* 7503 /*
7103 * Copy the entity child list and make it the new 7504 * Copy the entity child list and make it the new
7104 * entity child list. The goal is to make sure any 7505 * entity child list. The goal is to make sure any
7105 * ID or REF referenced will be the one from the 7506 * ID or REF referenced will be the one from the
7106 * document content and not the entity copy. 7507 * document content and not the entity copy.
7107 */ 7508 */
7108 cur = ent->children; 7509 cur = ent->children;
7109 ent->children = NULL; 7510 ent->children = NULL;
7110 last = ent->last; 7511 last = ent->last;
7111 ent->last = NULL; 7512 ent->last = NULL;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
7208 "xmlParseEntityRef: no name\n"); 7609 "xmlParseEntityRef: no name\n");
7209 return(NULL); 7610 return(NULL);
7210 } 7611 }
7211 if (RAW != ';') { 7612 if (RAW != ';') {
7212 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); 7613 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
7213 return(NULL); 7614 return(NULL);
7214 } 7615 }
7215 NEXT; 7616 NEXT;
7216 7617
7217 /* 7618 /*
7218 * Predefined entites override any extra definition 7619 * Predefined entities override any extra definition
7219 */ 7620 */
7220 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) { 7621 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7221 ent = xmlGetPredefinedEntity(name); 7622 ent = xmlGetPredefinedEntity(name);
7222 if (ent != NULL) 7623 if (ent != NULL)
7223 return(ent); 7624 return(ent);
7224 } 7625 }
7225 7626
7226 /* 7627 /*
7227 * Increate the number of entity references parsed 7628 * Increase the number of entity references parsed
7228 */ 7629 */
7229 ctxt->nbentities++; 7630 ctxt->nbentities++;
7230 7631
7231 /* 7632 /*
7232 * Ask first SAX for entity resolution, otherwise try the 7633 * Ask first SAX for entity resolution, otherwise try the
7233 * entities which may have stored in the parser context. 7634 * entities which may have stored in the parser context.
7234 */ 7635 */
7235 if (ctxt->sax != NULL) { 7636 if (ctxt->sax != NULL) {
7236 if (ctxt->sax->getEntity != NULL) 7637 if (ctxt->sax->getEntity != NULL)
7237 ent = ctxt->sax->getEntity(ctxt->userData, name); 7638 ent = ctxt->sax->getEntity(ctxt->userData, name);
7238 » if ((ctxt->wellFormed == 1 ) && (ent == NULL) && 7639 » if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7239 (ctxt->options & XML_PARSE_OLDSAX)) 7640 (ctxt->options & XML_PARSE_OLDSAX))
7240 ent = xmlGetPredefinedEntity(name); 7641 ent = xmlGetPredefinedEntity(name);
7241 if ((ctxt->wellFormed == 1 ) && (ent == NULL) && 7642 if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7242 (ctxt->userData==ctxt)) { 7643 (ctxt->userData==ctxt)) {
7243 ent = xmlSAX2GetEntity(ctxt, name); 7644 ent = xmlSAX2GetEntity(ctxt, name);
7244 } 7645 }
7245 } 7646 }
7246 if (ctxt->instate == XML_PARSER_EOF) 7647 if (ctxt->instate == XML_PARSER_EOF)
7247 return(NULL); 7648 return(NULL);
7248 /* 7649 /*
(...skipping 25 matching lines...) Expand all
7274 "Entity '%s' not defined\n", name); 7675 "Entity '%s' not defined\n", name);
7275 } else { 7676 } else {
7276 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, 7677 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7277 "Entity '%s' not defined\n", name); 7678 "Entity '%s' not defined\n", name);
7278 if ((ctxt->inSubset == 0) && 7679 if ((ctxt->inSubset == 0) &&
7279 (ctxt->sax != NULL) && 7680 (ctxt->sax != NULL) &&
7280 (ctxt->sax->reference != NULL)) { 7681 (ctxt->sax->reference != NULL)) {
7281 ctxt->sax->reference(ctxt->userData, name); 7682 ctxt->sax->reference(ctxt->userData, name);
7282 } 7683 }
7283 } 7684 }
7685 xmlParserEntityCheck(ctxt, 0, ent, 0);
7284 ctxt->valid = 0; 7686 ctxt->valid = 0;
7285 } 7687 }
7286 7688
7287 /* 7689 /*
7288 * [ WFC: Parsed Entity ] 7690 * [ WFC: Parsed Entity ]
7289 * An entity reference must not contain the name of an 7691 * An entity reference must not contain the name of an
7290 * unparsed entity 7692 * unparsed entity
7291 */ 7693 */
7292 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { 7694 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
7293 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, 7695 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
7294 "Entity reference to unparsed entity %s\n", name); 7696 "Entity reference to unparsed entity %s\n", name);
7295 } 7697 }
7296 7698
7297 /* 7699 /*
7298 * [ WFC: No External Entity References ] 7700 * [ WFC: No External Entity References ]
7299 * Attribute values cannot contain direct or indirect 7701 * Attribute values cannot contain direct or indirect
7300 * entity references to external entities. 7702 * entity references to external entities.
7301 */ 7703 */
7302 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && 7704 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7303 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { 7705 (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
7304 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL, 7706 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL,
7305 "Attribute references external entity '%s'\n", name); 7707 "Attribute references external entity '%s'\n", name);
7306 } 7708 }
7307 /* 7709 /*
7308 * [ WFC: No < in Attribute Values ] 7710 * [ WFC: No < in Attribute Values ]
7309 * The replacement text of any entity referred to directly or 7711 * The replacement text of any entity referred to directly or
7310 * indirectly in an attribute value (other than "&lt;") must 7712 * indirectly in an attribute value (other than "&lt;") must
7311 * not contain a <. 7713 * not contain a <.
7312 */ 7714 */
7313 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && 7715 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7314 » (ent != NULL) && (ent->content != NULL) && 7716 » (ent != NULL) &&
7315 » (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) && 7717 » (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) {
7316 » (xmlStrchr(ent->content, '<'))) { 7718 » if (((ent->checked & 1) || (ent->checked == 0)) &&
7317 » xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE, 7719 » (ent->content != NULL) && (xmlStrchr(ent->content, '<'))) {
7318 "'<' in entity '%s' is not allowed in attributes values\n", name); 7720 » xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
7721 » "'<' in entity '%s' is not allowed in attributes values\n", name);
7722 }
7319 } 7723 }
7320 7724
7321 /* 7725 /*
7322 * Internal check, no parameter entities here ... 7726 * Internal check, no parameter entities here ...
7323 */ 7727 */
7324 else { 7728 else {
7325 switch (ent->etype) { 7729 switch (ent->etype) {
7326 case XML_INTERNAL_PARAMETER_ENTITY: 7730 case XML_INTERNAL_PARAMETER_ENTITY:
7327 case XML_EXTERNAL_PARAMETER_ENTITY: 7731 case XML_EXTERNAL_PARAMETER_ENTITY:
7328 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER, 7732 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER,
7329 "Attempt to reference the parameter entity '%s'\n", 7733 "Attempt to reference the parameter entity '%s'\n",
7330 name); 7734 name);
7331 break; 7735 break;
7332 default: 7736 default:
7333 break; 7737 break;
7334 } 7738 }
7335 } 7739 }
7336 7740
7337 /* 7741 /*
7338 * [ WFC: No Recursion ] 7742 * [ WFC: No Recursion ]
7339 * A parsed entity must not contain a recursive reference 7743 * A parsed entity must not contain a recursive reference
7340 * to itself, either directly or indirectly. 7744 * to itself, either directly or indirectly.
7341 * Done somewhere else 7745 * Done somewhere else
7342 */ 7746 */
7343 return(ent); 7747 return(ent);
7344 } 7748 }
7345 7749
7346 /** 7750 /**
7347 * xmlParseStringEntityRef: 7751 * xmlParseStringEntityRef:
7348 * @ctxt: an XML parser context 7752 * @ctxt: an XML parser context
7349 * @str: a pointer to an index in the string 7753 * @str: a pointer to an index in the string
7350 * 7754 *
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7399 if (*ptr != ';') { 7803 if (*ptr != ';') {
7400 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL); 7804 xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
7401 xmlFree(name); 7805 xmlFree(name);
7402 *str = ptr; 7806 *str = ptr;
7403 return(NULL); 7807 return(NULL);
7404 } 7808 }
7405 ptr++; 7809 ptr++;
7406 7810
7407 7811
7408 /* 7812 /*
7409 * Predefined entites override any extra definition 7813 * Predefined entities override any extra definition
7410 */ 7814 */
7411 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) { 7815 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7412 ent = xmlGetPredefinedEntity(name); 7816 ent = xmlGetPredefinedEntity(name);
7413 if (ent != NULL) { 7817 if (ent != NULL) {
7414 xmlFree(name); 7818 xmlFree(name);
7415 *str = ptr; 7819 *str = ptr;
7416 return(ent); 7820 return(ent);
7417 } 7821 }
7418 } 7822 }
7419 7823
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7452 * The declaration of a parameter entity must precede any 7856 * The declaration of a parameter entity must precede any
7453 * reference to it. 7857 * reference to it.
7454 * Similarly, the declaration of a general entity must 7858 * Similarly, the declaration of a general entity must
7455 * precede any reference to it which appears in a default 7859 * precede any reference to it which appears in a default
7456 * value in an attribute-list declaration. Note that if 7860 * value in an attribute-list declaration. Note that if
7457 * entities are declared in the external subset or in 7861 * entities are declared in the external subset or in
7458 * external parameter entities, a non-validating processor 7862 * external parameter entities, a non-validating processor
7459 * is not obligated to read and process their declarations; 7863 * is not obligated to read and process their declarations;
7460 * for such documents, the rule that an entity must be 7864 * for such documents, the rule that an entity must be
7461 * declared is a well-formedness constraint only if 7865 * declared is a well-formedness constraint only if
7462 * standalone='yes'. 7866 * standalone='yes'.
7463 */ 7867 */
7464 if (ent == NULL) { 7868 if (ent == NULL) {
7465 if ((ctxt->standalone == 1) || 7869 if ((ctxt->standalone == 1) ||
7466 ((ctxt->hasExternalSubset == 0) && 7870 ((ctxt->hasExternalSubset == 0) &&
7467 (ctxt->hasPErefs == 0))) { 7871 (ctxt->hasPErefs == 0))) {
7468 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY, 7872 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7469 "Entity '%s' not defined\n", name); 7873 "Entity '%s' not defined\n", name);
7470 } else { 7874 } else {
7471 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, 7875 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7472 "Entity '%s' not defined\n", 7876 "Entity '%s' not defined\n",
7473 name); 7877 name);
7474 } 7878 }
7879 xmlParserEntityCheck(ctxt, 0, ent, 0);
7475 /* TODO ? check regressions ctxt->valid = 0; */ 7880 /* TODO ? check regressions ctxt->valid = 0; */
7476 } 7881 }
7477 7882
7478 /* 7883 /*
7479 * [ WFC: Parsed Entity ] 7884 * [ WFC: Parsed Entity ]
7480 * An entity reference must not contain the name of an 7885 * An entity reference must not contain the name of an
7481 * unparsed entity 7886 * unparsed entity
7482 */ 7887 */
7483 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { 7888 else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
7484 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, 7889 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7543 * @ctxt: an XML parser context 7948 * @ctxt: an XML parser context
7544 * 7949 *
7545 * parse PEReference declarations 7950 * parse PEReference declarations
7546 * The entity content is handled directly by pushing it's content as 7951 * The entity content is handled directly by pushing it's content as
7547 * a new input stream. 7952 * a new input stream.
7548 * 7953 *
7549 * [69] PEReference ::= '%' Name ';' 7954 * [69] PEReference ::= '%' Name ';'
7550 * 7955 *
7551 * [ WFC: No Recursion ] 7956 * [ WFC: No Recursion ]
7552 * A parsed entity must not contain a recursive 7957 * A parsed entity must not contain a recursive
7553 * reference to itself, either directly or indirectly. 7958 * reference to itself, either directly or indirectly.
7554 * 7959 *
7555 * [ WFC: Entity Declared ] 7960 * [ WFC: Entity Declared ]
7556 * In a document without any DTD, a document with only an internal DTD 7961 * In a document without any DTD, a document with only an internal DTD
7557 * subset which contains no parameter entity references, or a document 7962 * subset which contains no parameter entity references, or a document
7558 * with "standalone='yes'", ... ... The declaration of a parameter 7963 * with "standalone='yes'", ... ... The declaration of a parameter
7559 * entity must precede any reference to it... 7964 * entity must precede any reference to it...
7560 * 7965 *
7561 * [ VC: Entity Declared ] 7966 * [ VC: Entity Declared ]
7562 * In a document with an external subset or external parameter entities 7967 * In a document with an external subset or external parameter entities
7563 * with "standalone='no'", ... ... The declaration of a parameter entity 7968 * 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 8029 * In a document with an external subset or external
7625 * parameter entities with "standalone='no'", ... 8030 * parameter entities with "standalone='no'", ...
7626 * ... The declaration of a parameter entity must 8031 * ... The declaration of a parameter entity must
7627 * precede any reference to it... 8032 * precede any reference to it...
7628 */ 8033 */
7629 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8034 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7630 "PEReference: %%%s; not found\n", 8035 "PEReference: %%%s; not found\n",
7631 name, NULL); 8036 name, NULL);
7632 ctxt->valid = 0; 8037 ctxt->valid = 0;
7633 } 8038 }
8039 xmlParserEntityCheck(ctxt, 0, NULL, 0);
7634 } else { 8040 } else {
7635 /* 8041 /*
7636 * Internal checking in case the entity quest barfed 8042 * Internal checking in case the entity quest barfed
7637 */ 8043 */
7638 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && 8044 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
7639 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { 8045 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) {
7640 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8046 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7641 "Internal: %%%s; is not a parameter entity\n", 8047 "Internal: %%%s; is not a parameter entity\n",
7642 name, NULL); 8048 name, NULL);
7643 } else if (ctxt->input->free != deallocblankswrapper) { 8049 } else if (ctxt->input->free != deallocblankswrapper) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7725 if (xmlPushInput(ctxt, input) < 0) { 8131 if (xmlPushInput(ctxt, input) < 0) {
7726 xmlBufferFree(buf); 8132 xmlBufferFree(buf);
7727 return(-1); 8133 return(-1);
7728 } 8134 }
7729 8135
7730 GROW; 8136 GROW;
7731 c = CUR_CHAR(l); 8137 c = CUR_CHAR(l);
7732 while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) && 8138 while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) &&
7733 (IS_CHAR(c))) { 8139 (IS_CHAR(c))) {
7734 xmlBufferAdd(buf, ctxt->input->cur, l); 8140 xmlBufferAdd(buf, ctxt->input->cur, l);
7735 » if (count++ > 100) { 8141 » if (count++ > XML_PARSER_CHUNK_SIZE) {
7736 count = 0; 8142 count = 0;
7737 GROW; 8143 GROW;
7738 if (ctxt->instate == XML_PARSER_EOF) { 8144 if (ctxt->instate == XML_PARSER_EOF) {
7739 xmlBufferFree(buf); 8145 xmlBufferFree(buf);
7740 return(-1); 8146 return(-1);
7741 } 8147 }
7742 } 8148 }
7743 NEXTL(l); 8149 NEXTL(l);
7744 c = CUR_CHAR(l); 8150 c = CUR_CHAR(l);
8151 if (c == 0) {
8152 count = 0;
8153 GROW;
8154 if (ctxt->instate == XML_PARSER_EOF) {
8155 xmlBufferFree(buf);
8156 return(-1);
8157 }
8158 c = CUR_CHAR(l);
8159 }
7745 } 8160 }
7746 8161
7747 if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) { 8162 if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) {
7748 xmlPopInput(ctxt); 8163 xmlPopInput(ctxt);
7749 } else if (!IS_CHAR(c)) { 8164 } else if (!IS_CHAR(c)) {
7750 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, 8165 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
7751 "xmlLoadEntityContent: invalid char value %d\n", 8166 "xmlLoadEntityContent: invalid char value %d\n",
7752 c); 8167 c);
7753 xmlBufferFree(buf); 8168 xmlBufferFree(buf);
7754 return(-1); 8169 return(-1);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
7854 * In a document with an external subset or external 8269 * In a document with an external subset or external
7855 * parameter entities with "standalone='no'", ... 8270 * parameter entities with "standalone='no'", ...
7856 * ... The declaration of a parameter entity must 8271 * ... The declaration of a parameter entity must
7857 * precede any reference to it... 8272 * precede any reference to it...
7858 */ 8273 */
7859 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8274 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7860 "PEReference: %%%s; not found\n", 8275 "PEReference: %%%s; not found\n",
7861 name, NULL); 8276 name, NULL);
7862 ctxt->valid = 0; 8277 ctxt->valid = 0;
7863 } 8278 }
8279 xmlParserEntityCheck(ctxt, 0, NULL, 0);
7864 } else { 8280 } else {
7865 /* 8281 /*
7866 * Internal checking in case the entity quest barfed 8282 * Internal checking in case the entity quest barfed
7867 */ 8283 */
7868 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) && 8284 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
7869 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) { 8285 (entity->etype != XML_EXTERNAL_PARAMETER_ENTITY)) {
7870 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY, 8286 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7871 "%%%s; is not a parameter entity\n", 8287 "%%%s; is not a parameter entity\n",
7872 name, NULL); 8288 name, NULL);
7873 } 8289 }
7874 } 8290 }
7875 ctxt->hasPErefs = 1; 8291 ctxt->hasPErefs = 1;
7876 xmlFree(name); 8292 xmlFree(name);
7877 *str = ptr; 8293 *str = ptr;
7878 return(entity); 8294 return(entity);
7879 } 8295 }
7880 8296
7881 /** 8297 /**
7882 * xmlParseDocTypeDecl: 8298 * xmlParseDocTypeDecl:
7883 * @ctxt: an XML parser context 8299 * @ctxt: an XML parser context
7884 * 8300 *
7885 * parse a DOCTYPE declaration 8301 * parse a DOCTYPE declaration
7886 * 8302 *
7887 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? 8303 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
7888 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>' 8304 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
7889 * 8305 *
7890 * [ VC: Root Element Type ] 8306 * [ VC: Root Element Type ]
7891 * The Name in the document type declaration must match the element 8307 * The Name in the document type declaration must match the element
7892 * type of the root element. 8308 * type of the root element.
7893 */ 8309 */
7894 8310
7895 void 8311 void
7896 xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { 8312 xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) {
7897 const xmlChar *name = NULL; 8313 const xmlChar *name = NULL;
7898 xmlChar *ExternalID = NULL; 8314 xmlChar *ExternalID = NULL;
7899 xmlChar *URI = NULL; 8315 xmlChar *URI = NULL;
7900 8316
7901 /* 8317 /*
7902 * We know that '<!DOCTYPE' has been detected. 8318 * We know that '<!DOCTYPE' has been detected.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
7966 8382
7967 static void 8383 static void
7968 xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { 8384 xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
7969 /* 8385 /*
7970 * Is there any DTD definition ? 8386 * Is there any DTD definition ?
7971 */ 8387 */
7972 if (RAW == '[') { 8388 if (RAW == '[') {
7973 ctxt->instate = XML_PARSER_DTD; 8389 ctxt->instate = XML_PARSER_DTD;
7974 NEXT; 8390 NEXT;
7975 /* 8391 /*
7976 » * Parse the succession of Markup declarations and 8392 » * Parse the succession of Markup declarations and
7977 * PEReferences. 8393 * PEReferences.
7978 * Subsequence (markupdecl | PEReference | S)* 8394 * Subsequence (markupdecl | PEReference | S)*
7979 */ 8395 */
7980 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) { 8396 while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
7981 const xmlChar *check = CUR_PTR; 8397 const xmlChar *check = CUR_PTR;
7982 unsigned int cons = ctxt->input->consumed; 8398 unsigned int cons = ctxt->input->consumed;
7983 8399
7984 SKIP_BLANKS; 8400 SKIP_BLANKS;
7985 xmlParseMarkupDecl(ctxt); 8401 xmlParseMarkupDecl(ctxt);
7986 xmlParsePEReference(ctxt); 8402 xmlParsePEReference(ctxt);
7987 8403
7988 /* 8404 /*
7989 * Pop-up of finished entities. 8405 * Pop-up of finished entities.
7990 */ 8406 */
7991 while ((RAW == 0) && (ctxt->inputNr > 1)) 8407 while ((RAW == 0) && (ctxt->inputNr > 1))
7992 xmlPopInput(ctxt); 8408 xmlPopInput(ctxt);
7993 8409
7994 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { 8410 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
7995 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, 8411 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
7996 "xmlParseInternalSubset: error detected in Markup declaration\n"); 8412 "xmlParseInternalSubset: error detected in Markup declaration\n");
7997 break; 8413 break;
7998 } 8414 }
7999 } 8415 }
8000 » if (RAW == ']') { 8416 » if (RAW == ']') {
8001 NEXT; 8417 NEXT;
8002 SKIP_BLANKS; 8418 SKIP_BLANKS;
8003 } 8419 }
8004 } 8420 }
8005 8421
8006 /* 8422 /*
8007 * We should be at the end of the DOCTYPE declaration. 8423 * We should be at the end of the DOCTYPE declaration.
8008 */ 8424 */
8009 if (RAW != '>') { 8425 if (RAW != '>') {
8010 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL); 8426 xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
(...skipping 10 matching lines...) Expand all
8021 * parse an attribute 8437 * parse an attribute
8022 * 8438 *
8023 * [41] Attribute ::= Name Eq AttValue 8439 * [41] Attribute ::= Name Eq AttValue
8024 * 8440 *
8025 * [ WFC: No External Entity References ] 8441 * [ WFC: No External Entity References ]
8026 * Attribute values cannot contain direct or indirect entity references 8442 * Attribute values cannot contain direct or indirect entity references
8027 * to external entities. 8443 * to external entities.
8028 * 8444 *
8029 * [ WFC: No < in Attribute Values ] 8445 * [ WFC: No < in Attribute Values ]
8030 * The replacement text of any entity referred to directly or indirectly in 8446 * The replacement text of any entity referred to directly or indirectly in
8031 * an attribute value (other than "&lt;") must not contain a <. 8447 * an attribute value (other than "&lt;") must not contain a <.
8032 * 8448 *
8033 * [ VC: Attribute Value Type ] 8449 * [ VC: Attribute Value Type ]
8034 * The attribute must have been declared; the value must be of the type 8450 * The attribute must have been declared; the value must be of the type
8035 * declared for it. 8451 * declared for it.
8036 * 8452 *
8037 * [25] Eq ::= S? '=' S? 8453 * [25] Eq ::= S? '=' S?
8038 * 8454 *
8039 * With namespace: 8455 * With namespace:
8040 * 8456 *
8041 * [NS 11] Attribute ::= QName Eq AttValue 8457 * [NS 11] Attribute ::= QName Eq AttValue
8042 * 8458 *
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8103 } 8519 }
8104 } 8520 }
8105 8521
8106 *value = val; 8522 *value = val;
8107 return(name); 8523 return(name);
8108 } 8524 }
8109 8525
8110 /** 8526 /**
8111 * xmlParseStartTag: 8527 * xmlParseStartTag:
8112 * @ctxt: an XML parser context 8528 * @ctxt: an XML parser context
8113 * 8529 *
8114 * parse a start of tag either for rule element or 8530 * parse a start of tag either for rule element or
8115 * EmptyElement. In both case we don't parse the tag closing chars. 8531 * EmptyElement. In both case we don't parse the tag closing chars.
8116 * 8532 *
8117 * [40] STag ::= '<' Name (S Attribute)* S? '>' 8533 * [40] STag ::= '<' Name (S Attribute)* S? '>'
8118 * 8534 *
8119 * [ WFC: Unique Att Spec ] 8535 * [ WFC: Unique Att Spec ]
8120 * No attribute name may appear more than once in the same start-tag or 8536 * No attribute name may appear more than once in the same start-tag or
8121 * empty-element tag. 8537 * empty-element tag.
8122 * 8538 *
8123 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' 8539 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
8124 * 8540 *
8125 * [ WFC: Unique Att Spec ] 8541 * [ WFC: Unique Att Spec ]
8126 * No attribute name may appear more than once in the same start-tag or 8542 * No attribute name may appear more than once in the same start-tag or
8127 * empty-element tag. 8543 * empty-element tag.
8128 * 8544 *
8129 * With namespace: 8545 * With namespace:
8130 * 8546 *
8131 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' 8547 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
8132 * 8548 *
8133 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' 8549 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
8134 * 8550 *
8135 * Returns the element name parsed 8551 * Returns the element name parsed
8136 */ 8552 */
8137 8553
(...skipping 18 matching lines...) Expand all
8156 } 8572 }
8157 8573
8158 /* 8574 /*
8159 * Now parse the attributes, it ends up with the ending 8575 * Now parse the attributes, it ends up with the ending
8160 * 8576 *
8161 * (S Attribute)* S? 8577 * (S Attribute)* S?
8162 */ 8578 */
8163 SKIP_BLANKS; 8579 SKIP_BLANKS;
8164 GROW; 8580 GROW;
8165 8581
8166 while (((RAW != '>') && 8582 while (((RAW != '>') &&
8167 ((RAW != '/') || (NXT(1) != '>')) && 8583 ((RAW != '/') || (NXT(1) != '>')) &&
8168 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { 8584 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
8169 const xmlChar *q = CUR_PTR; 8585 const xmlChar *q = CUR_PTR;
8170 unsigned int cons = ctxt->input->consumed; 8586 unsigned int cons = ctxt->input->consumed;
8171 8587
8172 attname = xmlParseAttribute(ctxt, &attvalue); 8588 attname = xmlParseAttribute(ctxt, &attvalue);
8173 if ((attname != NULL) && (attvalue != NULL)) { 8589 if ((attname != NULL) && (attvalue != NULL)) {
8174 /* 8590 /*
8175 * [ WFC: Unique Att Spec ] 8591 * [ WFC: Unique Att Spec ]
8176 * No attribute name may appear more than once in the same 8592 * No attribute name may appear more than once in the same
8177 » * start-tag or empty-element tag. 8593 » * start-tag or empty-element tag.
8178 */ 8594 */
8179 for (i = 0; i < nbatts;i += 2) { 8595 for (i = 0; i < nbatts;i += 2) {
8180 if (xmlStrEqual(atts[i], attname)) { 8596 if (xmlStrEqual(atts[i], attname)) {
8181 xmlErrAttributeDup(ctxt, NULL, attname); 8597 xmlErrAttributeDup(ctxt, NULL, attname);
8182 xmlFree(attvalue); 8598 xmlFree(attvalue);
8183 goto failed; 8599 goto failed;
8184 } 8600 }
8185 } 8601 }
8186 /* 8602 /*
8187 * Add the pair to atts 8603 * Add the pair to atts
(...skipping 28 matching lines...) Expand all
8216 } 8632 }
8217 atts[nbatts++] = attname; 8633 atts[nbatts++] = attname;
8218 atts[nbatts++] = attvalue; 8634 atts[nbatts++] = attvalue;
8219 atts[nbatts] = NULL; 8635 atts[nbatts] = NULL;
8220 atts[nbatts + 1] = NULL; 8636 atts[nbatts + 1] = NULL;
8221 } else { 8637 } else {
8222 if (attvalue != NULL) 8638 if (attvalue != NULL)
8223 xmlFree(attvalue); 8639 xmlFree(attvalue);
8224 } 8640 }
8225 8641
8226 failed: 8642 failed:
8227 8643
8228 GROW 8644 GROW
8229 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>')))) 8645 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
8230 break; 8646 break;
8231 if (!IS_BLANK_CH(RAW)) { 8647 if (!IS_BLANK_CH(RAW)) {
8232 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, 8648 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
8233 "attributes construct error\n"); 8649 "attributes construct error\n");
8234 } 8650 }
8235 SKIP_BLANKS; 8651 SKIP_BLANKS;
8236 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && 8652 if ((cons == ctxt->input->consumed) && (q == CUR_PTR) &&
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
8298 GROW; 8714 GROW;
8299 SKIP_BLANKS; 8715 SKIP_BLANKS;
8300 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { 8716 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
8301 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 8717 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
8302 } else 8718 } else
8303 NEXT1; 8719 NEXT1;
8304 8720
8305 /* 8721 /*
8306 * [ WFC: Element Type Match ] 8722 * [ WFC: Element Type Match ]
8307 * The Name in an element's end-tag must match the element type in the 8723 * The Name in an element's end-tag must match the element type in the
8308 * start-tag. 8724 * start-tag.
8309 * 8725 *
8310 */ 8726 */
8311 if (name != (xmlChar*)1) { 8727 if (name != (xmlChar*)1) {
8312 if (name == NULL) name = BAD_CAST "unparseable"; 8728 if (name == NULL) name = BAD_CAST "unparseable";
8313 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, 8729 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH,
8314 "Opening and ending tag mismatch: %s line %d and %s\n", 8730 "Opening and ending tag mismatch: %s line %d and %s\n",
8315 ctxt->name, line, name); 8731 ctxt->name, line, name);
8316 } 8732 }
8317 8733
8318 /* 8734 /*
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
8394 xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) { 8810 xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix) {
8395 const xmlChar *l, *p; 8811 const xmlChar *l, *p;
8396 8812
8397 GROW; 8813 GROW;
8398 8814
8399 l = xmlParseNCName(ctxt); 8815 l = xmlParseNCName(ctxt);
8400 if (l == NULL) { 8816 if (l == NULL) {
8401 if (CUR == ':') { 8817 if (CUR == ':') {
8402 l = xmlParseName(ctxt); 8818 l = xmlParseName(ctxt);
8403 if (l != NULL) { 8819 if (l != NULL) {
8404 » xmlNsErr(ctxt, XML_NS_ERR_QNAME, 8820 » xmlNsErr(ctxt, XML_NS_ERR_QNAME,
8405 "Failed to parse QName '%s'\n", l, NULL, NULL); 8821 "Failed to parse QName '%s'\n", l, NULL, NULL);
8406 *prefix = NULL; 8822 *prefix = NULL;
8407 return(l); 8823 return(l);
8408 } 8824 }
8409 } 8825 }
8410 return(NULL); 8826 return(NULL);
8411 } 8827 }
8412 if (CUR == ':') { 8828 if (CUR == ':') {
8413 NEXT; 8829 NEXT;
8414 p = l; 8830 p = l;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
8477 const xmlChar *ret; 8893 const xmlChar *ret;
8478 const xmlChar *prefix2; 8894 const xmlChar *prefix2;
8479 8895
8480 if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name)); 8896 if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name));
8481 8897
8482 GROW; 8898 GROW;
8483 in = ctxt->input->cur; 8899 in = ctxt->input->cur;
8484 8900
8485 cmp = prefix; 8901 cmp = prefix;
8486 while (*in != 0 && *in == *cmp) { 8902 while (*in != 0 && *in == *cmp) {
8487 » ++in; 8903 » ++in;
8488 ++cmp; 8904 ++cmp;
8489 } 8905 }
8490 if ((*cmp == 0) && (*in == ':')) { 8906 if ((*cmp == 0) && (*in == ':')) {
8491 in++; 8907 in++;
8492 cmp = name; 8908 cmp = name;
8493 while (*in != 0 && *in == *cmp) { 8909 while (*in != 0 && *in == *cmp) {
8494 ++in; 8910 ++in;
8495 ++cmp; 8911 ++cmp;
8496 } 8912 }
8497 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { 8913 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
(...skipping 17 matching lines...) Expand all
8515 * @len: attribute len result 8931 * @len: attribute len result
8516 * @alloc: whether the attribute was reallocated as a new string 8932 * @alloc: whether the attribute was reallocated as a new string
8517 * @normalize: if 1 then further non-CDATA normalization must be done 8933 * @normalize: if 1 then further non-CDATA normalization must be done
8518 * 8934 *
8519 * parse a value for an attribute. 8935 * parse a value for an attribute.
8520 * NOTE: if no normalization is needed, the routine will return pointers 8936 * NOTE: if no normalization is needed, the routine will return pointers
8521 * directly from the data buffer. 8937 * directly from the data buffer.
8522 * 8938 *
8523 * 3.3.3 Attribute-Value Normalization: 8939 * 3.3.3 Attribute-Value Normalization:
8524 * Before the value of an attribute is passed to the application or 8940 * Before the value of an attribute is passed to the application or
8525 * checked for validity, the XML processor must normalize it as follows: 8941 * checked for validity, the XML processor must normalize it as follows:
8526 * - a character reference is processed by appending the referenced 8942 * - a character reference is processed by appending the referenced
8527 * character to the attribute value 8943 * character to the attribute value
8528 * - an entity reference is processed by recursively processing the 8944 * - an entity reference is processed by recursively processing the
8529 * replacement text of the entity 8945 * replacement text of the entity
8530 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by 8946 * - a whitespace character (#x20, #xD, #xA, #x9) is processed by
8531 * appending #x20 to the normalized value, except that only a single 8947 * 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 8948 * #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 8949 * parsed entity or the literal entity value of an internal parsed entity
8534 * - other characters are processed by appending them to the normalized value 8950 * - 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 8951 * If the declared value is not CDATA, then the XML processor must further
8536 * process the normalized attribute value by discarding any leading and 8952 * process the normalized attribute value by discarding any leading and
8537 * trailing space (#x20) characters, and by replacing sequences of space 8953 * trailing space (#x20) characters, and by replacing sequences of space
8538 * (#x20) characters by a single space (#x20) character. 8954 * (#x20) characters by a single space (#x20) character.
8539 * All attributes for which no declaration has been read should be treated 8955 * All attributes for which no declaration has been read should be treated
8540 * by a non-validating parser as if declared CDATA. 8956 * by a non-validating parser as if declared CDATA.
8541 * 8957 *
8542 * Returns the AttValue parsed or NULL. The value has to be freed by the 8958 * 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. 8959 * caller if it was copied, this can be detected by val[*len] == 0.
8544 */ 8960 */
8545 8961
8546 static xmlChar * 8962 static xmlChar *
8547 xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, 8963 xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
8548 int normalize) 8964 int normalize)
8549 { 8965 {
8550 xmlChar limit = 0; 8966 xmlChar limit = 0;
8551 const xmlChar *in = NULL, *start, *end, *last; 8967 const xmlChar *in = NULL, *start, *end, *last;
8552 xmlChar *ret = NULL; 8968 xmlChar *ret = NULL;
8969 int line, col;
8553 8970
8554 GROW; 8971 GROW;
8555 in = (xmlChar *) CUR_PTR; 8972 in = (xmlChar *) CUR_PTR;
8973 line = ctxt->input->line;
8974 col = ctxt->input->col;
8556 if (*in != '"' && *in != '\'') { 8975 if (*in != '"' && *in != '\'') {
8557 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL); 8976 xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL);
8558 return (NULL); 8977 return (NULL);
8559 } 8978 }
8560 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; 8979 ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE;
8561 8980
8562 /* 8981 /*
8563 * try to handle in this routine the most common case where no 8982 * try to handle in this routine the most common case where no
8564 * allocation of a new string is required and where content is 8983 * allocation of a new string is required and where content is
8565 * pure ASCII. 8984 * pure ASCII.
8566 */ 8985 */
8567 limit = *in++; 8986 limit = *in++;
8987 col++;
8568 end = ctxt->input->end; 8988 end = ctxt->input->end;
8569 start = in; 8989 start = in;
8570 if (in >= end) { 8990 if (in >= end) {
8571 const xmlChar *oldbase = ctxt->input->base; 8991 const xmlChar *oldbase = ctxt->input->base;
8572 GROW; 8992 GROW;
8573 if (oldbase != ctxt->input->base) { 8993 if (oldbase != ctxt->input->base) {
8574 long delta = ctxt->input->base - oldbase; 8994 long delta = ctxt->input->base - oldbase;
8575 start = start + delta; 8995 start = start + delta;
8576 in = in + delta; 8996 in = in + delta;
8577 } 8997 }
8578 end = ctxt->input->end; 8998 end = ctxt->input->end;
8579 } 8999 }
8580 if (normalize) { 9000 if (normalize) {
8581 /* 9001 /*
8582 * Skip any leading spaces 9002 * Skip any leading spaces
8583 */ 9003 */
8584 » while ((in < end) && (*in != limit) && 9004 » while ((in < end) && (*in != limit) &&
8585 ((*in == 0x20) || (*in == 0x9) || 9005 ((*in == 0x20) || (*in == 0x9) ||
8586 (*in == 0xA) || (*in == 0xD))) { 9006 (*in == 0xA) || (*in == 0xD))) {
9007 if (*in == 0xA) {
9008 line++; col = 1;
9009 } else {
9010 col++;
9011 }
8587 in++; 9012 in++;
8588 start = in; 9013 start = in;
8589 if (in >= end) { 9014 if (in >= end) {
8590 const xmlChar *oldbase = ctxt->input->base; 9015 const xmlChar *oldbase = ctxt->input->base;
8591 GROW; 9016 GROW;
8592 if (ctxt->instate == XML_PARSER_EOF) 9017 if (ctxt->instate == XML_PARSER_EOF)
8593 return(NULL); 9018 return(NULL);
8594 if (oldbase != ctxt->input->base) { 9019 if (oldbase != ctxt->input->base) {
8595 long delta = ctxt->input->base - oldbase; 9020 long delta = ctxt->input->base - oldbase;
8596 start = start + delta; 9021 start = start + delta;
8597 in = in + delta; 9022 in = in + delta;
8598 } 9023 }
8599 end = ctxt->input->end; 9024 end = ctxt->input->end;
9025 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9026 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9027 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9028 "AttValue length too long\n");
9029 return(NULL);
9030 }
8600 } 9031 }
8601 } 9032 }
8602 while ((in < end) && (*in != limit) && (*in >= 0x20) && 9033 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
8603 (*in <= 0x7f) && (*in != '&') && (*in != '<')) { 9034 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
9035 col++;
8604 if ((*in++ == 0x20) && (*in == 0x20)) break; 9036 if ((*in++ == 0x20) && (*in == 0x20)) break;
8605 if (in >= end) { 9037 if (in >= end) {
8606 const xmlChar *oldbase = ctxt->input->base; 9038 const xmlChar *oldbase = ctxt->input->base;
8607 GROW; 9039 GROW;
8608 if (ctxt->instate == XML_PARSER_EOF) 9040 if (ctxt->instate == XML_PARSER_EOF)
8609 return(NULL); 9041 return(NULL);
8610 if (oldbase != ctxt->input->base) { 9042 if (oldbase != ctxt->input->base) {
8611 long delta = ctxt->input->base - oldbase; 9043 long delta = ctxt->input->base - oldbase;
8612 start = start + delta; 9044 start = start + delta;
8613 in = in + delta; 9045 in = in + delta;
8614 } 9046 }
8615 end = ctxt->input->end; 9047 end = ctxt->input->end;
9048 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9049 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9050 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9051 "AttValue length too long\n");
9052 return(NULL);
9053 }
8616 } 9054 }
8617 } 9055 }
8618 last = in; 9056 last = in;
8619 /* 9057 /*
8620 * skip the trailing blanks 9058 * skip the trailing blanks
8621 */ 9059 */
8622 while ((last[-1] == 0x20) && (last > start)) last--; 9060 while ((last[-1] == 0x20) && (last > start)) last--;
8623 » while ((in < end) && (*in != limit) && 9061 » while ((in < end) && (*in != limit) &&
8624 ((*in == 0x20) || (*in == 0x9) || 9062 ((*in == 0x20) || (*in == 0x9) ||
8625 (*in == 0xA) || (*in == 0xD))) { 9063 (*in == 0xA) || (*in == 0xD))) {
9064 if (*in == 0xA) {
9065 line++, col = 1;
9066 } else {
9067 col++;
9068 }
8626 in++; 9069 in++;
8627 if (in >= end) { 9070 if (in >= end) {
8628 const xmlChar *oldbase = ctxt->input->base; 9071 const xmlChar *oldbase = ctxt->input->base;
8629 GROW; 9072 GROW;
8630 if (ctxt->instate == XML_PARSER_EOF) 9073 if (ctxt->instate == XML_PARSER_EOF)
8631 return(NULL); 9074 return(NULL);
8632 if (oldbase != ctxt->input->base) { 9075 if (oldbase != ctxt->input->base) {
8633 long delta = ctxt->input->base - oldbase; 9076 long delta = ctxt->input->base - oldbase;
8634 start = start + delta; 9077 start = start + delta;
8635 in = in + delta; 9078 in = in + delta;
8636 last = last + delta; 9079 last = last + delta;
8637 } 9080 }
8638 end = ctxt->input->end; 9081 end = ctxt->input->end;
9082 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9083 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9084 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9085 "AttValue length too long\n");
9086 return(NULL);
9087 }
8639 } 9088 }
8640 } 9089 }
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 }
8641 if (*in != limit) goto need_complex; 9096 if (*in != limit) goto need_complex;
8642 } else { 9097 } else {
8643 while ((in < end) && (*in != limit) && (*in >= 0x20) && 9098 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
8644 (*in <= 0x7f) && (*in != '&') && (*in != '<')) { 9099 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
8645 in++; 9100 in++;
9101 col++;
8646 if (in >= end) { 9102 if (in >= end) {
8647 const xmlChar *oldbase = ctxt->input->base; 9103 const xmlChar *oldbase = ctxt->input->base;
8648 GROW; 9104 GROW;
8649 if (ctxt->instate == XML_PARSER_EOF) 9105 if (ctxt->instate == XML_PARSER_EOF)
8650 return(NULL); 9106 return(NULL);
8651 if (oldbase != ctxt->input->base) { 9107 if (oldbase != ctxt->input->base) {
8652 long delta = ctxt->input->base - oldbase; 9108 long delta = ctxt->input->base - oldbase;
8653 start = start + delta; 9109 start = start + delta;
8654 in = in + delta; 9110 in = in + delta;
8655 } 9111 }
8656 end = ctxt->input->end; 9112 end = ctxt->input->end;
9113 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9114 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9115 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9116 "AttValue length too long\n");
9117 return(NULL);
9118 }
8657 } 9119 }
8658 } 9120 }
8659 last = in; 9121 last = in;
9122 if (((in - start) > XML_MAX_TEXT_LENGTH) &&
9123 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9124 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9125 "AttValue length too long\n");
9126 return(NULL);
9127 }
8660 if (*in != limit) goto need_complex; 9128 if (*in != limit) goto need_complex;
8661 } 9129 }
8662 in++; 9130 in++;
9131 col++;
8663 if (len != NULL) { 9132 if (len != NULL) {
8664 *len = last - start; 9133 *len = last - start;
8665 ret = (xmlChar *) start; 9134 ret = (xmlChar *) start;
8666 } else { 9135 } else {
8667 if (alloc) *alloc = 1; 9136 if (alloc) *alloc = 1;
8668 ret = xmlStrndup(start, last - start); 9137 ret = xmlStrndup(start, last - start);
8669 } 9138 }
8670 CUR_PTR = in; 9139 CUR_PTR = in;
9140 ctxt->input->line = line;
9141 ctxt->input->col = col;
8671 if (alloc) *alloc = 0; 9142 if (alloc) *alloc = 0;
8672 return ret; 9143 return ret;
8673 need_complex: 9144 need_complex:
8674 if (alloc) *alloc = 1; 9145 if (alloc) *alloc = 1;
8675 return xmlParseAttValueComplex(ctxt, len, normalize); 9146 return xmlParseAttValueComplex(ctxt, len, normalize);
8676 } 9147 }
8677 9148
8678 /** 9149 /**
8679 * xmlParseAttribute2: 9150 * xmlParseAttribute2:
8680 * @ctxt: an XML parser context 9151 * @ctxt: an XML parser context
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
8788 xmlFree(internal_val); 9259 xmlFree(internal_val);
8789 } 9260 }
8790 } 9261 }
8791 9262
8792 *value = val; 9263 *value = val;
8793 return (name); 9264 return (name);
8794 } 9265 }
8795 /** 9266 /**
8796 * xmlParseStartTag2: 9267 * xmlParseStartTag2:
8797 * @ctxt: an XML parser context 9268 * @ctxt: an XML parser context
8798 * 9269 *
8799 * parse a start of tag either for rule element or 9270 * parse a start of tag either for rule element or
8800 * EmptyElement. In both case we don't parse the tag closing chars. 9271 * EmptyElement. In both case we don't parse the tag closing chars.
8801 * This routine is called when running SAX2 parsing 9272 * This routine is called when running SAX2 parsing
8802 * 9273 *
8803 * [40] STag ::= '<' Name (S Attribute)* S? '>' 9274 * [40] STag ::= '<' Name (S Attribute)* S? '>'
8804 * 9275 *
8805 * [ WFC: Unique Att Spec ] 9276 * [ WFC: Unique Att Spec ]
8806 * No attribute name may appear more than once in the same start-tag or 9277 * No attribute name may appear more than once in the same start-tag or
8807 * empty-element tag. 9278 * empty-element tag.
8808 * 9279 *
8809 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' 9280 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
8810 * 9281 *
8811 * [ WFC: Unique Att Spec ] 9282 * [ WFC: Unique Att Spec ]
8812 * No attribute name may appear more than once in the same start-tag or 9283 * No attribute name may appear more than once in the same start-tag or
8813 * empty-element tag. 9284 * empty-element tag.
8814 * 9285 *
8815 * With namespace: 9286 * With namespace:
8816 * 9287 *
8817 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' 9288 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
8818 * 9289 *
8819 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' 9290 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
8820 * 9291 *
8821 * Returns the element name parsed 9292 * Returns the element name parsed
8822 */ 9293 */
8823 9294
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8872 9343
8873 /* 9344 /*
8874 * Now parse the attributes, it ends up with the ending 9345 * Now parse the attributes, it ends up with the ending
8875 * 9346 *
8876 * (S Attribute)* S? 9347 * (S Attribute)* S?
8877 */ 9348 */
8878 SKIP_BLANKS; 9349 SKIP_BLANKS;
8879 GROW; 9350 GROW;
8880 if (ctxt->input->base != base) goto base_changed; 9351 if (ctxt->input->base != base) goto base_changed;
8881 9352
8882 while (((RAW != '>') && 9353 while (((RAW != '>') &&
8883 ((RAW != '/') || (NXT(1) != '>')) && 9354 ((RAW != '/') || (NXT(1) != '>')) &&
8884 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { 9355 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
8885 const xmlChar *q = CUR_PTR; 9356 const xmlChar *q = CUR_PTR;
8886 unsigned int cons = ctxt->input->consumed; 9357 unsigned int cons = ctxt->input->consumed;
8887 int len = -1, alloc = 0; 9358 int len = -1, alloc = 0;
8888 9359
8889 attname = xmlParseAttribute2(ctxt, prefix, localname, 9360 attname = xmlParseAttribute2(ctxt, prefix, localname,
8890 &aprefix, &attvalue, &len, &alloc); 9361 &aprefix, &attvalue, &len, &alloc);
8891 if (ctxt->input->base != base) { 9362 if (ctxt->input->base != base) {
8892 if ((attvalue != NULL) && (alloc != 0)) 9363 if ((attvalue != NULL) && (alloc != 0))
8893 xmlFree(attvalue); 9364 xmlFree(attvalue);
8894 attvalue = NULL; 9365 attvalue = NULL;
8895 goto base_changed; 9366 goto base_changed;
8896 } 9367 }
8897 if ((attname != NULL) && (attvalue != NULL)) { 9368 if ((attname != NULL) && (attvalue != NULL)) {
8898 if (len < 0) len = xmlStrlen(attvalue); 9369 if (len < 0) len = xmlStrlen(attvalue);
8899 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { 9370 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
8900 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); 9371 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
8901 xmlURIPtr uri; 9372 xmlURIPtr uri;
8902 9373
9374 if (URL == NULL) {
9375 xmlErrMemory(ctxt, "dictionary allocation failure");
9376 if ((attvalue != NULL) && (alloc != 0))
9377 xmlFree(attvalue);
9378 return(NULL);
9379 }
8903 if (*URL != 0) { 9380 if (*URL != 0) {
8904 uri = xmlParseURI((const char *) URL); 9381 uri = xmlParseURI((const char *) URL);
8905 if (uri == NULL) { 9382 if (uri == NULL) {
8906 xmlNsErr(ctxt, XML_WAR_NS_URI, 9383 xmlNsErr(ctxt, XML_WAR_NS_URI,
8907 "xmlns: '%s' is not a valid URI\n", 9384 "xmlns: '%s' is not a valid URI\n",
8908 URL, NULL, NULL); 9385 URL, NULL, NULL);
8909 } else { 9386 } else {
8910 if (uri->scheme == NULL) { 9387 if (uri->scheme == NULL) {
8911 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE, 9388 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
8912 "xmlns: URI %s is not absolute\n", 9389 "xmlns: URI %s is not absolute\n",
(...skipping 23 matching lines...) Expand all
8936 */ 9413 */
8937 for (j = 1;j <= nbNs;j++) 9414 for (j = 1;j <= nbNs;j++)
8938 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL) 9415 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
8939 break; 9416 break;
8940 if (j <= nbNs) 9417 if (j <= nbNs)
8941 xmlErrAttributeDup(ctxt, NULL, attname); 9418 xmlErrAttributeDup(ctxt, NULL, attname);
8942 else 9419 else
8943 if (nsPush(ctxt, NULL, URL) > 0) nbNs++; 9420 if (nsPush(ctxt, NULL, URL) > 0) nbNs++;
8944 skip_default_ns: 9421 skip_default_ns:
8945 if (alloc != 0) xmlFree(attvalue); 9422 if (alloc != 0) xmlFree(attvalue);
9423 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9424 break;
9425 if (!IS_BLANK_CH(RAW)) {
9426 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9427 "attributes construct error\n");
9428 break;
9429 }
8946 SKIP_BLANKS; 9430 SKIP_BLANKS;
8947 continue; 9431 continue;
8948 } 9432 }
8949 if (aprefix == ctxt->str_xmlns) { 9433 if (aprefix == ctxt->str_xmlns) {
8950 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); 9434 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
8951 xmlURIPtr uri; 9435 xmlURIPtr uri;
8952 9436
8953 if (attname == ctxt->str_xml) { 9437 if (attname == ctxt->str_xml) {
8954 if (URL != ctxt->str_xml_ns) { 9438 if (URL != ctxt->str_xml_ns) {
8955 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE, 9439 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
9009 */ 9493 */
9010 for (j = 1;j <= nbNs;j++) 9494 for (j = 1;j <= nbNs;j++)
9011 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname) 9495 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
9012 break; 9496 break;
9013 if (j <= nbNs) 9497 if (j <= nbNs)
9014 xmlErrAttributeDup(ctxt, aprefix, attname); 9498 xmlErrAttributeDup(ctxt, aprefix, attname);
9015 else 9499 else
9016 if (nsPush(ctxt, attname, URL) > 0) nbNs++; 9500 if (nsPush(ctxt, attname, URL) > 0) nbNs++;
9017 skip_ns: 9501 skip_ns:
9018 if (alloc != 0) xmlFree(attvalue); 9502 if (alloc != 0) xmlFree(attvalue);
9503 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9504 break;
9505 if (!IS_BLANK_CH(RAW)) {
9506 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9507 "attributes construct error\n");
9508 break;
9509 }
9019 SKIP_BLANKS; 9510 SKIP_BLANKS;
9020 if (ctxt->input->base != base) goto base_changed; 9511 if (ctxt->input->base != base) goto base_changed;
9021 continue; 9512 continue;
9022 } 9513 }
9023 9514
9024 /* 9515 /*
9025 * Add the pair to atts 9516 * Add the pair to atts
9026 */ 9517 */
9027 if ((atts == NULL) || (nbatts + 5 > maxatts)) { 9518 if ((atts == NULL) || (nbatts + 5 > maxatts)) {
9028 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) { 9519 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
9138 atts[nbatts++] = attname; 9629 atts[nbatts++] = attname;
9139 atts[nbatts++] = aprefix; 9630 atts[nbatts++] = aprefix;
9140 if (aprefix == NULL) 9631 if (aprefix == NULL)
9141 atts[nbatts++] = NULL; 9632 atts[nbatts++] = NULL;
9142 else 9633 else
9143 atts[nbatts++] = xmlGetNamespace(ctxt, aprefix); 9634 atts[nbatts++] = xmlGetNamespace(ctxt, aprefix);
9144 atts[nbatts++] = defaults->values[5 * i + 2]; 9635 atts[nbatts++] = defaults->values[5 * i + 2];
9145 atts[nbatts++] = defaults->values[5 * i + 3]; 9636 atts[nbatts++] = defaults->values[5 * i + 3];
9146 if ((ctxt->standalone == 1) && 9637 if ((ctxt->standalone == 1) &&
9147 (defaults->values[5 * i + 4] != NULL)) { 9638 (defaults->values[5 * i + 4] != NULL)) {
9148 » » » xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED, 9639 » » » xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
9149 "standalone: attribute %s on %s defaulted from external subset\n", 9640 "standalone: attribute %s on %s defaulted from external subset\n",
9150 attname, localname); 9641 attname, localname);
9151 } 9642 }
9152 nbdef++; 9643 nbdef++;
9153 } 9644 }
9154 } 9645 }
9155 } 9646 }
9156 } 9647 }
9157 9648
9158 /* 9649 /*
9159 * The attributes checkings 9650 * The attributes checkings
9160 */ 9651 */
9161 for (i = 0; i < nbatts;i += 5) { 9652 for (i = 0; i < nbatts;i += 5) {
9162 /* 9653 /*
9163 * The default namespace does not apply to attribute names. 9654 * The default namespace does not apply to attribute names.
9164 */ 9655 */
9165 if (atts[i + 1] != NULL) { 9656 if (atts[i + 1] != NULL) {
9166 nsname = xmlGetNamespace(ctxt, atts[i + 1]); 9657 nsname = xmlGetNamespace(ctxt, atts[i + 1]);
9167 if (nsname == NULL) { 9658 if (nsname == NULL) {
9168 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, 9659 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
9169 "Namespace prefix %s for %s on %s is not defined\n", 9660 "Namespace prefix %s for %s on %s is not defined\n",
9170 atts[i + 1], atts[i], localname); 9661 atts[i + 1], atts[i], localname);
9171 } 9662 }
9172 atts[i + 2] = nsname; 9663 atts[i + 2] = nsname;
9173 } else 9664 } else
9174 nsname = NULL; 9665 nsname = NULL;
9175 /* 9666 /*
9176 * [ WFC: Unique Att Spec ] 9667 * [ WFC: Unique Att Spec ]
9177 * No attribute name may appear more than once in the same 9668 * No attribute name may appear more than once in the same
9178 » * start-tag or empty-element tag. 9669 » * start-tag or empty-element tag.
9179 * As extended by the Namespace in XML REC. 9670 * As extended by the Namespace in XML REC.
9180 */ 9671 */
9181 for (j = 0; j < i;j += 5) { 9672 for (j = 0; j < i;j += 5) {
9182 if (atts[i] == atts[j]) { 9673 if (atts[i] == atts[j]) {
9183 if (atts[i+1] == atts[j+1]) { 9674 if (atts[i+1] == atts[j+1]) {
9184 xmlErrAttributeDup(ctxt, atts[i+1], atts[i]); 9675 xmlErrAttributeDup(ctxt, atts[i+1], atts[i]);
9185 break; 9676 break;
9186 } 9677 }
9187 if ((nsname != NULL) && (atts[j + 2] == nsname)) { 9678 if ((nsname != NULL) && (atts[j + 2] == nsname)) {
9188 xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED, 9679 xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
9269 GROW; 9760 GROW;
9270 if ((RAW != '<') || (NXT(1) != '/')) { 9761 if ((RAW != '<') || (NXT(1) != '/')) {
9271 xmlFatalErr(ctxt, XML_ERR_LTSLASH_REQUIRED, NULL); 9762 xmlFatalErr(ctxt, XML_ERR_LTSLASH_REQUIRED, NULL);
9272 return; 9763 return;
9273 } 9764 }
9274 SKIP(2); 9765 SKIP(2);
9275 9766
9276 if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) { 9767 if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) {
9277 if (ctxt->input->cur[tlen] == '>') { 9768 if (ctxt->input->cur[tlen] == '>') {
9278 ctxt->input->cur += tlen + 1; 9769 ctxt->input->cur += tlen + 1;
9770 ctxt->input->col += tlen + 1;
9279 goto done; 9771 goto done;
9280 } 9772 }
9281 ctxt->input->cur += tlen; 9773 ctxt->input->cur += tlen;
9774 ctxt->input->col += tlen;
9282 name = (xmlChar*)1; 9775 name = (xmlChar*)1;
9283 } else { 9776 } else {
9284 if (prefix == NULL) 9777 if (prefix == NULL)
9285 name = xmlParseNameAndCompare(ctxt, ctxt->name); 9778 name = xmlParseNameAndCompare(ctxt, ctxt->name);
9286 else 9779 else
9287 name = xmlParseQNameAndCompare(ctxt, ctxt->name, prefix); 9780 name = xmlParseQNameAndCompare(ctxt, ctxt->name, prefix);
9288 } 9781 }
9289 9782
9290 /* 9783 /*
9291 * We should definitely be at the ending "S? '>'" part 9784 * We should definitely be at the ending "S? '>'" part
9292 */ 9785 */
9293 GROW; 9786 GROW;
9294 if (ctxt->instate == XML_PARSER_EOF) 9787 if (ctxt->instate == XML_PARSER_EOF)
9295 return; 9788 return;
9296 SKIP_BLANKS; 9789 SKIP_BLANKS;
9297 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) { 9790 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
9298 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL); 9791 xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
9299 } else 9792 } else
9300 NEXT1; 9793 NEXT1;
9301 9794
9302 /* 9795 /*
9303 * [ WFC: Element Type Match ] 9796 * [ WFC: Element Type Match ]
9304 * The Name in an element's end-tag must match the element type in the 9797 * The Name in an element's end-tag must match the element type in the
9305 * start-tag. 9798 * start-tag.
9306 * 9799 *
9307 */ 9800 */
9308 if (name != (xmlChar*)1) { 9801 if (name != (xmlChar*)1) {
9309 if (name == NULL) name = BAD_CAST "unparseable"; 9802 if (name == NULL) name = BAD_CAST "unparseable";
9310 if ((line == 0) && (ctxt->node != NULL)) 9803 if ((line == 0) && (ctxt->node != NULL))
9311 line = ctxt->node->line; 9804 line = ctxt->node->line;
9312 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH, 9805 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH,
9313 "Opening and ending tag mismatch: %s line %d and %s\n", 9806 "Opening and ending tag mismatch: %s line %d and %s\n",
9314 ctxt->name, line, name); 9807 ctxt->name, line, name);
9315 } 9808 }
9316 9809
9317 /* 9810 /*
9318 * SAX: End of Tag 9811 * SAX: End of Tag
9319 */ 9812 */
9320 done: 9813 done:
9321 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) && 9814 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) &&
9322 (!ctxt->disableSAX)) 9815 (!ctxt->disableSAX))
9323 ctxt->sax->endElementNs(ctxt->userData, ctxt->name, prefix, URI); 9816 ctxt->sax->endElementNs(ctxt->userData, ctxt->name, prefix, URI);
9324 9817
9325 spacePop(ctxt); 9818 spacePop(ctxt);
9326 if (nsNr != 0) 9819 if (nsNr != 0)
9327 nsPop(ctxt, nsNr); 9820 nsPop(ctxt, nsNr);
9328 return; 9821 return;
9329 } 9822 }
9330 9823
9331 /** 9824 /**
9332 * xmlParseCDSect: 9825 * xmlParseCDSect:
9333 * @ctxt: an XML parser context 9826 * @ctxt: an XML parser context
9334 * 9827 *
9335 * Parse escaped pure raw content. 9828 * Parse escaped pure raw content.
9336 * 9829 *
9337 * [18] CDSect ::= CDStart CData CDEnd 9830 * [18] CDSect ::= CDStart CData CDEnd
9338 * 9831 *
9339 * [19] CDStart ::= '<![CDATA[' 9832 * [19] CDStart ::= '<![CDATA['
9340 * 9833 *
9341 * [20] Data ::= (Char* - (Char* ']]>' Char*)) 9834 * [20] Data ::= (Char* - (Char* ']]>' Char*))
9342 * 9835 *
9343 * [21] CDEnd ::= ']]>' 9836 * [21] CDEnd ::= ']]>'
9344 */ 9837 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
9377 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); 9870 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
9378 if (buf == NULL) { 9871 if (buf == NULL) {
9379 xmlErrMemory(ctxt, NULL); 9872 xmlErrMemory(ctxt, NULL);
9380 return; 9873 return;
9381 } 9874 }
9382 while (IS_CHAR(cur) && 9875 while (IS_CHAR(cur) &&
9383 ((r != ']') || (s != ']') || (cur != '>'))) { 9876 ((r != ']') || (s != ']') || (cur != '>'))) {
9384 if (len + 5 >= size) { 9877 if (len + 5 >= size) {
9385 xmlChar *tmp; 9878 xmlChar *tmp;
9386 9879
9387 » size *= 2; 9880 if ((size > XML_MAX_TEXT_LENGTH) &&
9388 » tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 9881 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9882 xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED,
9883 "CData section too big found", NULL);
9884 xmlFree (buf);
9885 return;
9886 }
9887 » tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar));
9389 if (tmp == NULL) { 9888 if (tmp == NULL) {
9390 xmlFree(buf); 9889 xmlFree(buf);
9391 xmlErrMemory(ctxt, NULL); 9890 xmlErrMemory(ctxt, NULL);
9392 return; 9891 return;
9393 } 9892 }
9394 buf = tmp; 9893 buf = tmp;
9894 size *= 2;
9395 } 9895 }
9396 COPY_BUF(rl,buf,len,r); 9896 COPY_BUF(rl,buf,len,r);
9397 r = s; 9897 r = s;
9398 rl = sl; 9898 rl = sl;
9399 s = cur; 9899 s = cur;
9400 sl = l; 9900 sl = l;
9401 count++; 9901 count++;
9402 if (count > 50) { 9902 if (count > 50) {
9403 GROW; 9903 GROW;
9404 if (ctxt->instate == XML_PARSER_EOF) { 9904 if (ctxt->instate == XML_PARSER_EOF) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
9477 9977
9478 /* 9978 /*
9479 * Fourth case : a sub-element. 9979 * Fourth case : a sub-element.
9480 */ 9980 */
9481 else if (*cur == '<') { 9981 else if (*cur == '<') {
9482 xmlParseElement(ctxt); 9982 xmlParseElement(ctxt);
9483 } 9983 }
9484 9984
9485 /* 9985 /*
9486 * Fifth case : a reference. If if has not been resolved, 9986 * Fifth case : a reference. If if has not been resolved,
9487 » * parsing returns it's Name, create the node 9987 » * parsing returns it's Name, create the node
9488 */ 9988 */
9489 9989
9490 else if (*cur == '&') { 9990 else if (*cur == '&') {
9491 xmlParseReference(ctxt); 9991 xmlParseReference(ctxt);
9492 } 9992 }
9493 9993
9494 /* 9994 /*
9495 * Last case, text. Note that References are handled directly. 9995 * Last case, text. Note that References are handled directly.
9496 */ 9996 */
9497 else { 9997 else {
(...skipping 20 matching lines...) Expand all
9518 /** 10018 /**
9519 * xmlParseElement: 10019 * xmlParseElement:
9520 * @ctxt: an XML parser context 10020 * @ctxt: an XML parser context
9521 * 10021 *
9522 * parse an XML element, this is highly recursive 10022 * parse an XML element, this is highly recursive
9523 * 10023 *
9524 * [39] element ::= EmptyElemTag | STag content ETag 10024 * [39] element ::= EmptyElemTag | STag content ETag
9525 * 10025 *
9526 * [ WFC: Element Type Match ] 10026 * [ WFC: Element Type Match ]
9527 * The Name in an element's end-tag must match the element type in the 10027 * The Name in an element's end-tag must match the element type in the
9528 * start-tag. 10028 * start-tag.
9529 * 10029 *
9530 */ 10030 */
9531 10031
9532 void 10032 void
9533 xmlParseElement(xmlParserCtxtPtr ctxt) { 10033 xmlParseElement(xmlParserCtxtPtr ctxt) {
9534 const xmlChar *name; 10034 const xmlChar *name;
9535 const xmlChar *prefix = NULL; 10035 const xmlChar *prefix = NULL;
9536 const xmlChar *URI = NULL; 10036 const xmlChar *URI = NULL;
9537 xmlParserNodeInfo node_info; 10037 xmlParserNodeInfo node_info;
9538 int line, tlen; 10038 int line, tlen = 0;
9539 xmlNodePtr ret; 10039 xmlNodePtr ret;
9540 int nsNr = ctxt->nsNr; 10040 int nsNr = ctxt->nsNr;
9541 10041
9542 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) && 10042 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) &&
9543 ((ctxt->options & XML_PARSE_HUGE) == 0)) { 10043 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
9544 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR, 10044 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
9545 "Excessive depth in document: %d use XML_PARSE_HUGE option\n", 10045 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
9546 xmlParserMaxDepth); 10046 xmlParserMaxDepth);
9547 ctxt->instate = XML_PARSER_EOF; 10047 ctxt->instate = XML_PARSER_EOF;
9548 return; 10048 return;
(...skipping 28 matching lines...) Expand all
9577 spacePop(ctxt); 10077 spacePop(ctxt);
9578 return; 10078 return;
9579 } 10079 }
9580 namePush(ctxt, name); 10080 namePush(ctxt, name);
9581 ret = ctxt->node; 10081 ret = ctxt->node;
9582 10082
9583 #ifdef LIBXML_VALID_ENABLED 10083 #ifdef LIBXML_VALID_ENABLED
9584 /* 10084 /*
9585 * [ VC: Root Element Type ] 10085 * [ VC: Root Element Type ]
9586 * The Name in the document type declaration must match the element 10086 * The Name in the document type declaration must match the element
9587 * type of the root element. 10087 * type of the root element.
9588 */ 10088 */
9589 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && 10089 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
9590 ctxt->node && (ctxt->node == ctxt->myDoc->children)) 10090 ctxt->node && (ctxt->node == ctxt->myDoc->children))
9591 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); 10091 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
9592 #endif /* LIBXML_VALID_ENABLED */ 10092 #endif /* LIBXML_VALID_ENABLED */
9593 10093
9594 /* 10094 /*
9595 * Check for an Empty Element. 10095 * Check for an Empty Element.
9596 */ 10096 */
9597 if ((RAW == '/') && (NXT(1) == '>')) { 10097 if ((RAW == '/') && (NXT(1) == '>')) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
9860 buf[len] = 0; 10360 buf[len] = 0;
9861 } else { 10361 } else {
9862 xmlFatalErr(ctxt, XML_ERR_ENCODING_NAME, NULL); 10362 xmlFatalErr(ctxt, XML_ERR_ENCODING_NAME, NULL);
9863 } 10363 }
9864 return(buf); 10364 return(buf);
9865 } 10365 }
9866 10366
9867 /** 10367 /**
9868 * xmlParseEncodingDecl: 10368 * xmlParseEncodingDecl:
9869 * @ctxt: an XML parser context 10369 * @ctxt: an XML parser context
9870 * 10370 *
9871 * parse the XML encoding declaration 10371 * parse the XML encoding declaration
9872 * 10372 *
9873 * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'") 10373 * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'")
9874 * 10374 *
9875 * this setups the conversion filters. 10375 * this setups the conversion filters.
9876 * 10376 *
9877 * Returns the encoding value or NULL 10377 * Returns the encoding value or NULL
9878 */ 10378 */
9879 10379
9880 const xmlChar * 10380 const xmlChar *
(...skipping 20 matching lines...) Expand all
9901 } else if (RAW == '\''){ 10401 } else if (RAW == '\''){
9902 NEXT; 10402 NEXT;
9903 encoding = xmlParseEncName(ctxt); 10403 encoding = xmlParseEncName(ctxt);
9904 if (RAW != '\'') { 10404 if (RAW != '\'') {
9905 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL); 10405 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
9906 } else 10406 } else
9907 NEXT; 10407 NEXT;
9908 } else { 10408 } else {
9909 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); 10409 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL);
9910 } 10410 }
10411
10412 /*
10413 * Non standard parsing, allowing the user to ignore encoding
10414 */
10415 if (ctxt->options & XML_PARSE_IGNORE_ENC) {
10416 xmlFree((xmlChar *) encoding);
10417 return(NULL);
10418 }
10419
9911 /* 10420 /*
9912 * UTF-16 encoding stwich has already taken place at this stage, 10421 * UTF-16 encoding stwich has already taken place at this stage,
9913 * more over the little-endian/big-endian selection is already done 10422 * more over the little-endian/big-endian selection is already done
9914 */ 10423 */
9915 if ((encoding != NULL) && 10424 if ((encoding != NULL) &&
9916 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) || 10425 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) ||
9917 (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) { 10426 (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) {
9918 /* 10427 /*
9919 * If no encoding was passed to the parser, that we are 10428 * If no encoding was passed to the parser, that we are
9920 » * using UTF-16 and no decoder is present i.e. the 10429 » * using UTF-16 and no decoder is present i.e. the
9921 * document is apparently UTF-8 compatible, then raise an 10430 * document is apparently UTF-8 compatible, then raise an
9922 * encoding mismatch fatal error 10431 * encoding mismatch fatal error
9923 */ 10432 */
9924 if ((ctxt->encoding == NULL) && 10433 if ((ctxt->encoding == NULL) &&
9925 (ctxt->input->buf != NULL) && 10434 (ctxt->input->buf != NULL) &&
9926 (ctxt->input->buf->encoder == NULL)) { 10435 (ctxt->input->buf->encoder == NULL)) {
9927 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_ENCODING, 10436 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_ENCODING,
9928 "Document labelled UTF-16 but has UTF-8 content\n"); 10437 "Document labelled UTF-16 but has UTF-8 content\n");
9929 } 10438 }
9930 if (ctxt->encoding != NULL) 10439 if (ctxt->encoding != NULL)
(...skipping 30 matching lines...) Expand all
9961 return(encoding); 10470 return(encoding);
9962 } 10471 }
9963 10472
9964 /** 10473 /**
9965 * xmlParseSDDecl: 10474 * xmlParseSDDecl:
9966 * @ctxt: an XML parser context 10475 * @ctxt: an XML parser context
9967 * 10476 *
9968 * parse the XML standalone declaration 10477 * parse the XML standalone declaration
9969 * 10478 *
9970 * [32] SDDecl ::= S 'standalone' Eq 10479 * [32] SDDecl ::= S 'standalone' Eq
9971 * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) 10480 * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))
9972 * 10481 *
9973 * [ VC: Standalone Document Declaration ] 10482 * [ VC: Standalone Document Declaration ]
9974 * TODO The standalone document declaration must have the value "no" 10483 * TODO The standalone document declaration must have the value "no"
9975 * if any external markup declarations contain declarations of: 10484 * if any external markup declarations contain declarations of:
9976 * - attributes with default values, if elements to which these 10485 * - attributes with default values, if elements to which these
9977 * attributes apply appear in the document without specifications 10486 * attributes apply appear in the document without specifications
9978 * of values for these attributes, or 10487 * of values for these attributes, or
9979 * - entities (other than amp, lt, gt, apos, quot), if references 10488 * - entities (other than amp, lt, gt, apos, quot), if references
9980 * to those entities appear in the document, or 10489 * to those entities appear in the document, or
9981 * - attributes with values subject to normalization, where the 10490 * - attributes with values subject to normalization, where the
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
10041 } else { 10550 } else {
10042 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL); 10551 xmlFatalErr(ctxt, XML_ERR_STRING_NOT_STARTED, NULL);
10043 } 10552 }
10044 } 10553 }
10045 return(standalone); 10554 return(standalone);
10046 } 10555 }
10047 10556
10048 /** 10557 /**
10049 * xmlParseXMLDecl: 10558 * xmlParseXMLDecl:
10050 * @ctxt: an XML parser context 10559 * @ctxt: an XML parser context
10051 * 10560 *
10052 * parse an XML declaration header 10561 * parse an XML declaration header
10053 * 10562 *
10054 * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' 10563 * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
10055 */ 10564 */
10056 10565
10057 void 10566 void
10058 xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { 10567 xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
10059 xmlChar *version; 10568 xmlChar *version;
10060 10569
10061 /* 10570 /*
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
10155 } else { 10664 } else {
10156 xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); 10665 xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL);
10157 MOVETO_ENDTAG(CUR_PTR); 10666 MOVETO_ENDTAG(CUR_PTR);
10158 NEXT; 10667 NEXT;
10159 } 10668 }
10160 } 10669 }
10161 10670
10162 /** 10671 /**
10163 * xmlParseMisc: 10672 * xmlParseMisc:
10164 * @ctxt: an XML parser context 10673 * @ctxt: an XML parser context
10165 * 10674 *
10166 * parse an XML Misc* optional field. 10675 * parse an XML Misc* optional field.
10167 * 10676 *
10168 * [27] Misc ::= Comment | PI | S 10677 * [27] Misc ::= Comment | PI | S
10169 */ 10678 */
10170 10679
10171 void 10680 void
10172 xmlParseMisc(xmlParserCtxtPtr ctxt) { 10681 xmlParseMisc(xmlParserCtxtPtr ctxt) {
10173 while ((ctxt->instate != XML_PARSER_EOF) && 10682 while ((ctxt->instate != XML_PARSER_EOF) &&
10174 (((RAW == '<') && (NXT(1) == '?')) || 10683 (((RAW == '<') && (NXT(1) == '?')) ||
10175 (CMP4(CUR_PTR, '<', '!', '-', '-')) || 10684 (CMP4(CUR_PTR, '<', '!', '-', '-')) ||
10176 IS_BLANK_CH(CUR))) { 10685 IS_BLANK_CH(CUR))) {
10177 if ((RAW == '<') && (NXT(1) == '?')) { 10686 if ((RAW == '<') && (NXT(1) == '?')) {
10178 xmlParsePI(ctxt); 10687 xmlParsePI(ctxt);
10179 } else if (IS_BLANK_CH(CUR)) { 10688 } else if (IS_BLANK_CH(CUR)) {
10180 NEXT; 10689 NEXT;
10181 } else 10690 } else
10182 xmlParseComment(ctxt); 10691 xmlParseComment(ctxt);
10183 } 10692 }
10184 } 10693 }
10185 10694
10186 /** 10695 /**
10187 * xmlParseDocument: 10696 * xmlParseDocument:
10188 * @ctxt: an XML parser context 10697 * @ctxt: an XML parser context
10189 * 10698 *
10190 * parse an XML document (and build a tree if using the standard SAX 10699 * parse an XML document (and build a tree if using the standard SAX
10191 * interface). 10700 * interface).
10192 * 10701 *
10193 * [1] document ::= prolog element Misc* 10702 * [1] document ::= prolog element Misc*
10194 * 10703 *
10195 * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? 10704 * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
10196 * 10705 *
10197 * Returns 0, -1 in case of error. the parser context is augmented 10706 * Returns 0, -1 in case of error. the parser context is augmented
10198 * as a result of the parsing. 10707 * as a result of the parsing.
10199 */ 10708 */
(...skipping 16 matching lines...) Expand all
10216 xmlDetectSAX2(ctxt); 10725 xmlDetectSAX2(ctxt);
10217 10726
10218 /* 10727 /*
10219 * SAX: beginning of the document processing. 10728 * SAX: beginning of the document processing.
10220 */ 10729 */
10221 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) 10730 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10222 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); 10731 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10223 if (ctxt->instate == XML_PARSER_EOF) 10732 if (ctxt->instate == XML_PARSER_EOF)
10224 return(-1); 10733 return(-1);
10225 10734
10226 if ((ctxt->encoding == (const xmlChar *)XML_CHAR_ENCODING_NONE) && 10735 if ((ctxt->encoding == NULL) &&
10227 ((ctxt->input->end - ctxt->input->cur) >= 4)) { 10736 ((ctxt->input->end - ctxt->input->cur) >= 4)) {
10228 » /* 10737 » /*
10229 * Get the 4 first bytes and decode the charset 10738 * Get the 4 first bytes and decode the charset
10230 * if enc != XML_CHAR_ENCODING_NONE 10739 * if enc != XML_CHAR_ENCODING_NONE
10231 * plug some encoding conversion routines. 10740 * plug some encoding conversion routines.
10232 */ 10741 */
10233 start[0] = RAW; 10742 start[0] = RAW;
10234 start[1] = NXT(1); 10743 start[1] = NXT(1);
10235 start[2] = NXT(2); 10744 start[2] = NXT(2);
10236 start[3] = NXT(3); 10745 start[3] = NXT(3);
10237 enc = xmlDetectCharEncoding(&start[0], 4); 10746 enc = xmlDetectCharEncoding(&start[0], 4);
10238 if (enc != XML_CHAR_ENCODING_NONE) { 10747 if (enc != XML_CHAR_ENCODING_NONE) {
(...skipping 29 matching lines...) Expand all
10268 } 10777 }
10269 ctxt->standalone = ctxt->input->standalone; 10778 ctxt->standalone = ctxt->input->standalone;
10270 SKIP_BLANKS; 10779 SKIP_BLANKS;
10271 } else { 10780 } else {
10272 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION); 10781 ctxt->version = xmlCharStrdup(XML_DEFAULT_VERSION);
10273 } 10782 }
10274 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) 10783 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
10275 ctxt->sax->startDocument(ctxt->userData); 10784 ctxt->sax->startDocument(ctxt->userData);
10276 if (ctxt->instate == XML_PARSER_EOF) 10785 if (ctxt->instate == XML_PARSER_EOF)
10277 return(-1); 10786 return(-1);
10787 if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
10788 (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
10789 ctxt->myDoc->compression = ctxt->input->buf->compressed;
10790 }
10278 10791
10279 /* 10792 /*
10280 * The Misc part of the Prolog 10793 * The Misc part of the Prolog
10281 */ 10794 */
10282 GROW; 10795 GROW;
10283 xmlParseMisc(ctxt); 10796 xmlParseMisc(ctxt);
10284 10797
10285 /* 10798 /*
10286 * Then possibly doc type declaration(s) and more Misc 10799 * Then possibly doc type declaration(s) and more Misc
10287 * (doctypedecl Misc*)? 10800 * (doctypedecl Misc*)?
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
10367 if (! ctxt->wellFormed) { 10880 if (! ctxt->wellFormed) {
10368 ctxt->valid = 0; 10881 ctxt->valid = 0;
10369 return(-1); 10882 return(-1);
10370 } 10883 }
10371 return(0); 10884 return(0);
10372 } 10885 }
10373 10886
10374 /** 10887 /**
10375 * xmlParseExtParsedEnt: 10888 * xmlParseExtParsedEnt:
10376 * @ctxt: an XML parser context 10889 * @ctxt: an XML parser context
10377 * 10890 *
10378 * parse a general parsed entity 10891 * parse a general parsed entity
10379 * An external general parsed entity is well-formed if it matches the 10892 * An external general parsed entity is well-formed if it matches the
10380 * production labeled extParsedEnt. 10893 * production labeled extParsedEnt.
10381 * 10894 *
10382 * [78] extParsedEnt ::= TextDecl? content 10895 * [78] extParsedEnt ::= TextDecl? content
10383 * 10896 *
10384 * Returns 0, -1 in case of error. the parser context is augmented 10897 * Returns 0, -1 in case of error. the parser context is augmented
10385 * as a result of the parsing. 10898 * as a result of the parsing.
10386 */ 10899 */
10387 10900
(...skipping 10 matching lines...) Expand all
10398 xmlDetectSAX2(ctxt); 10911 xmlDetectSAX2(ctxt);
10399 10912
10400 GROW; 10913 GROW;
10401 10914
10402 /* 10915 /*
10403 * SAX: beginning of the document processing. 10916 * SAX: beginning of the document processing.
10404 */ 10917 */
10405 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) 10918 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10406 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator); 10919 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10407 10920
10408 /* 10921 /*
10409 * Get the 4 first bytes and decode the charset 10922 * Get the 4 first bytes and decode the charset
10410 * if enc != XML_CHAR_ENCODING_NONE 10923 * if enc != XML_CHAR_ENCODING_NONE
10411 * plug some encoding conversion routines. 10924 * plug some encoding conversion routines.
10412 */ 10925 */
10413 if ((ctxt->input->end - ctxt->input->cur) >= 4) { 10926 if ((ctxt->input->end - ctxt->input->cur) >= 4) {
10414 start[0] = RAW; 10927 start[0] = RAW;
10415 start[1] = NXT(1); 10928 start[1] = NXT(1);
10416 start[2] = NXT(2); 10929 start[2] = NXT(2);
10417 start[3] = NXT(3); 10930 start[3] = NXT(3);
10418 enc = xmlDetectCharEncoding(start, 4); 10931 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 10968 * Doing validity checking on chunk doesn't make sense
10456 */ 10969 */
10457 ctxt->instate = XML_PARSER_CONTENT; 10970 ctxt->instate = XML_PARSER_CONTENT;
10458 ctxt->validate = 0; 10971 ctxt->validate = 0;
10459 ctxt->loadsubset = 0; 10972 ctxt->loadsubset = 0;
10460 ctxt->depth = 0; 10973 ctxt->depth = 0;
10461 10974
10462 xmlParseContent(ctxt); 10975 xmlParseContent(ctxt);
10463 if (ctxt->instate == XML_PARSER_EOF) 10976 if (ctxt->instate == XML_PARSER_EOF)
10464 return(-1); 10977 return(-1);
10465 10978
10466 if ((RAW == '<') && (NXT(1) == '/')) { 10979 if ((RAW == '<') && (NXT(1) == '/')) {
10467 xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); 10980 xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL);
10468 } else if (RAW != 0) { 10981 } else if (RAW != 0) {
10469 xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL); 10982 xmlFatalErr(ctxt, XML_ERR_EXTRA_CONTENT, NULL);
10470 } 10983 }
10471 10984
10472 /* 10985 /*
10473 * SAX: end of the document processing. 10986 * SAX: end of the document processing.
10474 */ 10987 */
10475 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 10988 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10476 ctxt->sax->endDocument(ctxt->userData); 10989 ctxt->sax->endDocument(ctxt->userData);
10477 10990
10478 if (! ctxt->wellFormed) return(-1); 10991 if (! ctxt->wellFormed) return(-1);
10479 return(0); 10992 return(0);
10480 } 10993 }
10481 10994
10482 #ifdef LIBXML_PUSH_ENABLED 10995 #ifdef LIBXML_PUSH_ENABLED
10483 /************************************************************************ 10996 /************************************************************************
10484 * * 10997 * *
10485 * » » Progressive parsing interfaces» » » » * 10998 *» » Progressive parsing interfaces» » » » *
10486 * * 10999 * *
10487 ************************************************************************/ 11000 ************************************************************************/
10488 11001
10489 /** 11002 /**
10490 * xmlParseLookupSequence: 11003 * xmlParseLookupSequence:
10491 * @ctxt: an XML parser context 11004 * @ctxt: an XML parser context
10492 * @first: the first char to lookup 11005 * @first: the first char to lookup
10493 * @next: the next char to lookup or zero 11006 * @next: the next char to lookup or zero
10494 * @third: the next char to lookup or zero 11007 * @third: the next char to lookup or zero
10495 * 11008 *
(...skipping 16 matching lines...) Expand all
10512 in = ctxt->input; 11025 in = ctxt->input;
10513 if (in == NULL) return(-1); 11026 if (in == NULL) return(-1);
10514 base = in->cur - in->base; 11027 base = in->cur - in->base;
10515 if (base < 0) return(-1); 11028 if (base < 0) return(-1);
10516 if (ctxt->checkIndex > base) 11029 if (ctxt->checkIndex > base)
10517 base = ctxt->checkIndex; 11030 base = ctxt->checkIndex;
10518 if (in->buf == NULL) { 11031 if (in->buf == NULL) {
10519 buf = in->base; 11032 buf = in->base;
10520 len = in->length; 11033 len = in->length;
10521 } else { 11034 } else {
10522 » buf = in->buf->buffer->content; 11035 » buf = xmlBufContent(in->buf->buffer);
10523 » len = in->buf->buffer->use; 11036 » len = xmlBufUse(in->buf->buffer);
10524 } 11037 }
10525 /* take into account the sequence length */ 11038 /* take into account the sequence length */
10526 if (third) len -= 2; 11039 if (third) len -= 2;
10527 else if (next) len --; 11040 else if (next) len --;
10528 for (;base < len;base++) { 11041 for (;base < len;base++) {
10529 if (buf[base] == first) { 11042 if (buf[base] == first) {
10530 if (third != 0) { 11043 if (third != 0) {
10531 if ((buf[base + 1] != next) || 11044 if ((buf[base + 1] != next) ||
10532 (buf[base + 2] != third)) continue; 11045 (buf[base + 2] != third)) continue;
10533 } else if (next != 0) { 11046 } else if (next != 0) {
10534 if (buf[base + 1] != next) continue; 11047 if (buf[base + 1] != next) continue;
10535 } 11048 }
10536 ctxt->checkIndex = 0; 11049 ctxt->checkIndex = 0;
10537 #ifdef DEBUG_PUSH 11050 #ifdef DEBUG_PUSH
10538 if (next == 0) 11051 if (next == 0)
10539 xmlGenericError(xmlGenericErrorContext, 11052 xmlGenericError(xmlGenericErrorContext,
10540 "PP: lookup '%c' found at %d\n", 11053 "PP: lookup '%c' found at %d\n",
10541 first, base); 11054 first, base);
10542 else if (third == 0) 11055 else if (third == 0)
10543 xmlGenericError(xmlGenericErrorContext, 11056 xmlGenericError(xmlGenericErrorContext,
10544 "PP: lookup '%c%c' found at %d\n", 11057 "PP: lookup '%c%c' found at %d\n",
10545 first, next, base); 11058 first, next, base);
10546 » else 11059 » else
10547 xmlGenericError(xmlGenericErrorContext, 11060 xmlGenericError(xmlGenericErrorContext,
10548 "PP: lookup '%c%c%c' found at %d\n", 11061 "PP: lookup '%c%c%c' found at %d\n",
10549 first, next, third, base); 11062 first, next, third, base);
10550 #endif 11063 #endif
10551 return(base - (in->cur - in->base)); 11064 return(base - (in->cur - in->base));
10552 } 11065 }
10553 } 11066 }
10554 ctxt->checkIndex = base; 11067 ctxt->checkIndex = base;
10555 #ifdef DEBUG_PUSH 11068 #ifdef DEBUG_PUSH
10556 if (next == 0) 11069 if (next == 0)
10557 xmlGenericError(xmlGenericErrorContext, 11070 xmlGenericError(xmlGenericErrorContext,
10558 "PP: lookup '%c' failed\n", first); 11071 "PP: lookup '%c' failed\n", first);
10559 else if (third == 0) 11072 else if (third == 0)
10560 xmlGenericError(xmlGenericErrorContext, 11073 xmlGenericError(xmlGenericErrorContext,
10561 "PP: lookup '%c%c' failed\n", first, next); 11074 "PP: lookup '%c%c' failed\n", first, next);
10562 else» 11075 else
10563 xmlGenericError(xmlGenericErrorContext, 11076 xmlGenericError(xmlGenericErrorContext,
10564 "PP: lookup '%c%c%c' failed\n", first, next, third); 11077 "PP: lookup '%c%c%c' failed\n", first, next, third);
10565 #endif 11078 #endif
10566 return(-1); 11079 return(-1);
10567 } 11080 }
10568 11081
10569 /** 11082 /**
10570 * xmlParseGetLasts: 11083 * xmlParseGetLasts:
10571 * @ctxt: an XML parser context 11084 * @ctxt: an XML parser context
10572 * @lastlt: pointer to store the last '<' from the input 11085 * @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 11147 * UTF-8 error occured otherwise
10635 */ 11148 */
10636 static int 11149 static int
10637 xmlCheckCdataPush(const xmlChar *utf, int len) { 11150 xmlCheckCdataPush(const xmlChar *utf, int len) {
10638 int ix; 11151 int ix;
10639 unsigned char c; 11152 unsigned char c;
10640 int codepoint; 11153 int codepoint;
10641 11154
10642 if ((utf == NULL) || (len <= 0)) 11155 if ((utf == NULL) || (len <= 0))
10643 return(0); 11156 return(0);
10644 11157
10645 for (ix = 0; ix < len;) { /* string is 0-terminated */ 11158 for (ix = 0; ix < len;) { /* string is 0-terminated */
10646 c = utf[ix]; 11159 c = utf[ix];
10647 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */ 11160 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */
10648 if (c >= 0x20) 11161 if (c >= 0x20)
10649 ix++; 11162 ix++;
10650 else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) 11163 else if ((c == 0xA) || (c == 0xD) || (c == 0x9))
10651 ix++; 11164 ix++;
10652 else 11165 else
10653 return(-ix); 11166 return(-ix);
10654 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ 11167 } 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)) { 11279 (ctxt->input->cur - ctxt->input->base > 4096)) {
10767 xmlSHRINK(ctxt); 11280 xmlSHRINK(ctxt);
10768 ctxt->checkIndex = 0; 11281 ctxt->checkIndex = 0;
10769 } 11282 }
10770 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11283 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
10771 11284
10772 while (ctxt->instate != XML_PARSER_EOF) { 11285 while (ctxt->instate != XML_PARSER_EOF) {
10773 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 11286 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
10774 return(0); 11287 return(0);
10775 11288
10776 11289
10777 /* 11290 /*
10778 * Pop-up of finished entities. 11291 * Pop-up of finished entities.
10779 */ 11292 */
10780 while ((RAW == 0) && (ctxt->inputNr > 1)) 11293 while ((RAW == 0) && (ctxt->inputNr > 1))
10781 xmlPopInput(ctxt); 11294 xmlPopInput(ctxt);
10782 11295
10783 if (ctxt->input == NULL) break; 11296 if (ctxt->input == NULL) break;
10784 if (ctxt->input->buf == NULL) 11297 if (ctxt->input->buf == NULL)
10785 avail = ctxt->input->length - 11298 avail = ctxt->input->length -
10786 (ctxt->input->cur - ctxt->input->base); 11299 (ctxt->input->cur - ctxt->input->base);
10787 else { 11300 else {
10788 /* 11301 /*
10789 * If we are operating on converted input, try to flush 11302 * If we are operating on converted input, try to flush
10790 * remainng chars to avoid them stalling in the non-converted 11303 * remainng chars to avoid them stalling in the non-converted
10791 » * buffer. 11304 » * buffer. But do not do this in document start where
11305 » * encoding="..." may not have been read and we work on a
11306 » * guessed encoding.
10792 */ 11307 */
10793 » if ((ctxt->input->buf->raw != NULL) && 11308 » if ((ctxt->instate != XML_PARSER_START) &&
10794 » » (ctxt->input->buf->raw->use > 0)) { 11309 » (ctxt->input->buf->raw != NULL) &&
10795 » » int base = ctxt->input->base - 11310 » » (xmlBufIsEmpty(ctxt->input->buf->raw) == 0)) {
10796 » » ctxt->input->buf->buffer->content; 11311 size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
10797 » » int current = ctxt->input->cur - ctxt->input->base; 11312 ctxt->input);
11313 » » size_t current = ctxt->input->cur - ctxt->input->base;
10798 11314
10799 xmlParserInputBufferPush(ctxt->input->buf, 0, ""); 11315 xmlParserInputBufferPush(ctxt->input->buf, 0, "");
10800 » » ctxt->input->base = ctxt->input->buf->buffer->content + base; 11316 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
10801 » » ctxt->input->cur = ctxt->input->base + current; 11317 base, current);
10802 » » ctxt->input->end =
10803 » » &ctxt->input->buf->buffer->content[
10804 » » ctxt->input->buf->buffer->use];
10805 } 11318 }
10806 » avail = ctxt->input->buf->buffer->use - 11319 » avail = xmlBufUse(ctxt->input->buf->buffer) -
10807 (ctxt->input->cur - ctxt->input->base); 11320 (ctxt->input->cur - ctxt->input->base);
10808 } 11321 }
10809 if (avail < 1) 11322 if (avail < 1)
10810 goto done; 11323 goto done;
10811 switch (ctxt->instate) { 11324 switch (ctxt->instate) {
10812 case XML_PARSER_EOF: 11325 case XML_PARSER_EOF:
10813 /* 11326 /*
10814 * Document parsing is done ! 11327 * Document parsing is done !
10815 */ 11328 */
10816 goto done; 11329 goto done;
10817 case XML_PARSER_START: 11330 case XML_PARSER_START:
10818 if (ctxt->charset == XML_CHAR_ENCODING_NONE) { 11331 if (ctxt->charset == XML_CHAR_ENCODING_NONE) {
10819 xmlChar start[4]; 11332 xmlChar start[4];
10820 xmlCharEncoding enc; 11333 xmlCharEncoding enc;
10821 11334
10822 /* 11335 /*
10823 * Very first chars read from the document flow. 11336 * Very first chars read from the document flow.
10824 */ 11337 */
10825 if (avail < 4) 11338 if (avail < 4)
10826 goto done; 11339 goto done;
10827 11340
10828 » » /* 11341 » » /*
10829 * Get the 4 first bytes and decode the charset 11342 * Get the 4 first bytes and decode the charset
10830 * if enc != XML_CHAR_ENCODING_NONE 11343 * if enc != XML_CHAR_ENCODING_NONE
10831 * plug some encoding conversion routines, 11344 * plug some encoding conversion routines,
10832 * else xmlSwitchEncoding will set to (default) 11345 * else xmlSwitchEncoding will set to (default)
10833 * UTF8. 11346 * UTF8.
10834 */ 11347 */
10835 start[0] = RAW; 11348 start[0] = RAW;
10836 start[1] = NXT(1); 11349 start[1] = NXT(1);
10837 start[2] = NXT(2); 11350 start[2] = NXT(2);
10838 start[3] = NXT(3); 11351 start[3] = NXT(3);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
10973 spacePop(ctxt); 11486 spacePop(ctxt);
10974 ctxt->instate = XML_PARSER_EOF; 11487 ctxt->instate = XML_PARSER_EOF;
10975 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11488 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10976 ctxt->sax->endDocument(ctxt->userData); 11489 ctxt->sax->endDocument(ctxt->userData);
10977 goto done; 11490 goto done;
10978 } 11491 }
10979 #ifdef LIBXML_VALID_ENABLED 11492 #ifdef LIBXML_VALID_ENABLED
10980 /* 11493 /*
10981 * [ VC: Root Element Type ] 11494 * [ VC: Root Element Type ]
10982 * The Name in the document type declaration must match 11495 * The Name in the document type declaration must match
10983 » » * the element type of the root element. 11496 » » * the element type of the root element.
10984 */ 11497 */
10985 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && 11498 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
10986 ctxt->node && (ctxt->node == ctxt->myDoc->children)) 11499 ctxt->node && (ctxt->node == ctxt->myDoc->children))
10987 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); 11500 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
10988 #endif /* LIBXML_VALID_ENABLED */ 11501 #endif /* LIBXML_VALID_ENABLED */
10989 11502
10990 /* 11503 /*
10991 * Check for an Empty Element. 11504 * Check for an Empty Element.
10992 */ 11505 */
10993 if ((RAW == '/') && (NXT(1) == '>')) { 11506 if ((RAW == '/') && (NXT(1) == '>')) {
(...skipping 16 matching lines...) Expand all
11010 #endif /* LIBXML_SAX1_ENABLED */ 11523 #endif /* LIBXML_SAX1_ENABLED */
11011 } 11524 }
11012 if (ctxt->instate == XML_PARSER_EOF) 11525 if (ctxt->instate == XML_PARSER_EOF)
11013 goto done; 11526 goto done;
11014 spacePop(ctxt); 11527 spacePop(ctxt);
11015 if (ctxt->nameNr == 0) { 11528 if (ctxt->nameNr == 0) {
11016 ctxt->instate = XML_PARSER_EPILOG; 11529 ctxt->instate = XML_PARSER_EPILOG;
11017 } else { 11530 } else {
11018 ctxt->instate = XML_PARSER_CONTENT; 11531 ctxt->instate = XML_PARSER_CONTENT;
11019 } 11532 }
11533 ctxt->progressive = 1;
11020 break; 11534 break;
11021 } 11535 }
11022 if (RAW == '>') { 11536 if (RAW == '>') {
11023 NEXT; 11537 NEXT;
11024 } else { 11538 } else {
11025 xmlFatalErrMsgStr(ctxt, XML_ERR_GT_REQUIRED, 11539 xmlFatalErrMsgStr(ctxt, XML_ERR_GT_REQUIRED,
11026 "Couldn't find end of Start Tag %s\n", 11540 "Couldn't find end of Start Tag %s\n",
11027 name); 11541 name);
11028 nodePop(ctxt); 11542 nodePop(ctxt);
11029 spacePop(ctxt); 11543 spacePop(ctxt);
11030 } 11544 }
11031 if (ctxt->sax2) 11545 if (ctxt->sax2)
11032 nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr); 11546 nameNsPush(ctxt, name, prefix, URI, ctxt->nsNr - nsNr);
11033 #ifdef LIBXML_SAX1_ENABLED 11547 #ifdef LIBXML_SAX1_ENABLED
11034 else 11548 else
11035 namePush(ctxt, name); 11549 namePush(ctxt, name);
11036 #endif /* LIBXML_SAX1_ENABLED */ 11550 #endif /* LIBXML_SAX1_ENABLED */
11037 11551
11038 ctxt->instate = XML_PARSER_CONTENT; 11552 ctxt->instate = XML_PARSER_CONTENT;
11553 ctxt->progressive = 1;
11039 break; 11554 break;
11040 } 11555 }
11041 case XML_PARSER_CONTENT: { 11556 case XML_PARSER_CONTENT: {
11042 const xmlChar *test; 11557 const xmlChar *test;
11043 unsigned int cons; 11558 unsigned int cons;
11044 if ((avail < 2) && (ctxt->inputNr == 1)) 11559 if ((avail < 2) && (ctxt->inputNr == 1))
11045 goto done; 11560 goto done;
11046 cur = ctxt->input->cur[0]; 11561 cur = ctxt->input->cur[0];
11047 next = ctxt->input->cur[1]; 11562 next = ctxt->input->cur[1];
11048 11563
11049 test = CUR_PTR; 11564 test = CUR_PTR;
11050 cons = ctxt->input->consumed; 11565 cons = ctxt->input->consumed;
11051 if ((cur == '<') && (next == '/')) { 11566 if ((cur == '<') && (next == '/')) {
11052 ctxt->instate = XML_PARSER_END_TAG; 11567 ctxt->instate = XML_PARSER_END_TAG;
11053 break; 11568 break;
11054 } else if ((cur == '<') && (next == '?')) { 11569 } else if ((cur == '<') && (next == '?')) {
11055 if ((!terminate) && 11570 if ((!terminate) &&
11056 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11571 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11572 ctxt->progressive = XML_PARSER_PI;
11057 goto done; 11573 goto done;
11574 }
11058 xmlParsePI(ctxt); 11575 xmlParsePI(ctxt);
11576 ctxt->instate = XML_PARSER_CONTENT;
11577 ctxt->progressive = 1;
11059 } else if ((cur == '<') && (next != '!')) { 11578 } else if ((cur == '<') && (next != '!')) {
11060 ctxt->instate = XML_PARSER_START_TAG; 11579 ctxt->instate = XML_PARSER_START_TAG;
11061 break; 11580 break;
11062 } else if ((cur == '<') && (next == '!') && 11581 } else if ((cur == '<') && (next == '!') &&
11063 (ctxt->input->cur[2] == '-') && 11582 (ctxt->input->cur[2] == '-') &&
11064 (ctxt->input->cur[3] == '-')) { 11583 (ctxt->input->cur[3] == '-')) {
11065 int term; 11584 int term;
11066 11585
11067 if (avail < 4) 11586 if (avail < 4)
11068 goto done; 11587 goto done;
11069 ctxt->input->cur += 4; 11588 ctxt->input->cur += 4;
11070 term = xmlParseLookupSequence(ctxt, '-', '-', '>'); 11589 term = xmlParseLookupSequence(ctxt, '-', '-', '>');
11071 ctxt->input->cur -= 4; 11590 ctxt->input->cur -= 4;
11072 » » if ((!terminate) && (term < 0)) 11591 » » if ((!terminate) && (term < 0)) {
11592 ctxt->progressive = XML_PARSER_COMMENT;
11073 goto done; 11593 goto done;
11594 }
11074 xmlParseComment(ctxt); 11595 xmlParseComment(ctxt);
11075 ctxt->instate = XML_PARSER_CONTENT; 11596 ctxt->instate = XML_PARSER_CONTENT;
11597 ctxt->progressive = 1;
11076 } else if ((cur == '<') && (ctxt->input->cur[1] == '!') && 11598 } else if ((cur == '<') && (ctxt->input->cur[1] == '!') &&
11077 (ctxt->input->cur[2] == '[') && 11599 (ctxt->input->cur[2] == '[') &&
11078 (ctxt->input->cur[3] == 'C') && 11600 (ctxt->input->cur[3] == 'C') &&
11079 (ctxt->input->cur[4] == 'D') && 11601 (ctxt->input->cur[4] == 'D') &&
11080 (ctxt->input->cur[5] == 'A') && 11602 (ctxt->input->cur[5] == 'A') &&
11081 (ctxt->input->cur[6] == 'T') && 11603 (ctxt->input->cur[6] == 'T') &&
11082 (ctxt->input->cur[7] == 'A') && 11604 (ctxt->input->cur[7] == 'A') &&
11083 (ctxt->input->cur[8] == '[')) { 11605 (ctxt->input->cur[8] == '[')) {
11084 SKIP(9); 11606 SKIP(9);
11085 ctxt->instate = XML_PARSER_CDATA_SECTION; 11607 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) { 11682 if (ctxt->instate == XML_PARSER_EOF) {
11161 /* Nothing */ 11683 /* Nothing */
11162 } else if (ctxt->nameNr == 0) { 11684 } else if (ctxt->nameNr == 0) {
11163 ctxt->instate = XML_PARSER_EPILOG; 11685 ctxt->instate = XML_PARSER_EPILOG;
11164 } else { 11686 } else {
11165 ctxt->instate = XML_PARSER_CONTENT; 11687 ctxt->instate = XML_PARSER_CONTENT;
11166 } 11688 }
11167 break; 11689 break;
11168 case XML_PARSER_CDATA_SECTION: { 11690 case XML_PARSER_CDATA_SECTION: {
11169 /* 11691 /*
11170 » » * The Push mode need to have the SAX callback for 11692 » » * The Push mode need to have the SAX callback for
11171 * cdataBlock merge back contiguous callbacks. 11693 * cdataBlock merge back contiguous callbacks.
11172 */ 11694 */
11173 int base; 11695 int base;
11174 11696
11175 base = xmlParseLookupSequence(ctxt, ']', ']', '>'); 11697 base = xmlParseLookupSequence(ctxt, ']', ']', '>');
11176 if (base < 0) { 11698 if (base < 0) {
11177 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { 11699 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) {
11178 int tmp; 11700 int tmp;
11179 11701
11180 » » » tmp = xmlCheckCdataPush(ctxt->input->cur, 11702 » » » tmp = xmlCheckCdataPush(ctxt->input->cur,
11181 XML_PARSER_BIG_BUFFER_SIZE); 11703 XML_PARSER_BIG_BUFFER_SIZE);
11182 if (tmp < 0) { 11704 if (tmp < 0) {
11183 tmp = -tmp; 11705 tmp = -tmp;
11184 ctxt->input->cur += tmp; 11706 ctxt->input->cur += tmp;
11185 goto encoding_error; 11707 goto encoding_error;
11186 } 11708 }
11187 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { 11709 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
11188 if (ctxt->sax->cdataBlock != NULL) 11710 if (ctxt->sax->cdataBlock != NULL)
11189 ctxt->sax->cdataBlock(ctxt->userData, 11711 ctxt->sax->cdataBlock(ctxt->userData,
11190 ctxt->input->cur, tmp); 11712 ctxt->input->cur, tmp);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
11240 #endif 11762 #endif
11241 } 11763 }
11242 break; 11764 break;
11243 } 11765 }
11244 case XML_PARSER_MISC: 11766 case XML_PARSER_MISC:
11245 SKIP_BLANKS; 11767 SKIP_BLANKS;
11246 if (ctxt->input->buf == NULL) 11768 if (ctxt->input->buf == NULL)
11247 avail = ctxt->input->length - 11769 avail = ctxt->input->length -
11248 (ctxt->input->cur - ctxt->input->base); 11770 (ctxt->input->cur - ctxt->input->base);
11249 else 11771 else
11250 » » avail = ctxt->input->buf->buffer->use - 11772 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11251 (ctxt->input->cur - ctxt->input->base); 11773 (ctxt->input->cur - ctxt->input->base);
11252 if (avail < 2) 11774 if (avail < 2)
11253 goto done; 11775 goto done;
11254 cur = ctxt->input->cur[0]; 11776 cur = ctxt->input->cur[0];
11255 next = ctxt->input->cur[1]; 11777 next = ctxt->input->cur[1];
11256 if ((cur == '<') && (next == '?')) { 11778 if ((cur == '<') && (next == '?')) {
11257 if ((!terminate) && 11779 if ((!terminate) &&
11258 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11780 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11781 ctxt->progressive = XML_PARSER_PI;
11259 goto done; 11782 goto done;
11783 }
11260 #ifdef DEBUG_PUSH 11784 #ifdef DEBUG_PUSH
11261 xmlGenericError(xmlGenericErrorContext, 11785 xmlGenericError(xmlGenericErrorContext,
11262 "PP: Parsing PI\n"); 11786 "PP: Parsing PI\n");
11263 #endif 11787 #endif
11264 xmlParsePI(ctxt); 11788 xmlParsePI(ctxt);
11265 if (ctxt->instate == XML_PARSER_EOF) 11789 if (ctxt->instate == XML_PARSER_EOF)
11266 goto done; 11790 goto done;
11791 ctxt->instate = XML_PARSER_MISC;
11792 ctxt->progressive = 1;
11267 ctxt->checkIndex = 0; 11793 ctxt->checkIndex = 0;
11268 } else if ((cur == '<') && (next == '!') && 11794 } else if ((cur == '<') && (next == '!') &&
11269 (ctxt->input->cur[2] == '-') && 11795 (ctxt->input->cur[2] == '-') &&
11270 (ctxt->input->cur[3] == '-')) { 11796 (ctxt->input->cur[3] == '-')) {
11271 if ((!terminate) && 11797 if ((!terminate) &&
11272 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11798 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11799 ctxt->progressive = XML_PARSER_COMMENT;
11273 goto done; 11800 goto done;
11801 }
11274 #ifdef DEBUG_PUSH 11802 #ifdef DEBUG_PUSH
11275 xmlGenericError(xmlGenericErrorContext, 11803 xmlGenericError(xmlGenericErrorContext,
11276 "PP: Parsing Comment\n"); 11804 "PP: Parsing Comment\n");
11277 #endif 11805 #endif
11278 xmlParseComment(ctxt); 11806 xmlParseComment(ctxt);
11279 if (ctxt->instate == XML_PARSER_EOF) 11807 if (ctxt->instate == XML_PARSER_EOF)
11280 goto done; 11808 goto done;
11281 ctxt->instate = XML_PARSER_MISC; 11809 ctxt->instate = XML_PARSER_MISC;
11810 ctxt->progressive = 1;
11282 ctxt->checkIndex = 0; 11811 ctxt->checkIndex = 0;
11283 } else if ((cur == '<') && (next == '!') && 11812 } else if ((cur == '<') && (next == '!') &&
11284 (ctxt->input->cur[2] == 'D') && 11813 (ctxt->input->cur[2] == 'D') &&
11285 (ctxt->input->cur[3] == 'O') && 11814 (ctxt->input->cur[3] == 'O') &&
11286 (ctxt->input->cur[4] == 'C') && 11815 (ctxt->input->cur[4] == 'C') &&
11287 (ctxt->input->cur[5] == 'T') && 11816 (ctxt->input->cur[5] == 'T') &&
11288 (ctxt->input->cur[6] == 'Y') && 11817 (ctxt->input->cur[6] == 'Y') &&
11289 (ctxt->input->cur[7] == 'P') && 11818 (ctxt->input->cur[7] == 'P') &&
11290 (ctxt->input->cur[8] == 'E')) { 11819 (ctxt->input->cur[8] == 'E')) {
11291 if ((!terminate) && 11820 if ((!terminate) &&
11292 » » (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) 11821 » » (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) {
11822 ctxt->progressive = XML_PARSER_DTD;
11293 goto done; 11823 goto done;
11824 }
11294 #ifdef DEBUG_PUSH 11825 #ifdef DEBUG_PUSH
11295 xmlGenericError(xmlGenericErrorContext, 11826 xmlGenericError(xmlGenericErrorContext,
11296 "PP: Parsing internal subset\n"); 11827 "PP: Parsing internal subset\n");
11297 #endif 11828 #endif
11298 ctxt->inSubset = 1; 11829 ctxt->inSubset = 1;
11830 ctxt->progressive = 0;
11831 ctxt->checkIndex = 0;
11299 xmlParseDocTypeDecl(ctxt); 11832 xmlParseDocTypeDecl(ctxt);
11300 if (ctxt->instate == XML_PARSER_EOF) 11833 if (ctxt->instate == XML_PARSER_EOF)
11301 goto done; 11834 goto done;
11302 if (RAW == '[') { 11835 if (RAW == '[') {
11303 ctxt->instate = XML_PARSER_DTD; 11836 ctxt->instate = XML_PARSER_DTD;
11304 #ifdef DEBUG_PUSH 11837 #ifdef DEBUG_PUSH
11305 xmlGenericError(xmlGenericErrorContext, 11838 xmlGenericError(xmlGenericErrorContext,
11306 "PP: entering DTD\n"); 11839 "PP: entering DTD\n");
11307 #endif 11840 #endif
11308 } else { 11841 } else {
(...skipping 12 matching lines...) Expand all
11321 #ifdef DEBUG_PUSH 11854 #ifdef DEBUG_PUSH
11322 xmlGenericError(xmlGenericErrorContext, 11855 xmlGenericError(xmlGenericErrorContext,
11323 "PP: entering PROLOG\n"); 11856 "PP: entering PROLOG\n");
11324 #endif 11857 #endif
11325 } 11858 }
11326 } else if ((cur == '<') && (next == '!') && 11859 } else if ((cur == '<') && (next == '!') &&
11327 (avail < 9)) { 11860 (avail < 9)) {
11328 goto done; 11861 goto done;
11329 } else { 11862 } else {
11330 ctxt->instate = XML_PARSER_START_TAG; 11863 ctxt->instate = XML_PARSER_START_TAG;
11331 » » ctxt->progressive = 1; 11864 » » ctxt->progressive = XML_PARSER_START_TAG;
11332 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11865 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
11333 #ifdef DEBUG_PUSH 11866 #ifdef DEBUG_PUSH
11334 xmlGenericError(xmlGenericErrorContext, 11867 xmlGenericError(xmlGenericErrorContext,
11335 "PP: entering START_TAG\n"); 11868 "PP: entering START_TAG\n");
11336 #endif 11869 #endif
11337 } 11870 }
11338 break; 11871 break;
11339 case XML_PARSER_PROLOG: 11872 case XML_PARSER_PROLOG:
11340 SKIP_BLANKS; 11873 SKIP_BLANKS;
11341 if (ctxt->input->buf == NULL) 11874 if (ctxt->input->buf == NULL)
11342 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base); 11875 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base);
11343 else 11876 else
11344 » » avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); 11877 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11345 » » if (avail < 2) 11878 (ctxt->input->cur - ctxt->input->base);
11879 » » if (avail < 2)
11346 goto done; 11880 goto done;
11347 cur = ctxt->input->cur[0]; 11881 cur = ctxt->input->cur[0];
11348 next = ctxt->input->cur[1]; 11882 next = ctxt->input->cur[1];
11349 if ((cur == '<') && (next == '?')) { 11883 if ((cur == '<') && (next == '?')) {
11350 if ((!terminate) && 11884 if ((!terminate) &&
11351 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11885 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11886 ctxt->progressive = XML_PARSER_PI;
11352 goto done; 11887 goto done;
11888 }
11353 #ifdef DEBUG_PUSH 11889 #ifdef DEBUG_PUSH
11354 xmlGenericError(xmlGenericErrorContext, 11890 xmlGenericError(xmlGenericErrorContext,
11355 "PP: Parsing PI\n"); 11891 "PP: Parsing PI\n");
11356 #endif 11892 #endif
11357 xmlParsePI(ctxt); 11893 xmlParsePI(ctxt);
11358 if (ctxt->instate == XML_PARSER_EOF) 11894 if (ctxt->instate == XML_PARSER_EOF)
11359 goto done; 11895 goto done;
11896 ctxt->instate = XML_PARSER_PROLOG;
11897 ctxt->progressive = 1;
11360 } else if ((cur == '<') && (next == '!') && 11898 } else if ((cur == '<') && (next == '!') &&
11361 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) { 11899 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) {
11362 if ((!terminate) && 11900 if ((!terminate) &&
11363 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11901 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11902 ctxt->progressive = XML_PARSER_COMMENT;
11364 goto done; 11903 goto done;
11904 }
11365 #ifdef DEBUG_PUSH 11905 #ifdef DEBUG_PUSH
11366 xmlGenericError(xmlGenericErrorContext, 11906 xmlGenericError(xmlGenericErrorContext,
11367 "PP: Parsing Comment\n"); 11907 "PP: Parsing Comment\n");
11368 #endif 11908 #endif
11369 xmlParseComment(ctxt); 11909 xmlParseComment(ctxt);
11370 if (ctxt->instate == XML_PARSER_EOF) 11910 if (ctxt->instate == XML_PARSER_EOF)
11371 goto done; 11911 goto done;
11372 ctxt->instate = XML_PARSER_PROLOG; 11912 ctxt->instate = XML_PARSER_PROLOG;
11913 ctxt->progressive = 1;
11373 } else if ((cur == '<') && (next == '!') && 11914 } else if ((cur == '<') && (next == '!') &&
11374 (avail < 4)) { 11915 (avail < 4)) {
11375 goto done; 11916 goto done;
11376 } else { 11917 } else {
11377 ctxt->instate = XML_PARSER_START_TAG; 11918 ctxt->instate = XML_PARSER_START_TAG;
11378 if (ctxt->progressive == 0) 11919 if (ctxt->progressive == 0)
11379 » » » ctxt->progressive = 1; 11920 » » » ctxt->progressive = XML_PARSER_START_TAG;
11380 xmlParseGetLasts(ctxt, &lastlt, &lastgt); 11921 xmlParseGetLasts(ctxt, &lastlt, &lastgt);
11381 #ifdef DEBUG_PUSH 11922 #ifdef DEBUG_PUSH
11382 xmlGenericError(xmlGenericErrorContext, 11923 xmlGenericError(xmlGenericErrorContext,
11383 "PP: entering START_TAG\n"); 11924 "PP: entering START_TAG\n");
11384 #endif 11925 #endif
11385 } 11926 }
11386 break; 11927 break;
11387 case XML_PARSER_EPILOG: 11928 case XML_PARSER_EPILOG:
11388 SKIP_BLANKS; 11929 SKIP_BLANKS;
11389 if (ctxt->input->buf == NULL) 11930 if (ctxt->input->buf == NULL)
11390 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base); 11931 avail = ctxt->input->length - (ctxt->input->cur - ctxt->inpu t->base);
11391 else 11932 else
11392 » » avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base); 11933 » » avail = xmlBufUse(ctxt->input->buf->buffer) -
11934 (ctxt->input->cur - ctxt->input->base);
11393 if (avail < 2) 11935 if (avail < 2)
11394 goto done; 11936 goto done;
11395 cur = ctxt->input->cur[0]; 11937 cur = ctxt->input->cur[0];
11396 next = ctxt->input->cur[1]; 11938 next = ctxt->input->cur[1];
11397 if ((cur == '<') && (next == '?')) { 11939 if ((cur == '<') && (next == '?')) {
11398 if ((!terminate) && 11940 if ((!terminate) &&
11399 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) 11941 » » (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
11942 ctxt->progressive = XML_PARSER_PI;
11400 goto done; 11943 goto done;
11944 }
11401 #ifdef DEBUG_PUSH 11945 #ifdef DEBUG_PUSH
11402 xmlGenericError(xmlGenericErrorContext, 11946 xmlGenericError(xmlGenericErrorContext,
11403 "PP: Parsing PI\n"); 11947 "PP: Parsing PI\n");
11404 #endif 11948 #endif
11405 xmlParsePI(ctxt); 11949 xmlParsePI(ctxt);
11406 if (ctxt->instate == XML_PARSER_EOF) 11950 if (ctxt->instate == XML_PARSER_EOF)
11407 goto done; 11951 goto done;
11408 ctxt->instate = XML_PARSER_EPILOG; 11952 ctxt->instate = XML_PARSER_EPILOG;
11953 ctxt->progressive = 1;
11409 } else if ((cur == '<') && (next == '!') && 11954 } else if ((cur == '<') && (next == '!') &&
11410 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) { 11955 (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-') ) {
11411 if ((!terminate) && 11956 if ((!terminate) &&
11412 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) 11957 » » (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
11958 ctxt->progressive = XML_PARSER_COMMENT;
11413 goto done; 11959 goto done;
11960 }
11414 #ifdef DEBUG_PUSH 11961 #ifdef DEBUG_PUSH
11415 xmlGenericError(xmlGenericErrorContext, 11962 xmlGenericError(xmlGenericErrorContext,
11416 "PP: Parsing Comment\n"); 11963 "PP: Parsing Comment\n");
11417 #endif 11964 #endif
11418 xmlParseComment(ctxt); 11965 xmlParseComment(ctxt);
11419 if (ctxt->instate == XML_PARSER_EOF) 11966 if (ctxt->instate == XML_PARSER_EOF)
11420 goto done; 11967 goto done;
11421 ctxt->instate = XML_PARSER_EPILOG; 11968 ctxt->instate = XML_PARSER_EPILOG;
11969 ctxt->progressive = 1;
11422 } else if ((cur == '<') && (next == '!') && 11970 } else if ((cur == '<') && (next == '!') &&
11423 (avail < 4)) { 11971 (avail < 4)) {
11424 goto done; 11972 goto done;
11425 } else { 11973 } else {
11426 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 11974 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11427 ctxt->instate = XML_PARSER_EOF; 11975 ctxt->instate = XML_PARSER_EOF;
11428 #ifdef DEBUG_PUSH 11976 #ifdef DEBUG_PUSH
11429 xmlGenericError(xmlGenericErrorContext, 11977 xmlGenericError(xmlGenericErrorContext,
11430 "PP: entering EOF\n"); 11978 "PP: entering EOF\n");
11431 #endif 11979 #endif
11432 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 11980 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11433 ctxt->sax->endDocument(ctxt->userData); 11981 ctxt->sax->endDocument(ctxt->userData);
11434 goto done; 11982 goto done;
11435 } 11983 }
11436 break; 11984 break;
11437 case XML_PARSER_DTD: { 11985 case XML_PARSER_DTD: {
11438 /* 11986 /*
11439 * Sorry but progressive parsing of the internal subset 11987 * Sorry but progressive parsing of the internal subset
11440 * is not expected to be supported. We first check that 11988 * is not expected to be supported. We first check that
11441 * the full content of the internal subset is available and 11989 * the full content of the internal subset is available and
11442 * the parsing is launched only at that point. 11990 * the parsing is launched only at that point.
11443 * Internal subset ends up with "']' S? '>'" in an unescaped 11991 * Internal subset ends up with "']' S? '>'" in an unescaped
11444 * section and not in a ']]>' sequence which are conditional 11992 * section and not in a ']]>' sequence which are conditional
11445 * sections (whoever argued to keep that crap in XML deserve 11993 * sections (whoever argued to keep that crap in XML deserve
11446 * a place in hell !). 11994 * a place in hell !).
11447 */ 11995 */
11448 int base, i; 11996 int base, i;
11449 xmlChar *buf; 11997 xmlChar *buf;
11450 xmlChar quote = 0; 11998 xmlChar quote = 0;
11999 size_t use;
11451 12000
11452 base = ctxt->input->cur - ctxt->input->base; 12001 base = ctxt->input->cur - ctxt->input->base;
11453 if (base < 0) return(0); 12002 if (base < 0) return(0);
11454 if (ctxt->checkIndex > base) 12003 if (ctxt->checkIndex > base)
11455 base = ctxt->checkIndex; 12004 base = ctxt->checkIndex;
11456 » » buf = ctxt->input->buf->buffer->content; 12005 » » buf = xmlBufContent(ctxt->input->buf->buffer);
11457 » » for (;(unsigned int) base < ctxt->input->buf->buffer->use; 12006 use = xmlBufUse(ctxt->input->buf->buffer);
11458 » » base++) { 12007 » » for (;(unsigned int) base < use; base++) {
11459 if (quote != 0) { 12008 if (quote != 0) {
11460 if (buf[base] == quote) 12009 if (buf[base] == quote)
11461 quote = 0; 12010 quote = 0;
11462 » » » continue; 12011 » » » continue;
11463 } 12012 }
11464 if ((quote == 0) && (buf[base] == '<')) { 12013 if ((quote == 0) && (buf[base] == '<')) {
11465 int found = 0; 12014 int found = 0;
11466 /* special handling of comments */ 12015 /* special handling of comments */
11467 » » if (((unsigned int) base + 4 < 12016 » » if (((unsigned int) base + 4 < use) &&
11468 » » » ctxt->input->buf->buffer->use) &&
11469 (buf[base + 1] == '!') && 12017 (buf[base + 1] == '!') &&
11470 (buf[base + 2] == '-') && 12018 (buf[base + 2] == '-') &&
11471 (buf[base + 3] == '-')) { 12019 (buf[base + 3] == '-')) {
11472 » » » for (;(unsigned int) base + 3 < 12020 » » » for (;(unsigned int) base + 3 < use; base++) {
11473 » » » ctxt->input->buf->buffer->use; base++) {
11474 if ((buf[base] == '-') && 12021 if ((buf[base] == '-') &&
11475 (buf[base + 1] == '-') && 12022 (buf[base + 1] == '-') &&
11476 (buf[base + 2] == '>')) { 12023 (buf[base + 2] == '>')) {
11477 found = 1; 12024 found = 1;
11478 base += 2; 12025 base += 2;
11479 break; 12026 break;
11480 } 12027 }
11481 } 12028 }
11482 if (!found) { 12029 if (!found) {
11483 #if 0 12030 #if 0
(...skipping 10 matching lines...) Expand all
11494 } 12041 }
11495 if (buf[base] == '\'') { 12042 if (buf[base] == '\'') {
11496 quote = '\''; 12043 quote = '\'';
11497 continue; 12044 continue;
11498 } 12045 }
11499 if (buf[base] == ']') { 12046 if (buf[base] == ']') {
11500 #if 0 12047 #if 0
11501 fprintf(stderr, "%c%c%c%c: ", buf[base], 12048 fprintf(stderr, "%c%c%c%c: ", buf[base],
11502 buf[base + 1], buf[base + 2], buf[base + 3]); 12049 buf[base + 1], buf[base + 2], buf[base + 3]);
11503 #endif 12050 #endif
11504 » » if ((unsigned int) base +1 >= 12051 » » if ((unsigned int) base +1 >= use)
11505 » » ctxt->input->buf->buffer->use)
11506 break; 12052 break;
11507 if (buf[base + 1] == ']') { 12053 if (buf[base + 1] == ']') {
11508 /* conditional crap, skip both ']' ! */ 12054 /* conditional crap, skip both ']' ! */
11509 base++; 12055 base++;
11510 continue; 12056 continue;
11511 } 12057 }
11512 » » for (i = 1; 12058 » » 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] == '>') { 12059 if (buf[base + i] == '>') {
11516 #if 0 12060 #if 0
11517 fprintf(stderr, "found\n"); 12061 fprintf(stderr, "found\n");
11518 #endif 12062 #endif
11519 goto found_end_int_subset; 12063 goto found_end_int_subset;
11520 } 12064 }
11521 if (!IS_BLANK_CH(buf[base + i])) { 12065 if (!IS_BLANK_CH(buf[base + i])) {
11522 #if 0 12066 #if 0
11523 fprintf(stderr, "not found\n"); 12067 fprintf(stderr, "not found\n");
11524 #endif 12068 #endif
11525 goto not_end_of_int_subset; 12069 goto not_end_of_int_subset;
11526 } 12070 }
11527 } 12071 }
11528 #if 0 12072 #if 0
11529 fprintf(stderr, "end of stream\n"); 12073 fprintf(stderr, "end of stream\n");
11530 #endif 12074 #endif
11531 break; 12075 break;
11532 12076
11533 } 12077 }
11534 not_end_of_int_subset: 12078 not_end_of_int_subset:
11535 continue; /* for */ 12079 continue; /* for */
11536 } 12080 }
11537 /* 12081 /*
11538 * We didn't found the end of the Internal subset 12082 * We didn't found the end of the Internal subset
11539 */ 12083 */
12084 if (quote == 0)
12085 ctxt->checkIndex = base;
12086 else
12087 ctxt->checkIndex = 0;
11540 #ifdef DEBUG_PUSH 12088 #ifdef DEBUG_PUSH
11541 if (next == 0) 12089 if (next == 0)
11542 xmlGenericError(xmlGenericErrorContext, 12090 xmlGenericError(xmlGenericErrorContext,
11543 "PP: lookup of int subset end filed\n"); 12091 "PP: lookup of int subset end filed\n");
11544 #endif 12092 #endif
11545 goto done; 12093 goto done;
11546 12094
11547 found_end_int_subset: 12095 found_end_int_subset:
12096 ctxt->checkIndex = 0;
11548 xmlParseInternalSubset(ctxt); 12097 xmlParseInternalSubset(ctxt);
11549 if (ctxt->instate == XML_PARSER_EOF) 12098 if (ctxt->instate == XML_PARSER_EOF)
11550 goto done; 12099 goto done;
11551 ctxt->inSubset = 2; 12100 ctxt->inSubset = 2;
11552 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && 12101 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
11553 (ctxt->sax->externalSubset != NULL)) 12102 (ctxt->sax->externalSubset != NULL))
11554 ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName, 12103 ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName,
11555 ctxt->extSubSystem, ctxt->extSubURI); 12104 ctxt->extSubSystem, ctxt->extSubURI);
11556 ctxt->inSubset = 0; 12105 ctxt->inSubset = 0;
11557 xmlCleanSpecialAttr(ctxt); 12106 xmlCleanSpecialAttr(ctxt);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
11632 xmlGenericError(xmlGenericErrorContext, 12181 xmlGenericError(xmlGenericErrorContext,
11633 "PP: internal error, state == PUBLIC_LITERAL\n"); 12182 "PP: internal error, state == PUBLIC_LITERAL\n");
11634 ctxt->instate = XML_PARSER_START_TAG; 12183 ctxt->instate = XML_PARSER_START_TAG;
11635 #ifdef DEBUG_PUSH 12184 #ifdef DEBUG_PUSH
11636 xmlGenericError(xmlGenericErrorContext, 12185 xmlGenericError(xmlGenericErrorContext,
11637 "PP: entering START_TAG\n"); 12186 "PP: entering START_TAG\n");
11638 #endif 12187 #endif
11639 break; 12188 break;
11640 } 12189 }
11641 } 12190 }
11642 done: 12191 done:
11643 #ifdef DEBUG_PUSH 12192 #ifdef DEBUG_PUSH
11644 xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret); 12193 xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret);
11645 #endif 12194 #endif
11646 return(ret); 12195 return(ret);
11647 encoding_error: 12196 encoding_error:
11648 { 12197 {
11649 char buffer[150]; 12198 char buffer[150];
11650 12199
11651 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", 12200 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
11652 ctxt->input->cur[0], ctxt->input->cur[1], 12201 ctxt->input->cur[0], ctxt->input->cur[1],
11653 ctxt->input->cur[2], ctxt->input->cur[3]); 12202 ctxt->input->cur[2], ctxt->input->cur[3]);
11654 __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR, 12203 __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
11655 "Input is not proper UTF-8, indicate encoding !\n%s", 12204 "Input is not proper UTF-8, indicate encoding !\n%s",
11656 BAD_CAST buffer, NULL); 12205 BAD_CAST buffer, NULL);
11657 } 12206 }
11658 return(0); 12207 return(0);
11659 } 12208 }
11660 12209
11661 /** 12210 /**
12211 * xmlParseCheckTransition:
12212 * @ctxt: an XML parser context
12213 * @chunk: a char array
12214 * @size: the size in byte of the chunk
12215 *
12216 * Check depending on the current parser state if the chunk given must be
12217 * processed immediately or one need more data to advance on parsing.
12218 *
12219 * Returns -1 in case of error, 0 if the push is not needed and 1 if needed
12220 */
12221 static int
12222 xmlParseCheckTransition(xmlParserCtxtPtr ctxt, const char *chunk, int size) {
12223 if ((ctxt == NULL) || (chunk == NULL) || (size < 0))
12224 return(-1);
12225 if (ctxt->instate == XML_PARSER_START_TAG) {
12226 if (memchr(chunk, '>', size) != NULL)
12227 return(1);
12228 return(0);
12229 }
12230 if (ctxt->progressive == XML_PARSER_COMMENT) {
12231 if (memchr(chunk, '>', size) != NULL)
12232 return(1);
12233 return(0);
12234 }
12235 if (ctxt->instate == XML_PARSER_CDATA_SECTION) {
12236 if (memchr(chunk, '>', size) != NULL)
12237 return(1);
12238 return(0);
12239 }
12240 if (ctxt->progressive == XML_PARSER_PI) {
12241 if (memchr(chunk, '>', size) != NULL)
12242 return(1);
12243 return(0);
12244 }
12245 if (ctxt->instate == XML_PARSER_END_TAG) {
12246 if (memchr(chunk, '>', size) != NULL)
12247 return(1);
12248 return(0);
12249 }
12250 if ((ctxt->progressive == XML_PARSER_DTD) ||
12251 (ctxt->instate == XML_PARSER_DTD)) {
12252 if (memchr(chunk, '>', size) != NULL)
12253 return(1);
12254 return(0);
12255 }
12256 return(1);
12257 }
12258
12259 /**
11662 * xmlParseChunk: 12260 * xmlParseChunk:
11663 * @ctxt: an XML parser context 12261 * @ctxt: an XML parser context
11664 * @chunk: an char array 12262 * @chunk: an char array
11665 * @size: the size in byte of the chunk 12263 * @size: the size in byte of the chunk
11666 * @terminate: last chunk indicator 12264 * @terminate: last chunk indicator
11667 * 12265 *
11668 * Parse a Chunk of memory 12266 * Parse a Chunk of memory
11669 * 12267 *
11670 * Returns zero if no error, the xmlParserErrors otherwise. 12268 * Returns zero if no error, the xmlParserErrors otherwise.
11671 */ 12269 */
11672 int 12270 int
11673 xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, 12271 xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
11674 int terminate) { 12272 int terminate) {
11675 int end_in_lf = 0; 12273 int end_in_lf = 0;
11676 int remain = 0; 12274 int remain = 0;
12275 size_t old_avail = 0;
12276 size_t avail = 0;
11677 12277
11678 if (ctxt == NULL) 12278 if (ctxt == NULL)
11679 return(XML_ERR_INTERNAL_ERROR); 12279 return(XML_ERR_INTERNAL_ERROR);
11680 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 12280 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
11681 return(ctxt->errNo); 12281 return(ctxt->errNo);
11682 if (ctxt->instate == XML_PARSER_EOF) 12282 if (ctxt->instate == XML_PARSER_EOF)
11683 return(-1); 12283 return(-1);
11684 if (ctxt->instate == XML_PARSER_START) 12284 if (ctxt->instate == XML_PARSER_START)
11685 xmlDetectSAX2(ctxt); 12285 xmlDetectSAX2(ctxt);
11686 if ((size > 0) && (chunk != NULL) && (!terminate) && 12286 if ((size > 0) && (chunk != NULL) && (!terminate) &&
11687 (chunk[size - 1] == '\r')) { 12287 (chunk[size - 1] == '\r')) {
11688 end_in_lf = 1; 12288 end_in_lf = 1;
11689 size--; 12289 size--;
11690 } 12290 }
11691 12291
11692 xmldecl_done: 12292 xmldecl_done:
11693 12293
11694 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && 12294 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
11695 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { 12295 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
11696 » int base = ctxt->input->base - ctxt->input->buf->buffer->content; 12296 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
11697 » int cur = ctxt->input->cur - ctxt->input->base; 12297 » size_t cur = ctxt->input->cur - ctxt->input->base;
11698 int res; 12298 int res;
11699 12299
12300 old_avail = xmlBufUse(ctxt->input->buf->buffer);
11700 /* 12301 /*
11701 * Specific handling if we autodetected an encoding, we should not 12302 * Specific handling if we autodetected an encoding, we should not
11702 * push more than the first line ... which depend on the encoding 12303 * push more than the first line ... which depend on the encoding
11703 * And only push the rest once the final encoding was detected 12304 * And only push the rest once the final encoding was detected
11704 */ 12305 */
11705 if ((ctxt->instate == XML_PARSER_START) && (ctxt->input != NULL) && 12306 if ((ctxt->instate == XML_PARSER_START) && (ctxt->input != NULL) &&
11706 (ctxt->input->buf != NULL) && (ctxt->input->buf->encoder != NULL)) { 12307 (ctxt->input->buf != NULL) && (ctxt->input->buf->encoder != NULL)) {
11707 unsigned int len = 45; 12308 unsigned int len = 45;
11708 12309
11709 if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12310 if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11710 BAD_CAST "UTF-16")) || 12311 BAD_CAST "UTF-16")) ||
11711 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12312 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11712 BAD_CAST "UTF16"))) 12313 BAD_CAST "UTF16")))
11713 len = 90; 12314 len = 90;
11714 else if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12315 else if ((xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11715 BAD_CAST "UCS-4")) || 12316 BAD_CAST "UCS-4")) ||
11716 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name, 12317 (xmlStrcasestr(BAD_CAST ctxt->input->buf->encoder->name,
11717 BAD_CAST "UCS4"))) 12318 BAD_CAST "UCS4")))
11718 len = 180; 12319 len = 180;
11719 12320
11720 if (ctxt->input->buf->rawconsumed < len) 12321 if (ctxt->input->buf->rawconsumed < len)
11721 len -= ctxt->input->buf->rawconsumed; 12322 len -= ctxt->input->buf->rawconsumed;
11722 12323
11723 /* 12324 /*
11724 * Change size for reading the initial declaration only 12325 * Change size for reading the initial declaration only
11725 * if size is greater than len. Otherwise, memmove in xmlBufferAdd 12326 * if size is greater than len. Otherwise, memmove in xmlBufferAdd
11726 * will blindly copy extra bytes from memory. 12327 * will blindly copy extra bytes from memory.
11727 */ 12328 */
11728 if (size > len) { 12329 if ((unsigned int) size > len) {
11729 remain = size - len; 12330 remain = size - len;
11730 size = len; 12331 size = len;
11731 } else { 12332 } else {
11732 remain = 0; 12333 remain = 0;
11733 } 12334 }
11734 } 12335 }
11735 » res =xmlParserInputBufferPush(ctxt->input->buf, size, chunk); 12336 » res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
11736 if (res < 0) { 12337 if (res < 0) {
11737 ctxt->errNo = XML_PARSER_EOF; 12338 ctxt->errNo = XML_PARSER_EOF;
11738 ctxt->disableSAX = 1; 12339 ctxt->disableSAX = 1;
11739 return (XML_PARSER_EOF); 12340 return (XML_PARSER_EOF);
11740 } 12341 }
11741 » ctxt->input->base = ctxt->input->buf->buffer->content + base; 12342 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 12343 #ifdef DEBUG_PUSH
11746 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 12344 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
11747 #endif 12345 #endif
11748 12346
11749 } else if (ctxt->instate != XML_PARSER_EOF) { 12347 } else if (ctxt->instate != XML_PARSER_EOF) {
11750 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) { 12348 if ((ctxt->input != NULL) && ctxt->input->buf != NULL) {
11751 xmlParserInputBufferPtr in = ctxt->input->buf; 12349 xmlParserInputBufferPtr in = ctxt->input->buf;
11752 if ((in->encoder != NULL) && (in->buffer != NULL) && 12350 if ((in->encoder != NULL) && (in->buffer != NULL) &&
11753 (in->raw != NULL)) { 12351 (in->raw != NULL)) {
11754 int nbchars; 12352 int nbchars;
12353 size_t base = xmlBufGetInputBase(in->buffer, ctxt->input);
12354 size_t current = ctxt->input->cur - ctxt->input->base;
11755 12355
11756 » » nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); 12356 » » nbchars = xmlCharEncInput(in, terminate);
11757 if (nbchars < 0) { 12357 if (nbchars < 0) {
11758 /* TODO 2.6.0 */ 12358 /* TODO 2.6.0 */
11759 xmlGenericError(xmlGenericErrorContext, 12359 xmlGenericError(xmlGenericErrorContext,
11760 "xmlParseChunk: encoder error\n"); 12360 "xmlParseChunk: encoder error\n");
11761 return(XML_ERR_INVALID_ENCODING); 12361 return(XML_ERR_INVALID_ENCODING);
11762 } 12362 }
12363 xmlBufSetInputBaseCur(in->buffer, ctxt->input, base, current);
11763 } 12364 }
11764 } 12365 }
11765 } 12366 }
11766 if (remain != 0) 12367 if (remain != 0) {
11767 xmlParseTryOrFinish(ctxt, 0); 12368 xmlParseTryOrFinish(ctxt, 0);
11768 else 12369 } else {
11769 xmlParseTryOrFinish(ctxt, terminate); 12370 if ((ctxt->input != NULL) && (ctxt->input->buf != NULL))
12371 avail = xmlBufUse(ctxt->input->buf->buffer);
12372 /*
12373 * Depending on the current state it may not be such
12374 * a good idea to try parsing if there is nothing in the chunk
12375 * which would be worth doing a parser state transition and we
12376 * need to wait for more data
12377 */
12378 if ((terminate) || (avail > XML_MAX_TEXT_LENGTH) ||
12379 (old_avail == 0) || (avail == 0) ||
12380 (xmlParseCheckTransition(ctxt,
12381 (const char *)&ctxt->input->base[old_avail],
12382 avail - old_avail)))
12383 xmlParseTryOrFinish(ctxt, terminate);
12384 }
11770 if (ctxt->instate == XML_PARSER_EOF) 12385 if (ctxt->instate == XML_PARSER_EOF)
11771 return(ctxt->errNo); 12386 return(ctxt->errNo);
12387
12388 if ((ctxt->input != NULL) &&
12389 (((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
12390 ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
12391 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
12392 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
12393 ctxt->instate = XML_PARSER_EOF;
12394 }
11772 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) 12395 if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
11773 return(ctxt->errNo); 12396 return(ctxt->errNo);
11774 12397
11775 if (remain != 0) { 12398 if (remain != 0) {
11776 chunk += size; 12399 chunk += size;
11777 size = remain; 12400 size = remain;
11778 remain = 0; 12401 remain = 0;
11779 goto xmldecl_done; 12402 goto xmldecl_done;
11780 } 12403 }
11781 if ((end_in_lf == 1) && (ctxt->input != NULL) && 12404 if ((end_in_lf == 1) && (ctxt->input != NULL) &&
11782 (ctxt->input->buf != NULL)) { 12405 (ctxt->input->buf != NULL)) {
12406 size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
12407 ctxt->input);
12408 size_t current = ctxt->input->cur - ctxt->input->base;
12409
11783 xmlParserInputBufferPush(ctxt->input->buf, 1, "\r"); 12410 xmlParserInputBufferPush(ctxt->input->buf, 1, "\r");
12411
12412 xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
12413 base, current);
11784 } 12414 }
11785 if (terminate) { 12415 if (terminate) {
11786 /* 12416 /*
11787 * Check for termination 12417 * Check for termination
11788 */ 12418 */
11789 » int avail = 0; 12419 » int cur_avail = 0;
11790 12420
11791 if (ctxt->input != NULL) { 12421 if (ctxt->input != NULL) {
11792 if (ctxt->input->buf == NULL) 12422 if (ctxt->input->buf == NULL)
11793 » » avail = ctxt->input->length - 12423 » » cur_avail = ctxt->input->length -
11794 » » » (ctxt->input->cur - ctxt->input->base); 12424 » » » (ctxt->input->cur - ctxt->input->base);
11795 else 12425 else
11796 » » avail = ctxt->input->buf->buffer->use - 12426 » » cur_avail = xmlBufUse(ctxt->input->buf->buffer) -
11797 » » » (ctxt->input->cur - ctxt->input->base); 12427 » » » (ctxt->input->cur - ctxt->input->base);
11798 } 12428 }
11799 » » » 12429
11800 if ((ctxt->instate != XML_PARSER_EOF) && 12430 if ((ctxt->instate != XML_PARSER_EOF) &&
11801 (ctxt->instate != XML_PARSER_EPILOG)) { 12431 (ctxt->instate != XML_PARSER_EPILOG)) {
11802 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 12432 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11803 » } 12433 » }
11804 » if ((ctxt->instate == XML_PARSER_EPILOG) && (avail > 0)) { 12434 » if ((ctxt->instate == XML_PARSER_EPILOG) && (cur_avail > 0)) {
11805 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL); 12435 xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
11806 } 12436 }
11807 if (ctxt->instate != XML_PARSER_EOF) { 12437 if (ctxt->instate != XML_PARSER_EOF) {
11808 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) 12438 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
11809 ctxt->sax->endDocument(ctxt->userData); 12439 ctxt->sax->endDocument(ctxt->userData);
11810 } 12440 }
11811 ctxt->instate = XML_PARSER_EOF; 12441 ctxt->instate = XML_PARSER_EOF;
11812 } 12442 }
11813 return((xmlParserErrors) ctxt->errNo);» 12443 if (ctxt->wellFormed == 0)
12444 » return((xmlParserErrors) ctxt->errNo);
12445 else
12446 return(0);
11814 } 12447 }
11815 12448
11816 /************************************************************************ 12449 /************************************************************************
11817 * * 12450 * *
11818 * » » I/O front end functions to the parser» » » * 12451 *» » I/O front end functions to the parser» » » *
11819 * * 12452 * *
11820 ************************************************************************/ 12453 ************************************************************************/
11821 12454
11822 /** 12455 /**
11823 * xmlCreatePushParserCtxt: 12456 * xmlCreatePushParserCtxt:
11824 * @sax: a SAX handler 12457 * @sax: a SAX handler
11825 * @user_data: The user data returned on SAX callbacks 12458 * @user_data: The user data returned on SAX callbacks
11826 * @chunk: a pointer to an array of chars 12459 * @chunk: a pointer to an array of chars
11827 * @size: number of chars in the array 12460 * @size: number of chars in the array
11828 * @filename: an optional file name or URI 12461 * @filename: an optional file name or URI
11829 * 12462 *
11830 * Create a parser context for using the XML parser in push mode. 12463 * 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 12464 * If @buffer and @size are non-NULL, the data is used to detect
11832 * the encoding. The remaining characters will be parsed so they 12465 * the encoding. The remaining characters will be parsed so they
11833 * don't need to be fed in again through xmlParseChunk. 12466 * don't need to be fed in again through xmlParseChunk.
11834 * To allow content encoding detection, @size should be >= 4 12467 * To allow content encoding detection, @size should be >= 4
11835 * The value of @filename is used for fetching external entities 12468 * The value of @filename is used for fetching external entities
11836 * and error/warning reports. 12469 * and error/warning reports.
11837 * 12470 *
11838 * Returns the new parser context or NULL 12471 * Returns the new parser context or NULL
11839 */ 12472 */
11840 12473
11841 xmlParserCtxtPtr 12474 xmlParserCtxtPtr
11842 xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, 12475 xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
11843 const char *chunk, int size, const char *filename) { 12476 const char *chunk, int size, const char *filename) {
11844 xmlParserCtxtPtr ctxt; 12477 xmlParserCtxtPtr ctxt;
11845 xmlParserInputPtr inputStream; 12478 xmlParserInputPtr inputStream;
11846 xmlParserInputBufferPtr buf; 12479 xmlParserInputBufferPtr buf;
11847 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; 12480 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
11848 12481
11849 /* 12482 /*
11850 * plug some encoding conversion routines 12483 * plug some encoding conversion routines
11851 */ 12484 */
11852 if ((chunk != NULL) && (size >= 4)) 12485 if ((chunk != NULL) && (size >= 4))
(...skipping 28 matching lines...) Expand all
11881 xmlFreeParserCtxt(ctxt); 12514 xmlFreeParserCtxt(ctxt);
11882 return(NULL); 12515 return(NULL);
11883 } 12516 }
11884 memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); 12517 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
11885 if (sax->initialized == XML_SAX2_MAGIC) 12518 if (sax->initialized == XML_SAX2_MAGIC)
11886 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); 12519 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
11887 else 12520 else
11888 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); 12521 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
11889 if (user_data != NULL) 12522 if (user_data != NULL)
11890 ctxt->userData = user_data; 12523 ctxt->userData = user_data;
11891 }» 12524 }
11892 if (filename == NULL) { 12525 if (filename == NULL) {
11893 ctxt->directory = NULL; 12526 ctxt->directory = NULL;
11894 } else { 12527 } else {
11895 ctxt->directory = xmlParserGetDirectory(filename); 12528 ctxt->directory = xmlParserGetDirectory(filename);
11896 } 12529 }
11897 12530
11898 inputStream = xmlNewInputStream(ctxt); 12531 inputStream = xmlNewInputStream(ctxt);
11899 if (inputStream == NULL) { 12532 if (inputStream == NULL) {
11900 xmlFreeParserCtxt(ctxt); 12533 xmlFreeParserCtxt(ctxt);
11901 xmlFreeParserInputBuffer(buf); 12534 xmlFreeParserInputBuffer(buf);
11902 return(NULL); 12535 return(NULL);
11903 } 12536 }
11904 12537
11905 if (filename == NULL) 12538 if (filename == NULL)
11906 inputStream->filename = NULL; 12539 inputStream->filename = NULL;
11907 else { 12540 else {
11908 inputStream->filename = (char *) 12541 inputStream->filename = (char *)
11909 xmlCanonicPath((const xmlChar *) filename); 12542 xmlCanonicPath((const xmlChar *) filename);
11910 if (inputStream->filename == NULL) { 12543 if (inputStream->filename == NULL) {
11911 xmlFreeParserCtxt(ctxt); 12544 xmlFreeParserCtxt(ctxt);
11912 xmlFreeParserInputBuffer(buf); 12545 xmlFreeParserInputBuffer(buf);
11913 return(NULL); 12546 return(NULL);
11914 } 12547 }
11915 } 12548 }
11916 inputStream->buf = buf; 12549 inputStream->buf = buf;
11917 inputStream->base = inputStream->buf->buffer->content; 12550 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); 12551 inputPush(ctxt, inputStream);
11923 12552
11924 /* 12553 /*
11925 * If the caller didn't provide an initial 'chunk' for determining 12554 * If the caller didn't provide an initial 'chunk' for determining
11926 * the encoding, we set the context to XML_CHAR_ENCODING_NONE so 12555 * the encoding, we set the context to XML_CHAR_ENCODING_NONE so
11927 * that it can be automatically determined later 12556 * that it can be automatically determined later
11928 */ 12557 */
11929 if ((size == 0) || (chunk == NULL)) { 12558 if ((size == 0) || (chunk == NULL)) {
11930 ctxt->charset = XML_CHAR_ENCODING_NONE; 12559 ctxt->charset = XML_CHAR_ENCODING_NONE;
11931 } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) { 12560 } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) {
11932 » int base = ctxt->input->base - ctxt->input->buf->buffer->content; 12561 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
11933 » int cur = ctxt->input->cur - ctxt->input->base; 12562 » size_t cur = ctxt->input->cur - ctxt->input->base;
11934 12563
11935 » xmlParserInputBufferPush(ctxt->input->buf, size, chunk);» 12564 » xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
11936 12565
11937 » ctxt->input->base = ctxt->input->buf->buffer->content + base; 12566 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 12567 #ifdef DEBUG_PUSH
11942 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 12568 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
11943 #endif 12569 #endif
11944 } 12570 }
11945 12571
11946 if (enc != XML_CHAR_ENCODING_NONE) { 12572 if (enc != XML_CHAR_ENCODING_NONE) {
11947 xmlSwitchEncoding(ctxt, enc); 12573 xmlSwitchEncoding(ctxt, enc);
11948 } 12574 }
11949 12575
11950 return(ctxt); 12576 return(ctxt);
11951 } 12577 }
11952 #endif /* LIBXML_PUSH_ENABLED */ 12578 #endif /* LIBXML_PUSH_ENABLED */
11953 12579
11954 /** 12580 /**
11955 * xmlStopParser: 12581 * xmlStopParser:
11956 * @ctxt: an XML parser context 12582 * @ctxt: an XML parser context
11957 * 12583 *
11958 * Blocks further parser processing 12584 * Blocks further parser processing
11959 */ 12585 */
11960 void 12586 void
11961 xmlStopParser(xmlParserCtxtPtr ctxt) { 12587 xmlStopParser(xmlParserCtxtPtr ctxt) {
11962 if (ctxt == NULL) 12588 if (ctxt == NULL)
11963 return; 12589 return;
11964 ctxt->instate = XML_PARSER_EOF; 12590 ctxt->instate = XML_PARSER_EOF;
11965 ctxt->errNo = XML_ERR_USER_STOP; 12591 ctxt->errNo = XML_ERR_USER_STOP;
11966 ctxt->disableSAX = 1; 12592 ctxt->disableSAX = 1;
11967 if (ctxt->input != NULL) { 12593 if (ctxt->input != NULL) {
11968 ctxt->input->cur = BAD_CAST""; 12594 ctxt->input->cur = BAD_CAST"";
11969 ctxt->input->base = ctxt->input->cur; 12595 ctxt->input->base = ctxt->input->cur;
11970 } 12596 }
(...skipping 13 matching lines...) Expand all
11984 * 12610 *
11985 * Returns the new parser context or NULL 12611 * Returns the new parser context or NULL
11986 */ 12612 */
11987 xmlParserCtxtPtr 12613 xmlParserCtxtPtr
11988 xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, 12614 xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
11989 xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, 12615 xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
11990 void *ioctx, xmlCharEncoding enc) { 12616 void *ioctx, xmlCharEncoding enc) {
11991 xmlParserCtxtPtr ctxt; 12617 xmlParserCtxtPtr ctxt;
11992 xmlParserInputPtr inputStream; 12618 xmlParserInputPtr inputStream;
11993 xmlParserInputBufferPtr buf; 12619 xmlParserInputBufferPtr buf;
11994 12620
11995 if (ioread == NULL) return(NULL); 12621 if (ioread == NULL) return(NULL);
11996 12622
11997 buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc); 12623 buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
11998 if (buf == NULL) return(NULL); 12624 if (buf == NULL) {
12625 if (ioclose != NULL)
12626 ioclose(ioctx);
12627 return (NULL);
12628 }
11999 12629
12000 ctxt = xmlNewParserCtxt(); 12630 ctxt = xmlNewParserCtxt();
12001 if (ctxt == NULL) { 12631 if (ctxt == NULL) {
12002 xmlFreeParserInputBuffer(buf); 12632 xmlFreeParserInputBuffer(buf);
12003 return(NULL); 12633 return(NULL);
12004 } 12634 }
12005 if (sax != NULL) { 12635 if (sax != NULL) {
12006 #ifdef LIBXML_SAX1_ENABLED 12636 #ifdef LIBXML_SAX1_ENABLED
12007 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 12637 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
12008 #endif /* LIBXML_SAX1_ENABLED */ 12638 #endif /* LIBXML_SAX1_ENABLED */
12009 xmlFree(ctxt->sax); 12639 xmlFree(ctxt->sax);
12010 ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); 12640 ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
12011 if (ctxt->sax == NULL) { 12641 if (ctxt->sax == NULL) {
12012 xmlErrMemory(ctxt, NULL); 12642 xmlErrMemory(ctxt, NULL);
12013 xmlFreeParserCtxt(ctxt); 12643 xmlFreeParserCtxt(ctxt);
12014 return(NULL); 12644 return(NULL);
12015 } 12645 }
12016 memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); 12646 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
12017 if (sax->initialized == XML_SAX2_MAGIC) 12647 if (sax->initialized == XML_SAX2_MAGIC)
12018 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); 12648 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
12019 else 12649 else
12020 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); 12650 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
12021 if (user_data != NULL) 12651 if (user_data != NULL)
12022 ctxt->userData = user_data; 12652 ctxt->userData = user_data;
12023 }» 12653 }
12024 12654
12025 inputStream = xmlNewIOInputStream(ctxt, buf, enc); 12655 inputStream = xmlNewIOInputStream(ctxt, buf, enc);
12026 if (inputStream == NULL) { 12656 if (inputStream == NULL) {
12027 xmlFreeParserCtxt(ctxt); 12657 xmlFreeParserCtxt(ctxt);
12028 return(NULL); 12658 return(NULL);
12029 } 12659 }
12030 inputPush(ctxt, inputStream); 12660 inputPush(ctxt, inputStream);
12031 12661
12032 return(ctxt); 12662 return(ctxt);
12033 } 12663 }
12034 12664
12035 #ifdef LIBXML_VALID_ENABLED 12665 #ifdef LIBXML_VALID_ENABLED
12036 /************************************************************************ 12666 /************************************************************************
12037 * * 12667 * *
12038 * » » Front ends when parsing a DTD» » » » * 12668 *» » Front ends when parsing a DTD» » » » *
12039 * * 12669 * *
12040 ************************************************************************/ 12670 ************************************************************************/
12041 12671
12042 /** 12672 /**
12043 * xmlIOParseDTD: 12673 * xmlIOParseDTD:
12044 * @sax: the SAX handler block or NULL 12674 * @sax: the SAX handler block or NULL
12045 * @input: an Input Buffer 12675 * @input: an Input Buffer
12046 * @enc: the charset encoding if known 12676 * @enc: the charset encoding if known
12047 * 12677 *
12048 * Load and parse a DTD 12678 * Load and parse a DTD
12049 * 12679 *
12050 * Returns the resulting xmlDtdPtr or NULL in case of error. 12680 * Returns the resulting xmlDtdPtr or NULL in case of error.
12051 * @input will be freed by the function in any case. 12681 * @input will be freed by the function in any case.
12052 */ 12682 */
12053 12683
12054 xmlDtdPtr 12684 xmlDtdPtr
12055 xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, 12685 xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input,
12056 xmlCharEncoding enc) { 12686 xmlCharEncoding enc) {
12057 xmlDtdPtr ret = NULL; 12687 xmlDtdPtr ret = NULL;
12058 xmlParserCtxtPtr ctxt; 12688 xmlParserCtxtPtr ctxt;
12059 xmlParserInputPtr pinput = NULL; 12689 xmlParserInputPtr pinput = NULL;
12060 xmlChar start[4]; 12690 xmlChar start[4];
12061 12691
12062 if (input == NULL) 12692 if (input == NULL)
12063 return(NULL); 12693 return(NULL);
12064 12694
12065 ctxt = xmlNewParserCtxt(); 12695 ctxt = xmlNewParserCtxt();
12066 if (ctxt == NULL) { 12696 if (ctxt == NULL) {
12067 xmlFreeParserInputBuffer(input); 12697 xmlFreeParserInputBuffer(input);
12068 return(NULL); 12698 return(NULL);
12069 } 12699 }
12070 12700
12701 /* We are loading a DTD */
12702 ctxt->options |= XML_PARSE_DTDLOAD;
12703
12071 /* 12704 /*
12072 * Set-up the SAX context 12705 * Set-up the SAX context
12073 */ 12706 */
12074 if (sax != NULL) { 12707 if (sax != NULL) {
12075 if (ctxt->sax != NULL) 12708 if (ctxt->sax != NULL)
12076 xmlFree(ctxt->sax); 12709 xmlFree(ctxt->sax);
12077 ctxt->sax = sax; 12710 ctxt->sax = sax;
12078 ctxt->userData = ctxt; 12711 ctxt->userData = ctxt;
12079 } 12712 }
12080 xmlDetectSAX2(ctxt); 12713 xmlDetectSAX2(ctxt);
12081 12714
12082 /* 12715 /*
12083 * generate a parser input from the I/O handler 12716 * generate a parser input from the I/O handler
12084 */ 12717 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
12118 if (ctxt->myDoc == NULL) { 12751 if (ctxt->myDoc == NULL) {
12119 xmlErrMemory(ctxt, "New Doc failed"); 12752 xmlErrMemory(ctxt, "New Doc failed");
12120 return(NULL); 12753 return(NULL);
12121 } 12754 }
12122 ctxt->myDoc->properties = XML_DOC_INTERNAL; 12755 ctxt->myDoc->properties = XML_DOC_INTERNAL;
12123 ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none", 12756 ctxt->myDoc->extSubset = xmlNewDtd(ctxt->myDoc, BAD_CAST "none",
12124 BAD_CAST "none", BAD_CAST "none"); 12757 BAD_CAST "none", BAD_CAST "none");
12125 12758
12126 if ((enc == XML_CHAR_ENCODING_NONE) && 12759 if ((enc == XML_CHAR_ENCODING_NONE) &&
12127 ((ctxt->input->end - ctxt->input->cur) >= 4)) { 12760 ((ctxt->input->end - ctxt->input->cur) >= 4)) {
12128 » /* 12761 » /*
12129 * Get the 4 first bytes and decode the charset 12762 * Get the 4 first bytes and decode the charset
12130 * if enc != XML_CHAR_ENCODING_NONE 12763 * if enc != XML_CHAR_ENCODING_NONE
12131 * plug some encoding conversion routines. 12764 * plug some encoding conversion routines.
12132 */ 12765 */
12133 start[0] = RAW; 12766 start[0] = RAW;
12134 start[1] = NXT(1); 12767 start[1] = NXT(1);
12135 start[2] = NXT(2); 12768 start[2] = NXT(2);
12136 start[3] = NXT(3); 12769 start[3] = NXT(3);
12137 enc = xmlDetectCharEncoding(start, 4); 12770 enc = xmlDetectCharEncoding(start, 4);
12138 if (enc != XML_CHAR_ENCODING_NONE) { 12771 if (enc != XML_CHAR_ENCODING_NONE) {
(...skipping 18 matching lines...) Expand all
12157 } 12790 }
12158 } 12791 }
12159 } else { 12792 } else {
12160 ret = NULL; 12793 ret = NULL;
12161 } 12794 }
12162 xmlFreeDoc(ctxt->myDoc); 12795 xmlFreeDoc(ctxt->myDoc);
12163 ctxt->myDoc = NULL; 12796 ctxt->myDoc = NULL;
12164 } 12797 }
12165 if (sax != NULL) ctxt->sax = NULL; 12798 if (sax != NULL) ctxt->sax = NULL;
12166 xmlFreeParserCtxt(ctxt); 12799 xmlFreeParserCtxt(ctxt);
12167 12800
12168 return(ret); 12801 return(ret);
12169 } 12802 }
12170 12803
12171 /** 12804 /**
12172 * xmlSAXParseDTD: 12805 * xmlSAXParseDTD:
12173 * @sax: the SAX handler block 12806 * @sax: the SAX handler block
12174 * @ExternalID: a NAME* containing the External ID of the DTD 12807 * @ExternalID: a NAME* containing the External ID of the DTD
12175 * @SystemID: a NAME* containing the URL to the DTD 12808 * @SystemID: a NAME* containing the URL to the DTD
12176 * 12809 *
12177 * Load and parse an external subset. 12810 * Load and parse an external subset.
12178 * 12811 *
12179 * Returns the resulting xmlDtdPtr or NULL in case of error. 12812 * Returns the resulting xmlDtdPtr or NULL in case of error.
12180 */ 12813 */
12181 12814
12182 xmlDtdPtr 12815 xmlDtdPtr
12183 xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, 12816 xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID,
12184 const xmlChar *SystemID) { 12817 const xmlChar *SystemID) {
12185 xmlDtdPtr ret = NULL; 12818 xmlDtdPtr ret = NULL;
12186 xmlParserCtxtPtr ctxt; 12819 xmlParserCtxtPtr ctxt;
12187 xmlParserInputPtr input = NULL; 12820 xmlParserInputPtr input = NULL;
12188 xmlCharEncoding enc; 12821 xmlCharEncoding enc;
12189 xmlChar* systemIdCanonic; 12822 xmlChar* systemIdCanonic;
12190 12823
12191 if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); 12824 if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL);
12192 12825
12193 ctxt = xmlNewParserCtxt(); 12826 ctxt = xmlNewParserCtxt();
12194 if (ctxt == NULL) { 12827 if (ctxt == NULL) {
12195 return(NULL); 12828 return(NULL);
12196 } 12829 }
12197 12830
12831 /* We are loading a DTD */
12832 ctxt->options |= XML_PARSE_DTDLOAD;
12833
12198 /* 12834 /*
12199 * Set-up the SAX context 12835 * Set-up the SAX context
12200 */ 12836 */
12201 if (sax != NULL) { 12837 if (sax != NULL) {
12202 if (ctxt->sax != NULL) 12838 if (ctxt->sax != NULL)
12203 xmlFree(ctxt->sax); 12839 xmlFree(ctxt->sax);
12204 ctxt->sax = sax; 12840 ctxt->sax = sax;
12205 ctxt->userData = ctxt; 12841 ctxt->userData = ctxt;
12206 } 12842 }
12207 12843
12208 /* 12844 /*
12209 * Canonicalise the system ID 12845 * Canonicalise the system ID
12210 */ 12846 */
12211 systemIdCanonic = xmlCanonicPath(SystemID); 12847 systemIdCanonic = xmlCanonicPath(SystemID);
12212 if ((SystemID != NULL) && (systemIdCanonic == NULL)) { 12848 if ((SystemID != NULL) && (systemIdCanonic == NULL)) {
12213 xmlFreeParserCtxt(ctxt); 12849 xmlFreeParserCtxt(ctxt);
12214 return(NULL); 12850 return(NULL);
12215 } 12851 }
12216 12852
12217 /* 12853 /*
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
12308 */ 12944 */
12309 12945
12310 xmlDtdPtr 12946 xmlDtdPtr
12311 xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) { 12947 xmlParseDTD(const xmlChar *ExternalID, const xmlChar *SystemID) {
12312 return(xmlSAXParseDTD(NULL, ExternalID, SystemID)); 12948 return(xmlSAXParseDTD(NULL, ExternalID, SystemID));
12313 } 12949 }
12314 #endif /* LIBXML_VALID_ENABLED */ 12950 #endif /* LIBXML_VALID_ENABLED */
12315 12951
12316 /************************************************************************ 12952 /************************************************************************
12317 * * 12953 * *
12318 * » » Front ends when parsing an Entity» » » * 12954 *» » Front ends when parsing an Entity» » » *
12319 * * 12955 * *
12320 ************************************************************************/ 12956 ************************************************************************/
12321 12957
12322 /** 12958 /**
12323 * xmlParseCtxtExternalEntity: 12959 * xmlParseCtxtExternalEntity:
12324 * @ctx: the existing parsing context 12960 * @ctx: the existing parsing context
12325 * @URL: the URL for the entity to load 12961 * @URL: the URL for the entity to load
12326 * @ID: the System ID for the entity to load 12962 * @ID: the System ID for the entity to load
12327 * @lst: the return value for the set of parsed nodes 12963 * @lst: the return value for the set of parsed nodes
12328 * 12964 *
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
12424 /* 13060 /*
12425 * Parse a possible text declaration first 13061 * Parse a possible text declaration first
12426 */ 13062 */
12427 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) { 13063 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
12428 xmlParseTextDecl(ctxt); 13064 xmlParseTextDecl(ctxt);
12429 /* 13065 /*
12430 * An XML-1.0 document can't reference an entity not XML-1.0 13066 * An XML-1.0 document can't reference an entity not XML-1.0
12431 */ 13067 */
12432 if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) && 13068 if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) &&
12433 (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) { 13069 (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) {
12434 » xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH, 13070 » xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH,
12435 "Version mismatch between document and entity\n"); 13071 "Version mismatch between document and entity\n");
12436 } 13072 }
12437 } 13073 }
12438 13074
12439 /* 13075 /*
13076 * If the user provided its own SAX callbacks then reuse the
13077 * useData callback field, otherwise the expected setup in a
13078 * DOM builder is to have userData == ctxt
13079 */
13080 if (ctx->userData == ctx)
13081 ctxt->userData = ctxt;
13082 else
13083 ctxt->userData = ctx->userData;
13084
13085 /*
12440 * Doing validity checking on chunk doesn't make sense 13086 * Doing validity checking on chunk doesn't make sense
12441 */ 13087 */
12442 ctxt->instate = XML_PARSER_CONTENT; 13088 ctxt->instate = XML_PARSER_CONTENT;
12443 ctxt->validate = ctx->validate; 13089 ctxt->validate = ctx->validate;
12444 ctxt->valid = ctx->valid; 13090 ctxt->valid = ctx->valid;
12445 ctxt->loadsubset = ctx->loadsubset; 13091 ctxt->loadsubset = ctx->loadsubset;
12446 ctxt->depth = ctx->depth + 1; 13092 ctxt->depth = ctx->depth + 1;
12447 ctxt->replaceEntities = ctx->replaceEntities; 13093 ctxt->replaceEntities = ctx->replaceEntities;
12448 if (ctxt->validate) { 13094 if (ctxt->validate) {
12449 ctxt->vctxt.error = ctx->vctxt.error; 13095 ctxt->vctxt.error = ctx->vctxt.error;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
12697 if (ctxt->input != NULL) { 13343 if (ctxt->input != NULL) {
12698 oldctxt->sizeentities += ctxt->input->consumed; 13344 oldctxt->sizeentities += ctxt->input->consumed;
12699 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base); 13345 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base);
12700 } 13346 }
12701 /* 13347 /*
12702 * And record the last error if any 13348 * And record the last error if any
12703 */ 13349 */
12704 if (ctxt->lastError.code != XML_ERR_OK) 13350 if (ctxt->lastError.code != XML_ERR_OK)
12705 xmlCopyError(&ctxt->lastError, &oldctxt->lastError); 13351 xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
12706 13352
12707 if (sax != NULL) 13353 if (sax != NULL)
12708 ctxt->sax = oldsax; 13354 ctxt->sax = oldsax;
12709 oldctxt->node_seq.maximum = ctxt->node_seq.maximum; 13355 oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
12710 oldctxt->node_seq.length = ctxt->node_seq.length; 13356 oldctxt->node_seq.length = ctxt->node_seq.length;
12711 oldctxt->node_seq.buffer = ctxt->node_seq.buffer; 13357 oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
12712 ctxt->node_seq.maximum = 0; 13358 ctxt->node_seq.maximum = 0;
12713 ctxt->node_seq.length = 0; 13359 ctxt->node_seq.length = 0;
12714 ctxt->node_seq.buffer = NULL; 13360 ctxt->node_seq.buffer = NULL;
12715 xmlFreeParserCtxt(ctxt); 13361 xmlFreeParserCtxt(ctxt);
12716 newDoc->intSubset = NULL; 13362 newDoc->intSubset = NULL;
12717 newDoc->extSubset = NULL; 13363 newDoc->extSubset = NULL;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
13067 } else 13713 } else
13068 options |= XML_PARSE_NODICT; 13714 options |= XML_PARSE_NODICT;
13069 13715
13070 if (doc->encoding != NULL) { 13716 if (doc->encoding != NULL) {
13071 xmlCharEncodingHandlerPtr hdlr; 13717 xmlCharEncodingHandlerPtr hdlr;
13072 13718
13073 if (ctxt->encoding != NULL) 13719 if (ctxt->encoding != NULL)
13074 xmlFree((xmlChar *) ctxt->encoding); 13720 xmlFree((xmlChar *) ctxt->encoding);
13075 ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding); 13721 ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding);
13076 13722
13077 hdlr = xmlFindCharEncodingHandler(doc->encoding); 13723 hdlr = xmlFindCharEncodingHandler((const char *) doc->encoding);
13078 if (hdlr != NULL) { 13724 if (hdlr != NULL) {
13079 xmlSwitchToEncoding(ctxt, hdlr); 13725 xmlSwitchToEncoding(ctxt, hdlr);
13080 } else { 13726 } else {
13081 return(XML_ERR_UNSUPPORTED_ENCODING); 13727 return(XML_ERR_UNSUPPORTED_ENCODING);
13082 } 13728 }
13083 } 13729 }
13084 13730
13085 xmlCtxtUseOptionsInternal(ctxt, options, NULL); 13731 xmlCtxtUseOptionsInternal(ctxt, options, NULL);
13086 xmlDetectSAX2(ctxt); 13732 xmlDetectSAX2(ctxt);
13087 ctxt->myDoc = doc; 13733 ctxt->myDoc = doc;
13734 /* parsing in context, i.e. as within existing content */
13735 ctxt->instate = XML_PARSER_CONTENT;
13088 13736
13089 fake = xmlNewComment(NULL); 13737 fake = xmlNewComment(NULL);
13090 if (fake == NULL) { 13738 if (fake == NULL) {
13091 xmlFreeParserCtxt(ctxt); 13739 xmlFreeParserCtxt(ctxt);
13092 return(XML_ERR_NO_MEMORY); 13740 return(XML_ERR_NO_MEMORY);
13093 } 13741 }
13094 xmlAddChild(node, fake); 13742 xmlAddChild(node, fake);
13095 13743
13096 if (node->type == XML_ELEMENT_NODE) { 13744 if (node->type == XML_ELEMENT_NODE) {
13097 nodePush(ctxt, node); 13745 nodePush(ctxt, node);
(...skipping 15 matching lines...) Expand all
13113 } 13761 }
13114 13762
13115 if (xmlGetNamespace(ctxt, iprefix) == NULL) { 13763 if (xmlGetNamespace(ctxt, iprefix) == NULL) {
13116 nsPush(ctxt, iprefix, ihref); 13764 nsPush(ctxt, iprefix, ihref);
13117 nsnr++; 13765 nsnr++;
13118 } 13766 }
13119 ns = ns->next; 13767 ns = ns->next;
13120 } 13768 }
13121 cur = cur->parent; 13769 cur = cur->parent;
13122 } 13770 }
13123 ctxt->instate = XML_PARSER_CONTENT;
13124 } 13771 }
13125 13772
13126 if ((ctxt->validate) || (ctxt->replaceEntities != 0)) { 13773 if ((ctxt->validate) || (ctxt->replaceEntities != 0)) {
13127 /* 13774 /*
13128 * ID/IDREF registration will be done in xmlValidateElement below 13775 * ID/IDREF registration will be done in xmlValidateElement below
13129 */ 13776 */
13130 ctxt->loadsubset |= XML_SKIP_IDS; 13777 ctxt->loadsubset |= XML_SKIP_IDS;
13131 } 13778 }
13132 13779
13133 #ifdef LIBXML_HTML_ENABLED 13780 #ifdef LIBXML_HTML_ENABLED
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
13516 * * 14163 * *
13517 * Front ends when parsing from a file * 14164 * Front ends when parsing from a file *
13518 * * 14165 * *
13519 ************************************************************************/ 14166 ************************************************************************/
13520 14167
13521 /** 14168 /**
13522 * xmlCreateURLParserCtxt: 14169 * xmlCreateURLParserCtxt:
13523 * @filename: the filename or URL 14170 * @filename: the filename or URL
13524 * @options: a combination of xmlParserOption 14171 * @options: a combination of xmlParserOption
13525 * 14172 *
13526 * Create a parser context for a file or URL content. 14173 * Create a parser context for a file or URL content.
13527 * Automatic support for ZLIB/Compress compressed document is provided 14174 * Automatic support for ZLIB/Compress compressed document is provided
13528 * by default if found at compile-time and for file accesses 14175 * by default if found at compile-time and for file accesses
13529 * 14176 *
13530 * Returns the new parser context or NULL 14177 * Returns the new parser context or NULL
13531 */ 14178 */
13532 xmlParserCtxtPtr 14179 xmlParserCtxtPtr
13533 xmlCreateURLParserCtxt(const char *filename, int options) 14180 xmlCreateURLParserCtxt(const char *filename, int options)
13534 { 14181 {
13535 xmlParserCtxtPtr ctxt; 14182 xmlParserCtxtPtr ctxt;
13536 xmlParserInputPtr inputStream; 14183 xmlParserInputPtr inputStream;
(...skipping 21 matching lines...) Expand all
13558 if ((ctxt->directory == NULL) && (directory != NULL)) 14205 if ((ctxt->directory == NULL) && (directory != NULL))
13559 ctxt->directory = directory; 14206 ctxt->directory = directory;
13560 14207
13561 return(ctxt); 14208 return(ctxt);
13562 } 14209 }
13563 14210
13564 /** 14211 /**
13565 * xmlCreateFileParserCtxt: 14212 * xmlCreateFileParserCtxt:
13566 * @filename: the filename 14213 * @filename: the filename
13567 * 14214 *
13568 * Create a parser context for a file content. 14215 * Create a parser context for a file content.
13569 * Automatic support for ZLIB/Compress compressed document is provided 14216 * Automatic support for ZLIB/Compress compressed document is provided
13570 * by default if found at compile-time. 14217 * by default if found at compile-time.
13571 * 14218 *
13572 * Returns the new parser context or NULL 14219 * Returns the new parser context or NULL
13573 */ 14220 */
13574 xmlParserCtxtPtr 14221 xmlParserCtxtPtr
13575 xmlCreateFileParserCtxt(const char *filename) 14222 xmlCreateFileParserCtxt(const char *filename)
13576 { 14223 {
13577 return(xmlCreateURLParserCtxt(filename, 0)); 14224 return(xmlCreateURLParserCtxt(filename, 0));
13578 } 14225 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
13636 } 14283 }
13637 } 14284 }
13638 else { 14285 else {
13639 ret = NULL; 14286 ret = NULL;
13640 xmlFreeDoc(ctxt->myDoc); 14287 xmlFreeDoc(ctxt->myDoc);
13641 ctxt->myDoc = NULL; 14288 ctxt->myDoc = NULL;
13642 } 14289 }
13643 if (sax != NULL) 14290 if (sax != NULL)
13644 ctxt->sax = NULL; 14291 ctxt->sax = NULL;
13645 xmlFreeParserCtxt(ctxt); 14292 xmlFreeParserCtxt(ctxt);
13646 14293
13647 return(ret); 14294 return(ret);
13648 } 14295 }
13649 14296
13650 /** 14297 /**
13651 * xmlSAXParseFile: 14298 * xmlSAXParseFile:
13652 * @sax: the SAX handler block 14299 * @sax: the SAX handler block
13653 * @filename: the filename 14300 * @filename: the filename
13654 * @recovery: work in recovery mode, i.e. tries to read no Well Formed 14301 * @recovery: work in recovery mode, i.e. tries to read no Well Formed
13655 * documents 14302 * documents
13656 * 14303 *
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
13736 14383
13737 if ((ctxt == NULL) || (buffer == NULL)) 14384 if ((ctxt == NULL) || (buffer == NULL))
13738 return; 14385 return;
13739 14386
13740 input = xmlNewInputStream(ctxt); 14387 input = xmlNewInputStream(ctxt);
13741 if (input == NULL) { 14388 if (input == NULL) {
13742 xmlErrMemory(NULL, "parsing new buffer: out of memory\n"); 14389 xmlErrMemory(NULL, "parsing new buffer: out of memory\n");
13743 xmlClearParserCtxt(ctxt); 14390 xmlClearParserCtxt(ctxt);
13744 return; 14391 return;
13745 } 14392 }
13746 14393
13747 xmlClearParserCtxt(ctxt); 14394 xmlClearParserCtxt(ctxt);
13748 if (filename != NULL) 14395 if (filename != NULL)
13749 input->filename = (char *) xmlCanonicPath((const xmlChar *)filename); 14396 input->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
13750 input->base = buffer; 14397 input->base = buffer;
13751 input->cur = buffer; 14398 input->cur = buffer;
13752 input->end = &buffer[xmlStrlen(buffer)]; 14399 input->end = &buffer[xmlStrlen(buffer)];
13753 inputPush(ctxt, input); 14400 inputPush(ctxt, input);
13754 } 14401 }
13755 14402
13756 /** 14403 /**
13757 * xmlSAXUserParseFile: 14404 * xmlSAXUserParseFile:
13758 * @sax: a SAX handler 14405 * @sax: a SAX handler
13759 * @user_data: The user data returned on SAX callbacks 14406 * @user_data: The user data returned on SAX callbacks
13760 * @filename: a file name 14407 * @filename: a file name
13761 * 14408 *
13762 * parse an XML file and call the given SAX handler routines. 14409 * parse an XML file and call the given SAX handler routines.
13763 * Automatic support for ZLIB/Compress compressed document is provided 14410 * Automatic support for ZLIB/Compress compressed document is provided
13764 * 14411 *
13765 * Returns 0 in case of success or a error number otherwise 14412 * Returns 0 in case of success or a error number otherwise
13766 */ 14413 */
13767 int 14414 int
13768 xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, 14415 xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data,
13769 const char *filename) { 14416 const char *filename) {
13770 int ret = 0; 14417 int ret = 0;
13771 xmlParserCtxtPtr ctxt; 14418 xmlParserCtxtPtr ctxt;
13772 14419
13773 ctxt = xmlCreateFileParserCtxt(filename); 14420 ctxt = xmlCreateFileParserCtxt(filename);
13774 if (ctxt == NULL) return -1; 14421 if (ctxt == NULL) return -1;
13775 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 14422 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
13776 xmlFree(ctxt->sax); 14423 xmlFree(ctxt->sax);
13777 ctxt->sax = sax; 14424 ctxt->sax = sax;
13778 xmlDetectSAX2(ctxt); 14425 xmlDetectSAX2(ctxt);
13779 14426
13780 if (user_data != NULL) 14427 if (user_data != NULL)
13781 ctxt->userData = user_data; 14428 ctxt->userData = user_data;
13782 14429
13783 xmlParseDocument(ctxt); 14430 xmlParseDocument(ctxt);
13784 14431
13785 if (ctxt->wellFormed) 14432 if (ctxt->wellFormed)
13786 ret = 0; 14433 ret = 0;
13787 else { 14434 else {
13788 if (ctxt->errNo != 0) 14435 if (ctxt->errNo != 0)
13789 ret = ctxt->errNo; 14436 ret = ctxt->errNo;
13790 else 14437 else
13791 ret = -1; 14438 ret = -1;
13792 } 14439 }
13793 if (sax != NULL) 14440 if (sax != NULL)
13794 ctxt->sax = NULL; 14441 ctxt->sax = NULL;
13795 if (ctxt->myDoc != NULL) { 14442 if (ctxt->myDoc != NULL) {
13796 xmlFreeDoc(ctxt->myDoc); 14443 xmlFreeDoc(ctxt->myDoc);
13797 ctxt->myDoc = NULL; 14444 ctxt->myDoc = NULL;
13798 } 14445 }
13799 xmlFreeParserCtxt(ctxt); 14446 xmlFreeParserCtxt(ctxt);
13800 14447
13801 return ret; 14448 return ret;
13802 } 14449 }
13803 #endif /* LIBXML_SAX1_ENABLED */ 14450 #endif /* LIBXML_SAX1_ENABLED */
13804 14451
13805 /************************************************************************ 14452 /************************************************************************
13806 * * 14453 * *
13807 * » » Front ends when parsing from memory» » » * 14454 *» » Front ends when parsing from memory» » » *
13808 * * 14455 * *
13809 ************************************************************************/ 14456 ************************************************************************/
13810 14457
13811 /** 14458 /**
13812 * xmlCreateMemoryParserCtxt: 14459 * xmlCreateMemoryParserCtxt:
13813 * @buffer: a pointer to a char array 14460 * @buffer: a pointer to a char array
13814 * @size: the size of the array 14461 * @size: the size of the array
13815 * 14462 *
13816 * Create a parser context for an XML in-memory document. 14463 * Create a parser context for an XML in-memory document.
13817 * 14464 *
(...skipping 23 matching lines...) Expand all
13841 14488
13842 input = xmlNewInputStream(ctxt); 14489 input = xmlNewInputStream(ctxt);
13843 if (input == NULL) { 14490 if (input == NULL) {
13844 xmlFreeParserInputBuffer(buf); 14491 xmlFreeParserInputBuffer(buf);
13845 xmlFreeParserCtxt(ctxt); 14492 xmlFreeParserCtxt(ctxt);
13846 return(NULL); 14493 return(NULL);
13847 } 14494 }
13848 14495
13849 input->filename = NULL; 14496 input->filename = NULL;
13850 input->buf = buf; 14497 input->buf = buf;
13851 input->base = input->buf->buffer->content; 14498 xmlBufResetInput(input->buf->buffer, input);
13852 input->cur = input->buf->buffer->content;
13853 input->end = &input->buf->buffer->content[input->buf->buffer->use];
13854 14499
13855 inputPush(ctxt, input); 14500 inputPush(ctxt, input);
13856 return(ctxt); 14501 return(ctxt);
13857 } 14502 }
13858 14503
13859 #ifdef LIBXML_SAX1_ENABLED 14504 #ifdef LIBXML_SAX1_ENABLED
13860 /** 14505 /**
13861 * xmlSAXParseMemoryWithData: 14506 * xmlSAXParseMemoryWithData:
13862 * @sax: the SAX handler block 14507 * @sax: the SAX handler block
13863 * @buffer: an pointer to a char array 14508 * @buffer: an pointer to a char array
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
13899 ctxt->recovery = recovery; 14544 ctxt->recovery = recovery;
13900 14545
13901 xmlParseDocument(ctxt); 14546 xmlParseDocument(ctxt);
13902 14547
13903 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; 14548 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
13904 else { 14549 else {
13905 ret = NULL; 14550 ret = NULL;
13906 xmlFreeDoc(ctxt->myDoc); 14551 xmlFreeDoc(ctxt->myDoc);
13907 ctxt->myDoc = NULL; 14552 ctxt->myDoc = NULL;
13908 } 14553 }
13909 if (sax != NULL) 14554 if (sax != NULL)
13910 ctxt->sax = NULL; 14555 ctxt->sax = NULL;
13911 xmlFreeParserCtxt(ctxt); 14556 xmlFreeParserCtxt(ctxt);
13912 14557
13913 return(ret); 14558 return(ret);
13914 } 14559 }
13915 14560
13916 /** 14561 /**
13917 * xmlSAXParseMemory: 14562 * xmlSAXParseMemory:
13918 * @sax: the SAX handler block 14563 * @sax: the SAX handler block
13919 * @buffer: an pointer to a char array 14564 * @buffer: an pointer to a char array
13920 * @size: the size of the array 14565 * @size: the size of the array
13921 * @recovery: work in recovery mode, i.e. tries to read not Well Formed 14566 * @recovery: work in recovery mode, i.e. tries to read not Well Formed
13922 * documents 14567 * documents
13923 * 14568 *
13924 * parse an XML in-memory block and use the given SAX function block 14569 * 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 14570 * to handle the parsing callback. If sax is NULL, fallback to the default
13926 * DOM tree building routines. 14571 * DOM tree building routines.
13927 * 14572 *
13928 * Returns the resulting document tree 14573 * Returns the resulting document tree
13929 */ 14574 */
13930 xmlDocPtr 14575 xmlDocPtr
13931 xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, 14576 xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer,
13932 int size, int recovery) { 14577 int size, int recovery) {
13933 return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL); 14578 return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL);
13934 } 14579 }
13935 14580
13936 /** 14581 /**
13937 * xmlParseMemory: 14582 * xmlParseMemory:
13938 * @buffer: an pointer to a char array 14583 * @buffer: an pointer to a char array
13939 * @size: the size of the array 14584 * @size: the size of the array
13940 * 14585 *
13941 * parse an XML in-memory block and build a tree. 14586 * parse an XML in-memory block and build a tree.
13942 * 14587 *
13943 * Returns the resulting document tree 14588 * Returns the resulting document tree
13944 */ 14589 */
13945 14590
13946 xmlDocPtr xmlParseMemory(const char *buffer, int size) { 14591 xmlDocPtr xmlParseMemory(const char *buffer, int size) {
13947 return(xmlSAXParseMemory(NULL, buffer, size, 0)); 14592 return(xmlSAXParseMemory(NULL, buffer, size, 0));
13948 } 14593 }
13949 14594
13950 /** 14595 /**
13951 * xmlRecoverMemory: 14596 * xmlRecoverMemory:
13952 * @buffer: an pointer to a char array 14597 * @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; 14631 if (ctxt == NULL) return -1;
13987 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) 14632 if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
13988 xmlFree(ctxt->sax); 14633 xmlFree(ctxt->sax);
13989 ctxt->sax = sax; 14634 ctxt->sax = sax;
13990 xmlDetectSAX2(ctxt); 14635 xmlDetectSAX2(ctxt);
13991 14636
13992 if (user_data != NULL) 14637 if (user_data != NULL)
13993 ctxt->userData = user_data; 14638 ctxt->userData = user_data;
13994 14639
13995 xmlParseDocument(ctxt); 14640 xmlParseDocument(ctxt);
13996 14641
13997 if (ctxt->wellFormed) 14642 if (ctxt->wellFormed)
13998 ret = 0; 14643 ret = 0;
13999 else { 14644 else {
14000 if (ctxt->errNo != 0) 14645 if (ctxt->errNo != 0)
14001 ret = ctxt->errNo; 14646 ret = ctxt->errNo;
14002 else 14647 else
14003 ret = -1; 14648 ret = -1;
14004 } 14649 }
14005 if (sax != NULL) 14650 if (sax != NULL)
14006 ctxt->sax = NULL; 14651 ctxt->sax = NULL;
14007 if (ctxt->myDoc != NULL) { 14652 if (ctxt->myDoc != NULL) {
14008 xmlFreeDoc(ctxt->myDoc); 14653 xmlFreeDoc(ctxt->myDoc);
14009 ctxt->myDoc = NULL; 14654 ctxt->myDoc = NULL;
14010 } 14655 }
14011 xmlFreeParserCtxt(ctxt); 14656 xmlFreeParserCtxt(ctxt);
14012 14657
14013 return ret; 14658 return ret;
14014 } 14659 }
14015 #endif /* LIBXML_SAX1_ENABLED */ 14660 #endif /* LIBXML_SAX1_ENABLED */
14016 14661
14017 /** 14662 /**
14018 * xmlCreateDocParserCtxt: 14663 * xmlCreateDocParserCtxt:
14019 * @cur: a pointer to an array of xmlChar 14664 * @cur: a pointer to an array of xmlChar
14020 * 14665 *
14021 * Creates a parser context for an XML in-memory document. 14666 * Creates a parser context for an XML in-memory document.
14022 * 14667 *
(...skipping 13 matching lines...) Expand all
14036 /** 14681 /**
14037 * xmlSAXParseDoc: 14682 * xmlSAXParseDoc:
14038 * @sax: the SAX handler block 14683 * @sax: the SAX handler block
14039 * @cur: a pointer to an array of xmlChar 14684 * @cur: a pointer to an array of xmlChar
14040 * @recovery: work in recovery mode, i.e. tries to read no Well Formed 14685 * @recovery: work in recovery mode, i.e. tries to read no Well Formed
14041 * documents 14686 * documents
14042 * 14687 *
14043 * parse an XML in-memory document and build a tree. 14688 * parse an XML in-memory document and build a tree.
14044 * It use the given SAX function block to handle the parsing callback. 14689 * 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. 14690 * If sax is NULL, fallback to the default DOM tree building routines.
14046 * 14691 *
14047 * Returns the resulting document tree 14692 * Returns the resulting document tree
14048 */ 14693 */
14049 14694
14050 xmlDocPtr 14695 xmlDocPtr
14051 xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) { 14696 xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) {
14052 xmlDocPtr ret; 14697 xmlDocPtr ret;
14053 xmlParserCtxtPtr ctxt; 14698 xmlParserCtxtPtr ctxt;
14054 xmlSAXHandlerPtr oldsax = NULL; 14699 xmlSAXHandlerPtr oldsax = NULL;
14055 14700
14056 if (cur == NULL) return(NULL); 14701 if (cur == NULL) return(NULL);
14057 14702
14058 14703
14059 ctxt = xmlCreateDocParserCtxt(cur); 14704 ctxt = xmlCreateDocParserCtxt(cur);
14060 if (ctxt == NULL) return(NULL); 14705 if (ctxt == NULL) return(NULL);
14061 if (sax != NULL) { 14706 if (sax != NULL) {
14062 oldsax = ctxt->sax; 14707 oldsax = ctxt->sax;
14063 ctxt->sax = sax; 14708 ctxt->sax = sax;
14064 ctxt->userData = NULL; 14709 ctxt->userData = NULL;
14065 } 14710 }
14066 xmlDetectSAX2(ctxt); 14711 xmlDetectSAX2(ctxt);
14067 14712
14068 xmlParseDocument(ctxt); 14713 xmlParseDocument(ctxt);
14069 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; 14714 if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc;
14070 else { 14715 else {
14071 ret = NULL; 14716 ret = NULL;
14072 xmlFreeDoc(ctxt->myDoc); 14717 xmlFreeDoc(ctxt->myDoc);
14073 ctxt->myDoc = NULL; 14718 ctxt->myDoc = NULL;
14074 } 14719 }
14075 if (sax != NULL) 14720 if (sax != NULL)
14076 ctxt->sax = oldsax; 14721 ctxt->sax = oldsax;
14077 xmlFreeParserCtxt(ctxt); 14722 xmlFreeParserCtxt(ctxt);
14078 14723
14079 return(ret); 14724 return(ret);
14080 } 14725 }
14081 14726
14082 /** 14727 /**
14083 * xmlParseDoc: 14728 * xmlParseDoc:
14084 * @cur: a pointer to an array of xmlChar 14729 * @cur: a pointer to an array of xmlChar
14085 * 14730 *
14086 * parse an XML in-memory document and build a tree. 14731 * parse an XML in-memory document and build a tree.
14087 * 14732 *
14088 * Returns the resulting document tree 14733 * Returns the resulting document tree
14089 */ 14734 */
14090 14735
14091 xmlDocPtr 14736 xmlDocPtr
14092 xmlParseDoc(const xmlChar *cur) { 14737 xmlParseDoc(const xmlChar *cur) {
14093 return(xmlSAXParseDoc(NULL, cur, 0)); 14738 return(xmlSAXParseDoc(NULL, cur, 0));
14094 } 14739 }
14095 #endif /* LIBXML_SAX1_ENABLED */ 14740 #endif /* LIBXML_SAX1_ENABLED */
14096 14741
14097 #ifdef LIBXML_LEGACY_ENABLED 14742 #ifdef LIBXML_LEGACY_ENABLED
14098 /************************************************************************ 14743 /************************************************************************
14099 * * 14744 * *
14100 * » Specific function to keep track of entities references» » * 14745 *» Specific function to keep track of entities references» » *
14101 * » and used by the XSLT debugger» » » » » * 14746 *» and used by the XSLT debugger» » » » » *
14102 * * 14747 * *
14103 ************************************************************************/ 14748 ************************************************************************/
14104 14749
14105 static xmlEntityReferenceFunc xmlEntityRefFunc = NULL; 14750 static xmlEntityReferenceFunc xmlEntityRefFunc = NULL;
14106 14751
14107 /** 14752 /**
14108 * xmlAddEntityReference: 14753 * xmlAddEntityReference:
14109 * @ent : A valid entity 14754 * @ent : A valid entity
14110 * @firstNode : A valid first node for children of entity 14755 * @firstNode : A valid first node for children of entity
14111 * @lastNode : A valid last node of children entity 14756 * @lastNode : A valid last node of children entity
14112 * 14757 *
14113 * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY 14758 * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY
14114 */ 14759 */
14115 static void 14760 static void
14116 xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode, 14761 xmlAddEntityReference(xmlEntityPtr ent, xmlNodePtr firstNode,
14117 xmlNodePtr lastNode) 14762 xmlNodePtr lastNode)
14118 { 14763 {
14119 if (xmlEntityRefFunc != NULL) { 14764 if (xmlEntityRefFunc != NULL) {
14120 (*xmlEntityRefFunc) (ent, firstNode, lastNode); 14765 (*xmlEntityRefFunc) (ent, firstNode, lastNode);
14121 } 14766 }
14122 } 14767 }
14123 14768
14124 14769
14125 /** 14770 /**
14126 * xmlSetEntityReferenceFunc: 14771 * xmlSetEntityReferenceFunc:
14127 * @func: A valid function 14772 * @func: A valid function
14128 * 14773 *
14129 * Set the function to call call back when a xml reference has been made 14774 * Set the function to call call back when a xml reference has been made
14130 */ 14775 */
14131 void 14776 void
14132 xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) 14777 xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func)
14133 { 14778 {
14134 xmlEntityRefFunc = func; 14779 xmlEntityRefFunc = func;
14135 } 14780 }
14136 #endif /* LIBXML_LEGACY_ENABLED */ 14781 #endif /* LIBXML_LEGACY_ENABLED */
14137 14782
14138 /************************************************************************ 14783 /************************************************************************
14139 * * 14784 * *
14140 * » » » » Miscellaneous» » » » * 14785 *» » » » Miscellaneous» » » » *
14141 * * 14786 * *
14142 ************************************************************************/ 14787 ************************************************************************/
14143 14788
14144 #ifdef LIBXML_XPATH_ENABLED 14789 #ifdef LIBXML_XPATH_ENABLED
14145 #include <libxml/xpath.h> 14790 #include <libxml/xpath.h>
14146 #endif 14791 #endif
14147 14792
14148 extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...) ; 14793 extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...) ;
14149 static int xmlParserInitialized = 0; 14794 static int xmlParserInitialized = 0;
14150 14795
14151 /** 14796 /**
14152 * xmlInitParser: 14797 * xmlInitParser:
14153 * 14798 *
14154 * Initialization function for the XML parser. 14799 * Initialization function for the XML parser.
14155 * This is not reentrant. Call once before processing in case of 14800 * This is not reentrant. Call once before processing in case of
14156 * use in multithreaded programs. 14801 * use in multithreaded programs.
14157 */ 14802 */
14158 14803
14159 void 14804 void
14160 xmlInitParser(void) { 14805 xmlInitParser(void) {
14161 if (xmlParserInitialized != 0) 14806 if (xmlParserInitialized != 0)
14162 return; 14807 return;
14163 14808
14164 #ifdef LIBXML_THREAD_ENABLED 14809 #ifdef LIBXML_THREAD_ENABLED
14165 __xmlGlobalInitMutexLock(); 14810 __xmlGlobalInitMutexLock();
14166 if (xmlParserInitialized == 0) { 14811 if (xmlParserInitialized == 0) {
14167 #endif 14812 #endif
14813 xmlInitThreads();
14168 xmlInitGlobals(); 14814 xmlInitGlobals();
14169 xmlInitThreads();
14170 if ((xmlGenericError == xmlGenericErrorDefaultFunc) || 14815 if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
14171 (xmlGenericError == NULL)) 14816 (xmlGenericError == NULL))
14172 initGenericErrorDefaultFunc(NULL); 14817 initGenericErrorDefaultFunc(NULL);
14173 xmlInitMemory(); 14818 xmlInitMemory();
14819 xmlInitializeDict();
14174 xmlInitCharEncodingHandlers(); 14820 xmlInitCharEncodingHandlers();
14175 xmlDefaultSAXHandlerInit(); 14821 xmlDefaultSAXHandlerInit();
14176 xmlRegisterDefaultInputCallbacks(); 14822 xmlRegisterDefaultInputCallbacks();
14177 #ifdef LIBXML_OUTPUT_ENABLED 14823 #ifdef LIBXML_OUTPUT_ENABLED
14178 xmlRegisterDefaultOutputCallbacks(); 14824 xmlRegisterDefaultOutputCallbacks();
14179 #endif /* LIBXML_OUTPUT_ENABLED */ 14825 #endif /* LIBXML_OUTPUT_ENABLED */
14180 #ifdef LIBXML_HTML_ENABLED 14826 #ifdef LIBXML_HTML_ENABLED
14181 htmlInitAutoClose(); 14827 htmlInitAutoClose();
14182 htmlDefaultSAXHandlerInit(); 14828 htmlDefaultSAXHandlerInit();
14183 #endif 14829 #endif
14184 #ifdef LIBXML_XPATH_ENABLED 14830 #ifdef LIBXML_XPATH_ENABLED
14185 xmlXPathInit(); 14831 xmlXPathInit();
14186 #endif 14832 #endif
14833 #ifdef LIBXML_CATALOG_ENABLED
14834 xmlInitializeCatalog();
14835 #endif
14187 xmlParserInitialized = 1; 14836 xmlParserInitialized = 1;
14188 #ifdef LIBXML_THREAD_ENABLED 14837 #ifdef LIBXML_THREAD_ENABLED
14189 } 14838 }
14190 __xmlGlobalInitMutexUnlock(); 14839 __xmlGlobalInitMutexUnlock();
14191 #endif 14840 #endif
14192 } 14841 }
14193 14842
14194 /** 14843 /**
14195 * xmlCleanupParser: 14844 * xmlCleanupParser:
14196 * 14845 *
(...skipping 27 matching lines...) Expand all
14224 #endif 14873 #endif
14225 xmlDictCleanup(); 14874 xmlDictCleanup();
14226 xmlCleanupInputCallbacks(); 14875 xmlCleanupInputCallbacks();
14227 #ifdef LIBXML_OUTPUT_ENABLED 14876 #ifdef LIBXML_OUTPUT_ENABLED
14228 xmlCleanupOutputCallbacks(); 14877 xmlCleanupOutputCallbacks();
14229 #endif 14878 #endif
14230 #ifdef LIBXML_SCHEMAS_ENABLED 14879 #ifdef LIBXML_SCHEMAS_ENABLED
14231 xmlSchemaCleanupTypes(); 14880 xmlSchemaCleanupTypes();
14232 xmlRelaxNGCleanupTypes(); 14881 xmlRelaxNGCleanupTypes();
14233 #endif 14882 #endif
14883 xmlResetLastError();
14234 xmlCleanupGlobals(); 14884 xmlCleanupGlobals();
14235 xmlResetLastError();
14236 xmlCleanupThreads(); /* must be last if called not from the main thread */ 14885 xmlCleanupThreads(); /* must be last if called not from the main thread */
14237 xmlCleanupMemory(); 14886 xmlCleanupMemory();
14238 xmlParserInitialized = 0; 14887 xmlParserInitialized = 0;
14239 } 14888 }
14240 14889
14241 /************************************************************************ 14890 /************************************************************************
14242 * * 14891 * *
14243 * New set (2.6.0) of simpler and more flexible APIs * 14892 * New set (2.6.0) of simpler and more flexible APIs *
14244 * * 14893 * *
14245 ************************************************************************/ 14894 ************************************************************************/
14246 14895
14247 /** 14896 /**
14248 * DICT_FREE: 14897 * DICT_FREE:
14249 * @str: a string 14898 * @str: a string
14250 * 14899 *
14251 * Free a string if it is not owned by the "dict" dictionnary in the 14900 * Free a string if it is not owned by the "dict" dictionnary in the
14252 * current scope 14901 * current scope
14253 */ 14902 */
14254 #define DICT_FREE(str) \ 14903 #define DICT_FREE(str) \
14255 » if ((str) && ((!dict) || » » » » \ 14904 » if ((str) && ((!dict) ||» » » » \
14256 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ 14905 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
14257 xmlFree((char *)(str)); 14906 xmlFree((char *)(str));
14258 14907
14259 /** 14908 /**
14260 * xmlCtxtReset: 14909 * xmlCtxtReset:
14261 * @ctxt: an XML parser context 14910 * @ctxt: an XML parser context
14262 * 14911 *
14263 * Reset a parser context 14912 * Reset a parser context
14264 */ 14913 */
14265 void 14914 void
14266 xmlCtxtReset(xmlParserCtxtPtr ctxt) 14915 xmlCtxtReset(xmlParserCtxtPtr ctxt)
14267 { 14916 {
14268 xmlParserInputPtr input; 14917 xmlParserInputPtr input;
14269 xmlDictPtr dict; 14918 xmlDictPtr dict;
14270 14919
14271 if (ctxt == NULL) 14920 if (ctxt == NULL)
14272 return; 14921 return;
14273 14922
14274 dict = ctxt->dict; 14923 dict = ctxt->dict;
14275 14924
14276 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */ 14925 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
14277 xmlFreeInputStream(input); 14926 xmlFreeInputStream(input);
14278 } 14927 }
14279 ctxt->inputNr = 0; 14928 ctxt->inputNr = 0;
14280 ctxt->input = NULL; 14929 ctxt->input = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
14328 ctxt->record_info = 0; 14977 ctxt->record_info = 0;
14329 ctxt->nbChars = 0; 14978 ctxt->nbChars = 0;
14330 ctxt->checkIndex = 0; 14979 ctxt->checkIndex = 0;
14331 ctxt->inSubset = 0; 14980 ctxt->inSubset = 0;
14332 ctxt->errNo = XML_ERR_OK; 14981 ctxt->errNo = XML_ERR_OK;
14333 ctxt->depth = 0; 14982 ctxt->depth = 0;
14334 ctxt->charset = XML_CHAR_ENCODING_UTF8; 14983 ctxt->charset = XML_CHAR_ENCODING_UTF8;
14335 ctxt->catalogs = NULL; 14984 ctxt->catalogs = NULL;
14336 ctxt->nbentities = 0; 14985 ctxt->nbentities = 0;
14337 ctxt->sizeentities = 0; 14986 ctxt->sizeentities = 0;
14987 ctxt->sizeentcopy = 0;
14338 xmlInitNodeInfoSeq(&ctxt->node_seq); 14988 xmlInitNodeInfoSeq(&ctxt->node_seq);
14339 14989
14340 if (ctxt->attsDefault != NULL) { 14990 if (ctxt->attsDefault != NULL) {
14341 xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree); 14991 xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree);
14342 ctxt->attsDefault = NULL; 14992 ctxt->attsDefault = NULL;
14343 } 14993 }
14344 if (ctxt->attsSpecial != NULL) { 14994 if (ctxt->attsSpecial != NULL) {
14345 xmlHashFree(ctxt->attsSpecial, NULL); 14995 xmlHashFree(ctxt->attsSpecial, NULL);
14346 ctxt->attsSpecial = NULL; 14996 ctxt->attsSpecial = NULL;
14347 } 14997 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
14412 xmlFreeParserInputBuffer(buf); 15062 xmlFreeParserInputBuffer(buf);
14413 return(1); 15063 return(1);
14414 } 15064 }
14415 15065
14416 if (filename == NULL) 15066 if (filename == NULL)
14417 inputStream->filename = NULL; 15067 inputStream->filename = NULL;
14418 else 15068 else
14419 inputStream->filename = (char *) 15069 inputStream->filename = (char *)
14420 xmlCanonicPath((const xmlChar *) filename); 15070 xmlCanonicPath((const xmlChar *) filename);
14421 inputStream->buf = buf; 15071 inputStream->buf = buf;
14422 inputStream->base = inputStream->buf->buffer->content; 15072 xmlBufResetInput(buf->buffer, inputStream);
14423 inputStream->cur = inputStream->buf->buffer->content;
14424 inputStream->end =
14425 &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
14426 15073
14427 inputPush(ctxt, inputStream); 15074 inputPush(ctxt, inputStream);
14428 15075
14429 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && 15076 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
14430 (ctxt->input->buf != NULL)) { 15077 (ctxt->input->buf != NULL)) {
14431 int base = ctxt->input->base - ctxt->input->buf->buffer->content; 15078 » size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
14432 int cur = ctxt->input->cur - ctxt->input->base; 15079 size_t cur = ctxt->input->cur - ctxt->input->base;
14433 15080
14434 xmlParserInputBufferPush(ctxt->input->buf, size, chunk); 15081 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
14435 15082
14436 ctxt->input->base = ctxt->input->buf->buffer->content + base; 15083 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 15084 #ifdef DEBUG_PUSH
14442 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); 15085 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
14443 #endif 15086 #endif
14444 } 15087 }
14445 15088
14446 if (encoding != NULL) { 15089 if (encoding != NULL) {
14447 xmlCharEncodingHandlerPtr hdlr; 15090 xmlCharEncodingHandlerPtr hdlr;
14448 15091
14449 if (ctxt->encoding != NULL) 15092 if (ctxt->encoding != NULL)
14450 xmlFree((xmlChar *) ctxt->encoding); 15093 xmlFree((xmlChar *) ctxt->encoding);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
14581 ctxt->options |= XML_PARSE_OLD10; 15224 ctxt->options |= XML_PARSE_OLD10;
14582 options -= XML_PARSE_OLD10; 15225 options -= XML_PARSE_OLD10;
14583 } 15226 }
14584 if (options & XML_PARSE_NOBASEFIX) { 15227 if (options & XML_PARSE_NOBASEFIX) {
14585 ctxt->options |= XML_PARSE_NOBASEFIX; 15228 ctxt->options |= XML_PARSE_NOBASEFIX;
14586 options -= XML_PARSE_NOBASEFIX; 15229 options -= XML_PARSE_NOBASEFIX;
14587 } 15230 }
14588 if (options & XML_PARSE_HUGE) { 15231 if (options & XML_PARSE_HUGE) {
14589 ctxt->options |= XML_PARSE_HUGE; 15232 ctxt->options |= XML_PARSE_HUGE;
14590 options -= XML_PARSE_HUGE; 15233 options -= XML_PARSE_HUGE;
15234 if (ctxt->dict != NULL)
15235 xmlDictSetLimit(ctxt->dict, 0);
14591 } 15236 }
14592 if (options & XML_PARSE_OLDSAX) { 15237 if (options & XML_PARSE_OLDSAX) {
14593 ctxt->options |= XML_PARSE_OLDSAX; 15238 ctxt->options |= XML_PARSE_OLDSAX;
14594 options -= XML_PARSE_OLDSAX; 15239 options -= XML_PARSE_OLDSAX;
14595 } 15240 }
15241 if (options & XML_PARSE_IGNORE_ENC) {
15242 ctxt->options |= XML_PARSE_IGNORE_ENC;
15243 options -= XML_PARSE_IGNORE_ENC;
15244 }
15245 if (options & XML_PARSE_BIG_LINES) {
15246 ctxt->options |= XML_PARSE_BIG_LINES;
15247 options -= XML_PARSE_BIG_LINES;
15248 }
14596 ctxt->linenumbers = 1; 15249 ctxt->linenumbers = 1;
14597 return (options); 15250 return (options);
14598 } 15251 }
14599 15252
14600 /** 15253 /**
14601 * xmlCtxtUseOptions: 15254 * xmlCtxtUseOptions:
14602 * @ctxt: an XML parser context 15255 * @ctxt: an XML parser context
14603 * @options: a combination of xmlParserOption 15256 * @options: a combination of xmlParserOption
14604 * 15257 *
14605 * Applies the options to the parser context 15258 * Applies the options to the parser context
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
14660 } 15313 }
14661 15314
14662 /** 15315 /**
14663 * xmlReadDoc: 15316 * xmlReadDoc:
14664 * @cur: a pointer to a zero terminated string 15317 * @cur: a pointer to a zero terminated string
14665 * @URL: the base URL to use for the document 15318 * @URL: the base URL to use for the document
14666 * @encoding: the document encoding, or NULL 15319 * @encoding: the document encoding, or NULL
14667 * @options: a combination of xmlParserOption 15320 * @options: a combination of xmlParserOption
14668 * 15321 *
14669 * parse an XML in-memory document and build a tree. 15322 * parse an XML in-memory document and build a tree.
14670 * 15323 *
14671 * Returns the resulting document tree 15324 * Returns the resulting document tree
14672 */ 15325 */
14673 xmlDocPtr 15326 xmlDocPtr
14674 xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int optio ns) 15327 xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int optio ns)
14675 { 15328 {
14676 xmlParserCtxtPtr ctxt; 15329 xmlParserCtxtPtr ctxt;
14677 15330
14678 if (cur == NULL) 15331 if (cur == NULL)
14679 return (NULL); 15332 return (NULL);
15333 xmlInitParser();
14680 15334
14681 ctxt = xmlCreateDocParserCtxt(cur); 15335 ctxt = xmlCreateDocParserCtxt(cur);
14682 if (ctxt == NULL) 15336 if (ctxt == NULL)
14683 return (NULL); 15337 return (NULL);
14684 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15338 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14685 } 15339 }
14686 15340
14687 /** 15341 /**
14688 * xmlReadFile: 15342 * xmlReadFile:
14689 * @filename: a file or URL 15343 * @filename: a file or URL
14690 * @encoding: the document encoding, or NULL 15344 * @encoding: the document encoding, or NULL
14691 * @options: a combination of xmlParserOption 15345 * @options: a combination of xmlParserOption
14692 * 15346 *
14693 * parse an XML file from the filesystem or the network. 15347 * parse an XML file from the filesystem or the network.
14694 * 15348 *
14695 * Returns the resulting document tree 15349 * Returns the resulting document tree
14696 */ 15350 */
14697 xmlDocPtr 15351 xmlDocPtr
14698 xmlReadFile(const char *filename, const char *encoding, int options) 15352 xmlReadFile(const char *filename, const char *encoding, int options)
14699 { 15353 {
14700 xmlParserCtxtPtr ctxt; 15354 xmlParserCtxtPtr ctxt;
14701 15355
15356 xmlInitParser();
14702 ctxt = xmlCreateURLParserCtxt(filename, options); 15357 ctxt = xmlCreateURLParserCtxt(filename, options);
14703 if (ctxt == NULL) 15358 if (ctxt == NULL)
14704 return (NULL); 15359 return (NULL);
14705 return (xmlDoRead(ctxt, NULL, encoding, options, 0)); 15360 return (xmlDoRead(ctxt, NULL, encoding, options, 0));
14706 } 15361 }
14707 15362
14708 /** 15363 /**
14709 * xmlReadMemory: 15364 * xmlReadMemory:
14710 * @buffer: a pointer to a char array 15365 * @buffer: a pointer to a char array
14711 * @size: the size of the array 15366 * @size: the size of the array
14712 * @URL: the base URL to use for the document 15367 * @URL: the base URL to use for the document
14713 * @encoding: the document encoding, or NULL 15368 * @encoding: the document encoding, or NULL
14714 * @options: a combination of xmlParserOption 15369 * @options: a combination of xmlParserOption
14715 * 15370 *
14716 * parse an XML in-memory document and build a tree. 15371 * parse an XML in-memory document and build a tree.
14717 * 15372 *
14718 * Returns the resulting document tree 15373 * Returns the resulting document tree
14719 */ 15374 */
14720 xmlDocPtr 15375 xmlDocPtr
14721 xmlReadMemory(const char *buffer, int size, const char *URL, const char *encodin g, int options) 15376 xmlReadMemory(const char *buffer, int size, const char *URL, const char *encodin g, int options)
14722 { 15377 {
14723 xmlParserCtxtPtr ctxt; 15378 xmlParserCtxtPtr ctxt;
14724 15379
15380 xmlInitParser();
14725 ctxt = xmlCreateMemoryParserCtxt(buffer, size); 15381 ctxt = xmlCreateMemoryParserCtxt(buffer, size);
14726 if (ctxt == NULL) 15382 if (ctxt == NULL)
14727 return (NULL); 15383 return (NULL);
14728 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15384 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14729 } 15385 }
14730 15386
14731 /** 15387 /**
14732 * xmlReadFd: 15388 * xmlReadFd:
14733 * @fd: an open file descriptor 15389 * @fd: an open file descriptor
14734 * @URL: the base URL to use for the document 15390 * @URL: the base URL to use for the document
14735 * @encoding: the document encoding, or NULL 15391 * @encoding: the document encoding, or NULL
14736 * @options: a combination of xmlParserOption 15392 * @options: a combination of xmlParserOption
14737 * 15393 *
14738 * parse an XML from a file descriptor and build a tree. 15394 * parse an XML from a file descriptor and build a tree.
14739 * NOTE that the file descriptor will not be closed when the 15395 * NOTE that the file descriptor will not be closed when the
14740 * reader is closed or reset. 15396 * reader is closed or reset.
14741 * 15397 *
14742 * Returns the resulting document tree 15398 * Returns the resulting document tree
14743 */ 15399 */
14744 xmlDocPtr 15400 xmlDocPtr
14745 xmlReadFd(int fd, const char *URL, const char *encoding, int options) 15401 xmlReadFd(int fd, const char *URL, const char *encoding, int options)
14746 { 15402 {
14747 xmlParserCtxtPtr ctxt; 15403 xmlParserCtxtPtr ctxt;
14748 xmlParserInputBufferPtr input; 15404 xmlParserInputBufferPtr input;
14749 xmlParserInputPtr stream; 15405 xmlParserInputPtr stream;
14750 15406
14751 if (fd < 0) 15407 if (fd < 0)
14752 return (NULL); 15408 return (NULL);
15409 xmlInitParser();
14753 15410
14754 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); 15411 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
14755 if (input == NULL) 15412 if (input == NULL)
14756 return (NULL); 15413 return (NULL);
14757 input->closecallback = NULL; 15414 input->closecallback = NULL;
14758 ctxt = xmlNewParserCtxt(); 15415 ctxt = xmlNewParserCtxt();
14759 if (ctxt == NULL) { 15416 if (ctxt == NULL) {
14760 xmlFreeParserInputBuffer(input); 15417 xmlFreeParserInputBuffer(input);
14761 return (NULL); 15418 return (NULL);
14762 } 15419 }
(...skipping 10 matching lines...) Expand all
14773 /** 15430 /**
14774 * xmlReadIO: 15431 * xmlReadIO:
14775 * @ioread: an I/O read function 15432 * @ioread: an I/O read function
14776 * @ioclose: an I/O close function 15433 * @ioclose: an I/O close function
14777 * @ioctx: an I/O handler 15434 * @ioctx: an I/O handler
14778 * @URL: the base URL to use for the document 15435 * @URL: the base URL to use for the document
14779 * @encoding: the document encoding, or NULL 15436 * @encoding: the document encoding, or NULL
14780 * @options: a combination of xmlParserOption 15437 * @options: a combination of xmlParserOption
14781 * 15438 *
14782 * parse an XML document from I/O functions and source and build a tree. 15439 * parse an XML document from I/O functions and source and build a tree.
14783 * 15440 *
14784 * Returns the resulting document tree 15441 * Returns the resulting document tree
14785 */ 15442 */
14786 xmlDocPtr 15443 xmlDocPtr
14787 xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, 15444 xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
14788 void *ioctx, const char *URL, const char *encoding, int options) 15445 void *ioctx, const char *URL, const char *encoding, int options)
14789 { 15446 {
14790 xmlParserCtxtPtr ctxt; 15447 xmlParserCtxtPtr ctxt;
14791 xmlParserInputBufferPtr input; 15448 xmlParserInputBufferPtr input;
14792 xmlParserInputPtr stream; 15449 xmlParserInputPtr stream;
14793 15450
14794 if (ioread == NULL) 15451 if (ioread == NULL)
14795 return (NULL); 15452 return (NULL);
15453 xmlInitParser();
14796 15454
14797 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 15455 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
14798 XML_CHAR_ENCODING_NONE); 15456 XML_CHAR_ENCODING_NONE);
14799 if (input == NULL) 15457 if (input == NULL) {
15458 if (ioclose != NULL)
15459 ioclose(ioctx);
14800 return (NULL); 15460 return (NULL);
15461 }
14801 ctxt = xmlNewParserCtxt(); 15462 ctxt = xmlNewParserCtxt();
14802 if (ctxt == NULL) { 15463 if (ctxt == NULL) {
14803 xmlFreeParserInputBuffer(input); 15464 xmlFreeParserInputBuffer(input);
14804 return (NULL); 15465 return (NULL);
14805 } 15466 }
14806 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15467 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14807 if (stream == NULL) { 15468 if (stream == NULL) {
14808 xmlFreeParserInputBuffer(input); 15469 xmlFreeParserInputBuffer(input);
14809 xmlFreeParserCtxt(ctxt); 15470 xmlFreeParserCtxt(ctxt);
14810 return (NULL); 15471 return (NULL);
14811 } 15472 }
14812 inputPush(ctxt, stream); 15473 inputPush(ctxt, stream);
14813 return (xmlDoRead(ctxt, URL, encoding, options, 0)); 15474 return (xmlDoRead(ctxt, URL, encoding, options, 0));
14814 } 15475 }
14815 15476
14816 /** 15477 /**
14817 * xmlCtxtReadDoc: 15478 * xmlCtxtReadDoc:
14818 * @ctxt: an XML parser context 15479 * @ctxt: an XML parser context
14819 * @cur: a pointer to a zero terminated string 15480 * @cur: a pointer to a zero terminated string
14820 * @URL: the base URL to use for the document 15481 * @URL: the base URL to use for the document
14821 * @encoding: the document encoding, or NULL 15482 * @encoding: the document encoding, or NULL
14822 * @options: a combination of xmlParserOption 15483 * @options: a combination of xmlParserOption
14823 * 15484 *
14824 * parse an XML in-memory document and build a tree. 15485 * parse an XML in-memory document and build a tree.
14825 * This reuses the existing @ctxt parser context 15486 * This reuses the existing @ctxt parser context
14826 * 15487 *
14827 * Returns the resulting document tree 15488 * Returns the resulting document tree
14828 */ 15489 */
14829 xmlDocPtr 15490 xmlDocPtr
14830 xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur, 15491 xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
14831 const char *URL, const char *encoding, int options) 15492 const char *URL, const char *encoding, int options)
14832 { 15493 {
14833 xmlParserInputPtr stream; 15494 xmlParserInputPtr stream;
14834 15495
14835 if (cur == NULL) 15496 if (cur == NULL)
14836 return (NULL); 15497 return (NULL);
14837 if (ctxt == NULL) 15498 if (ctxt == NULL)
14838 return (NULL); 15499 return (NULL);
15500 xmlInitParser();
14839 15501
14840 xmlCtxtReset(ctxt); 15502 xmlCtxtReset(ctxt);
14841 15503
14842 stream = xmlNewStringInputStream(ctxt, cur); 15504 stream = xmlNewStringInputStream(ctxt, cur);
14843 if (stream == NULL) { 15505 if (stream == NULL) {
14844 return (NULL); 15506 return (NULL);
14845 } 15507 }
14846 inputPush(ctxt, stream); 15508 inputPush(ctxt, stream);
14847 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15509 return (xmlDoRead(ctxt, URL, encoding, options, 1));
14848 } 15510 }
14849 15511
14850 /** 15512 /**
14851 * xmlCtxtReadFile: 15513 * xmlCtxtReadFile:
14852 * @ctxt: an XML parser context 15514 * @ctxt: an XML parser context
14853 * @filename: a file or URL 15515 * @filename: a file or URL
14854 * @encoding: the document encoding, or NULL 15516 * @encoding: the document encoding, or NULL
14855 * @options: a combination of xmlParserOption 15517 * @options: a combination of xmlParserOption
14856 * 15518 *
14857 * parse an XML file from the filesystem or the network. 15519 * parse an XML file from the filesystem or the network.
14858 * This reuses the existing @ctxt parser context 15520 * This reuses the existing @ctxt parser context
14859 * 15521 *
14860 * Returns the resulting document tree 15522 * Returns the resulting document tree
14861 */ 15523 */
14862 xmlDocPtr 15524 xmlDocPtr
14863 xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename, 15525 xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename,
14864 const char *encoding, int options) 15526 const char *encoding, int options)
14865 { 15527 {
14866 xmlParserInputPtr stream; 15528 xmlParserInputPtr stream;
14867 15529
14868 if (filename == NULL) 15530 if (filename == NULL)
14869 return (NULL); 15531 return (NULL);
14870 if (ctxt == NULL) 15532 if (ctxt == NULL)
14871 return (NULL); 15533 return (NULL);
15534 xmlInitParser();
14872 15535
14873 xmlCtxtReset(ctxt); 15536 xmlCtxtReset(ctxt);
14874 15537
14875 stream = xmlLoadExternalEntity(filename, NULL, ctxt); 15538 stream = xmlLoadExternalEntity(filename, NULL, ctxt);
14876 if (stream == NULL) { 15539 if (stream == NULL) {
14877 return (NULL); 15540 return (NULL);
14878 } 15541 }
14879 inputPush(ctxt, stream); 15542 inputPush(ctxt, stream);
14880 return (xmlDoRead(ctxt, NULL, encoding, options, 1)); 15543 return (xmlDoRead(ctxt, NULL, encoding, options, 1));
14881 } 15544 }
14882 15545
14883 /** 15546 /**
14884 * xmlCtxtReadMemory: 15547 * xmlCtxtReadMemory:
14885 * @ctxt: an XML parser context 15548 * @ctxt: an XML parser context
14886 * @buffer: a pointer to a char array 15549 * @buffer: a pointer to a char array
14887 * @size: the size of the array 15550 * @size: the size of the array
14888 * @URL: the base URL to use for the document 15551 * @URL: the base URL to use for the document
14889 * @encoding: the document encoding, or NULL 15552 * @encoding: the document encoding, or NULL
14890 * @options: a combination of xmlParserOption 15553 * @options: a combination of xmlParserOption
14891 * 15554 *
14892 * parse an XML in-memory document and build a tree. 15555 * parse an XML in-memory document and build a tree.
14893 * This reuses the existing @ctxt parser context 15556 * This reuses the existing @ctxt parser context
14894 * 15557 *
14895 * Returns the resulting document tree 15558 * Returns the resulting document tree
14896 */ 15559 */
14897 xmlDocPtr 15560 xmlDocPtr
14898 xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size, 15561 xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size,
14899 const char *URL, const char *encoding, int options) 15562 const char *URL, const char *encoding, int options)
14900 { 15563 {
14901 xmlParserInputBufferPtr input; 15564 xmlParserInputBufferPtr input;
14902 xmlParserInputPtr stream; 15565 xmlParserInputPtr stream;
14903 15566
14904 if (ctxt == NULL) 15567 if (ctxt == NULL)
14905 return (NULL); 15568 return (NULL);
14906 if (buffer == NULL) 15569 if (buffer == NULL)
14907 return (NULL); 15570 return (NULL);
15571 xmlInitParser();
14908 15572
14909 xmlCtxtReset(ctxt); 15573 xmlCtxtReset(ctxt);
14910 15574
14911 input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE); 15575 input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE);
14912 if (input == NULL) { 15576 if (input == NULL) {
14913 return(NULL); 15577 return(NULL);
14914 } 15578 }
14915 15579
14916 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15580 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14917 if (stream == NULL) { 15581 if (stream == NULL) {
(...skipping 10 matching lines...) Expand all
14928 * @ctxt: an XML parser context 15592 * @ctxt: an XML parser context
14929 * @fd: an open file descriptor 15593 * @fd: an open file descriptor
14930 * @URL: the base URL to use for the document 15594 * @URL: the base URL to use for the document
14931 * @encoding: the document encoding, or NULL 15595 * @encoding: the document encoding, or NULL
14932 * @options: a combination of xmlParserOption 15596 * @options: a combination of xmlParserOption
14933 * 15597 *
14934 * parse an XML from a file descriptor and build a tree. 15598 * parse an XML from a file descriptor and build a tree.
14935 * This reuses the existing @ctxt parser context 15599 * This reuses the existing @ctxt parser context
14936 * NOTE that the file descriptor will not be closed when the 15600 * NOTE that the file descriptor will not be closed when the
14937 * reader is closed or reset. 15601 * reader is closed or reset.
14938 * 15602 *
14939 * Returns the resulting document tree 15603 * Returns the resulting document tree
14940 */ 15604 */
14941 xmlDocPtr 15605 xmlDocPtr
14942 xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd, 15606 xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
14943 const char *URL, const char *encoding, int options) 15607 const char *URL, const char *encoding, int options)
14944 { 15608 {
14945 xmlParserInputBufferPtr input; 15609 xmlParserInputBufferPtr input;
14946 xmlParserInputPtr stream; 15610 xmlParserInputPtr stream;
14947 15611
14948 if (fd < 0) 15612 if (fd < 0)
14949 return (NULL); 15613 return (NULL);
14950 if (ctxt == NULL) 15614 if (ctxt == NULL)
14951 return (NULL); 15615 return (NULL);
15616 xmlInitParser();
14952 15617
14953 xmlCtxtReset(ctxt); 15618 xmlCtxtReset(ctxt);
14954 15619
14955 15620
14956 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); 15621 input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
14957 if (input == NULL) 15622 if (input == NULL)
14958 return (NULL); 15623 return (NULL);
14959 input->closecallback = NULL; 15624 input->closecallback = NULL;
14960 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15625 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
14961 if (stream == NULL) { 15626 if (stream == NULL) {
14962 xmlFreeParserInputBuffer(input); 15627 xmlFreeParserInputBuffer(input);
14963 return (NULL); 15628 return (NULL);
14964 } 15629 }
14965 inputPush(ctxt, stream); 15630 inputPush(ctxt, stream);
14966 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15631 return (xmlDoRead(ctxt, URL, encoding, options, 1));
14967 } 15632 }
14968 15633
14969 /** 15634 /**
14970 * xmlCtxtReadIO: 15635 * xmlCtxtReadIO:
14971 * @ctxt: an XML parser context 15636 * @ctxt: an XML parser context
14972 * @ioread: an I/O read function 15637 * @ioread: an I/O read function
14973 * @ioclose: an I/O close function 15638 * @ioclose: an I/O close function
14974 * @ioctx: an I/O handler 15639 * @ioctx: an I/O handler
14975 * @URL: the base URL to use for the document 15640 * @URL: the base URL to use for the document
14976 * @encoding: the document encoding, or NULL 15641 * @encoding: the document encoding, or NULL
14977 * @options: a combination of xmlParserOption 15642 * @options: a combination of xmlParserOption
14978 * 15643 *
14979 * parse an XML document from I/O functions and source and build a tree. 15644 * parse an XML document from I/O functions and source and build a tree.
14980 * This reuses the existing @ctxt parser context 15645 * This reuses the existing @ctxt parser context
14981 * 15646 *
14982 * Returns the resulting document tree 15647 * Returns the resulting document tree
14983 */ 15648 */
14984 xmlDocPtr 15649 xmlDocPtr
14985 xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread, 15650 xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
14986 xmlInputCloseCallback ioclose, void *ioctx, 15651 xmlInputCloseCallback ioclose, void *ioctx,
14987 const char *URL, 15652 const char *URL,
14988 const char *encoding, int options) 15653 const char *encoding, int options)
14989 { 15654 {
14990 xmlParserInputBufferPtr input; 15655 xmlParserInputBufferPtr input;
14991 xmlParserInputPtr stream; 15656 xmlParserInputPtr stream;
14992 15657
14993 if (ioread == NULL) 15658 if (ioread == NULL)
14994 return (NULL); 15659 return (NULL);
14995 if (ctxt == NULL) 15660 if (ctxt == NULL)
14996 return (NULL); 15661 return (NULL);
15662 xmlInitParser();
14997 15663
14998 xmlCtxtReset(ctxt); 15664 xmlCtxtReset(ctxt);
14999 15665
15000 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 15666 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
15001 XML_CHAR_ENCODING_NONE); 15667 XML_CHAR_ENCODING_NONE);
15002 if (input == NULL) 15668 if (input == NULL) {
15669 if (ioclose != NULL)
15670 ioclose(ioctx);
15003 return (NULL); 15671 return (NULL);
15672 }
15004 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); 15673 stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
15005 if (stream == NULL) { 15674 if (stream == NULL) {
15006 xmlFreeParserInputBuffer(input); 15675 xmlFreeParserInputBuffer(input);
15007 return (NULL); 15676 return (NULL);
15008 } 15677 }
15009 inputPush(ctxt, stream); 15678 inputPush(ctxt, stream);
15010 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15679 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15011 } 15680 }
15012 15681
15013 #define bottom_parser 15682 #define bottom_parser
15014 #include "elfgcchack.h" 15683 #include "elfgcchack.h"
OLDNEW
« no previous file with comments | « third_party/libxml/src/nanohttp.c ('k') | third_party/libxml/src/parserInternals.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698