|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define IN_LIBXML |
|
|
#include "libxml.h" |
|
|
#ifdef LIBXML_HTML_ENABLED |
|
|
|
|
|
#include <string.h> |
|
|
#include <ctype.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
#include <libxml/HTMLparser.h> |
|
|
#include <libxml/xmlmemory.h> |
|
|
#include <libxml/tree.h> |
|
|
#include <libxml/parser.h> |
|
|
#include <libxml/parserInternals.h> |
|
|
#include <libxml/xmlerror.h> |
|
|
#include <libxml/HTMLtree.h> |
|
|
#include <libxml/entities.h> |
|
|
#include <libxml/encoding.h> |
|
|
#include <libxml/xmlIO.h> |
|
|
#include <libxml/uri.h> |
|
|
|
|
|
#include "private/buf.h" |
|
|
#include "private/dict.h" |
|
|
#include "private/enc.h" |
|
|
#include "private/error.h" |
|
|
#include "private/html.h" |
|
|
#include "private/io.h" |
|
|
#include "private/parser.h" |
|
|
#include "private/tree.h" |
|
|
|
|
|
#define HTML_MAX_NAMELEN 1000 |
|
|
#define HTML_PARSER_BIG_BUFFER_SIZE 1000 |
|
|
#define HTML_PARSER_BUFFER_SIZE 100 |
|
|
|
|
|
#define IS_WS_HTML(c) \ |
|
|
(((c) == 0x20) || \ |
|
|
(((c) >= 0x09) && ((c) <= 0x0D) && ((c) != 0x0B))) |
|
|
|
|
|
#define IS_HEX_DIGIT(c) \ |
|
|
((IS_ASCII_DIGIT(c)) || \ |
|
|
((((c) | 0x20) >= 'a') && (((c) | 0x20) <= 'f'))) |
|
|
|
|
|
#define IS_UPPER(c) \ |
|
|
(((c) >= 'A') && ((c) <= 'Z')) |
|
|
|
|
|
#define IS_ALNUM(c) \ |
|
|
(IS_ASCII_LETTER(c) || IS_ASCII_DIGIT(c)) |
|
|
|
|
|
typedef const unsigned htmlAsciiMask[2]; |
|
|
|
|
|
static htmlAsciiMask MASK_DQ = { |
|
|
0, |
|
|
1u << ('"' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_SQ = { |
|
|
0, |
|
|
1u << ('\'' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_GT = { |
|
|
0, |
|
|
1u << ('>' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_DASH = { |
|
|
0, |
|
|
1u << ('-' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_WS_GT = { |
|
|
1u << 0x09 | 1u << 0x0A | 1u << 0x0C | 1u << 0x0D, |
|
|
1u << (' ' - 32) | 1u << ('>' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_DQ_GT = { |
|
|
0, |
|
|
1u << ('"' - 32) | 1u << ('>' - 32), |
|
|
}; |
|
|
static htmlAsciiMask MASK_SQ_GT = { |
|
|
0, |
|
|
1u << ('\'' - 32) | 1u << ('>' - 32), |
|
|
}; |
|
|
|
|
|
static int htmlOmittedDefaultValue = 1; |
|
|
|
|
|
static int |
|
|
htmlParseElementInternal(htmlParserCtxtPtr ctxt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlErrMemory(xmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
xmlCtxtErrMemory(ctxt); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void LIBXML_ATTR_FORMAT(3,0) |
|
|
htmlParseErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, |
|
|
const char *msg, const xmlChar *str1, const xmlChar *str2) |
|
|
{ |
|
|
xmlCtxtErr(ctxt, NULL, XML_FROM_HTML, error, XML_ERR_ERROR, |
|
|
str1, str2, NULL, 0, msg, str1, str2); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value) |
|
|
{ |
|
|
if ((ctxt->html < 3) && (xmlStrEqual(value, BAD_CAST "head"))) |
|
|
ctxt->html = 3; |
|
|
if ((ctxt->html < 10) && (xmlStrEqual(value, BAD_CAST "body"))) |
|
|
ctxt->html = 10; |
|
|
if (ctxt->nameNr >= ctxt->nameMax) { |
|
|
size_t newSize = ctxt->nameMax * 2; |
|
|
const xmlChar **tmp; |
|
|
|
|
|
tmp = xmlRealloc((xmlChar **) ctxt->nameTab, |
|
|
newSize * sizeof(ctxt->nameTab[0])); |
|
|
if (tmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
return (-1); |
|
|
} |
|
|
ctxt->nameTab = tmp; |
|
|
ctxt->nameMax = newSize; |
|
|
} |
|
|
ctxt->nameTab[ctxt->nameNr] = value; |
|
|
ctxt->name = value; |
|
|
return (ctxt->nameNr++); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const xmlChar * |
|
|
htmlnamePop(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
const xmlChar *ret; |
|
|
|
|
|
if (ctxt->nameNr <= 0) |
|
|
return (NULL); |
|
|
ctxt->nameNr--; |
|
|
if (ctxt->nameNr < 0) |
|
|
return (NULL); |
|
|
if (ctxt->nameNr > 0) |
|
|
ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; |
|
|
else |
|
|
ctxt->name = NULL; |
|
|
ret = ctxt->nameTab[ctxt->nameNr]; |
|
|
ctxt->nameTab[ctxt->nameNr] = NULL; |
|
|
return (ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlNodeInfoPush(htmlParserCtxtPtr ctxt, htmlParserNodeInfo *value) |
|
|
{ |
|
|
if (ctxt->nodeInfoNr >= ctxt->nodeInfoMax) { |
|
|
if (ctxt->nodeInfoMax == 0) |
|
|
ctxt->nodeInfoMax = 5; |
|
|
ctxt->nodeInfoMax *= 2; |
|
|
ctxt->nodeInfoTab = (htmlParserNodeInfo *) |
|
|
xmlRealloc((htmlParserNodeInfo *)ctxt->nodeInfoTab, |
|
|
ctxt->nodeInfoMax * |
|
|
sizeof(ctxt->nodeInfoTab[0])); |
|
|
if (ctxt->nodeInfoTab == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
return (0); |
|
|
} |
|
|
} |
|
|
ctxt->nodeInfoTab[ctxt->nodeInfoNr] = *value; |
|
|
ctxt->nodeInfo = &ctxt->nodeInfoTab[ctxt->nodeInfoNr]; |
|
|
return (ctxt->nodeInfoNr++); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static htmlParserNodeInfo * |
|
|
htmlNodeInfoPop(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
if (ctxt->nodeInfoNr <= 0) |
|
|
return (NULL); |
|
|
ctxt->nodeInfoNr--; |
|
|
if (ctxt->nodeInfoNr < 0) |
|
|
return (NULL); |
|
|
if (ctxt->nodeInfoNr > 0) |
|
|
ctxt->nodeInfo = &ctxt->nodeInfoTab[ctxt->nodeInfoNr - 1]; |
|
|
else |
|
|
ctxt->nodeInfo = NULL; |
|
|
return &ctxt->nodeInfoTab[ctxt->nodeInfoNr]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define UPPER (toupper(*ctxt->input->cur)) |
|
|
|
|
|
#define SKIP(val) ctxt->input->cur += (val),ctxt->input->col+=(val) |
|
|
|
|
|
#define NXT(val) ctxt->input->cur[(val)] |
|
|
|
|
|
#define UPP(val) (toupper(ctxt->input->cur[(val)])) |
|
|
|
|
|
#define CUR_PTR ctxt->input->cur |
|
|
#define BASE_PTR ctxt->input->base |
|
|
|
|
|
#define SHRINK \ |
|
|
if ((!PARSER_PROGRESSIVE(ctxt)) && \ |
|
|
(ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \ |
|
|
(ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \ |
|
|
xmlParserShrink(ctxt); |
|
|
|
|
|
#define GROW \ |
|
|
if ((!PARSER_PROGRESSIVE(ctxt)) && \ |
|
|
(ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \ |
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
#define SKIP_BLANKS htmlSkipBlankChars(ctxt) |
|
|
|
|
|
|
|
|
|
|
|
#define CUR (*ctxt->input->cur) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlChar * |
|
|
htmlFindEncoding(xmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *start, *cur, *end; |
|
|
xmlChar *ret; |
|
|
|
|
|
if ((ctxt == NULL) || (ctxt->input == NULL) || |
|
|
(ctxt->input->flags & XML_INPUT_HAS_ENCODING)) |
|
|
return(NULL); |
|
|
if ((ctxt->input->cur == NULL) || (ctxt->input->end == NULL)) |
|
|
return(NULL); |
|
|
|
|
|
start = ctxt->input->cur; |
|
|
end = ctxt->input->end; |
|
|
|
|
|
if (*end != 0) |
|
|
return(NULL); |
|
|
|
|
|
cur = xmlStrcasestr(start, BAD_CAST "HTTP-EQUIV"); |
|
|
if (cur == NULL) |
|
|
return(NULL); |
|
|
cur = xmlStrcasestr(cur, BAD_CAST "CONTENT"); |
|
|
if (cur == NULL) |
|
|
return(NULL); |
|
|
cur = xmlStrcasestr(cur, BAD_CAST "CHARSET="); |
|
|
if (cur == NULL) |
|
|
return(NULL); |
|
|
cur += 8; |
|
|
start = cur; |
|
|
while ((IS_ALNUM(*cur)) || |
|
|
(*cur == '-') || (*cur == '_') || (*cur == ':') || (*cur == '/')) |
|
|
cur++; |
|
|
if (cur == start) |
|
|
return(NULL); |
|
|
ret = xmlStrndup(start, cur - start); |
|
|
if (ret == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
return(ret); |
|
|
} |
|
|
|
|
|
static int |
|
|
htmlMaskMatch(htmlAsciiMask mask, unsigned c) { |
|
|
if (c >= 64) |
|
|
return(0); |
|
|
return((mask[c/32] >> (c & 31)) & 1); |
|
|
} |
|
|
|
|
|
static int |
|
|
htmlValidateUtf8(xmlParserCtxtPtr ctxt, const xmlChar *str, size_t len) { |
|
|
unsigned c = str[0]; |
|
|
int size; |
|
|
|
|
|
if (c < 0xC2) { |
|
|
goto invalid; |
|
|
} else if (c < 0xE0) { |
|
|
if (len < 2) |
|
|
goto incomplete; |
|
|
if ((str[1] & 0xC0) != 0x80) |
|
|
goto invalid; |
|
|
size = 2; |
|
|
} else if (c < 0xF0) { |
|
|
unsigned v; |
|
|
|
|
|
if (len < 3) |
|
|
goto incomplete; |
|
|
|
|
|
v = str[1] << 8 | str[2]; |
|
|
v |= c << 16; |
|
|
|
|
|
if (((v & 0x00C0C0) != 0x008080) || |
|
|
((v & 0x0F2000) == 0x000000) || |
|
|
((v & 0x0F2000) == 0x0D2000)) |
|
|
goto invalid; |
|
|
|
|
|
size = 3; |
|
|
} else { |
|
|
unsigned v; |
|
|
|
|
|
if (len < 4) |
|
|
goto incomplete; |
|
|
|
|
|
v = c << 24 | str[1] << 16 | str[2] << 8 | str[3]; |
|
|
|
|
|
if (((v & 0x00C0C0C0) != 0x00808080) || |
|
|
(v < 0xF0900000) || (v >= 0xF4900000)) |
|
|
goto invalid; |
|
|
|
|
|
size = 4; |
|
|
} |
|
|
|
|
|
return(size); |
|
|
|
|
|
incomplete: |
|
|
return(0); |
|
|
|
|
|
invalid: |
|
|
|
|
|
if ((ctxt->input->flags & XML_INPUT_ENCODING_ERROR) == 0) { |
|
|
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING, |
|
|
"Invalid bytes in character encoding", NULL, NULL); |
|
|
ctxt->input->flags |= XML_INPUT_ENCODING_ERROR; |
|
|
} |
|
|
|
|
|
return(-1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlSkipBlankChars(xmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *cur = ctxt->input->cur; |
|
|
size_t avail = ctxt->input->end - cur; |
|
|
int res = 0; |
|
|
int line = ctxt->input->line; |
|
|
int col = ctxt->input->col; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
if (avail == 0) { |
|
|
ctxt->input->cur = cur; |
|
|
GROW; |
|
|
cur = ctxt->input->cur; |
|
|
avail = ctxt->input->end - cur; |
|
|
|
|
|
if (avail == 0) |
|
|
break; |
|
|
} |
|
|
|
|
|
if (*cur == '\n') { |
|
|
line++; |
|
|
col = 1; |
|
|
} else if (IS_WS_HTML(*cur)) { |
|
|
col++; |
|
|
} else { |
|
|
break; |
|
|
} |
|
|
|
|
|
cur += 1; |
|
|
avail -= 1; |
|
|
|
|
|
if (res < INT_MAX) |
|
|
res++; |
|
|
} |
|
|
|
|
|
ctxt->input->cur = cur; |
|
|
ctxt->input->line = line; |
|
|
ctxt->input->col = col; |
|
|
|
|
|
if (res > 8) |
|
|
GROW; |
|
|
|
|
|
return(res); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DATA_RCDATA 1 |
|
|
#define DATA_RAWTEXT 2 |
|
|
#define DATA_PLAINTEXT 3 |
|
|
#define DATA_SCRIPT 4 |
|
|
#define DATA_SCRIPT_ESC1 5 |
|
|
#define DATA_SCRIPT_ESC2 6 |
|
|
|
|
|
static const htmlElemDesc |
|
|
html40ElementTable[] = { |
|
|
{ "a", 0, 0, 0, 0, 0, 0, 1, "anchor ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "abbr", 0, 0, 0, 0, 0, 0, 1, "abbreviated form", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "acronym", 0, 0, 0, 0, 0, 0, 1, "", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "address", 0, 0, 0, 0, 0, 0, 0, "information on author ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "applet", 0, 0, 0, 0, 1, 1, 2, "java applet ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "area", 0, 2, 2, 1, 0, 0, 0, "client-side image map area ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "b", 0, 3, 0, 0, 0, 0, 1, "bold text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "base", 0, 2, 2, 1, 0, 0, 0, "document base uri ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "basefont", 0, 2, 2, 1, 1, 1, 1, "base font size " , |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "bdo", 0, 0, 0, 0, 0, 0, 1, "i18n bidi over-ride ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "big", 0, 3, 0, 0, 0, 0, 1, "large text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "blockquote", 0, 0, 0, 0, 0, 0, 0, "long quotation ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "body", 1, 1, 0, 0, 0, 0, 0, "document body ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "br", 0, 2, 2, 1, 0, 0, 1, "forced line break ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "button", 0, 0, 0, 0, 0, 0, 2, "push button ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "caption", 0, 0, 0, 0, 0, 0, 0, "table caption ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "center", 0, 3, 0, 0, 1, 1, 0, "shorthand for div align=center ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "cite", 0, 0, 0, 0, 0, 0, 1, "citation", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "code", 0, 0, 0, 0, 0, 0, 1, "computer code fragment", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "col", 0, 2, 2, 1, 0, 0, 0, "table column ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "colgroup", 0, 1, 0, 0, 0, 0, 0, "table column group ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "dd", 0, 1, 0, 0, 0, 0, 0, "definition description ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "del", 0, 0, 0, 0, 0, 0, 2, "deleted text ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "dfn", 0, 0, 0, 0, 0, 0, 1, "instance definition", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "dir", 0, 0, 0, 0, 1, 1, 0, "directory list", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "div", 0, 0, 0, 0, 0, 0, 0, "generic language/style container", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "dl", 0, 0, 0, 0, 0, 0, 0, "definition list ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "dt", 0, 1, 0, 0, 0, 0, 0, "definition term ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "em", 0, 3, 0, 0, 0, 0, 1, "emphasis", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "embed", 0, 1, 0, 0, 1, 1, 1, "generic embedded object ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "fieldset", 0, 0, 0, 0, 0, 0, 0, "form control group ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "font", 0, 3, 0, 0, 1, 1, 1, "local change to font ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "form", 0, 0, 0, 0, 0, 0, 0, "interactive form ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "frame", 0, 2, 2, 1, 0, 2, 0, "subwindow " , |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "frameset", 0, 0, 0, 0, 0, 2, 0, "window subdivision" , |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h1", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h2", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h3", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h4", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h5", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "h6", 0, 0, 0, 0, 0, 0, 0, "heading ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "head", 1, 1, 0, 0, 0, 0, 0, "document head ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "hr", 0, 2, 2, 1, 0, 0, 0, "horizontal rule " , |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "html", 1, 1, 0, 0, 0, 0, 0, "document root element ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "i", 0, 3, 0, 0, 0, 0, 1, "italic text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "iframe", 0, 0, 0, 0, 0, 1, 2, "inline subwindow ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RAWTEXT |
|
|
}, |
|
|
{ "img", 0, 2, 2, 1, 0, 0, 1, "embedded image ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "input", 0, 2, 2, 1, 0, 0, 1, "form control ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "ins", 0, 0, 0, 0, 0, 0, 2, "inserted text", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "isindex", 0, 2, 2, 1, 1, 1, 0, "single line prompt ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "kbd", 0, 0, 0, 0, 0, 0, 1, "text to be entered by the user", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "label", 0, 0, 0, 0, 0, 0, 1, "form field label text ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "legend", 0, 0, 0, 0, 0, 0, 0, "fieldset legend ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "li", 0, 1, 1, 0, 0, 0, 0, "list item ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "link", 0, 2, 2, 1, 0, 0, 0, "a media-independent link ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "map", 0, 0, 0, 0, 0, 0, 2, "client-side image map ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "menu", 0, 0, 0, 0, 1, 1, 0, "menu list ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "meta", 0, 2, 2, 1, 0, 0, 0, "generic metainformation ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "noembed", 0, 0, 0, 0, 0, 0, 0, "", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RAWTEXT |
|
|
}, |
|
|
{ "noframes", 0, 0, 0, 0, 0, 2, 0, "alternate content container for non frame-based rendering ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RAWTEXT |
|
|
}, |
|
|
{ "noscript", 0, 0, 0, 0, 0, 0, 0, "alternate content container for non script-based rendering ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "object", 0, 0, 0, 0, 0, 0, 2, "generic embedded object ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "ol", 0, 0, 0, 0, 0, 0, 0, "ordered list ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "optgroup", 0, 0, 0, 0, 0, 0, 0, "option group ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "option", 0, 1, 0, 0, 0, 0, 0, "selectable choice " , |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "p", 0, 1, 0, 0, 0, 0, 0, "paragraph ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "param", 0, 2, 2, 1, 0, 0, 0, "named property value ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "plaintext", 0, 0, 0, 0, 0, 0, 0, "", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_PLAINTEXT |
|
|
}, |
|
|
{ "pre", 0, 0, 0, 0, 0, 0, 0, "preformatted text ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "q", 0, 0, 0, 0, 0, 0, 1, "short inline quotation ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "s", 0, 3, 0, 0, 1, 1, 1, "strike-through text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "samp", 0, 0, 0, 0, 0, 0, 1, "sample program output, scripts, etc.", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "script", 0, 0, 0, 0, 0, 0, 2, "script statements ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_SCRIPT |
|
|
}, |
|
|
{ "select", 0, 0, 0, 0, 0, 0, 1, "option selector ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "small", 0, 3, 0, 0, 0, 0, 1, "small text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "span", 0, 0, 0, 0, 0, 0, 1, "generic language/style container ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "strike", 0, 3, 0, 0, 1, 1, 1, "strike-through text", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "strong", 0, 3, 0, 0, 0, 0, 1, "strong emphasis", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "style", 0, 0, 0, 0, 0, 0, 0, "style info ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RAWTEXT |
|
|
}, |
|
|
{ "sub", 0, 3, 0, 0, 0, 0, 1, "subscript", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "sup", 0, 3, 0, 0, 0, 0, 1, "superscript ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "table", 0, 0, 0, 0, 0, 0, 0, "", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "tbody", 1, 0, 0, 0, 0, 0, 0, "table body ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "td", 0, 0, 0, 0, 0, 0, 0, "table data cell", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "textarea", 0, 0, 0, 0, 0, 0, 1, "multi-line text field ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RCDATA |
|
|
}, |
|
|
{ "tfoot", 0, 1, 0, 0, 0, 0, 0, "table footer ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "th", 0, 1, 0, 0, 0, 0, 0, "table header cell", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "thead", 0, 1, 0, 0, 0, 0, 0, "table header ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "title", 0, 0, 0, 0, 0, 0, 0, "document title ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RCDATA |
|
|
}, |
|
|
{ "tr", 0, 0, 0, 0, 0, 0, 0, "table row ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "tt", 0, 3, 0, 0, 0, 0, 1, "teletype or monospaced text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "u", 0, 3, 0, 0, 1, 1, 1, "underlined text style", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "ul", 0, 0, 0, 0, 0, 0, 0, "unordered list ", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "var", 0, 0, 0, 0, 0, 0, 1, "instance of a variable or program argument", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
0 |
|
|
}, |
|
|
{ "xmp", 0, 0, 0, 0, 0, 0, 1, "", |
|
|
NULL, NULL, NULL, NULL, NULL, |
|
|
DATA_RAWTEXT |
|
|
} |
|
|
}; |
|
|
|
|
|
typedef struct { |
|
|
const char *oldTag; |
|
|
const char *newTag; |
|
|
} htmlStartCloseEntry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const htmlStartCloseEntry htmlStartClose[] = { |
|
|
{ "a", "a" }, |
|
|
{ "a", "fieldset" }, |
|
|
{ "a", "table" }, |
|
|
{ "a", "td" }, |
|
|
{ "a", "th" }, |
|
|
{ "address", "dd" }, |
|
|
{ "address", "dl" }, |
|
|
{ "address", "dt" }, |
|
|
{ "address", "form" }, |
|
|
{ "address", "li" }, |
|
|
{ "address", "ul" }, |
|
|
{ "b", "center" }, |
|
|
{ "b", "p" }, |
|
|
{ "b", "td" }, |
|
|
{ "b", "th" }, |
|
|
{ "big", "p" }, |
|
|
{ "caption", "col" }, |
|
|
{ "caption", "colgroup" }, |
|
|
{ "caption", "tbody" }, |
|
|
{ "caption", "tfoot" }, |
|
|
{ "caption", "thead" }, |
|
|
{ "caption", "tr" }, |
|
|
{ "col", "col" }, |
|
|
{ "col", "colgroup" }, |
|
|
{ "col", "tbody" }, |
|
|
{ "col", "tfoot" }, |
|
|
{ "col", "thead" }, |
|
|
{ "col", "tr" }, |
|
|
{ "colgroup", "colgroup" }, |
|
|
{ "colgroup", "tbody" }, |
|
|
{ "colgroup", "tfoot" }, |
|
|
{ "colgroup", "thead" }, |
|
|
{ "colgroup", "tr" }, |
|
|
{ "dd", "dt" }, |
|
|
{ "dir", "dd" }, |
|
|
{ "dir", "dl" }, |
|
|
{ "dir", "dt" }, |
|
|
{ "dir", "form" }, |
|
|
{ "dir", "ul" }, |
|
|
{ "dl", "form" }, |
|
|
{ "dl", "li" }, |
|
|
{ "dt", "dd" }, |
|
|
{ "dt", "dl" }, |
|
|
{ "font", "center" }, |
|
|
{ "font", "td" }, |
|
|
{ "font", "th" }, |
|
|
{ "form", "form" }, |
|
|
{ "h1", "fieldset" }, |
|
|
{ "h1", "form" }, |
|
|
{ "h1", "li" }, |
|
|
{ "h1", "p" }, |
|
|
{ "h1", "table" }, |
|
|
{ "h2", "fieldset" }, |
|
|
{ "h2", "form" }, |
|
|
{ "h2", "li" }, |
|
|
{ "h2", "p" }, |
|
|
{ "h2", "table" }, |
|
|
{ "h3", "fieldset" }, |
|
|
{ "h3", "form" }, |
|
|
{ "h3", "li" }, |
|
|
{ "h3", "p" }, |
|
|
{ "h3", "table" }, |
|
|
{ "h4", "fieldset" }, |
|
|
{ "h4", "form" }, |
|
|
{ "h4", "li" }, |
|
|
{ "h4", "p" }, |
|
|
{ "h4", "table" }, |
|
|
{ "h5", "fieldset" }, |
|
|
{ "h5", "form" }, |
|
|
{ "h5", "li" }, |
|
|
{ "h5", "p" }, |
|
|
{ "h5", "table" }, |
|
|
{ "h6", "fieldset" }, |
|
|
{ "h6", "form" }, |
|
|
{ "h6", "li" }, |
|
|
{ "h6", "p" }, |
|
|
{ "h6", "table" }, |
|
|
{ "head", "a" }, |
|
|
{ "head", "abbr" }, |
|
|
{ "head", "acronym" }, |
|
|
{ "head", "address" }, |
|
|
{ "head", "b" }, |
|
|
{ "head", "bdo" }, |
|
|
{ "head", "big" }, |
|
|
{ "head", "blockquote" }, |
|
|
{ "head", "body" }, |
|
|
{ "head", "br" }, |
|
|
{ "head", "center" }, |
|
|
{ "head", "cite" }, |
|
|
{ "head", "code" }, |
|
|
{ "head", "dd" }, |
|
|
{ "head", "dfn" }, |
|
|
{ "head", "dir" }, |
|
|
{ "head", "div" }, |
|
|
{ "head", "dl" }, |
|
|
{ "head", "dt" }, |
|
|
{ "head", "em" }, |
|
|
{ "head", "fieldset" }, |
|
|
{ "head", "font" }, |
|
|
{ "head", "form" }, |
|
|
{ "head", "frameset" }, |
|
|
{ "head", "h1" }, |
|
|
{ "head", "h2" }, |
|
|
{ "head", "h3" }, |
|
|
{ "head", "h4" }, |
|
|
{ "head", "h5" }, |
|
|
{ "head", "h6" }, |
|
|
{ "head", "hr" }, |
|
|
{ "head", "i" }, |
|
|
{ "head", "iframe" }, |
|
|
{ "head", "img" }, |
|
|
{ "head", "kbd" }, |
|
|
{ "head", "li" }, |
|
|
{ "head", "listing" }, |
|
|
{ "head", "map" }, |
|
|
{ "head", "menu" }, |
|
|
{ "head", "ol" }, |
|
|
{ "head", "p" }, |
|
|
{ "head", "pre" }, |
|
|
{ "head", "q" }, |
|
|
{ "head", "s" }, |
|
|
{ "head", "samp" }, |
|
|
{ "head", "small" }, |
|
|
{ "head", "span" }, |
|
|
{ "head", "strike" }, |
|
|
{ "head", "strong" }, |
|
|
{ "head", "sub" }, |
|
|
{ "head", "sup" }, |
|
|
{ "head", "table" }, |
|
|
{ "head", "tt" }, |
|
|
{ "head", "u" }, |
|
|
{ "head", "ul" }, |
|
|
{ "head", "var" }, |
|
|
{ "head", "xmp" }, |
|
|
{ "hr", "form" }, |
|
|
{ "i", "center" }, |
|
|
{ "i", "p" }, |
|
|
{ "i", "td" }, |
|
|
{ "i", "th" }, |
|
|
{ "legend", "fieldset" }, |
|
|
{ "li", "li" }, |
|
|
{ "link", "body" }, |
|
|
{ "link", "frameset" }, |
|
|
{ "listing", "dd" }, |
|
|
{ "listing", "dl" }, |
|
|
{ "listing", "dt" }, |
|
|
{ "listing", "fieldset" }, |
|
|
{ "listing", "form" }, |
|
|
{ "listing", "li" }, |
|
|
{ "listing", "table" }, |
|
|
{ "listing", "ul" }, |
|
|
{ "menu", "dd" }, |
|
|
{ "menu", "dl" }, |
|
|
{ "menu", "dt" }, |
|
|
{ "menu", "form" }, |
|
|
{ "menu", "ul" }, |
|
|
{ "ol", "form" }, |
|
|
{ "option", "optgroup" }, |
|
|
{ "option", "option" }, |
|
|
{ "p", "address" }, |
|
|
{ "p", "blockquote" }, |
|
|
{ "p", "body" }, |
|
|
{ "p", "caption" }, |
|
|
{ "p", "center" }, |
|
|
{ "p", "col" }, |
|
|
{ "p", "colgroup" }, |
|
|
{ "p", "dd" }, |
|
|
{ "p", "dir" }, |
|
|
{ "p", "div" }, |
|
|
{ "p", "dl" }, |
|
|
{ "p", "dt" }, |
|
|
{ "p", "fieldset" }, |
|
|
{ "p", "form" }, |
|
|
{ "p", "frameset" }, |
|
|
{ "p", "h1" }, |
|
|
{ "p", "h2" }, |
|
|
{ "p", "h3" }, |
|
|
{ "p", "h4" }, |
|
|
{ "p", "h5" }, |
|
|
{ "p", "h6" }, |
|
|
{ "p", "head" }, |
|
|
{ "p", "hr" }, |
|
|
{ "p", "li" }, |
|
|
{ "p", "listing" }, |
|
|
{ "p", "menu" }, |
|
|
{ "p", "ol" }, |
|
|
{ "p", "p" }, |
|
|
{ "p", "pre" }, |
|
|
{ "p", "table" }, |
|
|
{ "p", "tbody" }, |
|
|
{ "p", "td" }, |
|
|
{ "p", "tfoot" }, |
|
|
{ "p", "th" }, |
|
|
{ "p", "title" }, |
|
|
{ "p", "tr" }, |
|
|
{ "p", "ul" }, |
|
|
{ "p", "xmp" }, |
|
|
{ "pre", "dd" }, |
|
|
{ "pre", "dl" }, |
|
|
{ "pre", "dt" }, |
|
|
{ "pre", "fieldset" }, |
|
|
{ "pre", "form" }, |
|
|
{ "pre", "li" }, |
|
|
{ "pre", "table" }, |
|
|
{ "pre", "ul" }, |
|
|
{ "s", "p" }, |
|
|
{ "script", "noscript" }, |
|
|
{ "small", "p" }, |
|
|
{ "span", "td" }, |
|
|
{ "span", "th" }, |
|
|
{ "strike", "p" }, |
|
|
{ "style", "body" }, |
|
|
{ "style", "frameset" }, |
|
|
{ "tbody", "tbody" }, |
|
|
{ "tbody", "tfoot" }, |
|
|
{ "td", "tbody" }, |
|
|
{ "td", "td" }, |
|
|
{ "td", "tfoot" }, |
|
|
{ "td", "th" }, |
|
|
{ "td", "tr" }, |
|
|
{ "tfoot", "tbody" }, |
|
|
{ "th", "tbody" }, |
|
|
{ "th", "td" }, |
|
|
{ "th", "tfoot" }, |
|
|
{ "th", "th" }, |
|
|
{ "th", "tr" }, |
|
|
{ "thead", "tbody" }, |
|
|
{ "thead", "tfoot" }, |
|
|
{ "title", "body" }, |
|
|
{ "title", "frameset" }, |
|
|
{ "tr", "tbody" }, |
|
|
{ "tr", "tfoot" }, |
|
|
{ "tr", "tr" }, |
|
|
{ "tt", "p" }, |
|
|
{ "u", "p" }, |
|
|
{ "u", "td" }, |
|
|
{ "u", "th" }, |
|
|
{ "ul", "address" }, |
|
|
{ "ul", "form" }, |
|
|
{ "ul", "menu" }, |
|
|
{ "ul", "pre" }, |
|
|
{ "xmp", "dd" }, |
|
|
{ "xmp", "dl" }, |
|
|
{ "xmp", "dt" }, |
|
|
{ "xmp", "fieldset" }, |
|
|
{ "xmp", "form" }, |
|
|
{ "xmp", "li" }, |
|
|
{ "xmp", "table" }, |
|
|
{ "xmp", "ul" } |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *const htmlNoContentElements[] = { |
|
|
"html", |
|
|
"head", |
|
|
NULL |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *const htmlScriptAttributes[] = { |
|
|
"onclick", |
|
|
"ondblclick", |
|
|
"onmousedown", |
|
|
"onmouseup", |
|
|
"onmouseover", |
|
|
"onmousemove", |
|
|
"onmouseout", |
|
|
"onkeypress", |
|
|
"onkeydown", |
|
|
"onkeyup", |
|
|
"onload", |
|
|
"onunload", |
|
|
"onfocus", |
|
|
"onblur", |
|
|
"onsubmit", |
|
|
"onreset", |
|
|
"onchange", |
|
|
"onselect" |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
const char *name; |
|
|
int priority; |
|
|
} elementPriority; |
|
|
|
|
|
static const elementPriority htmlEndPriority[] = { |
|
|
{"div", 150}, |
|
|
{"td", 160}, |
|
|
{"th", 160}, |
|
|
{"tr", 170}, |
|
|
{"thead", 180}, |
|
|
{"tbody", 180}, |
|
|
{"tfoot", 180}, |
|
|
{"table", 190}, |
|
|
{"head", 200}, |
|
|
{"body", 200}, |
|
|
{"html", 220}, |
|
|
{NULL, 100} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParserFinishElementParsing(htmlParserCtxtPtr ctxt) { |
|
|
|
|
|
|
|
|
|
|
|
if ( ctxt->node != NULL && ctxt->record_info ) { |
|
|
ctxt->nodeInfo->end_pos = ctxt->input->consumed + |
|
|
(CUR_PTR - ctxt->input->base); |
|
|
ctxt->nodeInfo->end_line = ctxt->input->line; |
|
|
ctxt->nodeInfo->node = ctxt->node; |
|
|
xmlParserAddNodeInfo(ctxt, ctxt->nodeInfo); |
|
|
htmlNodeInfoPop(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
htmlInitAutoClose(void) { |
|
|
} |
|
|
|
|
|
static int |
|
|
htmlCompareTags(const void *key, const void *member) { |
|
|
const xmlChar *tag = (const xmlChar *) key; |
|
|
const htmlElemDesc *desc = (const htmlElemDesc *) member; |
|
|
|
|
|
return(xmlStrcasecmp(tag, BAD_CAST desc->name)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const htmlElemDesc * |
|
|
htmlTagLookup(const xmlChar *tag) { |
|
|
if (tag == NULL) |
|
|
return(NULL); |
|
|
|
|
|
return((const htmlElemDesc *) bsearch(tag, html40ElementTable, |
|
|
sizeof(html40ElementTable) / sizeof(htmlElemDesc), |
|
|
sizeof(htmlElemDesc), htmlCompareTags)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlGetEndPriority (const xmlChar *name) { |
|
|
int i = 0; |
|
|
|
|
|
while ((htmlEndPriority[i].name != NULL) && |
|
|
(!xmlStrEqual((const xmlChar *)htmlEndPriority[i].name, name))) |
|
|
i++; |
|
|
|
|
|
return(htmlEndPriority[i].priority); |
|
|
} |
|
|
|
|
|
|
|
|
static int |
|
|
htmlCompareStartClose(const void *vkey, const void *member) { |
|
|
const htmlStartCloseEntry *key = (const htmlStartCloseEntry *) vkey; |
|
|
const htmlStartCloseEntry *entry = (const htmlStartCloseEntry *) member; |
|
|
int ret; |
|
|
|
|
|
ret = strcmp(key->oldTag, entry->oldTag); |
|
|
if (ret == 0) |
|
|
ret = strcmp(key->newTag, entry->newTag); |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlCheckAutoClose(const xmlChar * newtag, const xmlChar * oldtag) |
|
|
{ |
|
|
htmlStartCloseEntry key; |
|
|
void *res; |
|
|
|
|
|
key.oldTag = (const char *) oldtag; |
|
|
key.newTag = (const char *) newtag; |
|
|
res = bsearch(&key, htmlStartClose, |
|
|
sizeof(htmlStartClose) / sizeof(htmlStartCloseEntry), |
|
|
sizeof(htmlStartCloseEntry), htmlCompareStartClose); |
|
|
return(res != NULL); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlAutoCloseOnClose(htmlParserCtxtPtr ctxt, const xmlChar * newtag) |
|
|
{ |
|
|
const htmlElemDesc *info; |
|
|
int i, priority; |
|
|
|
|
|
if (ctxt->options & HTML_PARSE_HTML5) |
|
|
return; |
|
|
|
|
|
priority = htmlGetEndPriority(newtag); |
|
|
|
|
|
for (i = (ctxt->nameNr - 1); i >= 0; i--) { |
|
|
|
|
|
if (xmlStrEqual(newtag, ctxt->nameTab[i])) |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (htmlGetEndPriority(ctxt->nameTab[i]) > priority) |
|
|
return; |
|
|
} |
|
|
if (i < 0) |
|
|
return; |
|
|
|
|
|
while (!xmlStrEqual(newtag, ctxt->name)) { |
|
|
info = htmlTagLookup(ctxt->name); |
|
|
if ((info != NULL) && (info->endTag == 3)) { |
|
|
htmlParseErr(ctxt, XML_ERR_TAG_NAME_MISMATCH, |
|
|
"Opening and ending tag mismatch: %s and %s\n", |
|
|
newtag, ctxt->name); |
|
|
} |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, ctxt->name); |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlAutoCloseOnEnd(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
if (ctxt->options & HTML_PARSE_HTML5) |
|
|
return; |
|
|
|
|
|
if (ctxt->nameNr == 0) |
|
|
return; |
|
|
for (i = (ctxt->nameNr - 1); i >= 0; i--) { |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, ctxt->name); |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlAutoClose(htmlParserCtxtPtr ctxt, const xmlChar * newtag) |
|
|
{ |
|
|
if (ctxt->options & HTML_PARSE_HTML5) |
|
|
return; |
|
|
|
|
|
if (newtag == NULL) |
|
|
return; |
|
|
|
|
|
while ((ctxt->name != NULL) && |
|
|
(htmlCheckAutoClose(newtag, ctxt->name))) { |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, ctxt->name); |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlAutoCloseTag(htmlDocPtr doc, const xmlChar *name, htmlNodePtr elem) { |
|
|
htmlNodePtr child; |
|
|
|
|
|
if (elem == NULL) return(1); |
|
|
if (xmlStrEqual(name, elem->name)) return(0); |
|
|
if (htmlCheckAutoClose(elem->name, name)) return(1); |
|
|
child = elem->children; |
|
|
while (child != NULL) { |
|
|
if (htmlAutoCloseTag(doc, name, child)) return(1); |
|
|
child = child->next; |
|
|
} |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlIsAutoClosed(htmlDocPtr doc, htmlNodePtr elem) { |
|
|
htmlNodePtr child; |
|
|
|
|
|
if (elem == NULL) return(1); |
|
|
child = elem->children; |
|
|
while (child != NULL) { |
|
|
if (htmlAutoCloseTag(doc, elem->name, child)) return(1); |
|
|
child = child->next; |
|
|
} |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) { |
|
|
int i; |
|
|
|
|
|
if (ctxt->options & (HTML_PARSE_NOIMPLIED | HTML_PARSE_HTML5)) |
|
|
return; |
|
|
if (!htmlOmittedDefaultValue) |
|
|
return; |
|
|
if (xmlStrEqual(newtag, BAD_CAST"html")) |
|
|
return; |
|
|
if (ctxt->nameNr <= 0) { |
|
|
htmlnamePush(ctxt, BAD_CAST"html"); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
|
|
ctxt->sax->startElement(ctxt->userData, BAD_CAST"html", NULL); |
|
|
} |
|
|
if ((xmlStrEqual(newtag, BAD_CAST"body")) || (xmlStrEqual(newtag, BAD_CAST"head"))) |
|
|
return; |
|
|
if ((ctxt->nameNr <= 1) && |
|
|
((xmlStrEqual(newtag, BAD_CAST"script")) || |
|
|
(xmlStrEqual(newtag, BAD_CAST"style")) || |
|
|
(xmlStrEqual(newtag, BAD_CAST"meta")) || |
|
|
(xmlStrEqual(newtag, BAD_CAST"link")) || |
|
|
(xmlStrEqual(newtag, BAD_CAST"title")) || |
|
|
(xmlStrEqual(newtag, BAD_CAST"base")))) { |
|
|
if (ctxt->html >= 3) { |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlnamePush(ctxt, BAD_CAST"head"); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
|
|
ctxt->sax->startElement(ctxt->userData, BAD_CAST"head", NULL); |
|
|
} else if ((!xmlStrEqual(newtag, BAD_CAST"noframes")) && |
|
|
(!xmlStrEqual(newtag, BAD_CAST"frame")) && |
|
|
(!xmlStrEqual(newtag, BAD_CAST"frameset"))) { |
|
|
if (ctxt->html >= 10) { |
|
|
|
|
|
return; |
|
|
} |
|
|
for (i = 0;i < ctxt->nameNr;i++) { |
|
|
if (xmlStrEqual(ctxt->nameTab[i], BAD_CAST"body")) { |
|
|
return; |
|
|
} |
|
|
if (xmlStrEqual(ctxt->nameTab[i], BAD_CAST"head")) { |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
htmlnamePush(ctxt, BAD_CAST"body"); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
|
|
ctxt->sax->startElement(ctxt->userData, BAD_CAST"body", NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlCheckParagraph(htmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *tag; |
|
|
int i; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return(-1); |
|
|
if (ctxt->options & HTML_PARSE_HTML5) |
|
|
return(0); |
|
|
|
|
|
tag = ctxt->name; |
|
|
if (tag == NULL) { |
|
|
htmlAutoClose(ctxt, BAD_CAST"p"); |
|
|
htmlCheckImplied(ctxt, BAD_CAST"p"); |
|
|
htmlnamePush(ctxt, BAD_CAST"p"); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
|
|
ctxt->sax->startElement(ctxt->userData, BAD_CAST"p", NULL); |
|
|
return(1); |
|
|
} |
|
|
if (!htmlOmittedDefaultValue) |
|
|
return(0); |
|
|
for (i = 0; htmlNoContentElements[i] != NULL; i++) { |
|
|
if (xmlStrEqual(tag, BAD_CAST htmlNoContentElements[i])) { |
|
|
htmlAutoClose(ctxt, BAD_CAST"p"); |
|
|
htmlCheckImplied(ctxt, BAD_CAST"p"); |
|
|
htmlnamePush(ctxt, BAD_CAST"p"); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) |
|
|
ctxt->sax->startElement(ctxt->userData, BAD_CAST"p", NULL); |
|
|
return(1); |
|
|
} |
|
|
} |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlIsScriptAttribute(const xmlChar *name) { |
|
|
unsigned int i; |
|
|
|
|
|
if (name == NULL) |
|
|
return(0); |
|
|
|
|
|
|
|
|
|
|
|
if ((name[0] != 'o') || (name[1] != 'n')) |
|
|
return(0); |
|
|
for (i = 0; |
|
|
i < sizeof(htmlScriptAttributes)/sizeof(htmlScriptAttributes[0]); |
|
|
i++) { |
|
|
if (xmlStrEqual(name, (const xmlChar *) htmlScriptAttributes[i])) |
|
|
return(1); |
|
|
} |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const htmlEntityDesc html40EntitiesTable[] = { |
|
|
|
|
|
|
|
|
|
|
|
{ 34, "quot", "quotation mark = APL quote, U+0022 ISOnum" }, |
|
|
{ 38, "amp", "ampersand, U+0026 ISOnum" }, |
|
|
{ 39, "apos", "single quote" }, |
|
|
{ 60, "lt", "less-than sign, U+003C ISOnum" }, |
|
|
{ 62, "gt", "greater-than sign, U+003E ISOnum" }, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ 160, "nbsp", "no-break space = non-breaking space, U+00A0 ISOnum" }, |
|
|
{ 161, "iexcl","inverted exclamation mark, U+00A1 ISOnum" }, |
|
|
{ 162, "cent", "cent sign, U+00A2 ISOnum" }, |
|
|
{ 163, "pound","pound sign, U+00A3 ISOnum" }, |
|
|
{ 164, "curren","currency sign, U+00A4 ISOnum" }, |
|
|
{ 165, "yen", "yen sign = yuan sign, U+00A5 ISOnum" }, |
|
|
{ 166, "brvbar","broken bar = broken vertical bar, U+00A6 ISOnum" }, |
|
|
{ 167, "sect", "section sign, U+00A7 ISOnum" }, |
|
|
{ 168, "uml", "diaeresis = spacing diaeresis, U+00A8 ISOdia" }, |
|
|
{ 169, "copy", "copyright sign, U+00A9 ISOnum" }, |
|
|
{ 170, "ordf", "feminine ordinal indicator, U+00AA ISOnum" }, |
|
|
{ 171, "laquo","left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum" }, |
|
|
{ 172, "not", "not sign, U+00AC ISOnum" }, |
|
|
{ 173, "shy", "soft hyphen = discretionary hyphen, U+00AD ISOnum" }, |
|
|
{ 174, "reg", "registered sign = registered trade mark sign, U+00AE ISOnum" }, |
|
|
{ 175, "macr", "macron = spacing macron = overline = APL overbar, U+00AF ISOdia" }, |
|
|
{ 176, "deg", "degree sign, U+00B0 ISOnum" }, |
|
|
{ 177, "plusmn","plus-minus sign = plus-or-minus sign, U+00B1 ISOnum" }, |
|
|
{ 178, "sup2", "superscript two = superscript digit two = squared, U+00B2 ISOnum" }, |
|
|
{ 179, "sup3", "superscript three = superscript digit three = cubed, U+00B3 ISOnum" }, |
|
|
{ 180, "acute","acute accent = spacing acute, U+00B4 ISOdia" }, |
|
|
{ 181, "micro","micro sign, U+00B5 ISOnum" }, |
|
|
{ 182, "para", "pilcrow sign = paragraph sign, U+00B6 ISOnum" }, |
|
|
{ 183, "middot","middle dot = Georgian comma Greek middle dot, U+00B7 ISOnum" }, |
|
|
{ 184, "cedil","cedilla = spacing cedilla, U+00B8 ISOdia" }, |
|
|
{ 185, "sup1", "superscript one = superscript digit one, U+00B9 ISOnum" }, |
|
|
{ 186, "ordm", "masculine ordinal indicator, U+00BA ISOnum" }, |
|
|
{ 187, "raquo","right-pointing double angle quotation mark right pointing guillemet, U+00BB ISOnum" }, |
|
|
{ 188, "frac14","vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum" }, |
|
|
{ 189, "frac12","vulgar fraction one half = fraction one half, U+00BD ISOnum" }, |
|
|
{ 190, "frac34","vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum" }, |
|
|
{ 191, "iquest","inverted question mark = turned question mark, U+00BF ISOnum" }, |
|
|
{ 192, "Agrave","latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1" }, |
|
|
{ 193, "Aacute","latin capital letter A with acute, U+00C1 ISOlat1" }, |
|
|
{ 194, "Acirc","latin capital letter A with circumflex, U+00C2 ISOlat1" }, |
|
|
{ 195, "Atilde","latin capital letter A with tilde, U+00C3 ISOlat1" }, |
|
|
{ 196, "Auml", "latin capital letter A with diaeresis, U+00C4 ISOlat1" }, |
|
|
{ 197, "Aring","latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1" }, |
|
|
{ 198, "AElig","latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1" }, |
|
|
{ 199, "Ccedil","latin capital letter C with cedilla, U+00C7 ISOlat1" }, |
|
|
{ 200, "Egrave","latin capital letter E with grave, U+00C8 ISOlat1" }, |
|
|
{ 201, "Eacute","latin capital letter E with acute, U+00C9 ISOlat1" }, |
|
|
{ 202, "Ecirc","latin capital letter E with circumflex, U+00CA ISOlat1" }, |
|
|
{ 203, "Euml", "latin capital letter E with diaeresis, U+00CB ISOlat1" }, |
|
|
{ 204, "Igrave","latin capital letter I with grave, U+00CC ISOlat1" }, |
|
|
{ 205, "Iacute","latin capital letter I with acute, U+00CD ISOlat1" }, |
|
|
{ 206, "Icirc","latin capital letter I with circumflex, U+00CE ISOlat1" }, |
|
|
{ 207, "Iuml", "latin capital letter I with diaeresis, U+00CF ISOlat1" }, |
|
|
{ 208, "ETH", "latin capital letter ETH, U+00D0 ISOlat1" }, |
|
|
{ 209, "Ntilde","latin capital letter N with tilde, U+00D1 ISOlat1" }, |
|
|
{ 210, "Ograve","latin capital letter O with grave, U+00D2 ISOlat1" }, |
|
|
{ 211, "Oacute","latin capital letter O with acute, U+00D3 ISOlat1" }, |
|
|
{ 212, "Ocirc","latin capital letter O with circumflex, U+00D4 ISOlat1" }, |
|
|
{ 213, "Otilde","latin capital letter O with tilde, U+00D5 ISOlat1" }, |
|
|
{ 214, "Ouml", "latin capital letter O with diaeresis, U+00D6 ISOlat1" }, |
|
|
{ 215, "times","multiplication sign, U+00D7 ISOnum" }, |
|
|
{ 216, "Oslash","latin capital letter O with stroke latin capital letter O slash, U+00D8 ISOlat1" }, |
|
|
{ 217, "Ugrave","latin capital letter U with grave, U+00D9 ISOlat1" }, |
|
|
{ 218, "Uacute","latin capital letter U with acute, U+00DA ISOlat1" }, |
|
|
{ 219, "Ucirc","latin capital letter U with circumflex, U+00DB ISOlat1" }, |
|
|
{ 220, "Uuml", "latin capital letter U with diaeresis, U+00DC ISOlat1" }, |
|
|
{ 221, "Yacute","latin capital letter Y with acute, U+00DD ISOlat1" }, |
|
|
{ 222, "THORN","latin capital letter THORN, U+00DE ISOlat1" }, |
|
|
{ 223, "szlig","latin small letter sharp s = ess-zed, U+00DF ISOlat1" }, |
|
|
{ 224, "agrave","latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1" }, |
|
|
{ 225, "aacute","latin small letter a with acute, U+00E1 ISOlat1" }, |
|
|
{ 226, "acirc","latin small letter a with circumflex, U+00E2 ISOlat1" }, |
|
|
{ 227, "atilde","latin small letter a with tilde, U+00E3 ISOlat1" }, |
|
|
{ 228, "auml", "latin small letter a with diaeresis, U+00E4 ISOlat1" }, |
|
|
{ 229, "aring","latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1" }, |
|
|
{ 230, "aelig","latin small letter ae = latin small ligature ae, U+00E6 ISOlat1" }, |
|
|
{ 231, "ccedil","latin small letter c with cedilla, U+00E7 ISOlat1" }, |
|
|
{ 232, "egrave","latin small letter e with grave, U+00E8 ISOlat1" }, |
|
|
{ 233, "eacute","latin small letter e with acute, U+00E9 ISOlat1" }, |
|
|
{ 234, "ecirc","latin small letter e with circumflex, U+00EA ISOlat1" }, |
|
|
{ 235, "euml", "latin small letter e with diaeresis, U+00EB ISOlat1" }, |
|
|
{ 236, "igrave","latin small letter i with grave, U+00EC ISOlat1" }, |
|
|
{ 237, "iacute","latin small letter i with acute, U+00ED ISOlat1" }, |
|
|
{ 238, "icirc","latin small letter i with circumflex, U+00EE ISOlat1" }, |
|
|
{ 239, "iuml", "latin small letter i with diaeresis, U+00EF ISOlat1" }, |
|
|
{ 240, "eth", "latin small letter eth, U+00F0 ISOlat1" }, |
|
|
{ 241, "ntilde","latin small letter n with tilde, U+00F1 ISOlat1" }, |
|
|
{ 242, "ograve","latin small letter o with grave, U+00F2 ISOlat1" }, |
|
|
{ 243, "oacute","latin small letter o with acute, U+00F3 ISOlat1" }, |
|
|
{ 244, "ocirc","latin small letter o with circumflex, U+00F4 ISOlat1" }, |
|
|
{ 245, "otilde","latin small letter o with tilde, U+00F5 ISOlat1" }, |
|
|
{ 246, "ouml", "latin small letter o with diaeresis, U+00F6 ISOlat1" }, |
|
|
{ 247, "divide","division sign, U+00F7 ISOnum" }, |
|
|
{ 248, "oslash","latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1" }, |
|
|
{ 249, "ugrave","latin small letter u with grave, U+00F9 ISOlat1" }, |
|
|
{ 250, "uacute","latin small letter u with acute, U+00FA ISOlat1" }, |
|
|
{ 251, "ucirc","latin small letter u with circumflex, U+00FB ISOlat1" }, |
|
|
{ 252, "uuml", "latin small letter u with diaeresis, U+00FC ISOlat1" }, |
|
|
{ 253, "yacute","latin small letter y with acute, U+00FD ISOlat1" }, |
|
|
{ 254, "thorn","latin small letter thorn with, U+00FE ISOlat1" }, |
|
|
{ 255, "yuml", "latin small letter y with diaeresis, U+00FF ISOlat1" }, |
|
|
|
|
|
{ 338, "OElig","latin capital ligature OE, U+0152 ISOlat2" }, |
|
|
{ 339, "oelig","latin small ligature oe, U+0153 ISOlat2" }, |
|
|
{ 352, "Scaron","latin capital letter S with caron, U+0160 ISOlat2" }, |
|
|
{ 353, "scaron","latin small letter s with caron, U+0161 ISOlat2" }, |
|
|
{ 376, "Yuml", "latin capital letter Y with diaeresis, U+0178 ISOlat2" }, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ 402, "fnof", "latin small f with hook = function = florin, U+0192 ISOtech" }, |
|
|
|
|
|
{ 710, "circ", "modifier letter circumflex accent, U+02C6 ISOpub" }, |
|
|
{ 732, "tilde","small tilde, U+02DC ISOdia" }, |
|
|
|
|
|
{ 913, "Alpha","greek capital letter alpha, U+0391" }, |
|
|
{ 914, "Beta", "greek capital letter beta, U+0392" }, |
|
|
{ 915, "Gamma","greek capital letter gamma, U+0393 ISOgrk3" }, |
|
|
{ 916, "Delta","greek capital letter delta, U+0394 ISOgrk3" }, |
|
|
{ 917, "Epsilon","greek capital letter epsilon, U+0395" }, |
|
|
{ 918, "Zeta", "greek capital letter zeta, U+0396" }, |
|
|
{ 919, "Eta", "greek capital letter eta, U+0397" }, |
|
|
{ 920, "Theta","greek capital letter theta, U+0398 ISOgrk3" }, |
|
|
{ 921, "Iota", "greek capital letter iota, U+0399" }, |
|
|
{ 922, "Kappa","greek capital letter kappa, U+039A" }, |
|
|
{ 923, "Lambda", "greek capital letter lambda, U+039B ISOgrk3" }, |
|
|
{ 924, "Mu", "greek capital letter mu, U+039C" }, |
|
|
{ 925, "Nu", "greek capital letter nu, U+039D" }, |
|
|
{ 926, "Xi", "greek capital letter xi, U+039E ISOgrk3" }, |
|
|
{ 927, "Omicron","greek capital letter omicron, U+039F" }, |
|
|
{ 928, "Pi", "greek capital letter pi, U+03A0 ISOgrk3" }, |
|
|
{ 929, "Rho", "greek capital letter rho, U+03A1" }, |
|
|
{ 931, "Sigma","greek capital letter sigma, U+03A3 ISOgrk3" }, |
|
|
{ 932, "Tau", "greek capital letter tau, U+03A4" }, |
|
|
{ 933, "Upsilon","greek capital letter upsilon, U+03A5 ISOgrk3" }, |
|
|
{ 934, "Phi", "greek capital letter phi, U+03A6 ISOgrk3" }, |
|
|
{ 935, "Chi", "greek capital letter chi, U+03A7" }, |
|
|
{ 936, "Psi", "greek capital letter psi, U+03A8 ISOgrk3" }, |
|
|
{ 937, "Omega","greek capital letter omega, U+03A9 ISOgrk3" }, |
|
|
|
|
|
{ 945, "alpha","greek small letter alpha, U+03B1 ISOgrk3" }, |
|
|
{ 946, "beta", "greek small letter beta, U+03B2 ISOgrk3" }, |
|
|
{ 947, "gamma","greek small letter gamma, U+03B3 ISOgrk3" }, |
|
|
{ 948, "delta","greek small letter delta, U+03B4 ISOgrk3" }, |
|
|
{ 949, "epsilon","greek small letter epsilon, U+03B5 ISOgrk3" }, |
|
|
{ 950, "zeta", "greek small letter zeta, U+03B6 ISOgrk3" }, |
|
|
{ 951, "eta", "greek small letter eta, U+03B7 ISOgrk3" }, |
|
|
{ 952, "theta","greek small letter theta, U+03B8 ISOgrk3" }, |
|
|
{ 953, "iota", "greek small letter iota, U+03B9 ISOgrk3" }, |
|
|
{ 954, "kappa","greek small letter kappa, U+03BA ISOgrk3" }, |
|
|
{ 955, "lambda","greek small letter lambda, U+03BB ISOgrk3" }, |
|
|
{ 956, "mu", "greek small letter mu, U+03BC ISOgrk3" }, |
|
|
{ 957, "nu", "greek small letter nu, U+03BD ISOgrk3" }, |
|
|
{ 958, "xi", "greek small letter xi, U+03BE ISOgrk3" }, |
|
|
{ 959, "omicron","greek small letter omicron, U+03BF NEW" }, |
|
|
{ 960, "pi", "greek small letter pi, U+03C0 ISOgrk3" }, |
|
|
{ 961, "rho", "greek small letter rho, U+03C1 ISOgrk3" }, |
|
|
{ 962, "sigmaf","greek small letter final sigma, U+03C2 ISOgrk3" }, |
|
|
{ 963, "sigma","greek small letter sigma, U+03C3 ISOgrk3" }, |
|
|
{ 964, "tau", "greek small letter tau, U+03C4 ISOgrk3" }, |
|
|
{ 965, "upsilon","greek small letter upsilon, U+03C5 ISOgrk3" }, |
|
|
{ 966, "phi", "greek small letter phi, U+03C6 ISOgrk3" }, |
|
|
{ 967, "chi", "greek small letter chi, U+03C7 ISOgrk3" }, |
|
|
{ 968, "psi", "greek small letter psi, U+03C8 ISOgrk3" }, |
|
|
{ 969, "omega","greek small letter omega, U+03C9 ISOgrk3" }, |
|
|
{ 977, "thetasym","greek small letter theta symbol, U+03D1 NEW" }, |
|
|
{ 978, "upsih","greek upsilon with hook symbol, U+03D2 NEW" }, |
|
|
{ 982, "piv", "greek pi symbol, U+03D6 ISOgrk3" }, |
|
|
|
|
|
{ 8194, "ensp", "en space, U+2002 ISOpub" }, |
|
|
{ 8195, "emsp", "em space, U+2003 ISOpub" }, |
|
|
{ 8201, "thinsp","thin space, U+2009 ISOpub" }, |
|
|
{ 8204, "zwnj", "zero width non-joiner, U+200C NEW RFC 2070" }, |
|
|
{ 8205, "zwj", "zero width joiner, U+200D NEW RFC 2070" }, |
|
|
{ 8206, "lrm", "left-to-right mark, U+200E NEW RFC 2070" }, |
|
|
{ 8207, "rlm", "right-to-left mark, U+200F NEW RFC 2070" }, |
|
|
{ 8211, "ndash","en dash, U+2013 ISOpub" }, |
|
|
{ 8212, "mdash","em dash, U+2014 ISOpub" }, |
|
|
{ 8216, "lsquo","left single quotation mark, U+2018 ISOnum" }, |
|
|
{ 8217, "rsquo","right single quotation mark, U+2019 ISOnum" }, |
|
|
{ 8218, "sbquo","single low-9 quotation mark, U+201A NEW" }, |
|
|
{ 8220, "ldquo","left double quotation mark, U+201C ISOnum" }, |
|
|
{ 8221, "rdquo","right double quotation mark, U+201D ISOnum" }, |
|
|
{ 8222, "bdquo","double low-9 quotation mark, U+201E NEW" }, |
|
|
{ 8224, "dagger","dagger, U+2020 ISOpub" }, |
|
|
{ 8225, "Dagger","double dagger, U+2021 ISOpub" }, |
|
|
|
|
|
{ 8226, "bull", "bullet = black small circle, U+2022 ISOpub" }, |
|
|
{ 8230, "hellip","horizontal ellipsis = three dot leader, U+2026 ISOpub" }, |
|
|
|
|
|
{ 8240, "permil","per mille sign, U+2030 ISOtech" }, |
|
|
|
|
|
{ 8242, "prime","prime = minutes = feet, U+2032 ISOtech" }, |
|
|
{ 8243, "Prime","double prime = seconds = inches, U+2033 ISOtech" }, |
|
|
|
|
|
{ 8249, "lsaquo","single left-pointing angle quotation mark, U+2039 ISO proposed" }, |
|
|
{ 8250, "rsaquo","single right-pointing angle quotation mark, U+203A ISO proposed" }, |
|
|
|
|
|
{ 8254, "oline","overline = spacing overscore, U+203E NEW" }, |
|
|
{ 8260, "frasl","fraction slash, U+2044 NEW" }, |
|
|
|
|
|
{ 8364, "euro", "euro sign, U+20AC NEW" }, |
|
|
|
|
|
{ 8465, "image","blackletter capital I = imaginary part, U+2111 ISOamso" }, |
|
|
{ 8472, "weierp","script capital P = power set = Weierstrass p, U+2118 ISOamso" }, |
|
|
{ 8476, "real", "blackletter capital R = real part symbol, U+211C ISOamso" }, |
|
|
{ 8482, "trade","trade mark sign, U+2122 ISOnum" }, |
|
|
{ 8501, "alefsym","alef symbol = first transfinite cardinal, U+2135 NEW" }, |
|
|
{ 8592, "larr", "leftwards arrow, U+2190 ISOnum" }, |
|
|
{ 8593, "uarr", "upwards arrow, U+2191 ISOnum" }, |
|
|
{ 8594, "rarr", "rightwards arrow, U+2192 ISOnum" }, |
|
|
{ 8595, "darr", "downwards arrow, U+2193 ISOnum" }, |
|
|
{ 8596, "harr", "left right arrow, U+2194 ISOamsa" }, |
|
|
{ 8629, "crarr","downwards arrow with corner leftwards = carriage return, U+21B5 NEW" }, |
|
|
{ 8656, "lArr", "leftwards double arrow, U+21D0 ISOtech" }, |
|
|
{ 8657, "uArr", "upwards double arrow, U+21D1 ISOamsa" }, |
|
|
{ 8658, "rArr", "rightwards double arrow, U+21D2 ISOtech" }, |
|
|
{ 8659, "dArr", "downwards double arrow, U+21D3 ISOamsa" }, |
|
|
{ 8660, "hArr", "left right double arrow, U+21D4 ISOamsa" }, |
|
|
|
|
|
{ 8704, "forall","for all, U+2200 ISOtech" }, |
|
|
{ 8706, "part", "partial differential, U+2202 ISOtech" }, |
|
|
{ 8707, "exist","there exists, U+2203 ISOtech" }, |
|
|
{ 8709, "empty","empty set = null set = diameter, U+2205 ISOamso" }, |
|
|
{ 8711, "nabla","nabla = backward difference, U+2207 ISOtech" }, |
|
|
{ 8712, "isin", "element of, U+2208 ISOtech" }, |
|
|
{ 8713, "notin","not an element of, U+2209 ISOtech" }, |
|
|
{ 8715, "ni", "contains as member, U+220B ISOtech" }, |
|
|
{ 8719, "prod", "n-ary product = product sign, U+220F ISOamsb" }, |
|
|
{ 8721, "sum", "n-ary summation, U+2211 ISOamsb" }, |
|
|
{ 8722, "minus","minus sign, U+2212 ISOtech" }, |
|
|
{ 8727, "lowast","asterisk operator, U+2217 ISOtech" }, |
|
|
{ 8730, "radic","square root = radical sign, U+221A ISOtech" }, |
|
|
{ 8733, "prop", "proportional to, U+221D ISOtech" }, |
|
|
{ 8734, "infin","infinity, U+221E ISOtech" }, |
|
|
{ 8736, "ang", "angle, U+2220 ISOamso" }, |
|
|
{ 8743, "and", "logical and = wedge, U+2227 ISOtech" }, |
|
|
{ 8744, "or", "logical or = vee, U+2228 ISOtech" }, |
|
|
{ 8745, "cap", "intersection = cap, U+2229 ISOtech" }, |
|
|
{ 8746, "cup", "union = cup, U+222A ISOtech" }, |
|
|
{ 8747, "int", "integral, U+222B ISOtech" }, |
|
|
{ 8756, "there4","therefore, U+2234 ISOtech" }, |
|
|
{ 8764, "sim", "tilde operator = varies with = similar to, U+223C ISOtech" }, |
|
|
{ 8773, "cong", "approximately equal to, U+2245 ISOtech" }, |
|
|
{ 8776, "asymp","almost equal to = asymptotic to, U+2248 ISOamsr" }, |
|
|
{ 8800, "ne", "not equal to, U+2260 ISOtech" }, |
|
|
{ 8801, "equiv","identical to, U+2261 ISOtech" }, |
|
|
{ 8804, "le", "less-than or equal to, U+2264 ISOtech" }, |
|
|
{ 8805, "ge", "greater-than or equal to, U+2265 ISOtech" }, |
|
|
{ 8834, "sub", "subset of, U+2282 ISOtech" }, |
|
|
{ 8835, "sup", "superset of, U+2283 ISOtech" }, |
|
|
{ 8836, "nsub", "not a subset of, U+2284 ISOamsn" }, |
|
|
{ 8838, "sube", "subset of or equal to, U+2286 ISOtech" }, |
|
|
{ 8839, "supe", "superset of or equal to, U+2287 ISOtech" }, |
|
|
{ 8853, "oplus","circled plus = direct sum, U+2295 ISOamsb" }, |
|
|
{ 8855, "otimes","circled times = vector product, U+2297 ISOamsb" }, |
|
|
{ 8869, "perp", "up tack = orthogonal to = perpendicular, U+22A5 ISOtech" }, |
|
|
{ 8901, "sdot", "dot operator, U+22C5 ISOamsb" }, |
|
|
{ 8968, "lceil","left ceiling = apl upstile, U+2308 ISOamsc" }, |
|
|
{ 8969, "rceil","right ceiling, U+2309 ISOamsc" }, |
|
|
{ 8970, "lfloor","left floor = apl downstile, U+230A ISOamsc" }, |
|
|
{ 8971, "rfloor","right floor, U+230B ISOamsc" }, |
|
|
{ 9001, "lang", "left-pointing angle bracket = bra, U+2329 ISOtech" }, |
|
|
{ 9002, "rang", "right-pointing angle bracket = ket, U+232A ISOtech" }, |
|
|
{ 9674, "loz", "lozenge, U+25CA ISOpub" }, |
|
|
|
|
|
{ 9824, "spades","black spade suit, U+2660 ISOpub" }, |
|
|
{ 9827, "clubs","black club suit = shamrock, U+2663 ISOpub" }, |
|
|
{ 9829, "hearts","black heart suit = valentine, U+2665 ISOpub" }, |
|
|
{ 9830, "diams","black diamond suit, U+2666 ISOpub" }, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const htmlEntityDesc * |
|
|
htmlEntityLookup(const xmlChar *name) { |
|
|
unsigned int i; |
|
|
|
|
|
for (i = 0;i < (sizeof(html40EntitiesTable)/ |
|
|
sizeof(html40EntitiesTable[0]));i++) { |
|
|
if (xmlStrEqual(name, BAD_CAST html40EntitiesTable[i].name)) { |
|
|
return((htmlEntityDescPtr) &html40EntitiesTable[i]); |
|
|
} |
|
|
} |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
static int |
|
|
htmlCompareEntityDesc(const void *vkey, const void *vdesc) { |
|
|
const unsigned *key = vkey; |
|
|
const htmlEntityDesc *desc = vdesc; |
|
|
|
|
|
return((int) *key - (int) desc->value); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const htmlEntityDesc * |
|
|
htmlEntityValueLookup(unsigned int value) { |
|
|
const htmlEntityDesc *desc; |
|
|
size_t nmemb; |
|
|
|
|
|
nmemb = sizeof(html40EntitiesTable) / sizeof(html40EntitiesTable[0]); |
|
|
desc = bsearch(&value, html40EntitiesTable, nmemb, sizeof(htmlEntityDesc), |
|
|
htmlCompareEntityDesc); |
|
|
|
|
|
return(desc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
UTF8ToHtml(unsigned char* out, int *outlen, |
|
|
const unsigned char* in, int *inlen) { |
|
|
const unsigned char* instart = in; |
|
|
const unsigned char* inend; |
|
|
unsigned char* outstart = out; |
|
|
unsigned char* outend; |
|
|
int ret = XML_ENC_ERR_SPACE; |
|
|
|
|
|
if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) |
|
|
return(XML_ENC_ERR_INTERNAL); |
|
|
|
|
|
if (in == NULL) { |
|
|
|
|
|
|
|
|
|
|
|
*outlen = 0; |
|
|
*inlen = 0; |
|
|
return(XML_ENC_ERR_SUCCESS); |
|
|
} |
|
|
|
|
|
inend = in + *inlen; |
|
|
outend = out + *outlen; |
|
|
while (in < inend) { |
|
|
const htmlEntityDesc *ent; |
|
|
const char *cp; |
|
|
char nbuf[16]; |
|
|
unsigned c, d; |
|
|
int seqlen, len, i; |
|
|
|
|
|
d = *in; |
|
|
|
|
|
if (d < 0x80) { |
|
|
if (out >= outend) |
|
|
goto done; |
|
|
*out++ = d; |
|
|
in += 1; |
|
|
continue; |
|
|
} |
|
|
|
|
|
if (d < 0xE0) { c = d & 0x1F; seqlen = 2; } |
|
|
else if (d < 0xF0) { c = d & 0x0F; seqlen = 3; } |
|
|
else { c = d & 0x07; seqlen = 4; } |
|
|
|
|
|
if (inend - in < seqlen) |
|
|
break; |
|
|
|
|
|
for (i = 1; i < seqlen; i++) { |
|
|
d = in[i]; |
|
|
c <<= 6; |
|
|
c |= d & 0x3F; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ent = htmlEntityValueLookup(c); |
|
|
|
|
|
if (ent == NULL) { |
|
|
snprintf(nbuf, sizeof(nbuf), "#%u", c); |
|
|
cp = nbuf; |
|
|
} else { |
|
|
cp = ent->name; |
|
|
} |
|
|
|
|
|
len = strlen(cp); |
|
|
if (outend - out < len + 2) |
|
|
goto done; |
|
|
|
|
|
*out++ = '&'; |
|
|
memcpy(out, cp, len); |
|
|
out += len; |
|
|
*out++ = ';'; |
|
|
|
|
|
in += seqlen; |
|
|
} |
|
|
|
|
|
ret = out - outstart; |
|
|
|
|
|
done: |
|
|
*outlen = out - outstart; |
|
|
*inlen = in - instart; |
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlEncodeEntities(unsigned char* out, int *outlen, |
|
|
const unsigned char* in, int *inlen, int quoteChar) { |
|
|
const unsigned char* processed = in; |
|
|
const unsigned char* outend; |
|
|
const unsigned char* outstart = out; |
|
|
const unsigned char* instart = in; |
|
|
const unsigned char* inend; |
|
|
unsigned int c, d; |
|
|
int trailing; |
|
|
|
|
|
if ((out == NULL) || (outlen == NULL) || (inlen == NULL) || (in == NULL)) |
|
|
return(-1); |
|
|
outend = out + (*outlen); |
|
|
inend = in + (*inlen); |
|
|
while (in < inend) { |
|
|
d = *in++; |
|
|
if (d < 0x80) { c= d; trailing= 0; } |
|
|
else if (d < 0xC0) { |
|
|
|
|
|
*outlen = out - outstart; |
|
|
*inlen = processed - instart; |
|
|
return(-2); |
|
|
} else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } |
|
|
else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } |
|
|
else if (d < 0xF8) { c= d & 0x07; trailing= 3; } |
|
|
else { |
|
|
|
|
|
*outlen = out - outstart; |
|
|
*inlen = processed - instart; |
|
|
return(-2); |
|
|
} |
|
|
|
|
|
if (inend - in < trailing) |
|
|
break; |
|
|
|
|
|
while (trailing--) { |
|
|
if (((d= *in++) & 0xC0) != 0x80) { |
|
|
*outlen = out - outstart; |
|
|
*inlen = processed - instart; |
|
|
return(-2); |
|
|
} |
|
|
c <<= 6; |
|
|
c |= d & 0x3F; |
|
|
} |
|
|
|
|
|
|
|
|
if ((c < 0x80) && (c != (unsigned int) quoteChar) && |
|
|
(c != '&') && (c != '<') && (c != '>')) { |
|
|
if (out >= outend) |
|
|
break; |
|
|
*out++ = c; |
|
|
} else { |
|
|
const htmlEntityDesc * ent; |
|
|
const char *cp; |
|
|
char nbuf[16]; |
|
|
int len; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ent = htmlEntityValueLookup(c); |
|
|
if (ent == NULL) { |
|
|
snprintf(nbuf, sizeof(nbuf), "#%u", c); |
|
|
cp = nbuf; |
|
|
} |
|
|
else |
|
|
cp = ent->name; |
|
|
len = strlen(cp); |
|
|
if (outend - out < len + 2) |
|
|
break; |
|
|
*out++ = '&'; |
|
|
memcpy(out, cp, len); |
|
|
out += len; |
|
|
*out++ = ';'; |
|
|
} |
|
|
processed = in; |
|
|
} |
|
|
*outlen = out - outstart; |
|
|
*inlen = processed - instart; |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *allowPCData[] = { |
|
|
"a", "abbr", "acronym", "address", "applet", "b", "bdo", "big", |
|
|
"blockquote", "body", "button", "caption", "center", "cite", "code", |
|
|
"dd", "del", "dfn", "div", "dt", "em", "font", "form", "h1", "h2", |
|
|
"h3", "h4", "h5", "h6", "i", "iframe", "ins", "kbd", "label", "legend", |
|
|
"li", "noframes", "noscript", "object", "p", "pre", "q", "s", "samp", |
|
|
"small", "span", "strike", "strong", "td", "th", "tt", "u", "var" |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int areBlanks(htmlParserCtxtPtr ctxt, const xmlChar *str, int len) { |
|
|
unsigned int i; |
|
|
int j; |
|
|
xmlNodePtr lastChild; |
|
|
xmlDtdPtr dtd; |
|
|
|
|
|
for (j = 0;j < len;j++) |
|
|
if (!(IS_WS_HTML(str[j]))) return(-1); |
|
|
|
|
|
if (CUR == 0) return(1); |
|
|
if (CUR != '<') return(0); |
|
|
if (ctxt->name == NULL) |
|
|
return(1); |
|
|
if (xmlStrEqual(ctxt->name, BAD_CAST"html")) |
|
|
return(1); |
|
|
if (xmlStrEqual(ctxt->name, BAD_CAST"head")) |
|
|
return(1); |
|
|
|
|
|
|
|
|
if (xmlStrEqual(ctxt->name, BAD_CAST "body") && ctxt->myDoc != NULL) { |
|
|
dtd = xmlGetIntSubset(ctxt->myDoc); |
|
|
if (dtd != NULL && dtd->ExternalID != NULL) { |
|
|
if (!xmlStrcasecmp(dtd->ExternalID, BAD_CAST "-//W3C//DTD HTML 4.01//EN") || |
|
|
!xmlStrcasecmp(dtd->ExternalID, BAD_CAST "-//W3C//DTD HTML 4//EN")) |
|
|
return(1); |
|
|
} |
|
|
} |
|
|
|
|
|
if (ctxt->node == NULL) return(0); |
|
|
lastChild = xmlGetLastChild(ctxt->node); |
|
|
while ((lastChild) && (lastChild->type == XML_COMMENT_NODE)) |
|
|
lastChild = lastChild->prev; |
|
|
if (lastChild == NULL) { |
|
|
if ((ctxt->node->type != XML_ELEMENT_NODE) && |
|
|
(ctxt->node->content != NULL)) return(0); |
|
|
|
|
|
|
|
|
for ( i = 0; i < sizeof(allowPCData)/sizeof(allowPCData[0]); i++ ) { |
|
|
if ( xmlStrEqual(ctxt->name, BAD_CAST allowPCData[i]) ) { |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
} else if (xmlNodeIsText(lastChild)) { |
|
|
return(0); |
|
|
} else { |
|
|
|
|
|
|
|
|
for ( i = 0; i < sizeof(allowPCData)/sizeof(allowPCData[0]); i++ ) { |
|
|
if ( xmlStrEqual(lastChild->name, BAD_CAST allowPCData[i]) ) { |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
} |
|
|
return(1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlNewDocNoDtD(const xmlChar *URI, const xmlChar *ExternalID) { |
|
|
xmlDocPtr cur; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); |
|
|
if (cur == NULL) |
|
|
return(NULL); |
|
|
memset(cur, 0, sizeof(xmlDoc)); |
|
|
|
|
|
cur->type = XML_HTML_DOCUMENT_NODE; |
|
|
cur->version = NULL; |
|
|
cur->intSubset = NULL; |
|
|
cur->doc = cur; |
|
|
cur->name = NULL; |
|
|
cur->children = NULL; |
|
|
cur->extSubset = NULL; |
|
|
cur->oldNs = NULL; |
|
|
cur->encoding = NULL; |
|
|
cur->standalone = 1; |
|
|
cur->compression = 0; |
|
|
cur->ids = NULL; |
|
|
cur->refs = NULL; |
|
|
cur->_private = NULL; |
|
|
cur->charset = XML_CHAR_ENCODING_UTF8; |
|
|
cur->properties = XML_DOC_HTML | XML_DOC_USERBUILT; |
|
|
if ((ExternalID != NULL) || |
|
|
(URI != NULL)) { |
|
|
xmlDtdPtr intSubset; |
|
|
|
|
|
intSubset = xmlCreateIntSubset(cur, BAD_CAST "html", ExternalID, URI); |
|
|
if (intSubset == NULL) { |
|
|
xmlFree(cur); |
|
|
return(NULL); |
|
|
} |
|
|
} |
|
|
if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
|
|
xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
|
|
return(cur); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlNewDoc(const xmlChar *URI, const xmlChar *ExternalID) { |
|
|
if ((URI == NULL) && (ExternalID == NULL)) |
|
|
return(htmlNewDocNoDtD( |
|
|
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd", |
|
|
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN")); |
|
|
|
|
|
return(htmlNewDocNoDtD(URI, ExternalID)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlHashedString |
|
|
htmlParseHTMLName(htmlParserCtxtPtr ctxt, int attr) { |
|
|
xmlHashedString ret; |
|
|
xmlChar buf[HTML_PARSER_BUFFER_SIZE]; |
|
|
const xmlChar *in; |
|
|
size_t avail; |
|
|
int eof = PARSER_PROGRESSIVE(ctxt); |
|
|
int nbchar = 0; |
|
|
int stop = attr ? '=' : ' '; |
|
|
|
|
|
in = ctxt->input->cur; |
|
|
avail = ctxt->input->end - in; |
|
|
|
|
|
while (1) { |
|
|
int c, size; |
|
|
|
|
|
if ((!eof) && (avail < 32)) { |
|
|
size_t oldAvail = avail; |
|
|
|
|
|
ctxt->input->cur = in; |
|
|
|
|
|
SHRINK; |
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
in = ctxt->input->cur; |
|
|
avail = ctxt->input->end - in; |
|
|
|
|
|
if (oldAvail == avail) |
|
|
eof = 1; |
|
|
} |
|
|
|
|
|
if (avail == 0) |
|
|
break; |
|
|
|
|
|
c = *in; |
|
|
size = 1; |
|
|
|
|
|
if ((nbchar != 0) && |
|
|
((c == '/') || (c == '>') || (c == stop) || |
|
|
(IS_WS_HTML(c)))) |
|
|
break; |
|
|
|
|
|
if (c == 0) { |
|
|
if (nbchar + 3 <= HTML_PARSER_BUFFER_SIZE) { |
|
|
buf[nbchar++] = 0xEF; |
|
|
buf[nbchar++] = 0xBF; |
|
|
buf[nbchar++] = 0xBD; |
|
|
} |
|
|
} else if (c < 0x80) { |
|
|
if (nbchar < HTML_PARSER_BUFFER_SIZE) { |
|
|
if (IS_UPPER(c)) |
|
|
c += 0x20; |
|
|
buf[nbchar++] = c; |
|
|
} |
|
|
} else { |
|
|
size = htmlValidateUtf8(ctxt, in, avail); |
|
|
|
|
|
if (size > 0) { |
|
|
if (nbchar + size <= HTML_PARSER_BUFFER_SIZE) { |
|
|
memcpy(buf + nbchar, in, size); |
|
|
nbchar += size; |
|
|
} |
|
|
} else { |
|
|
size = 1; |
|
|
|
|
|
if (nbchar + 3 <= HTML_PARSER_BUFFER_SIZE) { |
|
|
buf[nbchar++] = 0xEF; |
|
|
buf[nbchar++] = 0xBF; |
|
|
buf[nbchar++] = 0xBD; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
in += size; |
|
|
avail -= size; |
|
|
} |
|
|
|
|
|
ctxt->input->cur = in; |
|
|
|
|
|
SHRINK; |
|
|
|
|
|
ret = xmlDictLookupHashed(ctxt->dict, buf, nbchar); |
|
|
if (ret.name == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
static const short htmlC1Remap[32] = { |
|
|
0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, |
|
|
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, |
|
|
0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, |
|
|
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178 |
|
|
}; |
|
|
|
|
|
static const xmlChar * |
|
|
htmlCodePointToUtf8(int c, xmlChar *out, int *osize) { |
|
|
int i = 0; |
|
|
int bits, hi; |
|
|
|
|
|
if ((c >= 0x80) && (c < 0xA0)) { |
|
|
c = htmlC1Remap[c - 0x80]; |
|
|
} else if ((c <= 0) || |
|
|
((c >= 0xD800) && (c < 0xE000)) || |
|
|
(c > 0x10FFFF)) { |
|
|
c = 0xFFFD; |
|
|
} |
|
|
|
|
|
if (c < 0x80) { bits = 0; hi = 0x00; } |
|
|
else if (c < 0x800) { bits = 6; hi = 0xC0; } |
|
|
else if (c < 0x10000) { bits = 12; hi = 0xE0; } |
|
|
else { bits = 18; hi = 0xF0; } |
|
|
|
|
|
out[i++] = (c >> bits) | hi; |
|
|
|
|
|
while (bits > 0) { |
|
|
bits -= 6; |
|
|
out[i++] = ((c >> bits) & 0x3F) | 0x80; |
|
|
} |
|
|
|
|
|
*osize = i; |
|
|
return(out); |
|
|
} |
|
|
|
|
|
#include "html5ent.inc" |
|
|
|
|
|
#define ENT_F_SEMICOLON 0x80u |
|
|
#define ENT_F_SUBTABLE 0x40u |
|
|
#define ENT_F_ALL 0xC0u |
|
|
|
|
|
static const xmlChar * |
|
|
htmlFindEntityPrefix(const xmlChar *string, size_t slen, int isAttr, |
|
|
int *nlen, int *rlen) { |
|
|
const xmlChar *match = NULL; |
|
|
unsigned left, right; |
|
|
int first = string[0]; |
|
|
size_t matchLen = 0; |
|
|
size_t soff = 1; |
|
|
|
|
|
if (slen < 2) |
|
|
return(NULL); |
|
|
if (!IS_ASCII_LETTER(first)) |
|
|
return(NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
first &= 63; |
|
|
left = htmlEntAlpha[first*3] | htmlEntAlpha[first*3+1] << 8; |
|
|
right = left + htmlEntAlpha[first*3+2]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (left < right) { |
|
|
const xmlChar *bytes; |
|
|
unsigned mid; |
|
|
size_t len; |
|
|
int cmp; |
|
|
|
|
|
mid = left + (right - left) / 2; |
|
|
bytes = htmlEntStrings + htmlEntValues[mid]; |
|
|
len = bytes[0] & ~ENT_F_ALL; |
|
|
|
|
|
cmp = string[soff] - bytes[1]; |
|
|
|
|
|
if (cmp == 0) { |
|
|
if (slen < len) { |
|
|
cmp = strncmp((const char *) string + soff + 1, |
|
|
(const char *) bytes + 2, |
|
|
slen - 1); |
|
|
|
|
|
if (cmp == 0) |
|
|
break; |
|
|
} else { |
|
|
cmp = strncmp((const char *) string + soff + 1, |
|
|
(const char *) bytes + 2, |
|
|
len - 1); |
|
|
} |
|
|
} |
|
|
|
|
|
if (cmp < 0) { |
|
|
right = mid; |
|
|
} else if (cmp > 0) { |
|
|
left = mid + 1; |
|
|
} else { |
|
|
int term = soff + len < slen ? string[soff + len] : 0; |
|
|
int isAlnum, isTerm; |
|
|
|
|
|
isAlnum = IS_ALNUM(term); |
|
|
isTerm = ((term == ';') || |
|
|
((bytes[0] & ENT_F_SEMICOLON) && |
|
|
((!isAttr) || |
|
|
((!isAlnum) && (term != '='))))); |
|
|
|
|
|
if (isTerm) { |
|
|
match = bytes + len + 1; |
|
|
matchLen = soff + len; |
|
|
if (term == ';') |
|
|
matchLen += 1; |
|
|
} |
|
|
|
|
|
if (bytes[0] & ENT_F_SUBTABLE) { |
|
|
if (isTerm) |
|
|
match += 2; |
|
|
|
|
|
if ((isAlnum) && (soff + len < slen)) { |
|
|
left = mid + bytes[len + 1]; |
|
|
right = left + bytes[len + 2]; |
|
|
soff += len; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
if (match == NULL) |
|
|
return(NULL); |
|
|
|
|
|
*nlen = matchLen; |
|
|
*rlen = match[0]; |
|
|
return(match + 1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlChar * |
|
|
htmlParseData(htmlParserCtxtPtr ctxt, htmlAsciiMask mask, |
|
|
int comment, int refs, int maxLength) { |
|
|
xmlParserInputPtr input = ctxt->input; |
|
|
xmlChar *ret = NULL; |
|
|
xmlChar *buffer; |
|
|
xmlChar utf8Char[4]; |
|
|
size_t buffer_size; |
|
|
size_t used; |
|
|
int eof = PARSER_PROGRESSIVE(ctxt); |
|
|
int line, col; |
|
|
int termSkip = -1; |
|
|
|
|
|
used = 0; |
|
|
buffer_size = ctxt->spaceMax; |
|
|
buffer = (xmlChar *) ctxt->spaceTab; |
|
|
if (buffer == NULL) { |
|
|
buffer_size = 500; |
|
|
buffer = xmlMalloc(buffer_size + 1); |
|
|
if (buffer == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
line = input->line; |
|
|
col = input->col; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
const xmlChar *chunk, *in, *repl; |
|
|
size_t avail, chunkSize, extraSize; |
|
|
int replSize; |
|
|
int skip = 0; |
|
|
int ncr = 0; |
|
|
int ncrSize = 0; |
|
|
int cp = 0; |
|
|
|
|
|
chunk = input->cur; |
|
|
avail = input->end - chunk; |
|
|
in = chunk; |
|
|
|
|
|
repl = BAD_CAST ""; |
|
|
replSize = 0; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
size_t j; |
|
|
int cur, size; |
|
|
|
|
|
if ((!eof) && (avail <= 64)) { |
|
|
size_t oldAvail = avail; |
|
|
size_t off = in - chunk; |
|
|
|
|
|
input->cur = in; |
|
|
|
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
in = input->cur; |
|
|
chunk = in - off; |
|
|
input->cur = chunk; |
|
|
avail = input->end - in; |
|
|
|
|
|
if (oldAvail == avail) |
|
|
eof = 1; |
|
|
} |
|
|
|
|
|
if (avail == 0) { |
|
|
termSkip = 0; |
|
|
break; |
|
|
} |
|
|
|
|
|
cur = *in; |
|
|
size = 1; |
|
|
col += 1; |
|
|
|
|
|
if (htmlMaskMatch(mask, cur)) { |
|
|
if (comment) { |
|
|
if (avail < 2) { |
|
|
termSkip = 1; |
|
|
} else if (in[1] == '-') { |
|
|
if (avail < 3) { |
|
|
termSkip = 2; |
|
|
} else if (in[2] == '>') { |
|
|
termSkip = 3; |
|
|
} else if (in[2] == '!') { |
|
|
if (avail < 4) |
|
|
termSkip = 3; |
|
|
else if (in[3] == '>') |
|
|
termSkip = 4; |
|
|
} |
|
|
} |
|
|
|
|
|
if (termSkip >= 0) |
|
|
break; |
|
|
} else { |
|
|
termSkip = 0; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
if (ncr) { |
|
|
int lc = cur | 0x20; |
|
|
int digit; |
|
|
|
|
|
if ((cur >= '0') && (cur <= '9')) { |
|
|
digit = cur - '0'; |
|
|
} else if ((ncr == 16) && (lc >= 'a') && (lc <= 'f')) { |
|
|
digit = (lc - 'a') + 10; |
|
|
} else { |
|
|
if (cur == ';') { |
|
|
in += 1; |
|
|
size += 1; |
|
|
ncrSize += 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
cp = cp * ncr + digit; |
|
|
if (cp >= 0x110000) |
|
|
cp = 0x110000; |
|
|
|
|
|
ncrSize += 1; |
|
|
|
|
|
goto next_char; |
|
|
} |
|
|
|
|
|
switch (cur) { |
|
|
case '&': |
|
|
if (!refs) |
|
|
break; |
|
|
|
|
|
j = 1; |
|
|
|
|
|
if ((j < avail) && (in[j] == '#')) { |
|
|
j += 1; |
|
|
if (j < avail) { |
|
|
if ((in[j] | 0x20) == 'x') { |
|
|
j += 1; |
|
|
if ((j < avail) && (IS_HEX_DIGIT(in[j]))) { |
|
|
ncr = 16; |
|
|
size = 3; |
|
|
ncrSize = 3; |
|
|
cp = 0; |
|
|
} |
|
|
} else if (IS_ASCII_DIGIT(in[j])) { |
|
|
ncr = 10; |
|
|
size = 2; |
|
|
ncrSize = 2; |
|
|
cp = 0; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
repl = htmlFindEntityPrefix(in + j, |
|
|
avail - j, |
|
|
1, |
|
|
&skip, &replSize); |
|
|
if (repl != NULL) { |
|
|
skip += 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
skip = 0; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case '\0': |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
|
|
|
case '\n': |
|
|
line += 1; |
|
|
col = 1; |
|
|
break; |
|
|
|
|
|
case '\r': |
|
|
skip = 1; |
|
|
if (in[1] != 0x0A) { |
|
|
repl = BAD_CAST "\x0A"; |
|
|
replSize = 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
|
|
|
default: |
|
|
if (cur < 0x80) |
|
|
break; |
|
|
|
|
|
if ((input->flags & XML_INPUT_HAS_ENCODING) == 0) { |
|
|
xmlChar * guess; |
|
|
|
|
|
guess = htmlFindEncoding(ctxt); |
|
|
if (guess == NULL) { |
|
|
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1); |
|
|
} else { |
|
|
xmlSwitchEncodingName(ctxt, (const char *) guess); |
|
|
xmlFree(guess); |
|
|
} |
|
|
input->flags |= XML_INPUT_HAS_ENCODING; |
|
|
|
|
|
goto restart; |
|
|
} |
|
|
|
|
|
size = htmlValidateUtf8(ctxt, in, avail); |
|
|
|
|
|
if (size <= 0) { |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
break; |
|
|
} |
|
|
|
|
|
next_char: |
|
|
in += size; |
|
|
avail -= size; |
|
|
} |
|
|
|
|
|
next_chunk: |
|
|
if (ncrSize > 0) { |
|
|
skip = ncrSize; |
|
|
in -= ncrSize; |
|
|
|
|
|
repl = htmlCodePointToUtf8(cp, utf8Char, &replSize); |
|
|
} |
|
|
|
|
|
chunkSize = in - chunk; |
|
|
extraSize = chunkSize + replSize; |
|
|
|
|
|
if (extraSize > maxLength - used) { |
|
|
htmlParseErr(ctxt, XML_ERR_RESOURCE_LIMIT, |
|
|
"value too long\n", NULL, NULL); |
|
|
goto error; |
|
|
} |
|
|
|
|
|
if (extraSize > buffer_size - used) { |
|
|
size_t newSize = (used + extraSize) * 2; |
|
|
xmlChar *tmp = (xmlChar *) xmlRealloc(buffer, newSize + 1); |
|
|
|
|
|
if (tmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
goto error; |
|
|
} |
|
|
buffer = tmp; |
|
|
buffer_size = newSize; |
|
|
} |
|
|
|
|
|
if (chunkSize > 0) { |
|
|
input->cur += chunkSize; |
|
|
memcpy(buffer + used, chunk, chunkSize); |
|
|
used += chunkSize; |
|
|
} |
|
|
|
|
|
input->cur += skip; |
|
|
if (replSize > 0) { |
|
|
memcpy(buffer + used, repl, replSize); |
|
|
used += replSize; |
|
|
} |
|
|
|
|
|
SHRINK; |
|
|
|
|
|
if (termSkip >= 0) |
|
|
break; |
|
|
|
|
|
restart: |
|
|
; |
|
|
} |
|
|
|
|
|
if (termSkip > 0) { |
|
|
input->cur += termSkip; |
|
|
col += termSkip; |
|
|
} |
|
|
|
|
|
input->line = line; |
|
|
input->col = col; |
|
|
|
|
|
ret = xmlMalloc(used + 1); |
|
|
if (ret == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
} else { |
|
|
memcpy(ret, buffer, used); |
|
|
ret[used] = 0; |
|
|
} |
|
|
|
|
|
error: |
|
|
ctxt->spaceTab = (void *) buffer; |
|
|
ctxt->spaceMax = buffer_size; |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const htmlEntityDesc * |
|
|
htmlParseEntityRef(htmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, |
|
|
const xmlChar **str ATTRIBUTE_UNUSED) { |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlChar * |
|
|
htmlParseAttValue(htmlParserCtxtPtr ctxt) { |
|
|
xmlChar *ret = NULL; |
|
|
int maxLength = (ctxt->options & HTML_PARSE_HUGE) ? |
|
|
XML_MAX_HUGE_LENGTH : |
|
|
XML_MAX_TEXT_LENGTH; |
|
|
|
|
|
if (CUR == '"') { |
|
|
SKIP(1); |
|
|
ret = htmlParseData(ctxt, MASK_DQ, 0, 1, maxLength); |
|
|
if (CUR == '"') |
|
|
SKIP(1); |
|
|
} else if (CUR == '\'') { |
|
|
SKIP(1); |
|
|
ret = htmlParseData(ctxt, MASK_SQ, 0, 1, maxLength); |
|
|
if (CUR == '\'') |
|
|
SKIP(1); |
|
|
} else { |
|
|
ret = htmlParseData(ctxt, MASK_WS_GT, 0, 1, maxLength); |
|
|
} |
|
|
return(ret); |
|
|
} |
|
|
|
|
|
static void |
|
|
htmlCharDataSAXCallback(htmlParserCtxtPtr ctxt, const xmlChar *buf, |
|
|
int size, int mode) { |
|
|
if ((ctxt->sax == NULL) || (ctxt->disableSAX)) |
|
|
return; |
|
|
|
|
|
if ((mode == 0) || (mode == DATA_RCDATA) || |
|
|
(ctxt->sax->cdataBlock == NULL)) { |
|
|
int blank = areBlanks(ctxt, buf, size); |
|
|
|
|
|
if ((mode == 0) && (blank > 0) && (!ctxt->keepBlanks)) { |
|
|
if (ctxt->sax->ignorableWhitespace != NULL) |
|
|
ctxt->sax->ignorableWhitespace(ctxt->userData, |
|
|
buf, size); |
|
|
} else { |
|
|
if ((mode == 0) && (blank < 0)) |
|
|
htmlCheckParagraph(ctxt); |
|
|
|
|
|
if (ctxt->sax->characters != NULL) |
|
|
ctxt->sax->characters(ctxt->userData, buf, size); |
|
|
} |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
ctxt->sax->cdataBlock(ctxt->userData, buf, size); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseCharData(htmlParserCtxtPtr ctxt) { |
|
|
xmlParserInputPtr input = ctxt->input; |
|
|
xmlChar utf8Char[4]; |
|
|
int complete = 0; |
|
|
int done = 0; |
|
|
int mode; |
|
|
int eof = PARSER_PROGRESSIVE(ctxt); |
|
|
int line, col; |
|
|
|
|
|
mode = ctxt->endCheckState; |
|
|
|
|
|
line = input->line; |
|
|
col = input->col; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
const xmlChar *chunk, *in, *repl; |
|
|
size_t avail; |
|
|
int replSize; |
|
|
int skip = 0; |
|
|
int ncr = 0; |
|
|
int ncrSize = 0; |
|
|
int cp = 0; |
|
|
|
|
|
chunk = input->cur; |
|
|
avail = input->end - chunk; |
|
|
in = chunk; |
|
|
|
|
|
repl = BAD_CAST ""; |
|
|
replSize = 0; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
size_t j; |
|
|
int cur, size; |
|
|
|
|
|
if (avail <= 64) { |
|
|
if (!eof) { |
|
|
size_t oldAvail = avail; |
|
|
size_t off = in - chunk; |
|
|
|
|
|
input->cur = in; |
|
|
|
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
in = input->cur; |
|
|
chunk = in - off; |
|
|
input->cur = chunk; |
|
|
avail = input->end - in; |
|
|
|
|
|
if (oldAvail == avail) |
|
|
eof = 1; |
|
|
} |
|
|
|
|
|
if (avail == 0) { |
|
|
done = 1; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!ncr) { |
|
|
while (avail > 0) { |
|
|
static const unsigned mask[8] = { |
|
|
0x00002401, 0x10002040, |
|
|
0x00000000, 0x00000000, |
|
|
0xFFFFFFFF, 0xFFFFFFFF, |
|
|
0xFFFFFFFF, 0xFFFFFFFF |
|
|
}; |
|
|
cur = *in; |
|
|
if ((1u << (cur & 0x1F)) & mask[cur >> 5]) |
|
|
break; |
|
|
col += 1; |
|
|
in += 1; |
|
|
avail -= 1; |
|
|
} |
|
|
|
|
|
if ((!eof) && (avail <= 64)) |
|
|
continue; |
|
|
if (avail == 0) |
|
|
continue; |
|
|
} |
|
|
|
|
|
cur = *in; |
|
|
size = 1; |
|
|
col += 1; |
|
|
|
|
|
if (ncr) { |
|
|
int lc = cur | 0x20; |
|
|
int digit; |
|
|
|
|
|
if ((cur >= '0') && (cur <= '9')) { |
|
|
digit = cur - '0'; |
|
|
} else if ((ncr == 16) && (lc >= 'a') && (lc <= 'f')) { |
|
|
digit = (lc - 'a') + 10; |
|
|
} else { |
|
|
if (cur == ';') { |
|
|
in += 1; |
|
|
size += 1; |
|
|
ncrSize += 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
cp = cp * ncr + digit; |
|
|
if (cp >= 0x110000) |
|
|
cp = 0x110000; |
|
|
|
|
|
ncrSize += 1; |
|
|
|
|
|
goto next_char; |
|
|
} |
|
|
|
|
|
switch (cur) { |
|
|
case '<': |
|
|
if (mode == 0) { |
|
|
done = 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
if (mode == DATA_PLAINTEXT) |
|
|
break; |
|
|
|
|
|
j = 1; |
|
|
if (j < avail) { |
|
|
if ((mode == DATA_SCRIPT) && (in[j] == '!')) { |
|
|
|
|
|
|
|
|
j += 1; |
|
|
if ((j < avail) && (in[j] == '-')) { |
|
|
j += 1; |
|
|
if ((j < avail) && (in[j] == '-')) |
|
|
mode = DATA_SCRIPT_ESC1; |
|
|
} |
|
|
} else { |
|
|
int i = 0; |
|
|
int solidus = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (in[j] == '/') { |
|
|
j += 1; |
|
|
solidus = 1; |
|
|
} |
|
|
|
|
|
if ((solidus) || (mode == DATA_SCRIPT_ESC1)) { |
|
|
while ((j < avail) && |
|
|
(ctxt->name[i] != 0) && |
|
|
(ctxt->name[i] == (in[j] | 0x20))) { |
|
|
i += 1; |
|
|
j += 1; |
|
|
} |
|
|
|
|
|
if ((ctxt->name[i] == 0) && (j < avail)) { |
|
|
int c = in[j]; |
|
|
|
|
|
if ((c == '>') || (c == '/') || |
|
|
(IS_WS_HTML(c))) { |
|
|
if ((mode == DATA_SCRIPT_ESC1) && |
|
|
(!solidus)) { |
|
|
mode = DATA_SCRIPT_ESC2; |
|
|
} else if (mode == DATA_SCRIPT_ESC2) { |
|
|
mode = DATA_SCRIPT_ESC1; |
|
|
} else { |
|
|
complete = 1; |
|
|
done = 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if ((mode != 0) && (PARSER_PROGRESSIVE(ctxt))) { |
|
|
in += 1; |
|
|
done = 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case '-': |
|
|
if ((mode != DATA_SCRIPT_ESC1) && (mode != DATA_SCRIPT_ESC2)) |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
j = 1; |
|
|
if ((j < avail) && (in[j] == '-')) { |
|
|
j += 1; |
|
|
if ((j < avail) && (in[j] == '>')) |
|
|
mode = DATA_SCRIPT; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case '&': |
|
|
if ((mode != 0) && (mode != DATA_RCDATA)) |
|
|
break; |
|
|
|
|
|
j = 1; |
|
|
|
|
|
if ((j < avail) && (in[j] == '#')) { |
|
|
j += 1; |
|
|
if (j < avail) { |
|
|
if ((in[j] | 0x20) == 'x') { |
|
|
j += 1; |
|
|
if ((j < avail) && (IS_HEX_DIGIT(in[j]))) { |
|
|
ncr = 16; |
|
|
size = 3; |
|
|
ncrSize = 3; |
|
|
cp = 0; |
|
|
} |
|
|
} else if (IS_ASCII_DIGIT(in[j])) { |
|
|
ncr = 10; |
|
|
size = 2; |
|
|
ncrSize = 2; |
|
|
cp = 0; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
repl = htmlFindEntityPrefix(in + j, |
|
|
avail - j, |
|
|
0, |
|
|
&skip, &replSize); |
|
|
if (repl != NULL) { |
|
|
skip += 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
skip = 0; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case '\0': |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
|
|
|
case '\n': |
|
|
line += 1; |
|
|
col = 1; |
|
|
break; |
|
|
|
|
|
case '\r': |
|
|
skip = 1; |
|
|
if (in[1] != 0x0A) { |
|
|
repl = BAD_CAST "\x0A"; |
|
|
replSize = 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
|
|
|
default: |
|
|
if (cur < 0x80) |
|
|
break; |
|
|
|
|
|
if ((input->flags & XML_INPUT_HAS_ENCODING) == 0) { |
|
|
xmlChar * guess; |
|
|
|
|
|
guess = htmlFindEncoding(ctxt); |
|
|
if (guess == NULL) { |
|
|
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1); |
|
|
} else { |
|
|
xmlSwitchEncodingName(ctxt, (const char *) guess); |
|
|
xmlFree(guess); |
|
|
} |
|
|
input->flags |= XML_INPUT_HAS_ENCODING; |
|
|
|
|
|
goto restart; |
|
|
} |
|
|
|
|
|
size = htmlValidateUtf8(ctxt, in, avail); |
|
|
|
|
|
if (size <= 0) { |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
break; |
|
|
} |
|
|
|
|
|
next_char: |
|
|
in += size; |
|
|
avail -= size; |
|
|
} |
|
|
|
|
|
next_chunk: |
|
|
if (ncrSize > 0) { |
|
|
skip = ncrSize; |
|
|
in -= ncrSize; |
|
|
|
|
|
repl = htmlCodePointToUtf8(cp, utf8Char, &replSize); |
|
|
} |
|
|
|
|
|
if (in > chunk) { |
|
|
input->cur += in - chunk; |
|
|
htmlCharDataSAXCallback(ctxt, chunk, in - chunk, mode); |
|
|
} |
|
|
|
|
|
input->cur += skip; |
|
|
if (replSize > 0) |
|
|
htmlCharDataSAXCallback(ctxt, repl, replSize, mode); |
|
|
|
|
|
SHRINK; |
|
|
|
|
|
if (done) |
|
|
break; |
|
|
|
|
|
restart: |
|
|
; |
|
|
} |
|
|
|
|
|
input->line = line; |
|
|
input->col = col; |
|
|
|
|
|
if (complete) |
|
|
ctxt->endCheckState = 0; |
|
|
else |
|
|
ctxt->endCheckState = mode; |
|
|
|
|
|
return(complete); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlChar * |
|
|
htmlSecureComment(htmlParserCtxtPtr ctxt, htmlAsciiMask mask, |
|
|
int refs, int maxLength) { |
|
|
xmlParserInputPtr input = ctxt->input; |
|
|
xmlChar *ret = NULL; |
|
|
xmlChar *buffer; |
|
|
xmlChar utf8Char[4]; |
|
|
size_t buffer_size; |
|
|
size_t used; |
|
|
int eof = PARSER_PROGRESSIVE(ctxt); |
|
|
int line, col; |
|
|
int termSkip = -1; |
|
|
|
|
|
used = 0; |
|
|
buffer_size = ctxt->spaceMax; |
|
|
buffer = (xmlChar *) ctxt->spaceTab; |
|
|
if (buffer == NULL) { |
|
|
buffer_size = 500; |
|
|
buffer = xmlMalloc(buffer_size + 1); |
|
|
if (buffer == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
line = input->line; |
|
|
col = input->col; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
const xmlChar *chunk, *in, *repl; |
|
|
size_t avail, chunkSize, extraSize; |
|
|
int replSize; |
|
|
int skip = 0; |
|
|
int ncr = 0; |
|
|
int ncrSize = 0; |
|
|
int cp = 0; |
|
|
|
|
|
chunk = input->cur; |
|
|
avail = input->end - chunk; |
|
|
in = chunk; |
|
|
|
|
|
repl = BAD_CAST ""; |
|
|
replSize = 0; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
size_t j; |
|
|
int cur, size; |
|
|
|
|
|
if ((!eof) && (avail <= 64)) { |
|
|
size_t oldAvail = avail; |
|
|
size_t off = in - chunk; |
|
|
|
|
|
input->cur = in; |
|
|
|
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
in = input->cur; |
|
|
chunk = in - off; |
|
|
input->cur = chunk; |
|
|
avail = input->end - in; |
|
|
|
|
|
if (oldAvail == avail) |
|
|
eof = 1; |
|
|
} |
|
|
|
|
|
if (avail == 0) { |
|
|
termSkip = 0; |
|
|
break; |
|
|
} |
|
|
|
|
|
cur = *in; |
|
|
size = 1; |
|
|
col += 1; |
|
|
|
|
|
if (htmlMaskMatch(mask, cur)) { |
|
|
if (avail < 2) { |
|
|
termSkip = 1; |
|
|
} else if (in[1] == '-') { |
|
|
if (avail < 3) { |
|
|
termSkip = 2; |
|
|
} else if (in[2] == '>') { |
|
|
termSkip = 3; |
|
|
} else if (in[2] == '!') { |
|
|
if (avail < 4) |
|
|
termSkip = 3; |
|
|
else if (in[3] == '>') |
|
|
termSkip = 4; |
|
|
} |
|
|
} |
|
|
|
|
|
if (termSkip >= 0) |
|
|
break; |
|
|
} |
|
|
|
|
|
if (ncr) { |
|
|
int lc = cur | 0x20; |
|
|
int digit; |
|
|
|
|
|
if ((cur >= '0') && (cur <= '9')) { |
|
|
digit = cur - '0'; |
|
|
} else if ((ncr == 16) && (lc >= 'a') && (lc <= 'f')) { |
|
|
digit = (lc - 'a') + 10; |
|
|
} else { |
|
|
if (cur == ';') { |
|
|
in += 1; |
|
|
size += 1; |
|
|
ncrSize += 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
cp = cp * ncr + digit; |
|
|
if (cp >= 0x110000) |
|
|
cp = 0x110000; |
|
|
|
|
|
ncrSize += 1; |
|
|
|
|
|
goto next_char; |
|
|
} |
|
|
|
|
|
switch (cur) { |
|
|
case '&': |
|
|
if (!refs) |
|
|
break; |
|
|
|
|
|
j = 1; |
|
|
|
|
|
if ((j < avail) && (in[j] == '#')) { |
|
|
j += 1; |
|
|
if (j < avail) { |
|
|
if ((in[j] | 0x20) == 'x') { |
|
|
j += 1; |
|
|
if ((j < avail) && (IS_HEX_DIGIT(in[j]))) { |
|
|
ncr = 16; |
|
|
size = 3; |
|
|
ncrSize = 3; |
|
|
cp = 0; |
|
|
} |
|
|
} else if (IS_ASCII_DIGIT(in[j])) { |
|
|
ncr = 10; |
|
|
size = 2; |
|
|
ncrSize = 2; |
|
|
cp = 0; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
repl = htmlFindEntityPrefix(in + j, |
|
|
avail - j, |
|
|
1, |
|
|
&skip, &replSize); |
|
|
if (repl != NULL) { |
|
|
skip += 1; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
skip = 0; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case '\0': |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
|
|
|
case '\n': |
|
|
line += 1; |
|
|
col = 1; |
|
|
break; |
|
|
|
|
|
case '\r': |
|
|
skip = 1; |
|
|
if (in[1] != 0x0A) { |
|
|
repl = BAD_CAST "\x0A"; |
|
|
replSize = 1; |
|
|
} |
|
|
goto next_chunk; |
|
|
|
|
|
case '%': |
|
|
char c = 0; |
|
|
|
|
|
if ((in[1] >= '0') && (in[1] <= '9')) { |
|
|
c = in[1] - '0'; |
|
|
} else if ((in[1] >= 'a') && (in[1] <= 'f')) { |
|
|
c = (in[1] - 'a') + 10; |
|
|
} else if ((in[1] >= 'A') && (in[1] <= 'F')) { |
|
|
c = (in[1] - 'F') + 10; |
|
|
} else { |
|
|
break; |
|
|
} |
|
|
|
|
|
c <<= 4; |
|
|
|
|
|
if ((in[2] >= '0') && (in[2] <= '9')) { |
|
|
c |= in[2] - '0'; |
|
|
} else if ((in[2] >= 'a') && (in[2] <= 'f')) { |
|
|
c |= (in[2] - 'a') + 10; |
|
|
} else if ((in[2] >= 'A') && (in[2] <= 'F')) { |
|
|
c |= (in[2] - 'F') + 10; |
|
|
} else { |
|
|
break; |
|
|
} |
|
|
|
|
|
if (IS_ASCII_DIGIT(c) || IS_ASCII_LETTER(c) ) { |
|
|
skip = 3; |
|
|
repl = BAD_CAST &c; |
|
|
replSize = 1; |
|
|
|
|
|
goto next_chunk; |
|
|
} |
|
|
break; |
|
|
|
|
|
default: |
|
|
if (cur < 0x80) |
|
|
break; |
|
|
|
|
|
if ((input->flags & XML_INPUT_HAS_ENCODING) == 0) { |
|
|
xmlChar * guess; |
|
|
|
|
|
guess = htmlFindEncoding(ctxt); |
|
|
if (guess == NULL) { |
|
|
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1); |
|
|
} else { |
|
|
xmlSwitchEncodingName(ctxt, (const char *) guess); |
|
|
xmlFree(guess); |
|
|
} |
|
|
input->flags |= XML_INPUT_HAS_ENCODING; |
|
|
|
|
|
goto restart; |
|
|
} |
|
|
|
|
|
size = htmlValidateUtf8(ctxt, in, avail); |
|
|
|
|
|
if (size <= 0) { |
|
|
skip = 1; |
|
|
repl = BAD_CAST "\xEF\xBF\xBD"; |
|
|
replSize = 3; |
|
|
goto next_chunk; |
|
|
} |
|
|
|
|
|
break; |
|
|
} |
|
|
|
|
|
next_char: |
|
|
in += size; |
|
|
avail -= size; |
|
|
} |
|
|
|
|
|
next_chunk: |
|
|
if (ncrSize > 0) { |
|
|
skip = ncrSize; |
|
|
in -= ncrSize; |
|
|
|
|
|
repl = htmlCodePointToUtf8(cp, utf8Char, &replSize); |
|
|
} |
|
|
|
|
|
chunkSize = in - chunk; |
|
|
extraSize = chunkSize + replSize; |
|
|
|
|
|
if (extraSize > buffer_size) { |
|
|
size_t newSize = (used + extraSize) * 2; |
|
|
xmlChar *tmp = (xmlChar *) xmlRealloc(buffer, newSize + 1); |
|
|
|
|
|
if (tmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
goto error; |
|
|
} |
|
|
buffer = tmp; |
|
|
buffer_size = newSize; |
|
|
} |
|
|
|
|
|
if (chunkSize > 0) { |
|
|
input->cur += chunkSize; |
|
|
memcpy(buffer + used, chunk, chunkSize); |
|
|
used += chunkSize; |
|
|
} |
|
|
|
|
|
input->cur += skip; |
|
|
if (replSize > 0) { |
|
|
memcpy(buffer + used, repl, replSize); |
|
|
used += replSize; |
|
|
} |
|
|
|
|
|
SHRINK; |
|
|
|
|
|
if (termSkip >= 0) |
|
|
break; |
|
|
|
|
|
restart: |
|
|
; |
|
|
} |
|
|
|
|
|
if (termSkip > 0) { |
|
|
input->cur += termSkip; |
|
|
col += termSkip; |
|
|
} |
|
|
|
|
|
input->line = line; |
|
|
input->col = col; |
|
|
|
|
|
ret = xmlMalloc(used + 1); |
|
|
if (ret == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
} else { |
|
|
memcpy(ret, buffer, used); |
|
|
ret[used] = 0; |
|
|
} |
|
|
|
|
|
error: |
|
|
ctxt->spaceTab = (void *) buffer; |
|
|
ctxt->spaceMax = buffer_size; |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParseComment(htmlParserCtxtPtr ctxt, int bogus) { |
|
|
const xmlChar *comment = BAD_CAST ""; |
|
|
xmlChar *buf = NULL; |
|
|
int maxLength = (ctxt->options & HTML_PARSE_HUGE) ? |
|
|
XML_MAX_HUGE_LENGTH : |
|
|
XML_MAX_TEXT_LENGTH; |
|
|
|
|
|
if (bogus) { |
|
|
buf = htmlParseData(ctxt, MASK_GT, 0, 0, maxLength); |
|
|
if (CUR == '>') |
|
|
SKIP(1); |
|
|
comment = buf; |
|
|
} else { |
|
|
if (CUR == '>') { |
|
|
SKIP(1); |
|
|
} else if ((CUR == '-') && (NXT(1) == '>')) { |
|
|
SKIP(2); |
|
|
} else { |
|
|
buf = htmlParseData(ctxt, MASK_DASH, 1, 0, maxLength); |
|
|
comment = buf; |
|
|
} |
|
|
} |
|
|
|
|
|
if (comment == NULL) |
|
|
return; |
|
|
|
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && |
|
|
(!ctxt->disableSAX)) |
|
|
ctxt->sax->comment(ctxt->userData, comment); |
|
|
|
|
|
xmlFree(buf); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlTopParseComment(htmlParserCtxtPtr ctxt, int bogus) { |
|
|
const xmlChar *comment = BAD_CAST ""; |
|
|
xmlChar *buf = NULL; |
|
|
int maxLength = (ctxt->options & HTML_PARSE_HUGE) ? |
|
|
XML_MAX_HUGE_LENGTH : |
|
|
XML_MAX_TEXT_LENGTH; |
|
|
|
|
|
if (bogus) { |
|
|
buf = htmlParseData(ctxt, MASK_GT, 0, 0, maxLength); |
|
|
if (CUR == '>') |
|
|
SKIP(1); |
|
|
comment = buf; |
|
|
} else { |
|
|
if (CUR == '>') { |
|
|
SKIP(1); |
|
|
} else if ((CUR == '-') && (NXT(1) == '>')) { |
|
|
SKIP(2); |
|
|
} else { |
|
|
buf = htmlSecureComment(ctxt, MASK_DASH, 0, maxLength); |
|
|
comment = buf; |
|
|
} |
|
|
} |
|
|
|
|
|
if (comment == NULL) |
|
|
return; |
|
|
|
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) && |
|
|
(!ctxt->disableSAX)) |
|
|
ctxt->sax->comment(ctxt->userData, comment); |
|
|
|
|
|
xmlFree(buf); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlParseCharRef(htmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED) { |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlChar * |
|
|
htmlParseDoctypeLiteral(htmlParserCtxtPtr ctxt) { |
|
|
xmlChar *ret; |
|
|
int maxLength = (ctxt->options & HTML_PARSE_HUGE) ? |
|
|
XML_MAX_TEXT_LENGTH : |
|
|
XML_MAX_NAME_LENGTH; |
|
|
|
|
|
if (CUR == '"') { |
|
|
SKIP(1); |
|
|
ret = htmlParseData(ctxt, MASK_DQ_GT, 0, 0, maxLength); |
|
|
if (CUR == '"') |
|
|
SKIP(1); |
|
|
} else if (CUR == '\'') { |
|
|
SKIP(1); |
|
|
ret = htmlParseData(ctxt, MASK_SQ_GT, 0, 0, maxLength); |
|
|
if (CUR == '\'') |
|
|
SKIP(1); |
|
|
} else { |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
static void |
|
|
htmlSkipBogusDoctype(htmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *in; |
|
|
size_t avail; |
|
|
int eof = PARSER_PROGRESSIVE(ctxt); |
|
|
int line, col; |
|
|
|
|
|
line = ctxt->input->line; |
|
|
col = ctxt->input->col; |
|
|
|
|
|
in = ctxt->input->cur; |
|
|
avail = ctxt->input->end - in; |
|
|
|
|
|
while (!PARSER_STOPPED(ctxt)) { |
|
|
int cur; |
|
|
|
|
|
if ((!eof) && (avail <= 64)) { |
|
|
size_t oldAvail = avail; |
|
|
|
|
|
ctxt->input->cur = in; |
|
|
|
|
|
xmlParserGrow(ctxt); |
|
|
|
|
|
in = ctxt->input->cur; |
|
|
avail = ctxt->input->end - in; |
|
|
|
|
|
if (oldAvail == avail) |
|
|
eof = 1; |
|
|
} |
|
|
|
|
|
if (avail == 0) |
|
|
break; |
|
|
|
|
|
col += 1; |
|
|
|
|
|
cur = *in; |
|
|
if (cur == '>') { |
|
|
in += 1; |
|
|
break; |
|
|
} else if (cur == 0x0A) { |
|
|
line += 1; |
|
|
col = 1; |
|
|
} |
|
|
|
|
|
in += 1; |
|
|
avail -= 1; |
|
|
|
|
|
SHRINK; |
|
|
} |
|
|
|
|
|
ctxt->input->cur = in; |
|
|
ctxt->input->line = line; |
|
|
ctxt->input->col = col; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParseDocTypeDecl(htmlParserCtxtPtr ctxt) { |
|
|
xmlChar *name = NULL; |
|
|
xmlChar *publicId = NULL; |
|
|
xmlChar *URI = NULL; |
|
|
int maxLength = (ctxt->options & HTML_PARSE_HUGE) ? |
|
|
XML_MAX_TEXT_LENGTH : |
|
|
XML_MAX_NAME_LENGTH; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKIP(9); |
|
|
|
|
|
SKIP_BLANKS; |
|
|
|
|
|
if ((ctxt->input->cur < ctxt->input->end) && (CUR != '>')) { |
|
|
name = htmlParseData(ctxt, MASK_WS_GT, 0, 0, maxLength); |
|
|
|
|
|
if ((ctxt->options & HTML_PARSE_HTML5) && (name != NULL)) { |
|
|
xmlChar *cur; |
|
|
|
|
|
for (cur = name; *cur; cur++) { |
|
|
if (IS_UPPER(*cur)) |
|
|
*cur += 0x20; |
|
|
} |
|
|
} |
|
|
|
|
|
SKIP_BLANKS; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((UPPER == 'P') && (UPP(1) == 'U') && |
|
|
(UPP(2) == 'B') && (UPP(3) == 'L') && |
|
|
(UPP(4) == 'I') && (UPP(5) == 'C')) { |
|
|
SKIP(6); |
|
|
SKIP_BLANKS; |
|
|
publicId = htmlParseDoctypeLiteral(ctxt); |
|
|
if (publicId == NULL) |
|
|
goto bogus; |
|
|
SKIP_BLANKS; |
|
|
URI = htmlParseDoctypeLiteral(ctxt); |
|
|
} else if ((UPPER == 'S') && (UPP(1) == 'Y') && |
|
|
(UPP(2) == 'S') && (UPP(3) == 'T') && |
|
|
(UPP(4) == 'E') && (UPP(5) == 'M')) { |
|
|
SKIP(6); |
|
|
SKIP_BLANKS; |
|
|
URI = htmlParseDoctypeLiteral(ctxt); |
|
|
} |
|
|
|
|
|
bogus: |
|
|
htmlSkipBogusDoctype(ctxt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) && |
|
|
(!ctxt->disableSAX)) |
|
|
ctxt->sax->internalSubset(ctxt->userData, name, publicId, URI); |
|
|
|
|
|
xmlFree(name); |
|
|
xmlFree(URI); |
|
|
xmlFree(publicId); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlHashedString |
|
|
htmlParseAttribute(htmlParserCtxtPtr ctxt, xmlChar **value) { |
|
|
xmlHashedString hname; |
|
|
xmlChar *val = NULL; |
|
|
|
|
|
*value = NULL; |
|
|
hname = htmlParseHTMLName(ctxt, 1); |
|
|
if (hname.name == NULL) |
|
|
return(hname); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKIP_BLANKS; |
|
|
if (CUR == '=') { |
|
|
SKIP(1); |
|
|
SKIP_BLANKS; |
|
|
val = htmlParseAttValue(ctxt); |
|
|
} |
|
|
|
|
|
*value = val; |
|
|
return(hname); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) { |
|
|
const xmlChar *encoding; |
|
|
xmlChar *copy; |
|
|
|
|
|
if (!attvalue) |
|
|
return; |
|
|
|
|
|
encoding = xmlStrcasestr(attvalue, BAD_CAST"charset"); |
|
|
if (encoding != NULL) { |
|
|
encoding += 7; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (encoding && IS_WS_HTML(*encoding)) |
|
|
encoding = xmlStrcasestr(attvalue, BAD_CAST"="); |
|
|
if (encoding && *encoding == '=') { |
|
|
encoding ++; |
|
|
copy = xmlStrdup(encoding); |
|
|
if (copy == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
xmlSetDeclaredEncoding(ctxt, copy); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlCheckMeta(htmlParserCtxtPtr ctxt, const xmlChar **atts) { |
|
|
int i; |
|
|
const xmlChar *att, *value; |
|
|
int http = 0; |
|
|
const xmlChar *content = NULL; |
|
|
|
|
|
if ((ctxt == NULL) || (atts == NULL)) |
|
|
return; |
|
|
|
|
|
i = 0; |
|
|
att = atts[i++]; |
|
|
while (att != NULL) { |
|
|
value = atts[i++]; |
|
|
if (value != NULL) { |
|
|
if ((!xmlStrcasecmp(att, BAD_CAST "http-equiv")) && |
|
|
(!xmlStrcasecmp(value, BAD_CAST "Content-Type"))) { |
|
|
http = 1; |
|
|
} else if (!xmlStrcasecmp(att, BAD_CAST "charset")) { |
|
|
xmlChar *copy; |
|
|
|
|
|
copy = xmlStrdup(value); |
|
|
if (copy == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
xmlSetDeclaredEncoding(ctxt, copy); |
|
|
} else if (!xmlStrcasecmp(att, BAD_CAST "content")) { |
|
|
content = value; |
|
|
} |
|
|
} |
|
|
att = atts[i++]; |
|
|
} |
|
|
if ((http) && (content != NULL)) |
|
|
htmlCheckEncoding(ctxt, content); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlAttrHashInsert(xmlParserCtxtPtr ctxt, unsigned size, const xmlChar *name, |
|
|
unsigned hashValue, int aindex) { |
|
|
xmlAttrHashBucket *table = ctxt->attrHash; |
|
|
xmlAttrHashBucket *bucket; |
|
|
unsigned hindex; |
|
|
|
|
|
hindex = hashValue & (size - 1); |
|
|
bucket = &table[hindex]; |
|
|
|
|
|
while (bucket->index >= 0) { |
|
|
const xmlChar **atts = &ctxt->atts[bucket->index]; |
|
|
|
|
|
if (name == atts[0]) |
|
|
return(bucket->index); |
|
|
|
|
|
hindex++; |
|
|
bucket++; |
|
|
if (hindex >= size) { |
|
|
hindex = 0; |
|
|
bucket = table; |
|
|
} |
|
|
} |
|
|
|
|
|
bucket->index = aindex; |
|
|
|
|
|
return(INT_MAX); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParseStartTag(htmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *name; |
|
|
const xmlChar *attname; |
|
|
xmlChar *attvalue; |
|
|
const xmlChar **atts; |
|
|
int nbatts = 0; |
|
|
int maxatts; |
|
|
int meta = 0; |
|
|
int i; |
|
|
int discardtag = 0; |
|
|
|
|
|
ctxt->endCheckState = 0; |
|
|
|
|
|
SKIP(1); |
|
|
|
|
|
atts = ctxt->atts; |
|
|
maxatts = ctxt->maxatts; |
|
|
|
|
|
GROW; |
|
|
name = htmlParseHTMLName(ctxt, 0).name; |
|
|
if (name == NULL) |
|
|
return; |
|
|
if (xmlStrEqual(name, BAD_CAST"meta")) |
|
|
meta = 1; |
|
|
|
|
|
if ((ctxt->options & HTML_PARSE_HTML5) == 0) { |
|
|
|
|
|
|
|
|
|
|
|
htmlAutoClose(ctxt, name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlCheckImplied(ctxt, name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ctxt->nameNr > 0) && (xmlStrEqual(name, BAD_CAST"html"))) { |
|
|
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, |
|
|
"htmlParseStartTag: misplaced <html> tag\n", |
|
|
name, NULL); |
|
|
discardtag = 1; |
|
|
ctxt->depth++; |
|
|
} |
|
|
if ((ctxt->nameNr != 1) && |
|
|
(xmlStrEqual(name, BAD_CAST"head"))) { |
|
|
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, |
|
|
"htmlParseStartTag: misplaced <head> tag\n", |
|
|
name, NULL); |
|
|
discardtag = 1; |
|
|
ctxt->depth++; |
|
|
} |
|
|
if (xmlStrEqual(name, BAD_CAST"body")) { |
|
|
int indx; |
|
|
for (indx = 0;indx < ctxt->nameNr;indx++) { |
|
|
if (xmlStrEqual(ctxt->nameTab[indx], BAD_CAST"body")) { |
|
|
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, |
|
|
"htmlParseStartTag: misplaced <body> tag\n", |
|
|
name, NULL); |
|
|
discardtag = 1; |
|
|
ctxt->depth++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKIP_BLANKS; |
|
|
while ((ctxt->input->cur < ctxt->input->end) && |
|
|
(CUR != '>') && |
|
|
((CUR != '/') || (NXT(1) != '>')) && |
|
|
(PARSER_STOPPED(ctxt) == 0)) { |
|
|
xmlHashedString hattname; |
|
|
|
|
|
|
|
|
if (CUR == '/') { |
|
|
SKIP(1); |
|
|
SKIP_BLANKS; |
|
|
continue; |
|
|
} |
|
|
GROW; |
|
|
hattname = htmlParseAttribute(ctxt, &attvalue); |
|
|
attname = hattname.name; |
|
|
|
|
|
if (attname != NULL) { |
|
|
|
|
|
|
|
|
|
|
|
if (nbatts + 4 > maxatts) { |
|
|
const xmlChar **tmp; |
|
|
unsigned *utmp; |
|
|
size_t newSize = maxatts ? maxatts * 2 : 22; |
|
|
|
|
|
tmp = xmlMalloc(newSize * sizeof(tmp[0])); |
|
|
if (tmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
if (attvalue != NULL) |
|
|
xmlFree(attvalue); |
|
|
goto failed; |
|
|
} |
|
|
|
|
|
utmp = xmlRealloc(ctxt->attallocs, |
|
|
newSize / 2 * sizeof(utmp[0])); |
|
|
if (utmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
if (attvalue != NULL) |
|
|
xmlFree(attvalue); |
|
|
xmlFree(tmp); |
|
|
goto failed; |
|
|
} |
|
|
|
|
|
if (maxatts > 0) |
|
|
memcpy(tmp, atts, maxatts * sizeof(tmp[0])); |
|
|
xmlFree(atts); |
|
|
|
|
|
atts = tmp; |
|
|
maxatts = newSize; |
|
|
ctxt->atts = atts; |
|
|
ctxt->attallocs = utmp; |
|
|
ctxt->maxatts = maxatts; |
|
|
} |
|
|
|
|
|
ctxt->attallocs[nbatts/2] = hattname.hashValue; |
|
|
atts[nbatts++] = attname; |
|
|
atts[nbatts++] = attvalue; |
|
|
} |
|
|
else { |
|
|
if (attvalue != NULL) |
|
|
xmlFree(attvalue); |
|
|
} |
|
|
|
|
|
failed: |
|
|
SKIP_BLANKS; |
|
|
} |
|
|
|
|
|
if (ctxt->input->cur >= ctxt->input->end) { |
|
|
discardtag = 1; |
|
|
goto done; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nbatts > 2) { |
|
|
unsigned attrHashSize; |
|
|
int j, k; |
|
|
|
|
|
attrHashSize = 4; |
|
|
while (attrHashSize / 2 < (unsigned) nbatts / 2) |
|
|
attrHashSize *= 2; |
|
|
|
|
|
if (attrHashSize > ctxt->attrHashMax) { |
|
|
xmlAttrHashBucket *tmp; |
|
|
|
|
|
tmp = xmlRealloc(ctxt->attrHash, attrHashSize * sizeof(tmp[0])); |
|
|
if (tmp == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
goto done; |
|
|
} |
|
|
|
|
|
ctxt->attrHash = tmp; |
|
|
ctxt->attrHashMax = attrHashSize; |
|
|
} |
|
|
|
|
|
memset(ctxt->attrHash, -1, attrHashSize * sizeof(ctxt->attrHash[0])); |
|
|
|
|
|
for (i = 0, j = 0, k = 0; i < nbatts; i += 2, k++) { |
|
|
unsigned hashValue; |
|
|
int res; |
|
|
|
|
|
attname = atts[i]; |
|
|
hashValue = ctxt->attallocs[k] | 0x80000000; |
|
|
|
|
|
res = htmlAttrHashInsert(ctxt, attrHashSize, attname, |
|
|
hashValue, j); |
|
|
if (res < 0) |
|
|
continue; |
|
|
|
|
|
if (res == INT_MAX) { |
|
|
atts[j] = atts[i]; |
|
|
atts[j+1] = atts[i+1]; |
|
|
j += 2; |
|
|
} else { |
|
|
xmlFree((xmlChar *) atts[i+1]); |
|
|
} |
|
|
} |
|
|
|
|
|
nbatts = j; |
|
|
} |
|
|
|
|
|
if (nbatts > 0) { |
|
|
atts[nbatts] = NULL; |
|
|
atts[nbatts + 1] = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (meta) |
|
|
htmlCheckMeta(ctxt, atts); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!discardtag) { |
|
|
if (ctxt->options & HTML_PARSE_HTML5) { |
|
|
if (ctxt->nameNr > 0) |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
|
|
|
htmlnamePush(ctxt, name); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL)) { |
|
|
if (nbatts != 0) |
|
|
ctxt->sax->startElement(ctxt->userData, name, atts); |
|
|
else |
|
|
ctxt->sax->startElement(ctxt->userData, name, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
done: |
|
|
if (atts != NULL) { |
|
|
for (i = 1;i < nbatts;i += 2) { |
|
|
if (atts[i] != NULL) |
|
|
xmlFree((xmlChar *) atts[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParseEndTag(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
const xmlChar *name; |
|
|
const xmlChar *oldname; |
|
|
int i; |
|
|
|
|
|
ctxt->endCheckState = 0; |
|
|
|
|
|
SKIP(2); |
|
|
|
|
|
if (CUR == '>') { |
|
|
SKIP(1); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (!IS_ASCII_LETTER(CUR)) { |
|
|
htmlParseComment(ctxt, 1); |
|
|
return; |
|
|
} |
|
|
|
|
|
name = htmlParseHTMLName(ctxt, 0).name; |
|
|
if (name == NULL) |
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKIP_BLANKS; |
|
|
while ((ctxt->input->cur < ctxt->input->end) && |
|
|
(CUR != '>') && |
|
|
((CUR != '/') || (NXT(1) != '>')) && |
|
|
(ctxt->instate != XML_PARSER_EOF)) { |
|
|
xmlChar *attvalue = NULL; |
|
|
|
|
|
|
|
|
if (CUR == '/') { |
|
|
SKIP(1); |
|
|
SKIP_BLANKS; |
|
|
continue; |
|
|
} |
|
|
GROW; |
|
|
htmlParseAttribute(ctxt, &attvalue); |
|
|
if (attvalue != NULL) |
|
|
xmlFree(attvalue); |
|
|
|
|
|
SKIP_BLANKS; |
|
|
} |
|
|
|
|
|
if (CUR == '>') { |
|
|
SKIP(1); |
|
|
} else if ((CUR == '/') && (NXT(1) == '>')) { |
|
|
SKIP(2); |
|
|
} else { |
|
|
return; |
|
|
} |
|
|
|
|
|
if (ctxt->options & HTML_PARSE_HTML5) { |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ctxt->depth > 0) && |
|
|
(xmlStrEqual(name, BAD_CAST "html") || |
|
|
xmlStrEqual(name, BAD_CAST "body") || |
|
|
xmlStrEqual(name, BAD_CAST "head"))) { |
|
|
ctxt->depth--; |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = (ctxt->nameNr - 1); i >= 0; i--) { |
|
|
if (xmlStrEqual(name, ctxt->nameTab[i])) |
|
|
break; |
|
|
} |
|
|
if (i < 0) { |
|
|
htmlParseErr(ctxt, XML_ERR_TAG_NAME_MISMATCH, |
|
|
"Unexpected end tag : %s\n", name, NULL); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlAutoCloseOnClose(ctxt, name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ctxt->name != NULL) && (!xmlStrEqual(ctxt->name, name))) { |
|
|
htmlParseErr(ctxt, XML_ERR_TAG_NAME_MISMATCH, |
|
|
"Opening and ending tag mismatch: %s and %s\n", |
|
|
name, ctxt->name); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oldname = ctxt->name; |
|
|
if ((oldname != NULL) && (xmlStrEqual(oldname, name))) { |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
htmlParseContent(htmlParserCtxtPtr ctxt) { |
|
|
GROW; |
|
|
|
|
|
while ((PARSER_STOPPED(ctxt) == 0) && |
|
|
(ctxt->input->cur < ctxt->input->end)) { |
|
|
int mode; |
|
|
|
|
|
mode = ctxt->endCheckState; |
|
|
|
|
|
if ((mode == 0) && (CUR == '<')) { |
|
|
if (NXT(1) == '/') { |
|
|
htmlParseEndTag(ctxt); |
|
|
} else if (NXT(1) == '!') { |
|
|
|
|
|
|
|
|
|
|
|
if ((UPP(2) == 'D') && (UPP(3) == 'O') && |
|
|
(UPP(4) == 'C') && (UPP(5) == 'T') && |
|
|
(UPP(6) == 'Y') && (UPP(7) == 'P') && |
|
|
(UPP(8) == 'E')) { |
|
|
htmlParseDocTypeDecl(ctxt); |
|
|
} else if ((NXT(2) == '-') && (NXT(3) == '-')) { |
|
|
SKIP(4); |
|
|
htmlParseComment(ctxt, 0); |
|
|
} else { |
|
|
SKIP(2); |
|
|
htmlParseComment(ctxt, 1); |
|
|
} |
|
|
} else if (NXT(1) == '?') { |
|
|
SKIP(1); |
|
|
htmlParseComment(ctxt, 1); |
|
|
} else if (IS_ASCII_LETTER(NXT(1))) { |
|
|
htmlParseElementInternal(ctxt); |
|
|
} else { |
|
|
htmlCheckParagraph(ctxt); |
|
|
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
|
|
(ctxt->sax->characters != NULL)) |
|
|
ctxt->sax->characters(ctxt->userData, BAD_CAST "<", 1); |
|
|
SKIP(1); |
|
|
} |
|
|
} else { |
|
|
htmlParseCharData(ctxt); |
|
|
} |
|
|
|
|
|
SHRINK; |
|
|
GROW; |
|
|
} |
|
|
|
|
|
if (ctxt->input->cur >= ctxt->input->end) |
|
|
htmlAutoCloseOnEnd(ctxt); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseElementInternal(htmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *name; |
|
|
const htmlElemDesc * info; |
|
|
htmlParserNodeInfo node_info = { NULL, 0, 0, 0, 0 }; |
|
|
|
|
|
if ((ctxt == NULL) || (ctxt->input == NULL)) |
|
|
return(0); |
|
|
|
|
|
|
|
|
if (ctxt->record_info) { |
|
|
node_info.begin_pos = ctxt->input->consumed + |
|
|
(CUR_PTR - ctxt->input->base); |
|
|
node_info.begin_line = ctxt->input->line; |
|
|
} |
|
|
|
|
|
htmlParseStartTag(ctxt); |
|
|
name = ctxt->name; |
|
|
if (name == NULL) |
|
|
return(0); |
|
|
|
|
|
if (ctxt->record_info) |
|
|
htmlNodeInfoPush(ctxt, &node_info); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((CUR == '/') && (NXT(1) == '>')) { |
|
|
SKIP(2); |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->options & HTML_PARSE_HTML5) == 0) { |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
} |
|
|
htmlnamePop(ctxt); |
|
|
return(0); |
|
|
} |
|
|
|
|
|
if (CUR != '>') |
|
|
return(0); |
|
|
SKIP(1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info = htmlTagLookup(name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((info != NULL) && (info->empty)) { |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->options & HTML_PARSE_HTML5) == 0) { |
|
|
if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
} |
|
|
htmlnamePop(ctxt); |
|
|
return(0); |
|
|
} |
|
|
|
|
|
if (info != NULL) |
|
|
ctxt->endCheckState = info->dataMode; |
|
|
|
|
|
return(1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
htmlParseElement(htmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *oldptr; |
|
|
int depth; |
|
|
|
|
|
if ((ctxt == NULL) || (ctxt->input == NULL)) |
|
|
return; |
|
|
|
|
|
if (htmlParseElementInternal(ctxt) == 0) |
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
depth = ctxt->nameNr; |
|
|
while (CUR != 0) { |
|
|
oldptr = ctxt->input->cur; |
|
|
htmlParseContent(ctxt); |
|
|
if (oldptr==ctxt->input->cur) break; |
|
|
if (ctxt->nameNr < depth) break; |
|
|
} |
|
|
|
|
|
if (CUR == 0) { |
|
|
htmlAutoCloseOnEnd(ctxt); |
|
|
} |
|
|
} |
|
|
|
|
|
xmlNodePtr |
|
|
htmlCtxtParseContentInternal(htmlParserCtxtPtr ctxt, xmlParserInputPtr input) { |
|
|
xmlNodePtr root; |
|
|
xmlNodePtr list = NULL; |
|
|
xmlChar *rootName = BAD_CAST "#root"; |
|
|
|
|
|
root = xmlNewDocNode(ctxt->myDoc, NULL, rootName, NULL); |
|
|
if (root == NULL) { |
|
|
htmlErrMemory(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeNode(root); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
htmlnamePush(ctxt, rootName); |
|
|
nodePush(ctxt, root); |
|
|
|
|
|
htmlParseContent(ctxt); |
|
|
|
|
|
|
|
|
if (ctxt->errNo != XML_ERR_NO_MEMORY) { |
|
|
xmlNodePtr cur; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list = root->children; |
|
|
root->children = NULL; |
|
|
root->last = NULL; |
|
|
for (cur = list; cur != NULL; cur = cur->next) |
|
|
cur->parent = NULL; |
|
|
} |
|
|
|
|
|
nodePop(ctxt); |
|
|
htmlnamePop(ctxt); |
|
|
|
|
|
xmlCtxtPopInput(ctxt); |
|
|
|
|
|
xmlFreeNode(root); |
|
|
return(list); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlParseDocument(htmlParserCtxtPtr ctxt) { |
|
|
xmlDtdPtr dtd; |
|
|
|
|
|
if ((ctxt == NULL) || (ctxt->input == NULL)) |
|
|
return(-1); |
|
|
|
|
|
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) { |
|
|
ctxt->sax->setDocumentLocator(ctxt->userData, |
|
|
(xmlSAXLocator *) &xmlDefaultSAXLocator); |
|
|
} |
|
|
|
|
|
xmlDetectEncoding(ctxt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) && |
|
|
(xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0)) |
|
|
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SKIP_BLANKS; |
|
|
|
|
|
if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX)) |
|
|
ctxt->sax->startDocument(ctxt->userData); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (CUR == '<') { |
|
|
if ((NXT(1) == '!') && (NXT(2) == '-') && (NXT(3) == '-')) { |
|
|
SKIP(4); |
|
|
htmlTopParseComment(ctxt, 0); |
|
|
} else if (NXT(1) == '?') { |
|
|
SKIP(1); |
|
|
htmlTopParseComment(ctxt, 1); |
|
|
} else { |
|
|
break; |
|
|
} |
|
|
SKIP_BLANKS; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((CUR == '<') && (NXT(1) == '!') && |
|
|
(UPP(2) == 'D') && (UPP(3) == 'O') && |
|
|
(UPP(4) == 'C') && (UPP(5) == 'T') && |
|
|
(UPP(6) == 'Y') && (UPP(7) == 'P') && |
|
|
(UPP(8) == 'E')) { |
|
|
ctxt->instate = XML_PARSER_MISC; |
|
|
htmlParseDocTypeDecl(ctxt); |
|
|
} |
|
|
SKIP_BLANKS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctxt->instate = XML_PARSER_PROLOG; |
|
|
while (CUR == '<') { |
|
|
if ((NXT(1) == '!') && (NXT(2) == '-') && (NXT(3) == '-')) { |
|
|
SKIP(4); |
|
|
htmlParseComment(ctxt, 0); |
|
|
} else if (NXT(1) == '?') { |
|
|
SKIP(1); |
|
|
htmlParseComment(ctxt, 1); |
|
|
} else { |
|
|
break; |
|
|
} |
|
|
SKIP_BLANKS; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
htmlParseContent(ctxt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CUR == 0) |
|
|
htmlAutoCloseOnEnd(ctxt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
|
|
ctxt->sax->endDocument(ctxt->userData); |
|
|
|
|
|
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) && (ctxt->myDoc != NULL)) { |
|
|
dtd = xmlGetIntSubset(ctxt->myDoc); |
|
|
if (dtd == NULL) { |
|
|
ctxt->myDoc->intSubset = |
|
|
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html", |
|
|
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN", |
|
|
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd"); |
|
|
if (ctxt->myDoc->intSubset == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
} |
|
|
} |
|
|
if (! ctxt->wellFormed) return(-1); |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlInitParserCtxt(htmlParserCtxtPtr ctxt, const htmlSAXHandler *sax, |
|
|
void *userData) |
|
|
{ |
|
|
if (ctxt == NULL) return(-1); |
|
|
memset(ctxt, 0, sizeof(htmlParserCtxt)); |
|
|
|
|
|
ctxt->dict = xmlDictCreate(); |
|
|
if (ctxt->dict == NULL) |
|
|
return(-1); |
|
|
|
|
|
if (ctxt->sax == NULL) |
|
|
ctxt->sax = (htmlSAXHandler *) xmlMalloc(sizeof(htmlSAXHandler)); |
|
|
if (ctxt->sax == NULL) |
|
|
return(-1); |
|
|
if (sax == NULL) { |
|
|
memset(ctxt->sax, 0, sizeof(htmlSAXHandler)); |
|
|
xmlSAX2InitHtmlDefaultSAXHandler(ctxt->sax); |
|
|
ctxt->userData = ctxt; |
|
|
} else { |
|
|
memcpy(ctxt->sax, sax, sizeof(htmlSAXHandler)); |
|
|
ctxt->userData = userData ? userData : ctxt; |
|
|
} |
|
|
|
|
|
|
|
|
ctxt->inputTab = (htmlParserInputPtr *) |
|
|
xmlMalloc(5 * sizeof(htmlParserInputPtr)); |
|
|
if (ctxt->inputTab == NULL) |
|
|
return(-1); |
|
|
ctxt->inputNr = 0; |
|
|
ctxt->inputMax = 5; |
|
|
ctxt->input = NULL; |
|
|
ctxt->version = NULL; |
|
|
ctxt->encoding = NULL; |
|
|
ctxt->standalone = -1; |
|
|
ctxt->instate = XML_PARSER_START; |
|
|
|
|
|
|
|
|
ctxt->nodeTab = (htmlNodePtr *) xmlMalloc(10 * sizeof(htmlNodePtr)); |
|
|
if (ctxt->nodeTab == NULL) |
|
|
return(-1); |
|
|
ctxt->nodeNr = 0; |
|
|
ctxt->nodeMax = 10; |
|
|
ctxt->node = NULL; |
|
|
|
|
|
|
|
|
ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *)); |
|
|
if (ctxt->nameTab == NULL) |
|
|
return(-1); |
|
|
ctxt->nameNr = 0; |
|
|
ctxt->nameMax = 10; |
|
|
ctxt->name = NULL; |
|
|
|
|
|
ctxt->nodeInfoTab = NULL; |
|
|
ctxt->nodeInfoNr = 0; |
|
|
ctxt->nodeInfoMax = 0; |
|
|
|
|
|
ctxt->myDoc = NULL; |
|
|
ctxt->wellFormed = 1; |
|
|
ctxt->replaceEntities = 0; |
|
|
ctxt->linenumbers = xmlLineNumbersDefaultValue; |
|
|
ctxt->keepBlanks = xmlKeepBlanksDefaultValue; |
|
|
ctxt->html = 1; |
|
|
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT; |
|
|
ctxt->vctxt.userData = ctxt; |
|
|
ctxt->vctxt.error = xmlParserValidityError; |
|
|
ctxt->vctxt.warning = xmlParserValidityWarning; |
|
|
ctxt->record_info = 0; |
|
|
ctxt->validate = 0; |
|
|
ctxt->checkIndex = 0; |
|
|
ctxt->catalogs = NULL; |
|
|
xmlInitNodeInfoSeq(&ctxt->node_seq); |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
htmlFreeParserCtxt(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlParserCtxtPtr |
|
|
htmlNewParserCtxt(void) |
|
|
{ |
|
|
return(htmlNewSAXParserCtxt(NULL, NULL)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlParserCtxtPtr |
|
|
htmlNewSAXParserCtxt(const htmlSAXHandler *sax, void *userData) |
|
|
{ |
|
|
xmlParserCtxtPtr ctxt; |
|
|
|
|
|
xmlInitParser(); |
|
|
|
|
|
ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt)); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
memset(ctxt, 0, sizeof(xmlParserCtxt)); |
|
|
if (htmlInitParserCtxt(ctxt, sax, userData) < 0) { |
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
return(ctxt); |
|
|
} |
|
|
|
|
|
static htmlParserCtxtPtr |
|
|
htmlCreateMemoryParserCtxtInternal(const char *url, |
|
|
const char *buffer, size_t size, |
|
|
const char *encoding) { |
|
|
xmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (buffer == NULL) |
|
|
return(NULL); |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
input = xmlCtxtNewInputFromMemory(ctxt, url, buffer, size, encoding, 0); |
|
|
if (input == NULL) { |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeInputStream(input); |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
return(ctxt); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlParserCtxtPtr |
|
|
htmlCreateMemoryParserCtxt(const char *buffer, int size) { |
|
|
if (size <= 0) |
|
|
return(NULL); |
|
|
|
|
|
return(htmlCreateMemoryParserCtxtInternal(NULL, buffer, size, NULL)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static htmlParserCtxtPtr |
|
|
htmlCreateDocParserCtxt(const xmlChar *str, const char *url, |
|
|
const char *encoding) { |
|
|
xmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (str == NULL) |
|
|
return(NULL); |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
input = xmlCtxtNewInputFromString(ctxt, url, (const char *) str, |
|
|
encoding, 0); |
|
|
if (input == NULL) { |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeInputStream(input); |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
return(ctxt); |
|
|
} |
|
|
|
|
|
#ifdef LIBXML_PUSH_ENABLED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum xmlLookupStates { |
|
|
LSTATE_TAG_NAME = 0, |
|
|
LSTATE_BEFORE_ATTR_NAME, |
|
|
LSTATE_ATTR_NAME, |
|
|
LSTATE_AFTER_ATTR_NAME, |
|
|
LSTATE_BEFORE_ATTR_VALUE, |
|
|
LSTATE_ATTR_VALUE_DQUOTED, |
|
|
LSTATE_ATTR_VALUE_SQUOTED, |
|
|
LSTATE_ATTR_VALUE_UNQUOTED |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseLookupGt(xmlParserCtxtPtr ctxt) { |
|
|
const xmlChar *cur; |
|
|
const xmlChar *end = ctxt->input->end; |
|
|
int state = ctxt->endCheckState; |
|
|
size_t index; |
|
|
|
|
|
if (ctxt->checkIndex == 0) |
|
|
cur = ctxt->input->cur + 2; |
|
|
else |
|
|
cur = ctxt->input->cur + ctxt->checkIndex; |
|
|
|
|
|
while (cur < end) { |
|
|
int c = *cur++; |
|
|
|
|
|
if (state != LSTATE_ATTR_VALUE_SQUOTED && |
|
|
state != LSTATE_ATTR_VALUE_DQUOTED) { |
|
|
if (c == '/' && |
|
|
state != LSTATE_BEFORE_ATTR_VALUE && |
|
|
state != LSTATE_ATTR_VALUE_UNQUOTED) { |
|
|
state = LSTATE_BEFORE_ATTR_NAME; |
|
|
continue; |
|
|
} else if (c == '>') { |
|
|
ctxt->checkIndex = 0; |
|
|
ctxt->endCheckState = 0; |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
|
|
|
switch (state) { |
|
|
case LSTATE_TAG_NAME: |
|
|
if (IS_WS_HTML(c)) |
|
|
state = LSTATE_BEFORE_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_BEFORE_ATTR_NAME: |
|
|
if (!IS_WS_HTML(c)) |
|
|
state = LSTATE_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_ATTR_NAME: |
|
|
if (c == '=') |
|
|
state = LSTATE_BEFORE_ATTR_VALUE; |
|
|
else if (IS_WS_HTML(c)) |
|
|
state = LSTATE_AFTER_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_AFTER_ATTR_NAME: |
|
|
if (c == '=') |
|
|
state = LSTATE_BEFORE_ATTR_VALUE; |
|
|
else if (!IS_WS_HTML(c)) |
|
|
state = LSTATE_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_BEFORE_ATTR_VALUE: |
|
|
if (c == '"') |
|
|
state = LSTATE_ATTR_VALUE_DQUOTED; |
|
|
else if (c == '\'') |
|
|
state = LSTATE_ATTR_VALUE_SQUOTED; |
|
|
else if (!IS_WS_HTML(c)) |
|
|
state = LSTATE_ATTR_VALUE_UNQUOTED; |
|
|
break; |
|
|
|
|
|
case LSTATE_ATTR_VALUE_DQUOTED: |
|
|
if (c == '"') |
|
|
state = LSTATE_BEFORE_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_ATTR_VALUE_SQUOTED: |
|
|
if (c == '\'') |
|
|
state = LSTATE_BEFORE_ATTR_NAME; |
|
|
break; |
|
|
|
|
|
case LSTATE_ATTR_VALUE_UNQUOTED: |
|
|
if (IS_WS_HTML(c)) |
|
|
state = LSTATE_BEFORE_ATTR_NAME; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
index = cur - ctxt->input->cur; |
|
|
if (index > LONG_MAX) { |
|
|
ctxt->checkIndex = 0; |
|
|
ctxt->endCheckState = 0; |
|
|
return(0); |
|
|
} |
|
|
ctxt->checkIndex = index; |
|
|
ctxt->endCheckState = state; |
|
|
return(-1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseLookupString(xmlParserCtxtPtr ctxt, size_t startDelta, |
|
|
const char *str, size_t strLen, size_t extraLen) { |
|
|
const xmlChar *end = ctxt->input->end; |
|
|
const xmlChar *cur, *term; |
|
|
size_t index, rescan; |
|
|
int ret; |
|
|
|
|
|
if (ctxt->checkIndex == 0) { |
|
|
cur = ctxt->input->cur + startDelta; |
|
|
} else { |
|
|
cur = ctxt->input->cur + ctxt->checkIndex; |
|
|
} |
|
|
|
|
|
term = BAD_CAST strstr((const char *) cur, str); |
|
|
if ((term != NULL) && |
|
|
((size_t) (ctxt->input->end - term) >= extraLen + 1)) { |
|
|
ctxt->checkIndex = 0; |
|
|
|
|
|
if (term - ctxt->input->cur > INT_MAX / 2) |
|
|
ret = INT_MAX / 2; |
|
|
else |
|
|
ret = term - ctxt->input->cur; |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
rescan = strLen + extraLen - 1; |
|
|
if ((size_t) (end - cur) <= rescan) |
|
|
end = cur; |
|
|
else |
|
|
end -= rescan; |
|
|
index = end - ctxt->input->cur; |
|
|
if (index > INT_MAX / 2) { |
|
|
ctxt->checkIndex = 0; |
|
|
ret = INT_MAX / 2; |
|
|
} else { |
|
|
ctxt->checkIndex = index; |
|
|
ret = -1; |
|
|
} |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseLookupCommentEnd(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
int mark = 0; |
|
|
int offset; |
|
|
|
|
|
while (1) { |
|
|
mark = htmlParseLookupString(ctxt, 2, "--", 2, 0); |
|
|
if (mark < 0) |
|
|
break; |
|
|
if ((NXT(mark+2) == '>') || |
|
|
((NXT(mark+2) == '!') && (NXT(mark+3) == '>'))) { |
|
|
ctxt->checkIndex = 0; |
|
|
break; |
|
|
} |
|
|
offset = (NXT(mark+2) == '!') ? 3 : 2; |
|
|
if (mark + offset >= ctxt->input->end - ctxt->input->cur) { |
|
|
ctxt->checkIndex = mark; |
|
|
return(-1); |
|
|
} |
|
|
ctxt->checkIndex = mark + 1; |
|
|
} |
|
|
return mark; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int |
|
|
htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { |
|
|
int ret = 0; |
|
|
htmlParserInputPtr in; |
|
|
ptrdiff_t avail = 0; |
|
|
int cur; |
|
|
|
|
|
htmlParserNodeInfo node_info; |
|
|
|
|
|
while (PARSER_STOPPED(ctxt) == 0) { |
|
|
|
|
|
in = ctxt->input; |
|
|
if (in == NULL) break; |
|
|
avail = in->end - in->cur; |
|
|
if ((avail == 0) && (terminate)) { |
|
|
htmlAutoCloseOnEnd(ctxt); |
|
|
if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) { |
|
|
|
|
|
|
|
|
|
|
|
ctxt->instate = XML_PARSER_EOF; |
|
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
|
|
ctxt->sax->endDocument(ctxt->userData); |
|
|
} |
|
|
} |
|
|
if (avail < 1) |
|
|
goto done; |
|
|
cur = in->cur[0]; |
|
|
|
|
|
switch (ctxt->instate) { |
|
|
case XML_PARSER_EOF: |
|
|
|
|
|
|
|
|
|
|
|
goto done; |
|
|
case XML_PARSER_START: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) && |
|
|
(xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0)) { |
|
|
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8); |
|
|
} |
|
|
|
|
|
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator)) { |
|
|
ctxt->sax->setDocumentLocator(ctxt->userData, |
|
|
(xmlSAXLocator *) &xmlDefaultSAXLocator); |
|
|
} |
|
|
if ((ctxt->sax) && (ctxt->sax->startDocument) && |
|
|
(!ctxt->disableSAX)) |
|
|
ctxt->sax->startDocument(ctxt->userData); |
|
|
|
|
|
|
|
|
if (ctxt->instate == XML_PARSER_START) |
|
|
ctxt->instate = XML_PARSER_MISC; |
|
|
break; |
|
|
case XML_PARSER_START_TAG: { |
|
|
const xmlChar *name; |
|
|
int next; |
|
|
const htmlElemDesc * info; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (avail < 2) |
|
|
goto done; |
|
|
cur = in->cur[0]; |
|
|
next = in->cur[1]; |
|
|
if (cur != '<') { |
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
break; |
|
|
} |
|
|
if (next == '/') { |
|
|
ctxt->instate = XML_PARSER_END_TAG; |
|
|
ctxt->checkIndex = 0; |
|
|
break; |
|
|
} |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupGt(ctxt) < 0)) |
|
|
goto done; |
|
|
|
|
|
|
|
|
if (ctxt->record_info) { |
|
|
node_info.begin_pos = ctxt->input->consumed + |
|
|
(CUR_PTR - ctxt->input->base); |
|
|
node_info.begin_line = ctxt->input->line; |
|
|
} |
|
|
|
|
|
|
|
|
htmlParseStartTag(ctxt); |
|
|
name = ctxt->name; |
|
|
if (name == NULL) |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((CUR == '/') && (NXT(1) == '>')) { |
|
|
SKIP(2); |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->options & HTML_PARSE_HTML5) == 0) { |
|
|
if ((ctxt->sax != NULL) && |
|
|
(ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
} |
|
|
htmlnamePop(ctxt); |
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
break; |
|
|
} |
|
|
|
|
|
if (CUR != '>') |
|
|
break; |
|
|
SKIP(1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info = htmlTagLookup(name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((info != NULL) && (info->empty)) { |
|
|
htmlParserFinishElementParsing(ctxt); |
|
|
if ((ctxt->options & HTML_PARSE_HTML5) == 0) { |
|
|
if ((ctxt->sax != NULL) && |
|
|
(ctxt->sax->endElement != NULL)) |
|
|
ctxt->sax->endElement(ctxt->userData, name); |
|
|
} |
|
|
htmlnamePop(ctxt); |
|
|
} |
|
|
|
|
|
if (info != NULL) |
|
|
ctxt->endCheckState = info->dataMode; |
|
|
|
|
|
if (ctxt->record_info) |
|
|
htmlNodeInfoPush(ctxt, &node_info); |
|
|
|
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
break; |
|
|
} |
|
|
case XML_PARSER_MISC: |
|
|
case XML_PARSER_PROLOG: |
|
|
case XML_PARSER_CONTENT: |
|
|
case XML_PARSER_EPILOG: { |
|
|
int mode; |
|
|
|
|
|
if ((ctxt->instate == XML_PARSER_MISC) || |
|
|
(ctxt->instate == XML_PARSER_PROLOG)) { |
|
|
SKIP_BLANKS; |
|
|
avail = in->end - in->cur; |
|
|
} |
|
|
|
|
|
if (avail < 1) |
|
|
goto done; |
|
|
cur = in->cur[0]; |
|
|
mode = ctxt->endCheckState; |
|
|
|
|
|
if (mode != 0) { |
|
|
while ((PARSER_STOPPED(ctxt) == 0) && |
|
|
(in->cur < in->end)) { |
|
|
size_t extra; |
|
|
|
|
|
extra = strlen((const char *) ctxt->name) + 2; |
|
|
|
|
|
if ((!terminate) && |
|
|
(htmlParseLookupString(ctxt, 0, "<", 1, |
|
|
extra) < 0)) |
|
|
goto done; |
|
|
ctxt->checkIndex = 0; |
|
|
|
|
|
if (htmlParseCharData(ctxt)) |
|
|
break; |
|
|
} |
|
|
|
|
|
break; |
|
|
} else if (cur == '<') { |
|
|
int next; |
|
|
|
|
|
if (avail < 2) { |
|
|
if (!terminate) |
|
|
goto done; |
|
|
next = ' '; |
|
|
} else { |
|
|
next = in->cur[1]; |
|
|
} |
|
|
|
|
|
if (next == '!') { |
|
|
if ((!terminate) && (avail < 4)) |
|
|
goto done; |
|
|
if ((in->cur[2] == '-') && (in->cur[3] == '-')) { |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupCommentEnd(ctxt) < 0)) |
|
|
goto done; |
|
|
SKIP(4); |
|
|
htmlParseComment(ctxt, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
if ((!terminate) && (avail < 9)) |
|
|
goto done; |
|
|
if ((UPP(2) == 'D') && (UPP(3) == 'O') && |
|
|
(UPP(4) == 'C') && (UPP(5) == 'T') && |
|
|
(UPP(6) == 'Y') && (UPP(7) == 'P') && |
|
|
(UPP(8) == 'E')) { |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupString(ctxt, 9, ">", 1, |
|
|
0) < 0)) |
|
|
goto done; |
|
|
htmlParseDocTypeDecl(ctxt); |
|
|
if (ctxt->instate == XML_PARSER_MISC) |
|
|
ctxt->instate = XML_PARSER_PROLOG; |
|
|
} else { |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupString(ctxt, 2, ">", 1, 0) < 0)) |
|
|
goto done; |
|
|
SKIP(2); |
|
|
htmlParseComment(ctxt, 1); |
|
|
} |
|
|
} else if (next == '?') { |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupString(ctxt, 2, ">", 1, 0) < 0)) |
|
|
goto done; |
|
|
SKIP(1); |
|
|
htmlParseComment(ctxt, 1); |
|
|
} else if (next == '/') { |
|
|
ctxt->instate = XML_PARSER_END_TAG; |
|
|
ctxt->checkIndex = 0; |
|
|
break; |
|
|
} else if (IS_ASCII_LETTER(next)) { |
|
|
if ((!terminate) && (next == 0)) |
|
|
goto done; |
|
|
ctxt->instate = XML_PARSER_START_TAG; |
|
|
ctxt->checkIndex = 0; |
|
|
break; |
|
|
} else { |
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
htmlCheckParagraph(ctxt); |
|
|
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
|
|
(ctxt->sax->characters != NULL)) |
|
|
ctxt->sax->characters(ctxt->userData, |
|
|
BAD_CAST "<", 1); |
|
|
SKIP(1); |
|
|
} |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((!terminate) && |
|
|
(htmlParseLookupString(ctxt, 0, "<", 1, 0) < 0)) |
|
|
goto done; |
|
|
ctxt->checkIndex = 0; |
|
|
htmlParseCharData(ctxt); |
|
|
} |
|
|
|
|
|
break; |
|
|
} |
|
|
case XML_PARSER_END_TAG: |
|
|
if ((terminate) && (avail == 2)) { |
|
|
htmlCheckParagraph(ctxt); |
|
|
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && |
|
|
(ctxt->sax->characters != NULL)) |
|
|
ctxt->sax->characters(ctxt->userData, |
|
|
BAD_CAST "</", 2); |
|
|
goto done; |
|
|
} |
|
|
if ((!terminate) && |
|
|
(htmlParseLookupGt(ctxt) < 0)) |
|
|
goto done; |
|
|
htmlParseEndTag(ctxt); |
|
|
if (ctxt->nameNr == 0) { |
|
|
ctxt->instate = XML_PARSER_EPILOG; |
|
|
} else { |
|
|
ctxt->instate = XML_PARSER_CONTENT; |
|
|
} |
|
|
ctxt->checkIndex = 0; |
|
|
break; |
|
|
default: |
|
|
htmlParseErr(ctxt, XML_ERR_INTERNAL_ERROR, |
|
|
"HPP: internal error\n", NULL, NULL); |
|
|
ctxt->instate = XML_PARSER_EOF; |
|
|
break; |
|
|
} |
|
|
} |
|
|
done: |
|
|
if ((avail == 0) && (terminate)) { |
|
|
htmlAutoCloseOnEnd(ctxt); |
|
|
if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) { |
|
|
|
|
|
|
|
|
|
|
|
ctxt->instate = XML_PARSER_EOF; |
|
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
|
|
ctxt->sax->endDocument(ctxt->userData); |
|
|
} |
|
|
} |
|
|
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) && (ctxt->myDoc != NULL) && |
|
|
((terminate) || (ctxt->instate == XML_PARSER_EOF) || |
|
|
(ctxt->instate == XML_PARSER_EPILOG))) { |
|
|
xmlDtdPtr dtd; |
|
|
dtd = xmlGetIntSubset(ctxt->myDoc); |
|
|
if (dtd == NULL) { |
|
|
ctxt->myDoc->intSubset = |
|
|
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html", |
|
|
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN", |
|
|
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd"); |
|
|
if (ctxt->myDoc->intSubset == NULL) |
|
|
htmlErrMemory(ctxt); |
|
|
} |
|
|
} |
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size, |
|
|
int terminate) { |
|
|
if ((ctxt == NULL) || (ctxt->input == NULL)) |
|
|
return(XML_ERR_ARGUMENT); |
|
|
if (PARSER_STOPPED(ctxt) != 0) |
|
|
return(ctxt->errNo); |
|
|
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && |
|
|
(ctxt->input->buf != NULL)) { |
|
|
size_t pos = ctxt->input->cur - ctxt->input->base; |
|
|
int res; |
|
|
|
|
|
res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); |
|
|
xmlBufUpdateInput(ctxt->input->buf->buffer, ctxt->input, pos); |
|
|
if (res < 0) { |
|
|
htmlParseErr(ctxt, ctxt->input->buf->error, |
|
|
"xmlParserInputBufferPush failed", NULL, NULL); |
|
|
xmlHaltParser(ctxt); |
|
|
return (ctxt->errNo); |
|
|
} |
|
|
} |
|
|
htmlParseTryOrFinish(ctxt, terminate); |
|
|
if (terminate) { |
|
|
if (ctxt->instate != XML_PARSER_EOF) { |
|
|
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL)) |
|
|
ctxt->sax->endDocument(ctxt->userData); |
|
|
} |
|
|
ctxt->instate = XML_PARSER_EOF; |
|
|
} |
|
|
return((xmlParserErrors) ctxt->errNo); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlParserCtxtPtr |
|
|
htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data, |
|
|
const char *chunk, int size, const char *filename, |
|
|
xmlCharEncoding enc) { |
|
|
htmlParserCtxtPtr ctxt; |
|
|
htmlParserInputPtr input; |
|
|
const char *encoding; |
|
|
|
|
|
ctxt = htmlNewSAXParserCtxt(sax, user_data); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
encoding = xmlGetCharEncodingName(enc); |
|
|
input = xmlNewPushInput(filename, chunk, size); |
|
|
if (input == NULL) { |
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeInputStream(input); |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
if (encoding != NULL) |
|
|
xmlSwitchEncodingName(ctxt, encoding); |
|
|
|
|
|
return(ctxt); |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlSAXParseDoc(const xmlChar *cur, const char *encoding, |
|
|
htmlSAXHandlerPtr sax, void *userData) { |
|
|
htmlDocPtr ret; |
|
|
htmlParserCtxtPtr ctxt; |
|
|
|
|
|
if (cur == NULL) |
|
|
return(NULL); |
|
|
|
|
|
ctxt = htmlCreateDocParserCtxt(cur, NULL, encoding); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
if (sax != NULL) { |
|
|
*ctxt->sax = *sax; |
|
|
ctxt->userData = userData; |
|
|
} |
|
|
|
|
|
htmlParseDocument(ctxt); |
|
|
ret = ctxt->myDoc; |
|
|
htmlFreeParserCtxt(ctxt); |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlParseDoc(const xmlChar *cur, const char *encoding) { |
|
|
return(htmlSAXParseDoc(cur, encoding, NULL, NULL)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlParserCtxtPtr |
|
|
htmlCreateFileParserCtxt(const char *filename, const char *encoding) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
htmlParserInputPtr input; |
|
|
|
|
|
if (filename == NULL) |
|
|
return(NULL); |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) { |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0); |
|
|
if (input == NULL) { |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeInputStream(input); |
|
|
xmlFreeParserCtxt(ctxt); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
return(ctxt); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlSAXParseFile(const char *filename, const char *encoding, htmlSAXHandlerPtr sax, |
|
|
void *userData) { |
|
|
htmlDocPtr ret; |
|
|
htmlParserCtxtPtr ctxt; |
|
|
htmlSAXHandlerPtr oldsax = NULL; |
|
|
|
|
|
ctxt = htmlCreateFileParserCtxt(filename, encoding); |
|
|
if (ctxt == NULL) return(NULL); |
|
|
if (sax != NULL) { |
|
|
oldsax = ctxt->sax; |
|
|
ctxt->sax = sax; |
|
|
ctxt->userData = userData; |
|
|
} |
|
|
|
|
|
htmlParseDocument(ctxt); |
|
|
|
|
|
ret = ctxt->myDoc; |
|
|
if (sax != NULL) { |
|
|
ctxt->sax = oldsax; |
|
|
ctxt->userData = NULL; |
|
|
} |
|
|
htmlFreeParserCtxt(ctxt); |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlParseFile(const char *filename, const char *encoding) { |
|
|
return(htmlSAXParseFile(filename, encoding, NULL, NULL)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlHandleOmittedElem(int val) { |
|
|
int old = htmlOmittedDefaultValue; |
|
|
|
|
|
htmlOmittedDefaultValue = val; |
|
|
return(old); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlElementAllowedHere(const htmlElemDesc* parent ATTRIBUTE_UNUSED, |
|
|
const xmlChar* elt ATTRIBUTE_UNUSED) { |
|
|
return(1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlStatus |
|
|
htmlElementStatusHere(const htmlElemDesc* parent ATTRIBUTE_UNUSED, |
|
|
const htmlElemDesc* elt ATTRIBUTE_UNUSED) { |
|
|
return(HTML_VALID); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlStatus |
|
|
htmlAttrAllowed(const htmlElemDesc* elt ATTRIBUTE_UNUSED, |
|
|
const xmlChar* attr ATTRIBUTE_UNUSED, |
|
|
int legacy ATTRIBUTE_UNUSED) { |
|
|
return(HTML_VALID); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlStatus |
|
|
htmlNodeStatus(htmlNodePtr node ATTRIBUTE_UNUSED, |
|
|
int legacy ATTRIBUTE_UNUSED) { |
|
|
return(HTML_VALID); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DICT_FREE(str) \ |
|
|
if ((str) && ((!dict) || \ |
|
|
(xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ |
|
|
xmlFree((char *)(str)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
htmlCtxtReset(htmlParserCtxtPtr ctxt) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
xmlDictPtr dict; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return; |
|
|
|
|
|
dict = ctxt->dict; |
|
|
|
|
|
while ((input = xmlCtxtPopInput(ctxt)) != NULL) { |
|
|
xmlFreeInputStream(input); |
|
|
} |
|
|
ctxt->inputNr = 0; |
|
|
ctxt->input = NULL; |
|
|
|
|
|
ctxt->spaceNr = 0; |
|
|
if (ctxt->spaceTab != NULL) { |
|
|
ctxt->spaceTab[0] = -1; |
|
|
ctxt->space = &ctxt->spaceTab[0]; |
|
|
} else { |
|
|
ctxt->space = NULL; |
|
|
} |
|
|
|
|
|
|
|
|
ctxt->nodeNr = 0; |
|
|
ctxt->node = NULL; |
|
|
|
|
|
ctxt->nameNr = 0; |
|
|
ctxt->name = NULL; |
|
|
|
|
|
ctxt->nsNr = 0; |
|
|
|
|
|
DICT_FREE(ctxt->version); |
|
|
ctxt->version = NULL; |
|
|
DICT_FREE(ctxt->encoding); |
|
|
ctxt->encoding = NULL; |
|
|
DICT_FREE(ctxt->extSubURI); |
|
|
ctxt->extSubURI = NULL; |
|
|
DICT_FREE(ctxt->extSubSystem); |
|
|
ctxt->extSubSystem = NULL; |
|
|
|
|
|
if (ctxt->directory != NULL) { |
|
|
xmlFree(ctxt->directory); |
|
|
ctxt->directory = NULL; |
|
|
} |
|
|
|
|
|
if (ctxt->myDoc != NULL) |
|
|
xmlFreeDoc(ctxt->myDoc); |
|
|
ctxt->myDoc = NULL; |
|
|
|
|
|
ctxt->standalone = -1; |
|
|
ctxt->hasExternalSubset = 0; |
|
|
ctxt->hasPErefs = 0; |
|
|
ctxt->html = 1; |
|
|
ctxt->instate = XML_PARSER_START; |
|
|
|
|
|
ctxt->wellFormed = 1; |
|
|
ctxt->nsWellFormed = 1; |
|
|
ctxt->disableSAX = 0; |
|
|
ctxt->valid = 1; |
|
|
ctxt->vctxt.userData = ctxt; |
|
|
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT; |
|
|
ctxt->vctxt.error = xmlParserValidityError; |
|
|
ctxt->vctxt.warning = xmlParserValidityWarning; |
|
|
ctxt->record_info = 0; |
|
|
ctxt->checkIndex = 0; |
|
|
ctxt->endCheckState = 0; |
|
|
ctxt->inSubset = 0; |
|
|
ctxt->errNo = XML_ERR_OK; |
|
|
ctxt->depth = 0; |
|
|
ctxt->catalogs = NULL; |
|
|
xmlInitNodeInfoSeq(&ctxt->node_seq); |
|
|
|
|
|
if (ctxt->attsDefault != NULL) { |
|
|
xmlHashFree(ctxt->attsDefault, xmlHashDefaultDeallocator); |
|
|
ctxt->attsDefault = NULL; |
|
|
} |
|
|
if (ctxt->attsSpecial != NULL) { |
|
|
xmlHashFree(ctxt->attsSpecial, NULL); |
|
|
ctxt->attsSpecial = NULL; |
|
|
} |
|
|
|
|
|
ctxt->nbErrors = 0; |
|
|
ctxt->nbWarnings = 0; |
|
|
if (ctxt->lastError.code != XML_ERR_OK) |
|
|
xmlResetError(&ctxt->lastError); |
|
|
} |
|
|
|
|
|
static int |
|
|
htmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask) |
|
|
{ |
|
|
int allMask; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return(-1); |
|
|
|
|
|
allMask = HTML_PARSE_RECOVER | |
|
|
HTML_PARSE_HTML5 | |
|
|
HTML_PARSE_NODEFDTD | |
|
|
HTML_PARSE_NOERROR | |
|
|
HTML_PARSE_NOWARNING | |
|
|
HTML_PARSE_PEDANTIC | |
|
|
HTML_PARSE_NOBLANKS | |
|
|
HTML_PARSE_NONET | |
|
|
HTML_PARSE_NOIMPLIED | |
|
|
HTML_PARSE_COMPACT | |
|
|
HTML_PARSE_HUGE | |
|
|
HTML_PARSE_IGNORE_ENC | |
|
|
HTML_PARSE_BIG_LINES; |
|
|
|
|
|
ctxt->options = (ctxt->options & keepMask) | (options & allMask); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctxt->keepBlanks = (options & HTML_PARSE_NOBLANKS) ? 0 : 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (options & HTML_PARSE_NOBLANKS) { |
|
|
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace; |
|
|
} |
|
|
if (options & HTML_PARSE_HUGE) { |
|
|
if (ctxt->dict != NULL) |
|
|
xmlDictSetLimit(ctxt->dict, 0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctxt->dictNames = 0; |
|
|
|
|
|
ctxt->linenumbers = 1; |
|
|
|
|
|
return(options & ~allMask); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlCtxtSetOptions(xmlParserCtxtPtr ctxt, int options) |
|
|
{ |
|
|
return(htmlCtxtSetOptionsInternal(ctxt, options, 0)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
htmlCtxtUseOptions(htmlParserCtxtPtr ctxt, int options) |
|
|
{ |
|
|
int keepMask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keepMask = HTML_PARSE_NODEFDTD | |
|
|
HTML_PARSE_NOERROR | |
|
|
HTML_PARSE_NOWARNING | |
|
|
HTML_PARSE_NOIMPLIED | |
|
|
HTML_PARSE_COMPACT | |
|
|
HTML_PARSE_HUGE | |
|
|
HTML_PARSE_IGNORE_ENC | |
|
|
HTML_PARSE_BIG_LINES; |
|
|
|
|
|
return(htmlCtxtSetOptionsInternal(ctxt, options, keepMask)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtParseDocument(htmlParserCtxtPtr ctxt, xmlParserInputPtr input) |
|
|
{ |
|
|
htmlDocPtr ret; |
|
|
|
|
|
if ((ctxt == NULL) || (input == NULL)) |
|
|
return(NULL); |
|
|
|
|
|
|
|
|
while (ctxt->inputNr > 0) |
|
|
xmlFreeInputStream(xmlCtxtPopInput(ctxt)); |
|
|
|
|
|
if (xmlCtxtPushInput(ctxt, input) < 0) { |
|
|
xmlFreeInputStream(input); |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
ctxt->html = 1; |
|
|
htmlParseDocument(ctxt); |
|
|
|
|
|
if (ctxt->errNo != XML_ERR_NO_MEMORY) { |
|
|
ret = ctxt->myDoc; |
|
|
} else { |
|
|
ret = NULL; |
|
|
xmlFreeDoc(ctxt->myDoc); |
|
|
} |
|
|
ctxt->myDoc = NULL; |
|
|
|
|
|
|
|
|
while (ctxt->inputNr > 0) |
|
|
xmlFreeInputStream(xmlCtxtPopInput(ctxt)); |
|
|
|
|
|
return(ret); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlReadDoc(const xmlChar *str, const char *url, const char *encoding, |
|
|
int options) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
htmlDocPtr doc; |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromString(ctxt, url, (const char *) str, encoding, |
|
|
XML_INPUT_BUF_STATIC); |
|
|
|
|
|
doc = htmlCtxtParseDocument(ctxt, input); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlReadFile(const char *filename, const char *encoding, int options) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
htmlDocPtr doc; |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0); |
|
|
|
|
|
doc = htmlCtxtParseDocument(ctxt, input); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlReadMemory(const char *buffer, int size, const char *url, |
|
|
const char *encoding, int options) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
htmlDocPtr doc; |
|
|
|
|
|
if (size < 0) |
|
|
return(NULL); |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromMemory(ctxt, url, buffer, size, encoding, |
|
|
XML_INPUT_BUF_STATIC); |
|
|
|
|
|
doc = htmlCtxtParseDocument(ctxt, input); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlReadFd(int fd, const char *url, const char *encoding, int options) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
htmlDocPtr doc; |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromFd(ctxt, url, fd, encoding, 0); |
|
|
|
|
|
doc = htmlCtxtParseDocument(ctxt, input); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, |
|
|
void *ioctx, const char *url, const char *encoding, int options) |
|
|
{ |
|
|
htmlParserCtxtPtr ctxt; |
|
|
xmlParserInputPtr input; |
|
|
htmlDocPtr doc; |
|
|
|
|
|
ctxt = htmlNewParserCtxt(); |
|
|
if (ctxt == NULL) |
|
|
return (NULL); |
|
|
|
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromIO(ctxt, url, ioread, ioclose, ioctx, |
|
|
encoding, 0); |
|
|
|
|
|
doc = htmlCtxtParseDocument(ctxt, input); |
|
|
|
|
|
htmlFreeParserCtxt(ctxt); |
|
|
return(doc); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar *str, |
|
|
const char *URL, const char *encoding, int options) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return (NULL); |
|
|
|
|
|
htmlCtxtReset(ctxt); |
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromString(ctxt, URL, (const char *) str, |
|
|
encoding, 0); |
|
|
|
|
|
return(htmlCtxtParseDocument(ctxt, input)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtReadFile(htmlParserCtxtPtr ctxt, const char *filename, |
|
|
const char *encoding, int options) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return (NULL); |
|
|
|
|
|
htmlCtxtReset(ctxt); |
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromUrl(ctxt, filename, NULL, encoding, 0); |
|
|
|
|
|
return(htmlCtxtParseDocument(ctxt, input)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size, |
|
|
const char *URL, const char *encoding, int options) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if ((ctxt == NULL) || (size < 0)) |
|
|
return (NULL); |
|
|
|
|
|
htmlCtxtReset(ctxt); |
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromMemory(ctxt, URL, buffer, size, encoding, |
|
|
XML_INPUT_BUF_STATIC); |
|
|
|
|
|
return(htmlCtxtParseDocument(ctxt, input)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtReadFd(htmlParserCtxtPtr ctxt, int fd, |
|
|
const char *URL, const char *encoding, int options) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return(NULL); |
|
|
|
|
|
htmlCtxtReset(ctxt); |
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromFd(ctxt, URL, fd, encoding, 0); |
|
|
|
|
|
return(htmlCtxtParseDocument(ctxt, input)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlDocPtr |
|
|
htmlCtxtReadIO(htmlParserCtxtPtr ctxt, xmlInputReadCallback ioread, |
|
|
xmlInputCloseCallback ioclose, void *ioctx, |
|
|
const char *URL, |
|
|
const char *encoding, int options) |
|
|
{ |
|
|
xmlParserInputPtr input; |
|
|
|
|
|
if (ctxt == NULL) |
|
|
return (NULL); |
|
|
|
|
|
htmlCtxtReset(ctxt); |
|
|
htmlCtxtUseOptions(ctxt, options); |
|
|
|
|
|
input = xmlCtxtNewInputFromIO(ctxt, URL, ioread, ioclose, ioctx, |
|
|
encoding, 0); |
|
|
|
|
|
return(htmlCtxtParseDocument(ctxt, input)); |
|
|
} |
|
|
|
|
|
#endif |
|
|
|