mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
Convert of the HTML parser to new input buffers
Changes similar to the ones done in the XML parser for the routines which are not shared.
This commit is contained in:
61
HTMLparser.c
61
HTMLparser.c
@@ -44,6 +44,9 @@
|
|||||||
#include <libxml/globals.h>
|
#include <libxml/globals.h>
|
||||||
#include <libxml/uri.h>
|
#include <libxml/uri.h>
|
||||||
|
|
||||||
|
#include "buf.h"
|
||||||
|
#include "enc.h"
|
||||||
|
|
||||||
#define HTML_MAX_NAMELEN 1000
|
#define HTML_MAX_NAMELEN 1000
|
||||||
#define HTML_PARSER_BIG_BUFFER_SIZE 1000
|
#define HTML_PARSER_BIG_BUFFER_SIZE 1000
|
||||||
#define HTML_PARSER_BUFFER_SIZE 100
|
#define HTML_PARSER_BUFFER_SIZE 100
|
||||||
@@ -3509,19 +3512,16 @@ htmlCheckEncodingDirect(htmlParserCtxtPtr ctxt, const xmlChar *encoding) {
|
|||||||
* convert as much as possible to the parser reading buffer.
|
* convert as much as possible to the parser reading buffer.
|
||||||
*/
|
*/
|
||||||
processed = ctxt->input->cur - ctxt->input->base;
|
processed = ctxt->input->cur - ctxt->input->base;
|
||||||
xmlBufferShrink(ctxt->input->buf->buffer, processed);
|
xmlBufShrink(ctxt->input->buf->buffer, processed);
|
||||||
nbchars = xmlCharEncInFunc(ctxt->input->buf->encoder,
|
nbchars = xmlCharEncInput(ctxt->input->buf);
|
||||||
ctxt->input->buf->buffer,
|
|
||||||
ctxt->input->buf->raw);
|
|
||||||
if (nbchars < 0) {
|
if (nbchars < 0) {
|
||||||
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
|
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
|
||||||
"htmlCheckEncoding: encoder error\n",
|
"htmlCheckEncoding: encoder error\n",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
ctxt->input->base =
|
ctxt->input->base =
|
||||||
ctxt->input->cur = ctxt->input->buf->buffer->content;
|
ctxt->input->cur = xmlBufContent(ctxt->input->buf->buffer);
|
||||||
ctxt->input->end =
|
ctxt->input->end = xmlBufEnd(ctxt->input->buf->buffer);
|
||||||
&ctxt->input->base[ctxt->input->buf->buffer->use];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4906,9 +4906,9 @@ htmlCreateMemoryParserCtxt(const char *buffer, int size) {
|
|||||||
|
|
||||||
input->filename = NULL;
|
input->filename = NULL;
|
||||||
input->buf = buf;
|
input->buf = buf;
|
||||||
input->base = input->buf->buffer->content;
|
input->cur =
|
||||||
input->cur = input->buf->buffer->content;
|
input->base = xmlBufContent(input->buf->buffer);
|
||||||
input->end = &input->buf->buffer->content[input->buf->buffer->use];
|
input->end = xmlBufEnd(input->buf->buffer);
|
||||||
|
|
||||||
inputPush(ctxt, input);
|
inputPush(ctxt, input);
|
||||||
return(ctxt);
|
return(ctxt);
|
||||||
@@ -5025,8 +5025,8 @@ htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first,
|
|||||||
buf = in->base;
|
buf = in->base;
|
||||||
len = in->length;
|
len = in->length;
|
||||||
} else {
|
} else {
|
||||||
buf = in->buf->buffer->content;
|
buf = xmlBufContent(in->buf->buffer);
|
||||||
len = in->buf->buffer->use;
|
len = xmlBufUse(in->buf->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* take into account the sequence length */
|
/* take into account the sequence length */
|
||||||
@@ -5152,8 +5152,8 @@ htmlParseLookupChars(htmlParserCtxtPtr ctxt, const xmlChar * stop,
|
|||||||
buf = in->base;
|
buf = in->base;
|
||||||
len = in->length;
|
len = in->length;
|
||||||
} else {
|
} else {
|
||||||
buf = in->buf->buffer->content;
|
buf = xmlBufContent(in->buf->buffer);
|
||||||
len = in->buf->buffer->use;
|
len = xmlBufUse(in->buf->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; base < len; base++) {
|
for (; base < len; base++) {
|
||||||
@@ -5264,7 +5264,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
|||||||
if (in->buf == NULL)
|
if (in->buf == NULL)
|
||||||
avail = in->length - (in->cur - in->base);
|
avail = in->length - (in->cur - in->base);
|
||||||
else
|
else
|
||||||
avail = in->buf->buffer->use - (in->cur - in->base);
|
avail = xmlBufUse(in->buf->buffer) - (in->cur - in->base);
|
||||||
if ((avail == 0) && (terminate)) {
|
if ((avail == 0) && (terminate)) {
|
||||||
htmlAutoCloseOnEnd(ctxt);
|
htmlAutoCloseOnEnd(ctxt);
|
||||||
if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
|
if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
|
||||||
@@ -5300,7 +5300,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
|||||||
if (in->buf == NULL)
|
if (in->buf == NULL)
|
||||||
avail = in->length - (in->cur - in->base);
|
avail = in->length - (in->cur - in->base);
|
||||||
else
|
else
|
||||||
avail = in->buf->buffer->use - (in->cur - in->base);
|
avail = xmlBufUse(in->buf->buffer) - (in->cur - in->base);
|
||||||
}
|
}
|
||||||
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
|
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
|
||||||
ctxt->sax->setDocumentLocator(ctxt->userData,
|
ctxt->sax->setDocumentLocator(ctxt->userData,
|
||||||
@@ -5342,7 +5342,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
|||||||
if (in->buf == NULL)
|
if (in->buf == NULL)
|
||||||
avail = in->length - (in->cur - in->base);
|
avail = in->length - (in->cur - in->base);
|
||||||
else
|
else
|
||||||
avail = in->buf->buffer->use - (in->cur - in->base);
|
avail = xmlBufUse(in->buf->buffer) - (in->cur - in->base);
|
||||||
/*
|
/*
|
||||||
* no chars in buffer
|
* no chars in buffer
|
||||||
*/
|
*/
|
||||||
@@ -5415,7 +5415,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
|||||||
if (in->buf == NULL)
|
if (in->buf == NULL)
|
||||||
avail = in->length - (in->cur - in->base);
|
avail = in->length - (in->cur - in->base);
|
||||||
else
|
else
|
||||||
avail = in->buf->buffer->use - (in->cur - in->base);
|
avail = xmlBufUse(in->buf->buffer) - (in->cur - in->base);
|
||||||
if (avail < 2)
|
if (avail < 2)
|
||||||
goto done;
|
goto done;
|
||||||
cur = in->cur[0];
|
cur = in->cur[0];
|
||||||
@@ -5456,7 +5456,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
|
|||||||
if (in->buf == NULL)
|
if (in->buf == NULL)
|
||||||
avail = in->length - (in->cur - in->base);
|
avail = in->length - (in->cur - in->base);
|
||||||
else
|
else
|
||||||
avail = in->buf->buffer->use - (in->cur - in->base);
|
avail = xmlBufUse(in->buf->buffer) - (in->cur - in->base);
|
||||||
if (avail < 1)
|
if (avail < 1)
|
||||||
goto done;
|
goto done;
|
||||||
cur = in->cur[0];
|
cur = in->cur[0];
|
||||||
@@ -5979,7 +5979,7 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
|
|||||||
}
|
}
|
||||||
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
|
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
|
||||||
(ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
|
(ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
|
||||||
int base = ctxt->input->base - ctxt->input->buf->buffer->content;
|
int base = ctxt->input->base - xmlBufContent(ctxt->input->buf->buffer);
|
||||||
int cur = ctxt->input->cur - ctxt->input->base;
|
int cur = ctxt->input->cur - ctxt->input->base;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@@ -5989,10 +5989,9 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
|
|||||||
ctxt->disableSAX = 1;
|
ctxt->disableSAX = 1;
|
||||||
return (XML_PARSER_EOF);
|
return (XML_PARSER_EOF);
|
||||||
}
|
}
|
||||||
ctxt->input->base = ctxt->input->buf->buffer->content + base;
|
ctxt->input->base = xmlBufContent(ctxt->input->buf->buffer) + base;
|
||||||
ctxt->input->cur = ctxt->input->base + cur;
|
ctxt->input->cur = ctxt->input->base + cur;
|
||||||
ctxt->input->end =
|
ctxt->input->end = xmlBufEnd(ctxt->input->buf->buffer);
|
||||||
&ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use];
|
|
||||||
#ifdef DEBUG_PUSH
|
#ifdef DEBUG_PUSH
|
||||||
xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
|
xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
|
||||||
#endif
|
#endif
|
||||||
@@ -6008,7 +6007,7 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
|
|||||||
(in->raw != NULL)) {
|
(in->raw != NULL)) {
|
||||||
int nbchars;
|
int nbchars;
|
||||||
|
|
||||||
nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);
|
nbchars = xmlCharEncInput(in);
|
||||||
if (nbchars < 0) {
|
if (nbchars < 0) {
|
||||||
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
|
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
|
||||||
"encoder error\n", NULL, NULL);
|
"encoder error\n", NULL, NULL);
|
||||||
@@ -6107,24 +6106,22 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
|
|||||||
inputStream->filename = (char *)
|
inputStream->filename = (char *)
|
||||||
xmlCanonicPath((const xmlChar *) filename);
|
xmlCanonicPath((const xmlChar *) filename);
|
||||||
inputStream->buf = buf;
|
inputStream->buf = buf;
|
||||||
inputStream->base = inputStream->buf->buffer->content;
|
inputStream->cur =
|
||||||
inputStream->cur = inputStream->buf->buffer->content;
|
inputStream->base = xmlBufContent(buf->buffer);
|
||||||
inputStream->end =
|
inputStream->end = xmlBufEnd(buf->buffer);
|
||||||
&inputStream->buf->buffer->content[inputStream->buf->buffer->use];
|
|
||||||
|
|
||||||
inputPush(ctxt, inputStream);
|
inputPush(ctxt, inputStream);
|
||||||
|
|
||||||
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
|
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
|
||||||
(ctxt->input->buf != NULL)) {
|
(ctxt->input->buf != NULL)) {
|
||||||
int base = ctxt->input->base - ctxt->input->buf->buffer->content;
|
int base = ctxt->input->base - xmlBufContent(ctxt->input->buf->buffer);
|
||||||
int cur = ctxt->input->cur - ctxt->input->base;
|
int cur = ctxt->input->cur - ctxt->input->base;
|
||||||
|
|
||||||
xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
|
xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
|
||||||
|
|
||||||
ctxt->input->base = ctxt->input->buf->buffer->content + base;
|
ctxt->input->base = xmlBufContent(ctxt->input->buf->buffer) + base;
|
||||||
ctxt->input->cur = ctxt->input->base + cur;
|
ctxt->input->cur = ctxt->input->base + cur;
|
||||||
ctxt->input->end =
|
ctxt->input->end = xmlBufEnd(ctxt->input->buf->buffer);
|
||||||
&ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use];
|
|
||||||
#ifdef DEBUG_PUSH
|
#ifdef DEBUG_PUSH
|
||||||
xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
|
xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user