diff options
Diffstat (limited to 'chromium/third_party/libxml/src/parser.c')
-rw-r--r-- | chromium/third_party/libxml/src/parser.c | 655 |
1 files changed, 346 insertions, 309 deletions
diff --git a/chromium/third_party/libxml/src/parser.c b/chromium/third_party/libxml/src/parser.c index 441946b6fb7..cb473fe122b 100644 --- a/chromium/third_party/libxml/src/parser.c +++ b/chromium/third_party/libxml/src/parser.c @@ -57,6 +57,7 @@ #include <libxml/tree.h> #include <libxml/parser.h> #include <libxml/parserInternals.h> +#include <libxml/HTMLparser.h> #include <libxml/valid.h> #include <libxml/entities.h> #include <libxml/xmlerror.h> @@ -70,18 +71,17 @@ #include <libxml/xmlschemastypes.h> #include <libxml/relaxng.h> #endif -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> +#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) +#include <libxml/xpath.h> #endif -#include "buf.h" -#include "enc.h" +#include "private/buf.h" +#include "private/enc.h" +#include "private/error.h" +#include "private/html.h" +#include "private/io.h" +#include "private/parser.h" +#include "private/threads.h" struct _xmlStartTag { const xmlChar *prefix; @@ -94,8 +94,9 @@ static void xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info); static xmlParserCtxtPtr -xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, - const xmlChar *base, xmlParserCtxtPtr pctx); +xmlCreateEntityParserCtxtInternal(xmlSAXHandlerPtr sax, void *userData, + const xmlChar *URL, const xmlChar *ID, const xmlChar *base, + xmlParserCtxtPtr pctx); static void xmlHaltParser(xmlParserCtxtPtr ctxt); @@ -111,6 +112,8 @@ xmlParseElementEnd(xmlParserCtxtPtr ctxt); * * ************************************************************************/ +#define XML_MAX_HUGE_LENGTH 1000000000 + #define XML_PARSER_BIG_ENTITY 1000 #define XML_PARSER_LOT_ENTITY 5000 @@ -305,7 +308,7 @@ unsigned int xmlParserMaxDepth = 256; * List of XML prefixed PI allowed by W3C specs */ -static const char *xmlW3CPIs[] = { +static const char* const xmlW3CPIs[] = { "xml-stylesheet", "xml-model", NULL @@ -568,7 +571,7 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info) errmsg = "Malformed declaration expecting version"; break; case XML_ERR_NAME_TOO_LONG: - errmsg = "Name too long use XML_PARSE_HUGE option"; + errmsg = "Name too long"; break; #if 0 case: @@ -1063,11 +1066,7 @@ xmlHasFeature(xmlFeature feature) return(0); #endif case XML_WITH_DEBUG_RUN: -#ifdef LIBXML_DEBUG_RUNTIME - return(1); -#else return(0); -#endif case XML_WITH_ZLIB: #ifdef LIBXML_ZLIB_ENABLED return(1); @@ -1233,7 +1232,7 @@ xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, xmlChar *src, int *len) return(NULL); } xmlAttrNormalizeSpace(ret, ret); - *len = (int) strlen((const char *)ret); + *len = strlen((const char *)ret); return(ret); } else if (remove_head) { *len -= remove_head; @@ -1768,9 +1767,7 @@ inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value) sizeof(ctxt->inputTab[0])); if (ctxt->inputTab == NULL) { xmlErrMemory(ctxt, NULL); - xmlFreeInputStream(value); ctxt->inputMax /= 2; - value = NULL; return (-1); } } @@ -2180,9 +2177,12 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) { #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l) #define COPY_BUF(l,b,i,v) \ - if (l == 1) b[i++] = (xmlChar) v; \ + if (l == 1) b[i++] = v; \ else i += xmlCopyCharMultiByte(&b[i],v) +#define CUR_CONSUMED \ + (ctxt->input->consumed + (ctxt->input->cur - ctxt->input->base)) + /** * xmlSkipBlankChars: * @ctxt: the XML parser context @@ -2215,7 +2215,8 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) { ctxt->input->col++; } cur++; - res++; + if (res < INT_MAX) + res++; if (*cur == 0) { ctxt->input->cur = cur; xmlParserInputGrow(ctxt->input, INPUT_CHUNK); @@ -2251,7 +2252,8 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) { * by the attachment of one leading and one following space (#x20) * character." */ - res++; + if (res < INT_MAX) + res++; } } return(res); @@ -2328,6 +2330,8 @@ xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { * xmlParseCharRef: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse Reference declarations * * [66] CharRef ::= '&#' [0-9]+ ';' | @@ -2991,7 +2995,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { */ max = len * 2; - buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); + buffer = (xmlChar *) xmlMallocAtomic(max); if (buffer == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -3002,8 +3006,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { xmlChar *tmp; max *= 2; - tmp = (xmlChar *) xmlRealloc(buffer, - max * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buffer, max); if (tmp == NULL) { xmlFree(buffer); xmlErrMemory(ctxt, NULL); @@ -3070,7 +3073,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { */ max = len * 2; - buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); + buffer = (xmlChar *) xmlMallocAtomic(max); if (buffer == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -3081,8 +3084,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { xmlChar *tmp; max *= 2; - tmp = (xmlChar *) xmlRealloc(buffer, - max * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buffer, max); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); xmlFree(buffer); @@ -3215,6 +3217,9 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) { int len = 0, l; int c; int count = 0; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; #ifdef DEBUG nbParseNameComplex++; @@ -3280,7 +3285,8 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) { if (ctxt->instate == XML_PARSER_EOF) return(NULL); } - len += l; + if (len <= INT_MAX - l) + len += l; NEXTL(l); c = CUR_CHAR(l); } @@ -3306,13 +3312,13 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) { if (ctxt->instate == XML_PARSER_EOF) return(NULL); } - len += l; + if (len <= INT_MAX - l) + len += l; NEXTL(l); c = CUR_CHAR(l); } } - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (len > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name"); return(NULL); } @@ -3335,6 +3341,8 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) { * xmlParseName: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML name. * * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | @@ -3351,7 +3359,10 @@ const xmlChar * xmlParseName(xmlParserCtxtPtr ctxt) { const xmlChar *in; const xmlChar *ret; - int count = 0; + size_t count = 0; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; GROW; @@ -3375,8 +3386,7 @@ xmlParseName(xmlParserCtxtPtr ctxt) { in++; if ((*in > 0) && (*in < 0x80)) { count = in - ctxt->input->cur; - if ((count > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (count > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name"); return(NULL); } @@ -3397,6 +3407,9 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { int len = 0, l; int c; int count = 0; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; size_t startPosition = 0; #ifdef DEBUG @@ -3417,17 +3430,13 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */ (xmlIsNameChar(ctxt, c) && (c != ':'))) { if (count++ > XML_PARSER_CHUNK_SIZE) { - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); - return(NULL); - } count = 0; GROW; if (ctxt->instate == XML_PARSER_EOF) return(NULL); } - len += l; + if (len <= INT_MAX - l) + len += l; NEXTL(l); c = CUR_CHAR(l); if (c == 0) { @@ -3445,8 +3454,7 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { c = CUR_CHAR(l); } } - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (len > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); return(NULL); } @@ -3472,7 +3480,10 @@ static const xmlChar * xmlParseNCName(xmlParserCtxtPtr ctxt) { const xmlChar *in, *e; const xmlChar *ret; - int count = 0; + size_t count = 0; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; #ifdef DEBUG nbParseNCName++; @@ -3497,8 +3508,7 @@ xmlParseNCName(xmlParserCtxtPtr ctxt) { goto complex; if ((*in > 0) && (*in < 0x80)) { count = in - ctxt->input->cur; - if ((count > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (count > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); return(NULL); } @@ -3580,6 +3590,9 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { const xmlChar *cur = *str; int len = 0, l; int c; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; #ifdef DEBUG nbParseStringName++; @@ -3605,7 +3618,7 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { xmlChar *buffer; int max = len * 2; - buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); + buffer = (xmlChar *) xmlMallocAtomic(max); if (buffer == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -3615,15 +3628,8 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { if (len + 10 > max) { xmlChar *tmp; - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); - xmlFree(buffer); - return(NULL); - } max *= 2; - tmp = (xmlChar *) xmlRealloc(buffer, - max * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buffer, max); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); xmlFree(buffer); @@ -3634,14 +3640,18 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { COPY_BUF(l,buffer,len,c); cur += l; c = CUR_SCHAR(cur, l); + if (len > maxLength) { + xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); + xmlFree(buffer); + return(NULL); + } } buffer[len] = 0; *str = cur; return(buffer); } } - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (len > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName"); return(NULL); } @@ -3653,6 +3663,8 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { * xmlParseNmtoken: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML Nmtoken. * * [7] Nmtoken ::= (NameChar)+ @@ -3668,6 +3680,9 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { int len = 0, l; int c; int count = 0; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; #ifdef DEBUG nbParseNmToken++; @@ -3701,7 +3716,7 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { xmlChar *buffer; int max = len * 2; - buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); + buffer = (xmlChar *) xmlMallocAtomic(max); if (buffer == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -3719,15 +3734,8 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { if (len + 10 > max) { xmlChar *tmp; - if ((max > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken"); - xmlFree(buffer); - return(NULL); - } max *= 2; - tmp = (xmlChar *) xmlRealloc(buffer, - max * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buffer, max); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); xmlFree(buffer); @@ -3738,6 +3746,11 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { COPY_BUF(l,buffer,len,c); NEXTL(l); c = CUR_CHAR(l); + if (len > maxLength) { + xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken"); + xmlFree(buffer); + return(NULL); + } } buffer[len] = 0; return(buffer); @@ -3745,8 +3758,7 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { } if (len == 0) return(NULL); - if ((len > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (len > maxLength) { xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken"); return(NULL); } @@ -3758,6 +3770,8 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { * @ctxt: an XML parser context * @orig: if non-NULL store a copy of the original entity value * + * DEPRECATED: Internal function, don't use. + * * parse a value for ENTITY declarations * * [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | @@ -3772,6 +3786,9 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { int len = 0; int size = XML_PARSER_BUFFER_SIZE; int c, l; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; xmlChar stop; xmlChar *ret = NULL; const xmlChar *cur = NULL; @@ -3783,7 +3800,7 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { xmlFatalErr(ctxt, XML_ERR_ENTITY_NOT_STARTED, NULL); return(NULL); } - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -3815,7 +3832,7 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { xmlChar *tmp; size *= 2; - tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); goto error; @@ -3831,6 +3848,12 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { GROW; c = CUR_CHAR(l); } + + if (len > maxLength) { + xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_NOT_FINISHED, + "entity value too long\n"); + goto error; + } } buf[len] = 0; if (ctxt->instate == XML_PARSER_EOF) @@ -3918,6 +3941,9 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { xmlChar *rep = NULL; size_t len = 0; size_t buf_size = 0; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; int c, l, in_space = 0; xmlChar *current = NULL; xmlEntityPtr ent; @@ -3949,16 +3975,6 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { while (((NXT(0) != limit) && /* checked */ (IS_CHAR(c)) && (c != '<')) && (ctxt->instate != XML_PARSER_EOF)) { - /* - * Impose a reasonable limit on attribute size, unless XML_PARSE_HUGE - * special option is given - */ - if ((len > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, - "AttValue length too long\n"); - goto mem_error; - } if (c == '&') { in_space = 0; if (NXT(1) == '#') { @@ -4106,6 +4122,11 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { } GROW; c = CUR_CHAR(l); + if (len > maxLength) { + xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, + "AttValue length too long\n"); + goto mem_error; + } } if (ctxt->instate == XML_PARSER_EOF) goto error; @@ -4127,17 +4148,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { } else NEXT; - /* - * There we potentially risk an overflow, don't allow attribute value of - * length more than INT_MAX it is a very reasonable assumption ! - */ - if (len >= INT_MAX) { - xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, - "AttValue length too long\n"); - goto mem_error; - } - - if (attlen != NULL) *attlen = (int) len; + if (attlen != NULL) *attlen = len; return(buf); mem_error: @@ -4154,6 +4165,8 @@ error: * xmlParseAttValue: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse a value for an attribute * Note: the parser won't do substitution of entities here, this * will be handled later in xmlStringGetNodeList @@ -4194,6 +4207,8 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { * xmlParseSystemLiteral: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML Literal * * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") @@ -4207,6 +4222,9 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { int len = 0; int size = XML_PARSER_BUFFER_SIZE; int cur, l; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; xmlChar stop; int state = ctxt->instate; int count = 0; @@ -4223,7 +4241,7 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { return(NULL); } - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -4234,15 +4252,8 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { if (len + 5 >= size) { xmlChar *tmp; - if ((size > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "SystemLiteral"); - xmlFree(buf); - ctxt->instate = (xmlParserInputState) state; - return(NULL); - } size *= 2; - tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size); if (tmp == NULL) { xmlFree(buf); xmlErrMemory(ctxt, NULL); @@ -4269,6 +4280,12 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { SHRINK; cur = CUR_CHAR(l); } + if (len > maxLength) { + xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "SystemLiteral"); + xmlFree(buf); + ctxt->instate = (xmlParserInputState) state; + return(NULL); + } } buf[len] = 0; ctxt->instate = (xmlParserInputState) state; @@ -4284,6 +4301,8 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { * xmlParsePubidLiteral: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML public literal * * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" @@ -4296,6 +4315,9 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; int len = 0; int size = XML_PARSER_BUFFER_SIZE; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_TEXT_LENGTH : + XML_MAX_NAME_LENGTH; xmlChar cur; xmlChar stop; int count = 0; @@ -4312,7 +4334,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL); return(NULL); } - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -4323,14 +4345,8 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { if (len + 1 >= size) { xmlChar *tmp; - if ((size > XML_MAX_NAME_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Public ID"); - xmlFree(buf); - return(NULL); - } size *= 2; - tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); xmlFree(buf); @@ -4356,6 +4372,11 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { SHRINK; cur = CUR; } + if (len > maxLength) { + xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Public ID"); + xmlFree(buf); + return(NULL); + } } buf[len] = 0; if (cur != stop) { @@ -4412,6 +4433,8 @@ static const unsigned char test_char_data[256] = { * @ctxt: an XML parser context * @cdata: int indicating whether we are within a CDATA section * + * DEPRECATED: Internal function, don't use. + * * parse a CharData section. * if we are within a CDATA section ']]>' marks an end of section. * @@ -4666,6 +4689,8 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { * @strict: indicate whether we should restrict parsing to only * production [75], see NOTE below * + * DEPRECATED: Internal function, don't use. + * * Parse an External ID or a Public ID * * NOTE: Productions [75] and [83] interact badly since [75] can generate @@ -4755,6 +4780,9 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int r, rl; int cur, l; size_t count = 0; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; int inputid; inputid = ctxt->input->id; @@ -4762,7 +4790,7 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, if (buf == NULL) { len = 0; size = XML_PARSER_BUFFER_SIZE; - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return; @@ -4800,13 +4828,6 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, if ((r == '-') && (q == '-')) { xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL); } - if ((len > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, - "Comment too big found", NULL); - xmlFree (buf); - return; - } if (len + 5 >= size) { xmlChar *new_buf; size_t new_size; @@ -4844,6 +4865,13 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, GROW; cur = CUR_CHAR(l); } + + if (len > maxLength) { + xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, + "Comment too big found", NULL); + xmlFree (buf); + return; + } } buf[len] = 0; if (cur == 0) { @@ -4877,6 +4905,8 @@ not_terminated: * xmlParseComment: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * Skip an XML (SGML) comment <!-- .... --> * The spec says that "For compatibility, the string "--" (double-hyphen) * must not occur within comments. " @@ -4888,6 +4918,9 @@ xmlParseComment(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; size_t size = XML_PARSER_BUFFER_SIZE; size_t len = 0; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; xmlParserInputState state; const xmlChar *in; size_t nbchar = 0; @@ -4946,7 +4979,7 @@ get_more: size = nbchar + 1; else size = XML_PARSER_BUFFER_SIZE + nbchar; - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); ctxt->instate = state; @@ -4956,8 +4989,7 @@ get_more: } else if (len + nbchar + 1 >= size) { xmlChar *new_buf; size += len + nbchar + XML_PARSER_BUFFER_SIZE; - new_buf = (xmlChar *) xmlRealloc(buf, - size * sizeof(xmlChar)); + new_buf = (xmlChar *) xmlRealloc(buf, size); if (new_buf == NULL) { xmlFree (buf); xmlErrMemory(ctxt, NULL); @@ -4971,8 +5003,7 @@ get_more: buf[len] = 0; } } - if ((len > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if (len > maxLength) { xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED, "Comment too big found", NULL); xmlFree (buf); @@ -5052,6 +5083,8 @@ get_more: * xmlParsePITarget: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the name of a PI * * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) @@ -5160,6 +5193,8 @@ error: * xmlParsePI: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML Processing Instruction. * * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' @@ -5172,6 +5207,9 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; size_t len = 0; size_t size = XML_PARSER_BUFFER_SIZE; + size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; int cur, l; const xmlChar *target; xmlParserInputState state; @@ -5212,7 +5250,7 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { ctxt->instate = state; return; } - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); ctxt->instate = state; @@ -5247,14 +5285,6 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { return; } count = 0; - if ((len > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, - "PI %s too big found", target); - xmlFree(buf); - ctxt->instate = state; - return; - } } COPY_BUF(l,buf,len,cur); NEXTL(l); @@ -5264,15 +5294,14 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { GROW; cur = CUR_CHAR(l); } + if (len > maxLength) { + xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, + "PI %s too big found", target); + xmlFree(buf); + ctxt->instate = state; + return; + } } - if ((len > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, - "PI %s too big found", target); - xmlFree(buf); - ctxt->instate = state; - return; - } buf[len] = 0; if (cur != '?') { xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED, @@ -5318,6 +5347,8 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { * xmlParseNotationDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse a notation declaration * * [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>' @@ -5390,6 +5421,8 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { * xmlParseEntityDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse <!ENTITY declarations * * [70] EntityDecl ::= GEDecl | PEDecl @@ -5657,6 +5690,8 @@ done: * @ctxt: an XML parser context * @value: Receive a possible fixed default value for the attribute * + * DEPRECATED: Internal function, don't use. + * * Parse an attribute default declaration * * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) @@ -5718,6 +5753,8 @@ xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) { * xmlParseNotationType: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an Notation attribute type. * * Note: the leading 'NOTATION' S part has already being parsed... @@ -5790,6 +5827,8 @@ xmlParseNotationType(xmlParserCtxtPtr ctxt) { * xmlParseEnumerationType: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an Enumeration attribute type. * * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' @@ -5860,6 +5899,8 @@ xmlParseEnumerationType(xmlParserCtxtPtr ctxt) { * @ctxt: an XML parser context * @tree: the enumeration tree built while parsing * + * DEPRECATED: Internal function, don't use. + * * parse an Enumerated attribute type. * * [57] EnumeratedType ::= NotationType | Enumeration @@ -5893,6 +5934,8 @@ xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { * @ctxt: an XML parser context * @tree: the enumeration tree built while parsing * + * DEPRECATED: Internal function, don't use. + * * parse the Attribute list def for an element * * [54] AttType ::= StringType | TokenizedType | EnumeratedType @@ -5968,6 +6011,8 @@ xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { * xmlParseAttributeListDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * : parse the Attribute list def for an element * * [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>' @@ -6089,6 +6134,8 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { * @ctxt: an XML parser context * @inputchk: the input used for the current entity, needed for boundary checks * + * DEPRECATED: Internal function, don't use. + * * parse the declaration for a Mixed Element content * The leading '(' and spaces have been skipped in xmlParseElementContentDecl * @@ -6507,6 +6554,8 @@ xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk, * @ctxt: an XML parser context * @inputchk: the input used for the current entity, needed for boundary checks * + * DEPRECATED: Internal function, don't use. + * * parse the declaration for a Mixed Element content * The leading '(' and spaces have been skipped in xmlParseElementContentDecl * @@ -6544,6 +6593,8 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt, int inputchk) { * @name: the name of the element being defined. * @result: the Element Content pointer will be stored here if any * + * DEPRECATED: Internal function, don't use. + * * parse the declaration for an Element content either Mixed or Children, * the cases EMPTY and ANY are handled directly in xmlParseElementDecl * @@ -6588,6 +6639,8 @@ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name, * xmlParseElementDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an Element declaration. * * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>' @@ -6820,12 +6873,12 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { } SKIP(3); } else { - const xmlChar *check = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; xmlParseMarkupDecl(ctxt); - if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { + if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) { xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); xmlHaltParser(ctxt); goto error; @@ -6847,6 +6900,8 @@ error: * xmlParseMarkupDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse Markup declarations * * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | @@ -6909,6 +6964,8 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { * xmlParseTextDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML declaration header for external entities * * [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' @@ -6977,9 +7034,14 @@ xmlParseTextDecl(xmlParserCtxtPtr ctxt) { xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); NEXT; } else { + int c; + xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); - MOVETO_ENDTAG(CUR_PTR); - NEXT; + while ((c = CUR) != 0) { + NEXT; + if (c == '>') + break; + } } ctxt->instate = oldstate; @@ -7044,8 +7106,8 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, while (((RAW == '<') && (NXT(1) == '?')) || ((RAW == '<') && (NXT(1) == '!')) || (RAW == '%')) { - const xmlChar *check = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; GROW; if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { @@ -7054,7 +7116,7 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, xmlParseMarkupDecl(ctxt); SKIP_BLANKS; - if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { + if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) { xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); break; } @@ -7070,6 +7132,8 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, * xmlParseReference: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse and handle entity references in content, depending on the SAX * interface, this may end-up in a call to character() if this is a * CharRef, a predefined entity, if there is no reference() callback. @@ -7250,7 +7314,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { ent->owner = 1; while (list != NULL) { list->parent = (xmlNodePtr) ent; - xmlSetTreeDoc(list, ent->doc); + if (list->doc != ent->doc) + xmlSetTreeDoc(list, ent->doc); if (list->next == NULL) ent->last = list; list = list->next; @@ -7516,6 +7581,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { * xmlParseEntityRef: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse ENTITY references declarations * * [68] EntityRef ::= '&' Name ';' @@ -7896,6 +7963,8 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) { * xmlParsePEReference: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse PEReference declarations * The entity content is handled directly by pushing it's content as * a new input stream. @@ -8006,7 +8075,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) xmlChar start[4]; xmlCharEncoding enc; - if (xmlParserEntityCheck(ctxt, 0, entity, 0)) + if (xmlParserEntityCheck(ctxt, 0, entity, 0)) return; if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) && @@ -8095,6 +8164,7 @@ xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { "xmlLoadEntityContent parameter error"); return(-1); } + xmlBufferSetAllocationScheme(buf, XML_BUFFER_ALLOC_DOUBLEIT); input = xmlNewEntityInputStream(ctxt, entity); if (input == NULL) { @@ -8110,6 +8180,7 @@ xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { */ if (xmlPushInput(ctxt, input) < 0) { xmlBufferFree(buf); + xmlFreeInputStream(input); return(-1); } @@ -8279,6 +8350,8 @@ xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) { * xmlParseDocTypeDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse a DOCTYPE declaration * * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? @@ -8377,8 +8450,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { */ while (((RAW != ']') || (ctxt->inputNr > baseInputNr)) && (ctxt->instate != XML_PARSER_EOF)) { - const xmlChar *check = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; SKIP_BLANKS; xmlParseMarkupDecl(ctxt); @@ -8393,7 +8466,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { xmlParseConditionalSections(ctxt); } - if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) { + if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) { xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "xmlParseInternalSubset: error detected in Markup declaration\n"); if (ctxt->inputNr > baseInputNr) @@ -8424,6 +8497,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { * @ctxt: an XML parser context * @value: a xmlChar ** used to store the value of the attribute * + * DEPRECATED: Internal function, don't use. + * * parse an attribute * * [41] Attribute ::= Name Eq AttValue @@ -8517,6 +8592,8 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { * xmlParseStartTag: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse a start of tag either for rule element or * EmptyElement. In both case we don't parse the tag closing chars. * @@ -8572,8 +8649,8 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { while (((RAW != '>') && ((RAW != '/') || (NXT(1) != '>')) && (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { - const xmlChar *q = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; attname = xmlParseAttribute(ctxt, &attvalue); if ((attname != NULL) && (attvalue != NULL)) { @@ -8638,7 +8715,7 @@ failed: xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "attributes construct error\n"); } - if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && + if ((cons == CUR_CONSUMED) && (id == ctxt->input->id) && (attname == NULL) && (attvalue == NULL)) { xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, "xmlParseStartTag: problem parsing attributes\n"); @@ -8736,6 +8813,8 @@ xmlParseEndTag1(xmlParserCtxtPtr ctxt, int line) { * xmlParseEndTag: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an end of tag * * [42] ETag ::= '</' Name S? '>' @@ -8975,6 +9054,9 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, const xmlChar *in = NULL, *start, *end, *last; xmlChar *ret = NULL; int line, col; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; GROW; in = (xmlChar *) CUR_PTR; @@ -9014,8 +9096,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, start = in; if (in >= end) { GROW_PARSE_ATT_VALUE_INTERNAL(ctxt, in, start, end) - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); @@ -9028,8 +9109,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, if ((*in++ == 0x20) && (*in == 0x20)) break; if (in >= end) { GROW_PARSE_ATT_VALUE_INTERNAL(ctxt, in, start, end) - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); @@ -9062,16 +9142,14 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, last = last + delta; } end = ctxt->input->end; - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); } } } - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); @@ -9084,8 +9162,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, col++; if (in >= end) { GROW_PARSE_ATT_VALUE_INTERNAL(ctxt, in, start, end) - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); @@ -9093,8 +9170,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, } } last = in; - if (((in - start) > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { + if ((in - start) > maxLength) { xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED, "AttValue length too long\n"); return(NULL); @@ -9104,6 +9180,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, in++; col++; if (len != NULL) { + if (alloc) *alloc = 0; *len = last - start; ret = (xmlChar *) start; } else { @@ -9113,7 +9190,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, CUR_PTR = in; ctxt->input->line = line; ctxt->input->col = col; - if (alloc) *alloc = 0; return ret; need_complex: if (alloc) *alloc = 1; @@ -9322,8 +9398,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, while (((RAW != '>') && ((RAW != '/') || (NXT(1) != '>')) && (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) { - const xmlChar *q = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; int len = -1, alloc = 0; attname = xmlParseAttribute2(ctxt, prefix, localname, @@ -9504,7 +9580,7 @@ next_attr: "attributes construct error\n"); break; } - if ((cons == ctxt->input->consumed) && (q == CUR_PTR) && + if ((cons == CUR_CONSUMED) && (id == ctxt->input->id) && (attname == NULL) && (attvalue == NULL)) { xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "xmlParseStartTag: problem parsing attributes\n"); @@ -9765,6 +9841,8 @@ xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlStartTag *tag) { * xmlParseCDSect: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * Parse escaped pure raw content. * * [18] CDSect ::= CDStart CData CDEnd @@ -9784,6 +9862,9 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { int s, sl; int cur, l; int count = 0; + int maxLength = (ctxt->options & XML_PARSE_HUGE) ? + XML_MAX_HUGE_LENGTH : + XML_MAX_TEXT_LENGTH; /* Check 2.6.0 was NXT(0) not RAW */ if (CMP9(CUR_PTR, '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '[')) { @@ -9807,7 +9888,7 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { } NEXTL(sl); cur = CUR_CHAR(l); - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return; @@ -9817,14 +9898,7 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { if (len + 5 >= size) { xmlChar *tmp; - if ((size > XML_MAX_TEXT_LENGTH) && - ((ctxt->options & XML_PARSE_HUGE) == 0)) { - xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED, - "CData section too big found", NULL); - xmlFree (buf); - return; - } - tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size * 2); if (tmp == NULL) { xmlFree(buf); xmlErrMemory(ctxt, NULL); @@ -9850,6 +9924,12 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { } NEXTL(l); cur = CUR_CHAR(l); + if (len > maxLength) { + xmlFatalErrMsg(ctxt, XML_ERR_CDATA_NOT_FINISHED, + "CData section too big found\n"); + xmlFree(buf); + return; + } } buf[len] = 0; ctxt->instate = XML_PARSER_CONTENT; @@ -9888,8 +9968,8 @@ xmlParseContentInternal(xmlParserCtxtPtr ctxt) { GROW; while ((RAW != 0) && (ctxt->instate != XML_PARSER_EOF)) { - const xmlChar *test = CUR_PTR; - unsigned int cons = ctxt->input->consumed; + int id = ctxt->input->id; + unsigned long cons = CUR_CONSUMED; const xmlChar *cur = ctxt->input->cur; /* @@ -9948,7 +10028,7 @@ xmlParseContentInternal(xmlParserCtxtPtr ctxt) { GROW; SHRINK; - if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { + if ((cons == CUR_CONSUMED) && (id == ctxt->input->id)) { xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "detected an error in element content\n"); xmlHaltParser(ctxt); @@ -9985,6 +10065,8 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { * xmlParseElement: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML element * * [39] element ::= EmptyElemTag | STag content ETag @@ -10188,6 +10270,8 @@ xmlParseElementEnd(xmlParserCtxtPtr ctxt) { * xmlParseVersionNum: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the XML version value. * * [26] VersionNum ::= '1.' [0-9]+ @@ -10203,7 +10287,7 @@ xmlParseVersionNum(xmlParserCtxtPtr ctxt) { int size = 10; xmlChar cur; - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -10228,7 +10312,7 @@ xmlParseVersionNum(xmlParserCtxtPtr ctxt) { xmlChar *tmp; size *= 2; - tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size); if (tmp == NULL) { xmlFree(buf); xmlErrMemory(ctxt, NULL); @@ -10248,6 +10332,8 @@ xmlParseVersionNum(xmlParserCtxtPtr ctxt) { * xmlParseVersionInfo: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the XML version. * * [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ") @@ -10295,6 +10381,8 @@ xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { * xmlParseEncName: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the XML encoding name * * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* @@ -10311,7 +10399,7 @@ xmlParseEncName(xmlParserCtxtPtr ctxt) { cur = CUR; if (((cur >= 'a') && (cur <= 'z')) || ((cur >= 'A') && (cur <= 'Z'))) { - buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); + buf = (xmlChar *) xmlMallocAtomic(size); if (buf == NULL) { xmlErrMemory(ctxt, NULL); return(NULL); @@ -10329,7 +10417,7 @@ xmlParseEncName(xmlParserCtxtPtr ctxt) { xmlChar *tmp; size *= 2; - tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + tmp = (xmlChar *) xmlRealloc(buf, size); if (tmp == NULL) { xmlErrMemory(ctxt, NULL); xmlFree(buf); @@ -10357,6 +10445,8 @@ xmlParseEncName(xmlParserCtxtPtr ctxt) { * xmlParseEncodingDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the XML encoding declaration * * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'") @@ -10471,6 +10561,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { * xmlParseSDDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse the XML standalone declaration * * [32] SDDecl ::= S 'standalone' Eq @@ -10555,6 +10647,8 @@ xmlParseSDDecl(xmlParserCtxtPtr ctxt) { * xmlParseXMLDecl: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML declaration header * * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' @@ -10660,9 +10754,14 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); NEXT; } else { + int c; + xmlFatalErr(ctxt, XML_ERR_XMLDECL_NOT_FINISHED, NULL); - MOVETO_ENDTAG(CUR_PTR); - NEXT; + while ((c = CUR) != 0) { + NEXT; + if (c == '>') + break; + } } } @@ -10670,6 +10769,8 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { * xmlParseMisc: * @ctxt: an XML parser context * + * DEPRECATED: Internal function, don't use. + * * parse an XML Misc* optional field. * * [27] Misc ::= Comment | PI | S @@ -10905,8 +11006,6 @@ xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { if ((ctxt == NULL) || (ctxt->input == NULL)) return(-1); - xmlDefaultSAXHandlerInit(); - xmlDetectSAX2(ctxt); GROW; @@ -11543,15 +11642,15 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { break; } case XML_PARSER_CONTENT: { - const xmlChar *test; - unsigned int cons; + int id; + unsigned long cons; if ((avail < 2) && (ctxt->inputNr == 1)) goto done; cur = ctxt->input->cur[0]; next = ctxt->input->cur[1]; - test = CUR_PTR; - cons = ctxt->input->consumed; + id = ctxt->input->id; + cons = CUR_CONSUMED; if ((cur == '<') && (next == '/')) { ctxt->instate = XML_PARSER_END_TAG; break; @@ -11632,7 +11731,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { ctxt->checkIndex = 0; xmlParseCharData(ctxt, 0); } - if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) { + if ((cons == CUR_CONSUMED) && (id == ctxt->input->id)) { xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "detected an error in element content\n"); xmlHaltParser(ctxt); @@ -12470,33 +12569,13 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, buf = xmlAllocParserInputBuffer(enc); if (buf == NULL) return(NULL); - ctxt = xmlNewParserCtxt(); + ctxt = xmlNewSAXParserCtxt(sax, user_data); if (ctxt == NULL) { xmlErrMemory(NULL, "creating parser: out of memory\n"); xmlFreeParserInputBuffer(buf); return(NULL); } ctxt->dictNames = 1; - if (sax != NULL) { -#ifdef LIBXML_SAX1_ENABLED - if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) -#endif /* LIBXML_SAX1_ENABLED */ - xmlFree(ctxt->sax); - ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); - if (ctxt->sax == NULL) { - xmlErrMemory(ctxt, NULL); - xmlFreeParserInputBuffer(buf); - xmlFreeParserCtxt(ctxt); - return(NULL); - } - memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); - if (sax->initialized == XML_SAX2_MAGIC) - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); - else - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); - if (user_data != NULL) - ctxt->userData = user_data; - } if (filename == NULL) { ctxt->directory = NULL; } else { @@ -12632,31 +12711,11 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, return (NULL); } - ctxt = xmlNewParserCtxt(); + ctxt = xmlNewSAXParserCtxt(sax, user_data); if (ctxt == NULL) { xmlFreeParserInputBuffer(buf); return(NULL); } - if (sax != NULL) { -#ifdef LIBXML_SAX1_ENABLED - if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) -#endif /* LIBXML_SAX1_ENABLED */ - xmlFree(ctxt->sax); - ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); - if (ctxt->sax == NULL) { - xmlFreeParserInputBuffer(buf); - xmlErrMemory(ctxt, NULL); - xmlFreeParserCtxt(ctxt); - return(NULL); - } - memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); - if (sax->initialized == XML_SAX2_MAGIC) - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); - else - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); - if (user_data != NULL) - ctxt->userData = user_data; - } inputStream = xmlNewIOInputStream(ctxt, buf, enc); if (inputStream == NULL) { @@ -12698,7 +12757,7 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, if (input == NULL) return(NULL); - ctxt = xmlNewParserCtxt(); + ctxt = xmlNewSAXParserCtxt(sax, NULL); if (ctxt == NULL) { xmlFreeParserInputBuffer(input); return(NULL); @@ -12707,15 +12766,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, /* We are loading a DTD */ ctxt->options |= XML_PARSE_DTDLOAD; - /* - * Set-up the SAX context - */ - if (sax != NULL) { - if (ctxt->sax != NULL) - xmlFree(ctxt->sax); - ctxt->sax = sax; - ctxt->userData = ctxt; - } xmlDetectSAX2(ctxt); /* @@ -12724,7 +12774,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, pinput = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE); if (pinput == NULL) { - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserInputBuffer(input); xmlFreeParserCtxt(ctxt); return(NULL); @@ -12734,7 +12783,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, * plug some encoding conversion routines here. */ if (xmlPushInput(ctxt, pinput) < 0) { - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); return(NULL); } @@ -12801,7 +12849,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL; } - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); return(ret); @@ -12813,6 +12860,8 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, * @ExternalID: a NAME* containing the External ID of the DTD * @SystemID: a NAME* containing the URL to the DTD * + * DEPRECATED: Don't use. + * * Load and parse an external subset. * * Returns the resulting xmlDtdPtr or NULL in case of error. @@ -12829,7 +12878,7 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); - ctxt = xmlNewParserCtxt(); + ctxt = xmlNewSAXParserCtxt(sax, NULL); if (ctxt == NULL) { return(NULL); } @@ -12838,16 +12887,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, ctxt->options |= XML_PARSE_DTDLOAD; /* - * Set-up the SAX context - */ - if (sax != NULL) { - if (ctxt->sax != NULL) - xmlFree(ctxt->sax); - ctxt->sax = sax; - ctxt->userData = ctxt; - } - - /* * Canonicalise the system ID */ systemIdCanonic = xmlCanonicPath(SystemID); @@ -12864,7 +12903,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, systemIdCanonic); if (input == NULL) { - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); if (systemIdCanonic != NULL) xmlFree(systemIdCanonic); @@ -12875,7 +12913,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, * plug some encoding conversion routines here. */ if (xmlPushInput(ctxt, input) < 0) { - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); if (systemIdCanonic != NULL) xmlFree(systemIdCanonic); @@ -12903,7 +12940,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0"); if (ctxt->myDoc == NULL) { xmlErrMemory(ctxt, "New Doc failed"); - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); return(NULL); } @@ -12932,7 +12968,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID, xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL; } - if (sax != NULL) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); return(ret); @@ -13023,7 +13058,6 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, xmlParserCtxtPtr ctxt; xmlDocPtr newDoc; xmlNodePtr newRoot; - xmlSAXHandlerPtr oldsax = NULL; xmlParserErrors ret = XML_ERR_OK; xmlChar start[4]; xmlCharEncoding enc; @@ -13041,17 +13075,11 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, if (doc == NULL) return(XML_ERR_INTERNAL_ERROR); - - ctxt = xmlCreateEntityParserCtxtInternal(URL, ID, NULL, oldctxt); + ctxt = xmlCreateEntityParserCtxtInternal(sax, user_data, URL, ID, NULL, + oldctxt); if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY); - ctxt->userData = ctxt; - if (sax != NULL) { - oldsax = ctxt->sax; - ctxt->sax = sax; - if (user_data != NULL) - ctxt->userData = user_data; - } xmlDetectSAX2(ctxt); + newDoc = xmlNewDoc(BAD_CAST "1.0"); if (newDoc == NULL) { xmlFreeParserCtxt(ctxt); @@ -13072,7 +13100,6 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, newRoot = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL); if (newRoot == NULL) { if (sax != NULL) - ctxt->sax = oldsax; xmlFreeParserCtxt(ctxt); newDoc->intSubset = NULL; newDoc->extSubset = NULL; @@ -13213,8 +13240,6 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, if ((oldctxt != NULL) && (ctxt->lastError.code != XML_ERR_OK)) xmlCopyError(&ctxt->lastError, &oldctxt->lastError); - if (sax != NULL) - ctxt->sax = oldsax; if (oldctxt != NULL) { ctxt->dict = NULL; ctxt->attsDefault = NULL; @@ -13606,7 +13631,7 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen, ctxt->input_id = 2; ctxt->instate = XML_PARSER_CONTENT; - fake = xmlNewComment(NULL); + fake = xmlNewDocComment(node->doc, NULL); if (fake == NULL) { xmlFreeParserCtxt(ctxt); return(XML_ERR_NO_MEMORY); @@ -13889,6 +13914,8 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax, * @sax: the SAX handler block * @filename: the filename * + * DEPRECATED: Don't use. + * * parse an XML external entity out of context and build a tree. * It use the given SAX function block to handle the parsing callback. * If sax is NULL, fallback to the default DOM tree building routines. @@ -13965,14 +13992,15 @@ xmlParseEntity(const char *filename) { * Returns the new parser context or NULL */ static xmlParserCtxtPtr -xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, - const xmlChar *base, xmlParserCtxtPtr pctx) { +xmlCreateEntityParserCtxtInternal(xmlSAXHandlerPtr sax, void *userData, + const xmlChar *URL, const xmlChar *ID, const xmlChar *base, + xmlParserCtxtPtr pctx) { xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; char *directory = NULL; xmlChar *uri; - ctxt = xmlNewParserCtxt(); + ctxt = xmlNewSAXParserCtxt(sax, userData); if (ctxt == NULL) { return(NULL); } @@ -14040,7 +14068,7 @@ xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, xmlParserCtxtPtr xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID, const xmlChar *base) { - return xmlCreateEntityParserCtxtInternal(URL, ID, base, NULL); + return xmlCreateEntityParserCtxtInternal(NULL, NULL, URL, ID, base, NULL); } @@ -14118,6 +14146,8 @@ xmlCreateFileParserCtxt(const char *filename) * documents * @data: the userdata * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadFile. + * * parse an XML file and build a tree. Automatic support for ZLIB/Compress * compressed document is provided by default if found at compile-time. * It use the given SAX function block to handle the parsing callback. @@ -14186,6 +14216,8 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename, * @recovery: work in recovery mode, i.e. tries to read no Well Formed * documents * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadFile. + * * parse an XML file and build a tree. Automatic support for ZLIB/Compress * compressed document is provided by default if found at compile-time. * It use the given SAX function block to handle the parsing callback. @@ -14204,6 +14236,8 @@ xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, * xmlRecoverDoc: * @cur: a pointer to an array of xmlChar * + * DEPRECATED: Use xmlReadDoc with XML_PARSE_RECOVER. + * * parse an XML in-memory document and build a tree. * In the case the document is not Well Formed, a attempt to build a * tree is tried anyway @@ -14220,6 +14254,8 @@ xmlRecoverDoc(const xmlChar *cur) { * xmlParseFile: * @filename: the filename * + * DEPRECATED: Use xmlReadFile. + * * parse an XML file and build a tree. Automatic support for ZLIB/Compress * compressed document is provided by default if found at compile-time. * @@ -14236,6 +14272,8 @@ xmlParseFile(const char *filename) { * xmlRecoverFile: * @filename: the filename * + * DEPRECATED: Use xmlReadFile with XML_PARSE_RECOVER. + * * parse an XML file and build a tree. Automatic support for ZLIB/Compress * compressed document is provided by default if found at compile-time. * In the case the document is not Well Formed, it attempts to build @@ -14256,6 +14294,8 @@ xmlRecoverFile(const char *filename) { * @buffer: a xmlChar * buffer * @filename: a file name * + * DEPRECATED: Don't use. + * * Setup the parser context to parse a new buffer; Clears any prior * contents from the parser context. The buffer parameter must not be * NULL, but the filename parameter can be @@ -14291,6 +14331,8 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, * @user_data: The user data returned on SAX callbacks * @filename: a file name * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadFile. + * * parse an XML file and call the given SAX handler routines. * Automatic support for ZLIB/Compress compressed document is provided * @@ -14396,6 +14438,8 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) { * documents * @data: the userdata * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadMemory. + * * parse an XML in-memory block and use the given SAX function block * to handle the parsing callback. If sax is NULL, fallback to the default * DOM tree building routines. @@ -14451,6 +14495,8 @@ xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer, * @recovery: work in recovery mode, i.e. tries to read not Well Formed * documents * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadMemory. + * * parse an XML in-memory block and use the given SAX function block * to handle the parsing callback. If sax is NULL, fallback to the default * DOM tree building routines. @@ -14468,6 +14514,8 @@ xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, * @buffer: an pointer to a char array * @size: the size of the array * + * DEPRECATED: Use xmlReadMemory. + * * parse an XML in-memory block and build a tree. * * Returns the resulting document tree @@ -14482,6 +14530,8 @@ xmlDocPtr xmlParseMemory(const char *buffer, int size) { * @buffer: an pointer to a char array * @size: the size of the array * + * DEPRECATED: Use xmlReadMemory with XML_PARSE_RECOVER. + * * parse an XML in-memory block and build a tree. * In the case the document is not Well Formed, an attempt to * build a tree is tried anyway @@ -14500,7 +14550,8 @@ xmlDocPtr xmlRecoverMemory(const char *buffer, int size) { * @buffer: an in-memory XML document input * @size: the length of the XML document in bytes * - * A better SAX parsing routine. + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadMemory. + * * parse an XML in-memory buffer and call the given SAX handler routines. * * Returns 0 in case of success or a error number otherwise @@ -14570,6 +14621,8 @@ xmlCreateDocParserCtxt(const xmlChar *cur) { * @recovery: work in recovery mode, i.e. tries to read no Well Formed * documents * + * DEPRECATED: Use xmlNewSAXParserCtxt and xmlCtxtReadDoc. + * * parse an XML in-memory document and build a tree. * It use the given SAX function block to handle the parsing callback. * If sax is NULL, fallback to the default DOM tree building routines. @@ -14613,6 +14666,8 @@ xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cur, int recovery) { * xmlParseDoc: * @cur: a pointer to an array of xmlChar * + * DEPRECATED: Use xmlReadDoc. + * * parse an XML in-memory document and build a tree. * * Returns the resulting document tree @@ -14671,11 +14726,6 @@ xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) * * ************************************************************************/ -#ifdef LIBXML_XPATH_ENABLED -#include <libxml/xpath.h> -#endif - -extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...); static int xmlParserInitialized = 0; /** @@ -14702,9 +14752,6 @@ xmlInitParser(void) { #endif xmlInitThreads(); xmlInitGlobals(); - if ((xmlGenericError == xmlGenericErrorDefaultFunc) || - (xmlGenericError == NULL)) - initGenericErrorDefaultFunc(NULL); xmlInitMemory(); xmlInitializeDict(); xmlInitCharEncodingHandlers(); @@ -14717,7 +14764,7 @@ xmlInitParser(void) { htmlInitAutoClose(); htmlDefaultSAXHandlerInit(); #endif -#ifdef LIBXML_XPATH_ENABLED +#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) xmlXPathInit(); #endif xmlParserInitialized = 1; @@ -14843,6 +14890,8 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt) ctxt->nameNr = 0; ctxt->name = NULL; + ctxt->nsNr = 0; + DICT_FREE(ctxt->version); ctxt->version = NULL; DICT_FREE(ctxt->encoding); @@ -15380,22 +15429,10 @@ xmlDocPtr xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur, const char *URL, const char *encoding, int options) { - xmlParserInputPtr stream; - if (cur == NULL) return (NULL); - if (ctxt == NULL) - return (NULL); - xmlInitParser(); - - xmlCtxtReset(ctxt); - - stream = xmlNewStringInputStream(ctxt, cur); - if (stream == NULL) { - return (NULL); - } - inputPush(ctxt, stream); - return (xmlDoRead(ctxt, URL, encoding, options, 1)); + return (xmlCtxtReadMemory(ctxt, (const char *) cur, xmlStrlen(cur), URL, + encoding, options)); } /** |