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

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

Issue 1977213002: Roll libxml to 8effcb578e0590cc01bbcab0f9dccefc6bdbcdbd (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update README.chromium. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly 2 * parser.c : an XML 1.0 parser, namespaces and validity support are mostly
3 * implemented on top of the SAX interfaces 3 * implemented on top of the SAX interfaces
4 * 4 *
5 * References: 5 * References:
6 * The XML specification: 6 * The XML specification:
7 * http://www.w3.org/TR/REC-xml 7 * http://www.w3.org/TR/REC-xml
8 * Original 1.0 version: 8 * Original 1.0 version:
9 * http://www.w3.org/TR/1998/REC-xml-19980210 9 * http://www.w3.org/TR/1998/REC-xml-19980210
10 * XML second edition working draft 10 * XML second edition working draft
(...skipping 3607 matching lines...) Expand 10 before | Expand all | Expand 10 after
3618 ++cmp; 3618 ++cmp;
3619 ctxt->input->col++; 3619 ctxt->input->col++;
3620 } 3620 }
3621 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) { 3621 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
3622 /* success */ 3622 /* success */
3623 ctxt->input->cur = in; 3623 ctxt->input->cur = in;
3624 return (const xmlChar*) 1; 3624 return (const xmlChar*) 1;
3625 } 3625 }
3626 /* failure (or end of input buffer), check with full function */ 3626 /* failure (or end of input buffer), check with full function */
3627 ret = xmlParseName (ctxt); 3627 ret = xmlParseName (ctxt);
3628 /* strings coming from the dictionnary direct compare possible */ 3628 /* strings coming from the dictionary direct compare possible */
3629 if (ret == other) { 3629 if (ret == other) {
3630 return (const xmlChar*) 1; 3630 return (const xmlChar*) 1;
3631 } 3631 }
3632 return ret; 3632 return ret;
3633 } 3633 }
3634 3634
3635 /** 3635 /**
3636 * xmlParseStringName: 3636 * xmlParseStringName:
3637 * @ctxt: an XML parser context 3637 * @ctxt: an XML parser context
3638 * @str: a pointer to the string pointer (IN/OUT) 3638 * @str: a pointer to the string pointer (IN/OUT)
(...skipping 5173 matching lines...) Expand 10 before | Expand all | Expand 10 after
8812 * SAX 2 specific operations * 8812 * SAX 2 specific operations *
8813 * * 8813 * *
8814 ************************************************************************/ 8814 ************************************************************************/
8815 8815
8816 /* 8816 /*
8817 * xmlGetNamespace: 8817 * xmlGetNamespace:
8818 * @ctxt: an XML parser context 8818 * @ctxt: an XML parser context
8819 * @prefix: the prefix to lookup 8819 * @prefix: the prefix to lookup
8820 * 8820 *
8821 * Lookup the namespace name for the @prefix (which ca be NULL) 8821 * Lookup the namespace name for the @prefix (which ca be NULL)
8822 * The prefix must come from the @ctxt->dict dictionnary 8822 * The prefix must come from the @ctxt->dict dictionary
8823 * 8823 *
8824 * Returns the namespace name or NULL if not bound 8824 * Returns the namespace name or NULL if not bound
8825 */ 8825 */
8826 static const xmlChar * 8826 static const xmlChar *
8827 xmlGetNamespace(xmlParserCtxtPtr ctxt, const xmlChar *prefix) { 8827 xmlGetNamespace(xmlParserCtxtPtr ctxt, const xmlChar *prefix) {
8828 int i; 8828 int i;
8829 8829
8830 if (prefix == ctxt->str_xml) return(ctxt->str_xml_ns); 8830 if (prefix == ctxt->str_xml) return(ctxt->str_xml_ns);
8831 for (i = ctxt->nsNr - 2;i >= 0;i-=2) 8831 for (i = ctxt->nsNr - 2;i >= 0;i-=2)
8832 if (ctxt->nsTab[i] == prefix) { 8832 if (ctxt->nsTab[i] == prefix) {
(...skipping 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
11204 *lastgt = NULL; 11204 *lastgt = NULL;
11205 } 11205 }
11206 } 11206 }
11207 } else { 11207 } else {
11208 *lastlt = NULL; 11208 *lastlt = NULL;
11209 *lastgt = NULL; 11209 *lastgt = NULL;
11210 } 11210 }
11211 } 11211 }
11212 /** 11212 /**
11213 * xmlCheckCdataPush: 11213 * xmlCheckCdataPush:
11214 * @cur: pointer to the bock of characters 11214 * @cur: pointer to the block of characters
11215 * @len: length of the block in bytes 11215 * @len: length of the block in bytes
11216 * @complete: 1 if complete CDATA block is passed in, 0 if partial block
11216 * 11217 *
11217 * Check that the block of characters is okay as SCdata content [20] 11218 * Check that the block of characters is okay as SCdata content [20]
11218 * 11219 *
11219 * Returns the number of bytes to pass if okay, a negative index where an 11220 * Returns the number of bytes to pass if okay, a negative index where an
11220 * UTF-8 error occured otherwise 11221 * UTF-8 error occured otherwise
11221 */ 11222 */
11222 static int 11223 static int
11223 xmlCheckCdataPush(const xmlChar *utf, int len) { 11224 xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
11224 int ix; 11225 int ix;
11225 unsigned char c; 11226 unsigned char c;
11226 int codepoint; 11227 int codepoint;
11227 11228
11228 if ((utf == NULL) || (len <= 0)) 11229 if ((utf == NULL) || (len <= 0))
11229 return(0); 11230 return(0);
11230 11231
11231 for (ix = 0; ix < len;) { /* string is 0-terminated */ 11232 for (ix = 0; ix < len;) { /* string is 0-terminated */
11232 c = utf[ix]; 11233 c = utf[ix];
11233 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */ 11234 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */
11234 if (c >= 0x20) 11235 if (c >= 0x20)
11235 ix++; 11236 ix++;
11236 else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) 11237 else if ((c == 0xA) || (c == 0xD) || (c == 0x9))
11237 ix++; 11238 ix++;
11238 else 11239 else
11239 return(-ix); 11240 return(-ix);
11240 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ 11241 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */
11241 » if (ix + 2 > len) return(-ix); 11242 » if (ix + 2 > len) return(complete ? -ix : ix);
11242 if ((utf[ix+1] & 0xc0 ) != 0x80) 11243 if ((utf[ix+1] & 0xc0 ) != 0x80)
11243 return(-ix); 11244 return(-ix);
11244 codepoint = (utf[ix] & 0x1f) << 6; 11245 codepoint = (utf[ix] & 0x1f) << 6;
11245 codepoint |= utf[ix+1] & 0x3f; 11246 codepoint |= utf[ix+1] & 0x3f;
11246 if (!xmlIsCharQ(codepoint)) 11247 if (!xmlIsCharQ(codepoint))
11247 return(-ix); 11248 return(-ix);
11248 ix += 2; 11249 ix += 2;
11249 } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */ 11250 } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */
11250 » if (ix + 3 > len) return(-ix); 11251 » if (ix + 3 > len) return(complete ? -ix : ix);
11251 if (((utf[ix+1] & 0xc0) != 0x80) || 11252 if (((utf[ix+1] & 0xc0) != 0x80) ||
11252 ((utf[ix+2] & 0xc0) != 0x80)) 11253 ((utf[ix+2] & 0xc0) != 0x80))
11253 return(-ix); 11254 return(-ix);
11254 codepoint = (utf[ix] & 0xf) << 12; 11255 codepoint = (utf[ix] & 0xf) << 12;
11255 codepoint |= (utf[ix+1] & 0x3f) << 6; 11256 codepoint |= (utf[ix+1] & 0x3f) << 6;
11256 codepoint |= utf[ix+2] & 0x3f; 11257 codepoint |= utf[ix+2] & 0x3f;
11257 if (!xmlIsCharQ(codepoint)) 11258 if (!xmlIsCharQ(codepoint))
11258 return(-ix); 11259 return(-ix);
11259 ix += 3; 11260 ix += 3;
11260 } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */ 11261 } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */
11261 » if (ix + 4 > len) return(-ix); 11262 » if (ix + 4 > len) return(complete ? -ix : ix);
11262 if (((utf[ix+1] & 0xc0) != 0x80) || 11263 if (((utf[ix+1] & 0xc0) != 0x80) ||
11263 ((utf[ix+2] & 0xc0) != 0x80) || 11264 ((utf[ix+2] & 0xc0) != 0x80) ||
11264 ((utf[ix+3] & 0xc0) != 0x80)) 11265 ((utf[ix+3] & 0xc0) != 0x80))
11265 return(-ix); 11266 return(-ix);
11266 codepoint = (utf[ix] & 0x7) << 18; 11267 codepoint = (utf[ix] & 0x7) << 18;
11267 codepoint |= (utf[ix+1] & 0x3f) << 12; 11268 codepoint |= (utf[ix+1] & 0x3f) << 12;
11268 codepoint |= (utf[ix+2] & 0x3f) << 6; 11269 codepoint |= (utf[ix+2] & 0x3f) << 6;
11269 codepoint |= utf[ix+3] & 0x3f; 11270 codepoint |= utf[ix+3] & 0x3f;
11270 if (!xmlIsCharQ(codepoint)) 11271 if (!xmlIsCharQ(codepoint))
11271 return(-ix); 11272 return(-ix);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
11766 * cdataBlock merge back contiguous callbacks. 11767 * cdataBlock merge back contiguous callbacks.
11767 */ 11768 */
11768 int base; 11769 int base;
11769 11770
11770 base = xmlParseLookupSequence(ctxt, ']', ']', '>'); 11771 base = xmlParseLookupSequence(ctxt, ']', ']', '>');
11771 if (base < 0) { 11772 if (base < 0) {
11772 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { 11773 if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) {
11773 int tmp; 11774 int tmp;
11774 11775
11775 tmp = xmlCheckCdataPush(ctxt->input->cur, 11776 tmp = xmlCheckCdataPush(ctxt->input->cur,
11776 » » » XML_PARSER_BIG_BUFFER_SIZE); 11777 » » » XML_PARSER_BIG_BUFFER_SIZE, 0);
11777 if (tmp < 0) { 11778 if (tmp < 0) {
11778 tmp = -tmp; 11779 tmp = -tmp;
11779 ctxt->input->cur += tmp; 11780 ctxt->input->cur += tmp;
11780 goto encoding_error; 11781 goto encoding_error;
11781 } 11782 }
11782 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { 11783 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
11783 if (ctxt->sax->cdataBlock != NULL) 11784 if (ctxt->sax->cdataBlock != NULL)
11784 ctxt->sax->cdataBlock(ctxt->userData, 11785 ctxt->sax->cdataBlock(ctxt->userData,
11785 ctxt->input->cur, tmp); 11786 ctxt->input->cur, tmp);
11786 else if (ctxt->sax->characters != NULL) 11787 else if (ctxt->sax->characters != NULL)
11787 ctxt->sax->characters(ctxt->userData, 11788 ctxt->sax->characters(ctxt->userData,
11788 ctxt->input->cur, tmp); 11789 ctxt->input->cur, tmp);
11789 } 11790 }
11790 if (ctxt->instate == XML_PARSER_EOF) 11791 if (ctxt->instate == XML_PARSER_EOF)
11791 goto done; 11792 goto done;
11792 SKIPL(tmp); 11793 SKIPL(tmp);
11793 ctxt->checkIndex = 0; 11794 ctxt->checkIndex = 0;
11794 } 11795 }
11795 goto done; 11796 goto done;
11796 } else { 11797 } else {
11797 int tmp; 11798 int tmp;
11798 11799
11799 » » tmp = xmlCheckCdataPush(ctxt->input->cur, base); 11800 » » tmp = xmlCheckCdataPush(ctxt->input->cur, base, 1);
11800 if ((tmp < 0) || (tmp != base)) { 11801 if ((tmp < 0) || (tmp != base)) {
11801 tmp = -tmp; 11802 tmp = -tmp;
11802 ctxt->input->cur += tmp; 11803 ctxt->input->cur += tmp;
11803 goto encoding_error; 11804 goto encoding_error;
11804 } 11805 }
11805 if ((ctxt->sax != NULL) && (base == 0) && 11806 if ((ctxt->sax != NULL) && (base == 0) &&
11806 (ctxt->sax->cdataBlock != NULL) && 11807 (ctxt->sax->cdataBlock != NULL) &&
11807 (!ctxt->disableSAX)) { 11808 (!ctxt->disableSAX)) {
11808 /* 11809 /*
11809 * Special case to provide identical behaviour 11810 * Special case to provide identical behaviour
(...skipping 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after
14984 /************************************************************************ 14985 /************************************************************************
14985 * * 14986 * *
14986 * New set (2.6.0) of simpler and more flexible APIs * 14987 * New set (2.6.0) of simpler and more flexible APIs *
14987 * * 14988 * *
14988 ************************************************************************/ 14989 ************************************************************************/
14989 14990
14990 /** 14991 /**
14991 * DICT_FREE: 14992 * DICT_FREE:
14992 * @str: a string 14993 * @str: a string
14993 * 14994 *
14994 * Free a string if it is not owned by the "dict" dictionnary in the 14995 * Free a string if it is not owned by the "dict" dictionary in the
14995 * current scope 14996 * current scope
14996 */ 14997 */
14997 #define DICT_FREE(str) \ 14998 #define DICT_FREE(str) \
14998 if ((str) && ((!dict) || \ 14999 if ((str) && ((!dict) || \
14999 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ 15000 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
15000 xmlFree((char *)(str)); 15001 xmlFree((char *)(str));
15001 15002
15002 /** 15003 /**
15003 * xmlCtxtReset: 15004 * xmlCtxtReset:
15004 * @ctxt: an XML parser context 15005 * @ctxt: an XML parser context
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
15768 if (stream == NULL) { 15769 if (stream == NULL) {
15769 xmlFreeParserInputBuffer(input); 15770 xmlFreeParserInputBuffer(input);
15770 return (NULL); 15771 return (NULL);
15771 } 15772 }
15772 inputPush(ctxt, stream); 15773 inputPush(ctxt, stream);
15773 return (xmlDoRead(ctxt, URL, encoding, options, 1)); 15774 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15774 } 15775 }
15775 15776
15776 #define bottom_parser 15777 #define bottom_parser
15777 #include "elfgcchack.h" 15778 #include "elfgcchack.h"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698