diff --git a/ChangeLog b/ChangeLog index 843694ae..9f3683af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Oct 28 22:28:50 CET 2003 Daniel Veillard + + * parser.c include/libxml/parser.h: included a new function + to reuse a Push parser context, based on Graham Bennett original + code + * valid.c: in HTML, a name in an input is not an ID + * TODO: bug list update + Tue Oct 28 19:54:37 CET 2003 Daniel Veillard * xpath.c: applied patch from nico@xtradyne.com for #125030 diff --git a/TODO b/TODO index 1af220ee..a53e482c 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,5 @@ -125030 xmlXPathCompile() allows invalid xpath expressions to pass 124907 HTML parse buffer problem when parsing larse in-memory docs -124866 Python error catch for Relax-NG 124110 DTD validation && wrong namespace -124044 Segfault python bindings for reader 123564 xmllint --html --format TODO for the XML parser and stuff: diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 9da48cbd..1d8730d1 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -1107,6 +1107,12 @@ typedef enum { XMLPUBFUN void XMLCALL xmlCtxtReset (xmlParserCtxtPtr ctxt); +XMLPUBFUN int XMLCALL + xmlCtxtResetPush (xmlParserCtxtPtr ctxt, + const char *chunk, + int size, + const char *filename, + const char *encoding); XMLPUBFUN int XMLCALL xmlCtxtUseOptions (xmlParserCtxtPtr ctxt, int options); diff --git a/parser.c b/parser.c index edc2ee4f..171c6233 100644 --- a/parser.c +++ b/parser.c @@ -12121,6 +12121,107 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt) xmlResetError(&ctxt->lastError); } +/** + * xmlCtxtResetPush: + * @ctxt: an XML parser context + * @chunk: a pointer to an array of chars + * @size: number of chars in the array + * @filename: an optional file name or URI + * @encoding: the document encoding, or NULL + * + * Reset a parser context + */ +int +xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, + int size, const char *filename, const char *encoding) +{ + xmlParserInputPtr inputStream; + xmlParserInputBufferPtr buf; + xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; + + if ((encoding == NULL) && (chunk != NULL) && (size >= 4)) + enc = xmlDetectCharEncoding((const xmlChar *) chunk, size); + + buf = xmlAllocParserInputBuffer(enc); + if (buf == NULL) + return(1); + + if (ctxt == NULL) { + xmlFreeParserInputBuffer(buf); + return(1); + } + + xmlCtxtReset(ctxt); + + if (ctxt->pushTab == NULL) { + ctxt->pushTab = (void **) xmlMalloc(ctxt->nameMax * 3 * + sizeof(xmlChar *)); + if (ctxt->pushTab == NULL) { + xmlErrMemory(ctxt, NULL); + xmlFreeParserInputBuffer(buf); + return(1); + } + } + + if (filename == NULL) { + ctxt->directory = NULL; + } else { + ctxt->directory = xmlParserGetDirectory(filename); + } + + inputStream = xmlNewInputStream(ctxt); + if (inputStream == NULL) { + xmlFreeParserInputBuffer(buf); + return(1); + } + + if (filename == NULL) + inputStream->filename = NULL; + else + inputStream->filename = (char *) + xmlCanonicPath((const xmlChar *) filename); + inputStream->buf = buf; + inputStream->base = inputStream->buf->buffer->content; + inputStream->cur = inputStream->buf->buffer->content; + inputStream->end = + &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; + + inputPush(ctxt, inputStream); + + if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && + (ctxt->input->buf != NULL)) { + int base = ctxt->input->base - ctxt->input->buf->buffer->content; + int cur = ctxt->input->cur - ctxt->input->base; + + xmlParserInputBufferPush(ctxt->input->buf, size, chunk); + + ctxt->input->base = ctxt->input->buf->buffer->content + base; + ctxt->input->cur = ctxt->input->base + cur; + ctxt->input->end = + &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer-> + use]; +#ifdef DEBUG_PUSH + xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size); +#endif + } + + if (encoding != NULL) { + xmlCharEncodingHandlerPtr hdlr; + + hdlr = xmlFindCharEncodingHandler(encoding); + if (hdlr != NULL) { + xmlSwitchToEncoding(ctxt, hdlr); + } else { + xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING, + "Unsupported encoding %s\n", BAD_CAST encoding); + } + } else if (enc != XML_CHAR_ENCODING_NONE) { + xmlSwitchEncoding(ctxt, enc); + } + + return(0); +} + /** * xmlCtxtUseOptions: * @ctxt: an XML parser context diff --git a/valid.c b/valid.c index 8b9c429d..4853cc78 100644 --- a/valid.c +++ b/valid.c @@ -2498,8 +2498,9 @@ xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) { return(0); } else if (doc->type == XML_HTML_DOCUMENT_NODE) { - if ((xmlStrEqual(BAD_CAST "id", attr->name)) || - (xmlStrEqual(BAD_CAST "name", attr->name))) + if (((xmlStrEqual(BAD_CAST "id", attr->name)) || + (xmlStrEqual(BAD_CAST "name", attr->name))) && + ((elem != NULL) && (!xmlStrEqual(elem->name, BAD_CAST "input")))) return(1); return(0); } else {