diff --git a/Extras/LibXML/HTMLparser.c b/Extras/LibXML/HTMLparser.c index 0c0c9232a..2e646ad26 100644 --- a/Extras/LibXML/HTMLparser.c +++ b/Extras/LibXML/HTMLparser.c @@ -192,16 +192,16 @@ htmlnamePop(htmlParserCtxtPtr ctxt) const xmlChar *ret; if (ctxt->nameNr <= 0) - return (0); + return (NULL); ctxt->nameNr--; if (ctxt->nameNr < 0) - return (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] = 0; + ctxt->nameTab[ctxt->nameNr] = NULL; return (ret); } @@ -230,7 +230,7 @@ htmlnamePop(htmlParserCtxtPtr ctxt) * UTF-8 if we are using this mode. It returns an int. * NEXT Skip to the next character, this does the proper decoding * in UTF-8 mode. It also pop-up unfinished entities on the fly. - * NEXTL(l) Skip the current Unicode character of l xmlChars long. + * NEXTL(l) Skip the current unicode character of l xmlChars long. * COPY(to) copy one char to *to, increment CUR_PTR and to accordingly */ @@ -964,7 +964,6 @@ NULL static const char *htmlNoContentElements[] = { "html", "head", - "body", NULL }; @@ -1745,7 +1744,7 @@ htmlEntityLookup(const xmlChar *name) { /** * htmlEntityValueLookup: - * @value: the entity's Unicode value + * @value: the entity's unicode value * * Lookup the given entity in EntitiesTable * @@ -2042,6 +2041,7 @@ 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_BLANK_CH(str[j]))) return(0); @@ -2054,8 +2054,17 @@ static int areBlanks(htmlParserCtxtPtr ctxt, const xmlChar *str, int len) { return(1); if (xmlStrEqual(ctxt->name, BAD_CAST"head")) return(1); - if (xmlStrEqual(ctxt->name, BAD_CAST"body")) - return(1); + + /* Only strip CDATA children of the body tag for strict HTML DTDs */ + 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)) @@ -2627,12 +2636,12 @@ htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) { */ static void htmlParseScript(htmlParserCtxtPtr ctxt) { - xmlChar buf[HTML_PARSER_BIG_BUFFER_SIZE + 1]; + xmlChar buf[HTML_PARSER_BIG_BUFFER_SIZE + 5]; int nbchar = 0; - xmlChar cur; + int cur,l; SHRINK; - cur = CUR; + cur = CUR_CHAR(l); while (IS_CHAR_CH(cur)) { if ((cur == '<') && (NXT(1) == '!') && (NXT(2) == '-') && (NXT(3) == '-')) { @@ -2648,20 +2657,39 @@ htmlParseScript(htmlParserCtxtPtr ctxt) { } nbchar = 0; htmlParseComment(ctxt); - cur = CUR; + cur = CUR_CHAR(l); continue; } else if ((cur == '<') && (NXT(1) == '/')) { - /* - * One should break here, the specification is clear: - * Authors should therefore escape "= 'A') && (NXT(2) <= 'Z')) || - ((NXT(2) >= 'a') && (NXT(2) <= 'z'))) - break; /* while */ + /* + * One should break here, the specification is clear: + * Authors should therefore escape "recovery) { + if (xmlStrncasecmp(ctxt->name, ctxt->input->cur+2, + xmlStrlen(ctxt->name)) == 0) + { + break; /* while */ + } else { + htmlParseErr(ctxt, XML_ERR_TAG_NAME_MISMATCH, + "Element %s embeds close tag\n", + ctxt->name, NULL); + } + } else { + if (((NXT(2) >= 'A') && (NXT(2) <= 'Z')) || + ((NXT(2) >= 'a') && (NXT(2) <= 'z'))) + { + break; /* while */ + } + } } - buf[nbchar++] = cur; + COPY_BUF(l,buf,nbchar,cur); if (nbchar >= HTML_PARSER_BIG_BUFFER_SIZE) { if (ctxt->sax->cdataBlock!= NULL) { /* @@ -2673,9 +2701,11 @@ htmlParseScript(htmlParserCtxtPtr ctxt) { } nbchar = 0; } - NEXT; - cur = CUR; + GROW; + NEXTL(l); + cur = CUR_CHAR(l); } + if (!(IS_CHAR_CH(cur))) { htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR, "Invalid char in CDATA 0x%X\n", cur); @@ -2743,6 +2773,8 @@ htmlParseCharData(htmlParserCtxtPtr ctxt) { } } if (nbchar != 0) { + buf[nbchar] = 0; + /* * Ok the segment is to be consumed as chars. */ @@ -3349,27 +3381,31 @@ htmlCheckMeta(htmlParserCtxtPtr ctxt, const xmlChar **atts) { * * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>' * + * Returns 0 in case of success and -1 in case of error. */ -static void +static int htmlParseStartTag(htmlParserCtxtPtr ctxt) { const xmlChar *name; const xmlChar *attname; xmlChar *attvalue; - const xmlChar **atts = ctxt->atts; + const xmlChar **atts; int nbatts = 0; - int maxatts = ctxt->maxatts; + int maxatts; int meta = 0; int i; if ((ctxt == NULL) || (ctxt->input == NULL)) { htmlParseErr(ctxt, XML_ERR_INTERNAL_ERROR, "htmlParseStartTag: context error\n", NULL, NULL); - return; + return -1; } - if (CUR != '<') return; + if (CUR != '<') return -1; NEXT; + atts = ctxt->atts; + maxatts = ctxt->maxatts; + GROW; name = htmlParseHTMLName(ctxt); if (name == NULL) { @@ -3379,7 +3415,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) { /* Dump the bogus tag like browsers do */ while ((IS_CHAR_CH(CUR)) && (CUR != '>')) NEXT; - return; + return -1; } if (xmlStrEqual(name, BAD_CAST"meta")) meta = 1; @@ -3402,14 +3438,14 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) { htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, "htmlParseStartTag: misplaced tag\n", name, NULL); - return; + return 0; } if ((ctxt->nameNr != 1) && (xmlStrEqual(name, BAD_CAST"head"))) { htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, "htmlParseStartTag: misplaced tag\n", name, NULL); - return; + return 0; } if (xmlStrEqual(name, BAD_CAST"body")) { int indx; @@ -3420,7 +3456,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) { name, NULL); while ((IS_CHAR_CH(CUR)) && (CUR != '>')) NEXT; - return; + return 0; } } } @@ -3533,6 +3569,8 @@ failed: xmlFree((xmlChar *) atts[i]); } } + + return 0; } /** @@ -3575,6 +3613,15 @@ htmlParseEndTag(htmlParserCtxtPtr ctxt) if ((!IS_CHAR_CH(CUR)) || (CUR != '>')) { htmlParseErr(ctxt, XML_ERR_GT_REQUIRED, "End tag : expected '>'\n", NULL, NULL); + if (ctxt->recovery) { + /* + * We're not at the ending > !! + * Error, unless in recover mode where we search forwards + * until we find a > + */ + while (CUR != '\0' && CUR != '>') NEXT; + NEXT; + } } else NEXT; @@ -3709,10 +3756,8 @@ htmlParseReference(htmlParserCtxtPtr ctxt) { /** * htmlParseContent: * @ctxt: an HTML parser context - * @name: the node name * * Parse a content: comment, sub-element, reference or text. - * */ static void @@ -3830,6 +3875,19 @@ htmlParseContent(htmlParserCtxtPtr ctxt) { if (currentNode != NULL) xmlFree(currentNode); } +/** + * htmlParseContent: + * @ctxt: an HTML parser context + * + * Parse a content: comment, sub-element, reference or text. + */ + +void +__htmlParseContent(void *ctxt) { + if (ctxt != NULL) + htmlParseContent((htmlParserCtxtPtr) ctxt); +} + /** * htmlParseElement: * @ctxt: an HTML parser context @@ -3847,16 +3905,15 @@ htmlParseElement(htmlParserCtxtPtr ctxt) { xmlChar *currentNode = NULL; const htmlElemDesc * info; htmlParserNodeInfo node_info; - const xmlChar *oldname; + int failed; int depth; const xmlChar *oldptr; if ((ctxt == NULL) || (ctxt->input == NULL)) { htmlParseErr(ctxt, XML_ERR_INTERNAL_ERROR, - "htmlParseStartTag: context error\n", NULL, NULL); + "htmlParseElement: context error\n", NULL, NULL); return; } - depth = ctxt->nameNr; /* Capture start position */ if (ctxt->record_info) { node_info.begin_pos = ctxt->input->consumed + @@ -3864,11 +3921,9 @@ htmlParseElement(htmlParserCtxtPtr ctxt) { node_info.begin_line = ctxt->input->line; } - oldname = ctxt->name; - htmlParseStartTag(ctxt); + failed = htmlParseStartTag(ctxt); name = ctxt->name; - if (((depth == ctxt->nameNr) && (xmlStrEqual(oldname, ctxt->name))) || - (name == NULL)) { + if (failed || (name == NULL)) { if (CUR == '>') NEXT; return; @@ -3911,7 +3966,7 @@ htmlParseElement(htmlParserCtxtPtr ctxt) { /* * Capture end position and add node */ - if ( currentNode != NULL && ctxt->record_info ) { + if (ctxt->record_info) { node_info.end_pos = ctxt->input->consumed + (CUR_PTR - ctxt->input->base); node_info.end_line = ctxt->input->line; @@ -4577,11 +4632,11 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { #endif } else { ctxt->instate = XML_PARSER_MISC; - } #ifdef DEBUG_PUSH - xmlGenericError(xmlGenericErrorContext, - "HPP: entering MISC\n"); + xmlGenericError(xmlGenericErrorContext, + "HPP: entering MISC\n"); #endif + } break; case XML_PARSER_MISC: SKIP_BLANKS; @@ -4738,8 +4793,8 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { } break; case XML_PARSER_START_TAG: { - const xmlChar *name, *oldname; - int depth = ctxt->nameNr; + const xmlChar *name; + int failed; const htmlElemDesc * info; if (avail < 2) @@ -4766,11 +4821,9 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0)) goto done; - oldname = ctxt->name; - htmlParseStartTag(ctxt); + failed = htmlParseStartTag(ctxt); name = ctxt->name; - if (((depth == ctxt->nameNr) && - (xmlStrEqual(oldname, ctxt->name))) || + if (failed || (name == NULL)) { if (CUR == '>') NEXT; @@ -4793,7 +4846,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { SKIP(2); if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) ctxt->sax->endElement(ctxt->userData, name); - oldname = htmlnamePop(ctxt); + htmlnamePop(ctxt); ctxt->instate = XML_PARSER_CONTENT; #ifdef DEBUG_PUSH xmlGenericError(xmlGenericErrorContext, @@ -4814,7 +4867,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { */ if (xmlStrEqual(name, ctxt->name)) { nodePop(ctxt); - oldname = htmlnamePop(ctxt); + htmlnamePop(ctxt); } ctxt->instate = XML_PARSER_CONTENT; @@ -4831,7 +4884,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) { if ((info != NULL) && (info->empty)) { if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL)) ctxt->sax->endElement(ctxt->userData, name); - oldname = htmlnamePop(ctxt); + htmlnamePop(ctxt); } ctxt->instate = XML_PARSER_CONTENT; #ifdef DEBUG_PUSH @@ -5178,10 +5231,18 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size, (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { int base = ctxt->input->base - ctxt->input->buf->buffer->content; int cur = ctxt->input->cur - ctxt->input->base; + int res; - xmlParserInputBufferPush(ctxt->input->buf, size, chunk); + res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); + if (res < 0) { + ctxt->errNo = XML_PARSER_EOF; + ctxt->disableSAX = 1; + return (XML_PARSER_EOF); + } 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, "HPP: pushed %d\n", size); #endif @@ -5779,6 +5840,14 @@ htmlCtxtUseOptions(htmlParserCtxtPtr ctxt, int options) ctxt->options |= XML_PARSE_NOBLANKS; } else ctxt->keepBlanks = 1; + if (options & HTML_PARSE_RECOVER) { + ctxt->recovery = 1; + } else + ctxt->recovery = 0; + if (options & HTML_PARSE_COMPACT) { + ctxt->options |= HTML_PARSE_COMPACT; + options -= HTML_PARSE_COMPACT; + } ctxt->dictNames = 0; return (options); } diff --git a/Extras/LibXML/HTMLtree.c b/Extras/LibXML/HTMLtree.c index de086db46..d73024a97 100644 --- a/Extras/LibXML/HTMLtree.c +++ b/Extras/LibXML/HTMLtree.c @@ -506,16 +506,17 @@ htmlNodeDumpFile(FILE *out, xmlDocPtr doc, xmlNodePtr cur) { } /** - * htmlDocDumpMemory: + * htmlDocDumpMemoryFormat: * @cur: the document * @mem: OUT: the memory pointer * @size: OUT: the memory length + * @format: should formatting spaces been added * * Dump an HTML document in memory and return the xmlChar * and it's size. * It's up to the caller to free the memory. */ void -htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { +htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) { xmlOutputBufferPtr buf; xmlCharEncodingHandlerPtr handler = NULL; const char *encoding; @@ -552,6 +553,8 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { *size = 0; return; } + } else { + handler = xmlFindCharEncodingHandler(encoding); } } @@ -570,7 +573,8 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { return; } - htmlDocContentDumpOutput(buf, cur, NULL); + htmlDocContentDumpFormatOutput(buf, cur, NULL, format); + xmlOutputBufferFlush(buf); if (buf->conv != NULL) { *size = buf->conv->use; @@ -582,6 +586,20 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { (void)xmlOutputBufferClose(buf); } +/** + * htmlDocDumpMemory: + * @cur: the document + * @mem: OUT: the memory pointer + * @size: OUT: the memory length + * + * Dump an HTML document in memory and return the xmlChar * and it's size. + * It's up to the caller to free the memory. + */ +void +htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { + htmlDocDumpMemoryFormat(cur, mem, size, 1); +} + /************************************************************************ * * @@ -1026,6 +1044,8 @@ htmlDocDump(FILE *f, xmlDocPtr cur) { handler = xmlFindCharEncodingHandler(encoding); if (handler == NULL) return(-1); + } else { + handler = xmlFindCharEncodingHandler(encoding); } } diff --git a/Extras/LibXML/SAX2.c b/Extras/LibXML/SAX2.c index a3a95aaf3..75d5f4c4d 100644 --- a/Extras/LibXML/SAX2.c +++ b/Extras/LibXML/SAX2.c @@ -83,15 +83,126 @@ xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error, ctxt->errNo = error; if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) schannel = ctxt->sax->serror; - } - __xmlRaiseError(schannel, - ctxt->vctxt.error, ctxt->vctxt.userData, - ctxt, NULL, XML_FROM_DTD, error, - XML_ERR_ERROR, NULL, 0, (const char *) str1, - (const char *) str2, NULL, 0, 0, - msg, (const char *) str1, (const char *) str2); - if (ctxt != NULL) + __xmlRaiseError(schannel, + ctxt->vctxt.error, ctxt->vctxt.userData, + ctxt, NULL, XML_FROM_DTD, error, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + (const char *) str2, NULL, 0, 0, + msg, (const char *) str1, (const char *) str2); ctxt->valid = 0; + } else { + __xmlRaiseError(schannel, + NULL, NULL, + ctxt, NULL, XML_FROM_DTD, error, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + (const char *) str2, NULL, 0, 0, + msg, (const char *) str1, (const char *) str2); + } +} + +/** + * xmlFatalErrMsg: + * @ctxt: an XML parser context + * @error: the error number + * @msg: the error message + * @str1: an error string + * @str2: an error string + * + * Handle a fatal parser error, i.e. violating Well-Formedness constraints + */ +static void +xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const xmlChar *str1, const xmlChar *str2) +{ + if ((ctxt != NULL) && (ctxt->disableSAX != 0) && + (ctxt->instate == XML_PARSER_EOF)) + return; + if (ctxt != NULL) + ctxt->errNo = error; + __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, + XML_ERR_FATAL, NULL, 0, + (const char *) str1, (const char *) str2, + NULL, 0, 0, msg, str1, str2); + if (ctxt != NULL) { + ctxt->wellFormed = 0; + ctxt->valid = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } +} + +/** + * xmlWarnMsg: + * @ctxt: an XML parser context + * @error: the error number + * @msg: the error message + * @str1: an error string + * @str2: an error string + * + * Handle a parser warning + */ +static void +xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const xmlChar *str1) +{ + if ((ctxt != NULL) && (ctxt->disableSAX != 0) && + (ctxt->instate == XML_PARSER_EOF)) + return; + if (ctxt != NULL) + ctxt->errNo = error; + __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, + XML_ERR_WARNING, NULL, 0, + (const char *) str1, NULL, + NULL, 0, 0, msg, str1); +} + +/** + * xmlNsErrMsg: + * @ctxt: an XML parser context + * @error: the error number + * @msg: the error message + * @str1: an error string + * @str2: an error string + * + * Handle a namespace error + */ +static void +xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const xmlChar *str1, const xmlChar *str2) +{ + if ((ctxt != NULL) && (ctxt->disableSAX != 0) && + (ctxt->instate == XML_PARSER_EOF)) + return; + if (ctxt != NULL) + ctxt->errNo = error; + __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, + XML_ERR_ERROR, NULL, 0, + (const char *) str1, (const char *) str2, + NULL, 0, 0, msg, str1, str2); +} + +/** + * xmlNsWarnMsg: + * @ctxt: an XML parser context + * @error: the error number + * @msg: the error message + * @str1: an error string + * + * Handle a namespace warning + */ +static void +xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, + const char *msg, const xmlChar *str1, const xmlChar *str2) +{ + if ((ctxt != NULL) && (ctxt->disableSAX != 0) && + (ctxt->instate == XML_PARSER_EOF)) + return; + if (ctxt != NULL) + ctxt->errNo = error; + __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, + XML_ERR_WARNING, NULL, 0, + (const char *) str1, (const char *) str2, + NULL, 0, 0, msg, str1, str2); } /** @@ -122,7 +233,7 @@ const xmlChar * xmlSAX2GetSystemId(void *ctx) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - if ((ctx == NULL) || (ctxt->input == NULL)) return(0); + if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL); return((const xmlChar *) ctxt->input->filename); } @@ -134,12 +245,12 @@ xmlSAX2GetSystemId(void *ctx) * * Returns an int */ -intptr_t +int xmlSAX2GetLineNumber(void *ctx) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if ((ctx == NULL) || (ctxt->input == NULL)) return(0); - return (intptr_t) (ctxt->input->line); + return(ctxt->input->line); } /** @@ -150,12 +261,12 @@ xmlSAX2GetLineNumber(void *ctx) * * Returns an int */ -intptr_t +int xmlSAX2GetColumnNumber(void *ctx) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if ((ctx == NULL) || (ctxt->input == NULL)) return(0); - return ctxt->input->col; + return(ctxt->input->col); } /** @@ -436,12 +547,9 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name) ctxt->myDoc->standalone = 0; ret = xmlGetDocEntity(ctxt->myDoc, name); if (ret != NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "Entity(%s) document marked standalone but requires external subset\n", - name); - ctxt->valid = 0; - ctxt->wellFormed = 0; + xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE, + "Entity(%s) document marked standalone but requires external subset\n", + name, NULL); } ctxt->myDoc->standalone = 1; } @@ -466,11 +574,8 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name) if (val == 0) { xmlAddChildList((xmlNodePtr) ret, children); } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "Failure to process entity %s\n", name); - ctxt->wellFormed = 0; - ctxt->valid = 0; + xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, + "Failure to process entity %s\n", name, NULL); ctxt->validate = 0; return(NULL); } @@ -532,10 +637,10 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, if (ctxt->inSubset == 1) { ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId, systemId, content); - if ((ent == NULL) && (ctxt->pedantic) && - (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, - "Entity(%s) already defined in the internal subset\n", name); + if ((ent == NULL) && (ctxt->pedantic)) + xmlWarnMsg(ctxt, XML_WAR_ENTITY_REDEFINED, + "Entity(%s) already defined in the internal subset\n", + name); if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) { xmlChar *URI; const char *base = NULL; @@ -568,9 +673,9 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, ent->URI = URI; } } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n", name); + xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING, + "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n", + name, NULL); } } @@ -595,7 +700,9 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, xmlAttributePtr attr; xmlChar *name = NULL, *prefix = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n", @@ -623,9 +730,9 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, name, prefix, (xmlAttributeType) type, (xmlAttributeDefault) def, defaultValue, tree); else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", name); + xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, + "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n", + name, NULL); xmlFreeEnumeration(tree); return; } @@ -633,7 +740,7 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, if (ctxt->vctxt.valid == 0) ctxt->valid = 0; if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) && - (ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset != NULL)) + (ctxt->myDoc->intSubset != NULL)) ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, attr); #endif /* LIBXML_VALID_ENABLED */ @@ -659,7 +766,9 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type, xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlElementPtr elem = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type); @@ -672,10 +781,9 @@ xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type, elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name, (xmlElementTypeVal) type, content); else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n", - name); + xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, + "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n", + name, NULL); return; } #ifdef LIBXML_VALID_ENABLED @@ -704,18 +812,18 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name, xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNotationPtr nota = NULL; - if (ctx == NULL) return; + if ((ctxt == NULL) || (ctxt->myDoc == NULL)) + return; + #ifdef DEBUG_SAX xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId); #endif if ((publicId == NULL) && (systemId == NULL)) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n", name); - ctxt->valid = 0; - ctxt->wellFormed = 0; + xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING, + "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n", + name, NULL); return; } else if (ctxt->inSubset == 1) nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name, @@ -724,15 +832,15 @@ xmlSAX2NotationDecl(void *ctx, const xmlChar *name, nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name, publicId, systemId); else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n", name); + xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING, + "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n", + name, NULL); return; } #ifdef LIBXML_VALID_ENABLED if (nota == NULL) ctxt->valid = 0; - if (ctxt->validate && ctxt->wellFormed && - ctxt->myDoc && ctxt->myDoc->intSubset) + if ((ctxt->validate) && (ctxt->wellFormed) && + (ctxt->myDoc->intSubset != NULL)) ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, nota); #endif /* LIBXML_VALID_ENABLED */ @@ -802,9 +910,9 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name, ent->URI = URI; } } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n", name); + xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, + "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n", + name, NULL); } } @@ -926,7 +1034,7 @@ xmlSAX2EndDocument(void *ctx) } } -#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) +#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) /** * xmlSAX2AttributeInternal: * @ctx: the user data (XML parser context) @@ -956,13 +1064,13 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, name = xmlSplitQName(ctxt, fullname, &ns); if ((name != NULL) && (name[0] == 0)) { if (xmlStrEqual(ns, BAD_CAST "xmlns")) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "invalid namespace declaration '%s'\n", fullname); + xmlNsErrMsg(ctxt, XML_ERR_NS_DECL_ERROR, + "invalid namespace declaration '%s'\n", + fullname, NULL); } else { - if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, - "Avoid attribute ending with ':' like '%s'\n", fullname); + xmlNsWarnMsg(ctxt, XML_WAR_NS_COLUMN, + "Avoid attribute ending with ':' like '%s'\n", + fullname, NULL); } if (ns != NULL) xmlFree(ns); @@ -1076,22 +1184,19 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, } if (val[0] == 0) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "Empty namespace name for prefix %s\n", name); + xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY, + "Empty namespace name for prefix %s\n", name, NULL); } if ((ctxt->pedantic != 0) && (val[0] != 0)) { xmlURIPtr uri; uri = xmlParseURI((const char *)val); if (uri == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + xmlNsWarnMsg(ctxt, XML_WAR_NS_URI, "xmlns:%s: %s not a valid URI\n", name, value); } else { if (uri->scheme == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE, "xmlns:%s: URI %s is not absolute\n", name, value); } xmlFreeURI(uri); @@ -1124,8 +1229,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, xmlAttrPtr prop; namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns); if (namespace == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, + xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, "Namespace prefix %s of attribute %s is not defined\n", ns, name); } @@ -1136,9 +1240,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, if ((xmlStrEqual(name, prop->name)) && ((namespace == prop->ns) || (xmlStrEqual(namespace->href, prop->ns->href)))) { - ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, + xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED, "Attribute %s in %s redefined\n", name, namespace->href); ctxt->wellFormed = 0; @@ -1226,11 +1328,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, * when validating, the ID registration is done at the attribute * validation level. Otherwise we have to do specific handling here. */ - if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) - xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); - else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) - xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret); - else if (xmlStrEqual(fullname, BAD_CAST "xml:id")) { + if (xmlStrEqual(fullname, BAD_CAST "xml:id")) { /* * Add the xml:id value * @@ -1242,7 +1340,10 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname, (const char *) value, NULL); } xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); - } + } else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) + xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret); + else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) + xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret); } error: @@ -1669,7 +1770,7 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED) * Returns the newly allocated string or NULL if not needed or error */ static xmlNodePtr -xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) { +xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) { xmlNodePtr ret; const xmlChar *intern = NULL; @@ -1687,6 +1788,7 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) { xmlErrMemory(ctxt, "xmlSAX2Characters"); return(NULL); } + memset(ret, 0, sizeof(xmlNode)); /* * intern the formatting blanks found between tags, or the * very short strings @@ -1694,7 +1796,14 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) { if (ctxt->dictNames) { xmlChar cur = str[len]; - if ((len <= 3) && ((cur == '"') || (cur == '\'') || + if ((len < (int) (2 * sizeof(void *))) && + (ctxt->options & XML_PARSE_COMPACT)) { + /* store the string in the node overrithing properties and nsDef */ + xmlChar *tmp = (xmlChar *) &(ret->properties); + memcpy(tmp, str, len); + tmp[len] = 0; + intern = tmp; + } else if ((len <= 3) && ((cur == '"') || (cur == '\'') || ((cur == '<') && (str[len + 1] != '!')))) { intern = xmlDictLookup(ctxt->dict, str, len); } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') && @@ -1708,7 +1817,6 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len) { } } skip: - memset(ret, 0, sizeof(xmlNode)); ret->type = XML_TEXT_NODE; ret->name = xmlStringText; @@ -1950,16 +2058,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, * when validating, the ID registration is done at the attribute * validation level. Otherwise we have to do specific handling here. */ - if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) { - /* might be worth duplicate entry points and not copy */ - if (dup == NULL) - dup = xmlStrndup(value, valueend - value); - xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); - } else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) { - if (dup == NULL) - dup = xmlStrndup(value, valueend - value); - xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret); - } else if ((prefix == ctxt->str_xml) && + if ((prefix == ctxt->str_xml) && (localname[0] == 'i') && (localname[1] == 'd') && (localname[2] == 0)) { /* @@ -1977,6 +2076,15 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, } #endif xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); + } else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) { + /* might be worth duplicate entry points and not copy */ + if (dup == NULL) + dup = xmlStrndup(value, valueend - value); + xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret); + } else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) { + if (dup == NULL) + dup = xmlStrndup(value, valueend - value); + xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret); } } if (dup != NULL) @@ -2007,8 +2115,8 @@ xmlSAX2StartElementNs(void *ctx, const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, - intptr_t nb_attributes, - intptr_t nb_defaulted, + int nb_attributes, + int nb_defaulted, const xmlChar **attributes) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -2016,7 +2124,7 @@ xmlSAX2StartElementNs(void *ctx, xmlNodePtr parent; xmlNsPtr last = NULL, ns; const xmlChar *uri, *pref; - intptr_t i, j; + int i, j; if (ctx == NULL) return; parent = ctxt->node; @@ -2137,9 +2245,13 @@ xmlSAX2StartElementNs(void *ctx, */ if ((URI != NULL) && (ret->ns == NULL)) { ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix); + if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { + ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix); + } if (ret->ns == NULL) { ns = xmlNewNs(ret, NULL, prefix); if (ns == NULL) { + xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); return; } @@ -2259,7 +2371,7 @@ xmlSAX2Reference(void *ctx, const xmlChar *name) * receiving some chars from the parser. */ void -xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len) +xmlSAX2Characters(void *ctx, const xmlChar *ch, int len) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr lastChild; @@ -2317,17 +2429,20 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len) * We try to minimaze realloc() uses and avoid copying * and recomputing length over and over. */ - if ((ctxt->nodemem == ctxt->nodelen + 1) && - (xmlDictOwns(ctxt->dict, lastChild->content))) { + if (lastChild->content == (xmlChar *)&(lastChild->properties)) { + lastChild->content = xmlStrdup(lastChild->content); + lastChild->properties = NULL; + } else if ((ctxt->nodemem == ctxt->nodelen + 1) && + (xmlDictOwns(ctxt->dict, lastChild->content))) { lastChild->content = xmlStrdup(lastChild->content); } if (ctxt->nodelen + len >= ctxt->nodemem) { xmlChar *newbuf; - size_t size; + int size; size = ctxt->nodemem + len; size *= 2; - newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); + newbuf = (xmlChar *) xmlRealloc(lastChild->content,size); if (newbuf == NULL) { xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); return; @@ -2370,7 +2485,7 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, intptr_t len) * UNUSED: by default the DOM building will use xmlSAX2Characters */ void -xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, intptr_t len ATTRIBUTE_UNUSED) +xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED) { /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX @@ -2406,6 +2521,14 @@ xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target, if (ret == NULL) return; parent = ctxt->node; + if (ctxt->linenumbers) { + if (ctxt->input != NULL) { + if (ctxt->input->line < 65535) + ret->line = (short) ctxt->input->line; + else + ret->line = 65535; + } + } if (ctxt->inSubset == 1) { xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); return; @@ -2458,6 +2581,14 @@ xmlSAX2Comment(void *ctx, const xmlChar *value) #endif ret = xmlNewDocComment(ctxt->myDoc, value); if (ret == NULL) return; + if (ctxt->linenumbers) { + if (ctxt->input != NULL) { + if (ctxt->input->line < 65535) + ret->line = (short) ctxt->input->line; + else + ret->line = 65535; + } + } if (ctxt->inSubset == 1) { xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret); @@ -2499,7 +2630,7 @@ xmlSAX2Comment(void *ctx, const xmlChar *value) * called when a pcdata block has been parsed */ void -xmlSAX2CDataBlock(void *ctx, const xmlChar *value, intptr_t len) +xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr ret, lastChild; diff --git a/Extras/LibXML/c14n.c b/Extras/LibXML/c14n.c index 0088d1604..bb7c9ba83 100644 --- a/Extras/LibXML/c14n.c +++ b/Extras/LibXML/c14n.c @@ -793,7 +793,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) * default namespace (XML Namespaces: "default namespaces * do not apply directly to attributes") */ - if((attr->ns != NULL) && xmlC14NIsVisible(ctx, attr, cur)) { + if((attr->ns != NULL) && !xmlC14NIsXmlNs(attr->ns) && xmlC14NIsVisible(ctx, attr, cur)) { already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, attr->ns, ctx); xmlC14NVisibleNsStackAdd(ctx->ns_rendered, attr->ns, cur); if(!already_rendered && visible) { @@ -802,7 +802,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) if(xmlStrlen(attr->ns->prefix) == 0) { has_empty_ns = 1; } - } else if(attr->ns == NULL) { + } else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (xmlStrlen(attr->ns->href) == 0)) { has_visibly_utilized_empty_ns = 1; } } @@ -946,6 +946,7 @@ xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx) * xmlC14NProcessAttrsAxis: * @ctx: the C14N context * @cur: the current node + * @parent_visible: the visibility of parent node * * Prints out canonical attribute axis of the current node to the * buffer from C14N context as follows @@ -974,7 +975,7 @@ xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx) * Returns 0 on success or -1 on fail. */ static int -xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur) +xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible) { xmlAttrPtr attr; xmlListPtr list; @@ -1009,7 +1010,7 @@ xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur) * include attributes in "xml" namespace defined in ancestors * (only for non-exclusive XML Canonicalization) */ - if ((!ctx->exclusive) && (cur->parent != NULL) + if (parent_visible && (!ctx->exclusive) && (cur->parent != NULL) && (!xmlC14NIsVisible(ctx, cur->parent, cur->parent->parent))) { /* * If XPath node-set is not specified then the parent is always @@ -1138,6 +1139,7 @@ xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) /* * Save ns_rendered stack position */ + memset(&state, 0, sizeof(state)); xmlC14NVisibleNsStackSave(ctx->ns_rendered, &state); if (visible) { @@ -1171,12 +1173,10 @@ xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) xmlC14NVisibleNsStackShift(ctx->ns_rendered); } - if(visible) { - ret = xmlC14NProcessAttrsAxis(ctx, cur); - if (ret < 0) { - xmlC14NErrInternal("processing attributes axis"); - return (-1); - } + ret = xmlC14NProcessAttrsAxis(ctx, cur, visible); + if (ret < 0) { + xmlC14NErrInternal("processing attributes axis"); + return (-1); } if (visible) { diff --git a/Extras/LibXML/catalog.c b/Extras/LibXML/catalog.c index 202c288fc..5456094da 100644 --- a/Extras/LibXML/catalog.c +++ b/Extras/LibXML/catalog.c @@ -1200,8 +1200,6 @@ static void xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup) { - xmlChar *uri = NULL; - xmlChar *URL = NULL; xmlChar *base = NULL; xmlCatalogEntryPtr entry = NULL; @@ -1288,10 +1286,6 @@ xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, } if (base != NULL) xmlFree(base); - if (uri != NULL) - xmlFree(uri); - if (URL != NULL) - xmlFree(URL); } /** @@ -1546,6 +1540,7 @@ xmlAddXMLCatalog(xmlCatalogEntryPtr catal, const xmlChar *type, cur->next = xmlNewCatalogEntry(typ, orig, replace, NULL, catal->prefer, NULL); if (doregister) { + catal->type = XML_CATA_CATALOG; cur = xmlHashLookup(xmlCatalogXMLFiles, catal->URL); if (cur != NULL) cur->children = catal->children; @@ -1648,7 +1643,8 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, if (xmlStrEqual(sysID, cur->name)) { if (xmlDebugCatalogs) xmlGenericError(xmlGenericErrorContext, - "Found system match %s\n", cur->name); + "Found system match %s, using %s\n", + cur->name, cur->URL); catal->depth--; return(xmlStrdup(cur->URL)); } @@ -3218,7 +3214,7 @@ xmlLoadCatalogs(const char *pathss) { return; cur = pathss; - while ((cur != NULL) && (*cur != 0)) { + while (*cur != 0) { while (xmlIsBlank_ch(*cur)) cur++; if (*cur != 0) { paths = cur; diff --git a/Extras/LibXML/chvalid.c b/Extras/LibXML/chvalid.c index 227aeba17..00dd962c3 100644 --- a/Extras/LibXML/chvalid.c +++ b/Extras/LibXML/chvalid.c @@ -5,7 +5,7 @@ * This file is automatically generated from the cvs source * definition files using the genChRanges.py Python script * - * Generation date: Tue Nov 18 08:14:21 2003 + * Generation date: Mon Mar 27 11:09:48 2006 * Sources: chvalid.def * William Brack */ @@ -22,7 +22,7 @@ * allowed. * */ -unsigned char xmlIsPubidChar_tab[256] = { +const unsigned char xmlIsPubidChar_tab[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, @@ -46,65 +46,66 @@ unsigned char xmlIsPubidChar_tab[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static xmlChSRange xmlIsBaseChar_srng[] = { {0x100, 0x131}, {0x134, 0x13e}, - {0x141, 0x148}, {0x14a, 0x17e}, {0x180, 0x1c3}, {0x1cd, 0x1f0}, - {0x1f4, 0x1f5}, {0x1fa, 0x217}, {0x250, 0x2a8}, {0x2bb, 0x2c1}, - {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c}, {0x38e, 0x3a1}, - {0x3a3, 0x3ce}, {0x3d0, 0x3d6}, {0x3da, 0x3da}, {0x3dc, 0x3dc}, - {0x3de, 0x3de}, {0x3e0, 0x3e0}, {0x3e2, 0x3f3}, {0x401, 0x40c}, - {0x40e, 0x44f}, {0x451, 0x45c}, {0x45e, 0x481}, {0x490, 0x4c4}, - {0x4c7, 0x4c8}, {0x4cb, 0x4cc}, {0x4d0, 0x4eb}, {0x4ee, 0x4f5}, - {0x4f8, 0x4f9}, {0x531, 0x556}, {0x559, 0x559}, {0x561, 0x586}, - {0x5d0, 0x5ea}, {0x5f0, 0x5f2}, {0x621, 0x63a}, {0x641, 0x64a}, - {0x671, 0x6b7}, {0x6ba, 0x6be}, {0x6c0, 0x6ce}, {0x6d0, 0x6d3}, - {0x6d5, 0x6d5}, {0x6e5, 0x6e6}, {0x905, 0x939}, {0x93d, 0x93d}, - {0x958, 0x961}, {0x985, 0x98c}, {0x98f, 0x990}, {0x993, 0x9a8}, - {0x9aa, 0x9b0}, {0x9b2, 0x9b2}, {0x9b6, 0x9b9}, {0x9dc, 0x9dd}, - {0x9df, 0x9e1}, {0x9f0, 0x9f1}, {0xa05, 0xa0a}, {0xa0f, 0xa10}, - {0xa13, 0xa28}, {0xa2a, 0xa30}, {0xa32, 0xa33}, {0xa35, 0xa36}, - {0xa38, 0xa39}, {0xa59, 0xa5c}, {0xa5e, 0xa5e}, {0xa72, 0xa74}, - {0xa85, 0xa8b}, {0xa8d, 0xa8d}, {0xa8f, 0xa91}, {0xa93, 0xaa8}, - {0xaaa, 0xab0}, {0xab2, 0xab3}, {0xab5, 0xab9}, {0xabd, 0xabd}, - {0xae0, 0xae0}, {0xb05, 0xb0c}, {0xb0f, 0xb10}, {0xb13, 0xb28}, - {0xb2a, 0xb30}, {0xb32, 0xb33}, {0xb36, 0xb39}, {0xb3d, 0xb3d}, - {0xb5c, 0xb5d}, {0xb5f, 0xb61}, {0xb85, 0xb8a}, {0xb8e, 0xb90}, - {0xb92, 0xb95}, {0xb99, 0xb9a}, {0xb9c, 0xb9c}, {0xb9e, 0xb9f}, - {0xba3, 0xba4}, {0xba8, 0xbaa}, {0xbae, 0xbb5}, {0xbb7, 0xbb9}, - {0xc05, 0xc0c}, {0xc0e, 0xc10}, {0xc12, 0xc28}, {0xc2a, 0xc33}, - {0xc35, 0xc39}, {0xc60, 0xc61}, {0xc85, 0xc8c}, {0xc8e, 0xc90}, - {0xc92, 0xca8}, {0xcaa, 0xcb3}, {0xcb5, 0xcb9}, {0xcde, 0xcde}, - {0xce0, 0xce1}, {0xd05, 0xd0c}, {0xd0e, 0xd10}, {0xd12, 0xd28}, - {0xd2a, 0xd39}, {0xd60, 0xd61}, {0xe01, 0xe2e}, {0xe30, 0xe30}, - {0xe32, 0xe33}, {0xe40, 0xe45}, {0xe81, 0xe82}, {0xe84, 0xe84}, - {0xe87, 0xe88}, {0xe8a, 0xe8a}, {0xe8d, 0xe8d}, {0xe94, 0xe97}, - {0xe99, 0xe9f}, {0xea1, 0xea3}, {0xea5, 0xea5}, {0xea7, 0xea7}, - {0xeaa, 0xeab}, {0xead, 0xeae}, {0xeb0, 0xeb0}, {0xeb2, 0xeb3}, - {0xebd, 0xebd}, {0xec0, 0xec4}, {0xf40, 0xf47}, {0xf49, 0xf69}, - {0x10a0, 0x10c5}, {0x10d0, 0x10f6}, {0x1100, 0x1100}, {0x1102, 0x1103}, - {0x1105, 0x1107}, {0x1109, 0x1109}, {0x110b, 0x110c}, {0x110e, 0x1112}, - {0x113c, 0x113c}, {0x113e, 0x113e}, {0x1140, 0x1140}, {0x114c, 0x114c}, - {0x114e, 0x114e}, {0x1150, 0x1150}, {0x1154, 0x1155}, {0x1159, 0x1159}, - {0x115f, 0x1161}, {0x1163, 0x1163}, {0x1165, 0x1165}, {0x1167, 0x1167}, - {0x1169, 0x1169}, {0x116d, 0x116e}, {0x1172, 0x1173}, {0x1175, 0x1175}, - {0x119e, 0x119e}, {0x11a8, 0x11a8}, {0x11ab, 0x11ab}, {0x11ae, 0x11af}, - {0x11b7, 0x11b8}, {0x11ba, 0x11ba}, {0x11bc, 0x11c2}, {0x11eb, 0x11eb}, - {0x11f0, 0x11f0}, {0x11f9, 0x11f9}, {0x1e00, 0x1e9b}, {0x1ea0, 0x1ef9}, - {0x1f00, 0x1f15}, {0x1f18, 0x1f1d}, {0x1f20, 0x1f45}, {0x1f48, 0x1f4d}, - {0x1f50, 0x1f57}, {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, - {0x1f5f, 0x1f7d}, {0x1f80, 0x1fb4}, {0x1fb6, 0x1fbc}, {0x1fbe, 0x1fbe}, - {0x1fc2, 0x1fc4}, {0x1fc6, 0x1fcc}, {0x1fd0, 0x1fd3}, {0x1fd6, 0x1fdb}, - {0x1fe0, 0x1fec}, {0x1ff2, 0x1ff4}, {0x1ff6, 0x1ffc}, {0x2126, 0x2126}, - {0x212a, 0x212b}, {0x212e, 0x212e}, {0x2180, 0x2182}, {0x3041, 0x3094}, - {0x30a1, 0x30fa}, {0x3105, 0x312c}, {0xac00, 0xd7a3}}; -xmlChRangeGroup xmlIsBaseCharGroup = +static const xmlChSRange xmlIsBaseChar_srng[] = { {0x100, 0x131}, + {0x134, 0x13e}, {0x141, 0x148}, {0x14a, 0x17e}, {0x180, 0x1c3}, + {0x1cd, 0x1f0}, {0x1f4, 0x1f5}, {0x1fa, 0x217}, {0x250, 0x2a8}, + {0x2bb, 0x2c1}, {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c}, + {0x38e, 0x3a1}, {0x3a3, 0x3ce}, {0x3d0, 0x3d6}, {0x3da, 0x3da}, + {0x3dc, 0x3dc}, {0x3de, 0x3de}, {0x3e0, 0x3e0}, {0x3e2, 0x3f3}, + {0x401, 0x40c}, {0x40e, 0x44f}, {0x451, 0x45c}, {0x45e, 0x481}, + {0x490, 0x4c4}, {0x4c7, 0x4c8}, {0x4cb, 0x4cc}, {0x4d0, 0x4eb}, + {0x4ee, 0x4f5}, {0x4f8, 0x4f9}, {0x531, 0x556}, {0x559, 0x559}, + {0x561, 0x586}, {0x5d0, 0x5ea}, {0x5f0, 0x5f2}, {0x621, 0x63a}, + {0x641, 0x64a}, {0x671, 0x6b7}, {0x6ba, 0x6be}, {0x6c0, 0x6ce}, + {0x6d0, 0x6d3}, {0x6d5, 0x6d5}, {0x6e5, 0x6e6}, {0x905, 0x939}, + {0x93d, 0x93d}, {0x958, 0x961}, {0x985, 0x98c}, {0x98f, 0x990}, + {0x993, 0x9a8}, {0x9aa, 0x9b0}, {0x9b2, 0x9b2}, {0x9b6, 0x9b9}, + {0x9dc, 0x9dd}, {0x9df, 0x9e1}, {0x9f0, 0x9f1}, {0xa05, 0xa0a}, + {0xa0f, 0xa10}, {0xa13, 0xa28}, {0xa2a, 0xa30}, {0xa32, 0xa33}, + {0xa35, 0xa36}, {0xa38, 0xa39}, {0xa59, 0xa5c}, {0xa5e, 0xa5e}, + {0xa72, 0xa74}, {0xa85, 0xa8b}, {0xa8d, 0xa8d}, {0xa8f, 0xa91}, + {0xa93, 0xaa8}, {0xaaa, 0xab0}, {0xab2, 0xab3}, {0xab5, 0xab9}, + {0xabd, 0xabd}, {0xae0, 0xae0}, {0xb05, 0xb0c}, {0xb0f, 0xb10}, + {0xb13, 0xb28}, {0xb2a, 0xb30}, {0xb32, 0xb33}, {0xb36, 0xb39}, + {0xb3d, 0xb3d}, {0xb5c, 0xb5d}, {0xb5f, 0xb61}, {0xb85, 0xb8a}, + {0xb8e, 0xb90}, {0xb92, 0xb95}, {0xb99, 0xb9a}, {0xb9c, 0xb9c}, + {0xb9e, 0xb9f}, {0xba3, 0xba4}, {0xba8, 0xbaa}, {0xbae, 0xbb5}, + {0xbb7, 0xbb9}, {0xc05, 0xc0c}, {0xc0e, 0xc10}, {0xc12, 0xc28}, + {0xc2a, 0xc33}, {0xc35, 0xc39}, {0xc60, 0xc61}, {0xc85, 0xc8c}, + {0xc8e, 0xc90}, {0xc92, 0xca8}, {0xcaa, 0xcb3}, {0xcb5, 0xcb9}, + {0xcde, 0xcde}, {0xce0, 0xce1}, {0xd05, 0xd0c}, {0xd0e, 0xd10}, + {0xd12, 0xd28}, {0xd2a, 0xd39}, {0xd60, 0xd61}, {0xe01, 0xe2e}, + {0xe30, 0xe30}, {0xe32, 0xe33}, {0xe40, 0xe45}, {0xe81, 0xe82}, + {0xe84, 0xe84}, {0xe87, 0xe88}, {0xe8a, 0xe8a}, {0xe8d, 0xe8d}, + {0xe94, 0xe97}, {0xe99, 0xe9f}, {0xea1, 0xea3}, {0xea5, 0xea5}, + {0xea7, 0xea7}, {0xeaa, 0xeab}, {0xead, 0xeae}, {0xeb0, 0xeb0}, + {0xeb2, 0xeb3}, {0xebd, 0xebd}, {0xec0, 0xec4}, {0xf40, 0xf47}, + {0xf49, 0xf69}, {0x10a0, 0x10c5}, {0x10d0, 0x10f6}, {0x1100, 0x1100}, + {0x1102, 0x1103}, {0x1105, 0x1107}, {0x1109, 0x1109}, {0x110b, 0x110c}, + {0x110e, 0x1112}, {0x113c, 0x113c}, {0x113e, 0x113e}, {0x1140, 0x1140}, + {0x114c, 0x114c}, {0x114e, 0x114e}, {0x1150, 0x1150}, {0x1154, 0x1155}, + {0x1159, 0x1159}, {0x115f, 0x1161}, {0x1163, 0x1163}, {0x1165, 0x1165}, + {0x1167, 0x1167}, {0x1169, 0x1169}, {0x116d, 0x116e}, {0x1172, 0x1173}, + {0x1175, 0x1175}, {0x119e, 0x119e}, {0x11a8, 0x11a8}, {0x11ab, 0x11ab}, + {0x11ae, 0x11af}, {0x11b7, 0x11b8}, {0x11ba, 0x11ba}, {0x11bc, 0x11c2}, + {0x11eb, 0x11eb}, {0x11f0, 0x11f0}, {0x11f9, 0x11f9}, {0x1e00, 0x1e9b}, + {0x1ea0, 0x1ef9}, {0x1f00, 0x1f15}, {0x1f18, 0x1f1d}, {0x1f20, 0x1f45}, + {0x1f48, 0x1f4d}, {0x1f50, 0x1f57}, {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, + {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f7d}, {0x1f80, 0x1fb4}, {0x1fb6, 0x1fbc}, + {0x1fbe, 0x1fbe}, {0x1fc2, 0x1fc4}, {0x1fc6, 0x1fcc}, {0x1fd0, 0x1fd3}, + {0x1fd6, 0x1fdb}, {0x1fe0, 0x1fec}, {0x1ff2, 0x1ff4}, {0x1ff6, 0x1ffc}, + {0x2126, 0x2126}, {0x212a, 0x212b}, {0x212e, 0x212e}, {0x2180, 0x2182}, + {0x3041, 0x3094}, {0x30a1, 0x30fa}, {0x3105, 0x312c}, {0xac00, 0xd7a3}}; +const xmlChRangeGroup xmlIsBaseCharGroup = {197, 0, xmlIsBaseChar_srng, (xmlChLRangePtr)0}; -static xmlChSRange xmlIsChar_srng[] = { {0x100, 0xd7ff}, {0xe000, 0xfffd}}; -static xmlChLRange xmlIsChar_lrng[] = { {0x10000, 0x10ffff}}; -xmlChRangeGroup xmlIsCharGroup = +static const xmlChSRange xmlIsChar_srng[] = { {0x100, 0xd7ff}, + {0xe000, 0xfffd}}; +static const xmlChLRange xmlIsChar_lrng[] = { {0x10000, 0x10ffff}}; +const xmlChRangeGroup xmlIsCharGroup = {2, 1, xmlIsChar_srng, xmlIsChar_lrng}; -static xmlChSRange xmlIsCombining_srng[] = { {0x300, 0x345}, +static const xmlChSRange xmlIsCombining_srng[] = { {0x300, 0x345}, {0x360, 0x361}, {0x483, 0x486}, {0x591, 0x5a1}, {0x5a3, 0x5b9}, {0x5bb, 0x5bd}, {0x5bf, 0x5bf}, {0x5c1, 0x5c2}, {0x5c4, 0x5c4}, {0x64b, 0x652}, {0x670, 0x670}, {0x6d6, 0x6dc}, {0x6dd, 0x6df}, @@ -129,25 +130,27 @@ static xmlChSRange xmlIsCombining_srng[] = { {0x300, 0x345}, {0xf90, 0xf95}, {0xf97, 0xf97}, {0xf99, 0xfad}, {0xfb1, 0xfb7}, {0xfb9, 0xfb9}, {0x20d0, 0x20dc}, {0x20e1, 0x20e1}, {0x302a, 0x302f}, {0x3099, 0x3099}, {0x309a, 0x309a}}; -xmlChRangeGroup xmlIsCombiningGroup = +const xmlChRangeGroup xmlIsCombiningGroup = {95, 0, xmlIsCombining_srng, (xmlChLRangePtr)0}; -static xmlChSRange xmlIsDigit_srng[] = { {0x660, 0x669}, {0x6f0, 0x6f9}, - {0x966, 0x96f}, {0x9e6, 0x9ef}, {0xa66, 0xa6f}, {0xae6, 0xaef}, - {0xb66, 0xb6f}, {0xbe7, 0xbef}, {0xc66, 0xc6f}, {0xce6, 0xcef}, - {0xd66, 0xd6f}, {0xe50, 0xe59}, {0xed0, 0xed9}, {0xf20, 0xf29}}; -xmlChRangeGroup xmlIsDigitGroup = +static const xmlChSRange xmlIsDigit_srng[] = { {0x660, 0x669}, + {0x6f0, 0x6f9}, {0x966, 0x96f}, {0x9e6, 0x9ef}, {0xa66, 0xa6f}, + {0xae6, 0xaef}, {0xb66, 0xb6f}, {0xbe7, 0xbef}, {0xc66, 0xc6f}, + {0xce6, 0xcef}, {0xd66, 0xd6f}, {0xe50, 0xe59}, {0xed0, 0xed9}, + {0xf20, 0xf29}}; +const xmlChRangeGroup xmlIsDigitGroup = {14, 0, xmlIsDigit_srng, (xmlChLRangePtr)0}; -static xmlChSRange xmlIsExtender_srng[] = { {0x2d0, 0x2d0}, {0x2d1, 0x2d1}, - {0x387, 0x387}, {0x640, 0x640}, {0xe46, 0xe46}, {0xec6, 0xec6}, - {0x3005, 0x3005}, {0x3031, 0x3035}, {0x309d, 0x309e}, {0x30fc, 0x30fe}}; -xmlChRangeGroup xmlIsExtenderGroup = +static const xmlChSRange xmlIsExtender_srng[] = { {0x2d0, 0x2d0}, + {0x2d1, 0x2d1}, {0x387, 0x387}, {0x640, 0x640}, {0xe46, 0xe46}, + {0xec6, 0xec6}, {0x3005, 0x3005}, {0x3031, 0x3035}, {0x309d, 0x309e}, + {0x30fc, 0x30fe}}; +const xmlChRangeGroup xmlIsExtenderGroup = {10, 0, xmlIsExtender_srng, (xmlChLRangePtr)0}; -static xmlChSRange xmlIsIdeographic_srng[] = { {0x3007, 0x3007}, +static const xmlChSRange xmlIsIdeographic_srng[] = { {0x3007, 0x3007}, {0x3021, 0x3029}, {0x4e00, 0x9fa5}}; -xmlChRangeGroup xmlIsIdeographicGroup = +const xmlChRangeGroup xmlIsIdeographicGroup = {3, 0, xmlIsIdeographic_srng, (xmlChLRangePtr)0}; @@ -162,10 +165,10 @@ xmlChRangeGroup xmlIsIdeographicGroup = * Returns: true if character valid, false otherwise */ int -xmlCharInRange (unsigned int val, const xmlChRangeGroupPtr rptr) { +xmlCharInRange (unsigned int val, const xmlChRangeGroup *rptr) { int low, high, mid; - xmlChSRangePtr sptr; - xmlChLRangePtr lptr; + const xmlChSRange *sptr; + const xmlChLRange *lptr; if (rptr == NULL) return(0); if (val < 0x10000) { /* is val in 'short' or 'long' array? */ diff --git a/Extras/LibXML/debugXML.c b/Extras/LibXML/debugXML.c index 20190ad27..3985ad38b 100644 --- a/Extras/LibXML/debugXML.c +++ b/Extras/LibXML/debugXML.c @@ -34,6 +34,8 @@ #include #endif +#define DUMP_TEXT_TYPE 1 + typedef struct _xmlDebugCtxt xmlDebugCtxt; typedef xmlDebugCtxt *xmlDebugCtxtPtr; struct _xmlDebugCtxt { @@ -46,6 +48,7 @@ struct _xmlDebugCtxt { int check; /* do just checkings */ int errors; /* number of errors found */ int nodict; /* if the document has no dictionnary */ + int options; /* options */ }; static void xmlCtxtDumpNodeList(xmlDebugCtxtPtr ctxt, xmlNodePtr node); @@ -63,6 +66,7 @@ xmlCtxtDumpInitCtxt(xmlDebugCtxtPtr ctxt) ctxt->node = NULL; ctxt->dict = NULL; ctxt->nodict = 0; + ctxt->options = 0; for (i = 0; i < 100; i++) ctxt->shift[i] = ' '; ctxt->shift[100] = 0; @@ -344,8 +348,10 @@ xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) { if ((node->type != XML_ELEMENT_NODE) && (node->type != XML_ATTRIBUTE_NODE) && + (node->type != XML_ELEMENT_DECL) && (node->type != XML_ATTRIBUTE_DECL) && (node->type != XML_DTD_NODE) && + (node->type != XML_ELEMENT_DECL) && (node->type != XML_HTML_DOCUMENT_NODE) && (node->type != XML_DOCUMENT_NODE)) { if (node->content != NULL) @@ -900,9 +906,18 @@ xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node) if (!ctxt->check) { xmlCtxtDumpSpaces(ctxt); if (node->name == (const xmlChar *) xmlStringTextNoenc) - fprintf(ctxt->output, "TEXT no enc\n"); + fprintf(ctxt->output, "TEXT no enc"); else - fprintf(ctxt->output, "TEXT\n"); + fprintf(ctxt->output, "TEXT"); + if (ctxt->options & DUMP_TEXT_TYPE) { + if (node->content == (xmlChar *) &(node->properties)) + fprintf(ctxt->output, " compact\n"); + else if (xmlDictOwns(ctxt->dict, node->content) == 1) + fprintf(ctxt->output, " interned\n"); + else + fprintf(ctxt->output, "\n"); + } else + fprintf(ctxt->output, "\n"); } break; case XML_CDATA_SECTION_NODE: @@ -1003,9 +1018,9 @@ xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node) fprintf(ctxt->output, "PBM: doc == NULL !!!\n"); } ctxt->depth++; - if (node->nsDef != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL)) xmlCtxtDumpNamespaceList(ctxt, node->nsDef); - if (node->properties != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL)) xmlCtxtDumpAttrList(ctxt, node->properties); if (node->type != XML_ENTITY_REF_NODE) { if ((node->type != XML_ELEMENT_NODE) && (node->content != NULL)) { @@ -1050,7 +1065,8 @@ xmlCtxtDumpNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node) return; } xmlCtxtDumpOneNode(ctxt, node); - if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) { + if ((node->type != XML_NAMESPACE_DECL) && + (node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) { ctxt->depth++; xmlCtxtDumpNodeList(ctxt, node->children); ctxt->depth--; @@ -1487,6 +1503,7 @@ xmlDebugDumpDocumentHead(FILE * output, xmlDocPtr doc) if (output == NULL) output = stdout; xmlCtxtDumpInitCtxt(&ctxt); + ctxt.options |= DUMP_TEXT_TYPE; ctxt.output = output; xmlCtxtDumpDocumentHead(&ctxt, doc); xmlCtxtDumpCleanCtxt(&ctxt); @@ -1507,6 +1524,7 @@ xmlDebugDumpDocument(FILE * output, xmlDocPtr doc) if (output == NULL) output = stdout; xmlCtxtDumpInitCtxt(&ctxt); + ctxt.options |= DUMP_TEXT_TYPE; ctxt.output = output; xmlCtxtDumpDocument(&ctxt, doc); xmlCtxtDumpCleanCtxt(&ctxt); @@ -1527,6 +1545,7 @@ xmlDebugDumpDTD(FILE * output, xmlDtdPtr dtd) if (output == NULL) output = stdout; xmlCtxtDumpInitCtxt(&ctxt); + ctxt.options |= DUMP_TEXT_TYPE; ctxt.output = output; xmlCtxtDumpDTD(&ctxt, dtd); xmlCtxtDumpCleanCtxt(&ctxt); @@ -2122,6 +2141,37 @@ xmlShellRegisterNamespace(xmlShellCtxtPtr ctxt, char *arg, xmlFree(nsListDup); return(0); } +/** + * xmlShellRegisterRootNamespaces: + * @ctxt: the shell context + * @arg: unused + * @node: the root element + * @node2: unused + * + * Implements the XML shell function "setrootns" + * which registers all namespaces declarations found on the root element. + * + * Returns 0 on success and a negative value otherwise. + */ +static int +xmlShellRegisterRootNamespaces(xmlShellCtxtPtr ctxt, char *arg ATTRIBUTE_UNUSED, + xmlNodePtr root, xmlNodePtr node2 ATTRIBUTE_UNUSED) +{ + xmlNsPtr ns; + + if ((root == NULL) || (root->type != XML_ELEMENT_NODE) || + (root->nsDef == NULL) || (ctxt == NULL) || (ctxt->pctxt == NULL)) + return(-1); + ns = root->nsDef; + while (ns != NULL) { + if (ns->prefix == NULL) + xmlXPathRegisterNs(ctxt->pctxt, BAD_CAST "defaultns", ns->href); + else + xmlXPathRegisterNs(ctxt->pctxt, ns->prefix, ns->href); + ns = ns->next; + } + return(0); +} #endif /** @@ -2859,6 +2909,8 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, fprintf(ctxt->output, "\txpath expr evaluate the XPath expression in that context and print the result\n"); fprintf(ctxt->output, "\tsetns nsreg register a namespace to a prefix in the XPath evaluation context\n"); fprintf(ctxt->output, "\t format for nsreg is: prefix=[nsuri] (i.e. prefix= unsets a prefix)\n"); + fprintf(ctxt->output, "\tsetrootns register all namespace found on the root element\n"); + fprintf(ctxt->output, "\t the default namespace if any uses 'defaultns' prefix\n"); #endif /* LIBXML_XPATH_ENABLED */ fprintf(ctxt->output, "\tpwd display current working directory\n"); fprintf(ctxt->output, "\tquit leave shell\n"); @@ -2923,6 +2975,11 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input, } else { xmlShellRegisterNamespace(ctxt, arg, NULL, NULL); } + } else if (!strcmp(command, "setrootns")) { + xmlNodePtr root; + + root = xmlDocGetRootElement(ctxt->doc); + xmlShellRegisterRootNamespaces(ctxt, NULL, root, NULL); } else if (!strcmp(command, "xpath")) { if (arg[0] == 0) { xmlGenericError(xmlGenericErrorContext, diff --git a/Extras/LibXML/dict.c b/Extras/LibXML/dict.c index 51048f842..3b4054f23 100644 --- a/Extras/LibXML/dict.c +++ b/Extras/LibXML/dict.c @@ -41,7 +41,7 @@ typedef xmlDictEntry *xmlDictEntryPtr; struct _xmlDictEntry { struct _xmlDictEntry *next; const xmlChar *name; - intptr_t len; + int len; int valid; }; @@ -51,8 +51,8 @@ struct _xmlDictStrings { xmlDictStringsPtr next; xmlChar *free; xmlChar *end; - intptr_t size; - intptr_t nbStrings; + int size; + int nbStrings; xmlChar array[1]; }; /* @@ -125,10 +125,10 @@ xmlDictCleanup(void) { * Returns the pointer of the local string, or NULL in case of error. */ static const xmlChar * -xmlDictAddString(xmlDictPtr dict, const xmlChar *name, intptr_t namelen) { +xmlDictAddString(xmlDictPtr dict, const xmlChar *name, int namelen) { xmlDictStringsPtr pool; const xmlChar *ret; - intptr_t size = 0; /* + sizeof(_xmlDictStrings) == 1024 */ + int size = 0; /* + sizeof(_xmlDictStrings) == 1024 */ pool = dict->strings; while (pool != NULL) { @@ -176,12 +176,12 @@ found_pool: */ static const xmlChar * xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, - const xmlChar *name, intptr_t namelen) + const xmlChar *name, int namelen) { xmlDictStringsPtr pool; const xmlChar *ret; - intptr_t size = 0; /* + sizeof(_xmlDictStrings) == 1024 */ - size_t plen; + int size = 0; /* + sizeof(_xmlDictStrings) == 1024 */ + int plen; if (prefix == NULL) return(xmlDictAddString(dict, name, namelen)); plen = xmlStrlen(prefix); @@ -228,7 +228,7 @@ found_pool: * Calculate the hash key */ static unsigned long -xmlDictComputeKey(const xmlChar *name, intptr_t namelen) { +xmlDictComputeKey(const xmlChar *name, int namelen) { unsigned long value = 0L; if (name == NULL) return(0); @@ -258,10 +258,10 @@ xmlDictComputeKey(const xmlChar *name, intptr_t namelen) { * Calculate the hash key */ static unsigned long -xmlDictComputeQKey(const xmlChar *prefix, const xmlChar *name, intptr_t len) +xmlDictComputeQKey(const xmlChar *prefix, const xmlChar *name, int len) { unsigned long value = 0L; - size_t plen; + int plen; if (prefix == NULL) return(xmlDictComputeKey(name, len)); @@ -560,7 +560,7 @@ xmlDictFree(xmlDictPtr dict) { * Returns the internal copy of the name or NULL in case of internal error */ const xmlChar * -xmlDictLookup(xmlDictPtr dict, const xmlChar *name, intptr_t len) { +xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len) { unsigned long key, okey, nbi = 0; xmlDictEntryPtr entry; xmlDictEntryPtr insert; @@ -679,7 +679,7 @@ xmlDictLookup(xmlDictPtr dict, const xmlChar *name, intptr_t len) { * Returns the internal copy of the name or NULL if not found. */ const xmlChar * -xmlDictExists(xmlDictPtr dict, const xmlChar *name, intptr_t len) { +xmlDictExists(xmlDictPtr dict, const xmlChar *name, int len) { unsigned long key, okey, nbi = 0; xmlDictEntryPtr insert; @@ -776,7 +776,7 @@ xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) { xmlDictEntryPtr entry; xmlDictEntryPtr insert; const xmlChar *ret; - intptr_t len; + int len; if ((dict == NULL) || (name == NULL)) return(NULL); diff --git a/Extras/LibXML/elfgcchack.h b/Extras/LibXML/elfgcchack.h index 59579884a..741f806ae 100644 --- a/Extras/LibXML/elfgcchack.h +++ b/Extras/LibXML/elfgcchack.h @@ -36,6 +36,7 @@ #include "libxml/SAX2.h" #include "libxml/SAX.h" #include "libxml/schemasInternals.h" +#include "libxml/schematron.h" #include "libxml/threads.h" #include "libxml/tree.h" #include "libxml/uri.h" @@ -300,6 +301,18 @@ extern __typeof (htmlDocDumpMemory) htmlDocDumpMemory__internal_alias __attribut #endif #endif +#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) +#ifdef bottom_HTMLtree +#undef htmlDocDumpMemoryFormat +extern __typeof (htmlDocDumpMemoryFormat) htmlDocDumpMemoryFormat __attribute((alias("htmlDocDumpMemoryFormat__internal_alias"))); +#else +#ifndef htmlDocDumpMemoryFormat +extern __typeof (htmlDocDumpMemoryFormat) htmlDocDumpMemoryFormat__internal_alias __attribute((visibility("hidden"))); +#define htmlDocDumpMemoryFormat htmlDocDumpMemoryFormat__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_HTML_ENABLED) #ifdef bottom_HTMLparser #undef htmlElementAllowedHere @@ -1222,6 +1235,18 @@ extern __typeof (xmlAutomataNewEpsilon) xmlAutomataNewEpsilon__internal_alias __ #endif #endif +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_AUTOMATA_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlAutomataNewNegTrans +extern __typeof (xmlAutomataNewNegTrans) xmlAutomataNewNegTrans __attribute((alias("xmlAutomataNewNegTrans__internal_alias"))); +#else +#ifndef xmlAutomataNewNegTrans +extern __typeof (xmlAutomataNewNegTrans) xmlAutomataNewNegTrans__internal_alias __attribute((visibility("hidden"))); +#define xmlAutomataNewNegTrans xmlAutomataNewNegTrans__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_AUTOMATA_ENABLED) #ifdef bottom_xmlregexp #undef xmlAutomataNewOnceTrans @@ -2496,6 +2521,66 @@ extern __typeof (xmlCurrentChar) xmlCurrentChar__internal_alias __attribute((vis #endif #endif +#ifdef bottom_tree +#undef xmlDOMWrapAdoptNode +extern __typeof (xmlDOMWrapAdoptNode) xmlDOMWrapAdoptNode __attribute((alias("xmlDOMWrapAdoptNode__internal_alias"))); +#else +#ifndef xmlDOMWrapAdoptNode +extern __typeof (xmlDOMWrapAdoptNode) xmlDOMWrapAdoptNode__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapAdoptNode xmlDOMWrapAdoptNode__internal_alias +#endif +#endif + +#ifdef bottom_tree +#undef xmlDOMWrapCloneNode +extern __typeof (xmlDOMWrapCloneNode) xmlDOMWrapCloneNode __attribute((alias("xmlDOMWrapCloneNode__internal_alias"))); +#else +#ifndef xmlDOMWrapCloneNode +extern __typeof (xmlDOMWrapCloneNode) xmlDOMWrapCloneNode__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapCloneNode xmlDOMWrapCloneNode__internal_alias +#endif +#endif + +#ifdef bottom_tree +#undef xmlDOMWrapFreeCtxt +extern __typeof (xmlDOMWrapFreeCtxt) xmlDOMWrapFreeCtxt __attribute((alias("xmlDOMWrapFreeCtxt__internal_alias"))); +#else +#ifndef xmlDOMWrapFreeCtxt +extern __typeof (xmlDOMWrapFreeCtxt) xmlDOMWrapFreeCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapFreeCtxt xmlDOMWrapFreeCtxt__internal_alias +#endif +#endif + +#ifdef bottom_tree +#undef xmlDOMWrapNewCtxt +extern __typeof (xmlDOMWrapNewCtxt) xmlDOMWrapNewCtxt __attribute((alias("xmlDOMWrapNewCtxt__internal_alias"))); +#else +#ifndef xmlDOMWrapNewCtxt +extern __typeof (xmlDOMWrapNewCtxt) xmlDOMWrapNewCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapNewCtxt xmlDOMWrapNewCtxt__internal_alias +#endif +#endif + +#ifdef bottom_tree +#undef xmlDOMWrapReconcileNamespaces +extern __typeof (xmlDOMWrapReconcileNamespaces) xmlDOMWrapReconcileNamespaces __attribute((alias("xmlDOMWrapReconcileNamespaces__internal_alias"))); +#else +#ifndef xmlDOMWrapReconcileNamespaces +extern __typeof (xmlDOMWrapReconcileNamespaces) xmlDOMWrapReconcileNamespaces__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapReconcileNamespaces xmlDOMWrapReconcileNamespaces__internal_alias +#endif +#endif + +#ifdef bottom_tree +#undef xmlDOMWrapRemoveNode +extern __typeof (xmlDOMWrapRemoveNode) xmlDOMWrapRemoveNode __attribute((alias("xmlDOMWrapRemoveNode__internal_alias"))); +#else +#ifndef xmlDOMWrapRemoveNode +extern __typeof (xmlDOMWrapRemoveNode) xmlDOMWrapRemoveNode__internal_alias __attribute((visibility("hidden"))); +#define xmlDOMWrapRemoveNode xmlDOMWrapRemoveNode__internal_alias +#endif +#endif + #if defined(LIBXML_DEBUG_ENABLED) #ifdef bottom_debugXML #undef xmlDebugCheckDocument @@ -3044,6 +3129,234 @@ extern __typeof (xmlErrMemory) xmlErrMemory__internal_alias __attribute((visibil #endif #endif +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpCtxtNbCons +extern __typeof (xmlExpCtxtNbCons) xmlExpCtxtNbCons __attribute((alias("xmlExpCtxtNbCons__internal_alias"))); +#else +#ifndef xmlExpCtxtNbCons +extern __typeof (xmlExpCtxtNbCons) xmlExpCtxtNbCons__internal_alias __attribute((visibility("hidden"))); +#define xmlExpCtxtNbCons xmlExpCtxtNbCons__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpCtxtNbNodes +extern __typeof (xmlExpCtxtNbNodes) xmlExpCtxtNbNodes __attribute((alias("xmlExpCtxtNbNodes__internal_alias"))); +#else +#ifndef xmlExpCtxtNbNodes +extern __typeof (xmlExpCtxtNbNodes) xmlExpCtxtNbNodes__internal_alias __attribute((visibility("hidden"))); +#define xmlExpCtxtNbNodes xmlExpCtxtNbNodes__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpDump +extern __typeof (xmlExpDump) xmlExpDump __attribute((alias("xmlExpDump__internal_alias"))); +#else +#ifndef xmlExpDump +extern __typeof (xmlExpDump) xmlExpDump__internal_alias __attribute((visibility("hidden"))); +#define xmlExpDump xmlExpDump__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpExpDerive +extern __typeof (xmlExpExpDerive) xmlExpExpDerive __attribute((alias("xmlExpExpDerive__internal_alias"))); +#else +#ifndef xmlExpExpDerive +extern __typeof (xmlExpExpDerive) xmlExpExpDerive__internal_alias __attribute((visibility("hidden"))); +#define xmlExpExpDerive xmlExpExpDerive__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpFree +extern __typeof (xmlExpFree) xmlExpFree __attribute((alias("xmlExpFree__internal_alias"))); +#else +#ifndef xmlExpFree +extern __typeof (xmlExpFree) xmlExpFree__internal_alias __attribute((visibility("hidden"))); +#define xmlExpFree xmlExpFree__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpFreeCtxt +extern __typeof (xmlExpFreeCtxt) xmlExpFreeCtxt __attribute((alias("xmlExpFreeCtxt__internal_alias"))); +#else +#ifndef xmlExpFreeCtxt +extern __typeof (xmlExpFreeCtxt) xmlExpFreeCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlExpFreeCtxt xmlExpFreeCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpGetLanguage +extern __typeof (xmlExpGetLanguage) xmlExpGetLanguage __attribute((alias("xmlExpGetLanguage__internal_alias"))); +#else +#ifndef xmlExpGetLanguage +extern __typeof (xmlExpGetLanguage) xmlExpGetLanguage__internal_alias __attribute((visibility("hidden"))); +#define xmlExpGetLanguage xmlExpGetLanguage__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpGetStart +extern __typeof (xmlExpGetStart) xmlExpGetStart __attribute((alias("xmlExpGetStart__internal_alias"))); +#else +#ifndef xmlExpGetStart +extern __typeof (xmlExpGetStart) xmlExpGetStart__internal_alias __attribute((visibility("hidden"))); +#define xmlExpGetStart xmlExpGetStart__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpIsNillable +extern __typeof (xmlExpIsNillable) xmlExpIsNillable __attribute((alias("xmlExpIsNillable__internal_alias"))); +#else +#ifndef xmlExpIsNillable +extern __typeof (xmlExpIsNillable) xmlExpIsNillable__internal_alias __attribute((visibility("hidden"))); +#define xmlExpIsNillable xmlExpIsNillable__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpMaxToken +extern __typeof (xmlExpMaxToken) xmlExpMaxToken __attribute((alias("xmlExpMaxToken__internal_alias"))); +#else +#ifndef xmlExpMaxToken +extern __typeof (xmlExpMaxToken) xmlExpMaxToken__internal_alias __attribute((visibility("hidden"))); +#define xmlExpMaxToken xmlExpMaxToken__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpNewAtom +extern __typeof (xmlExpNewAtom) xmlExpNewAtom __attribute((alias("xmlExpNewAtom__internal_alias"))); +#else +#ifndef xmlExpNewAtom +extern __typeof (xmlExpNewAtom) xmlExpNewAtom__internal_alias __attribute((visibility("hidden"))); +#define xmlExpNewAtom xmlExpNewAtom__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpNewCtxt +extern __typeof (xmlExpNewCtxt) xmlExpNewCtxt __attribute((alias("xmlExpNewCtxt__internal_alias"))); +#else +#ifndef xmlExpNewCtxt +extern __typeof (xmlExpNewCtxt) xmlExpNewCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlExpNewCtxt xmlExpNewCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpNewOr +extern __typeof (xmlExpNewOr) xmlExpNewOr __attribute((alias("xmlExpNewOr__internal_alias"))); +#else +#ifndef xmlExpNewOr +extern __typeof (xmlExpNewOr) xmlExpNewOr__internal_alias __attribute((visibility("hidden"))); +#define xmlExpNewOr xmlExpNewOr__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpNewRange +extern __typeof (xmlExpNewRange) xmlExpNewRange __attribute((alias("xmlExpNewRange__internal_alias"))); +#else +#ifndef xmlExpNewRange +extern __typeof (xmlExpNewRange) xmlExpNewRange__internal_alias __attribute((visibility("hidden"))); +#define xmlExpNewRange xmlExpNewRange__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpNewSeq +extern __typeof (xmlExpNewSeq) xmlExpNewSeq __attribute((alias("xmlExpNewSeq__internal_alias"))); +#else +#ifndef xmlExpNewSeq +extern __typeof (xmlExpNewSeq) xmlExpNewSeq__internal_alias __attribute((visibility("hidden"))); +#define xmlExpNewSeq xmlExpNewSeq__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpParse +extern __typeof (xmlExpParse) xmlExpParse __attribute((alias("xmlExpParse__internal_alias"))); +#else +#ifndef xmlExpParse +extern __typeof (xmlExpParse) xmlExpParse__internal_alias __attribute((visibility("hidden"))); +#define xmlExpParse xmlExpParse__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpRef +extern __typeof (xmlExpRef) xmlExpRef __attribute((alias("xmlExpRef__internal_alias"))); +#else +#ifndef xmlExpRef +extern __typeof (xmlExpRef) xmlExpRef__internal_alias __attribute((visibility("hidden"))); +#define xmlExpRef xmlExpRef__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpStringDerive +extern __typeof (xmlExpStringDerive) xmlExpStringDerive __attribute((alias("xmlExpStringDerive__internal_alias"))); +#else +#ifndef xmlExpStringDerive +extern __typeof (xmlExpStringDerive) xmlExpStringDerive__internal_alias __attribute((visibility("hidden"))); +#define xmlExpStringDerive xmlExpStringDerive__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_EXPR_ENABLED) +#ifdef bottom_xmlregexp +#undef xmlExpSubsume +extern __typeof (xmlExpSubsume) xmlExpSubsume __attribute((alias("xmlExpSubsume__internal_alias"))); +#else +#ifndef xmlExpSubsume +extern __typeof (xmlExpSubsume) xmlExpSubsume__internal_alias __attribute((visibility("hidden"))); +#define xmlExpSubsume xmlExpSubsume__internal_alias +#endif +#endif +#endif + #ifdef bottom_xmlIO #undef xmlFileClose extern __typeof (xmlFileClose) xmlFileClose __attribute((alias("xmlFileClose__internal_alias"))); @@ -3780,6 +4093,16 @@ extern __typeof (xmlHandleEntity) xmlHandleEntity__internal_alias __attribute((v #endif #endif +#ifdef bottom_parser +#undef xmlHasFeature +extern __typeof (xmlHasFeature) xmlHasFeature __attribute((alias("xmlHasFeature__internal_alias"))); +#else +#ifndef xmlHasFeature +extern __typeof (xmlHasFeature) xmlHasFeature__internal_alias __attribute((visibility("hidden"))); +#define xmlHasFeature xmlHasFeature__internal_alias +#endif +#endif + #ifdef bottom_tree #undef xmlHasNsProp extern __typeof (xmlHasNsProp) xmlHasNsProp __attribute((alias("xmlHasNsProp__internal_alias"))); @@ -6270,6 +6593,18 @@ extern __typeof (xmlOutputBufferClose) xmlOutputBufferClose__internal_alias __at #endif #endif +#if defined(LIBXML_OUTPUT_ENABLED) +#ifdef bottom_xmlIO +#undef xmlOutputBufferCreateBuffer +extern __typeof (xmlOutputBufferCreateBuffer) xmlOutputBufferCreateBuffer __attribute((alias("xmlOutputBufferCreateBuffer__internal_alias"))); +#else +#ifndef xmlOutputBufferCreateBuffer +extern __typeof (xmlOutputBufferCreateBuffer) xmlOutputBufferCreateBuffer__internal_alias __attribute((visibility("hidden"))); +#define xmlOutputBufferCreateBuffer xmlOutputBufferCreateBuffer__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_OUTPUT_ENABLED) #ifdef bottom_xmlIO #undef xmlOutputBufferCreateFd @@ -6996,6 +7331,16 @@ extern __typeof (xmlParseURI) xmlParseURI__internal_alias __attribute((visibilit #endif #endif +#ifdef bottom_uri +#undef xmlParseURIRaw +extern __typeof (xmlParseURIRaw) xmlParseURIRaw __attribute((alias("xmlParseURIRaw__internal_alias"))); +#else +#ifndef xmlParseURIRaw +extern __typeof (xmlParseURIRaw) xmlParseURIRaw__internal_alias __attribute((visibility("hidden"))); +#define xmlParseURIRaw xmlParseURIRaw__internal_alias +#endif +#endif + #ifdef bottom_uri #undef xmlParseURIReference extern __typeof (xmlParseURIReference) xmlParseURIReference __attribute((alias("xmlParseURIReference__internal_alias"))); @@ -7336,6 +7681,18 @@ extern __typeof (xmlPatternMaxDepth) xmlPatternMaxDepth__internal_alias __attrib #endif #endif +#if defined(LIBXML_PATTERN_ENABLED) +#ifdef bottom_pattern +#undef xmlPatternMinDepth +extern __typeof (xmlPatternMinDepth) xmlPatternMinDepth __attribute((alias("xmlPatternMinDepth__internal_alias"))); +#else +#ifndef xmlPatternMinDepth +extern __typeof (xmlPatternMinDepth) xmlPatternMinDepth__internal_alias __attribute((visibility("hidden"))); +#define xmlPatternMinDepth xmlPatternMinDepth__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_PATTERN_ENABLED) #ifdef bottom_pattern #undef xmlPatternStreamable @@ -8070,6 +8427,18 @@ extern __typeof (xmlRelaxNGSetParserErrors) xmlRelaxNGSetParserErrors__internal_ #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_relaxng +#undef xmlRelaxNGSetParserStructuredErrors +extern __typeof (xmlRelaxNGSetParserStructuredErrors) xmlRelaxNGSetParserStructuredErrors __attribute((alias("xmlRelaxNGSetParserStructuredErrors__internal_alias"))); +#else +#ifndef xmlRelaxNGSetParserStructuredErrors +extern __typeof (xmlRelaxNGSetParserStructuredErrors) xmlRelaxNGSetParserStructuredErrors__internal_alias __attribute((visibility("hidden"))); +#define xmlRelaxNGSetParserStructuredErrors xmlRelaxNGSetParserStructuredErrors__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_relaxng #undef xmlRelaxNGSetValidErrors @@ -8082,6 +8451,18 @@ extern __typeof (xmlRelaxNGSetValidErrors) xmlRelaxNGSetValidErrors__internal_al #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_relaxng +#undef xmlRelaxNGSetValidStructuredErrors +extern __typeof (xmlRelaxNGSetValidStructuredErrors) xmlRelaxNGSetValidStructuredErrors __attribute((alias("xmlRelaxNGSetValidStructuredErrors__internal_alias"))); +#else +#ifndef xmlRelaxNGSetValidStructuredErrors +extern __typeof (xmlRelaxNGSetValidStructuredErrors) xmlRelaxNGSetValidStructuredErrors__internal_alias __attribute((visibility("hidden"))); +#define xmlRelaxNGSetValidStructuredErrors xmlRelaxNGSetValidStructuredErrors__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_relaxng #undef xmlRelaxNGValidateDoc @@ -8278,7 +8659,7 @@ extern __typeof (xmlSAX2EndDocument) xmlSAX2EndDocument__internal_alias __attrib #endif #endif -#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) +#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) #ifdef bottom_SAX2 #undef xmlSAX2EndElement extern __typeof (xmlSAX2EndElement) xmlSAX2EndElement __attribute((alias("xmlSAX2EndElement__internal_alias"))); @@ -8524,7 +8905,7 @@ extern __typeof (xmlSAX2StartDocument) xmlSAX2StartDocument__internal_alias __at #endif #endif -#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) +#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) #ifdef bottom_SAX2 #undef xmlSAX2StartElement extern __typeof (xmlSAX2StartElement) xmlSAX2StartElement __attribute((alias("xmlSAX2StartElement__internal_alias"))); @@ -8818,6 +9199,18 @@ extern __typeof (xmlSaveSetEscape) xmlSaveSetEscape__internal_alias __attribute( #endif #endif +#if defined(LIBXML_OUTPUT_ENABLED) +#ifdef bottom_xmlsave +#undef xmlSaveToBuffer +extern __typeof (xmlSaveToBuffer) xmlSaveToBuffer __attribute((alias("xmlSaveToBuffer__internal_alias"))); +#else +#ifndef xmlSaveToBuffer +extern __typeof (xmlSaveToBuffer) xmlSaveToBuffer__internal_alias __attribute((visibility("hidden"))); +#define xmlSaveToBuffer xmlSaveToBuffer__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_OUTPUT_ENABLED) #ifdef bottom_xmlsave #undef xmlSaveToFd @@ -9092,6 +9485,18 @@ extern __typeof (xmlSchemaGetCanonValue) xmlSchemaGetCanonValue__internal_alias #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaGetCanonValueWhtsp +extern __typeof (xmlSchemaGetCanonValueWhtsp) xmlSchemaGetCanonValueWhtsp __attribute((alias("xmlSchemaGetCanonValueWhtsp__internal_alias"))); +#else +#ifndef xmlSchemaGetCanonValueWhtsp +extern __typeof (xmlSchemaGetCanonValueWhtsp) xmlSchemaGetCanonValueWhtsp__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaGetCanonValueWhtsp xmlSchemaGetCanonValueWhtsp__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemastypes #undef xmlSchemaGetFacetValueAsULong @@ -9176,6 +9581,18 @@ extern __typeof (xmlSchemaIsBuiltInTypeFacet) xmlSchemaIsBuiltInTypeFacet__inter #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaIsValid +extern __typeof (xmlSchemaIsValid) xmlSchemaIsValid __attribute((alias("xmlSchemaIsValid__internal_alias"))); +#else +#ifndef xmlSchemaIsValid +extern __typeof (xmlSchemaIsValid) xmlSchemaIsValid__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaIsValid xmlSchemaIsValid__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemas #undef xmlSchemaNewDocParserCtxt @@ -9236,6 +9653,18 @@ extern __typeof (xmlSchemaNewParserCtxt) xmlSchemaNewParserCtxt__internal_alias #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaNewQNameValue +extern __typeof (xmlSchemaNewQNameValue) xmlSchemaNewQNameValue __attribute((alias("xmlSchemaNewQNameValue__internal_alias"))); +#else +#ifndef xmlSchemaNewQNameValue +extern __typeof (xmlSchemaNewQNameValue) xmlSchemaNewQNameValue__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaNewQNameValue xmlSchemaNewQNameValue__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemastypes #undef xmlSchemaNewStringValue @@ -9272,6 +9701,30 @@ extern __typeof (xmlSchemaParse) xmlSchemaParse__internal_alias __attribute((vis #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaSAXPlug +extern __typeof (xmlSchemaSAXPlug) xmlSchemaSAXPlug __attribute((alias("xmlSchemaSAXPlug__internal_alias"))); +#else +#ifndef xmlSchemaSAXPlug +extern __typeof (xmlSchemaSAXPlug) xmlSchemaSAXPlug__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaSAXPlug xmlSchemaSAXPlug__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaSAXUnplug +extern __typeof (xmlSchemaSAXUnplug) xmlSchemaSAXUnplug __attribute((alias("xmlSchemaSAXUnplug__internal_alias"))); +#else +#ifndef xmlSchemaSAXUnplug +extern __typeof (xmlSchemaSAXUnplug) xmlSchemaSAXUnplug__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaSAXUnplug xmlSchemaSAXUnplug__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemas #undef xmlSchemaSetParserErrors @@ -9284,6 +9737,18 @@ extern __typeof (xmlSchemaSetParserErrors) xmlSchemaSetParserErrors__internal_al #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaSetParserStructuredErrors +extern __typeof (xmlSchemaSetParserStructuredErrors) xmlSchemaSetParserStructuredErrors __attribute((alias("xmlSchemaSetParserStructuredErrors__internal_alias"))); +#else +#ifndef xmlSchemaSetParserStructuredErrors +extern __typeof (xmlSchemaSetParserStructuredErrors) xmlSchemaSetParserStructuredErrors__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaSetParserStructuredErrors xmlSchemaSetParserStructuredErrors__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemas #undef xmlSchemaSetValidErrors @@ -9308,6 +9773,18 @@ extern __typeof (xmlSchemaSetValidOptions) xmlSchemaSetValidOptions__internal_al #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaSetValidStructuredErrors +extern __typeof (xmlSchemaSetValidStructuredErrors) xmlSchemaSetValidStructuredErrors __attribute((alias("xmlSchemaSetValidStructuredErrors__internal_alias"))); +#else +#ifndef xmlSchemaSetValidStructuredErrors +extern __typeof (xmlSchemaSetValidStructuredErrors) xmlSchemaSetValidStructuredErrors__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaSetValidStructuredErrors xmlSchemaSetValidStructuredErrors__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemastypes #undef xmlSchemaValPredefTypeNode @@ -9380,6 +9857,18 @@ extern __typeof (xmlSchemaValidateFacetWhtsp) xmlSchemaValidateFacetWhtsp__inter #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemas +#undef xmlSchemaValidateFile +extern __typeof (xmlSchemaValidateFile) xmlSchemaValidateFile __attribute((alias("xmlSchemaValidateFile__internal_alias"))); +#else +#ifndef xmlSchemaValidateFile +extern __typeof (xmlSchemaValidateFile) xmlSchemaValidateFile__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaValidateFile xmlSchemaValidateFile__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemastypes #undef xmlSchemaValidateLengthFacet @@ -9452,6 +9941,54 @@ extern __typeof (xmlSchemaValidateStream) xmlSchemaValidateStream__internal_alia #endif #endif +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaValueAppend +extern __typeof (xmlSchemaValueAppend) xmlSchemaValueAppend __attribute((alias("xmlSchemaValueAppend__internal_alias"))); +#else +#ifndef xmlSchemaValueAppend +extern __typeof (xmlSchemaValueAppend) xmlSchemaValueAppend__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaValueAppend xmlSchemaValueAppend__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaValueGetAsBoolean +extern __typeof (xmlSchemaValueGetAsBoolean) xmlSchemaValueGetAsBoolean __attribute((alias("xmlSchemaValueGetAsBoolean__internal_alias"))); +#else +#ifndef xmlSchemaValueGetAsBoolean +extern __typeof (xmlSchemaValueGetAsBoolean) xmlSchemaValueGetAsBoolean__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaValueGetAsBoolean xmlSchemaValueGetAsBoolean__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaValueGetAsString +extern __typeof (xmlSchemaValueGetAsString) xmlSchemaValueGetAsString __attribute((alias("xmlSchemaValueGetAsString__internal_alias"))); +#else +#ifndef xmlSchemaValueGetAsString +extern __typeof (xmlSchemaValueGetAsString) xmlSchemaValueGetAsString__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaValueGetAsString xmlSchemaValueGetAsString__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlschemastypes +#undef xmlSchemaValueGetNext +extern __typeof (xmlSchemaValueGetNext) xmlSchemaValueGetNext __attribute((alias("xmlSchemaValueGetNext__internal_alias"))); +#else +#ifndef xmlSchemaValueGetNext +extern __typeof (xmlSchemaValueGetNext) xmlSchemaValueGetNext__internal_alias __attribute((visibility("hidden"))); +#define xmlSchemaValueGetNext xmlSchemaValueGetNext__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_SCHEMAS_ENABLED) #ifdef bottom_xmlschemastypes #undef xmlSchemaWhiteSpaceReplace @@ -9464,6 +10001,114 @@ extern __typeof (xmlSchemaWhiteSpaceReplace) xmlSchemaWhiteSpaceReplace__interna #endif #endif +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronFree +extern __typeof (xmlSchematronFree) xmlSchematronFree __attribute((alias("xmlSchematronFree__internal_alias"))); +#else +#ifndef xmlSchematronFree +extern __typeof (xmlSchematronFree) xmlSchematronFree__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronFree xmlSchematronFree__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronFreeParserCtxt +extern __typeof (xmlSchematronFreeParserCtxt) xmlSchematronFreeParserCtxt __attribute((alias("xmlSchematronFreeParserCtxt__internal_alias"))); +#else +#ifndef xmlSchematronFreeParserCtxt +extern __typeof (xmlSchematronFreeParserCtxt) xmlSchematronFreeParserCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronFreeParserCtxt xmlSchematronFreeParserCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronFreeValidCtxt +extern __typeof (xmlSchematronFreeValidCtxt) xmlSchematronFreeValidCtxt __attribute((alias("xmlSchematronFreeValidCtxt__internal_alias"))); +#else +#ifndef xmlSchematronFreeValidCtxt +extern __typeof (xmlSchematronFreeValidCtxt) xmlSchematronFreeValidCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronFreeValidCtxt xmlSchematronFreeValidCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronNewDocParserCtxt +extern __typeof (xmlSchematronNewDocParserCtxt) xmlSchematronNewDocParserCtxt __attribute((alias("xmlSchematronNewDocParserCtxt__internal_alias"))); +#else +#ifndef xmlSchematronNewDocParserCtxt +extern __typeof (xmlSchematronNewDocParserCtxt) xmlSchematronNewDocParserCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronNewDocParserCtxt xmlSchematronNewDocParserCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronNewMemParserCtxt +extern __typeof (xmlSchematronNewMemParserCtxt) xmlSchematronNewMemParserCtxt __attribute((alias("xmlSchematronNewMemParserCtxt__internal_alias"))); +#else +#ifndef xmlSchematronNewMemParserCtxt +extern __typeof (xmlSchematronNewMemParserCtxt) xmlSchematronNewMemParserCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronNewMemParserCtxt xmlSchematronNewMemParserCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronNewParserCtxt +extern __typeof (xmlSchematronNewParserCtxt) xmlSchematronNewParserCtxt __attribute((alias("xmlSchematronNewParserCtxt__internal_alias"))); +#else +#ifndef xmlSchematronNewParserCtxt +extern __typeof (xmlSchematronNewParserCtxt) xmlSchematronNewParserCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronNewParserCtxt xmlSchematronNewParserCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronNewValidCtxt +extern __typeof (xmlSchematronNewValidCtxt) xmlSchematronNewValidCtxt __attribute((alias("xmlSchematronNewValidCtxt__internal_alias"))); +#else +#ifndef xmlSchematronNewValidCtxt +extern __typeof (xmlSchematronNewValidCtxt) xmlSchematronNewValidCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronNewValidCtxt xmlSchematronNewValidCtxt__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronParse +extern __typeof (xmlSchematronParse) xmlSchematronParse __attribute((alias("xmlSchematronParse__internal_alias"))); +#else +#ifndef xmlSchematronParse +extern __typeof (xmlSchematronParse) xmlSchematronParse__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronParse xmlSchematronParse__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_SCHEMATRON_ENABLED) +#ifdef bottom_schematron +#undef xmlSchematronValidateDoc +extern __typeof (xmlSchematronValidateDoc) xmlSchematronValidateDoc __attribute((alias("xmlSchematronValidateDoc__internal_alias"))); +#else +#ifndef xmlSchematronValidateDoc +extern __typeof (xmlSchematronValidateDoc) xmlSchematronValidateDoc__internal_alias __attribute((visibility("hidden"))); +#define xmlSchematronValidateDoc xmlSchematronValidateDoc__internal_alias +#endif +#endif +#endif + #ifdef bottom_tree #undef xmlSearchNs extern __typeof (xmlSearchNs) xmlSearchNs __attribute((alias("xmlSearchNs__internal_alias"))); @@ -9864,7 +10509,6 @@ extern __typeof (xmlSprintfElementContent) xmlSprintfElementContent__internal_al #endif #endif -#if defined(LIBXML_PUSH_ENABLED) #ifdef bottom_parser #undef xmlStopParser extern __typeof (xmlStopParser) xmlStopParser __attribute((alias("xmlStopParser__internal_alias"))); @@ -9874,7 +10518,6 @@ extern __typeof (xmlStopParser) xmlStopParser__internal_alias __attribute((visib #define xmlStopParser xmlStopParser__internal_alias #endif #endif -#endif #ifdef bottom_xmlstring #undef xmlStrEqual @@ -10012,6 +10655,30 @@ extern __typeof (xmlStreamPushAttr) xmlStreamPushAttr__internal_alias __attribut #endif #endif +#if defined(LIBXML_PATTERN_ENABLED) +#ifdef bottom_pattern +#undef xmlStreamPushNode +extern __typeof (xmlStreamPushNode) xmlStreamPushNode __attribute((alias("xmlStreamPushNode__internal_alias"))); +#else +#ifndef xmlStreamPushNode +extern __typeof (xmlStreamPushNode) xmlStreamPushNode__internal_alias __attribute((visibility("hidden"))); +#define xmlStreamPushNode xmlStreamPushNode__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_PATTERN_ENABLED) +#ifdef bottom_pattern +#undef xmlStreamWantsAnyNode +extern __typeof (xmlStreamWantsAnyNode) xmlStreamWantsAnyNode __attribute((alias("xmlStreamWantsAnyNode__internal_alias"))); +#else +#ifndef xmlStreamWantsAnyNode +extern __typeof (xmlStreamWantsAnyNode) xmlStreamWantsAnyNode__internal_alias __attribute((visibility("hidden"))); +#define xmlStreamWantsAnyNode xmlStreamWantsAnyNode__internal_alias +#endif +#endif +#endif + #ifdef bottom_parserInternals #undef xmlStringCurrentChar extern __typeof (xmlStringCurrentChar) xmlStringCurrentChar __attribute((alias("xmlStringCurrentChar__internal_alias"))); @@ -10850,7 +11517,7 @@ extern __typeof (xmlTextReaderReadAttributeValue) xmlTextReaderReadAttributeValu #endif #endif -#if defined(LIBXML_READER_ENABLED) +#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_WRITER_ENABLED) #ifdef bottom_xmlreader #undef xmlTextReaderReadInnerXml extern __typeof (xmlTextReaderReadInnerXml) xmlTextReaderReadInnerXml __attribute((alias("xmlTextReaderReadInnerXml__internal_alias"))); @@ -10862,7 +11529,7 @@ extern __typeof (xmlTextReaderReadInnerXml) xmlTextReaderReadInnerXml__internal_ #endif #endif -#if defined(LIBXML_READER_ENABLED) +#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_WRITER_ENABLED) #ifdef bottom_xmlreader #undef xmlTextReaderReadOuterXml extern __typeof (xmlTextReaderReadOuterXml) xmlTextReaderReadOuterXml __attribute((alias("xmlTextReaderReadOuterXml__internal_alias"))); @@ -10922,6 +11589,30 @@ extern __typeof (xmlTextReaderRelaxNGValidate) xmlTextReaderRelaxNGValidate__int #endif #endif +#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlreader +#undef xmlTextReaderSchemaValidate +extern __typeof (xmlTextReaderSchemaValidate) xmlTextReaderSchemaValidate __attribute((alias("xmlTextReaderSchemaValidate__internal_alias"))); +#else +#ifndef xmlTextReaderSchemaValidate +extern __typeof (xmlTextReaderSchemaValidate) xmlTextReaderSchemaValidate__internal_alias __attribute((visibility("hidden"))); +#define xmlTextReaderSchemaValidate xmlTextReaderSchemaValidate__internal_alias +#endif +#endif +#endif + +#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlreader +#undef xmlTextReaderSchemaValidateCtxt +extern __typeof (xmlTextReaderSchemaValidateCtxt) xmlTextReaderSchemaValidateCtxt __attribute((alias("xmlTextReaderSchemaValidateCtxt__internal_alias"))); +#else +#ifndef xmlTextReaderSchemaValidateCtxt +extern __typeof (xmlTextReaderSchemaValidateCtxt) xmlTextReaderSchemaValidateCtxt__internal_alias __attribute((visibility("hidden"))); +#define xmlTextReaderSchemaValidateCtxt xmlTextReaderSchemaValidateCtxt__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_READER_ENABLED) #ifdef bottom_xmlreader #undef xmlTextReaderSetErrorHandler @@ -10946,6 +11637,18 @@ extern __typeof (xmlTextReaderSetParserProp) xmlTextReaderSetParserProp__interna #endif #endif +#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_SCHEMAS_ENABLED) +#ifdef bottom_xmlreader +#undef xmlTextReaderSetSchema +extern __typeof (xmlTextReaderSetSchema) xmlTextReaderSetSchema __attribute((alias("xmlTextReaderSetSchema__internal_alias"))); +#else +#ifndef xmlTextReaderSetSchema +extern __typeof (xmlTextReaderSetSchema) xmlTextReaderSetSchema__internal_alias __attribute((visibility("hidden"))); +#define xmlTextReaderSetSchema xmlTextReaderSetSchema__internal_alias +#endif +#endif +#endif + #if defined(LIBXML_READER_ENABLED) #ifdef bottom_xmlreader #undef xmlTextReaderSetStructuredErrorHandler @@ -14350,7 +15053,7 @@ extern __typeof (xmlValidateElementDecl) xmlValidateElementDecl__internal_alias #endif #endif -#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) #ifdef bottom_tree #undef xmlValidateNCName extern __typeof (xmlValidateNCName) xmlValidateNCName __attribute((alias("xmlValidateNCName__internal_alias"))); diff --git a/Extras/LibXML/encoding.c b/Extras/LibXML/encoding.c index e1b2f1a72..6dee212e7 100644 --- a/Extras/LibXML/encoding.c +++ b/Extras/LibXML/encoding.c @@ -70,6 +70,32 @@ static void xmlRegisterCharEncodingHandlersISO8859x (void); static int xmlLittleEndian = 1; +/** + * xmlEncodingErrMemory: + * @extra: extra informations + * + * Handle an out of memory condition + */ +static void +xmlEncodingErrMemory(const char *extra) +{ + __xmlSimpleError(XML_FROM_I18N, XML_ERR_NO_MEMORY, NULL, NULL, extra); +} + +/** + * xmlErrEncoding: + * @error: the error number + * @msg: the error message + * + * n encoding error + */ +static void +xmlEncodingErr(xmlParserErrors error, const char *msg, const char *val) +{ + __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, + XML_FROM_I18N, error, XML_ERR_FATAL, + NULL, 0, val, NULL, NULL, 0, 0, msg, val); +} /************************************************************************ * * @@ -91,36 +117,30 @@ static int xmlLittleEndian = 1; * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -static intptr_t -asciiToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +static int +asciiToUTF8(unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { unsigned char* outstart = out; const unsigned char* base = in; const unsigned char* processed = in; unsigned char* outend = out + *outlen; const unsigned char* inend; unsigned int c; - int bits; inend = in + (*inlen); while ((in < inend) && (out - outstart + 5 < *outlen)) { c= *in++; - /* assertion: c is a single UTF-4 value */ if (out >= outend) break; - if (c < 0x80) { *out++= c; bits= -6; } - else { + if (c < 0x80) { + *out++ = c; + } else { *outlen = out - outstart; *inlen = processed - base; return(-1); } - for ( ; bits >= 0; bits-= 6) { - if (out >= outend) - break; - *out++= ((c >> bits) & 0x3F) | 0x80; - } processed = (const unsigned char*) in; } *outlen = out - outstart; @@ -144,9 +164,9 @@ asciiToUTF8(unsigned char* out, intptr_t* outlen, * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -static intptr_t -UTF8Toascii(unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +static int +UTF8Toascii(unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { const unsigned char* processed = in; const unsigned char* outend; const unsigned char* outstart = out; @@ -228,9 +248,9 @@ UTF8Toascii(unsigned char* out, intptr_t* outlen, * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -intptr_t -isolat1ToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +int +isolat1ToUTF8(unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { unsigned char* outstart = out; const unsigned char* base = in; unsigned char* outend; @@ -276,11 +296,11 @@ isolat1ToUTF8(unsigned char* out, intptr_t* outlen, * The value of *inlen after return is the number of octets consumed * if the return value is positive, else unpredictable. */ -static intptr_t -UTF8ToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* inb, intptr_t* inlenb) +static int +UTF8ToUTF8(unsigned char* out, int *outlen, + const unsigned char* inb, int *inlenb) { - intptr_t len; + int len; if ((out == NULL) || (inb == NULL) || (outlen == NULL) || (inlenb == NULL)) return(-1); @@ -317,9 +337,9 @@ UTF8ToUTF8(unsigned char* out, intptr_t* outlen, * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -intptr_t -UTF8Toisolat1(unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +int +UTF8Toisolat1(unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { const unsigned char* processed = in; const unsigned char* outend; const unsigned char* outstart = out; @@ -409,17 +429,16 @@ UTF8Toisolat1(unsigned char* out, intptr_t* outlen, * The value of *inlen after return is the number of octets consumed * if the return value is positive, else unpredictable. */ -static intptr_t -UTF16LEToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* inb, intptr_t* inlenb) +static int +UTF16LEToUTF8(unsigned char* out, int *outlen, + const unsigned char* inb, int *inlenb) { unsigned char* outstart = out; const unsigned char* processed = inb; unsigned char* outend = out + *outlen; unsigned short* in = (unsigned short*) inb; unsigned short* inend; - unsigned int c, d; - size_t inlen; + unsigned int c, d, inlen; unsigned char *tmp; int bits; @@ -495,18 +514,18 @@ UTF16LEToUTF8(unsigned char* out, intptr_t* outlen, * Returns the number of bytes written, or -1 if lack of space, or -2 * if the transcoding failed. */ -static intptr_t -UTF8ToUTF16LE(unsigned char* outb, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) +static int +UTF8ToUTF16LE(unsigned char* outb, int *outlen, + const unsigned char* in, int *inlen) { unsigned short* out = (unsigned short*) outb; const unsigned char* processed = in; const unsigned char *const instart = in; unsigned short* outstart= out; unsigned short* outend; - const unsigned char* inend= in+*inlen; + const unsigned char* inend; unsigned int c, d; - intptr_t trailing; + int trailing; unsigned char *tmp; unsigned short tmp1, tmp2; @@ -517,6 +536,7 @@ UTF8ToUTF16LE(unsigned char* outb, intptr_t* outlen, *inlen = 0; return(0); } + inend= in + *inlen; outend = out + (*outlen / 2); while (in < inend) { d= *in++; @@ -603,9 +623,9 @@ UTF8ToUTF16LE(unsigned char* outb, intptr_t* outlen, * Returns the number of bytes written, or -1 if lack of space, or -2 * if the transcoding failed. */ -static intptr_t -UTF8ToUTF16(unsigned char* outb, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) +static int +UTF8ToUTF16(unsigned char* outb, int *outlen, + const unsigned char* in, int *inlen) { if (in == NULL) { /* @@ -647,17 +667,16 @@ UTF8ToUTF16(unsigned char* outb, intptr_t* outlen, * The value of *inlen after return is the number of octets consumed * if the return value is positive, else unpredictable. */ -static intptr_t -UTF16BEToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* inb, intptr_t* inlenb) +static int +UTF16BEToUTF8(unsigned char* out, int *outlen, + const unsigned char* inb, int *inlenb) { unsigned char* outstart = out; const unsigned char* processed = inb; unsigned char* outend = out + *outlen; unsigned short* in = (unsigned short*) inb; unsigned short* inend; - unsigned int c, d; - size_t inlen; + unsigned int c, d, inlen; unsigned char *tmp; int bits; @@ -737,18 +756,18 @@ UTF16BEToUTF8(unsigned char* out, intptr_t* outlen, * Returns the number of byte written, or -1 by lack of space, or -2 * if the transcoding failed. */ -static intptr_t -UTF8ToUTF16BE(unsigned char* outb, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) +static int +UTF8ToUTF16BE(unsigned char* outb, int *outlen, + const unsigned char* in, int *inlen) { unsigned short* out = (unsigned short*) outb; const unsigned char* processed = in; const unsigned char *const instart = in; unsigned short* outstart= out; unsigned short* outend; - const unsigned char* inend= in+*inlen; + const unsigned char* inend; unsigned int c, d; - intptr_t trailing; + int trailing; unsigned char *tmp; unsigned short tmp1, tmp2; @@ -759,6 +778,7 @@ UTF8ToUTF16BE(unsigned char* outb, intptr_t* outlen, *inlen = 0; return(0); } + inend= in + *inlen; outend = out + (*outlen / 2); while (in < inend) { d= *in++; @@ -848,7 +868,7 @@ UTF8ToUTF16BE(unsigned char* outb, intptr_t* outlen, * Returns one of the XML_CHAR_ENCODING_... values. */ xmlCharEncoding -xmlDetectCharEncoding(const unsigned char* in, intptr_t len) +xmlDetectCharEncoding(const unsigned char* in, int len) { if (in == NULL) return(XML_CHAR_ENCODING_NONE); @@ -1241,7 +1261,7 @@ xmlNewCharEncodingHandler(const char *name, const char *alias; char upper[500]; int i; - char *up = 0; + char *up = NULL; /* * Do the alias resolution @@ -1254,8 +1274,8 @@ xmlNewCharEncodingHandler(const char *name, * Keep only the uppercase version of the encoding. */ if (name == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : no name !\n"); + xmlEncodingErr(XML_I18N_NO_NAME, + "xmlNewCharEncodingHandler : no name !\n", NULL); return(NULL); } for (i = 0;i < 499;i++) { @@ -1265,8 +1285,7 @@ xmlNewCharEncodingHandler(const char *name, upper[i] = 0; up = xmlMemStrdup(upper); if (up == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : out of memory !\n"); + xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n"); return(NULL); } @@ -1277,8 +1296,7 @@ xmlNewCharEncodingHandler(const char *name, xmlMalloc(sizeof(xmlCharEncodingHandler)); if (handler == NULL) { xmlFree(up); - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : out of memory !\n"); + xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n"); return(NULL); } handler->input = input; @@ -1321,12 +1339,13 @@ xmlInitCharEncodingHandlers(void) { if (*ptr == 0x12) xmlLittleEndian = 0; else if (*ptr == 0x34) xmlLittleEndian = 1; - else xmlGenericError(xmlGenericErrorContext, - "Odd problem at endianness detection\n"); + else { + xmlEncodingErr(XML_ERR_INTERNAL_ERROR, + "Odd problem at endianness detection\n", NULL); + } if (handlers == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlInitCharEncodingHandlers : out of memory !\n"); + xmlEncodingErrMemory("xmlInitCharEncodingHandlers : out of memory !\n"); return; } xmlNewCharEncodingHandler("UTF-8", UTF8ToUTF8, UTF8ToUTF8); @@ -1396,16 +1415,15 @@ void xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) { if (handlers == NULL) xmlInitCharEncodingHandlers(); if (handler == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlRegisterCharEncodingHandler: NULL handler !\n"); + xmlEncodingErr(XML_I18N_NO_HANDLER, + "xmlRegisterCharEncodingHandler: NULL handler !\n", NULL); return; } if (nbCharEncodingHandler >= MAX_ENCODING_HANDLERS) { - xmlGenericError(xmlGenericErrorContext, - "xmlRegisterCharEncodingHandler: Too many handler registered\n"); - xmlGenericError(xmlGenericErrorContext, - "\tincrease MAX_ENCODING_HANDLERS : %s\n", __FILE__); + xmlEncodingErr(XML_I18N_EXCESS_HANDLER, + "xmlRegisterCharEncodingHandler: Too many handler registered, see %s\n", + "MAX_ENCODING_HANDLERS"); return; } handlers[nbCharEncodingHandler++] = handler; @@ -1614,7 +1632,7 @@ xmlFindCharEncodingHandler(const char *name) { #endif return enc; } else if ((icv_in != (iconv_t) -1) || icv_out != (iconv_t) -1) { - xmlGenericError(xmlGenericErrorContext, + xmlEncodingErr(XML_ERR_INTERNAL_ERROR, "iconv : problems with filters for '%s'\n", name); } #endif /* LIBXML_ICONV_ENABLED */ @@ -1665,9 +1683,9 @@ xmlFindCharEncodingHandler(const char *name) { * as the return value is positive, else unpredictable. * The value of @outlen after return is the number of ocetes consumed. */ -static intptr_t -xmlIconvWrapper(iconv_t cd, unsigned char *out, intptr_t* outlen, - const unsigned char *in, intptr_t* inlen) { +static int +xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen, + const unsigned char *in, int *inlen) { size_t icv_inlen, icv_outlen; const char *icv_in = (const char *) in; char *icv_out = (char *) out; @@ -1680,13 +1698,8 @@ xmlIconvWrapper(iconv_t cd, unsigned char *out, intptr_t* outlen, icv_inlen = *inlen; icv_outlen = *outlen; ret = iconv(cd, (char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen); - if (in != NULL) { - *inlen -= icv_inlen; - *outlen -= icv_outlen; - } else { - *inlen = 0; - *outlen = 0; - } + *inlen -= icv_inlen; + *outlen -= icv_outlen; if ((icv_inlen != 0) || (ret == -1)) { #ifdef EILSEQ if (errno == EILSEQ) { @@ -1731,12 +1744,12 @@ xmlIconvWrapper(iconv_t cd, unsigned char *out, intptr_t* outlen, * -2 if the transcoding fails (for *in is not valid utf8 string or * the result of transformation can't fit into the encoding we want), or */ -intptr_t +int xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in) { - intptr_t ret = -2; - intptr_t written; - intptr_t toconv; + int ret = -2; + int written; + int toconv; if (handler == NULL) return(-1); if (out == NULL) return(-1); @@ -1817,13 +1830,13 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out, * -2 if the transcoding fails (for *in is not valid utf8 string or * the result of transformation can't fit into the encoding we want), or */ -intptr_t +int xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out, xmlBufferPtr in) { - intptr_t ret = -2; - intptr_t written; - intptr_t toconv; + int ret = -2; + int written; + int toconv; if (handler == NULL) return (-1); @@ -1880,20 +1893,24 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out, toconv, written, in->use); #endif break; - case -2: - xmlGenericError(xmlGenericErrorContext, - "input conversion failed due to input error\n"); - xmlGenericError(xmlGenericErrorContext, - "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", - in->content[0], in->content[1], - in->content[2], in->content[3]); + case -2: { + char buf[50]; + + snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X", + in->content[0], in->content[1], + in->content[2], in->content[3]); + buf[49] = 0; + xmlEncodingErr(XML_I18N_CONV_FAILED, + "input conversion failed due to input error, bytes %s\n", + buf); + } } /* * Ignore when input buffer is not on a boundary */ if (ret == -3) ret = 0; - return (written); + return (written? written : ret); } /** @@ -1917,11 +1934,11 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out, int xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in) { - intptr_t ret = -2; - intptr_t written; - intptr_t writtentot = 0; - intptr_t toconv; - intptr_t output = 0; + int ret = -2; + int written; + int writtentot = 0; + int toconv; + int output = 0; if (handler == NULL) return(-1); if (out == NULL) return(-1); @@ -1999,8 +2016,8 @@ retry: } #endif /* LIBXML_ICONV_ENABLED */ else { - xmlGenericError(xmlGenericErrorContext, - "xmlCharEncOutFunc: no output function !\n"); + xmlEncodingErr(XML_I18N_NO_OUTPUT, + "xmlCharEncOutFunc: no output function !\n", NULL); return(-1); } @@ -2030,9 +2047,9 @@ retry: #endif break; case -2: { - intptr_t len = in->use; + int len = in->use; const xmlChar *utf = (const xmlChar *) in->content; - intptr_t cur; + int cur; cur = xmlGetUTF8Char(utf, &len); if (cur > 0) { @@ -2051,19 +2068,23 @@ retry: * and continue the transcoding phase, hoping the error * did not mangle the encoder state. */ - snprintf((char *) charref, sizeof(charref), "&#%d;", cur); + snprintf((char *) &charref[0], sizeof(charref), "&#%d;", cur); xmlBufferShrink(in, len); xmlBufferAddHead(in, charref, -1); goto retry; } else { - xmlGenericError(xmlGenericErrorContext, - "output conversion failed due to conv error\n"); - xmlGenericError(xmlGenericErrorContext, - "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", - in->content[0], in->content[1], - in->content[2], in->content[3]); - in->content[0] = ' '; + char buf[50]; + + snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X", + in->content[0], in->content[1], + in->content[2], in->content[3]); + buf[49] = 0; + xmlEncodingErr(XML_I18N_CONV_FAILED, + "output conversion failed due to conv error, bytes %s\n", + buf); + if (in->alloc != XML_BUFFER_ALLOC_IMMUTABLE) + in->content[0] = ' '; } break; } @@ -2132,7 +2153,7 @@ xmlCharEncCloseFunc(xmlCharEncodingHandler *handler) { * Returns the index in bytes from the beginning of the entity or -1 * in case the index could not be computed. */ -intptr_t +long xmlByteConsumed(xmlParserCtxtPtr ctxt) { xmlParserInputPtr in; @@ -2140,7 +2161,7 @@ xmlByteConsumed(xmlParserCtxtPtr ctxt) { in = ctxt->input; if (in == NULL) return(-1); if ((in->buf != NULL) && (in->buf->encoder != NULL)) { - size_t unused = 0; + unsigned int unused = 0; xmlCharEncodingHandler * handler = in->buf->encoder; /* * Encoding conversion, compute the number of unused original @@ -2150,9 +2171,9 @@ xmlByteConsumed(xmlParserCtxtPtr ctxt) { if (in->end - in->cur > 0) { unsigned char convbuf[32000]; const unsigned char *cur = (const unsigned char *)in->cur; - intptr_t toconv = in->end - in->cur, written = 32000; + int toconv = in->end - in->cur, written = 32000; - intptr_t ret; + int ret; if (handler->output != NULL) { do { @@ -2327,8 +2348,8 @@ UTF8ToISO8859x(unsigned char* out, int *outlen, * The value of @outlen after return is the number of ocetes produced. */ static int -ISO8859xToUTF8(unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen, +ISO8859xToUTF8(unsigned char* out, int *outlen, + const unsigned char* in, int *inlen, unsigned short const *unicodetable) { unsigned char* outstart = out; unsigned char* outend; @@ -3116,129 +3137,129 @@ static unsigned char const xmltranscodetable_ISO8859_16 [48 + 9 * 64] = { * auto-generated functions for ISO-8859-2 .. ISO-8859-16 */ -static intptr_t ISO8859_2ToUTF8 (unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +static int ISO8859_2ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_2); } -static intptr_t UTF8ToISO8859_2 (unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +static int UTF8ToISO8859_2 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_2); } -static intptr_t ISO8859_3ToUTF8 (unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t* inlen) { +static int ISO8859_3ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_3); } -static intptr_t UTF8ToISO8859_3 (unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_3 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_3); } -static intptr_t ISO8859_4ToUTF8 (unsigned char* out, intptr_t* outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_4ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_4); } -static intptr_t UTF8ToISO8859_4 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_4 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_4); } -static intptr_t ISO8859_5ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_5ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_5); } -static intptr_t UTF8ToISO8859_5 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_5 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_5); } -static intptr_t ISO8859_6ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_6ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_6); } -static intptr_t UTF8ToISO8859_6 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_6 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_6); } -static intptr_t ISO8859_7ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_7ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_7); } -static intptr_t UTF8ToISO8859_7 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_7 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_7); } -static intptr_t ISO8859_8ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_8ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_8); } -static intptr_t UTF8ToISO8859_8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_8); } -static intptr_t ISO8859_9ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_9ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_9); } -static intptr_t UTF8ToISO8859_9 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_9 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_9); } -static intptr_t ISO8859_10ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_10ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_10); } -static intptr_t UTF8ToISO8859_10 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_10 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_10); } -static intptr_t ISO8859_11ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_11ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_11); } -static intptr_t UTF8ToISO8859_11 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_11 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_11); } -static intptr_t ISO8859_13ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_13ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_13); } -static intptr_t UTF8ToISO8859_13 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_13 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_13); } -static intptr_t ISO8859_14ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_14ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_14); } -static intptr_t UTF8ToISO8859_14 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_14 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_14); } -static intptr_t ISO8859_15ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_15ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_15); } -static intptr_t UTF8ToISO8859_15 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_15 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_15); } -static intptr_t ISO8859_16ToUTF8 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int ISO8859_16ToUTF8 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return ISO8859xToUTF8 (out, outlen, in, inlen, xmlunicodetable_ISO8859_16); } -static intptr_t UTF8ToISO8859_16 (unsigned char* out, intptr_t *outlen, - const unsigned char* in, intptr_t *inlen) { +static int UTF8ToISO8859_16 (unsigned char* out, int *outlen, + const unsigned char* in, int *inlen) { return UTF8ToISO8859x (out, outlen, in, inlen, xmltranscodetable_ISO8859_16); } diff --git a/Extras/LibXML/entities.c b/Extras/LibXML/entities.c index 3f8aef7a5..6a0e38d7e 100644 --- a/Extras/LibXML/entities.c +++ b/Extras/LibXML/entities.c @@ -518,7 +518,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { while (*cur != '\0') { if (out - buffer > buffer_size - 100) { - intptr_t indx = out - buffer; + int indx = out - buffer; growBufferReentrant(); out = &buffer[indx]; @@ -560,7 +560,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { *out++ = xc; } else */ - *out++ = *cur; + *out++ = *cur; } else { /* * We assume we have UTF-8 input. @@ -616,10 +616,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { /* * We could do multiple things here. Just save as a char ref */ - if (html) - snprintf(buf, sizeof(buf), "&#%d;", val); - else - snprintf(buf, sizeof(buf), "&#x%X;", val); + snprintf(buf, sizeof(buf), "&#x%X;", val); buf[sizeof(buf) - 1] = 0; ptr = buf; while (*ptr != 0) *out++ = *ptr++; @@ -671,7 +668,7 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) { while (*cur != '\0') { if (out - buffer > buffer_size - 10) { - intptr_t indx = out - buffer; + int indx = out - buffer; growBufferReentrant(); out = &buffer[indx]; diff --git a/Extras/LibXML/error.c b/Extras/LibXML/error.c index fb1371def..722ffbb5b 100644 --- a/Extras/LibXML/error.c +++ b/Extras/LibXML/error.c @@ -16,12 +16,12 @@ #include #include -void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, +void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...); #define XML_GET_VAR_STR(msg, str) { \ - int size; \ + int size, prev_size = -1; \ int chars; \ char *larger; \ va_list ap; \ @@ -35,8 +35,13 @@ void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, va_start(ap, msg); \ chars = vsnprintf(str, size, msg, ap); \ va_end(ap); \ - if ((chars > -1) && (chars < size)) \ - break; \ + if ((chars > -1) && (chars < size)) { \ + if (prev_size == chars) { \ + break; \ + } else { \ + prev_size = chars; \ + } \ + } \ if (chars > -1) \ size += chars + 1; \ else \ @@ -62,7 +67,7 @@ void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, * * Default handler for out of context error messages. */ -void +void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { va_list args; @@ -168,7 +173,7 @@ static void xmlParserPrintFileContextInternal(xmlParserInputPtr input , xmlGenericErrorFunc channel, void *data ) { const xmlChar *cur, *base; - size_t n, col; /* GCC warns if signed, because compared with sizeof() */ + unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */ xmlChar content[81]; /* space for 80 chars + line terminator */ xmlChar *ctnt; @@ -293,8 +298,6 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, if (name != NULL) { channel(data, "element %s: ", name); } - if (code == XML_ERR_OK) - return; switch (domain) { case XML_FROM_PARSER: channel(data, "parser "); @@ -354,11 +357,12 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, case XML_FROM_XSLT: channel(data, "XSLT "); break; + case XML_FROM_I18N: + channel(data, "encoding "); + break; default: break; } - if (code == XML_ERR_OK) - return; switch (level) { case XML_ERR_NONE: channel(data, ": "); @@ -373,11 +377,9 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, channel(data, "error : "); break; } - if (code == XML_ERR_OK) - return; if (str != NULL) { - intptr_t len; - len = xmlStrlen((const xmlChar *)str); + int len; + len = xmlStrlen((const xmlChar *)str); if ((len > 0) && (str[len - 1] != '\n')) channel(data, "%s\n", str); else @@ -385,8 +387,6 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, } else { channel(data, "%s\n", "out of memory error"); } - if (code == XML_ERR_OK) - return; if (ctxt != NULL) { xmlParserPrintFileContextInternal(input, channel, data); @@ -437,12 +437,12 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, * then forward the error message down the parser or generic * error callback handler */ -void +void XMLCDECL __xmlRaiseError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, void *data, void *ctx, void *nod, int domain, int code, xmlErrorLevel level, const char *file, int line, const char *str1, - const char *str2, const char *str3, int int1, intptr_t col, + const char *str2, const char *str3, int int1, int col, const char *msg, ...) { xmlParserCtxtPtr ctxt = NULL; @@ -512,8 +512,10 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, } else if ((node != NULL) && (file == NULL)) { int i; - if ((node->doc != NULL) && (node->doc->URL != NULL)) + if ((node->doc != NULL) && (node->doc->URL != NULL)) { baseptr = node; +/* file = (const char *) node->doc->URL; */ + } for (i = 0; ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE)); i++) @@ -558,10 +560,19 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, } } if (prev != NULL) { - to->file = (char *) xmlGetProp(prev, BAD_CAST "href"); + if (prev->type == XML_XINCLUDE_START) { + prev->type = XML_ELEMENT_NODE; + to->file = (char *) xmlGetProp(prev, BAD_CAST "href"); + prev->type = XML_XINCLUDE_START; + } else { + to->file = (char *) xmlGetProp(prev, BAD_CAST "href"); + } } else #endif to->file = (char *) xmlStrdup(baseptr->doc->URL); + if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) { + to->file = (char *) xmlStrdup(node->doc->URL); + } file = to->file; } to->line = line; @@ -593,8 +604,10 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, schannel = xmlStructuredError; else channel = xmlGenericError; + if (!data) { data = xmlGenericErrorContext; } + } if (schannel != NULL) { schannel(data, to); return; @@ -653,7 +666,7 @@ __xmlSimpleError(int domain, int code, xmlNodePtr node, * Display and format an error messages, gives file, line, position and * extra parameters. */ -void +void XMLCDECL xmlParserError(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -696,7 +709,7 @@ xmlParserError(void *ctx, const char *msg, ...) * Display and format a warning messages, gives file, line, position and * extra parameters. */ -void +void XMLCDECL xmlParserWarning(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; @@ -745,13 +758,13 @@ xmlParserWarning(void *ctx, const char *msg, ...) * Display and format an validity error messages, gives file, * line, position and extra parameters. */ -void +void XMLCDECL xmlParserValidityError(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; - intptr_t len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlen((const xmlChar *) msg); static int had_info = 0; if ((len > 1) && (msg[len - 2] != ':')) { @@ -789,13 +802,13 @@ xmlParserValidityError(void *ctx, const char *msg, ...) * Display and format a validity warning messages, gives file, line, * position and extra parameters. */ -void +void XMLCDECL xmlParserValidityWarning(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; - intptr_t len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlen((const xmlChar *) msg); if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { input = ctxt->input; diff --git a/Extras/LibXML/globals.c b/Extras/LibXML/globals.c index 4a002d389..c104a1ab8 100644 --- a/Extras/LibXML/globals.c +++ b/Extras/LibXML/globals.c @@ -44,7 +44,7 @@ static xmlMutexPtr xmlThrDefMutex = NULL; * * Additional initialisation for multi-threading */ -void xmlInitGlobals() +void xmlInitGlobals(void) { xmlThrDefMutex = xmlNewMutex(); } @@ -54,7 +54,7 @@ void xmlInitGlobals() * * Additional cleanup for multi-threading */ -void xmlCleanupGlobals() +void xmlCleanupGlobals(void) { if (xmlThrDefMutex != NULL) { xmlFreeMutex(xmlThrDefMutex); @@ -289,7 +289,7 @@ static xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValueThrDe /* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */ /* Must initialize xmlGenericError in xmlInitParser */ -void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, +void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...); /** @@ -344,7 +344,7 @@ static const char *xmlTreeIndentStringThrDef = " "; * Disabled by default */ int xmlSaveNoEmptyTags = 0; -int xmlSaveNoEmptyTagsThrDef = 0; +static int xmlSaveNoEmptyTagsThrDef = 0; #ifdef LIBXML_SAX1_ENABLED /** @@ -496,10 +496,10 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs) xmlMutexLock(xmlThrDefMutex); -#ifdef LIBXML_DOCB_ENABLED +#if defined(LIBXML_DOCB_ENABLED) && defined(LIBXML_LEGACY_ENABLED) && defined(LIBXML_SAX1_ENABLED) initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler); #endif -#ifdef LIBXML_HTML_ENABLED +#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_LEGACY_ENABLED) inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler); #endif diff --git a/Extras/LibXML/include/Makefile.in b/Extras/LibXML/include/Makefile.in index 9371f6409..9e3071db0 100644 --- a/Extras/LibXML/include/Makefile.in +++ b/Extras/LibXML/include/Makefile.in @@ -1,8 +1,8 @@ -# Makefile.in generated by automake 1.9.2 from Makefile.am. +# Makefile.in generated by automake 1.9.6 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004 Free Software Foundation, Inc. +# 2003, 2004, 2005 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -67,6 +67,7 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BASE_THREAD_LIBS = @BASE_THREAD_LIBS@ C14N_OBJ = @C14N_OBJ@ CATALOG_OBJ = @CATALOG_OBJ@ CC = @CC@ @@ -160,6 +161,7 @@ TEST_PUSH = @TEST_PUSH@ TEST_REGEXPS = @TEST_REGEXPS@ TEST_SAX = @TEST_SAX@ TEST_SCHEMAS = @TEST_SCHEMAS@ +TEST_SCHEMATRON = @TEST_SCHEMATRON@ TEST_THREADS = @TEST_THREADS@ TEST_VALID = @TEST_VALID@ TEST_VTIME = @TEST_VTIME@ @@ -195,6 +197,7 @@ WITH_REGEXPS = @WITH_REGEXPS@ WITH_RUN_DEBUG = @WITH_RUN_DEBUG@ WITH_SAX1 = @WITH_SAX1@ WITH_SCHEMAS = @WITH_SCHEMAS@ +WITH_SCHEMATRON = @WITH_SCHEMATRON@ WITH_THREADS = @WITH_THREADS@ WITH_TREE = @WITH_TREE@ WITH_TRIO = @WITH_TRIO@ @@ -316,7 +319,13 @@ uninstall-info-am: # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. $(RECURSIVE_TARGETS): - @set fnord $$MAKEFLAGS; amf=$$2; \ + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ list='$(SUBDIRS)'; for subdir in $$list; do \ @@ -328,7 +337,7 @@ $(RECURSIVE_TARGETS): local_target="$$target"; \ fi; \ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ @@ -336,7 +345,13 @@ $(RECURSIVE_TARGETS): mostlyclean-recursive clean-recursive distclean-recursive \ maintainer-clean-recursive: - @set fnord $$MAKEFLAGS; amf=$$2; \ + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ dot_seen=no; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ @@ -357,7 +372,7 @@ maintainer-clean-recursive: local_target="$$target"; \ fi; \ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + || eval $$failcom; \ done && test -z "$$fail" tags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ diff --git a/Extras/LibXML/include/libxml/HTMLparser.h b/Extras/LibXML/include/libxml/HTMLparser.h index 2604d8600..8477efbb7 100644 --- a/Extras/LibXML/include/libxml/HTMLparser.h +++ b/Extras/LibXML/include/libxml/HTMLparser.h @@ -173,11 +173,13 @@ XMLPUBFUN void XMLCALL * to the xmlReadDoc() and similar calls. */ typedef enum { + HTML_PARSE_RECOVER = 1<<0, /* Relaxed parsing */ HTML_PARSE_NOERROR = 1<<5, /* suppress error reports */ HTML_PARSE_NOWARNING= 1<<6, /* suppress warning reports */ HTML_PARSE_PEDANTIC = 1<<7, /* pedantic error reporting */ HTML_PARSE_NOBLANKS = 1<<8, /* remove blank nodes */ - HTML_PARSE_NONET = 1<<11 /* Forbid network access */ + HTML_PARSE_NONET = 1<<11,/* Forbid network access */ + HTML_PARSE_COMPACT = 1<<16 /* compact small text nodes */ } htmlParserOption; XMLPUBFUN void XMLCALL diff --git a/Extras/LibXML/include/libxml/HTMLtree.h b/Extras/LibXML/include/libxml/HTMLtree.h index 50b85442e..6ea820789 100644 --- a/Extras/LibXML/include/libxml/HTMLtree.h +++ b/Extras/LibXML/include/libxml/HTMLtree.h @@ -75,6 +75,11 @@ XMLPUBFUN void XMLCALL htmlDocDumpMemory (xmlDocPtr cur, xmlChar **mem, int *size); +XMLPUBFUN void XMLCALL + htmlDocDumpMemoryFormat (xmlDocPtr cur, + xmlChar **mem, + int *size, + int format); XMLPUBFUN int XMLCALL htmlDocDump (FILE *f, xmlDocPtr cur); diff --git a/Extras/LibXML/include/libxml/SAX2.h b/Extras/LibXML/include/libxml/SAX2.h index 2041e902e..8d2db02d8 100644 --- a/Extras/LibXML/include/libxml/SAX2.h +++ b/Extras/LibXML/include/libxml/SAX2.h @@ -29,9 +29,9 @@ XMLPUBFUN void XMLCALL xmlSAX2SetDocumentLocator (void *ctx, xmlSAXLocatorPtr loc); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSAX2GetLineNumber (void *ctx); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSAX2GetColumnNumber (void *ctx); XMLPUBFUN int XMLCALL @@ -98,7 +98,7 @@ XMLPUBFUN void XMLCALL xmlSAX2StartDocument (void *ctx); XMLPUBFUN void XMLCALL xmlSAX2EndDocument (void *ctx); -#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) +#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) XMLPUBFUN void XMLCALL xmlSAX2StartElement (void *ctx, const xmlChar *fullname, @@ -114,8 +114,8 @@ XMLPUBFUN void XMLCALL const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, - intptr_t nb_attributes, - intptr_t nb_defaulted, + int nb_attributes, + int nb_defaulted, const xmlChar **attributes); XMLPUBFUN void XMLCALL xmlSAX2EndElementNs (void *ctx, @@ -128,11 +128,11 @@ XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL xmlSAX2Characters (void *ctx, const xmlChar *ch, - intptr_t len); + int len); XMLPUBFUN void XMLCALL xmlSAX2IgnorableWhitespace (void *ctx, const xmlChar *ch, - intptr_t len); + int len); XMLPUBFUN void XMLCALL xmlSAX2ProcessingInstruction (void *ctx, const xmlChar *target, @@ -143,7 +143,7 @@ XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL xmlSAX2CDataBlock (void *ctx, const xmlChar *value, - intptr_t len); + int len); #ifdef LIBXML_SAX1_ENABLED XMLPUBFUN int XMLCALL diff --git a/Extras/LibXML/include/libxml/chvalid.h b/Extras/LibXML/include/libxml/chvalid.h index 6301a91fa..fb4301698 100644 --- a/Extras/LibXML/include/libxml/chvalid.h +++ b/Extras/LibXML/include/libxml/chvalid.h @@ -1,12 +1,12 @@ /* * Summary: Unicode character range checking * Description: this module exports interfaces for the character - * range validation APIs + * range validation APIs * * This file is automatically generated from the cvs source * definition files using the genChRanges.py Python script * - * Generation date: Tue Nov 18 08:14:21 2003 + * Generation date: Mon Mar 27 11:09:48 2006 * Sources: chvalid.def * Author: William Brack */ @@ -44,15 +44,15 @@ typedef xmlChRangeGroup *xmlChRangeGroupPtr; struct _xmlChRangeGroup { int nbShortRange; int nbLongRange; - xmlChSRangePtr shortRange; /* points to an array of ranges */ - xmlChLRangePtr longRange; + const xmlChSRange *shortRange; /* points to an array of ranges */ + const xmlChLRange *longRange; }; /** * Range checking routine */ XMLPUBFUN int XMLCALL - xmlCharInRange(unsigned int val, const xmlChRangeGroupPtr group); + xmlCharInRange(unsigned int val, const xmlChRangeGroup *group); /** @@ -77,7 +77,7 @@ XMLPUBFUN int XMLCALL xmlIsBaseChar_ch((c)) : \ xmlCharInRange((c), &xmlIsBaseCharGroup)) -XMLPUBVAR xmlChRangeGroup xmlIsBaseCharGroup; +XMLPUBVAR const xmlChRangeGroup xmlIsBaseCharGroup; /** * xmlIsBlank_ch: @@ -121,7 +121,7 @@ XMLPUBVAR xmlChRangeGroup xmlIsBaseCharGroup; ((0xe000 <= (c)) && ((c) <= 0xfffd)) || \ ((0x10000 <= (c)) && ((c) <= 0x10ffff)))) -XMLPUBVAR xmlChRangeGroup xmlIsCharGroup; +XMLPUBVAR const xmlChRangeGroup xmlIsCharGroup; /** * xmlIsCombiningQ: @@ -133,7 +133,7 @@ XMLPUBVAR xmlChRangeGroup xmlIsCharGroup; 0 : \ xmlCharInRange((c), &xmlIsCombiningGroup)) -XMLPUBVAR xmlChRangeGroup xmlIsCombiningGroup; +XMLPUBVAR const xmlChRangeGroup xmlIsCombiningGroup; /** * xmlIsDigit_ch: @@ -153,7 +153,7 @@ XMLPUBVAR xmlChRangeGroup xmlIsCombiningGroup; xmlIsDigit_ch((c)) : \ xmlCharInRange((c), &xmlIsDigitGroup)) -XMLPUBVAR xmlChRangeGroup xmlIsDigitGroup; +XMLPUBVAR const xmlChRangeGroup xmlIsDigitGroup; /** * xmlIsExtender_ch: @@ -173,7 +173,7 @@ XMLPUBVAR xmlChRangeGroup xmlIsDigitGroup; xmlIsExtender_ch((c)) : \ xmlCharInRange((c), &xmlIsExtenderGroup)) -XMLPUBVAR xmlChRangeGroup xmlIsExtenderGroup; +XMLPUBVAR const xmlChRangeGroup xmlIsExtenderGroup; /** * xmlIsIdeographicQ: @@ -187,8 +187,8 @@ XMLPUBVAR xmlChRangeGroup xmlIsExtenderGroup; ((c) == 0x3007) || \ ((0x3021 <= (c)) && ((c) <= 0x3029)))) -XMLPUBVAR xmlChRangeGroup xmlIsIdeographicGroup; -XMLPUBVAR unsigned char xmlIsPubidChar_tab[256]; +XMLPUBVAR const xmlChRangeGroup xmlIsIdeographicGroup; +XMLPUBVAR const unsigned char xmlIsPubidChar_tab[256]; /** * xmlIsPubidChar_ch: diff --git a/Extras/LibXML/include/libxml/dict.h b/Extras/LibXML/include/libxml/dict.h index 117a1a56c..abb8339cb 100644 --- a/Extras/LibXML/include/libxml/dict.h +++ b/Extras/LibXML/include/libxml/dict.h @@ -42,11 +42,11 @@ XMLPUBFUN void XMLCALL XMLPUBFUN const xmlChar * XMLCALL xmlDictLookup (xmlDictPtr dict, const xmlChar *name, - intptr_t len); + int len); XMLPUBFUN const xmlChar * XMLCALL xmlDictExists (xmlDictPtr dict, const xmlChar *name, - intptr_t len); + int len); XMLPUBFUN const xmlChar * XMLCALL xmlDictQLookup (xmlDictPtr dict, const xmlChar *prefix, diff --git a/Extras/LibXML/include/libxml/encoding.h b/Extras/LibXML/include/libxml/encoding.h index fd396ec30..c74b25f3c 100644 --- a/Extras/LibXML/include/libxml/encoding.h +++ b/Extras/LibXML/include/libxml/encoding.h @@ -95,8 +95,8 @@ typedef enum { * if the return value is positive, else unpredictiable. * The value of @outlen after return is the number of octets consumed. */ -typedef intptr_t (* xmlCharEncodingInputFunc)(unsigned char *out, intptr_t* outlen, - const unsigned char *in, intptr_t* inlen); +typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen, + const unsigned char *in, int *inlen); /** @@ -117,8 +117,8 @@ typedef intptr_t (* xmlCharEncodingInputFunc)(unsigned char *out, intptr_t* outl * if the return value is positive, else unpredictiable. * The value of @outlen after return is the number of octets produced. */ -typedef intptr_t (* xmlCharEncodingOutputFunc)(unsigned char *out, intptr_t* outlen, - const unsigned char *in, intptr_t* inlen); +typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen, + const unsigned char *in, int *inlen); /* @@ -186,18 +186,18 @@ XMLPUBFUN const char * XMLCALL */ XMLPUBFUN xmlCharEncoding XMLCALL xmlDetectCharEncoding (const unsigned char *in, - intptr_t len); + int len); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlCharEncOutFunc (xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlCharEncInFunc (xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlCharEncFirstLine (xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in); @@ -208,17 +208,17 @@ XMLPUBFUN int XMLCALL * Export a few useful functions */ #ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL UTF8Toisolat1 (unsigned char *out, - intptr_t* outlen, + int *outlen, const unsigned char *in, - intptr_t* inlen); + int *inlen); #endif /* LIBXML_OUTPUT_ENABLED */ -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL isolat1ToUTF8 (unsigned char *out, - intptr_t* outlen, + int *outlen, const unsigned char *in, - intptr_t* inlen); + int *inlen); #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/entities.h b/Extras/LibXML/include/libxml/entities.h index e9dbe518e..0bb28a0bd 100644 --- a/Extras/LibXML/include/libxml/entities.h +++ b/Extras/LibXML/include/libxml/entities.h @@ -48,7 +48,7 @@ struct _xmlEntity { xmlChar *orig; /* content without ref substitution */ xmlChar *content; /* content or ndata if unparsed */ - intptr_t length; /* the content length */ + int length; /* the content length */ xmlEntityType etype; /* The entity type */ const xmlChar *ExternalID; /* External identifier for PUBLIC */ const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */ diff --git a/Extras/LibXML/include/libxml/parser.h b/Extras/LibXML/include/libxml/parser.h index 19c543966..46377ff22 100644 --- a/Extras/LibXML/include/libxml/parser.h +++ b/Extras/LibXML/include/libxml/parser.h @@ -60,15 +60,15 @@ struct _xmlParserInput { const xmlChar *base; /* Base of the array to parse */ const xmlChar *cur; /* Current char being parsed */ const xmlChar *end; /* end of the array to parse */ - intptr_t length; /* length if known */ + int length; /* length if known */ int line; /* Current line */ - intptr_t col; /* Current column */ + int col; /* Current column */ /* * NOTE: consumed is only tested for equality in the parser code, * so even if there is an overflow this should not give troubles * for parsing very large instances. */ - size_t consumed; /* How many xmlChars already consumed */ + unsigned long consumed; /* How many xmlChars already consumed */ xmlParserInputDeallocate free; /* function to deallocate the base */ const xmlChar *encoding; /* the encoding string for entity */ const xmlChar *version; /* the version string for entity */ @@ -89,9 +89,9 @@ typedef xmlParserNodeInfo *xmlParserNodeInfoPtr; struct _xmlParserNodeInfo { const struct _xmlNode* node; /* Position & line # that text that created the node begins & ends on */ - size_t begin_pos; + unsigned long begin_pos; unsigned long begin_line; - size_t end_pos; + unsigned long end_pos; unsigned long end_line; }; @@ -228,8 +228,8 @@ struct _xmlParserCtxt { int nameMax; /* Max depth of the parsing stack */ const xmlChar * *nameTab; /* array of nodes */ - intptr_t nbChars; /* number of xmlChar processed */ - intptr_t checkIndex; /* used by progressive parsing lookup */ + long nbChars; /* number of xmlChar processed */ + long checkIndex; /* used by progressive parsing lookup */ int keepBlanks; /* ugly but ... */ int disableSAX; /* SAX callbacks are disabled */ int inSubset; /* Parsing is in int 1/ext 2 subset */ @@ -247,8 +247,8 @@ struct _xmlParserCtxt { xmlParserInputPtr entity; /* used to check entities boundaries */ int charset; /* encoding of the in-memory content actually an xmlCharEncoding */ - intptr_t nodelen; /* Those two fields are there to */ - intptr_t nodemem; /* Speed up large node parsing */ + int nodelen; /* Those two fields are there to */ + int nodemem; /* Speed up large node parsing */ int pedantic; /* signal pedantic warnings */ void *_private; /* For user data, libxml won't touch it */ @@ -259,7 +259,7 @@ struct _xmlParserCtxt { int progressive; /* is this a progressive parsing */ xmlDictPtr dict; /* dictionnary for the parser */ const xmlChar * *atts; /* array for the attributes callbacks */ - intptr_t maxatts; /* the size of the array */ + int maxatts; /* the size of the array */ int docdict; /* use strings from dict to build tree */ /* @@ -276,7 +276,7 @@ struct _xmlParserCtxt { int nsNr; /* the number of inherited namespaces */ int nsMax; /* the size of the arrays */ const xmlChar * *nsTab; /* the array of prefix/namespace name */ - intptr_t *attallocs; /* which attribute were allocated */ + int *attallocs; /* which attribute were allocated */ void * *pushTab; /* array of data for push */ xmlHashTablePtr attsDefault; /* defaulted attributes if any */ xmlHashTablePtr attsSpecial; /* non-CDATA attributes if any */ @@ -307,8 +307,8 @@ struct _xmlParserCtxt { struct _xmlSAXLocator { const xmlChar *(*getPublicId)(void *ctx); const xmlChar *(*getSystemId)(void *ctx); - intptr_t (*getLineNumber)(void *ctx); - intptr_t (*getColumnNumber)(void *ctx); + int (*getLineNumber)(void *ctx); + int (*getColumnNumber)(void *ctx); }; /** @@ -538,7 +538,7 @@ typedef void (*referenceSAXFunc) (void *ctx, */ typedef void (*charactersSAXFunc) (void *ctx, const xmlChar *ch, - intptr_t len); + int len); /** * ignorableWhitespaceSAXFunc: * @ctx: the user data (XML parser context) @@ -550,7 +550,7 @@ typedef void (*charactersSAXFunc) (void *ctx, */ typedef void (*ignorableWhitespaceSAXFunc) (void *ctx, const xmlChar *ch, - intptr_t len); + int len); /** * processingInstructionSAXFunc: * @ctx: the user data (XML parser context) @@ -580,9 +580,9 @@ typedef void (*commentSAXFunc) (void *ctx, * Called when a pcdata block has been parsed. */ typedef void (*cdataBlockSAXFunc) ( - void *ctx, + void *ctx, const xmlChar *value, - intptr_t len); + int len); /** * warningSAXFunc: * @ctx: an XML parser context @@ -591,7 +591,7 @@ typedef void (*cdataBlockSAXFunc) ( * * Display and format a warning messages, callback. */ -typedef void (*warningSAXFunc) (void *ctx, +typedef void (XMLCDECL *warningSAXFunc) (void *ctx, const char *msg, ...); /** * errorSAXFunc: @@ -601,7 +601,7 @@ typedef void (*warningSAXFunc) (void *ctx, * * Display and format an error messages, callback. */ -typedef void (*errorSAXFunc) (void *ctx, +typedef void (XMLCDECL *errorSAXFunc) (void *ctx, const char *msg, ...); /** * fatalErrorSAXFunc: @@ -613,7 +613,7 @@ typedef void (*errorSAXFunc) (void *ctx, * Note: so far fatalError() SAX callbacks are not used, error() * get all the callbacks for errors. */ -typedef void (*fatalErrorSAXFunc) (void *ctx, +typedef void (XMLCDECL *fatalErrorSAXFunc) (void *ctx, const char *msg, ...); /** * isStandaloneSAXFunc: @@ -681,8 +681,8 @@ typedef void (*startElementNsSAX2Func) (void *ctx, const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, - intptr_t nb_attributes, - intptr_t nb_defaulted, + int nb_attributes, + int nb_defaulted, const xmlChar **attributes); /** @@ -813,12 +813,12 @@ XMLPUBFUN void XMLCALL /* * Input functions */ -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlParserInputRead (xmlParserInputPtr in, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlParserInputGrow (xmlParserInputPtr in, - intptr_t len); + int len); /* * Basic parsing Interfaces @@ -830,16 +830,14 @@ XMLPUBFUN xmlDocPtr XMLCALL xmlParseFile (const char *filename); XMLPUBFUN xmlDocPtr XMLCALL xmlParseMemory (const char *buffer, - intptr_t size); + int size); #endif /* LIBXML_SAX1_ENABLED */ XMLPUBFUN int XMLCALL xmlSubstituteEntitiesDefault(int val); XMLPUBFUN int XMLCALL xmlKeepBlanksDefault (int val); -#ifdef LIBXML_PUSH_ENABLED XMLPUBFUN void XMLCALL xmlStopParser (xmlParserCtxtPtr ctxt); -#endif /* LIBXML_PUSH_ENABLED */ XMLPUBFUN int XMLCALL xmlPedanticParserDefault(int val); XMLPUBFUN int XMLCALL @@ -882,12 +880,12 @@ XMLPUBFUN xmlDocPtr XMLCALL XMLPUBFUN xmlDocPtr XMLCALL xmlSAXParseMemory (xmlSAXHandlerPtr sax, const char *buffer, - intptr_t size, + int size, int recovery); XMLPUBFUN xmlDocPtr XMLCALL xmlSAXParseMemoryWithData (xmlSAXHandlerPtr sax, const char *buffer, - intptr_t size, + int size, int recovery, void *data); XMLPUBFUN xmlDocPtr XMLCALL @@ -1003,12 +1001,12 @@ XMLPUBFUN xmlParserCtxtPtr XMLCALL xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, const char *chunk, - intptr_t size, + int size, const char *filename); XMLPUBFUN int XMLCALL xmlParseChunk (xmlParserCtxtPtr ctxt, const char *chunk, - intptr_t size, + int size, int terminate); #endif /* LIBXML_PUSH_ENABLED */ @@ -1062,7 +1060,7 @@ XMLPUBFUN xmlParserInputPtr XMLCALL /* * Index lookup, actually implemented in the encoding module */ -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN long XMLCALL xmlByteConsumed (xmlParserCtxtPtr ctxt); /* @@ -1090,7 +1088,8 @@ typedef enum { XML_PARSE_NODICT = 1<<12,/* Do not reuse the context dictionnary */ XML_PARSE_NSCLEAN = 1<<13,/* remove redundant namespaces declarations */ XML_PARSE_NOCDATA = 1<<14,/* merge CDATA as text nodes */ - XML_PARSE_NOXINCNODE= 1<<15 /* do not generate XINCLUDE START/END nodes */ + XML_PARSE_NOXINCNODE= 1<<15,/* do not generate XINCLUDE START/END nodes */ + XML_PARSE_COMPACT = 1<<16 /* compact small text nodes */ } xmlParserOption; XMLPUBFUN void XMLCALL @@ -1164,6 +1163,53 @@ XMLPUBFUN xmlDocPtr XMLCALL const char *encoding, int options); +/* + * Library wide options + */ +/** + * xmlFeature: + * + * Used to examine the existance of features that can be enabled + * or disabled at compile-time. + * They used to be called XML_FEATURE_xxx but this clashed with Expat + */ +typedef enum { + XML_WITH_THREAD = 1, + XML_WITH_TREE = 2, + XML_WITH_OUTPUT = 3, + XML_WITH_PUSH = 4, + XML_WITH_READER = 5, + XML_WITH_PATTERN = 6, + XML_WITH_WRITER = 7, + XML_WITH_SAX1 = 8, + XML_WITH_FTP = 9, + XML_WITH_HTTP = 10, + XML_WITH_VALID = 11, + XML_WITH_HTML = 12, + XML_WITH_LEGACY = 13, + XML_WITH_C14N = 14, + XML_WITH_CATALOG = 15, + XML_WITH_XPATH = 16, + XML_WITH_XPTR = 17, + XML_WITH_XINCLUDE = 18, + XML_WITH_ICONV = 19, + XML_WITH_ISO8859X = 20, + XML_WITH_UNICODE = 21, + XML_WITH_REGEXP = 22, + XML_WITH_AUTOMATA = 23, + XML_WITH_EXPR = 24, + XML_WITH_SCHEMAS = 25, + XML_WITH_SCHEMATRON = 26, + XML_WITH_MODULES = 27, + XML_WITH_DEBUG = 28, + XML_WITH_DEBUG_MEM = 29, + XML_WITH_DEBUG_RUN = 30, + XML_WITH_NONE = 99999 /* just to be sure of allocation size */ +} xmlFeature; + +XMLPUBFUN int XMLCALL + xmlHasFeature (xmlFeature feature); + #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/parserInternals.h b/Extras/LibXML/include/libxml/parserInternals.h index ababdab7e..7ac0ce6eb 100644 --- a/Extras/LibXML/include/libxml/parserInternals.h +++ b/Extras/LibXML/include/libxml/parserInternals.h @@ -286,7 +286,7 @@ XMLPUBFUN xmlParserCtxtPtr XMLCALL int options); XMLPUBFUN xmlParserCtxtPtr XMLCALL xmlCreateMemoryParserCtxt(const char *buffer, - intptr_t size); + int size); XMLPUBFUN xmlParserCtxtPtr XMLCALL xmlCreateEntityParserCtxt(const xmlChar *URL, const xmlChar *ID, @@ -486,7 +486,7 @@ XMLPUBFUN xmlChar * XMLCALL XMLPUBFUN xmlChar * XMLCALL xmlStringLenDecodeEntities (xmlParserCtxtPtr ctxt, const xmlChar *str, - intptr_t len, + int len, int what, xmlChar end, xmlChar end2, @@ -520,9 +520,9 @@ XMLPUBFUN int XMLCALL xmlCheckLanguageID (const xmlChar *lang); */ XMLPUBFUN int XMLCALL xmlCurrentChar (xmlParserCtxtPtr ctxt, int *len); -XMLPUBFUN intptr_t XMLCALL xmlCopyCharMultiByte (xmlChar *out, +XMLPUBFUN int XMLCALL xmlCopyCharMultiByte (xmlChar *out, int val); -XMLPUBFUN intptr_t XMLCALL xmlCopyChar (intptr_t len, +XMLPUBFUN int XMLCALL xmlCopyChar (int len, xmlChar *out, int val); XMLPUBFUN void XMLCALL xmlNextChar (xmlParserCtxtPtr ctxt); diff --git a/Extras/LibXML/include/libxml/pattern.h b/Extras/LibXML/include/libxml/pattern.h index f801a3744..97d2cd2bc 100644 --- a/Extras/LibXML/include/libxml/pattern.h +++ b/Extras/LibXML/include/libxml/pattern.h @@ -29,6 +29,20 @@ extern "C" { typedef struct _xmlPattern xmlPattern; typedef xmlPattern *xmlPatternPtr; +/** + * xmlPatternFlags: + * + * This is the set of options affecting the behaviour of pattern + * matching with this module + * + */ +typedef enum { + XML_PATTERN_DEFAULT = 0, /* simple pattern match */ + XML_PATTERN_XPATH = 1<<0, /* standard XPath pattern */ + XML_PATTERN_XSSEL = 1<<1, /* XPath subset for schema selector */ + XML_PATTERN_XSFIELD = 1<<2 /* XPath subset for schema field */ +} xmlPatternFlags; + XMLPUBFUN void XMLCALL xmlFreePattern (xmlPatternPtr comp); @@ -52,12 +66,19 @@ XMLPUBFUN int XMLCALL xmlPatternStreamable (xmlPatternPtr comp); XMLPUBFUN int XMLCALL xmlPatternMaxDepth (xmlPatternPtr comp); +XMLPUBFUN int XMLCALL + xmlPatternMinDepth (xmlPatternPtr comp); XMLPUBFUN int XMLCALL xmlPatternFromRoot (xmlPatternPtr comp); XMLPUBFUN xmlStreamCtxtPtr XMLCALL xmlPatternGetStreamCtxt (xmlPatternPtr comp); XMLPUBFUN void XMLCALL xmlFreeStreamCtxt (xmlStreamCtxtPtr stream); +XMLPUBFUN int XMLCALL + xmlStreamPushNode (xmlStreamCtxtPtr stream, + const xmlChar *name, + const xmlChar *ns, + int nodeType); XMLPUBFUN int XMLCALL xmlStreamPush (xmlStreamCtxtPtr stream, const xmlChar *name, @@ -68,6 +89,8 @@ XMLPUBFUN int XMLCALL const xmlChar *ns); XMLPUBFUN int XMLCALL xmlStreamPop (xmlStreamCtxtPtr stream); +XMLPUBFUN int XMLCALL + xmlStreamWantsAnyNode (xmlStreamCtxtPtr stream); #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/relaxng.h b/Extras/LibXML/include/libxml/relaxng.h index ca3c13ba4..6acd4674b 100644 --- a/Extras/LibXML/include/libxml/relaxng.h +++ b/Extras/LibXML/include/libxml/relaxng.h @@ -27,8 +27,8 @@ typedef xmlRelaxNG *xmlRelaxNGPtr; /** * A schemas validation context */ -typedef void (*xmlRelaxNGValidityErrorFunc) (void *ctx, const char *msg, ...); -typedef void (*xmlRelaxNGValidityWarningFunc) (void *ctx, const char *msg, ...); +typedef void (XMLCDECL *xmlRelaxNGValidityErrorFunc) (void *ctx, const char *msg, ...); +typedef void (XMLCDECL *xmlRelaxNGValidityWarningFunc) (void *ctx, const char *msg, ...); typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt; typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr; @@ -127,6 +127,11 @@ XMLPUBFUN int XMLCALL xmlRelaxNGValidityErrorFunc *err, xmlRelaxNGValidityWarningFunc *warn, void **ctx); +XMLPUBFUN void XMLCALL + xmlRelaxNGSetParserStructuredErrors( + xmlRelaxNGParserCtxtPtr ctxt, + xmlStructuredErrorFunc serror, + void *ctx); XMLPUBFUN xmlRelaxNGPtr XMLCALL xmlRelaxNGParse (xmlRelaxNGParserCtxtPtr ctxt); XMLPUBFUN void XMLCALL @@ -152,6 +157,9 @@ XMLPUBFUN int XMLCALL xmlRelaxNGValidityErrorFunc *err, xmlRelaxNGValidityWarningFunc *warn, void **ctx); +XMLPUBFUN void XMLCALL + xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt, + xmlStructuredErrorFunc serror, void *ctx); XMLPUBFUN xmlRelaxNGValidCtxtPtr XMLCALL xmlRelaxNGNewValidCtxt (xmlRelaxNGPtr schema); XMLPUBFUN void XMLCALL diff --git a/Extras/LibXML/include/libxml/schemasInternals.h b/Extras/LibXML/include/libxml/schemasInternals.h index 2c39a8789..b68a6e128 100644 --- a/Extras/LibXML/include/libxml/schemasInternals.h +++ b/Extras/LibXML/include/libxml/schemasInternals.h @@ -2,6 +2,8 @@ * Summary: internal interfaces for XML Schemas * Description: internal interfaces for the XML Schemas handling * and schema validity checking + * The Schemas development is a Work In Progress. + * Some of those interfaces are not garanteed to be API or ABI stable ! * * Copy: See Copyright for the status of this software. * @@ -83,7 +85,7 @@ typedef enum { XML_SCHEMA_TYPE_FACET, XML_SCHEMA_TYPE_SIMPLE, XML_SCHEMA_TYPE_COMPLEX, - XML_SCHEMA_TYPE_SEQUENCE, + XML_SCHEMA_TYPE_SEQUENCE = 6, XML_SCHEMA_TYPE_CHOICE, XML_SCHEMA_TYPE_ALL, XML_SCHEMA_TYPE_SIMPLE_CONTENT, @@ -102,7 +104,8 @@ typedef enum { XML_SCHEMA_TYPE_IDC_UNIQUE, XML_SCHEMA_TYPE_IDC_KEY, XML_SCHEMA_TYPE_IDC_KEYREF, - XML_SCHEMA_TYPE_PARTICLE, + XML_SCHEMA_TYPE_PARTICLE = 25, + XML_SCHEMA_TYPE_ATTRIBUTE_USE, XML_SCHEMA_FACET_MININCLUSIVE = 1000, XML_SCHEMA_FACET_MINEXCLUSIVE, XML_SCHEMA_FACET_MAXINCLUSIVE, @@ -115,7 +118,8 @@ typedef enum { XML_SCHEMA_FACET_LENGTH, XML_SCHEMA_FACET_MAXLENGTH, XML_SCHEMA_FACET_MINLENGTH, - XML_SCHEMA_EXTRA_QNAMEREF = 2000 + XML_SCHEMA_EXTRA_QNAMEREF = 2000, + XML_SCHEMA_EXTRA_ATTR_USE_PROHIB } xmlSchemaTypeType; typedef enum { @@ -124,7 +128,7 @@ typedef enum { XML_SCHEMA_CONTENT_ELEMENTS, XML_SCHEMA_CONTENT_MIXED, XML_SCHEMA_CONTENT_SIMPLE, - XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS, /* obsolete, not used */ + XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS, /* Obsolete */ XML_SCHEMA_CONTENT_BASIC, XML_SCHEMA_CONTENT_ANY } xmlSchemaContentType; @@ -242,31 +246,32 @@ struct _xmlSchemaAnnot { typedef struct _xmlSchemaAttribute xmlSchemaAttribute; typedef xmlSchemaAttribute *xmlSchemaAttributePtr; struct _xmlSchemaAttribute { - xmlSchemaTypeType type; /* The kind of type */ - struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */ - const xmlChar *name; /* name of the declaration or empty if particle */ - const xmlChar *id; - const xmlChar *ref; /* the local name of the attribute decl. if a particle */ - const xmlChar *refNs; /* the ns URI of the attribute decl. if a particle */ + xmlSchemaTypeType type; + struct _xmlSchemaAttribute *next; /* the next attribute (not used?) */ + const xmlChar *name; /* the name of the declaration */ + const xmlChar *id; /* Deprecated; not used */ + const xmlChar *ref; /* Deprecated; not used */ + const xmlChar *refNs; /* Deprecated; not used */ const xmlChar *typeName; /* the local name of the type definition */ const xmlChar *typeNs; /* the ns URI of the type definition */ xmlSchemaAnnotPtr annot; - xmlSchemaTypePtr base; /* obsolete, not used */ - int occurs; - const xmlChar *defValue; + xmlSchemaTypePtr base; /* Deprecated; not used */ + int occurs; /* Deprecated; not used */ + const xmlChar *defValue; /* The initial value of the value constraint */ xmlSchemaTypePtr subtypes; /* the type definition */ xmlNodePtr node; const xmlChar *targetNamespace; int flags; - const xmlChar *refPrefix; - xmlSchemaValPtr defVal; - xmlSchemaAttributePtr refDecl; + const xmlChar *refPrefix; /* Deprecated; not used */ + xmlSchemaValPtr defVal; /* The compiled value constraint */ + xmlSchemaAttributePtr refDecl; /* Deprecated; not used */ }; /** * xmlSchemaAttributeLink: * Used to build a list of attribute uses on complexType definitions. + * WARNING: Deprecated; not used. */ typedef struct _xmlSchemaAttributeLink xmlSchemaAttributeLink; typedef xmlSchemaAttributeLink *xmlSchemaAttributeLinkPtr; @@ -301,11 +306,11 @@ typedef struct _xmlSchemaWildcard xmlSchemaWildcard; typedef xmlSchemaWildcard *xmlSchemaWildcardPtr; struct _xmlSchemaWildcard { xmlSchemaTypeType type; /* The kind of type */ - const xmlChar *id; + const xmlChar *id; /* Deprecated; not used */ xmlSchemaAnnotPtr annot; xmlNodePtr node; - int minOccurs; - int maxOccurs; + int minOccurs; /* Deprecated; not used */ + int maxOccurs; /* Deprecated; not used */ int processContents; int any; /* Indicates if the ns constraint is of ##any */ xmlSchemaWildcardNsPtr nsSet; /* The list of allowed namespaces */ @@ -332,6 +337,19 @@ struct _xmlSchemaWildcard { */ #define XML_SCHEMAS_ATTRGROUP_MARKED 1 << 2 +/** + * XML_SCHEMAS_ATTRGROUP_REDEFINED: + * + * The attr group was redefined. + */ +#define XML_SCHEMAS_ATTRGROUP_REDEFINED 1 << 3 +/** + * XML_SCHEMAS_ATTRGROUP_HAS_REFS: + * + * Whether this attr. group contains attr. group references. + */ +#define XML_SCHEMAS_ATTRGROUP_HAS_REFS 1 << 4 + /** * An attribute group definition. * @@ -345,17 +363,18 @@ struct _xmlSchemaAttributeGroup { struct _xmlSchemaAttribute *next;/* the next attribute if in a group ... */ const xmlChar *name; const xmlChar *id; - const xmlChar *ref; - const xmlChar *refNs; + const xmlChar *ref; /* Deprecated; not used */ + const xmlChar *refNs; /* Deprecated; not used */ xmlSchemaAnnotPtr annot; - xmlSchemaAttributePtr attributes; + xmlSchemaAttributePtr attributes; /* Deprecated; not used */ xmlNodePtr node; int flags; xmlSchemaWildcardPtr attributeWildcard; - const xmlChar *refPrefix; - xmlSchemaAttributeGroupPtr refItem; /* The referenced attribute group */ + const xmlChar *refPrefix; /* Deprecated; not used */ + xmlSchemaAttributeGroupPtr refItem; /* Deprecated; not used */ const xmlChar *targetNamespace; + void *attrUses; }; /** @@ -367,7 +386,7 @@ typedef struct _xmlSchemaTypeLink xmlSchemaTypeLink; typedef xmlSchemaTypeLink *xmlSchemaTypeLinkPtr; struct _xmlSchemaTypeLink { struct _xmlSchemaTypeLink *next;/* the next type link ... */ - xmlSchemaTypePtr type;/* the linked type*/ + xmlSchemaTypePtr type;/* the linked type */ }; /** @@ -416,6 +435,9 @@ struct _xmlSchemaFacetLink { * XML_SCHEMAS_TYPE_VARIETY_ABSENT: * * the simpleType has a variety of "absent". + * TODO: Actually not necessary :-/, since if + * none of the variety flags occur then it's + * automatically absent. */ #define XML_SCHEMAS_TYPE_VARIETY_ABSENT 1 << 5 /** @@ -521,7 +543,56 @@ struct _xmlSchemaFacetLink { * indicates that the type is invalid */ #define XML_SCHEMAS_TYPE_INTERNAL_INVALID 1 << 23 +/** + * XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE: + * + * a whitespace-facet value of "preserve" + */ +#define XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE 1 << 24 +/** + * XML_SCHEMAS_TYPE_WHITESPACE_REPLACE: + * + * a whitespace-facet value of "replace" + */ +#define XML_SCHEMAS_TYPE_WHITESPACE_REPLACE 1 << 25 +/** + * XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE: + * + * a whitespace-facet value of "collapse" + */ +#define XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE 1 << 26 +/** + * XML_SCHEMAS_TYPE_HAS_FACETS: + * + * has facets + */ +#define XML_SCHEMAS_TYPE_HAS_FACETS 1 << 27 +/** + * XML_SCHEMAS_TYPE_NORMVALUENEEDED: + * + * indicates if the facets (pattern) need a normalized value + */ +#define XML_SCHEMAS_TYPE_NORMVALUENEEDED 1 << 28 +/** + * XML_SCHEMAS_TYPE_FIXUP_1: + * + * First stage of fixup was done. + */ +#define XML_SCHEMAS_TYPE_FIXUP_1 1 << 29 + +/** + * XML_SCHEMAS_TYPE_REDEFINED: + * + * The type was redefined. + */ +#define XML_SCHEMAS_TYPE_REDEFINED 1 << 30 +/** + * XML_SCHEMAS_TYPE_REDEFINING: + * + * The type redefines an other type. + */ +/* #define XML_SCHEMAS_TYPE_REDEFINING 1 << 31 */ /** * _xmlSchemaType: @@ -529,36 +600,38 @@ struct _xmlSchemaFacetLink { * Schemas type definition. */ struct _xmlSchemaType { - xmlSchemaTypeType type; /* The kind of type */ - struct _xmlSchemaType *next;/* the next type if in a sequence ... */ + xmlSchemaTypeType type; /* The kind of type */ + struct _xmlSchemaType *next; /* the next type if in a sequence ... */ const xmlChar *name; - const xmlChar *id; - const xmlChar *ref; - const xmlChar *refNs; + const xmlChar *id ; /* Deprecated; not used */ + const xmlChar *ref; /* Deprecated; not used */ + const xmlChar *refNs; /* Deprecated; not used */ xmlSchemaAnnotPtr annot; xmlSchemaTypePtr subtypes; - xmlSchemaAttributePtr attributes; + xmlSchemaAttributePtr attributes; /* Deprecated; not used */ xmlNodePtr node; - int minOccurs; - int maxOccurs; + int minOccurs; /* Deprecated; not used */ + int maxOccurs; /* Deprecated; not used */ int flags; xmlSchemaContentType contentType; - const xmlChar *base; - const xmlChar *baseNs; - xmlSchemaTypePtr baseType; - xmlSchemaFacetPtr facets; - struct _xmlSchemaType *redef;/* possible redefinitions for the type */ - int recurse; - xmlSchemaAttributeLinkPtr attributeUses; + const xmlChar *base; /* Base type's local name */ + const xmlChar *baseNs; /* Base type's target namespace */ + xmlSchemaTypePtr baseType; /* The base type component */ + xmlSchemaFacetPtr facets; /* Local facets */ + struct _xmlSchemaType *redef; /* Deprecated; not used */ + int recurse; /* Obsolete */ + xmlSchemaAttributeLinkPtr *attributeUses; /* Deprecated; not used */ xmlSchemaWildcardPtr attributeWildcard; - int builtInType; - xmlSchemaTypeLinkPtr memberTypes; - xmlSchemaFacetLinkPtr facetSet; - const xmlChar *refPrefix; - xmlSchemaTypePtr contentTypeDef; - xmlRegexpPtr contModel; + int builtInType; /* Type of built-in types. */ + xmlSchemaTypeLinkPtr memberTypes; /* member-types if a union type. */ + xmlSchemaFacetLinkPtr facetSet; /* All facets (incl. inherited) */ + const xmlChar *refPrefix; /* Deprecated; not used */ + xmlSchemaTypePtr contentTypeDef; /* Used for the simple content of complex types. + Could we use @subtypes for this? */ + xmlRegexpPtr contModel; /* Holds the automaton of the content model */ const xmlChar *targetNamespace; + void *attrUses; }; /* @@ -673,23 +746,35 @@ struct _xmlSchemaType { * substitution group exclusions: "restriction" */ #define XML_SCHEMAS_ELEM_FINAL_RESTRICTION 1 << 16 - +/** + * XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD: + * + * the declaration is a substitution group head + */ +#define XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD 1 << 17 +/** + * XML_SCHEMAS_ELEM_INTERNAL_CHECKED: + * + * this is set when the elem decl has been checked against + * all constraints + */ +#define XML_SCHEMAS_ELEM_INTERNAL_CHECKED 1 << 18 typedef struct _xmlSchemaElement xmlSchemaElement; typedef xmlSchemaElement *xmlSchemaElementPtr; struct _xmlSchemaElement { - xmlSchemaTypeType type; /* The kind of type */ - struct _xmlSchemaType *next;/* the next type if in a sequence ... */ + xmlSchemaTypeType type; /* The kind of type */ + struct _xmlSchemaType *next; /* Not used? */ const xmlChar *name; - const xmlChar *id; - const xmlChar *ref; /* the local name of the element declaration if a particle */ - const xmlChar *refNs; /* the ns URI of the element declaration if a particle */ + const xmlChar *id; /* Deprecated; not used */ + const xmlChar *ref; /* Deprecated; not used */ + const xmlChar *refNs; /* Deprecated; not used */ xmlSchemaAnnotPtr annot; xmlSchemaTypePtr subtypes; /* the type definition */ xmlSchemaAttributePtr attributes; xmlNodePtr node; - int minOccurs; - int maxOccurs; + int minOccurs; /* Deprecated; not used */ + int maxOccurs; /* Deprecated; not used */ int flags; const xmlChar *targetNamespace; @@ -698,13 +783,14 @@ struct _xmlSchemaElement { const xmlChar *substGroup; const xmlChar *substGroupNs; const xmlChar *scope; - const xmlChar *value; - struct _xmlSchemaElement *refDecl; /* the element declaration if a particle */ - xmlRegexpPtr contModel; + const xmlChar *value; /* The original value of the value constraint. */ + struct _xmlSchemaElement *refDecl; /* This will now be used for the + substitution group affiliation */ + xmlRegexpPtr contModel; /* Obsolete for WXS, maybe used for RelaxNG */ xmlSchemaContentType contentType; - const xmlChar *refPrefix; - xmlSchemaValPtr defVal; - void *idcs; + const xmlChar *refPrefix; /* Deprecated; not used */ + xmlSchemaValPtr defVal; /* The compiled value contraint. */ + void *idcs; /* The identity-constraint defs */ }; /* @@ -737,14 +823,14 @@ struct _xmlSchemaElement { struct _xmlSchemaFacet { xmlSchemaTypeType type; /* The kind of type */ struct _xmlSchemaFacet *next;/* the next type if in a sequence ... */ - const xmlChar *value; - const xmlChar *id; + const xmlChar *value; /* The original value */ + const xmlChar *id; /* Obsolete */ xmlSchemaAnnotPtr annot; xmlNodePtr node; - int fixed; + int fixed; /* XML_SCHEMAS_FACET_PRESERVE, etc. */ int whitespace; - xmlSchemaValPtr val; - xmlRegexpPtr regexp; + xmlSchemaValPtr val; /* The compiled value */ + xmlRegexpPtr regexp; /* The regex for patterns */ }; /** @@ -753,23 +839,31 @@ struct _xmlSchemaFacet { typedef struct _xmlSchemaNotation xmlSchemaNotation; typedef xmlSchemaNotation *xmlSchemaNotationPtr; struct _xmlSchemaNotation { - xmlSchemaTypeType type; /* The kind of type */ + xmlSchemaTypeType type; /* The kind of type */ const xmlChar *name; xmlSchemaAnnotPtr annot; const xmlChar *identifier; const xmlChar *targetNamespace; }; +/* +* TODO: Actually all those flags used for the schema should sit +* on the schema parser context, since they are used only +* during parsing an XML schema document, and not available +* on the component level as per spec. +*/ /** * XML_SCHEMAS_QUALIF_ELEM: * - * the schema requires qualified elements + * Reflects elementFormDefault == qualified in + * an XML schema document. */ #define XML_SCHEMAS_QUALIF_ELEM 1 << 0 /** * XML_SCHEMAS_QUALIF_ATTR: * - * the schema requires qualified attributes + * Reflects attributeFormDefault == qualified in + * an XML schema document. */ #define XML_SCHEMAS_QUALIF_ATTR 1 << 1 /** @@ -827,10 +921,10 @@ struct _xmlSchemaNotation { * A Schemas definition */ struct _xmlSchema { - const xmlChar *name; /* schema name */ - const xmlChar *targetNamespace; /* the target namespace */ + const xmlChar *name; /* schema name */ + const xmlChar *targetNamespace; /* the target namespace */ const xmlChar *version; - const xmlChar *id; + const xmlChar *id; /* Obsolete */ xmlDocPtr doc; xmlSchemaAnnotPtr annot; int flags; @@ -849,8 +943,8 @@ struct _xmlSchema { void *includes; /* the includes, this is opaque for now */ int preserve; /* whether to free the document */ int counter; /* used to give ononymous components unique names */ - xmlHashTablePtr idcDef; - void *volatiles; /* Misc. helper items (e.g. reference items) */ + xmlHashTablePtr idcDef; /* All identity-constraint defs. */ + void *volatiles; /* Obsolete */ }; XMLPUBFUN void XMLCALL xmlSchemaFreeType (xmlSchemaTypePtr type); diff --git a/Extras/LibXML/include/libxml/threads.h b/Extras/LibXML/include/libxml/threads.h index fb6b70488..4f7d10f71 100644 --- a/Extras/LibXML/include/libxml/threads.h +++ b/Extras/LibXML/include/libxml/threads.h @@ -36,7 +36,6 @@ typedef xmlRMutex *xmlRMutexPtr; #ifdef __cplusplus extern "C" { #endif - XMLPUBFUN xmlMutexPtr XMLCALL xmlNewMutex (void); XMLPUBFUN void XMLCALL diff --git a/Extras/LibXML/include/libxml/tree.h b/Extras/LibXML/include/libxml/tree.h index 99f598ea8..b1625745c 100644 --- a/Extras/LibXML/include/libxml/tree.h +++ b/Extras/LibXML/include/libxml/tree.h @@ -54,6 +54,33 @@ typedef xmlEntity *xmlEntityPtr; */ #define BASE_BUFFER_SIZE 4096 +/** + * xmlBufferAllocationScheme: + * + * A buffer allocation scheme can be defined to either match exactly the + * need or double it's allocated size each time it is found too small. + */ + +typedef enum { + XML_BUFFER_ALLOC_DOUBLEIT, + XML_BUFFER_ALLOC_EXACT, + XML_BUFFER_ALLOC_IMMUTABLE +} xmlBufferAllocationScheme; + +/** + * xmlBuffer: + * + * A buffer structure. + */ +typedef struct _xmlBuffer xmlBuffer; +typedef xmlBuffer *xmlBufferPtr; +struct _xmlBuffer { + xmlChar *content; /* The buffer content UTF8 */ + unsigned int use; /* The buffer size used */ + unsigned int size; /* The buffer size */ + xmlBufferAllocationScheme alloc; /* The realloc method */ +}; + /** * XML_XML_NAMESPACE: * @@ -250,7 +277,6 @@ typedef enum { XML_ELEMENT_TYPE_ELEMENT } xmlElementTypeVal; - #ifdef __cplusplus } #endif @@ -402,33 +428,6 @@ struct _xmlRef { int lineno; /* The line number if attr is not available */ }; -/** - * xmlBufferAllocationScheme: - * - * A buffer allocation scheme can be defined to either match exactly the - * need or double it's allocated size each time it is found too small. - */ - -typedef enum { - XML_BUFFER_ALLOC_DOUBLEIT, - XML_BUFFER_ALLOC_EXACT, - XML_BUFFER_ALLOC_IMMUTABLE -} xmlBufferAllocationScheme; - -/** - * xmlBuffer: - * - * A buffer structure. - */ -typedef struct _xmlBuffer xmlBuffer; -typedef xmlBuffer *xmlBufferPtr; -struct _xmlBuffer { - xmlChar *content; /* The buffer content UTF8 */ - size_t use; /* The buffer size used */ - size_t size; /* The buffer size */ - xmlBufferAllocationScheme alloc; /* The realloc method */ -}; - /** * xmlNode: * @@ -509,6 +508,12 @@ struct _xmlDoc { void *psvi; /* for type/PSVI informations */ }; +typedef struct _xmlDOMWrapCtxt xmlDOMWrapCtxt; +typedef xmlDOMWrapCtxt *xmlDOMWrapCtxtPtr; +struct _xmlDOMWrapCtxt { + void * _private; +}; + /** * xmlChildrenNode: * @@ -536,7 +541,7 @@ struct _xmlDoc { /* * Some helper functions */ -#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) XMLPUBFUN int XMLCALL xmlValidateNCName (const xmlChar *value, int space); @@ -558,13 +563,13 @@ XMLPUBFUN xmlChar * XMLCALL xmlBuildQName (const xmlChar *ncname, const xmlChar *prefix, xmlChar *memory, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlSplitQName2 (const xmlChar *name, xmlChar **prefix); XMLPUBFUN const xmlChar * XMLCALL xmlSplitQName3 (const xmlChar *name, - intptr_t *len); + int *len); /* * Handling Buffers. @@ -584,32 +589,32 @@ XMLPUBFUN xmlBufferPtr XMLCALL size_t size); XMLPUBFUN int XMLCALL xmlBufferResize (xmlBufferPtr buf, - size_t size); + unsigned int size); XMLPUBFUN void XMLCALL xmlBufferFree (xmlBufferPtr buf); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlBufferDump (FILE *file, xmlBufferPtr buf); XMLPUBFUN int XMLCALL xmlBufferAdd (xmlBufferPtr buf, const xmlChar *str, - intptr_t len); + int len); XMLPUBFUN int XMLCALL xmlBufferAddHead (xmlBufferPtr buf, const xmlChar *str, - intptr_t len); + int len); XMLPUBFUN int XMLCALL xmlBufferCat (xmlBufferPtr buf, const xmlChar *str); XMLPUBFUN int XMLCALL xmlBufferCCat (xmlBufferPtr buf, const char *str); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlBufferShrink (xmlBufferPtr buf, - size_t len); -XMLPUBFUN intptr_t XMLCALL + unsigned int len); +XMLPUBFUN int XMLCALL xmlBufferGrow (xmlBufferPtr buf, - size_t len); + unsigned int len); XMLPUBFUN void XMLCALL xmlBufferEmpty (xmlBufferPtr buf); XMLPUBFUN const xmlChar* XMLCALL @@ -617,7 +622,7 @@ XMLPUBFUN const xmlChar* XMLCALL XMLPUBFUN void XMLCALL xmlBufferSetAllocationScheme(xmlBufferPtr buf, xmlBufferAllocationScheme scheme); -XMLPUBFUN size_t XMLCALL +XMLPUBFUN int XMLCALL xmlBufferLength (const xmlBufferPtr buf); /* @@ -736,10 +741,10 @@ XMLPUBFUN xmlNodePtr XMLCALL XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocTextLen (xmlDocPtr doc, const xmlChar *content, - intptr_t len); + int len); XMLPUBFUN xmlNodePtr XMLCALL xmlNewTextLen (const xmlChar *content, - intptr_t len); + int len); XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocComment (xmlDocPtr doc, const xmlChar *content); @@ -748,7 +753,7 @@ XMLPUBFUN xmlNodePtr XMLCALL XMLPUBFUN xmlNodePtr XMLCALL xmlNewCDataBlock (xmlDocPtr doc, const xmlChar *content, - intptr_t len); + int len); XMLPUBFUN xmlNodePtr XMLCALL xmlNewCharRef (xmlDocPtr doc, const xmlChar *name); @@ -844,7 +849,7 @@ XMLPUBFUN xmlNodePtr XMLCALL XMLPUBFUN int XMLCALL xmlTextConcat (xmlNodePtr node, const xmlChar *content, - intptr_t len); + int len); XMLPUBFUN void XMLCALL xmlFreeNodeList (xmlNodePtr cur); XMLPUBFUN void XMLCALL @@ -917,7 +922,7 @@ XMLPUBFUN xmlNodePtr XMLCALL XMLPUBFUN xmlNodePtr XMLCALL xmlStringLenGetNodeList (xmlDocPtr doc, const xmlChar *value, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlNodeListGetString (xmlDocPtr doc, xmlNodePtr list, @@ -935,7 +940,7 @@ XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL xmlNodeSetContentLen (xmlNodePtr cur, const xmlChar *content, - intptr_t len); + int len); #endif /* LIBXML_TREE_ENABLED */ XMLPUBFUN void XMLCALL xmlNodeAddContent (xmlNodePtr cur, @@ -943,7 +948,7 @@ XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL xmlNodeAddContentLen (xmlNodePtr cur, const xmlChar *content, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlNodeGetContent (xmlNodePtr cur); XMLPUBFUN int XMLCALL @@ -973,10 +978,8 @@ XMLPUBFUN void XMLCALL /* * Removing content. */ -#ifdef LIBXML_TREE_ENABLED XMLPUBFUN int XMLCALL xmlRemoveProp (xmlAttrPtr cur); -#endif /* LIBXML_TREE_ENABLED */ #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) XMLPUBFUN int XMLCALL xmlUnsetNsProp (xmlNodePtr node, @@ -1032,44 +1035,44 @@ XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL xmlDocDumpMemoryEnc (xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - intptr_t* doc_txt_len, + int * doc_txt_len, const char *txt_encoding); XMLPUBFUN void XMLCALL xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - intptr_t* doc_txt_len, + int * doc_txt_len, const char *txt_encoding, int format); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlDocFormatDump (FILE *f, xmlDocPtr cur, int format); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlDocDump (FILE *f, xmlDocPtr cur); XMLPUBFUN void XMLCALL xmlElemDump (FILE *f, xmlDocPtr doc, xmlNodePtr cur); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFile (const char *filename, xmlDocPtr cur); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFormatFile (const char *filename, xmlDocPtr cur, int format); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlNodeDump (xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, int format); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFileTo (xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFormatFileTo (xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding, @@ -1082,13 +1085,13 @@ XMLPUBFUN void XMLCALL int format, const char *encoding); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFormatFileEnc (const char *filename, xmlDocPtr cur, const char *encoding, int format); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFileEnc (const char *filename, xmlDocPtr cur, const char *encoding); @@ -1114,6 +1117,39 @@ XMLPUBFUN int XMLCALL XMLPUBFUN void XMLCALL xmlSetCompressMode (int mode); +/* +* DOM-wrapper helper functions. +*/ +XMLPUBFUN xmlDOMWrapCtxtPtr XMLCALL + xmlDOMWrapNewCtxt (void); +XMLPUBFUN void XMLCALL + xmlDOMWrapFreeCtxt (xmlDOMWrapCtxtPtr ctxt); +XMLPUBFUN int XMLCALL + xmlDOMWrapReconcileNamespaces(xmlDOMWrapCtxtPtr ctxt, + xmlNodePtr elem, + int options); +XMLPUBFUN int XMLCALL + xmlDOMWrapAdoptNode (xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlNodePtr node, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int options); +XMLPUBFUN int XMLCALL + xmlDOMWrapRemoveNode (xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr doc, + xmlNodePtr node, + int options); +XMLPUBFUN int XMLCALL + xmlDOMWrapCloneNode (xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlNodePtr node, + xmlNodePtr *clonedNode, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int deep, + int options); + #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/uri.h b/Extras/LibXML/include/libxml/uri.h index b05c00546..89e365356 100644 --- a/Extras/LibXML/include/libxml/uri.h +++ b/Extras/LibXML/include/libxml/uri.h @@ -47,13 +47,16 @@ struct _xmlURI { XMLPUBFUN xmlURIPtr XMLCALL xmlCreateURI (void); XMLPUBFUN xmlChar * XMLCALL - xmlBuildURI (const xmlChar *URI, - const xmlChar *base); + xmlBuildURI (const xmlChar *URI, + const xmlChar *base); XMLPUBFUN xmlChar * XMLCALL xmlBuildRelativeURI (const xmlChar *URI, - const xmlChar *base); + const xmlChar *base); XMLPUBFUN xmlURIPtr XMLCALL xmlParseURI (const char *str); +XMLPUBFUN xmlURIPtr XMLCALL + xmlParseURIRaw (const char *str, + int raw); XMLPUBFUN int XMLCALL xmlParseURIReference (xmlURIPtr uri, const char *str); @@ -67,7 +70,7 @@ XMLPUBFUN xmlChar * XMLCALL const xmlChar *list); XMLPUBFUN char * XMLCALL xmlURIUnescapeString (const char *str, - intptr_t len, + int len, char *target); XMLPUBFUN int XMLCALL xmlNormalizeURIPath (char *path); diff --git a/Extras/LibXML/include/libxml/valid.h b/Extras/LibXML/include/libxml/valid.h index fe70020de..7492d28b0 100644 --- a/Extras/LibXML/include/libxml/valid.h +++ b/Extras/LibXML/include/libxml/valid.h @@ -39,7 +39,7 @@ typedef xmlValidState *xmlValidStatePtr; * Callback called when a validity error is found. This is a message * oriented function similar to an *printf function. */ -typedef void (*xmlValidityErrorFunc) (void *ctx, +typedef void (XMLCDECL *xmlValidityErrorFunc) (void *ctx, const char *msg, ...); @@ -54,7 +54,7 @@ typedef void (*xmlValidityErrorFunc) (void *ctx, * Callback called when a validity warning is found. This is a message * oriented function similar to an *printf function. */ -typedef void (*xmlValidityWarningFunc) (void *ctx, +typedef void (XMLCDECL *xmlValidityWarningFunc) (void *ctx, const char *msg, ...); @@ -193,15 +193,15 @@ XMLPUBFUN void XMLCALL xmlElementContentPtr cur); XMLPUBFUN void XMLCALL xmlSnprintfElementContent(char *buf, - size_t size, - xmlElementContentPtr content, - int glob); + int size, + xmlElementContentPtr content, + int englob); #ifdef LIBXML_OUTPUT_ENABLED /* DEPRECATED */ XMLPUBFUN void XMLCALL xmlSprintfElementContent(char *buf, - xmlElementContentPtr content, - int glob); + xmlElementContentPtr content, + int englob); #endif /* LIBXML_OUTPUT_ENABLED */ /* DEPRECATED */ @@ -410,7 +410,7 @@ XMLPUBFUN xmlElementPtr XMLCALL XMLPUBFUN int XMLCALL xmlValidGetPotentialChildren(xmlElementContent *ctree, - const xmlChar **list, + const xmlChar **names, int *len, int max); diff --git a/Extras/LibXML/include/libxml/xmlIO.h b/Extras/LibXML/include/libxml/xmlIO.h index 50af40886..eea9ed6c0 100644 --- a/Extras/LibXML/include/libxml/xmlIO.h +++ b/Extras/LibXML/include/libxml/xmlIO.h @@ -31,7 +31,7 @@ extern "C" { * * Returns 1 if yes and 0 if another Input module should be used */ -typedef int (*xmlInputMatchCallback) (char const *filename); +typedef int (XMLCALL *xmlInputMatchCallback) (char const *filename); /** * xmlInputOpenCallback: * @filename: the filename or URI @@ -40,7 +40,7 @@ typedef int (*xmlInputMatchCallback) (char const *filename); * * Returns an Input context or NULL in case or error */ -typedef void * (*xmlInputOpenCallback) (char const *filename); +typedef void * (XMLCALL *xmlInputOpenCallback) (char const *filename); /** * xmlInputReadCallback: * @context: an Input context @@ -51,7 +51,7 @@ typedef void * (*xmlInputOpenCallback) (char const *filename); * * Returns the number of bytes read or -1 in case of error */ -typedef intptr_t (*xmlInputReadCallback) (void * context, char * buffer, size_t len); +typedef int (XMLCALL *xmlInputReadCallback) (void * context, char * buffer, int len); /** * xmlInputCloseCallback: * @context: an Input context @@ -60,7 +60,7 @@ typedef intptr_t (*xmlInputReadCallback) (void * context, char * buffer, size_t * * Returns 0 or -1 in case of error */ -typedef int (*xmlInputCloseCallback) (void * context); +typedef int (XMLCALL *xmlInputCloseCallback) (void * context); #ifdef LIBXML_OUTPUT_ENABLED /* @@ -77,7 +77,7 @@ typedef int (*xmlInputCloseCallback) (void * context); * * Returns 1 if yes and 0 if another Output module should be used */ -typedef int (*xmlOutputMatchCallback) (char const *filename); +typedef int (XMLCALL *xmlOutputMatchCallback) (char const *filename); /** * xmlOutputOpenCallback: * @filename: the filename or URI @@ -86,7 +86,7 @@ typedef int (*xmlOutputMatchCallback) (char const *filename); * * Returns an Output context or NULL in case or error */ -typedef void * (*xmlOutputOpenCallback) (char const *filename); +typedef void * (XMLCALL *xmlOutputOpenCallback) (char const *filename); /** * xmlOutputWriteCallback: * @context: an Output context @@ -97,8 +97,8 @@ typedef void * (*xmlOutputOpenCallback) (char const *filename); * * Returns the number of bytes written or -1 in case of error */ -typedef intptr_t (*xmlOutputWriteCallback) (void * context, const char * buffer, - size_t len); +typedef int (XMLCALL *xmlOutputWriteCallback) (void * context, const char * buffer, + int len); /** * xmlOutputCloseCallback: * @context: an Output context @@ -107,7 +107,7 @@ typedef intptr_t (*xmlOutputWriteCallback) (void * context, const char * buffer, * * Returns 0 or -1 in case of error */ -typedef int (*xmlOutputCloseCallback) (void * context); +typedef int (XMLCALL *xmlOutputCloseCallback) (void * context); #endif /* LIBXML_OUTPUT_ENABLED */ #ifdef __cplusplus @@ -133,7 +133,7 @@ struct _xmlParserInputBuffer { xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */ int compressed; /* -1=unknown, 0=not compressed, 1=compressed */ int error; - size_t rawconsumed;/* amount consumed from raw */ + unsigned long rawconsumed;/* amount consumed from raw */ }; @@ -147,7 +147,7 @@ struct _xmlOutputBuffer { xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */ xmlBufferPtr conv; /* if encoder != NULL buffer for output */ - intptr_t written; /* total number of byte written */ + int written; /* total number of byte written */ int error; }; #endif /* LIBXML_OUTPUT_ENABLED */ @@ -176,25 +176,25 @@ XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateFd (int fd, xmlCharEncoding enc); XMLPUBFUN xmlParserInputBufferPtr XMLCALL - xmlParserInputBufferCreateMem (const char *mem, intptr_t size, + xmlParserInputBufferCreateMem (const char *mem, int size, xmlCharEncoding enc); XMLPUBFUN xmlParserInputBufferPtr XMLCALL - xmlParserInputBufferCreateStatic (const char *mem, intptr_t size, + xmlParserInputBufferCreateStatic (const char *mem, int size, xmlCharEncoding enc); XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateIO (xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, xmlCharEncoding enc); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlParserInputBufferRead (xmlParserInputBufferPtr in, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlParserInputBufferGrow (xmlParserInputBufferPtr in, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlParserInputBufferPush (xmlParserInputBufferPtr in, - intptr_t len, + int len, const char *buf); XMLPUBFUN void XMLCALL xmlFreeParserInputBuffer (xmlParserInputBufferPtr in); @@ -231,6 +231,10 @@ XMLPUBFUN xmlOutputBufferPtr XMLCALL xmlOutputBufferCreateFile (FILE *file, xmlCharEncodingHandlerPtr encoder); +XMLPUBFUN xmlOutputBufferPtr XMLCALL + xmlOutputBufferCreateBuffer (xmlBufferPtr buffer, + xmlCharEncodingHandlerPtr encoder); + XMLPUBFUN xmlOutputBufferPtr XMLCALL xmlOutputBufferCreateFd (int fd, xmlCharEncodingHandlerPtr encoder); @@ -241,21 +245,21 @@ XMLPUBFUN xmlOutputBufferPtr XMLCALL void *ioctx, xmlCharEncodingHandlerPtr encoder); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlOutputBufferWrite (xmlOutputBufferPtr out, - intptr_t len, + int len, const char *buf); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlOutputBufferWriteString (xmlOutputBufferPtr out, const char *str); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlOutputBufferWriteEscape (xmlOutputBufferPtr out, const xmlChar *str, xmlCharEncodingOutputFunc escaping); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlOutputBufferFlush (xmlOutputBufferPtr out); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlOutputBufferClose (xmlOutputBufferPtr out); XMLPUBFUN int XMLCALL @@ -305,10 +309,10 @@ XMLPUBFUN int XMLCALL xmlFileMatch (const char *filename); XMLPUBFUN void * XMLCALL xmlFileOpen (const char *filename); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlFileRead (void * context, char * buffer, - size_t len); + int len); XMLPUBFUN int XMLCALL xmlFileClose (void * context); diff --git a/Extras/LibXML/include/libxml/xmlautomata.h b/Extras/LibXML/include/libxml/xmlautomata.h index d29ddcfcc..f98b55e2b 100644 --- a/Extras/LibXML/include/libxml/xmlautomata.h +++ b/Extras/LibXML/include/libxml/xmlautomata.h @@ -65,6 +65,14 @@ XMLPUBFUN xmlAutomataStatePtr XMLCALL const xmlChar *token, const xmlChar *token2, void *data); +XMLPUBFUN xmlAutomataStatePtr XMLCALL + xmlAutomataNewNegTrans (xmlAutomataPtr am, + xmlAutomataStatePtr from, + xmlAutomataStatePtr to, + const xmlChar *token, + const xmlChar *token2, + void *data); + XMLPUBFUN xmlAutomataStatePtr XMLCALL xmlAutomataNewCountTrans (xmlAutomataPtr am, xmlAutomataStatePtr from, diff --git a/Extras/LibXML/include/libxml/xmlerror.h b/Extras/LibXML/include/libxml/xmlerror.h index e57c8bf84..c5f216409 100644 --- a/Extras/LibXML/include/libxml/xmlerror.h +++ b/Extras/LibXML/include/libxml/xmlerror.h @@ -60,7 +60,8 @@ typedef enum { XML_FROM_VALID, /* The XML DTD validation with valid context */ XML_FROM_CHECK, /* The error checking module */ XML_FROM_WRITER, /* The xmlwriter module */ - XML_FROM_MODULE /* The dynamically loaded module module*/ + XML_FROM_MODULE, /* The dynamically loaded module module*/ + XML_FROM_I18N /* The module handling character conversion */ } xmlErrorDomain; /** @@ -82,7 +83,7 @@ struct _xmlError { char *str2; /* extra string information */ char *str3; /* extra string information */ int int1; /* extra number information */ - intptr_t int2; /* column number of the error or 0 if N/A (todo: rename this field when we would break ABI) */ + int int2; /* column number of the error or 0 if N/A (todo: rename this field when we would break ABI) */ void *ctxt; /* the parser context if available */ void *node; /* the node in the tree */ }; @@ -195,10 +196,17 @@ typedef enum { XML_WAR_NS_URI, /* 99 */ XML_WAR_NS_URI_RELATIVE, /* 100 */ XML_ERR_MISSING_ENCODING, /* 101 */ + XML_WAR_SPACE_VALUE, /* 102 */ + XML_ERR_NOT_STANDALONE, /* 103 */ + XML_ERR_ENTITY_PROCESSING, /* 104 */ + XML_ERR_NOTATION_PROCESSING, /* 105 */ + XML_WAR_NS_COLUMN, /* 106 */ + XML_WAR_ENTITY_REDEFINED, /* 107 */ XML_NS_ERR_XML_NAMESPACE = 200, XML_NS_ERR_UNDEFINED_NAMESPACE, /* 201 */ XML_NS_ERR_QNAME, /* 202 */ XML_NS_ERR_ATTRIBUTE_REDEFINED, /* 203 */ + XML_NS_ERR_EMPTY, /* 204 */ XML_DTD_ATTRIBUTE_DEFAULT = 500, XML_DTD_ATTRIBUTE_REDEFINED, /* 501 */ XML_DTD_ATTRIBUTE_VALUE, /* 502 */ @@ -655,6 +663,7 @@ typedef enum { XML_SCHEMAV_CVC_TYPE_2, /* 1876 */ XML_SCHEMAV_CVC_IDC, /* 1877 */ XML_SCHEMAV_CVC_WILDCARD, /* 1878 */ + XML_SCHEMAV_MISC, /* 1879 */ XML_XPTR_UNKNOWN_SCHEME = 1900, XML_XPTR_CHILDSEQ_START, /* 1901 */ XML_XPTR_EVAL_FAILED, /* 1902 */ @@ -752,6 +761,18 @@ typedef enum { XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3, /* 3077 */ XML_SCHEMAP_AU_PROPS_CORRECT_2, /* 3078 */ XML_SCHEMAP_A_PROPS_CORRECT_2, /* 3079 */ + XML_SCHEMAP_C_PROPS_CORRECT, /* 3080 */ + XML_SCHEMAP_SRC_REDEFINE, /* 3081 */ + XML_SCHEMAP_SRC_IMPORT, /* 3082 */ + XML_SCHEMAP_WARN_SKIP_SCHEMA, /* 3083 */ + XML_SCHEMAP_WARN_UNLOCATED_SCHEMA, /* 3084 */ + XML_SCHEMAP_WARN_ATTR_REDECL_PROH, /* 3085 */ + XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH, /* 3085 */ + XML_SCHEMAP_AG_PROPS_CORRECT, /* 3086 */ + XML_SCHEMAP_COS_CT_EXTENDS_1_2, /* 3087 */ + XML_SCHEMAP_AU_PROPS_CORRECT, /* 3088 */ + XML_SCHEMAP_A_PROPS_CORRECT_3, /* 3089 */ + XML_SCHEMAP_COS_ALL_LIMITED, /* 3090 */ XML_MODULE_OPEN = 4900, /* 4900 */ XML_MODULE_CLOSE, /* 4901 */ XML_CHECK_FOUND_ELEMENT = 5000, @@ -791,7 +812,12 @@ typedef enum { XML_CHECK_NOT_NCNAME, /* 5034 */ XML_CHECK_OUTSIDE_DICT, /* 5035 */ XML_CHECK_WRONG_NAME, /* 5036 */ - XML_CHECK_NAME_NOT_NULL /* 5037 */ + XML_CHECK_NAME_NOT_NULL, /* 5037 */ + XML_I18N_NO_NAME = 6000, + XML_I18N_NO_HANDLER, /* 6001 */ + XML_I18N_EXCESS_HANDLER, /* 6002 */ + XML_I18N_CONV_FAILED, /* 6003 */ + XML_I18N_NO_OUTPUT /* 6004 */ #if 0 XML_CHECK_, /* 5033 */ XML_CHECK_X /* 503 */ @@ -807,7 +833,7 @@ typedef enum { * Signature of the function to use when there is an error and * no parsing or validity context available . */ -typedef void (*xmlGenericErrorFunc) (void *ctx, +typedef void (XMLCDECL *xmlGenericErrorFunc) (void *ctx, const char *msg, ...); /** @@ -818,7 +844,7 @@ typedef void (*xmlGenericErrorFunc) (void *ctx, * Signature of the function to use when there is an error and * the module handles the new error reporting mechanism. */ -typedef void (*xmlStructuredErrorFunc) (void *userData, xmlErrorPtr error); +typedef void (XMLCALL *xmlStructuredErrorFunc) (void *userData, xmlErrorPtr error); /* * Use the following function to reset the two global variables @@ -837,19 +863,19 @@ XMLPUBFUN void XMLCALL * Default message routines used by SAX and Valid context for error * and warning reporting. */ -XMLPUBFUN void XMLCALL +XMLPUBFUN void XMLCDECL xmlParserError (void *ctx, const char *msg, ...); -XMLPUBFUN void XMLCALL +XMLPUBFUN void XMLCDECL xmlParserWarning (void *ctx, const char *msg, ...); -XMLPUBFUN void XMLCALL +XMLPUBFUN void XMLCDECL xmlParserValidityError (void *ctx, const char *msg, ...); -XMLPUBFUN void XMLCALL +XMLPUBFUN void XMLCDECL xmlParserValidityWarning (void *ctx, const char *msg, ...); diff --git a/Extras/LibXML/include/libxml/xmlexports.h b/Extras/LibXML/include/libxml/xmlexports.h index ee03cad13..29a6f54f7 100644 --- a/Extras/LibXML/include/libxml/xmlexports.h +++ b/Extras/LibXML/include/libxml/xmlexports.h @@ -40,6 +40,13 @@ * Macros which declare the called convention for exported functions */ #define XMLCALL +/** + * XMLCDECL: + * + * Macro which declares the calling convention for exported functions that + * use '...'. + */ +#define XMLCDECL /** DOC_DISABLE */ @@ -48,6 +55,7 @@ #undef XMLPUBFUN #undef XMLPUBVAR #undef XMLCALL + #undef XMLCDECL #if defined(IN_LIBXML) && !defined(LIBXML_STATIC) #define XMLPUBFUN __declspec(dllexport) #define XMLPUBVAR __declspec(dllexport) @@ -59,7 +67,12 @@ #define XMLPUBVAR extern #endif #endif - #define XMLCALL __cdecl + #if defined(LIBXML_FASTCALL) + #define XMLCALL __fastcall + #else + #define XMLCALL __cdecl + #endif + #define XMLCDECL __cdecl #if !defined _REENTRANT #define _REENTRANT #endif @@ -70,6 +83,7 @@ #undef XMLPUBFUN #undef XMLPUBVAR #undef XMLCALL + #undef XMLCDECL #if defined(IN_LIBXML) && !defined(LIBXML_STATIC) #define XMLPUBFUN __declspec(dllexport) #define XMLPUBVAR __declspec(dllexport) extern @@ -82,6 +96,7 @@ #endif #endif #define XMLCALL __cdecl + #define XMLCDECL __cdecl #if !defined _REENTRANT #define _REENTRANT #endif @@ -92,6 +107,7 @@ #undef XMLPUBFUN #undef XMLPUBVAR #undef XMLCALL + #undef XMLCDECL #if defined(IN_LIBXML) && !defined(LIBXML_STATIC) #define XMLPUBFUN __declspec(dllexport) #define XMLPUBVAR __declspec(dllexport) @@ -104,6 +120,7 @@ #endif #endif #define XMLCALL __cdecl + #define XMLCDECL __cdecl #if !defined _REENTRANT #define _REENTRANT #endif @@ -114,6 +131,7 @@ #undef XMLPUBFUN #undef XMLPUBVAR #undef XMLCALL + #undef XMLCDECL #if defined(IN_LIBXML) && !defined(LIBXML_STATIC) #define XMLPUBFUN __declspec(dllexport) #define XMLPUBVAR __declspec(dllexport) @@ -126,6 +144,7 @@ #endif #endif #define XMLCALL __cdecl + #define XMLCDECL __cdecl #endif /* Compatibility */ diff --git a/Extras/LibXML/include/libxml/xmlmemory.h b/Extras/LibXML/include/libxml/xmlmemory.h index 4c6d18728..235721cea 100644 --- a/Extras/LibXML/include/libxml/xmlmemory.h +++ b/Extras/LibXML/include/libxml/xmlmemory.h @@ -88,14 +88,13 @@ typedef char *(XMLCALL *xmlStrdupFunc)(const char *str); /* * The 4 interfaces used for all memory handling within libxml. +LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree; +LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc; +LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic; +LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc; +LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup; */ -LIBXML_DLL_IMPORT xmlFreeFunc xmlFree; -LIBXML_DLL_IMPORT xmlMallocFunc xmlMalloc; -LIBXML_DLL_IMPORT xmlMallocFunc xmlMallocAtomic; -LIBXML_DLL_IMPORT xmlReallocFunc xmlRealloc; -LIBXML_DLL_IMPORT xmlStrdupFunc xmlMemStrdup; - /* * The way to overload the existing functions. * The xmlGc function have an extra entry for atomic block @@ -138,9 +137,9 @@ XMLPUBFUN void XMLCALL /* * These are specific to the XML debug memory wrapper. */ -XMLPUBFUN size_t XMLCALL +XMLPUBFUN int XMLCALL xmlMemUsed (void); -XMLPUBFUN size_t XMLCALL +XMLPUBFUN int XMLCALL xmlMemBlocks (void); XMLPUBFUN void XMLCALL xmlMemDisplay (FILE *fp); diff --git a/Extras/LibXML/include/libxml/xmlreader.h b/Extras/LibXML/include/libxml/xmlreader.h index 3b32d39a5..1d12988f1 100644 --- a/Extras/LibXML/include/libxml/xmlreader.h +++ b/Extras/LibXML/include/libxml/xmlreader.h @@ -15,6 +15,7 @@ #include #ifdef LIBXML_SCHEMAS_ENABLED #include +#include #endif #ifdef LIBXML_READER_ENABLED @@ -120,10 +121,15 @@ XMLPUBFUN void XMLCALL */ XMLPUBFUN int XMLCALL xmlTextReaderRead (xmlTextReaderPtr reader); + +#ifdef LIBXML_WRITER_ENABLED XMLPUBFUN xmlChar * XMLCALL xmlTextReaderReadInnerXml (xmlTextReaderPtr reader); + XMLPUBFUN xmlChar * XMLCALL xmlTextReaderReadOuterXml (xmlTextReaderPtr reader); +#endif + XMLPUBFUN xmlChar * XMLCALL xmlTextReaderReadString (xmlTextReaderPtr reader); XMLPUBFUN int XMLCALL @@ -247,7 +253,7 @@ XMLPUBFUN xmlNodePtr XMLCALL XMLPUBFUN int XMLCALL xmlTextReaderGetParserLineNumber(xmlTextReaderPtr reader); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlTextReaderGetParserColumnNumber(xmlTextReaderPtr reader); XMLPUBFUN xmlNodePtr XMLCALL @@ -275,6 +281,16 @@ XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema); +XMLPUBFUN int XMLCALL + xmlTextReaderSchemaValidate (xmlTextReaderPtr reader, + const char *xsd); +XMLPUBFUN int XMLCALL + xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader, + xmlSchemaValidCtxtPtr ctxt, + int options); +XMLPUBFUN int XMLCALL + xmlTextReaderSetSchema (xmlTextReaderPtr reader, + xmlSchemaPtr schema); #endif XMLPUBFUN const xmlChar * XMLCALL xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader); @@ -285,7 +301,7 @@ XMLPUBFUN int XMLCALL /* * Index lookup */ -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN long XMLCALL xmlTextReaderByteConsumed (xmlTextReaderPtr reader); /* @@ -304,7 +320,7 @@ XMLPUBFUN xmlTextReaderPtr XMLCALL int options); XMLPUBFUN xmlTextReaderPtr XMLCALL xmlReaderForMemory (const char *buffer, - intptr_t size, + int size, const char *URL, const char *encoding, int options); @@ -338,7 +354,7 @@ XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL xmlReaderNewMemory (xmlTextReaderPtr reader, const char *buffer, - intptr_t size, + int size, const char *URL, const char *encoding, int options); diff --git a/Extras/LibXML/include/libxml/xmlregexp.h b/Extras/LibXML/include/libxml/xmlregexp.h index a7b3b2931..022cd6a98 100644 --- a/Extras/LibXML/include/libxml/xmlregexp.h +++ b/Extras/LibXML/include/libxml/xmlregexp.h @@ -40,6 +40,7 @@ typedef xmlRegExecCtxt *xmlRegExecCtxtPtr; } #endif #include +#include #ifdef __cplusplus extern "C" { #endif @@ -99,6 +100,113 @@ XMLPUBFUN int XMLCALL int *nbneg, xmlChar **values, int *terminal); +#ifdef LIBXML_EXPR_ENABLED +/* + * Formal regular expression handling + * Its goal is to do some formal work on content models + */ + +/* expressions are used within a context */ +typedef struct _xmlExpCtxt xmlExpCtxt; +typedef xmlExpCtxt *xmlExpCtxtPtr; + +XMLPUBFUN void XMLCALL + xmlExpFreeCtxt (xmlExpCtxtPtr ctxt); +XMLPUBFUN xmlExpCtxtPtr XMLCALL + xmlExpNewCtxt (int maxNodes, + xmlDictPtr dict); + +XMLPUBFUN int XMLCALL + xmlExpCtxtNbNodes(xmlExpCtxtPtr ctxt); +XMLPUBFUN int XMLCALL + xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt); + +/* Expressions are trees but the tree is opaque */ +typedef struct _xmlExpNode xmlExpNode; +typedef xmlExpNode *xmlExpNodePtr; + +typedef enum { + XML_EXP_EMPTY = 0, + XML_EXP_FORBID = 1, + XML_EXP_ATOM = 2, + XML_EXP_SEQ = 3, + XML_EXP_OR = 4, + XML_EXP_COUNT = 5 +} xmlExpNodeType; + +/* + * 2 core expressions shared by all for the empty language set + * and for the set with just the empty token + */ +XMLPUBVAR xmlExpNodePtr forbiddenExp; +XMLPUBVAR xmlExpNodePtr emptyExp; + +/* + * Expressions are reference counted internally + */ +XMLPUBFUN void XMLCALL + xmlExpFree (xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr); +XMLPUBFUN void XMLCALL + xmlExpRef (xmlExpNodePtr expr); + +/* + * constructors can be either manual or from a string + */ +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpParse (xmlExpCtxtPtr ctxt, + const char *expr); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpNewAtom (xmlExpCtxtPtr ctxt, + const xmlChar *name, + int len); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpNewOr (xmlExpCtxtPtr ctxt, + xmlExpNodePtr left, + xmlExpNodePtr right); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpNewSeq (xmlExpCtxtPtr ctxt, + xmlExpNodePtr left, + xmlExpNodePtr right); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpNewRange (xmlExpCtxtPtr ctxt, + xmlExpNodePtr subset, + int min, + int max); +/* + * The really interesting APIs + */ +XMLPUBFUN int XMLCALL + xmlExpIsNillable(xmlExpNodePtr expr); +XMLPUBFUN int XMLCALL + xmlExpMaxToken (xmlExpNodePtr expr); +XMLPUBFUN int XMLCALL + xmlExpGetLanguage(xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr, + const xmlChar**langList, + int len); +XMLPUBFUN int XMLCALL + xmlExpGetStart (xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr, + const xmlChar**tokList, + int len); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpStringDerive(xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr, + const xmlChar *str, + int len); +XMLPUBFUN xmlExpNodePtr XMLCALL + xmlExpExpDerive (xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr, + xmlExpNodePtr sub); +XMLPUBFUN int XMLCALL + xmlExpSubsume (xmlExpCtxtPtr ctxt, + xmlExpNodePtr expr, + xmlExpNodePtr sub); +XMLPUBFUN void XMLCALL + xmlExpDump (xmlBufferPtr buf, + xmlExpNodePtr expr); +#endif /* LIBXML_EXPR_ENABLED */ #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/xmlsave.h b/Extras/LibXML/include/libxml/xmlsave.h index dab8de98f..c71c71a03 100644 --- a/Extras/LibXML/include/libxml/xmlsave.h +++ b/Extras/LibXML/include/libxml/xmlsave.h @@ -27,7 +27,10 @@ extern "C" { * to the xmlSaveToFd() and similar calls. */ typedef enum { - XML_SAVE_FORMAT = 1<<0 /* format save output */ + XML_SAVE_FORMAT = 1<<0, /* format save output */ + XML_SAVE_NO_DECL = 1<<1, /* drop the xml declaration */ + XML_SAVE_NO_EMPTY = 1<<2, /* no empty tags */ + XML_SAVE_NO_XHTML = 1<<3 /* disable XHTML1 specific rules */ } xmlSaveOption; @@ -42,14 +45,12 @@ XMLPUBFUN xmlSaveCtxtPtr XMLCALL xmlSaveToFilename (const char *filename, const char *encoding, int options); -/****** - Not yet implemented. XMLPUBFUN xmlSaveCtxtPtr XMLCALL xmlSaveToBuffer (xmlBufferPtr buffer, const char *encoding, int options); - ******/ + XMLPUBFUN xmlSaveCtxtPtr XMLCALL xmlSaveToIO (xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, @@ -64,9 +65,9 @@ XMLPUBFUN long XMLCALL xmlSaveTree (xmlSaveCtxtPtr ctxt, xmlNodePtr node); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveFlush (xmlSaveCtxtPtr ctxt); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlSaveClose (xmlSaveCtxtPtr ctxt); XMLPUBFUN int XMLCALL xmlSaveSetEscape (xmlSaveCtxtPtr ctxt, diff --git a/Extras/LibXML/include/libxml/xmlschemas.h b/Extras/LibXML/include/libxml/xmlschemas.h index 0af2be559..15faef582 100644 --- a/Extras/LibXML/include/libxml/xmlschemas.h +++ b/Extras/LibXML/include/libxml/xmlschemas.h @@ -87,8 +87,8 @@ typedef xmlSchema *xmlSchemaPtr; /** * A schemas validation context */ -typedef void (*xmlSchemaValidityErrorFunc) (void *ctx, const char *msg, ...); -typedef void (*xmlSchemaValidityWarningFunc) (void *ctx, const char *msg, ...); +typedef void (XMLCDECL *xmlSchemaValidityErrorFunc) (void *ctx, const char *msg, ...); +typedef void (XMLCDECL *xmlSchemaValidityWarningFunc) (void *ctx, const char *msg, ...); typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt; typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr; @@ -113,11 +113,18 @@ XMLPUBFUN void XMLCALL xmlSchemaValidityErrorFunc err, xmlSchemaValidityWarningFunc warn, void *ctx); +XMLPUBFUN void XMLCALL + xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt, + xmlStructuredErrorFunc serror, + void *ctx); XMLPUBFUN int XMLCALL - xmlSchemaGetParserErrors (xmlSchemaParserCtxtPtr ctxt, + xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, xmlSchemaValidityErrorFunc * err, xmlSchemaValidityWarningFunc * warn, void **ctx); +XMLPUBFUN int XMLCALL + xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt); + XMLPUBFUN xmlSchemaPtr XMLCALL xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt); XMLPUBFUN void XMLCALL @@ -135,6 +142,10 @@ XMLPUBFUN void XMLCALL xmlSchemaValidityErrorFunc err, xmlSchemaValidityWarningFunc warn, void *ctx); +XMLPUBFUN void XMLCALL + xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt, + xmlStructuredErrorFunc serror, + void *ctx); XMLPUBFUN int XMLCALL xmlSchemaGetValidErrors (xmlSchemaValidCtxtPtr ctxt, xmlSchemaValidityErrorFunc *err, @@ -156,12 +167,29 @@ XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL xmlSchemaValidateOneElement (xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem); -XMLPUBFUN int XMLCALL +XMLPUBFUN int XMLCALL xmlSchemaValidateStream (xmlSchemaValidCtxtPtr ctxt, xmlParserInputBufferPtr input, xmlCharEncoding enc, xmlSAXHandlerPtr sax, void *user_data); +XMLPUBFUN int XMLCALL + xmlSchemaValidateFile (xmlSchemaValidCtxtPtr ctxt, + const char * filename, + int options); + +/* + * Interface to insert Schemas SAX velidation in a SAX stream + */ +typedef struct _xmlSchemaSAXPlug xmlSchemaSAXPlugStruct; +typedef xmlSchemaSAXPlugStruct *xmlSchemaSAXPlugPtr; + +XMLPUBFUN xmlSchemaSAXPlugPtr XMLCALL + xmlSchemaSAXPlug (xmlSchemaValidCtxtPtr ctxt, + xmlSAXHandlerPtr *sax, + void **user_data); +XMLPUBFUN int XMLCALL + xmlSchemaSAXUnplug (xmlSchemaSAXPlugPtr plug); #ifdef __cplusplus } #endif diff --git a/Extras/LibXML/include/libxml/xmlschemastypes.h b/Extras/LibXML/include/libxml/xmlschemastypes.h index 18014fe93..9a3a7a175 100644 --- a/Extras/LibXML/include/libxml/xmlschemastypes.h +++ b/Extras/LibXML/include/libxml/xmlschemastypes.h @@ -111,13 +111,28 @@ XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL xmlSchemaGetCanonValue (xmlSchemaValPtr val, const xmlChar **retValue); +XMLPUBFUN int XMLCALL + xmlSchemaGetCanonValueWhtsp (xmlSchemaValPtr val, + const xmlChar **retValue, + xmlSchemaWhitespaceValueType ws); +XMLPUBFUN int XMLCALL + xmlSchemaValueAppend (xmlSchemaValPtr prev, + xmlSchemaValPtr cur); +XMLPUBFUN xmlSchemaValPtr XMLCALL + xmlSchemaValueGetNext (xmlSchemaValPtr cur); +XMLPUBFUN const xmlChar * XMLCALL + xmlSchemaValueGetAsString (xmlSchemaValPtr val); +XMLPUBFUN int XMLCALL + xmlSchemaValueGetAsBoolean (xmlSchemaValPtr val); XMLPUBFUN xmlSchemaValPtr XMLCALL xmlSchemaNewStringValue (xmlSchemaValType type, const xmlChar *value); XMLPUBFUN xmlSchemaValPtr XMLCALL xmlSchemaNewNOTATIONValue (const xmlChar *name, const xmlChar *ns); - +XMLPUBFUN xmlSchemaValPtr XMLCALL + xmlSchemaNewQNameValue (const xmlChar *namespaceName, + const xmlChar *localName); XMLPUBFUN int XMLCALL xmlSchemaCompareValuesWhtsp (xmlSchemaValPtr x, xmlSchemaWhitespaceValueType xws, diff --git a/Extras/LibXML/include/libxml/xmlstring.h b/Extras/LibXML/include/libxml/xmlstring.h index a3d186de3..1dfc5ea09 100644 --- a/Extras/LibXML/include/libxml/xmlstring.h +++ b/Extras/LibXML/include/libxml/xmlstring.h @@ -25,7 +25,6 @@ extern "C" { * It's unsigned allowing to pinpoint case where char * are assigned * to xmlChar * (possibly making serialization back impossible). */ - typedef unsigned char xmlChar; /** @@ -42,16 +41,16 @@ XMLPUBFUN xmlChar * XMLCALL xmlStrdup (const xmlChar *cur); XMLPUBFUN xmlChar * XMLCALL xmlStrndup (const xmlChar *cur, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlCharStrndup (const char *cur, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlCharStrdup (const char *cur); XMLPUBFUN xmlChar * XMLCALL xmlStrsub (const xmlChar *str, - intptr_t start, - intptr_t len); + int start, + int len); XMLPUBFUN const xmlChar * XMLCALL xmlStrchr (const xmlChar *str, xmlChar val); @@ -61,28 +60,28 @@ XMLPUBFUN const xmlChar * XMLCALL XMLPUBFUN const xmlChar * XMLCALL xmlStrcasestr (const xmlChar *str, xmlChar *val); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrcmp (const xmlChar *str1, const xmlChar *str2); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrncmp (const xmlChar *str1, const xmlChar *str2, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlStrcasecmp (const xmlChar *str1, const xmlChar *str2); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrncasecmp (const xmlChar *str1, const xmlChar *str2, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlStrEqual (const xmlChar *str1, const xmlChar *str2); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrQEqual (const xmlChar *pref, const xmlChar *name, const xmlChar *str); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrlen (const xmlChar *str); XMLPUBFUN xmlChar * XMLCALL xmlStrcat (xmlChar *cur, @@ -90,48 +89,48 @@ XMLPUBFUN xmlChar * XMLCALL XMLPUBFUN xmlChar * XMLCALL xmlStrncat (xmlChar *cur, const xmlChar *add, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlStrncatNew (const xmlChar *str1, const xmlChar *str2, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int len); +XMLPUBFUN int XMLCALL xmlStrPrintf (xmlChar *buf, - intptr_t len, + int len, const xmlChar *msg, ...); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlStrVPrintf (xmlChar *buf, - intptr_t len, + int len, const xmlChar *msg, va_list ap); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlGetUTF8Char (const unsigned char *utf, - intptr_t *len); -XMLPUBFUN intptr_t XMLCALL + int *len); +XMLPUBFUN int XMLCALL xmlCheckUTF8 (const unsigned char *utf); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlUTF8Strsize (const xmlChar *utf, - intptr_t len); + int len); XMLPUBFUN xmlChar * XMLCALL xmlUTF8Strndup (const xmlChar *utf, - intptr_t len); + int len); XMLPUBFUN const xmlChar * XMLCALL xmlUTF8Strpos (const xmlChar *utf, - intptr_t pos); -XMLPUBFUN intptr_t XMLCALL + int pos); +XMLPUBFUN int XMLCALL xmlUTF8Strloc (const xmlChar *utf, const xmlChar *utfchar); XMLPUBFUN xmlChar * XMLCALL xmlUTF8Strsub (const xmlChar *utf, - intptr_t start, - intptr_t len); -XMLPUBFUN intptr_t XMLCALL + int start, + int len); +XMLPUBFUN int XMLCALL xmlUTF8Strlen (const xmlChar *utf); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlUTF8Size (const xmlChar *utf); -XMLPUBFUN intptr_t XMLCALL +XMLPUBFUN int XMLCALL xmlUTF8Charcmp (const xmlChar *utf1, const xmlChar *utf2); diff --git a/Extras/LibXML/include/libxml/xmlunicode.h b/Extras/LibXML/include/libxml/xmlunicode.h index 3882b1fb7..01ac8b61f 100644 --- a/Extras/LibXML/include/libxml/xmlunicode.h +++ b/Extras/LibXML/include/libxml/xmlunicode.h @@ -4,11 +4,11 @@ * * This file is automatically generated from the * UCS description files of the Unicode Character Database - * http://www.unicode.org/Public/4.0-Update1/UCD-4.0.1d5b.html + * http://www.unicode.org/Public/4.0-Update1/UCD-4.0.1.html * using the genUnicode.py Python script. * - * Generation date: Mon Nov 10 22:35:10 2003 - * Sources: Blocks-4.0.1d1b.txt UnicodeData-4.0.1d1b.txt + * Generation date: Mon Mar 27 11:09:52 2006 + * Sources: Blocks-4.0.1.txt UnicodeData-4.0.1.txt * Author: Daniel Veillard */ diff --git a/Extras/LibXML/include/libxml/xmlversion.h b/Extras/LibXML/include/libxml/xmlversion.h index 0dffbcac8..cc75dc027 100644 --- a/Extras/LibXML/include/libxml/xmlversion.h +++ b/Extras/LibXML/include/libxml/xmlversion.h @@ -29,28 +29,28 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * the version string like "1.2.3" */ -#define LIBXML_DOTTED_VERSION "2.6.19" +#define LIBXML_DOTTED_VERSION "2.6.26" /** * LIBXML_VERSION: * * the version number: 1.2.3 value is 1002003 */ -#define LIBXML_VERSION 20619 +#define LIBXML_VERSION 20626 /** * LIBXML_VERSION_STRING: * * the version number string, 1.2.3 value is "1002003" */ -#define LIBXML_VERSION_STRING "20619" +#define LIBXML_VERSION_STRING "20626" /** * LIBXML_VERSION_EXTRA: * * extra version information, used to show a CVS compilation */ -#define LIBXML_VERSION_EXTRA "" +#define LIBXML_VERSION_EXTRA "-CVS2798" /** * LIBXML_TEST_VERSION: @@ -58,7 +58,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * Macro to check that the libxml version in use is compatible with * the version the software has been compiled against */ -#define LIBXML_TEST_VERSION xmlCheckVersion(20619); +#define LIBXML_TEST_VERSION xmlCheckVersion(20626); #ifndef VMS #if 0 @@ -90,7 +90,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the thread support is configured in */ -#if 0 +#if 1 #if defined(_REENTRANT) || defined(__MT__) || (_POSIX_C_SOURCE - 0 >= 199506L) #define LIBXML_THREAD_ENABLED #endif @@ -137,7 +137,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the xmlPattern node selection interface is configured in */ -#if 0 +#if 1 #define LIBXML_PATTERN_ENABLED #endif @@ -164,7 +164,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the FTP support is configured in */ -#if 0 +#if 1 #define LIBXML_FTP_ENABLED #endif @@ -173,7 +173,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the HTTP support is configured in */ -#if 0 +#if 1 #define LIBXML_HTTP_ENABLED #endif @@ -182,7 +182,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the DTD validation support is configured in */ -#if 0 +#if 1 #define LIBXML_VALID_ENABLED #endif @@ -191,7 +191,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the HTML support is configured in */ -#if 0 +#if 1 #define LIBXML_HTML_ENABLED #endif @@ -200,7 +200,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the deprecated APIs are compiled in for compatibility */ -#if 0 +#if 1 #define LIBXML_LEGACY_ENABLED #endif @@ -209,7 +209,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the Canonicalization support is configured in */ -#if 0 +#if 1 #define LIBXML_C14N_ENABLED #endif @@ -218,7 +218,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the Catalog support is configured in */ -#if 0 +#if 1 #define LIBXML_CATALOG_ENABLED #endif @@ -227,7 +227,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the SGML Docbook support is configured in */ -#if 0 +#if 1 #define LIBXML_DOCB_ENABLED #endif @@ -236,7 +236,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether XPath is configured in */ -#if 0 +#if 1 #define LIBXML_XPATH_ENABLED #endif @@ -245,7 +245,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether XPointer is configured in */ -#if 0 +#if 1 #define LIBXML_XPTR_ENABLED #endif @@ -254,7 +254,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether XInclude is configured in */ -#if 0 +#if 1 #define LIBXML_XINCLUDE_ENABLED #endif @@ -263,7 +263,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether iconv support is available */ -#if 0 +#if 1 #define LIBXML_ICONV_ENABLED #endif @@ -272,7 +272,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether ISO-8859-* support is made available in case iconv is not */ -#if 0 +#if 1 #define LIBXML_ISO8859X_ENABLED #endif @@ -281,7 +281,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether Debugging module is configured in */ -#if 0 +#if 1 #define LIBXML_DEBUG_ENABLED #endif @@ -290,7 +290,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the memory debugging is configured in */ -#if 0 +#if 1 #define DEBUG_MEMORY_LOCATION #endif @@ -299,7 +299,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the runtime debugging is configured in */ -#if 0 +#if 1 #define LIBXML_DEBUG_RUNTIME #endif @@ -317,7 +317,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the regular expressions interfaces are compiled in */ -#if 0 +#if 1 #define LIBXML_REGEXP_ENABLED #endif @@ -326,27 +326,50 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); * * Whether the automata interfaces are compiled in */ -#if 0 +#if 1 #define LIBXML_AUTOMATA_ENABLED #endif +/** + * LIBXML_EXPR_ENABLED: + * + * Whether the formal expressions interfaces are compiled in + */ +#if 1 +#define LIBXML_EXPR_ENABLED +#endif + /** * LIBXML_SCHEMAS_ENABLED: * * Whether the Schemas validation interfaces are compiled in */ -#if 0 +#if 1 #define LIBXML_SCHEMAS_ENABLED #endif +/** + * LIBXML_SCHEMATRON_ENABLED: + * + * Whether the Schematron validation interfaces are compiled in + */ +#if 1 +#define LIBXML_SCHEMATRON_ENABLED +#endif + /** * LIBXML_MODULES_ENABLED: * * Whether the module interfaces are compiled in */ -#if 0 +#if 1 #define LIBXML_MODULES_ENABLED -#define LIBXML_MODULE_EXTENSION ".dll" +/** + * LIBXML_MODULE_EXTENSION: + * + * the string suffix used by dynamic modules (usually shared libraries) + */ +#define LIBXML_MODULE_EXTENSION ".so" #endif /** diff --git a/Extras/LibXML/include/libxml/xmlwriter.h b/Extras/LibXML/include/libxml/xmlwriter.h index 1ad0768db..31ceb5f1a 100644 --- a/Extras/LibXML/include/libxml/xmlwriter.h +++ b/Extras/LibXML/include/libxml/xmlwriter.h @@ -53,28 +53,28 @@ extern "C" { /* * Document */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version, const char *encoding, const char *standalone); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndDocument(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterEndDocument(xmlTextWriterPtr writer); /* * Comments */ - XMLPUBFUN intptr_t XMLCALL xmlTextWriterStartComment(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterStartComment(xmlTextWriterPtr writer); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndComment(xmlTextWriterPtr writer); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterEndComment(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteComment(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content); @@ -82,51 +82,51 @@ extern "C" { /* * Elements */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterStartElementNS(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterStartElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndElement(xmlTextWriterPtr writer); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterFullEndElement(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterEndElement(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterFullEndElement(xmlTextWriterPtr writer); /* * Elements conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteElement(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteElementNS(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, @@ -139,44 +139,44 @@ extern "C" { /* * Text */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, - const xmlChar * content, intptr_t len); - XMLPUBFUN intptr_t XMLCALL + const xmlChar * content, int len); + XMLPUBFUN int XMLCALL xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteFormatString(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteVFormatString(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteString(xmlTextWriterPtr writer, + XMLPUBFUN int XMLCALL xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteBase64(xmlTextWriterPtr writer, + XMLPUBFUN int XMLCALL xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data, - intptr_t start, intptr_t len); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, + int start, int len); + XMLPUBFUN int XMLCALL xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data, - intptr_t start, intptr_t len); + int start, int len); /* * Attributes */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterStartAttributeNS(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, @@ -184,40 +184,40 @@ extern "C" { name, const xmlChar * namespaceURI); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndAttribute(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterEndAttribute(xmlTextWriterPtr writer); /* * Attributes conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteAttribute(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteAttributeNS(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, @@ -231,23 +231,23 @@ extern "C" { /* * PI's */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndPI(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterEndPI(xmlTextWriterPtr writer); /* * PI conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer, const xmlChar * target, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target, const xmlChar * content); @@ -262,48 +262,48 @@ extern "C" { /* * CDATA */ - XMLPUBFUN intptr_t XMLCALL xmlTextWriterStartCDATA(xmlTextWriterPtr writer); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndCDATA(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterStartCDATA(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterEndCDATA(xmlTextWriterPtr writer); /* * CDATA conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content); /* * DTD */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndDTD(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterEndDTD(xmlTextWriterPtr writer); /* * DTD conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, @@ -320,25 +320,25 @@ extern "C" { /* * DTD element definition */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndDTDElement(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDElement(xmlTextWriterPtr writer); /* * DTD element definition conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteDTDElement(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer, const xmlChar * name, @@ -348,25 +348,25 @@ extern "C" { /* * DTD attribute list definition */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndDTDAttlist(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer); /* * DTD attribute list definition conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, @@ -376,47 +376,47 @@ extern "C" { /* * DTD entity definition */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, - intptr_t pe, const xmlChar * name); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterEndDTDEntity(xmlTextWriterPtr + int pe, const xmlChar * name); + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer); /* * DTD entity definition conveniency functions */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const char *format, ...); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const xmlChar * content); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const xmlChar * ndataid); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer, const xmlChar * pubid, const xmlChar * sysid, const xmlChar * ndataid); - XMLPUBFUN intptr_t XMLCALL xmlTextWriterWriteDTDEntity(xmlTextWriterPtr - writer, intptr_t pe, + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDEntity(xmlTextWriterPtr + writer, int pe, const xmlChar * name, const xmlChar * pubid, @@ -430,7 +430,7 @@ extern "C" { /* * DTD notation definition */ - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, @@ -439,16 +439,16 @@ extern "C" { /* * Indentation */ - XMLPUBFUN intptr_t XMLCALL - xmlTextWriterSetIndent(xmlTextWriterPtr writer, intptr_t indent); - XMLPUBFUN intptr_t XMLCALL + XMLPUBFUN int XMLCALL + xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent); + XMLPUBFUN int XMLCALL xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str); /* * misc */ - XMLPUBFUN intptr_t XMLCALL xmlTextWriterFlush(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterFlush(xmlTextWriterPtr writer); #ifdef __cplusplus } diff --git a/Extras/LibXML/include/libxml/xpath.h b/Extras/LibXML/include/libxml/xpath.h index eee263056..be8780c74 100644 --- a/Extras/LibXML/include/libxml/xpath.h +++ b/Extras/LibXML/include/libxml/xpath.h @@ -35,6 +35,7 @@ extern "C" { #endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */ #ifdef LIBXML_XPATH_ENABLED + typedef struct _xmlXPathContext xmlXPathContext; typedef xmlXPathContext *xmlXPathContextPtr; typedef struct _xmlXPathParserContext xmlXPathParserContext; @@ -248,6 +249,23 @@ typedef xmlXPathFunction (*xmlXPathFuncLookupFunc) (void *ctxt, const xmlChar *name, const xmlChar *ns_uri); +/** + * xmlXPathFlags: + * Flags for XPath engine compilation and runtime + */ +/** + * XML_XPATH_CHECKNS: + * + * check namespaces at compilation + */ +#define XML_XPATH_CHECKNS (1<<0) +/** + * XML_XPATH_NOVAR: + * + * forbid variables in expression + */ +#define XML_XPATH_NOVAR (1<<1) + /** * xmlXPathContext: * @@ -324,6 +342,10 @@ struct _xmlXPathContext { /* dictionnary */ xmlDictPtr dict; /* dictionnary if any */ + + int flags; /* flags to control compilation */ + /* Cache for reusal of XPath objects */ + void *cache; }; /* @@ -466,9 +488,13 @@ XMLPUBFUN xmlXPathObjectPtr XMLCALL */ XMLPUBFUN xmlXPathContextPtr XMLCALL xmlXPathNewContext (xmlDocPtr doc); -XMLPUBFUN void XMLCALL +XMLPUBFUN void XMLCALL xmlXPathFreeContext (xmlXPathContextPtr ctxt); - +XMLPUBFUN int XMLCALL + xmlXPathContextSetCache(xmlXPathContextPtr ctxt, + int active, + int value, + int options); /** * Evaluation functions. */ diff --git a/Extras/LibXML/include/win32config.h b/Extras/LibXML/include/win32config.h index 9c75afd7e..c61dfa99e 100644 --- a/Extras/LibXML/include/win32config.h +++ b/Extras/LibXML/include/win32config.h @@ -84,10 +84,12 @@ static int isnan (double d) { #endif #endif /* _MSC_VER */ -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_MSC_VER) #define mkdir(p,m) _mkdir(p) #define snprintf _snprintf #define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a) +#elif defined(__MINGW32__) +#define mkdir(p,m) _mkdir(p) #endif /* Threading API to use should be specified here for compatibility reasons. diff --git a/Extras/LibXML/include/wsockcompat.h b/Extras/LibXML/include/wsockcompat.h index 16cb7669c..333b5614f 100644 --- a/Extras/LibXML/include/wsockcompat.h +++ b/Extras/LibXML/include/wsockcompat.h @@ -7,11 +7,29 @@ #ifdef _WIN32_WCE #include -#elif defined (WIN32) +#else #undef HAVE_ERRNO_H #include -#elif defined (LINUX) -#include + +/* the following is a workaround a problem for 'inline' keyword in said + header when compiled with Borland C++ 6 */ +#if defined(__BORLANDC__) && !defined(__cplusplus) +#define inline __inline +#endif + +#include + +/* Check if ws2tcpip.h is a recent version which provides getaddrinfo() */ +#if defined(GetAddrInfo) +#define HAVE_GETADDRINFO +#endif +#endif + +#ifdef __MINGW32__ +/* Include here to ensure that it doesn't get included later + * (e.g. by iconv.h) and overwrites the definition of EWOULDBLOCK. */ +#include +#undef EWOULDBLOCK #endif #if !defined SOCKLEN_T diff --git a/Extras/LibXML/legacy.c b/Extras/LibXML/legacy.c index bbbd2c98e..e75178a02 100644 --- a/Extras/LibXML/legacy.c +++ b/Extras/LibXML/legacy.c @@ -673,7 +673,6 @@ xmlHandleEntity(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, * * Creation of a Namespace, the old way using PI and without scoping * DEPRECATED !!! - * It now create a namespace on the root element of the document if found. * Returns NULL this functionality had been removed */ xmlNsPtr diff --git a/Extras/LibXML/libxml.h b/Extras/LibXML/libxml.h index 6163c3c74..696be62e7 100644 --- a/Extras/LibXML/libxml.h +++ b/Extras/LibXML/libxml.h @@ -19,10 +19,17 @@ #endif #if defined(macintosh) - #include "config-mac.h" +#include "config-mac.h" #else - #include "config.h" - #include +#include "config.h" +#include +#endif + +#if defined(__Lynx__) +#include /* pull definition of size_t */ +#include +int snprintf(char *, size_t, const char *, ...); +int vfprintf(FILE *, const char *, va_list); #endif #ifndef WITH_TRIO @@ -49,6 +56,14 @@ extern int __xmlRegisterCallbacks; */ void __xmlIOErr(int domain, int code, const char *extra); void __xmlLoaderErr(void *ctx, const char *msg, const char *filename); +#ifdef LIBXML_HTML_ENABLED +/* + * internal function of HTML parser needed for xmlParseInNodeContext + * but not part of the API + */ +void __htmlParseContent(void *ctx); +#endif + #ifdef IN_LIBXML #ifdef __GNUC__ diff --git a/Extras/LibXML/nanoftp.c b/Extras/LibXML/nanoftp.c index e4319cf1e..c78503bf5 100644 --- a/Extras/LibXML/nanoftp.c +++ b/Extras/LibXML/nanoftp.c @@ -94,9 +94,6 @@ #endif #define SOCKET int #endif -#if defined(VMS) || defined(__VMS) -#define XML_SOCKLEN_T unsigned int -#endif #ifdef __BEOS__ #ifndef PF_INET @@ -108,10 +105,14 @@ #define ss_family __ss_family #endif +#ifndef XML_SOCKLEN_T +#define XML_SOCKLEN_T unsigned int +#endif + #define FTP_COMMAND_OK 200 #define FTP_SYNTAX_ERROR 500 #define FTP_GET_PASSWD 331 -#define FTP_BUF_SIZE 512 +#define FTP_BUF_SIZE 1024 #define XML_NANO_MAX_URLBUF 4096 @@ -315,7 +316,7 @@ xmlNanoFTPScanURL(void *ctx, const char *URL) { } if (URL == NULL) return; - uri = xmlParseURI(URL); + uri = xmlParseURIRaw(URL, 1); if (uri == NULL) return; @@ -376,7 +377,7 @@ xmlNanoFTPUpdateURL(void *ctx, const char *URL) { if (ctxt->hostname == NULL) return(-1); - uri = xmlParseURI(URL); + uri = xmlParseURIRaw(URL, 1); if (uri == NULL) return(-1); @@ -439,7 +440,7 @@ xmlNanoFTPScanProxy(const char *URL) { #endif if (URL == NULL) return; - uri = xmlParseURI(URL); + uri = xmlParseURIRaw(URL, 1); if ((uri == NULL) || (uri->scheme == NULL) || (strcmp(uri->scheme, "ftp")) || (uri->server == NULL)) { __xmlIOErr(XML_FROM_FTP, XML_FTP_URL_SYNTAX, "Syntax Error\n"); @@ -943,7 +944,7 @@ xmlNanoFTPConnect(void *ctx) { ((struct sockaddr_in *)&ctxt->ftpAddr)->sin_family = AF_INET; memcpy (&((struct sockaddr_in *)&ctxt->ftpAddr)->sin_addr, hp->h_addr_list[0], hp->h_length); - ((struct sockaddr_in *)&ctxt->ftpAddr)->sin_port = htons (port); + ((struct sockaddr_in *)&ctxt->ftpAddr)->sin_port = (u_short)htons ((unsigned short)port); ctxt->controlFd = socket (AF_INET, SOCK_STREAM, 0); addrlen = sizeof (struct sockaddr_in); } diff --git a/Extras/LibXML/nanohttp.c b/Extras/LibXML/nanohttp.c index 9897c14ab..ae7923f14 100644 --- a/Extras/LibXML/nanohttp.c +++ b/Extras/LibXML/nanohttp.c @@ -11,9 +11,6 @@ * daniel@veillard.com */ -/* TODO add compression support, Send the Accept- , and decompress on the - fly with ZLIB if found at compile-time */ - #define NEED_SOCKETS #define IN_LIBXML #include "libxml.h" @@ -66,6 +63,10 @@ #ifdef SUPPORT_IP6 #include #endif +#ifdef HAVE_ZLIB_H +#include +#endif + #ifdef VMS #include @@ -134,6 +135,7 @@ typedef struct xmlNanoHTTPCtxt { char *hostname; /* the host name */ int port; /* the port */ char *path; /* the path within the URL */ + char *query; /* the query string */ SOCKET fd; /* the file descriptor for the socket */ int state; /* WRITE / READ / CLOSED */ char *out; /* buffer sent (zero terminated) */ @@ -151,6 +153,10 @@ typedef struct xmlNanoHTTPCtxt { char *authHeader; /* contents of {WWW,Proxy}-Authenticate header */ char *encoding; /* encoding extracted from the contentType */ char *mimeType; /* Mime-Type extracted from the contentType */ +#ifdef HAVE_ZLIB_H + z_stream *strm; /* Zlib stream object */ + int usesGzip; /* "Content-Encoding: gzip" was detected */ +#endif } xmlNanoHTTPCtxt, *xmlNanoHTTPCtxtPtr; static int initialized = 0; @@ -247,8 +253,10 @@ done: void xmlNanoHTTPCleanup(void) { - if (proxy != NULL) + if (proxy != NULL) { xmlFree(proxy); + proxy = NULL; + } #ifdef _WINSOCKAPI_ if (initialized) WSACleanup(); @@ -284,9 +292,13 @@ xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) { xmlFree(ctxt->path); ctxt->path = NULL; } + if (ctxt->query != NULL) { + xmlFree(ctxt->query); + ctxt->query = NULL; + } if (URL == NULL) return; - uri = xmlParseURI(URL); + uri = xmlParseURIRaw(URL, 1); if (uri == NULL) return; @@ -301,6 +313,8 @@ xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) { ctxt->path = xmlMemStrdup(uri->path); else ctxt->path = xmlMemStrdup("/"); + if (uri->query != NULL) + ctxt->query = xmlMemStrdup(uri->query); if (uri->port != 0) ctxt->port = uri->port; @@ -337,7 +351,7 @@ xmlNanoHTTPScanProxy(const char *URL) { #endif if (URL == NULL) return; - uri = xmlParseURI(URL); + uri = xmlParseURIRaw(URL, 1); if ((uri == NULL) || (uri->scheme == NULL) || (strcmp(uri->scheme, "http")) || (uri->server == NULL)) { __xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, "Syntax Error\n"); @@ -396,6 +410,7 @@ xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) { if (ctxt->hostname != NULL) xmlFree(ctxt->hostname); if (ctxt->protocol != NULL) xmlFree(ctxt->protocol); if (ctxt->path != NULL) xmlFree(ctxt->path); + if (ctxt->query != NULL) xmlFree(ctxt->query); if (ctxt->out != NULL) xmlFree(ctxt->out); if (ctxt->in != NULL) xmlFree(ctxt->in); if (ctxt->contentType != NULL) xmlFree(ctxt->contentType); @@ -403,6 +418,13 @@ xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) { if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType); if (ctxt->location != NULL) xmlFree(ctxt->location); if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); +#ifdef HAVE_ZLIB_H + if (ctxt->strm != NULL) { + inflateEnd(ctxt->strm); + xmlFree(ctxt->strm); + } +#endif + ctxt->state = XML_NANO_HTTP_NONE; if (ctxt->fd >= 0) closesocket(ctxt->fd); ctxt->fd = -1; @@ -452,7 +474,14 @@ xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char * xmt_ptr, int outlen) { tv.tv_sec = timeout; tv.tv_usec = 0; FD_ZERO( &wfd ); +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4018) +#endif FD_SET( ctxt->fd, &wfd ); +#ifdef _MSC_VER +#pragma warning(pop) +#endif (void)select( ctxt->fd + 1, NULL, &wfd, NULL, &tv ); } } @@ -545,7 +574,14 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt) { tv.tv_sec = timeout; tv.tv_usec = 0; FD_ZERO(&rfd); +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4018) +#endif FD_SET(ctxt->fd, &rfd); +#ifdef _MSC_VER +#pragma warning(pop) +#endif if ( (select(ctxt->fd+1, &rfd, NULL, NULL, &tv)<1) #if defined(EINTR) @@ -728,6 +764,26 @@ xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) { if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); ctxt->authHeader = xmlMemStrdup(cur); +#ifdef HAVE_ZLIB_H + } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Encoding:", 17) ) { + cur += 17; + while ((*cur == ' ') || (*cur == '\t')) cur++; + if ( !xmlStrncasecmp( BAD_CAST cur, BAD_CAST"gzip", 4) ) { + ctxt->usesGzip = 1; + + ctxt->strm = xmlMalloc(sizeof(z_stream)); + + if (ctxt->strm != NULL) { + ctxt->strm->zalloc = Z_NULL; + ctxt->strm->zfree = Z_NULL; + ctxt->strm->opaque = Z_NULL; + ctxt->strm->avail_in = 0; + ctxt->strm->next_in = Z_NULL; + + inflateInit2( ctxt->strm, 31 ); + } + } +#endif } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Length:", 15) ) { cur += 15; ctxt->ContentLength = strtol( cur, NULL, 10 ); @@ -831,7 +887,11 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr) tv.tv_sec = timeout; tv.tv_usec = 0; - + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4018) +#endif FD_ZERO(&wfd); FD_SET(s, &wfd); @@ -842,6 +902,9 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr) switch(select(s+1, NULL, &wfd, &xfd, &tv)) #else switch(select(s+1, NULL, &wfd, NULL, &tv)) +#endif +#ifdef _MSC_VER +#pragma warning(pop) #endif { case 0: @@ -915,14 +978,21 @@ xmlNanoHTTPConnectHost(const char *host, int port) memset (&sockin, 0, sizeof(sockin)); #ifdef SUPPORT_IP6 memset (&sockin6, 0, sizeof(sockin6)); +#endif + +#if !defined(HAVE_GETADDRINFO) && defined(SUPPORT_IP6) && defined(RES_USE_INET6) if (have_ipv6 ()) -#if !defined(HAVE_GETADDRINFO) && defined(RES_USE_INET6) { if (!(_res.options & RES_INIT)) res_init(); _res.options |= RES_USE_INET6; } -#elif defined(HAVE_GETADDRINFO) +#endif + +#if defined(HAVE_GETADDRINFO) && defined(SUPPORT_IP6) && !defined(_WIN32) + if (have_ipv6 ()) +#endif +#if defined(HAVE_GETADDRINFO) && (defined(SUPPORT_IP6) || defined(_WIN32)) { int status; struct addrinfo hints, *res, *result; @@ -938,42 +1008,45 @@ xmlNanoHTTPConnectHost(const char *host, int port) } for (res = result; res; res = res->ai_next) { - if (res->ai_family == AF_INET || res->ai_family == AF_INET6) { - if (res->ai_family == AF_INET6) { - if (res->ai_addrlen > sizeof(sockin6)) { - __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); - freeaddrinfo (result); - return (-1); - } - memcpy (&sockin6, res->ai_addr, res->ai_addrlen); - sockin6.sin6_port = htons (port); - addr = (struct sockaddr *)&sockin6; - } - else { - if (res->ai_addrlen > sizeof(sockin)) { - __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); - freeaddrinfo (result); - return (-1); - } - memcpy (&sockin, res->ai_addr, res->ai_addrlen); - sockin.sin_port = htons (port); - addr = (struct sockaddr *)&sockin; - } - - s = xmlNanoHTTPConnectAttempt (addr); - if (s != -1) { + if (res->ai_family == AF_INET) { + if (res->ai_addrlen > sizeof(sockin)) { + __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); freeaddrinfo (result); - return (s); + return (-1); } + memcpy (&sockin, res->ai_addr, res->ai_addrlen); + sockin.sin_port = htons (port); + addr = (struct sockaddr *)&sockin; +#ifdef SUPPORT_IP6 + } else if (have_ipv6 () && (res->ai_family == AF_INET6)) { + if (res->ai_addrlen > sizeof(sockin6)) { + __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); + freeaddrinfo (result); + return (-1); + } + memcpy (&sockin6, res->ai_addr, res->ai_addrlen); + sockin6.sin6_port = htons (port); + addr = (struct sockaddr *)&sockin6; +#endif + } else + continue; /* for */ + + s = xmlNanoHTTPConnectAttempt (addr); + if (s != -1) { + freeaddrinfo (result); + return (s); } } + if (result) freeaddrinfo (result); - return (-1); - } else + } #endif +#if defined(HAVE_GETADDRINFO) && defined(SUPPORT_IP6) && !defined(_WIN32) + else #endif - { +#if !defined(HAVE_GETADDRINFO) || !defined(_WIN32) + { h = gethostbyname (host); if (h == NULL) { @@ -1026,7 +1099,7 @@ xmlNanoHTTPConnectHost(const char *host, int port) memcpy (&ia, h->h_addr_list[i], h->h_length); sockin.sin_family = h->h_addrtype; sockin.sin_addr = ia; - sockin.sin_port = htons (port); + sockin.sin_port = (u_short)htons ((unsigned short)port); addr = (struct sockaddr *) &sockin; #ifdef SUPPORT_IP6 } else if (have_ipv6 () && (h->h_addrtype == AF_INET6)) { @@ -1049,6 +1122,8 @@ xmlNanoHTTPConnectHost(const char *host, int port) return (s); } } +#endif + #ifdef DEBUG_HTTP xmlGenericError(xmlGenericErrorContext, "xmlNanoHTTPConnectHost: unable to connect to '%s'.\n", @@ -1113,11 +1188,38 @@ xmlNanoHTTPOpenRedir(const char *URL, char **contentType, char **redir) { int xmlNanoHTTPRead(void *ctx, void *dest, int len) { xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx; +#ifdef HAVE_ZLIB_H + int bytes_read = 0; + int orig_avail_in; + int z_ret; +#endif if (ctx == NULL) return(-1); if (dest == NULL) return(-1); if (len <= 0) return(0); +#ifdef HAVE_ZLIB_H + if (ctxt->usesGzip == 1) { + if (ctxt->strm == NULL) return(0); + + ctxt->strm->next_out = dest; + ctxt->strm->avail_out = len; + + do { + orig_avail_in = ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr - bytes_read; + ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read); + + z_ret = inflate(ctxt->strm, Z_NO_FLUSH); + bytes_read += orig_avail_in - ctxt->strm->avail_in; + + if (z_ret != Z_OK) break; + } while (ctxt->strm->avail_out > 0 && xmlNanoHTTPRecv(ctxt) > 0); + + ctxt->inrptr += bytes_read; + return(len - ctxt->strm->avail_out); + } +#endif + while (ctxt->inptr - ctxt->inrptr < len) { if (xmlNanoHTTPRecv(ctxt) <= 0) break; } @@ -1229,7 +1331,12 @@ retry: blen += strlen(headers) + 2; if (contentType && *contentType) blen += strlen(*contentType) + 16; + if (ctxt->query != NULL) + blen += strlen(ctxt->query) + 1; blen += strlen(method) + strlen(ctxt->path) + 24; +#ifdef HAVE_ZLIB_H + blen += 23; +#endif bp = (char*)xmlMallocAtomic(blen); if ( bp == NULL ) { xmlNanoHTTPFreeCtxt( ctxt ); @@ -1252,9 +1359,16 @@ retry: else p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path); + if (ctxt->query != NULL) + p += snprintf( p, blen - (p - bp), "?%s", ctxt->query); + p += snprintf( p, blen - (p - bp), " HTTP/1.0\r\nHost: %s\r\n", ctxt->hostname); +#ifdef HAVE_ZLIB_H + p += snprintf(p, blen - (p - bp), "Accept-Encoding: gzip\r\n"); +#endif + if (contentType != NULL && *contentType) p += snprintf(p, blen - (p - bp), "Content-Type: %s\r\n", *contentType); diff --git a/Extras/LibXML/parser.c b/Extras/LibXML/parser.c index 229f77577..12b2d7f89 100644 --- a/Extras/LibXML/parser.c +++ b/Extras/LibXML/parser.c @@ -147,7 +147,8 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; + if (ctxt != NULL) + ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED; if (prefix == NULL) __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, ctxt->errNo, XML_ERR_FATAL, NULL, 0, @@ -159,9 +160,11 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix, (const char *) prefix, (const char *) localname, NULL, 0, 0, "Attribute %s:%s redefined\n", prefix, localname); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -359,13 +362,16 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info) default: errmsg = "Unregistered error message\n"; } - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg, info); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -383,12 +389,15 @@ xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -410,7 +419,8 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) + if ((ctxt != NULL) && (ctxt->sax != NULL) && + (ctxt->sax->initialized == XML_SAX2_MAGIC)) schannel = ctxt->sax->serror; __xmlRaiseError(schannel, (ctxt->sax) ? ctxt->sax->warning : NULL, @@ -439,16 +449,20 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; - if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) - schannel = ctxt->sax->serror; + if (ctxt != NULL) { + ctxt->errNo = error; + if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC)) + schannel = ctxt->sax->serror; + } __xmlRaiseError(schannel, ctxt->vctxt.error, ctxt->vctxt.userData, ctxt, NULL, XML_FROM_DTD, error, XML_ERR_ERROR, NULL, 0, (const char *) str1, NULL, NULL, 0, 0, msg, (const char *) str1); - ctxt->valid = 0; + if (ctxt != NULL) { + ctxt->valid = 0; + } } /** @@ -467,13 +481,16 @@ xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, val, 0, msg, val); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -495,14 +512,17 @@ xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, NULL, 0, (const char *) str1, (const char *) str2, NULL, val, 0, msg, str1, val, str2); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -521,14 +541,17 @@ xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL, NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg, val); - ctxt->wellFormed = 0; - if (ctxt->recovery == 0) - ctxt->disableSAX = 1; + if (ctxt != NULL) { + ctxt->wellFormed = 0; + if (ctxt->recovery == 0) + ctxt->disableSAX = 1; + } } /** @@ -547,7 +570,8 @@ xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_ERROR, NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg, @@ -573,12 +597,220 @@ xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, if ((ctxt != NULL) && (ctxt->disableSAX != 0) && (ctxt->instate == XML_PARSER_EOF)) return; - ctxt->errNo = error; + if (ctxt != NULL) + ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, XML_ERR_ERROR, NULL, 0, (const char *) info1, (const char *) info2, (const char *) info3, 0, 0, msg, info1, info2, info3); - ctxt->nsWellFormed = 0; + if (ctxt != NULL) + ctxt->nsWellFormed = 0; +} + +/************************************************************************ + * * + * Library wide options * + * * + ************************************************************************/ + +/** + * xmlHasFeature: + * @feature: the feature to be examined + * + * Examines if the library has been compiled with a given feature. + * + * Returns a non-zero value if the feature exist, otherwise zero. + * Returns zero (0) if the feature does not exist or an unknown + * unknown feature is requested, non-zero otherwise. + */ +int +xmlHasFeature(xmlFeature feature) +{ + switch (feature) { + case XML_WITH_THREAD: +#ifdef LIBXML_THREAD_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_TREE: +#ifdef LIBXML_TREE_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_OUTPUT: +#ifdef LIBXML_OUTPUT_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_PUSH: +#ifdef LIBXML_PUSH_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_READER: +#ifdef LIBXML_READER_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_PATTERN: +#ifdef LIBXML_PATTERN_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_WRITER: +#ifdef LIBXML_WRITER_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_SAX1: +#ifdef LIBXML_SAX1_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_FTP: +#ifdef LIBXML_FTP_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_HTTP: +#ifdef LIBXML_HTTP_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_VALID: +#ifdef LIBXML_VALID_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_HTML: +#ifdef LIBXML_HTML_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_LEGACY: +#ifdef LIBXML_LEGACY_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_C14N: +#ifdef LIBXML_C14N_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_CATALOG: +#ifdef LIBXML_CATALOG_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_XPATH: +#ifdef LIBXML_XPATH_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_XPTR: +#ifdef LIBXML_XPTR_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_XINCLUDE: +#ifdef LIBXML_XINCLUDE_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_ICONV: +#ifdef LIBXML_ICONV_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_ISO8859X: +#ifdef LIBXML_ISO8859X_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_UNICODE: +#ifdef LIBXML_UNICODE_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_REGEXP: +#ifdef LIBXML_REGEXP_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_AUTOMATA: +#ifdef LIBXML_AUTOMATA_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_EXPR: +#ifdef LIBXML_EXPR_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_SCHEMAS: +#ifdef LIBXML_SCHEMAS_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_SCHEMATRON: +#ifdef LIBXML_SCHEMATRON_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_MODULES: +#ifdef LIBXML_MODULES_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_DEBUG: +#ifdef LIBXML_DEBUG_ENABLED + return(1); +#else + return(0); +#endif + case XML_WITH_DEBUG_MEM: +#ifdef DEBUG_MEMORY_LOCATION + return(1); +#else + return(0); +#endif + case XML_WITH_DEBUG_RUN: +#ifdef LIBXML_DEBUG_RUNTIME + return(1); +#else + return(0); +#endif + default: + break; + } + return(0); } /************************************************************************ @@ -636,7 +868,7 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt, const xmlChar *fullattr, const xmlChar *value) { xmlDefAttrsPtr defaults; - intptr_t len; + int len; const xmlChar *name; const xmlChar *prefix; @@ -684,7 +916,7 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt, } /* - * plit the element name into prefix:localname , the string found + * Split the element name into prefix:localname , the string found * are within the DTD and hen not associated to namespace names. */ name = xmlSplitQName3(fullattr, &len); @@ -734,7 +966,7 @@ xmlAddSpecialAttr(xmlParserCtxtPtr ctxt, } xmlHashAddEntry2(ctxt->attsSpecial, fullname, fullattr, - (void *) (size_t) type); + (void *) (long) type); return; mem_error: @@ -905,11 +1137,11 @@ nsPop(xmlParserCtxtPtr ctxt, int nr) } #endif -static intptr_t -xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, intptr_t nr) { +static int +xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) { const xmlChar **atts; - intptr_t *attallocs; - intptr_t maxatts; + int *attallocs; + int maxatts; if (ctxt->atts == NULL) { maxatts = 55; /* allow for 10 attrs by default */ @@ -917,7 +1149,7 @@ xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, intptr_t nr) { xmlMalloc(maxatts * sizeof(xmlChar *)); if (atts == NULL) goto mem_error; ctxt->atts = atts; - attallocs = (intptr_t *) xmlMalloc((maxatts / 5) * sizeof(intptr_t)); + attallocs = (int *) xmlMalloc((maxatts / 5) * sizeof(int)); if (attallocs == NULL) goto mem_error; ctxt->attallocs = attallocs; ctxt->maxatts = maxatts; @@ -927,8 +1159,8 @@ xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, intptr_t nr) { maxatts * sizeof(const xmlChar *)); if (atts == NULL) goto mem_error; ctxt->atts = atts; - attallocs = (intptr_t *) xmlRealloc((void *) ctxt->attallocs, - (maxatts / 5) * sizeof(intptr_t)); + attallocs = (int *) xmlRealloc((void *) ctxt->attallocs, + (maxatts / 5) * sizeof(int)); if (attallocs == NULL) goto mem_error; ctxt->attallocs = attallocs; ctxt->maxatts = maxatts; @@ -984,14 +1216,14 @@ inputPop(xmlParserCtxtPtr ctxt) if (ctxt == NULL) return(NULL); if (ctxt->inputNr <= 0) - return (0); + return (NULL); ctxt->inputNr--; if (ctxt->inputNr > 0) ctxt->input = ctxt->inputTab[ctxt->inputNr - 1]; else ctxt->input = NULL; ret = ctxt->inputTab[ctxt->inputNr]; - ctxt->inputTab[ctxt->inputNr] = 0; + ctxt->inputTab[ctxt->inputNr] = NULL; return (ret); } /** @@ -1053,7 +1285,7 @@ nodePop(xmlParserCtxtPtr ctxt) else ctxt->node = NULL; ret = ctxt->nodeTab[ctxt->nodeNr]; - ctxt->nodeTab[ctxt->nodeNr] = 0; + ctxt->nodeTab[ctxt->nodeNr] = NULL; return (ret); } @@ -1098,7 +1330,7 @@ nameNsPush(xmlParserCtxtPtr ctxt, const xmlChar * value, ctxt->name = value; ctxt->pushTab[ctxt->nameNr * 3] = (void *) prefix; ctxt->pushTab[ctxt->nameNr * 3 + 1] = (void *) URI; - ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (size_t) nsNr; + ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (long) nsNr; return (ctxt->nameNr++); mem_error: xmlErrMemory(ctxt, NULL); @@ -1118,7 +1350,7 @@ nameNsPop(xmlParserCtxtPtr ctxt) const xmlChar *ret; if (ctxt->nameNr <= 0) - return (0); + return (NULL); ctxt->nameNr--; if (ctxt->nameNr > 0) ctxt->name = ctxt->nameTab[ctxt->nameNr - 1]; @@ -1184,7 +1416,7 @@ namePop(xmlParserCtxtPtr ctxt) else ctxt->name = NULL; ret = ctxt->nameTab[ctxt->nameNr]; - ctxt->nameTab[ctxt->nameNr] = 0; + ctxt->nameTab[ctxt->nameNr] = NULL; return (ret); } @@ -1242,11 +1474,11 @@ static int spacePop(xmlParserCtxtPtr ctxt) { * * NEXT Skip to the next character, this does the proper decoding * in UTF-8 mode. It also pop-up unfinished entities on the fly. - * NEXTL(l) Skip the current Unicode character of l xmlChars long. - * CUR_CHAR(l) returns the current Unicode character (int), set l + * NEXTL(l) Skip the current unicode character of l xmlChars long. + * CUR_CHAR(l) returns the current unicode character (int), set l * to the number of xmlChars used for the encoding [0-5]. * CUR_SCHAR same but operate on a string instead of the context - * COPY_BUF copy the current Unicode char to the target buffer, increment + * COPY_BUF copy the current unicode char to the target buffer, increment * the index * GROW, SHRINK handling of input buffers */ @@ -1927,16 +2159,16 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { * must deallocate it ! */ xmlChar * -xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len, +xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int what, xmlChar end, xmlChar end2, xmlChar end3) { xmlChar *buffer = NULL; - intptr_t buffer_size = 0; + int buffer_size = 0; xmlChar *current = NULL; const xmlChar *last; xmlEntityPtr ent; int c,l; - size_t nbchars = 0; + int nbchars = 0; if ((ctxt == NULL) || (str == NULL) || (len < 0)) return(NULL); @@ -1971,6 +2203,9 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t l if (val != 0) { COPY_BUF(0,buffer,nbchars,val); } + if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { + growBuffer(buffer); + } } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) { if (xmlParserDebugEntities) xmlGenericError(xmlGenericErrorContext, @@ -1981,6 +2216,9 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t l (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { if (ent->content != NULL) { COPY_BUF(0,buffer,nbchars,ent->content[0]); + if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { + growBuffer(buffer); + } } else { xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, "predefined entity has no content\n"); @@ -1996,18 +2234,19 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t l current = rep; while (*current != 0) { /* non input consuming loop */ buffer[nbchars++] = *current++; - if ((intptr_t) (nbchars) > buffer_size - XML_PARSER_BUFFER_SIZE) { + if (nbchars > + buffer_size - XML_PARSER_BUFFER_SIZE) { growBuffer(buffer); } } xmlFree(rep); } } else if (ent != NULL) { - intptr_t i = xmlStrlen(ent->name); + int i = xmlStrlen(ent->name); const xmlChar *cur = ent->name; buffer[nbchars++] = '&'; - if ((intptr_t) (nbchars) > buffer_size - i - XML_PARSER_BUFFER_SIZE) { + if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) { growBuffer(buffer); } for (;i > 0;i--) @@ -2030,7 +2269,8 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t l current = rep; while (*current != 0) { /* non input consuming loop */ buffer[nbchars++] = *current++; - if ((intptr_t) (nbchars) > buffer_size - XML_PARSER_BUFFER_SIZE) { + if (nbchars > + buffer_size - XML_PARSER_BUFFER_SIZE) { growBuffer(buffer); } } @@ -2040,7 +2280,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t l } else { COPY_BUF(l,buffer,nbchars,c); str += l; - if ((intptr_t) (nbchars) > buffer_size - XML_PARSER_BUFFER_SIZE) { + if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) { growBuffer(buffer); } } @@ -2101,10 +2341,9 @@ xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, * Returns 1 if ignorable 0 otherwise. */ -static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len, +static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int blank_chars) { - intptr_t i; - int ret; + int i, ret; xmlNodePtr lastChild; /* @@ -2141,7 +2380,7 @@ static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, intptr_t len, /* * Otherwise, heuristic :-\ */ - if (RAW != '<') return(0); + if ((RAW != '<') && (RAW != 0xD)) return(0); if ((ctxt->node->children == NULL) && (RAW == '<') && (NXT(1) == '/')) return(0); @@ -2186,8 +2425,8 @@ xmlChar * xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { xmlChar buf[XML_MAX_NAMELEN + 5]; xmlChar *buffer = NULL; - intptr_t len = 0; - intptr_t max = XML_MAX_NAMELEN; + int len = 0; + int max = XML_MAX_NAMELEN; xmlChar *ret = NULL; const xmlChar *cur = name; int c; @@ -2341,7 +2580,8 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) { ************************************************************************/ static const xmlChar * xmlParseNameComplex(xmlParserCtxtPtr ctxt); -static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, int normalize); +static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, + int *len, int *alloc, int normalize); /** * xmlParseName: @@ -2363,7 +2603,7 @@ const xmlChar * xmlParseName(xmlParserCtxtPtr ctxt) { const xmlChar *in; const xmlChar *ret; - intptr_t count = 0; + int count = 0; GROW; @@ -2465,6 +2705,8 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) { NEXTL(l); c = CUR_CHAR(l); } + if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r')) + return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len)); return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); } @@ -2490,8 +2732,8 @@ static xmlChar * xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { xmlChar buf[XML_MAX_NAMELEN + 5]; const xmlChar *cur = *str; - size_t len = 0; - int l, c; + int len = 0, l; + int c; c = CUR_SCHAR(cur, l); if (!IS_LETTER(c) && (c != '_') && @@ -2513,7 +2755,7 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { * for the processing speed. */ xmlChar *buffer; - size_t max = len * 2; + int max = len * 2; buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); if (buffer == NULL) { @@ -2568,8 +2810,8 @@ xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) { xmlChar * xmlParseNmtoken(xmlParserCtxtPtr ctxt) { xmlChar buf[XML_MAX_NAMELEN + 5]; - size_t len = 0; - int l, c; + int len = 0, l; + int c; int count = 0; GROW; @@ -2593,7 +2835,7 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { * for the processing speed. */ xmlChar *buffer; - size_t max = len * 2; + int max = len * 2; buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar)); if (buffer == NULL) { @@ -2652,8 +2894,8 @@ xmlParseNmtoken(xmlParserCtxtPtr ctxt) { xmlChar * xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = XML_PARSER_BUFFER_SIZE; + int len = 0; + int size = XML_PARSER_BUFFER_SIZE; int c, l; xmlChar stop; xmlChar *ret = NULL; @@ -2789,11 +3031,11 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) { * Returns the AttValue parsed or NULL. The value has to be freed by the caller. */ static xmlChar * -xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, intptr_t* attlen, int normalize) { +xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { xmlChar limit = 0; xmlChar *buf = NULL; - intptr_t len = 0; - intptr_t buf_size = 0; + int len = 0; + int buf_size = 0; int c, l, in_space = 0; xmlChar *current = NULL; xmlEntityPtr ent; @@ -2899,7 +3141,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, intptr_t* attlen, int normalize) buf[len++] = ent->content[0]; } } else if (ent != NULL) { - intptr_t i = xmlStrlen(ent->name); + int i = xmlStrlen(ent->name); const xmlChar *cur = ent->name; /* @@ -3023,8 +3265,8 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { xmlChar * xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = XML_PARSER_BUFFER_SIZE; + int len = 0; + int size = XML_PARSER_BUFFER_SIZE; int cur, l; xmlChar stop; int state = ctxt->instate; @@ -3164,6 +3406,45 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { } void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata); + +/* + * used for the test in the inner loop of the char data testing + */ +static const unsigned char test_char_data[256] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x9, CR/LF separated */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x00, 0x27, /* & */ + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x00, 0x3D, 0x3E, 0x3F, /* < */ + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x00, 0x5E, 0x5F, /* ] */ + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* non-ascii */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + /** * xmlParseCharData: * @ctxt: an XML parser context @@ -3183,10 +3464,10 @@ void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata); void xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { const xmlChar *in; - intptr_t nbchar = 0; + int nbchar = 0; int line = ctxt->input->line; - intptr_t col = ctxt->input->col; - intptr_t ccol; + int col = ctxt->input->col; + int ccol; SHRINK; GROW; @@ -3200,12 +3481,10 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { get_more_space: while (*in == 0x20) in++; if (*in == 0xA) { - ctxt->input->line++; ctxt->input->col = 1; - in++; - while (*in == 0xA) { + do { ctxt->input->line++; ctxt->input->col = 1; in++; - } + } while (*in == 0xA); goto get_more_space; } if (*in == '<') { @@ -3234,23 +3513,17 @@ get_more_space: } get_more: - ccol = ctxt->input->col; - while (((*in > ']') && (*in <= 0x7F)) || - ((*in > '&') && (*in < '<')) || - ((*in > '<') && (*in < ']')) || - ((*in >= 0x20) && (*in < '&')) || - (*in == 0x09)) { - in++; - ccol++; - } + ccol = ctxt->input->col; + while (test_char_data[*in]) { + in++; + ccol++; + } ctxt->input->col = ccol; if (*in == 0xA) { - ctxt->input->line++; ctxt->input->col = 1; - in++; - while (*in == 0xA) { + do { ctxt->input->line++; ctxt->input->col = 1; in++; - } + } while (*in == 0xA); goto get_more; } if (*in == ']') { @@ -3329,7 +3602,7 @@ get_more: void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5]; - intptr_t nbchar = 0; + int nbchar = 0; int cur, l; int count = 0; @@ -3388,6 +3661,13 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) { } } } + if ((cur != 0) && (!IS_CHAR(cur))) { + /* Generate the error and skip the offending character */ + xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR, + "PCDATA invalid Char value %d\n", + cur); + NEXTL(l); + } } /** @@ -3488,7 +3768,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict) { * [15] Comment ::= '' */ static void -xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, size_t len, size_t size) { +xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) { int q, ql; int r, rl; int cur, l; @@ -3586,11 +3866,11 @@ not_terminated: void xmlParseComment(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t size = XML_PARSER_BUFFER_SIZE; - size_t len = 0; + int size = XML_PARSER_BUFFER_SIZE; + int len = 0; xmlParserInputState state; const xmlChar *in; - intptr_t nbchar = 0, ccol; + int nbchar = 0, ccol; /* * Check that there is a comment right here. @@ -3611,12 +3891,10 @@ xmlParseComment(xmlParserCtxtPtr ctxt) { in = ctxt->input->cur; do { if (*in == 0xA) { - ctxt->input->line++; ctxt->input->col = 1; - in++; - while (*in == 0xA) { + do { ctxt->input->line++; ctxt->input->col = 1; in++; - } + } while (*in == 0xA); } get_more: ccol = ctxt->input->col; @@ -3628,12 +3906,10 @@ get_more: } ctxt->input->col = ccol; if (*in == 0xA) { - ctxt->input->line++; ctxt->input->col = 1; - in++; - while (*in == 0xA) { + do { ctxt->input->line++; ctxt->input->col = 1; in++; - } + } while (*in == 0xA); goto get_more; } nbchar = in - ctxt->input->cur; @@ -3674,8 +3950,10 @@ get_more: } } ctxt->input->cur = in; - if (*in == 0xA) - + if (*in == 0xA) { + in++; + ctxt->input->line++; ctxt->input->col = 1; + } if (*in == 0xD) { in++; if (*in == 0xA) { @@ -3746,7 +4024,7 @@ xmlParsePITarget(xmlParserCtxtPtr ctxt) { ((name[0] == 'x') || (name[0] == 'X')) && ((name[1] == 'm') || (name[1] == 'M')) && ((name[2] == 'l') || (name[2] == 'L'))) { - intptr_t i; + int i; if ((name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') && (name[3] == 0)) { xmlFatalErrMsg(ctxt, XML_ERR_RESERVED_XML_NAME, @@ -3844,8 +4122,8 @@ error: void xmlParsePI(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = XML_PARSER_BUFFER_SIZE; + int len = 0; + int size = XML_PARSER_BUFFER_SIZE; int cur, l; const xmlChar *target; xmlParserInputState state; @@ -4617,16 +4895,12 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { if (!IS_BLANK_CH(CUR)) { xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Space required after the attribute name\n"); - if (defaultValue != NULL) - xmlFree(defaultValue); break; } SKIP_BLANKS; type = xmlParseAttributeType(ctxt, &tree); if (type <= 0) { - if (defaultValue != NULL) - xmlFree(defaultValue); break; } @@ -4634,8 +4908,6 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { if (!IS_BLANK_CH(CUR)) { xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Space required after the attribute type\n"); - if (defaultValue != NULL) - xmlFree(defaultValue); if (tree != NULL) xmlFreeEnumeration(tree); break; @@ -5036,7 +5308,7 @@ xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) { * Some normalization: * (a | b* | c?)* == (a | b | c)* */ - while (cur->type == XML_ELEMENT_CONTENT_OR) { + while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) { if ((cur->c1 != NULL) && ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) || (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) @@ -5063,7 +5335,7 @@ xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk) { * (a | b*)+ == (a | b)* * (a | b?)+ == (a | b)* */ - while (cur->type == XML_ELEMENT_CONTENT_OR) { + while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) { if ((cur->c1 != NULL) && ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) || (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) { @@ -5280,7 +5552,7 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { while ((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') || (NXT(2) != '>'))) { const xmlChar *check = CUR_PTR; - size_t cons = ctxt->input->consumed; + unsigned int cons = ctxt->input->consumed; if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { xmlParseConditionalSections(ctxt); @@ -5566,7 +5838,7 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, ((RAW == '<') && (NXT(1) == '!')) || (RAW == '%') || IS_BLANK_CH(CUR)) { const xmlChar *check = CUR_PTR; - size_t cons = ctxt->input->consumed; + unsigned int cons = ctxt->input->consumed; GROW; if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) { @@ -5614,7 +5886,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { if (RAW != '&') return; if (NXT(1) == '#') { - size_t i = 0; + int i = 0; xmlChar out[10]; int hex = NXT(2); int value = xmlParseCharRef(ctxt); @@ -5860,6 +6132,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { * node cases in the reader tests */ if ((ctxt->parseMode == XML_PARSE_READER) && + (nw != NULL) && (nw->type == XML_ELEMENT_NODE) && (nw->children == NULL)) nw->extra = 1; @@ -6061,6 +6334,11 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) { } else { xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY, "Entity '%s' not defined\n", name); + if ((ctxt->inSubset == 0) && + (ctxt->sax != NULL) && + (ctxt->sax->reference != NULL)) { + ctxt->sax->reference(ctxt, name); + } } ctxt->valid = 0; } @@ -6627,7 +6905,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { */ while (RAW != ']') { const xmlChar *check = CUR_PTR; - size_t cons = ctxt->input->consumed; + unsigned int cons = ctxt->input->consumed; SKIP_BLANKS; xmlParseMarkupDecl(ctxt); @@ -6745,9 +7023,9 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) { else if (xmlStrEqual(val, BAD_CAST "preserve")) *(ctxt->space) = 1; else { - xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE, + xmlWarningMsg(ctxt, XML_WAR_SPACE_VALUE, "Invalid value \"%s\" for xml:space : \"default\" or \"preserve\" expected\n", - val); + val, NULL); } } @@ -6789,9 +7067,9 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { const xmlChar *attname; xmlChar *attvalue; const xmlChar **atts = ctxt->atts; - intptr_t nbatts = 0; - intptr_t maxatts = ctxt->maxatts; - intptr_t i; + int nbatts = 0; + int maxatts = ctxt->maxatts; + int i; if (RAW != '<') return(NULL); NEXT1; @@ -6815,7 +7093,7 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { ((RAW != '/') || (NXT(1) != '>')) && (IS_BYTE_CHAR(RAW))) { const xmlChar *q = CUR_PTR; - size_t cons = ctxt->input->consumed; + unsigned int cons = ctxt->input->consumed; attname = xmlParseAttribute(ctxt, &attvalue); if ((attname != NULL) && (attvalue != NULL)) { @@ -7075,7 +7353,7 @@ static const xmlChar * xmlParseNCName(xmlParserCtxtPtr ctxt) { const xmlChar *in; const xmlChar *ret; - intptr_t count = 0; + int count = 0; /* * Accelerator for simple ASCII names @@ -7268,7 +7546,7 @@ xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name, */ static xmlChar * -xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, +xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, int normalize) { xmlChar limit = 0; @@ -7295,7 +7573,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, const xmlChar *oldbase = ctxt->input->base; GROW; if (oldbase != ctxt->input->base) { - intptr_t delta = ctxt->input->base - oldbase; + long delta = ctxt->input->base - oldbase; start = start + delta; in = in + delta; } @@ -7314,7 +7592,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, const xmlChar *oldbase = ctxt->input->base; GROW; if (oldbase != ctxt->input->base) { - intptr_t delta = ctxt->input->base - oldbase; + long delta = ctxt->input->base - oldbase; start = start + delta; in = in + delta; } @@ -7328,7 +7606,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, const xmlChar *oldbase = ctxt->input->base; GROW; if (oldbase != ctxt->input->base) { - intptr_t delta = ctxt->input->base - oldbase; + long delta = ctxt->input->base - oldbase; start = start + delta; in = in + delta; } @@ -7348,7 +7626,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, const xmlChar *oldbase = ctxt->input->base; GROW; if (oldbase != ctxt->input->base) { - intptr_t delta = ctxt->input->base - oldbase; + long delta = ctxt->input->base - oldbase; start = start + delta; in = in + delta; last = last + delta; @@ -7365,7 +7643,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, intptr_t* len, int *alloc, const xmlChar *oldbase = ctxt->input->base; GROW; if (oldbase != ctxt->input->base) { - intptr_t delta = ctxt->input->base - oldbase; + long delta = ctxt->input->base - oldbase; start = start + delta; in = in + delta; } @@ -7410,9 +7688,9 @@ static const xmlChar * xmlParseAttribute2(xmlParserCtxtPtr ctxt, const xmlChar *pref, const xmlChar *elem, const xmlChar **prefix, xmlChar **value, - intptr_t* len, int *alloc) { + int *len, int *alloc) { const xmlChar *name; - xmlChar *val; + xmlChar *val, *internal_val = NULL; int normalize = 0; *value = NULL; @@ -7428,9 +7706,11 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt, * get the type if needed */ if (ctxt->attsSpecial != NULL) { - void* type; - type = xmlHashQLookup2(ctxt->attsSpecial, pref, elem, *prefix, name); - if (type != 0) normalize = 1; + int type; + + type = (int) (long) xmlHashQLookup2(ctxt->attsSpecial, + pref, elem, *prefix, name); + if (type != 0) normalize = 1; } /* @@ -7448,33 +7728,40 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt, return(NULL); } - /* - * Check that xml:lang conforms to the specification - * No more registered as an error, just generate a warning now - * since this was deprecated in XML second edition - */ - if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "xml:lang"))) { - if (!xmlCheckLanguageID(val)) { - xmlWarningMsg(ctxt, XML_WAR_LANG_VALUE, - "Malformed value for xml:lang : %s\n", - val, NULL); - } - } + if (*prefix == ctxt->str_xml) { + /* + * Check that xml:lang conforms to the specification + * No more registered as an error, just generate a warning now + * since this was deprecated in XML second edition + */ + if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "lang"))) { + internal_val = xmlStrndup(val, *len); + if (!xmlCheckLanguageID(internal_val)) { + xmlWarningMsg(ctxt, XML_WAR_LANG_VALUE, + "Malformed value for xml:lang : %s\n", + internal_val, NULL); + } + } - /* - * Check that xml:space conforms to the specification - */ - if (xmlStrEqual(name, BAD_CAST "xml:space")) { - if (xmlStrEqual(val, BAD_CAST "default")) - *(ctxt->space) = 0; - else if (xmlStrEqual(val, BAD_CAST "preserve")) - *(ctxt->space) = 1; - else { - xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE, + /* + * Check that xml:space conforms to the specification + */ + if (xmlStrEqual(name, BAD_CAST "space")) { + internal_val = xmlStrndup(val, *len); + if (xmlStrEqual(internal_val, BAD_CAST "default")) + *(ctxt->space) = 0; + else if (xmlStrEqual(internal_val, BAD_CAST "preserve")) + *(ctxt->space) = 1; + else { + xmlWarningMsg(ctxt, XML_WAR_SPACE_VALUE, "Invalid value \"%s\" for xml:space : \"default\" or \"preserve\" expected\n", - val); + internal_val, NULL); + } + } + if (internal_val) { + xmlFree(internal_val); + } } - } *value = val; return(name); @@ -7511,7 +7798,7 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt, static const xmlChar * xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, - const xmlChar **URI, intptr_t* tlen) { + const xmlChar **URI, int *tlen) { const xmlChar *localname; const xmlChar *prefix; const xmlChar *attname; @@ -7519,11 +7806,12 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, const xmlChar *nsname; xmlChar *attvalue; const xmlChar **atts = ctxt->atts; - intptr_t maxatts = ctxt->maxatts; - intptr_t nratts, nbatts, nbdef; + int maxatts = ctxt->maxatts; + int nratts, nbatts, nbdef; int i, j, nbNs, attval; const xmlChar *base; - intptr_t cur; + unsigned long cur; + int nsNr = ctxt->nsNr; if (RAW != '<') return(NULL); NEXT1; @@ -7544,6 +7832,8 @@ reparse: nbdef = 0; nbNs = 0; attval = 0; + /* Forget any namespaces added during an earlier parse of this element. */ + ctxt->nsNr = nsNr; localname = xmlParseQName(ctxt, &prefix); if (localname == NULL) { @@ -7566,8 +7856,8 @@ reparse: ((RAW != '/') || (NXT(1) != '>')) && (IS_BYTE_CHAR(RAW))) { const xmlChar *q = CUR_PTR; - size_t cons = ctxt->input->consumed; - intptr_t len = -1, alloc = 0; + unsigned int cons = ctxt->input->consumed; + int len = -1, alloc = 0; attname = xmlParseAttribute2(ctxt, prefix, localname, &aprefix, &attvalue, &len, &alloc); @@ -7783,13 +8073,19 @@ failed: * The attributes checkings */ for (i = 0; i < nbatts;i += 5) { - nsname = xmlGetNamespace(ctxt, atts[i + 1]); - if ((atts[i + 1] != NULL) && (nsname == NULL)) { - xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, - "Namespace prefix %s for %s on %s is not defined\n", - atts[i + 1], atts[i], localname); - } - atts[i + 2] = nsname; + /* + * The default namespace does not apply to attribute names. + */ + if (atts[i + 1] != NULL) { + nsname = xmlGetNamespace(ctxt, atts[i + 1]); + if (nsname == NULL) { + xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE, + "Namespace prefix %s for %s on %s is not defined\n", + atts[i + 1], atts[i], localname); + } + atts[i + 2] = nsname; + } else + nsname = NULL; /* * [ WFC: Unique Att Spec ] * No attribute name may appear more than once in the same @@ -7879,7 +8175,7 @@ base_changed: static void xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *prefix, - const xmlChar *URI, int line, int nsNr, intptr_t tlen) { + const xmlChar *URI, int line, int nsNr, int tlen) { const xmlChar *name; GROW; @@ -7957,8 +8253,8 @@ done: void xmlParseCDSect(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = XML_PARSER_BUFFER_SIZE; + int len = 0; + int size = XML_PARSER_BUFFER_SIZE; int r, rl; int s, sl; int cur, l; @@ -8055,7 +8351,7 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { while ((RAW != 0) && ((RAW != '<') || (NXT(1) != '/'))) { const xmlChar *test = CUR_PTR; - size_t cons = ctxt->input->consumed; + unsigned int cons = ctxt->input->consumed; const xmlChar *cur = ctxt->input->cur; /* @@ -8142,8 +8438,7 @@ xmlParseElement(xmlParserCtxtPtr ctxt) { const xmlChar *prefix; const xmlChar *URI; xmlParserNodeInfo node_info; - int line; - intptr_t tlen; + int line, tlen; xmlNodePtr ret; int nsNr = ctxt->nsNr; @@ -8301,8 +8596,8 @@ xmlParseElement(xmlParserCtxtPtr ctxt) { xmlChar * xmlParseVersionNum(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = 10; + int len = 0; + int size = 10; xmlChar cur; buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); @@ -8395,8 +8690,8 @@ xmlParseVersionInfo(xmlParserCtxtPtr ctxt) { xmlChar * xmlParseEncName(xmlParserCtxtPtr ctxt) { xmlChar *buf = NULL; - size_t len = 0; - size_t size = 10; + int len = 0; + int size = 10; xmlChar cur; cur = CUR; @@ -8621,6 +8916,13 @@ void xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { xmlChar *version; + /* + * This value for standalone indicates that the document has an + * XML declaration but it does not have a standalone attribute. + * It will be overwritten later if a standalone attribute is found. + */ + ctxt->input->standalone = -2; + /* * We know that '= 0x20) + ix++; + else if ((c == 0xA) || (c == 0xD) || (c == 0x9)) + ix++; + else + return(-ix); + } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */ + if (ix + 2 > len) return(ix); + if ((utf[ix+1] & 0xc0 ) != 0x80) + return(-ix); + codepoint = (utf[ix] & 0x1f) << 6; + codepoint |= utf[ix+1] & 0x3f; + if (!xmlIsCharQ(codepoint)) + return(-ix); + ix += 2; + } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */ + if (ix + 3 > len) return(ix); + if (((utf[ix+1] & 0xc0) != 0x80) || + ((utf[ix+2] & 0xc0) != 0x80)) + return(-ix); + codepoint = (utf[ix] & 0xf) << 12; + codepoint |= (utf[ix+1] & 0x3f) << 6; + codepoint |= utf[ix+2] & 0x3f; + if (!xmlIsCharQ(codepoint)) + return(-ix); + ix += 3; + } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */ + if (ix + 4 > len) return(ix); + if (((utf[ix+1] & 0xc0) != 0x80) || + ((utf[ix+2] & 0xc0) != 0x80) || + ((utf[ix+3] & 0xc0) != 0x80)) + return(-ix); + codepoint = (utf[ix] & 0x7) << 18; + codepoint |= (utf[ix+1] & 0x3f) << 12; + codepoint |= (utf[ix+2] & 0x3f) << 6; + codepoint |= utf[ix+3] & 0x3f; + if (!xmlIsCharQ(codepoint)) + return(-ix); + ix += 4; + } else /* unknown encoding */ + return(-ix); + } + return(ix); +} + /** * xmlParseTryOrFinish: * @ctxt: an XML parser context @@ -9145,8 +9514,7 @@ xmlParseGetLasts(xmlParserCtxtPtr ctxt, const xmlChar **lastlt, static int xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { int ret = 0; - intptr_t avail; - intptr_t tlen; + int avail, tlen; xmlChar cur, next; const xmlChar *lastlt, *lastgt; @@ -9236,9 +9604,9 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { */ if ((ctxt->input->buf->raw != NULL) && (ctxt->input->buf->raw->use > 0)) { - intptr_t base = ctxt->input->base - + int base = ctxt->input->base - ctxt->input->buf->buffer->content; - intptr_t current = ctxt->input->cur - ctxt->input->base; + int current = ctxt->input->cur - ctxt->input->base; xmlParserInputBufferPush(ctxt->input->buf, 0, ""); ctxt->input->base = ctxt->input->buf->buffer->content + base; @@ -9478,7 +9846,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { } case XML_PARSER_CONTENT: { const xmlChar *test; - size_t cons; + unsigned int cons; if ((avail < 2) && (ctxt->inputNr == 1)) goto done; cur = ctxt->input->cur[0]; @@ -9500,8 +9868,14 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { } else if ((cur == '<') && (next == '!') && (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) { - if ((!terminate) && - (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) + int term; + + if (avail < 4) + goto done; + ctxt->input->cur += 4; + term = xmlParseLookupSequence(ctxt, '-', '-', '>'); + ctxt->input->cur -= 4; + if ((!terminate) && (term < 0)) goto done; xmlParseComment(ctxt); ctxt->instate = XML_PARSER_CONTENT; @@ -9582,7 +9956,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { xmlParseEndTag2(ctxt, (void *) ctxt->pushTab[ctxt->nameNr * 3 - 3], (void *) ctxt->pushTab[ctxt->nameNr * 3 - 2], 0, - (int) (intptr_t) ctxt->pushTab[ctxt->nameNr * 3 - 1], 0); + (int) (long) ctxt->pushTab[ctxt->nameNr * 3 - 1], 0); nameNsPop(ctxt); } #ifdef LIBXML_SAX1_ENABLED @@ -9600,26 +9974,41 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { * The Push mode need to have the SAX callback for * cdataBlock merge back contiguous callbacks. */ - intptr_t base; + int base; base = xmlParseLookupSequence(ctxt, ']', ']', '>'); if (base < 0) { if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) { + int tmp; + + tmp = xmlCheckCdataPush(ctxt->input->cur, + XML_PARSER_BIG_BUFFER_SIZE); + if (tmp < 0) { + tmp = -tmp; + ctxt->input->cur += tmp; + goto encoding_error; + } if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) { if (ctxt->sax->cdataBlock != NULL) ctxt->sax->cdataBlock(ctxt->userData, - ctxt->input->cur, - XML_PARSER_BIG_BUFFER_SIZE); + ctxt->input->cur, tmp); else if (ctxt->sax->characters != NULL) ctxt->sax->characters(ctxt->userData, - ctxt->input->cur, - XML_PARSER_BIG_BUFFER_SIZE); + ctxt->input->cur, tmp); } - SKIPL(XML_PARSER_BIG_BUFFER_SIZE); + SKIPL(tmp); ctxt->checkIndex = 0; } goto done; } else { + int tmp; + + tmp = xmlCheckCdataPush(ctxt->input->cur, base); + if ((tmp < 0) || (tmp != base)) { + tmp = -tmp; + ctxt->input->cur += tmp; + goto encoding_error; + } if ((ctxt->sax != NULL) && (base > 0) && (!ctxt->disableSAX)) { if (ctxt->sax->cdataBlock != NULL) @@ -9826,7 +10215,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { * sections (whoever argued to keep that crap in XML deserve * a place in hell !). */ - intptr_t base, i; + int base, i; xmlChar *buf; xmlChar quote = 0; @@ -9891,7 +10280,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) { continue; } for (i = 1; - (size_t) (base + i) < ctxt->input->buf->buffer->use; + (unsigned int) base + i < ctxt->input->buf->buffer->use; i++) { if (buf[base + i] == '>') { #if 0 @@ -10020,6 +10409,18 @@ done: xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret); #endif return(ret); +encoding_error: + { + char buffer[150]; + + snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", + ctxt->input->cur[0], ctxt->input->cur[1], + ctxt->input->cur[2], ctxt->input->cur[3]); + __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR, + "Input is not proper UTF-8, indicate encoding !\n%s", + BAD_CAST buffer, NULL); + } + return(0); } /** @@ -10036,19 +10437,26 @@ done: int xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, int terminate) { + int end_in_lf = 0; + if (ctxt == NULL) return(XML_ERR_INTERNAL_ERROR); if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) return(ctxt->errNo); if (ctxt->instate == XML_PARSER_START) xmlDetectSAX2(ctxt); + if ((size > 0) && (chunk != NULL) && (!terminate) && + (chunk[size - 1] == '\r')) { + end_in_lf = 1; + size--; + } if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) { - intptr_t base = ctxt->input->base - ctxt->input->buf->buffer->content; - intptr_t cur = ctxt->input->cur - ctxt->input->base; - intptr_t res; + int base = ctxt->input->base - ctxt->input->buf->buffer->content; + int cur = ctxt->input->cur - ctxt->input->base; + int res; - res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk); + res =xmlParserInputBufferPush(ctxt->input->buf, size, chunk); if (res < 0) { ctxt->errNo = XML_PARSER_EOF; ctxt->disableSAX = 1; @@ -10067,7 +10475,7 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, xmlParserInputBufferPtr in = ctxt->input->buf; if ((in->encoder != NULL) && (in->buffer != NULL) && (in->raw != NULL)) { - intptr_t nbchars; + int nbchars; nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); if (nbchars < 0) { @@ -10080,13 +10488,17 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, } } xmlParseTryOrFinish(ctxt, terminate); + if ((end_in_lf == 1) && (ctxt->input != NULL) && + (ctxt->input->buf != NULL)) { + xmlParserInputBufferPush(ctxt->input->buf, 1, "\r"); + } if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1)) return(ctxt->errNo); if (terminate) { /* * Check for termination */ - intptr_t avail = 0; + int avail = 0; if (ctxt->input != NULL) { if (ctxt->input->buf == NULL) @@ -10119,24 +10531,6 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size, * * ************************************************************************/ -/** - * xmlStopParser: - * @ctxt: an XML parser context - * - * Blocks further parser processing - */ -void -xmlStopParser(xmlParserCtxtPtr ctxt) { - if (ctxt == NULL) - return; - ctxt->instate = XML_PARSER_EOF; - ctxt->disableSAX = 1; - if (ctxt->input != NULL) { - ctxt->input->cur = BAD_CAST""; - ctxt->input->base = ctxt->input->cur; - } -} - /** * xmlCreatePushParserCtxt: * @sax: a SAX handler @@ -10158,7 +10552,7 @@ xmlStopParser(xmlParserCtxtPtr ctxt) { xmlParserCtxtPtr xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, - const char *chunk, intptr_t size, const char *filename) { + const char *chunk, int size, const char *filename) { xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; xmlParserInputBufferPtr buf; @@ -10247,8 +10641,8 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, if ((size == 0) || (chunk == NULL)) { ctxt->charset = XML_CHAR_ENCODING_NONE; } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - intptr_t base = ctxt->input->base - ctxt->input->buf->buffer->content; - intptr_t cur = ctxt->input->cur - ctxt->input->base; + int base = ctxt->input->base - ctxt->input->buf->buffer->content; + int cur = ctxt->input->cur - ctxt->input->base; xmlParserInputBufferPush(ctxt->input->buf, size, chunk); @@ -10269,6 +10663,24 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, } #endif /* LIBXML_PUSH_ENABLED */ +/** + * xmlStopParser: + * @ctxt: an XML parser context + * + * Blocks further parser processing + */ +void +xmlStopParser(xmlParserCtxtPtr ctxt) { + if (ctxt == NULL) + return; + ctxt->instate = XML_PARSER_EOF; + ctxt->disableSAX = 1; + if (ctxt->input != NULL) { + ctxt->input->cur = BAD_CAST""; + ctxt->input->base = ctxt->input->cur; + } +} + /** * xmlCreateIOParserCtxt: * @sax: a SAX handler @@ -10298,7 +10710,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { - xmlFree(buf); + xmlFreeParserInputBuffer(buf); return(NULL); } if (sax != NULL) { @@ -10309,7 +10721,7 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler)); if (ctxt->sax == NULL) { xmlErrMemory(ctxt, NULL); - xmlFree(ctxt); + xmlFreeParserCtxt(ctxt); return(NULL); } memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); @@ -10818,7 +11230,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, *list = NULL; if ((URL == NULL) && (ID == NULL)) return(XML_ERR_INTERNAL_ERROR); - if (doc == NULL) /* @@ relax but check for dereferences */ + if (doc == NULL) return(XML_ERR_INTERNAL_ERROR); @@ -10859,13 +11271,9 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, xmlFreeParserCtxt(ctxt); return(XML_ERR_INTERNAL_ERROR); } - if (doc != NULL) { - newDoc->intSubset = doc->intSubset; - newDoc->extSubset = doc->extSubset; - newDoc->dict = doc->dict; - } else if (oldctxt != NULL) { - newDoc->dict = oldctxt->dict; - } + newDoc->intSubset = doc->intSubset; + newDoc->extSubset = doc->extSubset; + newDoc->dict = doc->dict; xmlDictReference(newDoc->dict); if (doc->URL != NULL) { @@ -10886,12 +11294,8 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, } xmlAddChild((xmlNodePtr) newDoc, newRoot); nodePush(ctxt, newDoc->children); - if (doc == NULL) { - ctxt->myDoc = newDoc; - } else { - ctxt->myDoc = doc; - newRoot->doc = doc; - } + ctxt->myDoc = doc; + newRoot->doc = doc; /* * Get the 4 first bytes and decode the charset @@ -11056,7 +11460,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, xmlSAXHandlerPtr oldsax = NULL; xmlNodePtr content = NULL; xmlNodePtr last = NULL; - intptr_t size; + int size; xmlParserErrors ret = XML_ERR_OK; if (oldctxt->depth > 40) { @@ -11165,8 +11569,9 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, *lst = cur; while (cur != NULL) { #ifdef LIBXML_VALID_ENABLED - if (oldctxt->validate && oldctxt->wellFormed && - oldctxt->myDoc && oldctxt->myDoc->intSubset) { + if ((oldctxt->validate) && (oldctxt->wellFormed) && + (oldctxt->myDoc) && (oldctxt->myDoc->intSubset) && + (cur->type == XML_ELEMENT_NODE)) { oldctxt->valid &= xmlValidateElement(&oldctxt->vctxt, oldctxt->myDoc, cur); } @@ -11332,7 +11737,13 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen, ctxt->loadsubset |= XML_SKIP_IDS; } - xmlParseContent(ctxt); +#ifdef LIBXML_HTML_ENABLED + if (doc->type == XML_HTML_DOCUMENT_NODE) + __htmlParseContent(ctxt); + else +#endif + xmlParseContent(ctxt); + nsPop(ctxt, nsnr); if ((RAW == '<') && (NXT(1) == '/')) { xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL); @@ -11425,7 +11836,7 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax, xmlDocPtr newDoc; xmlSAXHandlerPtr oldsax = NULL; xmlNodePtr content, newRoot; - intptr_t size; + int size; int ret = 0; if (depth > 40) { @@ -11986,7 +12397,7 @@ xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, * Returns the new parser context or NULL */ xmlParserCtxtPtr -xmlCreateMemoryParserCtxt(const char *buffer, intptr_t size) { +xmlCreateMemoryParserCtxt(const char *buffer, int size) { xmlParserCtxtPtr ctxt; xmlParserInputPtr input; xmlParserInputBufferPtr buf; @@ -12046,7 +12457,7 @@ xmlCreateMemoryParserCtxt(const char *buffer, intptr_t size) { xmlDocPtr xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer, - intptr_t size, int recovery, void *data) { + int size, int recovery, void *data) { xmlDocPtr ret; xmlParserCtxtPtr ctxt; @@ -12095,7 +12506,7 @@ xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer, */ xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, - intptr_t size, int recovery) { + int size, int recovery) { return xmlSAXParseMemoryWithData(sax, buffer, size, recovery, NULL); } @@ -12109,7 +12520,7 @@ xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *buffer, * Returns the resulting document tree */ -xmlDocPtr xmlParseMemory(const char *buffer, intptr_t size) { +xmlDocPtr xmlParseMemory(const char *buffer, int size) { return(xmlSAXParseMemory(NULL, buffer, size, 0)); } @@ -12186,7 +12597,7 @@ int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data, */ xmlParserCtxtPtr xmlCreateDocParserCtxt(const xmlChar *cur) { - intptr_t len; + int len; if (cur == NULL) return(NULL); @@ -12307,7 +12718,7 @@ xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) #include #endif -extern void xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...); +extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...); static int xmlParserInitialized = 0; /** @@ -12565,8 +12976,8 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) && (ctxt->input->buf != NULL)) { - intptr_t base = ctxt->input->base - ctxt->input->buf->buffer->content; - intptr_t cur = ctxt->input->cur - ctxt->input->base; + int base = ctxt->input->base - ctxt->input->buf->buffer->content; + int cur = ctxt->input->cur - ctxt->input->base; xmlParserInputBufferPush(ctxt->input->buf, size, chunk); @@ -12632,15 +13043,6 @@ xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options) options -= XML_PARSE_NOENT; } else ctxt->replaceEntities = 0; - if (options & XML_PARSE_NOWARNING) { - ctxt->sax->warning = NULL; - options -= XML_PARSE_NOWARNING; - } - if (options & XML_PARSE_NOERROR) { - ctxt->sax->error = NULL; - ctxt->sax->fatalError = NULL; - options -= XML_PARSE_NOERROR; - } if (options & XML_PARSE_PEDANTIC) { ctxt->pedantic = 1; options -= XML_PARSE_PEDANTIC; @@ -12661,6 +13063,15 @@ xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options) options -= XML_PARSE_DTDVALID; } else ctxt->validate = 0; + if (options & XML_PARSE_NOWARNING) { + ctxt->sax->warning = NULL; + options -= XML_PARSE_NOWARNING; + } + if (options & XML_PARSE_NOERROR) { + ctxt->sax->error = NULL; + ctxt->sax->fatalError = NULL; + options -= XML_PARSE_NOERROR; + } #ifdef LIBXML_SAX1_ENABLED if (options & XML_PARSE_SAX1) { ctxt->sax->startElement = xmlSAX2StartElement; @@ -12689,6 +13100,10 @@ xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options) ctxt->options |= XML_PARSE_NONET; options -= XML_PARSE_NONET; } + if (options & XML_PARSE_COMPACT) { + ctxt->options |= XML_PARSE_COMPACT; + options -= XML_PARSE_COMPACT; + } ctxt->linenumbers = 1; return (options); } diff --git a/Extras/LibXML/parserInternals.c b/Extras/LibXML/parserInternals.c index ee7edae92..57062991a 100644 --- a/Extras/LibXML/parserInternals.c +++ b/Extras/LibXML/parserInternals.c @@ -211,7 +211,7 @@ xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, /** * xmlIsLetter: - * @c: an Unicode character (int) + * @c: an unicode character (int) * * Check whether the character is allowed by the production * [84] Letter ::= BaseChar | Ideographic @@ -275,11 +275,11 @@ void check_buffer(xmlParserInputPtr in) { * Returns the number of xmlChars read, or -1 in case of error, 0 indicate the * end of this entity */ -intptr_t +int xmlParserInputRead(xmlParserInputPtr in, int len) { - intptr_t ret; - intptr_t used; - intptr_t indx; + int ret; + int used; + int indx; if (in == NULL) return(-1); #ifdef DEBUG_INPUT @@ -326,10 +326,10 @@ xmlParserInputRead(xmlParserInputPtr in, int len) { * Returns the number of xmlChars read, or -1 in case of error, 0 indicate the * end of this entity */ -intptr_t -xmlParserInputGrow(xmlParserInputPtr in, intptr_t len) { - intptr_t ret; - intptr_t indx; +int +xmlParserInputGrow(xmlParserInputPtr in, int len) { + int ret; + int indx; if (in == NULL) return(-1); #ifdef DEBUG_INPUT @@ -383,9 +383,9 @@ xmlParserInputGrow(xmlParserInputPtr in, intptr_t len) { */ void xmlParserInputShrink(xmlParserInputPtr in) { - intptr_t used; - intptr_t ret; - intptr_t indx; + int used; + int ret; + int indx; #ifdef DEBUG_INPUT xmlGenericError(xmlGenericErrorContext, "Shrink\n"); @@ -728,7 +728,7 @@ encoding_error: { char buffer[150]; - snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", + snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", ctxt->input->cur[0], ctxt->input->cur[1], ctxt->input->cur[2], ctxt->input->cur[3]); __xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR, @@ -861,7 +861,7 @@ encoding_error: * * Returns the number of xmlChar written */ -intptr_t +int xmlCopyCharMultiByte(xmlChar *out, int val) { if (out == NULL) return(0); /* @@ -904,11 +904,11 @@ xmlCopyCharMultiByte(xmlChar *out, int val) { * Returns the number of xmlChar written */ -intptr_t -xmlCopyChar(intptr_t len ATTRIBUTE_UNUSED, xmlChar *out, int val) { +int +xmlCopyChar(int len ATTRIBUTE_UNUSED, xmlChar *out, int val) { if (out == NULL) return(0); /* the len parameter is ignored */ - if (val >= 0x80) { + if (val >= 0x80) { return(xmlCopyCharMultiByte (out, val)); } *out = (xmlChar) val; @@ -941,7 +941,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) case XML_CHAR_ENCODING_ERROR: __xmlErrEncoding(ctxt, XML_ERR_UNKNOWN_ENCODING, "encoding unknown\n", NULL, NULL); - break; + return(-1); case XML_CHAR_ENCODING_NONE: /* let's assume it's UTF-8 without the XML decl */ ctxt->charset = XML_CHAR_ENCODING_UTF8; @@ -972,7 +972,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) *has also been converted into *an UTF-8 BOM. Let's skip that BOM. */ - if ((ctxt->input != NULL) && + if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) && (ctxt->input->cur[0] == 0xEF) && (ctxt->input->cur[1] == 0xBB) && (ctxt->input->cur[2] == 0xBF)) { @@ -988,15 +988,6 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) * Default handlers. */ switch (enc) { - case XML_CHAR_ENCODING_ERROR: - __xmlErrEncoding(ctxt, XML_ERR_UNKNOWN_ENCODING, - "encoding unknown\n", NULL, NULL); - break; - case XML_CHAR_ENCODING_NONE: - /* let's assume it's UTF-8 without the XML decl */ - ctxt->charset = XML_CHAR_ENCODING_UTF8; - return(0); - case XML_CHAR_ENCODING_UTF8: case XML_CHAR_ENCODING_ASCII: /* default encoding, no conversion should be needed */ ctxt->charset = XML_CHAR_ENCODING_UTF8; @@ -1052,6 +1043,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) */ if ((ctxt->inputNr == 1) && (ctxt->encoding == NULL) && + (ctxt->input != NULL) && (ctxt->input->encoding != NULL)) { ctxt->encoding = xmlStrdup(ctxt->input->encoding); } @@ -1072,6 +1064,8 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) "encoding not supported %s\n", BAD_CAST "EUC-JP", NULL); break; + default: + break; } } if (handler == NULL) @@ -1095,7 +1089,7 @@ int xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler) { - intptr_t nbchars; + int nbchars; if (handler == NULL) return (-1); @@ -1135,8 +1129,8 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, * Is there already some content down the pipe to convert ? */ if ((input->buf->buffer != NULL) && (input->buf->buffer->use > 0)) { - intptr_t processed; - size_t use; + int processed; + unsigned int use; /* * Specific handling of the Byte Order Mark for @@ -1206,50 +1200,13 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, } return (0); - } else { - if ((input->length == 0) || (input->buf == NULL)) { - /* - * When parsing a static memory array one must know the - * size to be able to convert the buffer. - */ - xmlErrInternal(ctxt, "switching encoding : no input\n", NULL); - return (-1); - } else { - intptr_t processed; - - /* - * Shrink the current input buffer. - * Move it as the raw buffer and create a new input buffer - */ - processed = input->cur - input->base; - - input->buf->raw = xmlBufferCreate(); - xmlBufferAdd(input->buf->raw, input->cur, - input->length - processed); - input->buf->buffer = xmlBufferCreate(); - - /* - * convert as much as possible of the raw input - * to the parser reading buffer. - */ - nbchars = xmlCharEncInFunc(input->buf->encoder, - input->buf->buffer, - input->buf->raw); - if (nbchars < 0) { - xmlErrInternal(ctxt, - "switching encoding: encoder error\n", - NULL); - return (-1); - } - - /* - * Conversion succeeded, get rid of the old buffer - */ - if ((input->free != NULL) && (input->base != NULL)) - input->free((xmlChar *) input->base); - input->base = input->cur = input->buf->buffer->content; - input->end = &input->base[input->buf->buffer->use]; - } + } else if (input->length == 0) { + /* + * When parsing a static memory array one must know the + * size to be able to convert the buffer. + */ + xmlErrInternal(ctxt, "switching encoding : no input\n", NULL); + return (-1); } return (0); } @@ -1267,9 +1224,11 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, int xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler) { + int ret = 0; + if (handler != NULL) { if (ctxt->input != NULL) { - xmlSwitchInputEncoding(ctxt, ctxt->input, handler); + ret = xmlSwitchInputEncoding(ctxt, ctxt->input, handler); } else { xmlErrInternal(ctxt, "xmlSwitchToEncoding : no input\n", NULL); @@ -1281,7 +1240,7 @@ xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler) ctxt->charset = XML_CHAR_ENCODING_UTF8; } else return(-1); - return(0); + return(ret); } /************************************************************************ @@ -1490,17 +1449,20 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { if (ctxt == NULL) return(NULL); buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); if (buf == NULL) { - __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n", - (const char *) filename); + if (filename == NULL) + __xmlLoaderErr(ctxt, + "failed to load external entity: NULL filename \n", + NULL); + else + __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n", + (const char *) filename); return(NULL); } inputStream = xmlNewInputStream(ctxt); - if (inputStream == NULL) { - if (directory != NULL) xmlFree((char *) directory); - if (URI != NULL) xmlFree((char *) URI); + if (inputStream == NULL) return(NULL); - } + inputStream->buf = buf; inputStream = xmlCheckHTTPInput(ctxt, inputStream); if (inputStream == NULL) @@ -1792,7 +1754,7 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) */ xmlParserCtxtPtr -xmlNewParserCtxt() +xmlNewParserCtxt(void) { xmlParserCtxtPtr ctxt; @@ -1910,7 +1872,7 @@ xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq, int found = 0; if ((seq == NULL) || (node == NULL)) - return (-1); + return ((unsigned long) -1); /* Do a binary search for the key */ lower = 1; @@ -1952,8 +1914,10 @@ xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, /* Find pos and check to see if node is already in the sequence */ pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (xmlNodePtr) info->node); - if (pos < ctxt->node_seq.length - && ctxt->node_seq.buffer[pos].node == info->node) { + + if ((pos < ctxt->node_seq.length) && + (ctxt->node_seq.buffer != NULL) && + (ctxt->node_seq.buffer[pos].node == info->node)) { ctxt->node_seq.buffer[pos] = *info; } diff --git a/Extras/LibXML/pattern.c b/Extras/LibXML/pattern.c index 4e31c3a56..cf416064b 100644 --- a/Extras/LibXML/pattern.c +++ b/Extras/LibXML/pattern.c @@ -20,7 +20,7 @@ * and indicating we are on / (the document node), probably need * something similar for . * - get rid of the "compile" starting with lowercase - * - get rid of the Strdup/Strndup in case of dictionary + * - DONE (2006-05-16): get rid of the Strdup/Strndup in case of dictionary */ #define IN_LIBXML @@ -38,7 +38,6 @@ #ifdef LIBXML_PATTERN_ENABLED /* #define DEBUG_STREAMING */ -#define SUPPORT_IDC #define ERROR(a, b, c, d) #define ERROR5(a, b, c, d, e) @@ -47,8 +46,42 @@ #define XML_STREAM_STEP_FINAL 2 #define XML_STREAM_STEP_ROOT 4 #define XML_STREAM_STEP_ATTR 8 +#define XML_STREAM_STEP_NODE 16 +#define XML_STREAM_STEP_IN_SET 32 -#define XML_PATTERN_NOTPATTERN 1 +/* +* NOTE: Those private flags (XML_STREAM_xxx) are used +* in _xmlStreamCtxt->flag. They extend the public +* xmlPatternFlags, so be carefull not to interfere with the +* reserved values for xmlPatternFlags. +*/ +#define XML_STREAM_FINAL_IS_ANY_NODE 1<<14 +#define XML_STREAM_FROM_ROOT 1<<15 +#define XML_STREAM_DESC 1<<16 + +/* +* XML_STREAM_ANY_NODE is used for comparison against +* xmlElementType enums, to indicate a node of any type. +*/ +#define XML_STREAM_ANY_NODE 100 + +#define XML_PATTERN_NOTPATTERN (XML_PATTERN_XPATH | \ + XML_PATTERN_XSSEL | \ + XML_PATTERN_XSFIELD) + +#define XML_STREAM_XS_IDC(c) ((c)->flags & \ + (XML_PATTERN_XSSEL | XML_PATTERN_XSFIELD)) + +#define XML_STREAM_XS_IDC_SEL(c) ((c)->flags & XML_PATTERN_XSSEL) + +#define XML_STREAM_XS_IDC_FIELD(c) ((c)->flags & XML_PATTERN_XSFIELD) + +#define XML_PAT_COPY_NSNAME(c, r, nsname) \ + if ((c)->comp->dict) \ + r = (xmlChar *) xmlDictLookup((c)->comp->dict, BAD_CAST nsname, -1); \ + else r = xmlStrdup(BAD_CAST nsname); + +#define XML_PAT_FREE_STRING(c, r) if ((c)->comp->dict == NULL) xmlFree(r); typedef struct _xmlStreamStep xmlStreamStep; typedef xmlStreamStep *xmlStreamStepPtr; @@ -56,25 +89,28 @@ struct _xmlStreamStep { int flags; /* properties of that step */ const xmlChar *name; /* first string value if NULL accept all */ const xmlChar *ns; /* second string value */ + int nodeType; /* type of node */ }; typedef struct _xmlStreamComp xmlStreamComp; typedef xmlStreamComp *xmlStreamCompPtr; struct _xmlStreamComp { - xmlDict *dict; /* the dictionnary if any */ + xmlDict *dict; /* the dictionary if any */ int nbStep; /* number of steps in the automata */ int maxStep; /* allocated number of steps */ xmlStreamStepPtr steps; /* the array of steps */ + int flags; }; struct _xmlStreamCtxt { struct _xmlStreamCtxt *next;/* link to next sub pattern if | */ xmlStreamCompPtr comp; /* the compiled stream */ - int nbState; /* number of state in the automata */ - int maxState; /* allocated number of state */ + int nbState; /* number of states in the automata */ + int maxState; /* allocated number of states */ int level; /* how deep are we ? */ int *states; /* the array of step indexes */ int flags; /* validation options */ + int blockLevel; }; static void xmlFreeStreamComp(xmlStreamCompPtr comp); @@ -116,18 +152,17 @@ typedef xmlStepOp *xmlStepOpPtr; struct _xmlStepOp { xmlPatOp op; const xmlChar *value; - const xmlChar *value2; + const xmlChar *value2; /* The namespace name */ }; -#define PAT_FROM_ROOT 1 -#define PAT_FROM_CUR 2 +#define PAT_FROM_ROOT (1<<8) +#define PAT_FROM_CUR (1<<9) struct _xmlPattern { void *data; /* the associated template */ - xmlDictPtr dict; /* the optional dictionnary */ + xmlDictPtr dict; /* the optional dictionary */ struct _xmlPattern *next; /* next pattern if | is used */ const xmlChar *pattern; /* the pattern */ - int flags; /* flags */ int nbStep; int maxStep; @@ -141,7 +176,7 @@ struct _xmlPatParserContext { const xmlChar *cur; /* the current char being parsed */ const xmlChar *base; /* the full expression */ int error; /* error code */ - xmlDictPtr dict; /* the dictionnary if any */ + xmlDictPtr dict; /* the dictionary if any */ xmlPatternPtr comp; /* the result */ xmlNodePtr elem; /* the current node if any */ const xmlChar **namespaces; /* the namespaces definitions */ @@ -242,7 +277,7 @@ xmlFreePatternList(xmlPatternPtr comp) { /** * xmlNewPatParserContext: * @pattern: the pattern context - * @dict: the inherited dictionnary or NULL + * @dict: the inherited dictionary or NULL * @namespaces: the prefix definitions, array of [URI, prefix] terminated * with [NULL, NULL] or NULL if no namespace is used * @@ -288,7 +323,7 @@ xmlNewPatParserContext(const xmlChar *pattern, xmlDictPtr dict, static void xmlFreePatParserContext(xmlPatParserContextPtr ctxt) { if (ctxt == NULL) - return; + return; memset(ctxt, -1, sizeof(xmlPatParserContext)); xmlFree(ctxt); } @@ -300,7 +335,7 @@ xmlFreePatParserContext(xmlPatParserContextPtr ctxt) { * @value: the first value * @value2: the second value * - * Add an step to an XSLT Compiled Match + * Add a step to an XSLT Compiled Match * * Returns -1 in case of failure, 0 otherwise. */ @@ -451,7 +486,7 @@ xmlPatPushState(xmlStepStates *states, int step, xmlNodePtr node) { * @comp: the precompiled pattern * @node: a node * - * Test wether the node matches the pattern + * Test whether the node matches the pattern * * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure */ @@ -596,8 +631,6 @@ restart: goto rollback; node = node->parent; while (node != NULL) { - if (node == NULL) - goto rollback; if ((node->type == XML_ELEMENT_NODE) && (step->value[0] == node->name[0]) && (xmlStrEqual(step->value, node->name))) { @@ -679,6 +712,7 @@ rollback: #define CUR (*ctxt->cur) #define SKIP(val) ctxt->cur += (val) #define NXT(val) ctxt->cur[(val)] +#define PEEKPREV(val) ctxt->cur[-(val)] #define CUR_PTR ctxt->cur #define SKIP_BLANKS \ @@ -692,11 +726,11 @@ rollback: if (xmlPatternAdd(ctxt, ctxt->comp, (op), (val), (val2))) goto error; #define XSLT_ERROR(X) \ - { xsltError(ctxt, __FILE__, __LINE__, X); \ + { xsltError(ctxt, __FILE__, __LINE__, X); \ ctxt->error = (X); return; } #define XSLT_ERROR0(X) \ - { xsltError(ctxt, __FILE__, __LINE__, X); \ + { xsltError(ctxt, __FILE__, __LINE__, X); \ ctxt->error = (X); return(0); } #if 0 @@ -731,7 +765,10 @@ xmlPatScanLiteral(xmlPatParserContextPtr ctxt) { ctxt->error = 1; return(NULL); } else { - ret = xmlStrndup(q, cur - q); + if (ctxt->dict) + ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); + else + ret = xmlStrndup(q, cur - q); } cur += len; CUR_PTR = cur; @@ -747,7 +784,10 @@ xmlPatScanLiteral(xmlPatParserContextPtr ctxt) { ctxt->error = 1; return(NULL); } else { - ret = xmlStrndup(q, cur - q); + if (ctxt->dict) + ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); + else + ret = xmlStrndup(q, cur - q); } cur += len; CUR_PTR = cur; @@ -795,7 +835,10 @@ xmlPatScanName(xmlPatParserContextPtr ctxt) { cur += len; val = xmlStringCurrentChar(NULL, cur, &len); } - ret = xmlStrndup(q, cur - q); + if (ctxt->dict) + ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); + else + ret = xmlStrndup(q, cur - q); CUR_PTR = cur; return(ret); } @@ -830,7 +873,10 @@ xmlPatScanNCName(xmlPatParserContextPtr ctxt) { cur += len; val = xmlStringCurrentChar(NULL, cur, &len); } - ret = xmlStrndup(q, cur - q); + if (ctxt->dict) + ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); + else + ret = xmlStrndup(q, cur - q); CUR_PTR = cur; return(ret); } @@ -873,10 +919,12 @@ xmlCompileAttributeTest(xmlPatParserContextPtr ctxt) { xmlChar *name = NULL; xmlChar *URL = NULL; + SKIP_BLANKS; name = xmlPatScanNCName(ctxt); if (name == NULL) { if (CUR == '*') { PUSH(XML_OP_ATTR, NULL, NULL); + NEXT; } else { ERROR(NULL, NULL, NULL, "xmlCompileAttributeTest : Name expected\n"); @@ -889,25 +937,39 @@ xmlCompileAttributeTest(xmlPatParserContextPtr ctxt) { xmlChar *prefix = name; NEXT; + + if (IS_BLANK_CH(CUR)) { + ERROR5(NULL, NULL, NULL, "Invalid QName.\n", NULL); + XML_PAT_FREE_STRING(ctxt, prefix); + ctxt->error = 1; + goto error; + } /* * This is a namespace match */ token = xmlPatScanName(ctxt); - for (i = 0;i < ctxt->nb_namespaces;i++) { - if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { - URL = xmlStrdup(ctxt->namespaces[2 * i]); - break; + if ((prefix[0] == 'x') && + (prefix[1] == 'm') && + (prefix[2] == 'l') && + (prefix[3] == 0)) + { + XML_PAT_COPY_NSNAME(ctxt, URL, XML_XML_NAMESPACE); + } else { + for (i = 0;i < ctxt->nb_namespaces;i++) { + if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { + XML_PAT_COPY_NSNAME(ctxt, URL, ctxt->namespaces[2 * i]) + break; + } + } + if (i >= ctxt->nb_namespaces) { + ERROR5(NULL, NULL, NULL, + "xmlCompileAttributeTest : no namespace bound to prefix %s\n", + prefix); + ctxt->error = 1; + goto error; } } - if (i >= ctxt->nb_namespaces) { - ERROR5(NULL, NULL, NULL, - "xmlCompileAttributeTest : no namespace bound to prefix %s\n", - prefix); - ctxt->error = 1; - goto error; - } - - xmlFree(prefix); + XML_PAT_FREE_STRING(ctxt, prefix); if (token == NULL) { if (CUR == '*') { NEXT; @@ -927,12 +989,11 @@ xmlCompileAttributeTest(xmlPatParserContextPtr ctxt) { return; error: if (URL != NULL) - xmlFree(URL); + XML_PAT_FREE_STRING(ctxt, URL) if (token != NULL) - xmlFree(token); + XML_PAT_FREE_STRING(ctxt, token); } - /** * xmlCompileStepPattern: * @ctxt: the compilation context @@ -949,25 +1010,39 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { xmlChar *token = NULL; xmlChar *name = NULL; xmlChar *URL = NULL; + int hasBlanks = 0; SKIP_BLANKS; if (CUR == '.') { + /* + * Context node. + */ NEXT; PUSH(XML_OP_ELEM, NULL, NULL); return; } + if (CUR == '@') { + /* + * Attribute test. + */ + if (XML_STREAM_XS_IDC_SEL(ctxt->comp)) { + ERROR5(NULL, NULL, NULL, + "Unexpected attribute axis in '%s'.\n", ctxt->base); + ctxt->error = 1; + return; + } + NEXT; + xmlCompileAttributeTest(ctxt); + if (ctxt->error != 0) + goto error; + return; + } name = xmlPatScanNCName(ctxt); if (name == NULL) { if (CUR == '*') { NEXT; PUSH(XML_OP_ALL, NULL, NULL); return; - } else if (CUR == '@') { - NEXT; - xmlCompileAttributeTest(ctxt); - if (ctxt->error != 0) - goto error; - return; } else { ERROR(NULL, NULL, NULL, "xmlCompileStepPattern : Name expected\n"); @@ -975,31 +1050,47 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { return; } } - SKIP_BLANKS; + if (IS_BLANK_CH(CUR)) { + hasBlanks = 1; + SKIP_BLANKS; + } if (CUR == ':') { NEXT; if (CUR != ':') { xmlChar *prefix = name; - int i; + int i; + if (hasBlanks || IS_BLANK_CH(CUR)) { + ERROR5(NULL, NULL, NULL, "Invalid QName.\n", NULL); + ctxt->error = 1; + goto error; + } /* * This is a namespace match */ token = xmlPatScanName(ctxt); - for (i = 0;i < ctxt->nb_namespaces;i++) { - if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { - URL = xmlStrdup(ctxt->namespaces[2 * i]); - break; + if ((prefix[0] == 'x') && + (prefix[1] == 'm') && + (prefix[2] == 'l') && + (prefix[3] == 0)) + { + XML_PAT_COPY_NSNAME(ctxt, URL, XML_XML_NAMESPACE) + } else { + for (i = 0;i < ctxt->nb_namespaces;i++) { + if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { + XML_PAT_COPY_NSNAME(ctxt, URL, ctxt->namespaces[2 * i]) + break; + } + } + if (i >= ctxt->nb_namespaces) { + ERROR5(NULL, NULL, NULL, + "xmlCompileStepPattern : no namespace bound to prefix %s\n", + prefix); + ctxt->error = 1; + goto error; } } - if (i >= ctxt->nb_namespaces) { - ERROR5(NULL, NULL, NULL, - "xmlCompileStepPattern : no namespace bound to prefix %s\n", - prefix); - ctxt->error = 1; - goto error; - } - xmlFree(prefix); + XML_PAT_FREE_STRING(ctxt, prefix); if (token == NULL) { if (CUR == '*') { NEXT; @@ -1015,8 +1106,8 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { } } else { NEXT; - if (xmlStrEqual(name, (const xmlChar *) "child")) { - xmlFree(name); + if (xmlStrEqual(name, (const xmlChar *) "child")) { + XML_PAT_FREE_STRING(ctxt, name); name = xmlPatScanName(ctxt); if (name == NULL) { if (CUR == '*') { @@ -1035,24 +1126,37 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { int i; NEXT; + if (IS_BLANK_CH(CUR)) { + ERROR5(NULL, NULL, NULL, "Invalid QName.\n", NULL); + ctxt->error = 1; + goto error; + } /* * This is a namespace match */ token = xmlPatScanName(ctxt); - for (i = 0;i < ctxt->nb_namespaces;i++) { - if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { - URL = xmlStrdup(ctxt->namespaces[2 * i]); - break; + if ((prefix[0] == 'x') && + (prefix[1] == 'm') && + (prefix[2] == 'l') && + (prefix[3] == 0)) + { + XML_PAT_COPY_NSNAME(ctxt, URL, XML_XML_NAMESPACE) + } else { + for (i = 0;i < ctxt->nb_namespaces;i++) { + if (xmlStrEqual(ctxt->namespaces[2 * i + 1], prefix)) { + XML_PAT_COPY_NSNAME(ctxt, URL, ctxt->namespaces[2 * i]) + break; + } + } + if (i >= ctxt->nb_namespaces) { + ERROR5(NULL, NULL, NULL, + "xmlCompileStepPattern : no namespace bound " + "to prefix %s\n", prefix); + ctxt->error = 1; + goto error; } } - if (i >= ctxt->nb_namespaces) { - ERROR5(NULL, NULL, NULL, - "xmlCompileStepPattern : no namespace bound to prefix %s\n", - prefix); - ctxt->error = 1; - goto error; - } - xmlFree(prefix); + XML_PAT_FREE_STRING(ctxt, prefix); if (token == NULL) { if (CUR == '*') { NEXT; @@ -1070,19 +1174,24 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { PUSH(XML_OP_CHILD, name, NULL); return; } else if (xmlStrEqual(name, (const xmlChar *) "attribute")) { - xmlFree(name); + XML_PAT_FREE_STRING(ctxt, name) name = NULL; + if (XML_STREAM_XS_IDC_SEL(ctxt->comp)) { + ERROR5(NULL, NULL, NULL, + "Unexpected attribute axis in '%s'.\n", ctxt->base); + ctxt->error = 1; + goto error; + } xmlCompileAttributeTest(ctxt); if (ctxt->error != 0) goto error; return; } else { - ERROR(NULL, NULL, NULL, - "xmlCompileStepPattern : 'child' or 'attribute' expected\n"); + ERROR5(NULL, NULL, NULL, + "The 'element' or 'attribute' axis is expected.\n", NULL); ctxt->error = 1; goto error; - } - /* NOT REACHED xmlFree(name); */ + } } } else if (CUR == '*') { if (name != NULL) { @@ -1092,20 +1201,16 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) { NEXT; PUSH(XML_OP_ALL, token, NULL); } else { - if (name == NULL) { - ctxt->error = 1; - goto error; - } PUSH(XML_OP_ELEM, name, NULL); } return; error: if (URL != NULL) - xmlFree(URL); + XML_PAT_FREE_STRING(ctxt, URL) if (token != NULL) - xmlFree(token); + XML_PAT_FREE_STRING(ctxt, token) if (name != NULL) - xmlFree(name); + XML_PAT_FREE_STRING(ctxt, name) } /** @@ -1122,9 +1227,10 @@ xmlCompilePathPattern(xmlPatParserContextPtr ctxt) { SKIP_BLANKS; if (CUR == '/') { ctxt->comp->flags |= PAT_FROM_ROOT; - } else if (CUR == '.') { + } else if ((CUR == '.') || (ctxt->comp->flags & XML_PATTERN_NOTPATTERN)) { ctxt->comp->flags |= PAT_FROM_CUR; } + if ((CUR == '/') && (NXT(1) == '/')) { PUSH(XML_OP_ANCESTOR, NULL, NULL); NEXT; @@ -1134,35 +1240,64 @@ xmlCompilePathPattern(xmlPatParserContextPtr ctxt) { NEXT; NEXT; NEXT; + /* Check for incompleteness. */ + SKIP_BLANKS; + if (CUR == 0) { + ERROR5(NULL, NULL, NULL, + "Incomplete expression '%s'.\n", ctxt->base); + ctxt->error = 1; + goto error; + } } if (CUR == '@') { NEXT; xmlCompileAttributeTest(ctxt); SKIP_BLANKS; - if ((CUR != 0) || (CUR == '|')) { + /* TODO: check for incompleteness */ + if (CUR != 0) { xmlCompileStepPattern(ctxt); + if (ctxt->error != 0) + goto error; } } else { if (CUR == '/') { PUSH(XML_OP_ROOT, NULL, NULL); NEXT; + /* Check for incompleteness. */ + SKIP_BLANKS; + if (CUR == 0) { + ERROR5(NULL, NULL, NULL, + "Incomplete expression '%s'.\n", ctxt->base); + ctxt->error = 1; + goto error; + } } xmlCompileStepPattern(ctxt); + if (ctxt->error != 0) + goto error; SKIP_BLANKS; while (CUR == '/') { - if ((CUR == '/') && (NXT(1) == '/')) { + if (NXT(1) == '/') { PUSH(XML_OP_ANCESTOR, NULL, NULL); NEXT; NEXT; SKIP_BLANKS; xmlCompileStepPattern(ctxt); + if (ctxt->error != 0) + goto error; } else { PUSH(XML_OP_PARENT, NULL, NULL); NEXT; SKIP_BLANKS; - if ((CUR != 0) || (CUR == '|')) { - xmlCompileStepPattern(ctxt); + if (CUR == 0) { + ERROR5(NULL, NULL, NULL, + "Incomplete expression '%s'.\n", ctxt->base); + ctxt->error = 1; + goto error; } + xmlCompileStepPattern(ctxt); + if (ctxt->error != 0) + goto error; } } } @@ -1175,6 +1310,107 @@ error: return; } +/** + * xmlCompileIDCXPathPath: + * @ctxt: the compilation context + * + * Compile the Path Pattern and generates a precompiled + * form suitable for fast matching. + * + * [5] Path ::= ('.//')? ( Step '/' )* ( Step | '@' NameTest ) + */ +static void +xmlCompileIDCXPathPath(xmlPatParserContextPtr ctxt) { + SKIP_BLANKS; + if (CUR == '/') { + ERROR5(NULL, NULL, NULL, + "Unexpected selection of the document root in '%s'.\n", + ctxt->base); + goto error; + } + ctxt->comp->flags |= PAT_FROM_CUR; + + if (CUR == '.') { + /* "." - "self::node()" */ + NEXT; + SKIP_BLANKS; + if (CUR == 0) { + /* + * Selection of the context node. + */ + PUSH(XML_OP_ELEM, NULL, NULL); + return; + } + if (CUR != '/') { + /* TODO: A more meaningful error message. */ + ERROR5(NULL, NULL, NULL, + "Unexpected token after '.' in '%s'.\n", ctxt->base); + goto error; + } + /* "./" - "self::node()/" */ + NEXT; + SKIP_BLANKS; + if (CUR == '/') { + if (IS_BLANK_CH(PEEKPREV(1))) { + /* + * Disallow "./ /" + */ + ERROR5(NULL, NULL, NULL, + "Unexpected '/' token in '%s'.\n", ctxt->base); + goto error; + } + /* ".//" - "self:node()/descendant-or-self::node()/" */ + PUSH(XML_OP_ANCESTOR, NULL, NULL); + NEXT; + SKIP_BLANKS; + } + if (CUR == 0) + goto error_unfinished; + } + /* + * Process steps. + */ + do { + xmlCompileStepPattern(ctxt); + if (ctxt->error != 0) + goto error; + SKIP_BLANKS; + if (CUR != '/') + break; + PUSH(XML_OP_PARENT, NULL, NULL); + NEXT; + SKIP_BLANKS; + if (CUR == '/') { + /* + * Disallow subsequent '//'. + */ + ERROR5(NULL, NULL, NULL, + "Unexpected subsequent '//' in '%s'.\n", + ctxt->base); + goto error; + } + if (CUR == 0) + goto error_unfinished; + + } while (CUR != 0); + + if (CUR != 0) { + ERROR5(NULL, NULL, NULL, + "Failed to compile expression '%s'.\n", ctxt->base); + ctxt->error = 1; + } + return; +error: + ctxt->error = 1; + return; + +error_unfinished: + ctxt->error = 1; + ERROR5(NULL, NULL, NULL, + "Unfinished expression '%s'.\n", ctxt->base); + return; +} + /************************************************************************ * * * The streaming code * @@ -1301,7 +1537,7 @@ xmlFreeStreamComp(xmlStreamCompPtr comp) { */ static int xmlStreamCompAddStep(xmlStreamCompPtr comp, const xmlChar *name, - const xmlChar *ns, int flags) { + const xmlChar *ns, int nodeType, int flags) { xmlStreamStepPtr cur; if (comp->nbStep >= comp->maxStep) { @@ -1319,6 +1555,7 @@ xmlStreamCompAddStep(xmlStreamCompPtr comp, const xmlChar *name, cur->flags = flags; cur->name = name; cur->ns = ns; + cur->nodeType = nodeType; return(comp->nbStep - 1); } @@ -1333,7 +1570,8 @@ xmlStreamCompAddStep(xmlStreamCompPtr comp, const xmlChar *name, static int xmlStreamCompile(xmlPatternPtr comp) { xmlStreamCompPtr stream; - int i, s = 0, root = 0, flags = 0; + int i, s = 0, root = 0, flags = 0, prevs = -1; + xmlStepOp step; if ((comp == NULL) || (comp->steps == NULL)) return(-1); @@ -1347,6 +1585,8 @@ xmlStreamCompile(xmlPatternPtr comp) { stream = xmlNewStreamComp(0); if (stream == NULL) return(-1); + /* Note that the stream will have no steps in this case. */ + stream->flags |= XML_STREAM_FINAL_IS_ANY_NODE; comp->stream = stream; return(0); } @@ -1359,19 +1599,13 @@ xmlStreamCompile(xmlPatternPtr comp) { xmlDictReference(stream->dict); } - /* - * Skip leading ./ on relative paths - */ - i = 0; - while ((comp->flags & PAT_FROM_CUR) && (comp->nbStep > i + 2) && - (comp->steps[i].op == XML_OP_ELEM) && - (comp->steps[i].value == NULL) && - (comp->steps[i].value2 == NULL) && - (comp->steps[i + 1].op == XML_OP_PARENT)) { - i += 2; - } + i = 0; + if (comp->flags & PAT_FROM_ROOT) + stream->flags |= XML_STREAM_FROM_ROOT; + for (;i < comp->nbStep;i++) { - switch (comp->steps[i].op) { + step = comp->steps[i]; + switch (step.op) { case XML_OP_END: break; case XML_OP_ROOT: @@ -1380,55 +1614,120 @@ xmlStreamCompile(xmlPatternPtr comp) { root = 1; break; case XML_OP_NS: - s = xmlStreamCompAddStep(stream, NULL, - comp->steps[i].value, flags); - flags = 0; + s = xmlStreamCompAddStep(stream, NULL, step.value, + XML_ELEMENT_NODE, flags); if (s < 0) goto error; + prevs = s; + flags = 0; break; case XML_OP_ATTR: flags |= XML_STREAM_STEP_ATTR; - s = xmlStreamCompAddStep(stream, comp->steps[i].value, - comp->steps[i].value2, flags); + prevs = -1; + s = xmlStreamCompAddStep(stream, + step.value, step.value2, XML_ATTRIBUTE_NODE, flags); flags = 0; if (s < 0) goto error; break; - case XML_OP_ELEM: - if ((comp->steps[i].value == NULL) && - (comp->steps[i].value2 == NULL) && - (comp->nbStep > i + 2) && - (comp->steps[i + 1].op == XML_OP_PARENT)) { - i++; - continue; - } - case XML_OP_CHILD: - s = xmlStreamCompAddStep(stream, comp->steps[i].value, - comp->steps[i].value2, flags); - flags = 0; + case XML_OP_ELEM: + if ((step.value == NULL) && (step.value2 == NULL)) { + /* + * We have a "." or "self::node()" here. + * Eliminate redundant self::node() tests like in "/./." + * or "//./" + * The only case we won't eliminate is "//.", i.e. if + * self::node() is the last node test and we had + * continuation somewhere beforehand. + */ + if ((comp->nbStep == i + 1) && + (flags & XML_STREAM_STEP_DESC)) { + /* + * Mark the special case where the expression resolves + * to any type of node. + */ + if (comp->nbStep == i + 1) { + stream->flags |= XML_STREAM_FINAL_IS_ANY_NODE; + } + flags |= XML_STREAM_STEP_NODE; + s = xmlStreamCompAddStep(stream, NULL, NULL, + XML_STREAM_ANY_NODE, flags); + if (s < 0) + goto error; + flags = 0; + /* + * If there was a previous step, mark it to be added to + * the result node-set; this is needed since only + * the last step will be marked as "final" and only + * "final" nodes are added to the resulting set. + */ + if (prevs != -1) { + stream->steps[prevs].flags |= XML_STREAM_STEP_IN_SET; + prevs = -1; + } + break; + + } else { + /* Just skip this one. */ + continue; + } + } + /* An element node. */ + s = xmlStreamCompAddStep(stream, step.value, step.value2, + XML_ELEMENT_NODE, flags); if (s < 0) goto error; + prevs = s; + flags = 0; + break; + case XML_OP_CHILD: + /* An element node child. */ + s = xmlStreamCompAddStep(stream, step.value, step.value2, + XML_ELEMENT_NODE, flags); + if (s < 0) + goto error; + prevs = s; + flags = 0; break; case XML_OP_ALL: - s = xmlStreamCompAddStep(stream, NULL, NULL, flags); - flags = 0; + s = xmlStreamCompAddStep(stream, NULL, NULL, + XML_ELEMENT_NODE, flags); if (s < 0) goto error; + prevs = s; + flags = 0; break; - case XML_OP_PARENT: - if ((comp->nbStep > i + 1) && - (comp->steps[i + 1].op == XML_OP_ELEM) && - (comp->steps[i + 1].value == NULL) && - (comp->steps[i + 1].value2 == NULL)) { - i++; - continue; - } + case XML_OP_PARENT: break; case XML_OP_ANCESTOR: + /* Skip redundant continuations. */ + if (flags & XML_STREAM_STEP_DESC) + break; flags |= XML_STREAM_STEP_DESC; + /* + * Mark the expression as having "//". + */ + if ((stream->flags & XML_STREAM_DESC) == 0) + stream->flags |= XML_STREAM_DESC; break; } + } + if ((! root) && (comp->flags & XML_PATTERN_NOTPATTERN) == 0) { + /* + * If this should behave like a real pattern, we will mark + * the first step as having "//", to be reentrant on every + * tree level. + */ + if ((stream->flags & XML_STREAM_DESC) == 0) + stream->flags |= XML_STREAM_DESC; + + if (stream->nbStep > 0) { + if ((stream->steps[0].flags & XML_STREAM_STEP_DESC) == 0) + stream->steps[0].flags |= XML_STREAM_STEP_DESC; + } } + if (stream->nbStep <= s) + goto error; stream->steps[s].flags |= XML_STREAM_STEP_FINAL; if (root) stream->steps[0].flags |= XML_STREAM_STEP_ROOT; @@ -1472,6 +1771,7 @@ xmlNewStreamCtxt(xmlStreamCompPtr stream) { cur->maxState = 4; cur->level = 0; cur->comp = stream; + cur->blockLevel = -1; return(cur); } @@ -1538,8 +1838,8 @@ xmlStreamCtxtAddState(xmlStreamCtxtPtr comp, int idx, int level) { * @ns: the namespace name * @nodeType: the type of the node * - * push new data onto the stream. NOTE: if the call xmlPatterncompile() - * indicated a dictionnary, then strings for name and ns will be expected + * Push new data onto the stream. NOTE: if the call xmlPatterncompile() + * indicated a dictionary, then strings for name and ns will be expected * to come from the dictionary. * Both @name and @ns being NULL means the / i.e. the root of the document. * This can also act as a reset. @@ -1550,9 +1850,10 @@ xmlStreamCtxtAddState(xmlStreamCtxtPtr comp, int idx, int level) { static int xmlStreamPushInternal(xmlStreamCtxtPtr stream, const xmlChar *name, const xmlChar *ns, - xmlElementType nodeType) { - int ret = 0, err = 0, tmp, i, m, match, step, desc, final; + int nodeType) { + int ret = 0, err = 0, final = 0, tmp, i, m, match, stepNr, desc; xmlStreamCompPtr comp; + xmlStreamStep step; #ifdef DEBUG_STREAMING xmlStreamCtxtPtr orig = stream; #endif @@ -1562,17 +1863,34 @@ xmlStreamPushInternal(xmlStreamCtxtPtr stream, while (stream != NULL) { comp = stream->comp; - if ((name == NULL) && (ns == NULL)) { + + if ((nodeType == XML_ELEMENT_NODE) && + (name == NULL) && (ns == NULL)) { + /* We have a document node here (or a reset). */ stream->nbState = 0; stream->level = 0; - if (comp->steps[0].flags & XML_STREAM_STEP_ROOT) { - tmp = xmlStreamCtxtAddState(stream, 0, 0); - if (tmp < 0) - err++; - if (comp->nbStep == 0) + stream->blockLevel = -1; + if (comp->flags & XML_STREAM_FROM_ROOT) { + if (comp->nbStep == 0) { + /* TODO: We have a "/." here? */ ret = 1; - stream = stream->next; - continue; /* while */ + } else { + if ((comp->nbStep == 1) && + (comp->steps[0].nodeType == XML_STREAM_ANY_NODE) && + (comp->steps[0].flags & XML_STREAM_STEP_DESC)) + { + /* + * In the case of "//." the document node will match + * as well. + */ + ret = 1; + } else if (comp->steps[0].flags & XML_STREAM_STEP_ROOT) { + /* TODO: Do we need this ? */ + tmp = xmlStreamCtxtAddState(stream, 0, 0); + if (tmp < 0) + err++; + } + } } stream = stream->next; continue; /* while */ @@ -1582,170 +1900,284 @@ xmlStreamPushInternal(xmlStreamCtxtPtr stream, * Fast check for ".". */ if (comp->nbStep == 0) { - if (nodeType == XML_ELEMENT_NODE) - ret = 1; + /* + * / and . are handled at the XPath node set creation + * level by checking min depth + */ + if (stream->flags & XML_PATTERN_XPATH) { + stream = stream->next; + continue; /* while */ + } + /* + * For non-pattern like evaluation like XML Schema IDCs + * or traditional XPath expressions, this will match if + * we are at the first level only, otherwise on every level. + */ + if ((nodeType != XML_ATTRIBUTE_NODE) && + (((stream->flags & XML_PATTERN_NOTPATTERN) == 0) || + (stream->level == 0))) { + ret = 1; + } + stream->level++; + goto stream_next; + } + if (stream->blockLevel != -1) { + /* + * Skip blocked expressions. + */ + stream->level++; + goto stream_next; + } + + if ((nodeType != XML_ELEMENT_NODE) && + (nodeType != XML_ATTRIBUTE_NODE) && + ((comp->flags & XML_STREAM_FINAL_IS_ANY_NODE) == 0)) { + /* + * No need to process nodes of other types if we don't + * resolve to those types. + * TODO: Do we need to block the context here? + */ + stream->level++; goto stream_next; } /* * Check evolution of existing states */ + i = 0; m = stream->nbState; - for (i = 0;i < m;i++) { - match = 0; - step = stream->states[2 * i]; - /* dead states */ - if (step < 0) continue; - /* skip new states just added */ - if (stream->states[(2 * i) + 1] > stream->level) - continue; - /* skip continuations */ - desc = comp->steps[step].flags & XML_STREAM_STEP_DESC; - if ((stream->states[(2 * i) + 1] < stream->level) && (!desc)) - continue; + while (i < m) { + if ((comp->flags & XML_STREAM_DESC) == 0) { + /* + * If there is no "//", then only the last + * added state is of interest. + */ + stepNr = stream->states[2 * (stream->nbState -1)]; + /* + * TODO: Security check, should not happen, remove it. + */ + if (stream->states[(2 * (stream->nbState -1)) + 1] < + stream->level) { + return (-1); + } + desc = 0; + /* loop-stopper */ + i = m; + } else { + /* + * If there are "//", then we need to process every "//" + * occuring in the states, plus any other state for this + * level. + */ + stepNr = stream->states[2 * i]; - /* discard old states */ - /* something needed about old level discarded */ + /* TODO: should not happen anymore: dead states */ + if (stepNr < 0) + goto next_state; + tmp = stream->states[(2 * i) + 1]; + + /* skip new states just added */ + if (tmp > stream->level) + goto next_state; + + /* skip states at ancestor levels, except if "//" */ + desc = comp->steps[stepNr].flags & XML_STREAM_STEP_DESC; + if ((tmp < stream->level) && (!desc)) + goto next_state; + } /* * Check for correct node-type. */ - if ((comp->steps[step].flags & XML_STREAM_STEP_ATTR) && - (nodeType != XML_ATTRIBUTE_NODE)) - continue; - - if (comp->dict) { - if (comp->steps[step].name == NULL) { - if (comp->steps[step].ns == NULL) + step = comp->steps[stepNr]; + if (step.nodeType != nodeType) { + if (step.nodeType == XML_ATTRIBUTE_NODE) { + /* + * Block this expression for deeper evaluation. + */ + if ((comp->flags & XML_STREAM_DESC) == 0) + stream->blockLevel = stream->level +1; + goto next_state; + } else if (step.nodeType != XML_STREAM_ANY_NODE) + goto next_state; + } + /* + * Compare local/namespace-name. + */ + match = 0; + if (step.nodeType == XML_STREAM_ANY_NODE) { + match = 1; + } else if (step.name == NULL) { + if (step.ns == NULL) { + /* + * This lets through all elements/attributes. + */ + match = 1; + } else if (ns != NULL) + match = xmlStrEqual(step.ns, ns); + } else if (((step.ns != NULL) == (ns != NULL)) && + (name != NULL) && + (step.name[0] == name[0]) && + xmlStrEqual(step.name, name) && + ((step.ns == ns) || xmlStrEqual(step.ns, ns))) + { + match = 1; + } +#if 0 +/* +* TODO: Pointer comparison won't work, since not guaranteed that the given +* values are in the same dict; especially if it's the namespace name, +* normally coming from ns->href. We need a namespace dict mechanism ! +*/ + } else if (comp->dict) { + if (step.name == NULL) { + if (step.ns == NULL) match = 1; else - match = (comp->steps[step].ns == ns); + match = (step.ns == ns); } else { - match = ((comp->steps[step].name == name) && - (comp->steps[step].ns == ns)); + match = ((step.name == name) && (step.ns == ns)); } - } else { - if (comp->steps[step].name == NULL) { - if (comp->steps[step].ns == NULL) - match = 1; - else - match = xmlStrEqual(comp->steps[step].ns, ns); - } else { - match = ((xmlStrEqual(comp->steps[step].name, name)) && - (xmlStrEqual(comp->steps[step].ns, ns))); - } - } +#endif /* if 0 ------------------------------------------------------- */ if (match) { - final = comp->steps[step].flags & XML_STREAM_STEP_FINAL; + final = step.flags & XML_STREAM_STEP_FINAL; if (desc) { if (final) { ret = 1; } else { /* descending match create a new state */ - xmlStreamCtxtAddState(stream, step + 1, + xmlStreamCtxtAddState(stream, stepNr + 1, stream->level + 1); } } else { if (final) { ret = 1; } else { - xmlStreamCtxtAddState(stream, step + 1, + xmlStreamCtxtAddState(stream, stepNr + 1, stream->level + 1); } } - } - } - - /* - * Check creating a new state. - */ - stream->level++; - - /* - * Check the start only if this is a "desc" evaluation - * or if we are at the first level of evaluation. - */ - desc = comp->steps[0].flags & XML_STREAM_STEP_DESC; - if ( ((comp->steps[0].flags & XML_STREAM_STEP_ROOT) == 0) && - ( ((stream->flags & XML_PATTERN_NOTPATTERN) == 0) || - ( (desc || (stream->level == 1)) ) - ) - ) { - -/* -#ifdef SUPPORT_IDC - - - if ((desc || (stream->level == 1)) && - (!(comp->steps[0].flags & XML_STREAM_STEP_ROOT))) { - - * - * Workaround for missing "self::node()" on "@foo". - * - if (comp->steps[0].flags & XML_STREAM_STEP_ATTR) { - xmlStreamCtxtAddState(stream, 0, stream->level); - goto stream_next; - } -#else - - if (!(comp->steps[0].flags & XML_STREAM_STEP_ROOT)) { -#endif - */ - match = 0; - if (comp->dict) { - if (comp->steps[0].name == NULL) { - if (comp->steps[0].ns == NULL) - match = 1; - else - match = (comp->steps[0].ns == ns); - } else { - if (stream->flags & XML_PATTERN_NOTPATTERN) { - /* - * Workaround for missing "self::node() on "foo". - */ - if (!desc) { - xmlStreamCtxtAddState(stream, 0, stream->level); - goto stream_next; - } else { - match = ((comp->steps[0].name == name) && - (comp->steps[0].ns == ns)); - } - } else { - match = ((comp->steps[0].name == name) && - (comp->steps[0].ns == ns)); - } - } - } else { - if (comp->steps[0].name == NULL) { - if (comp->steps[0].ns == NULL) - match = 1; - else - match = xmlStrEqual(comp->steps[0].ns, ns); - } else { - if (stream->flags & XML_PATTERN_NOTPATTERN) { - /* - * Workaround for missing "self::node() on "foo". - */ - if (!desc) { - xmlStreamCtxtAddState(stream, 0, stream->level); - goto stream_next; - } else { - match = ((xmlStrEqual(comp->steps[0].name, name)) && - (xmlStrEqual(comp->steps[0].ns, ns))); - } - } else { - match = ((xmlStrEqual(comp->steps[0].name, name)) && - (xmlStrEqual(comp->steps[0].ns, ns))); - } - } - } - if (match) { - if (comp->steps[0].flags & XML_STREAM_STEP_FINAL) + if ((ret != 1) && (step.flags & XML_STREAM_STEP_IN_SET)) { + /* + * Check if we have a special case like "foo/bar//.", where + * "foo" is selected as well. + */ ret = 1; - else - xmlStreamCtxtAddState(stream, 1, stream->level); + } + } + if (((comp->flags & XML_STREAM_DESC) == 0) && + ((! match) || final)) { + /* + * Mark this expression as blocked for any evaluation at + * deeper levels. Note that this includes "/foo" + * expressions if the *pattern* behaviour is used. + */ + stream->blockLevel = stream->level +1; + } +next_state: + i++; + } + + stream->level++; + + /* + * Re/enter the expression. + * Don't reenter if it's an absolute expression like "/foo", + * except "//foo". + */ + step = comp->steps[0]; + if (step.flags & XML_STREAM_STEP_ROOT) + goto stream_next; + + desc = step.flags & XML_STREAM_STEP_DESC; + if (stream->flags & XML_PATTERN_NOTPATTERN) { + /* + * Re/enter the expression if it is a "descendant" one, + * or if we are at the 1st level of evaluation. + */ + + if (stream->level == 1) { + if (XML_STREAM_XS_IDC(stream)) { + /* + * XS-IDC: The missing "self::node()" will always + * match the first given node. + */ + goto stream_next; + } else + goto compare; + } + /* + * A "//" is always reentrant. + */ + if (desc) + goto compare; + + /* + * XS-IDC: Process the 2nd level, since the missing + * "self::node()" is responsible for the 2nd level being + * the real start level. + */ + if ((stream->level == 2) && XML_STREAM_XS_IDC(stream)) + goto compare; + + goto stream_next; + } + +compare: + /* + * Check expected node-type. + */ + if (step.nodeType != nodeType) { + if (nodeType == XML_ATTRIBUTE_NODE) + goto stream_next; + else if (step.nodeType != XML_STREAM_ANY_NODE) + goto stream_next; + } + /* + * Compare local/namespace-name. + */ + match = 0; + if (step.nodeType == XML_STREAM_ANY_NODE) { + match = 1; + } else if (step.name == NULL) { + if (step.ns == NULL) { + /* + * This lets through all elements/attributes. + */ + match = 1; + } else if (ns != NULL) + match = xmlStrEqual(step.ns, ns); + } else if (((step.ns != NULL) == (ns != NULL)) && + (name != NULL) && + (step.name[0] == name[0]) && + xmlStrEqual(step.name, name) && + ((step.ns == ns) || xmlStrEqual(step.ns, ns))) + { + match = 1; + } + final = step.flags & XML_STREAM_STEP_FINAL; + if (match) { + if (final) + ret = 1; + else + xmlStreamCtxtAddState(stream, 1, stream->level); + if ((ret != 1) && (step.flags & XML_STREAM_STEP_IN_SET)) { + /* + * Check if we have a special case like "foo//.", where + * "foo" is selected as well. + */ + ret = 1; } } + if (((comp->flags & XML_STREAM_DESC) == 0) && + ((! match) || final)) { + /* + * Mark this expression as blocked for any evaluation at + * deeper levels. + */ + stream->blockLevel = stream->level; + } + stream_next: stream = stream->next; } /* while stream != NULL */ @@ -1764,11 +2196,12 @@ stream_next: * @name: the current name * @ns: the namespace name * - * push new data onto the stream. NOTE: if the call xmlPatterncompile() - * indicated a dictionnary, then strings for name and ns will be expected + * Push new data onto the stream. NOTE: if the call xmlPatterncompile() + * indicated a dictionary, then strings for name and ns will be expected * to come from the dictionary. * Both @name and @ns being NULL means the / i.e. the root of the document. * This can also act as a reset. + * Otherwise the function will act as if it has been given an element-node. * * Returns: -1 in case of error, 1 if the current state in the stream is a * match and 0 otherwise. @@ -1776,7 +2209,35 @@ stream_next: int xmlStreamPush(xmlStreamCtxtPtr stream, const xmlChar *name, const xmlChar *ns) { - return (xmlStreamPushInternal(stream, name, ns, XML_ELEMENT_NODE)); + return (xmlStreamPushInternal(stream, name, ns, (int) XML_ELEMENT_NODE)); +} + +/** + * xmlStreamPushNode: + * @stream: the stream context + * @name: the current name + * @ns: the namespace name + * @nodeType: the type of the node being pushed + * + * Push new data onto the stream. NOTE: if the call xmlPatterncompile() + * indicated a dictionary, then strings for name and ns will be expected + * to come from the dictionary. + * Both @name and @ns being NULL means the / i.e. the root of the document. + * This can also act as a reset. + * Different from xmlStreamPush() this function can be fed with nodes of type: + * element-, attribute-, text-, cdata-section-, comment- and + * processing-instruction-node. + * + * Returns: -1 in case of error, 1 if the current state in the stream is a + * match and 0 otherwise. + */ +int +xmlStreamPushNode(xmlStreamCtxtPtr stream, + const xmlChar *name, const xmlChar *ns, + int nodeType) +{ + return (xmlStreamPushInternal(stream, name, ns, + nodeType)); } /** @@ -1785,11 +2246,12 @@ xmlStreamPush(xmlStreamCtxtPtr stream, * @name: the current name * @ns: the namespace name * -* push new attribute data onto the stream. NOTE: if the call xmlPatterncompile() -* indicated a dictionnary, then strings for name and ns will be expected +* Push new attribute data onto the stream. NOTE: if the call xmlPatterncompile() +* indicated a dictionary, then strings for name and ns will be expected * to come from the dictionary. * Both @name and @ns being NULL means the / i.e. the root of the document. * This can also act as a reset. +* Otherwise the function will act as if it has been given an attribute-node. * * Returns: -1 in case of error, 1 if the current state in the stream is a * match and 0 otherwise. @@ -1797,7 +2259,7 @@ xmlStreamPush(xmlStreamCtxtPtr stream, int xmlStreamPushAttr(xmlStreamCtxtPtr stream, const xmlChar *name, const xmlChar *ns) { - return (xmlStreamPushInternal(stream, name, ns, XML_ATTRIBUTE_NODE)); + return (xmlStreamPushInternal(stream, name, ns, (int) XML_ATTRIBUTE_NODE)); } /** @@ -1810,32 +2272,61 @@ xmlStreamPushAttr(xmlStreamCtxtPtr stream, */ int xmlStreamPop(xmlStreamCtxtPtr stream) { - int i, m; - int ret; - + int i, lev; + if (stream == NULL) return(-1); - ret = 0; while (stream != NULL) { + /* + * Reset block-level. + */ + if (stream->blockLevel == stream->level) + stream->blockLevel = -1; + stream->level--; if (stream->level < 0) - ret = -1; - + return(-1); /* * Check evolution of existing states - */ - m = stream->nbState; - for (i = 0;i < m;i++) { - if (stream->states[(2 * i)] < 0) break; + */ + for (i = stream->nbState -1; i >= 0; i--) { /* discard obsoleted states */ - if (stream->states[(2 * i) + 1] > stream->level) - stream->states[(2 * i)] = -1; + lev = stream->states[(2 * i) + 1]; + if (lev > stream->level) + stream->nbState--; + if (lev <= stream->level) + break; } stream = stream->next; } return(0); } +/** + * xmlStreamWantsAnyNode: + * @streamCtxt: the stream context + * + * Query if the streaming pattern additionally needs to be fed with + * text-, cdata-section-, comment- and processing-instruction-nodes. + * If the result is 0 then only element-nodes and attribute-nodes + * need to be pushed. + * + * Returns: 1 in case of need of nodes of the above described types, + * 0 otherwise. -1 on API errors. + */ +int +xmlStreamWantsAnyNode(xmlStreamCtxtPtr streamCtxt) +{ + if (streamCtxt == NULL) + return(-1); + while (streamCtxt != NULL) { + if (streamCtxt->comp->flags & XML_STREAM_FINAL_IS_ANY_NODE) + return(1); + streamCtxt = streamCtxt->next; + } + return(0); +} + /************************************************************************ * * * The public interfaces * @@ -1845,17 +2336,16 @@ xmlStreamPop(xmlStreamCtxtPtr stream) { /** * xmlPatterncompile: * @pattern: the pattern to compile - * @dict: an optional dictionnary for interned strings - * @flags: compilation flags, undefined yet + * @dict: an optional dictionary for interned strings + * @flags: compilation flags, see xmlPatternFlags * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * * Compile a pattern. * - * Returns the compiled for of the pattern or NULL in case of error + * Returns the compiled form of the pattern or NULL in case of error */ xmlPatternPtr -xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, - int flags ATTRIBUTE_UNUSED, +xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, int flags, const xmlChar **namespaces) { xmlPatternPtr ret = NULL, cur; xmlPatParserContextPtr ctxt = NULL; @@ -1881,9 +2371,16 @@ xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, } or++; } - if (ctxt == NULL) goto error; + if (ctxt == NULL) goto error; cur = xmlNewPattern(); if (cur == NULL) goto error; + /* + * Assign string dict. + */ + if (dict) { + cur->dict = dict; + xmlDictReference(dict); + } if (ret == NULL) ret = cur; else { @@ -1893,10 +2390,14 @@ xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, cur->flags = flags; ctxt->comp = cur; - xmlCompilePathPattern(ctxt); + if (XML_STREAM_XS_IDC(cur)) + xmlCompileIDCXPathPath(ctxt); + else + xmlCompilePathPattern(ctxt); if (ctxt->error != 0) goto error; xmlFreePatParserContext(ctxt); + ctxt = NULL; if (streamable) { @@ -1944,7 +2445,7 @@ error: * @comp: the precompiled pattern * @node: a node * - * Test wether the node matches the pattern + * Test whether the node matches the pattern * * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure */ @@ -2049,7 +2550,33 @@ xmlPatternMaxDepth(xmlPatternPtr comp) { comp = comp->next; } return(ret); +} +/** + * xmlPatternMinDepth: + * @comp: the precompiled pattern + * + * Check the minimum depth reachable by a pattern, 0 mean the / or . are + * part of the set. + * + * Returns -1 in case of error otherwise the depth, + * + */ +int +xmlPatternMinDepth(xmlPatternPtr comp) { + int ret = 12345678; + if (comp == NULL) + return(-1); + while (comp != NULL) { + if (comp->stream == NULL) + return(-1); + if (comp->stream->nbStep < ret) + ret = comp->stream->nbStep; + if (ret == 0) + return(0); + comp = comp->next; + } + return(ret); } /** diff --git a/Extras/LibXML/relaxng.c b/Extras/LibXML/relaxng.c index cd280343a..dd8b6cd3a 100644 --- a/Extras/LibXML/relaxng.c +++ b/Extras/LibXML/relaxng.c @@ -45,27 +45,29 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *) (xmlStrEqual(node->ns->href, xmlRelaxNGNs))) -/* #define DEBUG 1 */ +#if 0 +#define DEBUG 1 -/* #define DEBUG_GRAMMAR 1 */ +#define DEBUG_GRAMMAR 1 -/* #define DEBUG_CONTENT 1 */ +#define DEBUG_CONTENT 1 -/* #define DEBUG_TYPE 1 */ +#define DEBUG_TYPE 1 -/* #define DEBUG_VALID 1 */ +#define DEBUG_VALID 1 -/* #define DEBUG_INTERLEAVE 1 */ +#define DEBUG_INTERLEAVE 1 -/* #define DEBUG_LIST 1 */ +#define DEBUG_LIST 1 -/* #define DEBUG_INCLUDE */ +#define DEBUG_INCLUDE 1 -/* #define DEBUG_ERROR 1 */ +#define DEBUG_ERROR 1 -/* #define DEBUG_COMPILE 1 */ +#define DEBUG_COMPILE 1 -/* #define DEBUG_PROGRESSIVE 1 */ +#define DEBUG_PROGRESSIVE 1 +#endif #define MAX_ERROR 5 @@ -254,6 +256,7 @@ struct _xmlRelaxNGParserCtxt { #define FLAGS_IGNORABLE 1 #define FLAGS_NEGATIVE 2 #define FLAGS_MIXED_CONTENT 4 +#define FLAGS_NOERROR 8 /** * xmlRelaxNGInterleaveGroup: @@ -435,10 +438,12 @@ xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra) void *data = NULL; if (ctxt != NULL) { - channel = ctxt->error; + if (ctxt->serror != NULL) + schannel = ctxt->serror; + else + channel = ctxt->error; data = ctxt->userData; ctxt->nbErrors++; - schannel = ctxt->serror; } if (extra) __xmlRaiseError(schannel, channel, data, @@ -468,10 +473,12 @@ xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt, const char *extra) void *data = NULL; if (ctxt != NULL) { - channel = ctxt->error; + if (ctxt->serror != NULL) + schannel = ctxt->serror; + else + channel = ctxt->error; data = ctxt->userData; ctxt->nbErrors++; - schannel = ctxt->serror; } if (extra) __xmlRaiseError(schannel, channel, data, @@ -506,10 +513,12 @@ xmlRngPErr(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node, int error, void *data = NULL; if (ctxt != NULL) { - channel = ctxt->error; + if (ctxt->serror != NULL) + schannel = ctxt->serror; + else + channel = ctxt->error; data = ctxt->userData; ctxt->nbErrors++; - schannel = ctxt->serror; } __xmlRaiseError(schannel, channel, data, NULL, node, XML_FROM_RELAXNGP, @@ -538,10 +547,12 @@ xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error, void *data = NULL; if (ctxt != NULL) { - channel = ctxt->error; + if (ctxt->serror != NULL) + schannel = ctxt->serror; + else + channel = ctxt->error; data = ctxt->userData; ctxt->nbErrors++; - schannel = ctxt->serror; } __xmlRaiseError(schannel, channel, data, NULL, node, XML_FROM_RELAXNGV, @@ -1148,7 +1159,7 @@ xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt, ctxt->freeStates = tmp; ctxt->freeStatesMax *= 2; } - if ((ctxt == NULL) || (ctxt->freeState == NULL)) { + if ((ctxt == NULL) || (ctxt->freeStates == NULL)) { xmlFree(states->tabState); xmlFree(states); } else { @@ -1477,14 +1488,14 @@ xmlRelaxNGIncludePop(xmlRelaxNGParserCtxtPtr ctxt) xmlRelaxNGIncludePtr ret; if (ctxt->incNr <= 0) - return (0); + return (NULL); ctxt->incNr--; if (ctxt->incNr > 0) ctxt->inc = ctxt->incTab[ctxt->incNr - 1]; else ctxt->inc = NULL; ret = ctxt->incTab[ctxt->incNr]; - ctxt->incTab[ctxt->incNr] = 0; + ctxt->incTab[ctxt->incNr] = NULL; return (ret); } @@ -1552,8 +1563,10 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt, children, name) == 1) { found = 1; } +#ifdef DEBUG_INCLUDE if (href != NULL) xmlFree(href); +#endif } } } @@ -1889,14 +1902,14 @@ xmlRelaxNGDocumentPop(xmlRelaxNGParserCtxtPtr ctxt) xmlRelaxNGDocumentPtr ret; if (ctxt->docNr <= 0) - return (0); + return (NULL); ctxt->docNr--; if (ctxt->docNr > 0) ctxt->doc = ctxt->docTab[ctxt->docNr - 1]; else ctxt->doc = NULL; ret = ctxt->docTab[ctxt->docNr]; - ctxt->docTab[ctxt->docNr] = 0; + ctxt->docTab[ctxt->docNr] = NULL; return (ret); } @@ -2220,7 +2233,7 @@ xmlRelaxNGShowValidError(xmlRelaxNGValidCtxtPtr ctxt, { xmlChar *msg; - if (ctxt->error == NULL) + if (ctxt->flags & FLAGS_NOERROR) return; #ifdef DEBUG_ERROR @@ -2332,7 +2345,9 @@ xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGValidErr err, const xmlChar * arg1, const xmlChar * arg2, int dup) { - if ((ctxt == NULL) || (ctxt->error == NULL)) + if (ctxt == NULL) + return; + if (ctxt->flags & FLAGS_NOERROR) return; #ifdef DEBUG_ERROR @@ -2573,11 +2588,11 @@ xmlRelaxNGSchemaTypeCompare(void *data ATTRIBUTE_UNUSED, } ret = xmlSchemaValPredefTypeNode(typ, value2, &res2, ctxt2); if (ret != 0) { - xmlSchemaFreeValue(res1); + if ((comp1 == NULL) && (res1 != NULL)) + xmlSchemaFreeValue(res1); return (-1); } if (res1 == NULL) { - xmlSchemaFreeValue(res1); return (-1); } ret = xmlSchemaCompareValues(res1, res2); @@ -3564,7 +3579,7 @@ xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) static xmlRelaxNGDefinePtr xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) { - xmlRelaxNGDefinePtr def = NULL, except, last = NULL; + xmlRelaxNGDefinePtr def = NULL, except; xmlRelaxNGDefinePtr param, lastparam = NULL; xmlRelaxNGTypeLibraryPtr lib; xmlChar *type; @@ -3672,7 +3687,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) if ((content != NULL) && (xmlStrEqual(content->name, BAD_CAST "except"))) { xmlNodePtr child; - xmlRelaxNGDefinePtr tmp2, last2 = NULL; + xmlRelaxNGDefinePtr tmp2, last = NULL; except = xmlRelaxNGNewDefine(ctxt, node); if (except == NULL) { @@ -3680,11 +3695,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) } except->type = XML_RELAXNG_EXCEPT; child = content->children; - if (last == NULL) { - def->content = except; - } else { - last->next = except; - } + def->content = except; if (child == NULL) { xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT, "except has no content\n", NULL, NULL); @@ -3692,11 +3703,11 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) while (child != NULL) { tmp2 = xmlRelaxNGParsePattern(ctxt, child); if (tmp2 != NULL) { - if (last2 == NULL) { - except->content = last2 = tmp2; + if (last == NULL) { + except->content = last = tmp2; } else { - last2->next = tmp2; - last2 = tmp2; + last->next = tmp2; + last = tmp2; } } child = child->next; @@ -3739,10 +3750,10 @@ xmlRelaxNGCompareNameClasses(xmlRelaxNGDefinePtr def1, xmlNs ns; xmlRelaxNGValidCtxt ctxt; - ctxt.flags = FLAGS_IGNORABLE; - memset(&ctxt, 0, sizeof(xmlRelaxNGValidCtxt)); + ctxt.flags = FLAGS_IGNORABLE | FLAGS_NOERROR; + if ((def1->type == XML_RELAXNG_ELEMENT) || (def1->type == XML_RELAXNG_ATTRIBUTE)) { if (def2->type == XML_RELAXNG_TEXT) @@ -6908,6 +6919,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF, "xmlRelaxNGParse: externalRef has no href attribute\n", NULL, NULL); + if (ns != NULL) + xmlFree(ns); delete = cur; goto skip_children; } @@ -6916,6 +6929,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR, "Incorrect URI for externalRef %s\n", href, NULL); + if (ns != NULL) + xmlFree(ns); if (href != NULL) xmlFree(href); delete = cur; @@ -6925,6 +6940,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR, "Fragment forbidden in URI for externalRef %s\n", href, NULL); + if (ns != NULL) + xmlFree(ns); xmlFreeURI(uri); if (href != NULL) xmlFree(href); @@ -6938,6 +6955,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR, "Failed to compute URL for externalRef %s\n", href, NULL); + if (ns != NULL) + xmlFree(ns); if (href != NULL) xmlFree(href); if (base != NULL) @@ -6954,6 +6973,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) xmlRngPErr(ctxt, cur, XML_RNGP_EXTERNAL_REF_FAILURE, "Failed to load externalRef %s\n", URL, NULL); + if (ns != NULL) + xmlFree(ns); xmlFree(URL); delete = cur; goto skip_children; @@ -7310,7 +7331,6 @@ xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc) * * parse a schema definition resource and build an internal * XML Shema struture which can be used to validate instances. - * *WARNING* this interface is highly subject to change * * Returns the internal XML RelaxNG structure built from the resource or * NULL in case of error @@ -7374,13 +7394,16 @@ xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt) if (root == NULL) { xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", - ctxt->URL, NULL); - xmlFreeDoc(doc); + (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); + + xmlFreeDoc(ctxt->document); + ctxt->document = NULL; return (NULL); } ret = xmlRelaxNGParseDocument(ctxt, root); if (ret == NULL) { - xmlFreeDoc(doc); + xmlFreeDoc(ctxt->document); + ctxt->document = NULL; return (NULL); } @@ -7459,6 +7482,7 @@ xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt, return; ctxt->error = err; ctxt->warning = warn; + ctxt->serror = NULL; ctxt->userData = ctx; } @@ -7489,6 +7513,27 @@ xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt, return (0); } +/** + * xmlRelaxNGSetParserStructuredErrors: + * @ctxt: a Relax-NG parser context + * @serror: the error callback + * @ctx: contextual data for the callbacks + * + * Set the callback functions used to handle errors for a parsing context + */ +void +xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt, + xmlStructuredErrorFunc serror, + void *ctx) +{ + if (ctxt == NULL) + return; + ctxt->serror = serror; + ctxt->error = NULL; + ctxt->warning = NULL; + ctxt->userData = ctx; +} + #ifdef LIBXML_OUTPUT_ENABLED /************************************************************************ @@ -7759,8 +7804,6 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED, #endif if (ctxt == NULL) { fprintf(stderr, "callback on %s missing context\n", token); - if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK)) - ctxt->errNo = XML_RELAXNG_ERR_INTERNAL; return; } if (define == NULL) { @@ -7804,10 +7847,11 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt, xmlRegExecCtxtPtr exec; xmlNodePtr cur; int ret = 0; - int oldperr = ctxt->perr; + int oldperr; if ((ctxt == NULL) || (regexp == NULL)) return (-1); + oldperr = ctxt->perr; exec = xmlRegNewExecCtxt(regexp, xmlRelaxNGValidateCompiledCallback, ctxt); ctxt->perr = 0; @@ -7966,7 +8010,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata; xmlRelaxNGDefinePtr define = (xmlRelaxNGDefinePtr) transdata; xmlRelaxNGValidStatePtr state, oldstate; - xmlNodePtr node = ctxt->pnode; + xmlNodePtr node; int ret = 0, oldflags; #ifdef DEBUG_PROGRESSIVE @@ -7977,6 +8021,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec fprintf(stderr, "callback on %s missing context\n", token); return; } + node = ctxt->pnode; ctxt->pstate = 1; if (define == NULL) { if (token[0] == '#') @@ -8628,8 +8673,6 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, if (ctxt->errNr > 0) xmlRelaxNGPopErrors(ctxt, 0); } - if (ret == 0) - xmlRelaxNGNextValue(ctxt); break; } case XML_RELAXNG_LIST:{ @@ -8732,13 +8775,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, cur = ctxt->state->value; } ctxt->flags = oldflags; - if (ret != 0) { - if ((ctxt->flags & FLAGS_IGNORABLE) == 0) - xmlRelaxNGDumpValidError(ctxt); - } else { - if (ctxt->errNr > 0) - xmlRelaxNGPopErrors(ctxt, 0); - } + if (ctxt->errNr > 0) + xmlRelaxNGPopErrors(ctxt, 0); break; } case XML_RELAXNG_EXCEPT:{ @@ -9234,21 +9272,56 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt, } else if (ctxt->states != NULL) { int j; int found = 0; + int best = -1; + int lowattr = -1; + + /* + * PBM: what happen if there is attributes checks in the interleaves + */ for (j = 0; j < ctxt->states->nbState; j++) { cur = ctxt->states->tabState[j]->seq; cur = xmlRelaxNGSkipIgnored(ctxt, cur); if (cur == NULL) { + if (found == 0) { + lowattr = ctxt->states->tabState[j]->nbAttrLeft; + best = j; + } found = 1; - break; - } + if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) { + /* try to keep the latest one to mach old heuristic */ + lowattr = ctxt->states->tabState[j]->nbAttrLeft; + best = j; + } + if (lowattr == 0) + break; + } else if (found == 0) { + if (lowattr == -1) { + lowattr = ctxt->states->tabState[j]->nbAttrLeft; + best = j; + } else + if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) { + /* try to keep the latest one to mach old heuristic */ + lowattr = ctxt->states->tabState[j]->nbAttrLeft; + best = j; + } + } } + /* + * BIG PBM: here we pick only one restarting point :-( + */ if (ctxt->states->nbState > 0) { xmlRelaxNGFreeValidState(ctxt, oldstate); - oldstate = - ctxt->states->tabState[ctxt->states->nbState - 1]; + if (best != -1) { + oldstate = ctxt->states->tabState[best]; + ctxt->states->tabState[best] = NULL; + } else { + oldstate = + ctxt->states->tabState[ctxt->states->nbState - 1]; + ctxt->states->tabState[ctxt->states->nbState - 1] = NULL; + } } - for (j = 0; j < ctxt->states->nbState - 1; j++) { + for (j = 0; j < ctxt->states->nbState ; j++) { xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[j]); } xmlRelaxNGFreeStates(ctxt, ctxt->states); @@ -10021,6 +10094,11 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, if (states == NULL) { xmlRelaxNGNewStates(ctxt, res->nbState - base); + states = ctxt->states; + if (states == NULL) { + progress = 0; + break; + } } states->nbState = 0; for (i = base; i < res->nbState; i++) @@ -10581,7 +10659,8 @@ xmlRelaxNGNewValidCtxt(xmlRelaxNGPtr schema) ret->errMax = 0; ret->err = NULL; ret->errTab = NULL; - ret->idref = schema->idref; + if (schema != NULL) + ret->idref = schema->idref; ret->states = NULL; ret->freeState = NULL; ret->freeStates = NULL; @@ -10650,6 +10729,27 @@ xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt, ctxt->error = err; ctxt->warning = warn; ctxt->userData = ctx; + ctxt->serror = NULL; +} + +/** + * xmlRelaxNGSetValidStructuredErrors: + * @ctxt: a Relax-NG validation context + * @serror: the structured error function + * @ctx: the functions context + * + * Set the structured error callback + */ +void +xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt, + xmlStructuredErrorFunc serror, void *ctx) +{ + if (ctxt == NULL) + return; + ctxt->serror = serror; + ctxt->error = NULL; + ctxt->warning = NULL; + ctxt->userData = ctx; } /** diff --git a/Extras/LibXML/threads.c b/Extras/LibXML/threads.c index 6066a2761..90a461aef 100644 --- a/Extras/LibXML/threads.c +++ b/Extras/LibXML/threads.c @@ -46,6 +46,46 @@ /* #define DEBUG_THREADS */ +#ifdef HAVE_PTHREAD_H + +static int libxml_is_threaded = -1; +#ifdef __GNUC__ +#ifdef linux +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3) +extern int pthread_once (pthread_once_t *__once_control, + void (*__init_routine) (void)) + __attribute((weak)); +extern void *pthread_getspecific (pthread_key_t __key) + __attribute((weak)); +extern int pthread_setspecific (pthread_key_t __key, + __const void *__pointer) + __attribute((weak)); +extern int pthread_key_create (pthread_key_t *__key, + void (*__destr_function) (void *)) + __attribute((weak)); +extern int pthread_mutex_init () + __attribute((weak)); +extern int pthread_mutex_destroy () + __attribute((weak)); +extern int pthread_mutex_lock () + __attribute((weak)); +extern int pthread_mutex_unlock () + __attribute((weak)); +extern int pthread_cond_init () + __attribute((weak)); +extern int pthread_equal () + __attribute((weak)); +extern pthread_t pthread_self () + __attribute((weak)); +extern int pthread_key_create () + __attribute((weak)); +extern int pthread_cond_signal () + __attribute((weak)); +#endif +#endif /* linux */ +#endif /* __GNUC__ */ +#endif /* HAVE_PTHREAD_H */ + /* * TODO: this module still uses malloc/free and not xmlMalloc/xmlFree * to avoid some crazyness since xmlMalloc/xmlFree may actually @@ -140,7 +180,8 @@ xmlNewMutex(void) if ((tok = malloc(sizeof(xmlMutex))) == NULL) return (NULL); #ifdef HAVE_PTHREAD_H - pthread_mutex_init(&tok->lock, NULL); + if (libxml_is_threaded != 0) + pthread_mutex_init(&tok->lock, NULL); #elif defined HAVE_WIN32_THREADS tok->mutex = CreateMutex(NULL, FALSE, NULL); #elif defined HAVE_BEOS_THREADS @@ -166,7 +207,8 @@ xmlFreeMutex(xmlMutexPtr tok) if (tok == NULL) return; #ifdef HAVE_PTHREAD_H - pthread_mutex_destroy(&tok->lock); + if (libxml_is_threaded != 0) + pthread_mutex_destroy(&tok->lock); #elif defined HAVE_WIN32_THREADS CloseHandle(tok->mutex); #elif defined HAVE_BEOS_THREADS @@ -187,7 +229,8 @@ xmlMutexLock(xmlMutexPtr tok) if (tok == NULL) return; #ifdef HAVE_PTHREAD_H - pthread_mutex_lock(&tok->lock); + if (libxml_is_threaded != 0) + pthread_mutex_lock(&tok->lock); #elif defined HAVE_WIN32_THREADS WaitForSingleObject(tok->mutex, INFINITE); #elif defined HAVE_BEOS_THREADS @@ -214,7 +257,8 @@ xmlMutexUnlock(xmlMutexPtr tok) if (tok == NULL) return; #ifdef HAVE_PTHREAD_H - pthread_mutex_unlock(&tok->lock); + if (libxml_is_threaded != 0) + pthread_mutex_unlock(&tok->lock); #elif defined HAVE_WIN32_THREADS ReleaseMutex(tok->mutex); #elif defined HAVE_BEOS_THREADS @@ -243,10 +287,12 @@ xmlNewRMutex(void) if ((tok = malloc(sizeof(xmlRMutex))) == NULL) return (NULL); #ifdef HAVE_PTHREAD_H - pthread_mutex_init(&tok->lock, NULL); - tok->held = 0; - tok->waiters = 0; - pthread_cond_init(&tok->cv, NULL); + if (libxml_is_threaded != 0) { + pthread_mutex_init(&tok->lock, NULL); + tok->held = 0; + tok->waiters = 0; + pthread_cond_init(&tok->cv, NULL); + } #elif defined HAVE_WIN32_THREADS InitializeCriticalSection(&tok->cs); tok->count = 0; @@ -270,8 +316,11 @@ xmlNewRMutex(void) void xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED) { + if (tok == NULL) + return; #ifdef HAVE_PTHREAD_H - pthread_mutex_destroy(&tok->lock); + if (libxml_is_threaded != 0) + pthread_mutex_destroy(&tok->lock); #elif defined HAVE_WIN32_THREADS DeleteCriticalSection(&tok->cs); #elif defined HAVE_BEOS_THREADS @@ -292,6 +341,9 @@ xmlRMutexLock(xmlRMutexPtr tok) if (tok == NULL) return; #ifdef HAVE_PTHREAD_H + if (libxml_is_threaded == 0) + return; + pthread_mutex_lock(&tok->lock); if (tok->held) { if (pthread_equal(tok->tid, pthread_self())) { @@ -334,6 +386,9 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED) if (tok == NULL) return; #ifdef HAVE_PTHREAD_H + if (libxml_is_threaded == 0) + return; + pthread_mutex_lock(&tok->lock); tok->held--; if (tok->held == 0) { @@ -417,7 +472,7 @@ typedef struct _xmlGlobalStateCleanupHelperParams void *memory; } xmlGlobalStateCleanupHelperParams; -static void xmlGlobalStateCleanupHelper (void *p) +static void XMLCDECL xmlGlobalStateCleanupHelper (void *p) { xmlGlobalStateCleanupHelperParams *params = (xmlGlobalStateCleanupHelperParams *) p; WaitForSingleObject(params->thread, INFINITE); @@ -470,6 +525,9 @@ xmlGetGlobalState(void) #ifdef HAVE_PTHREAD_H xmlGlobalState *globalval; + if (libxml_is_threaded == 0) + return(NULL); + pthread_once(&once_control, xmlOnceInit); if ((globalval = (xmlGlobalState *) @@ -559,6 +617,8 @@ int xmlGetThreadId(void) { #ifdef HAVE_PTHREAD_H + if (libxml_is_threaded == 0) + return(0); return((int) pthread_self()); #elif defined HAVE_WIN32_THREADS return GetCurrentThreadId(); @@ -580,6 +640,10 @@ int xmlIsMainThread(void) { #ifdef HAVE_PTHREAD_H + if (libxml_is_threaded == -1) + xmlInitThreads(); + if (libxml_is_threaded == 0) + return(1); pthread_once(&once_control, xmlOnceInit); #elif defined HAVE_WIN32_THREADS xmlOnceInit (); @@ -646,6 +710,29 @@ xmlInitThreads(void) #if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) InitializeCriticalSection(&cleanup_helpers_cs); #endif +#ifdef HAVE_PTHREAD_H + if (libxml_is_threaded == -1) { + if ((pthread_once != NULL) && + (pthread_getspecific != NULL) && + (pthread_setspecific != NULL) && + (pthread_key_create != NULL) && + (pthread_mutex_init != NULL) && + (pthread_mutex_destroy != NULL) && + (pthread_mutex_lock != NULL) && + (pthread_mutex_unlock != NULL) && + (pthread_cond_init != NULL) && + (pthread_equal != NULL) && + (pthread_self != NULL) && + (pthread_key_create != NULL) && + (pthread_cond_signal != NULL)) { + libxml_is_threaded = 1; +/* fprintf(stderr, "Running multithreaded\n"); */ + } else { +/* fprintf(stderr, "Running without multithread\n"); */ + libxml_is_threaded = 0; + } + } +#endif } /** diff --git a/Extras/LibXML/tree.c b/Extras/LibXML/tree.c index 1cfef28b7..d382e2922 100644 --- a/Extras/LibXML/tree.c +++ b/Extras/LibXML/tree.c @@ -119,6 +119,9 @@ static int xmlCheckDTD = 1; (n)->last = ulccur; \ }} +#define IS_STR_XML(str) ((str != NULL) && (str[0] == 'x') && \ + (str[1] == 'm') && (str[2] == 'l') && (str[3] == 0)) + /* #define DEBUG_BUFFER */ /* #define DEBUG_TREE */ @@ -197,8 +200,8 @@ xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { */ xmlChar * xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix, - xmlChar *memory, intptr_t len) { - size_t lenn, lenp; + xmlChar *memory, int len) { + int lenn, lenp; xmlChar *ret; if (ncname == NULL) return(NULL); @@ -207,7 +210,7 @@ xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix, lenn = strlen((char *) ncname); lenp = strlen((char *) prefix); - if ((memory == NULL) || (len < (intptr_t) (lenn + lenp + 2))) { + if ((memory == NULL) || (len < lenn + lenp + 2)) { ret = (xmlChar *) xmlMallocAtomic(lenn + lenp + 2); if (ret == NULL) { xmlTreeErrMemory("building QName"); @@ -297,11 +300,12 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { * * returns NULL if it is not a Qualified Name, otherwise, update len * with the lenght in byte of the prefix and return a pointer + * to the start of the name without the prefix */ const xmlChar * -xmlSplitQName3(const xmlChar *name, intptr_t* len) { - intptr_t l = 0; +xmlSplitQName3(const xmlChar *name, int *len) { + int l = 0; if (name == NULL) return(NULL); if (len == NULL) return(NULL); @@ -333,7 +337,7 @@ xmlSplitQName3(const xmlChar *name, intptr_t* len) { #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) -#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) /** * xmlValidateNCName: * @value: the value to check @@ -1133,7 +1137,9 @@ xmlFreeDoc(xmlDocPtr cur) { return; } #ifdef LIBXML_DEBUG_RUNTIME +#ifdef LIBXML_DEBUG_ENABLED xmlDebugCheckDocument(stderr, cur); +#endif #endif if (cur != NULL) dict = cur->dict; @@ -1185,7 +1191,7 @@ xmlFreeDoc(xmlDocPtr cur) { * Returns a pointer to the first child */ xmlNodePtr -xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, intptr_t len) { +xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { xmlNodePtr ret = NULL, last = NULL; xmlNodePtr node; xmlChar *val; @@ -1336,7 +1342,7 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, intptr_t len) { } if (charval != 0) { xmlChar buf[10]; - intptr_t l; + int l; l = xmlCopyCharMultiByte(buf, charval); buf[l] = 0; @@ -1520,7 +1526,7 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { } if (charval != 0) { xmlChar buf[10]; - intptr_t len; + int len; len = xmlCopyCharMultiByte(buf, charval); buf[len] = 0; @@ -1721,80 +1727,87 @@ xmlNodeListGetRawString(xmlDocPtr doc, xmlNodePtr list, int inLine) } #endif /* LIBXML_TREE_ENABLED */ -static xmlAttrPtr xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, - const xmlChar *name, const xmlChar *value, int eatname) { +static xmlAttrPtr +xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, + const xmlChar * name, const xmlChar * value, + int eatname) +{ xmlAttrPtr cur; xmlDocPtr doc = NULL; if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) { - if (eatname == 1) - xmlFree((xmlChar *) name); - return(NULL); - } + if (eatname == 1) + xmlFree((xmlChar *) name); + return (NULL); + } /* * Allocate a new property and fill the fields. */ cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); if (cur == NULL) { - if (eatname == 1) - xmlFree((xmlChar *) name); - xmlTreeErrMemory("building attribute"); - return(NULL); + if (eatname == 1) + xmlFree((xmlChar *) name); + xmlTreeErrMemory("building attribute"); + return (NULL); } memset(cur, 0, sizeof(xmlAttr)); cur->type = XML_ATTRIBUTE_NODE; - cur->parent = node; + cur->parent = node; if (node != NULL) { - doc = node->doc; - cur->doc = doc; + doc = node->doc; + cur->doc = doc; } - cur->ns = ns; + cur->ns = ns; - if (eatname == 0) { - if ((doc != NULL) && (doc->dict != NULL)) - cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); - else - cur->name = xmlStrdup(name); - } else - cur->name = name; + if (eatname == 0) { + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); + } else + cur->name = name; if (value != NULL) { - xmlChar *buffer; - xmlNodePtr tmp; + xmlChar *buffer; + xmlNodePtr tmp; - buffer = xmlEncodeEntitiesReentrant(doc, value); - cur->children = xmlStringGetNodeList(doc, buffer); - cur->last = NULL; - tmp = cur->children; - while (tmp != NULL) { - tmp->parent = (xmlNodePtr) cur; - if (tmp->next == NULL) - cur->last = tmp; - tmp = tmp->next; - } - xmlFree(buffer); - } + buffer = xmlEncodeEntitiesReentrant(doc, value); + cur->children = xmlStringGetNodeList(doc, buffer); + cur->last = NULL; + tmp = cur->children; + while (tmp != NULL) { + tmp->parent = (xmlNodePtr) cur; + if (tmp->next == NULL) + cur->last = tmp; + tmp = tmp->next; + } + xmlFree(buffer); + } /* * Add it at the end to preserve parsing order ... */ if (node != NULL) { - if (node->properties == NULL) { - node->properties = cur; - } else { - xmlAttrPtr prev = node->properties; + if (node->properties == NULL) { + node->properties = cur; + } else { + xmlAttrPtr prev = node->properties; - while (prev->next != NULL) prev = prev->next; - prev->next = cur; - cur->prev = prev; - } + while (prev->next != NULL) + prev = prev->next; + prev->next = cur; + cur->prev = prev; + } } + if (xmlIsID((node == NULL) ? NULL : node->doc, node, cur) == 1) + xmlAddID(NULL, node->doc, value, cur); + if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) - xmlRegisterNodeDefaultValue((xmlNodePtr)cur); - return(cur); + xmlRegisterNodeDefaultValue((xmlNodePtr) cur); + return (cur); } #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ @@ -1964,18 +1977,14 @@ xmlFreeProp(xmlAttrPtr cur) { xmlDeregisterNodeDefaultValue((xmlNodePtr)cur); /* Check for ID removal -> leading to invalid references ! */ - if ((cur->parent != NULL) && (cur->parent->doc != NULL) && - ((cur->parent->doc->intSubset != NULL) || - (cur->parent->doc->extSubset != NULL))) { - if (xmlIsID(cur->parent->doc, cur->parent, cur)) - xmlRemoveID(cur->parent->doc, cur); + if ((cur->doc != NULL) && (cur->atype == XML_ATTRIBUTE_ID)) { + xmlRemoveID(cur->doc, cur); } if (cur->children != NULL) xmlFreeNodeList(cur->children); DICT_FREE(cur->name) xmlFree(cur); } -#ifdef LIBXML_TREE_ENABLED /** * xmlRemoveProp: * @cur: an attribute @@ -2005,6 +2014,8 @@ xmlRemoveProp(xmlAttrPtr cur) { tmp = cur->parent->properties; if (tmp == cur) { cur->parent->properties = cur->next; + if (cur->next != NULL) + cur->next->prev = NULL; xmlFreeProp(cur); return(0); } @@ -2024,7 +2035,6 @@ xmlRemoveProp(xmlAttrPtr cur) { #endif return(-1); } -#endif /* LIBXML_TREE_ENABLED */ /** * xmlNewDocPI: @@ -2441,15 +2451,15 @@ xmlNewCharRef(xmlDocPtr doc, const xmlChar *name) { cur->doc = doc; if (name[0] == '&') { - intptr_t len; + int len; name++; - len = xmlStrlen(name); - if (name[len - 1] == ';') - cur->name = xmlStrndup(name, len - 1); - else - cur->name = xmlStrndup(name, len); + len = xmlStrlen(name); + if (name[len - 1] == ';') + cur->name = xmlStrndup(name, len - 1); + else + cur->name = xmlStrndup(name, len); } else - cur->name = xmlStrdup(name); + cur->name = xmlStrdup(name); if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) xmlRegisterNodeDefaultValue(cur); @@ -2485,7 +2495,7 @@ xmlNewReference(xmlDocPtr doc, const xmlChar *name) { cur->doc = doc; if (name[0] == '&') { - intptr_t len; + int len; name++; len = xmlStrlen(name); if (name[len - 1] == ';') @@ -2538,7 +2548,7 @@ xmlNewDocText(xmlDocPtr doc, const xmlChar *content) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewTextLen(const xmlChar *content, intptr_t len) { +xmlNewTextLen(const xmlChar *content, int len) { xmlNodePtr cur; /* @@ -2573,7 +2583,7 @@ xmlNewTextLen(const xmlChar *content, intptr_t len) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, intptr_t len) { +xmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, int len) { xmlNodePtr cur; cur = xmlNewTextLen(content, len); @@ -2623,7 +2633,7 @@ xmlNewComment(const xmlChar *content) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, intptr_t len) { +xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len) { xmlNodePtr cur; /* @@ -2793,6 +2803,55 @@ xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, } #endif /* LIBXML_TREE_ENABLED */ +/** + * xmlAddPropSibling: + * @prev: the attribute to which @prop is added after + * @cur: the base attribute passed to calling function + * @prop: the new attribute + * + * Add a new attribute after @prev using @cur as base attribute. + * When inserting before @cur, @prev is passed as @cur->prev. + * When inserting after @cur, @prev is passed as @cur. + * If an existing attribute is found it is detroyed prior to adding @prop. + * + * Returns the attribute being inserted or NULL in case of error. + */ +static xmlNodePtr +xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { + xmlAttrPtr attr; + + if (cur->type != XML_ATTRIBUTE_NODE) + return(NULL); + + /* check if an attribute with the same name exists */ + if (prop->ns == NULL) + attr = xmlHasNsProp(cur->parent, prop->name, NULL); + else + attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href); + + if (prop->doc != cur->doc) { + xmlSetTreeDoc(prop, cur->doc); + } + prop->parent = cur->parent; + prop->prev = prev; + if (prev != NULL) { + prop->next = prev->next; + prev->next = prop; + if (prop->next) + prop->next->prev = prop; + } else { + prop->next = cur; + cur->prev = prop; + } + if (prop->prev == NULL && prop->parent != NULL) + prop->parent->properties = (xmlAttrPtr) prop; + if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { + /* different instance, destroy it (attributes must be unique) */ + xmlRemoveProp((xmlAttrPtr) attr); + } + return prop; +} + /** * xmlAddNextSibling: * @cur: the child node @@ -2824,6 +2883,14 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { return(NULL); } + if (cur == elem) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddNextSibling : cur == elem\n"); +#endif + return(NULL); + } + xmlUnlinkNode(elem); if (elem->type == XML_TEXT_NODE) { @@ -2844,17 +2911,7 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { return(cur->next); } } else if (elem->type == XML_ATTRIBUTE_NODE) { - /* check if an attribute with the same name exists */ - xmlAttrPtr attr; - - if (elem->ns == NULL) - attr = xmlHasProp(cur->parent, elem->name); - else - attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); - if ((attr != NULL) && (attr != (xmlAttrPtr) elem)) { - /* different instance, destroy it (attributes must be unique) */ - xmlFreeProp(attr); - } + return xmlAddPropSibling(cur, cur, elem); } if (elem->doc != cur->doc) { @@ -2866,7 +2923,7 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { cur->next = elem; if (elem->next != NULL) elem->next->prev = elem; - if ((elem->parent != NULL) && (elem->parent->last == cur) && (elem->type != XML_ATTRIBUTE_NODE)) + if ((elem->parent != NULL) && (elem->parent->last == cur)) elem->parent->last = elem; return(elem); } @@ -2904,6 +2961,14 @@ xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { return(NULL); } + if (cur == elem) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddPrevSibling : cur == elem\n"); +#endif + return(NULL); + } + xmlUnlinkNode(elem); if (elem->type == XML_TEXT_NODE) { @@ -2924,17 +2989,7 @@ xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { return(cur->prev); } } else if (elem->type == XML_ATTRIBUTE_NODE) { - /* check if an attribute with the same name exists */ - xmlAttrPtr attr; - - if (elem->ns == NULL) - attr = xmlHasProp(cur->parent, elem->name); - else - attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); - if ((attr != NULL) && (attr != (xmlAttrPtr) elem)) { - /* different instance, destroy it (attributes must be unique) */ - xmlFreeProp(attr); - } + return xmlAddPropSibling(cur->prev, cur, elem); } if (elem->doc != cur->doc) { @@ -2946,16 +3001,8 @@ xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { cur->prev = elem; if (elem->prev != NULL) elem->prev->next = elem; - if (elem->parent != NULL) { - if (elem->type == XML_ATTRIBUTE_NODE) { - if (elem->parent->properties == (xmlAttrPtr) cur) { - elem->parent->properties = (xmlAttrPtr) elem; - } - } else { - if (elem->parent->children == cur) { + if ((elem->parent != NULL) && (elem->parent->children == cur)) { elem->parent->children = elem; - } - } } return(elem); } @@ -2997,7 +3044,7 @@ xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { * Constant time is we can rely on the ->parent->last to find * the last sibling. */ - if ((cur->parent != NULL) && + if ((cur->type != XML_ATTRIBUTE_NODE) && (cur->parent != NULL) && (cur->parent->children != NULL) && (cur->parent->last != NULL) && (cur->parent->last->next == NULL)) { @@ -3013,6 +3060,8 @@ xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { xmlNodeAddContent(cur, elem->content); xmlFreeNode(elem); return(cur); + } else if (elem->type == XML_ATTRIBUTE_NODE) { + return xmlAddPropSibling(cur, cur, elem); } if (elem->doc != cur->doc) { @@ -3142,6 +3191,13 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { return(NULL); } + if (parent == cur) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddChild : parent == cur\n"); +#endif + return(NULL); + } /* * If cur is a TEXT node, merge its content with adjacent TEXT nodes * cur is then freed. @@ -3149,8 +3205,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { if (cur->type == XML_TEXT_NODE) { if ((parent->type == XML_TEXT_NODE) && (parent->content != NULL) && - (parent->name == cur->name) && - (parent != cur)) { + (parent->name == cur->name)) { xmlNodeAddContent(parent, cur->content); xmlFreeNode(cur); return(parent); @@ -3189,6 +3244,8 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { return(parent); } if (cur->type == XML_ATTRIBUTE_NODE) { + if (parent->type != XML_ELEMENT_NODE) + return(NULL); if (parent->properties == NULL) { parent->properties = (xmlAttrPtr) cur; } else { @@ -3196,13 +3253,16 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { xmlAttrPtr lastattr; if (cur->ns == NULL) - lastattr = xmlHasProp(parent, cur->name); + lastattr = xmlHasNsProp(parent, cur->name, NULL); else lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href); - if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur)) { + if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur) && (lastattr->type != XML_ATTRIBUTE_DECL)) { /* different instance, destroy it (attributes must be unique) */ + xmlUnlinkNode((xmlNodePtr) lastattr); xmlFreeProp(lastattr); } + if (lastattr == (xmlAttrPtr) cur) + return(cur); /* find the end */ lastattr = parent->properties; while (lastattr->next != NULL) { @@ -3288,7 +3348,8 @@ xmlFreeNodeList(xmlNodePtr cur) { if ((cur->type != XML_ELEMENT_NODE) && (cur->type != XML_XINCLUDE_START) && (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_ENTITY_REF_NODE)) { + (cur->type != XML_ENTITY_REF_NODE) && + (cur->content != (xmlChar *) &(cur->properties))) { DICT_FREE(cur->content) } if (((cur->type == XML_ELEMENT_NODE) || @@ -3357,7 +3418,8 @@ xmlFreeNode(xmlNodePtr cur) { (cur->content != NULL) && (cur->type != XML_ENTITY_REF_NODE) && (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_XINCLUDE_START)) { + (cur->type != XML_XINCLUDE_START) && + (cur->content != (xmlChar *) &(cur->properties))) { DICT_FREE(cur->content) } @@ -3469,7 +3531,7 @@ xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { return(old); } xmlUnlinkNode(cur); - cur->doc = old->doc; + xmlSetTreeDoc(cur, old->doc); cur->parent = old->parent; cur->next = old->next; if (cur->next != NULL) @@ -3555,22 +3617,16 @@ xmlCopyNamespaceList(xmlNsPtr cur) { static xmlNodePtr xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); -/** - * xmlCopyProp: - * @target: the element where the attribute will be grafted - * @cur: the attribute - * - * Do a copy of the attribute. - * - * Returns: a new #xmlAttrPtr, or NULL in case of error. - */ -xmlAttrPtr -xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { + +static xmlAttrPtr +xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { xmlAttrPtr ret; if (cur == NULL) return(NULL); if (target != NULL) ret = xmlNewDocProp(target->doc, cur->name, NULL); + else if (doc != NULL) + ret = xmlNewDocProp(doc, cur->name, NULL); else if (cur->parent != NULL) ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); else if (cur->children != NULL) @@ -3658,6 +3714,20 @@ xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { return(ret); } +/** + * xmlCopyProp: + * @target: the element where the attribute will be grafted + * @cur: the attribute + * + * Do a copy of the attribute. + * + * Returns: a new #xmlAttrPtr, or NULL in case of error. + */ +xmlAttrPtr +xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { + return xmlCopyPropInternal(NULL, target, cur); +} + /** * xmlCopyPropList: * @target: the element where the attributes will be grafted @@ -3726,7 +3796,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, case XML_XINCLUDE_END: break; case XML_ATTRIBUTE_NODE: - return((xmlNodePtr) xmlCopyProp(parent, (xmlAttrPtr) node)); + return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr) node)); case XML_NAMESPACE_DECL: return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node)); @@ -3801,7 +3871,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, if (!extended) goto out; - if (node->nsDef != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL)) ret->nsDef = xmlCopyNamespaceList(node->nsDef); if (node->ns != NULL) { @@ -3828,7 +3898,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, ret->ns = ns; } } - if (node->properties != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL)) ret->properties = xmlCopyPropList(ret, node->properties); if (node->type == XML_ENTITY_REF_NODE) { if ((doc == NULL) || (node->doc != doc)) { @@ -4128,15 +4198,19 @@ xmlGetLineNo(xmlNodePtr node) if (!node) return result; - if (node->type == XML_ELEMENT_NODE) + if ((node->type == XML_ELEMENT_NODE) || + (node->type == XML_TEXT_NODE) || + (node->type == XML_COMMENT_NODE) || + (node->type == XML_PI_NODE)) result = (long) node->line; else if ((node->prev != NULL) && ((node->prev->type == XML_ELEMENT_NODE) || - (node->prev->type == XML_TEXT_NODE))) + (node->prev->type == XML_TEXT_NODE) || + (node->prev->type == XML_COMMENT_NODE) || + (node->prev->type == XML_PI_NODE))) result = xmlGetLineNo(node->prev); else if ((node->parent != NULL) && - ((node->parent->type == XML_ELEMENT_NODE) || - (node->parent->type == XML_TEXT_NODE))) + (node->parent->type == XML_ELEMENT_NODE)) result = xmlGetLineNo(node->parent); return result; @@ -4272,21 +4346,26 @@ xmlGetNodePath(xmlNodePtr node) */ tmp = cur->prev; while (tmp != NULL) { - if ((cur->type == XML_TEXT_NODE) || - (cur->type == XML_CDATA_SECTION_NODE)) + if ((tmp->type == XML_TEXT_NODE) || + (tmp->type == XML_CDATA_SECTION_NODE)) occur++; tmp = tmp->prev; } + /* + * Evaluate if this is the only text- or CDATA-section-node; + * if yes, then we'll get "text()", otherwise "text()[1]". + */ if (occur == 0) { tmp = cur->next; - while (tmp != NULL && occur == 0) { - if ((tmp->type == XML_TEXT_NODE) || - (tmp->type == XML_CDATA_SECTION_NODE)) - occur++; - tmp = tmp->next; - } - if (occur != 0) - occur = 1; + while (tmp != NULL) { + if ((tmp->type == XML_TEXT_NODE) || + (tmp->type == XML_CDATA_SECTION_NODE)) + { + occur = 1; + break; + } + tmp = tmp->next; + } } else occur++; } else if (cur->type == XML_PI_NODE) { @@ -4324,6 +4403,16 @@ xmlGetNodePath(xmlNodePtr node) } else if (cur->type == XML_ATTRIBUTE_NODE) { sep = "/@"; name = (const char *) (((xmlAttrPtr) cur)->name); + if (cur->ns) { + if (cur->ns->prefix != NULL) + snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", + (char *)cur->ns->prefix, (char *)cur->name); + else + snprintf(nametemp, sizeof(nametemp) - 1, "%s", + (char *)cur->name); + nametemp[sizeof(nametemp) - 1] = 0; + name = nametemp; + } next = ((xmlAttrPtr) cur)->parent; } else { next = cur->parent; @@ -4827,8 +4916,8 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) xmlBufferCat(buffer, tmp->content); break; case XML_ENTITY_REF_NODE: - xmlNodeBufGetContent(buffer, tmp->children); - break; + xmlNodeBufGetContent(buffer, tmp); + break; default: break; } @@ -5082,9 +5171,10 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { case XML_ENTITY_NODE: case XML_PI_NODE: case XML_COMMENT_NODE: - if (cur->content != NULL) { + if ((cur->content != NULL) && + (cur->content != (xmlChar *) &(cur->properties))) { if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && - (!xmlDictOwns(cur->doc->dict, cur->content)))) + (xmlDictOwns(cur->doc->dict, cur->content)))) xmlFree(cur->content); } if (cur->children != NULL) xmlFreeNodeList(cur->children); @@ -5093,6 +5183,8 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { cur->content = xmlStrdup(content); } else cur->content = NULL; + cur->properties = NULL; + cur->nsDef = NULL; break; case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: @@ -5131,7 +5223,7 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { * Replace the content of a node. */ void -xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { +xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -5154,8 +5246,11 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { case XML_PI_NODE: case XML_COMMENT_NODE: case XML_NOTATION_NODE: - if (cur->content != NULL) { - xmlFree(cur->content); + if ((cur->content != NULL) && + (cur->content != (xmlChar *) &(cur->properties))) { + if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && + (xmlDictOwns(cur->doc->dict, cur->content)))) + xmlFree(cur->content); } if (cur->children != NULL) xmlFreeNodeList(cur->children); cur->children = cur->last = NULL; @@ -5163,6 +5258,8 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { cur->content = xmlStrndup(content, len); } else cur->content = NULL; + cur->properties = NULL; + cur->nsDef = NULL; break; case XML_DOCUMENT_NODE: case XML_DTD_NODE: @@ -5197,7 +5294,7 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { * Append the extra substring to the node content. */ void -xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { +xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -5233,10 +5330,12 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { case XML_COMMENT_NODE: case XML_NOTATION_NODE: if (content != NULL) { - if ((cur->doc != NULL) && (cur->doc->dict != NULL) && - xmlDictOwns(cur->doc->dict, cur->content)) { - cur->content = - xmlStrncatNew(cur->content, content, len); + if ((cur->content == (xmlChar *) &(cur->properties)) || + ((cur->doc != NULL) && (cur->doc->dict != NULL) && + xmlDictOwns(cur->doc->dict, cur->content))) { + cur->content = xmlStrncatNew(cur->content, content, len); + cur->properties = NULL; + cur->nsDef = NULL; break; } cur->content = xmlStrncat(cur->content, content, len); @@ -5268,7 +5367,7 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, intptr_t len) { */ void xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { - intptr_t len; + int len; if (cur == NULL) { #ifdef DEBUG_TREE @@ -5412,6 +5511,11 @@ xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { node->nsDef = cur; return(cur); } + if (doc == NULL) { + doc = node->doc; + if (doc == NULL) + return(NULL); + } if (doc->oldNs == NULL) { /* * Allocate a new Namespace and fill the fields. @@ -5549,6 +5653,11 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) node->nsDef = cur; return (cur); } + if (doc == NULL) { + doc = node->doc; + if (doc == NULL) + return(NULL); + } if (doc->oldNs == NULL) { /* * Allocate a new Namespace and fill the fields. @@ -5862,6 +5971,154 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) { } #endif /* LIBXML_TREE_ENABLED */ +static xmlAttrPtr +xmlGetPropNodeInternal(xmlNodePtr node, const xmlChar *name, + const xmlChar *nsName, int useDTD) +{ + xmlAttrPtr prop; + + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) + return(NULL); + + if (node->properties != NULL) { + prop = node->properties; + if (nsName == NULL) { + /* + * We want the attr to be in no namespace. + */ + do { + if ((prop->ns == NULL) && xmlStrEqual(prop->name, name)) { + return(prop); + } + prop = prop->next; + } while (prop != NULL); + } else { + /* + * We want the attr to be in the specified namespace. + */ + do { + if ((prop->ns != NULL) && xmlStrEqual(prop->name, name) && + ((prop->ns->href == nsName) || + xmlStrEqual(prop->ns->href, nsName))) + { + return(prop); + } + prop = prop->next; + } while (prop != NULL); + } + } + +#ifdef LIBXML_TREE_ENABLED + if (! useDTD) + return(NULL); + /* + * Check if there is a default/fixed attribute declaration in + * the internal or external subset. + */ + if ((node->doc != NULL) && (node->doc->intSubset != NULL)) { + xmlDocPtr doc = node->doc; + xmlAttributePtr attrDecl = NULL; + xmlChar *elemQName, *tmpstr = NULL; + + /* + * We need the QName of the element for the DTD-lookup. + */ + if ((node->ns != NULL) && (node->ns->prefix != NULL)) { + tmpstr = xmlStrdup(node->ns->prefix); + tmpstr = xmlStrcat(tmpstr, BAD_CAST ":"); + tmpstr = xmlStrcat(tmpstr, node->name); + if (tmpstr == NULL) + return(NULL); + elemQName = tmpstr; + } else + elemQName = (xmlChar *) node->name; + if (nsName == NULL) { + /* + * The common and nice case: Attr in no namespace. + */ + attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, + elemQName, name, NULL); + if ((attrDecl == NULL) && (doc->extSubset != NULL)) { + attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, + elemQName, name, NULL); + } + } else { + xmlNsPtr *nsList, *cur; + + /* + * The ugly case: Search using the prefixes of in-scope + * ns-decls corresponding to @nsName. + */ + nsList = xmlGetNsList(node->doc, node); + if (nsList == NULL) { + if (tmpstr != NULL) + xmlFree(tmpstr); + return(NULL); + } + cur = nsList; + while (*cur != NULL) { + if (xmlStrEqual((*cur)->href, nsName)) { + attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elemQName, + name, (*cur)->prefix); + if (attrDecl) + break; + if (doc->extSubset != NULL) { + attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elemQName, + name, (*cur)->prefix); + if (attrDecl) + break; + } + } + cur++; + } + xmlFree(nsList); + } + if (tmpstr != NULL) + xmlFree(tmpstr); + /* + * Only default/fixed attrs are relevant. + */ + if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) + return((xmlAttrPtr) attrDecl); + } +#endif /* LIBXML_TREE_ENABLED */ + return(NULL); +} + +static xmlChar* +xmlGetPropNodeValueInternal(xmlAttrPtr prop) +{ + if (prop == NULL) + return(NULL); + if (prop->type == XML_ATTRIBUTE_NODE) { + /* + * Note that we return at least the empty string. + * TODO: Do we really always want that? + */ + if (prop->children != NULL) { + if ((prop->children == prop->last) && + ((prop->children->type == XML_TEXT_NODE) || + (prop->children->type == XML_CDATA_SECTION_NODE))) + { + /* + * Optimization for the common case: only 1 text node. + */ + return(xmlStrdup(prop->children->content)); + } else { + xmlChar *ret; + + ret = xmlNodeListGetString(prop->doc, prop->children, 1); + if (ret != NULL) + return(ret); + } + } + return(xmlStrdup((xmlChar *)"")); + } else if (prop->type == XML_ATTRIBUTE_DECL) { + return(xmlStrdup(((xmlAttributePtr)prop)->defaultValue)); + } + return(NULL); +} + /** * xmlHasProp: * @node: the node @@ -5879,7 +6136,8 @@ xmlHasProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; xmlDocPtr doc; - if ((node == NULL) || (name == NULL)) return(NULL); + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) + return(NULL); /* * Check on the properties attached to the node */ @@ -5930,86 +6188,8 @@ xmlHasProp(xmlNodePtr node, const xmlChar *name) { */ xmlAttrPtr xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { - xmlAttrPtr prop; -#ifdef LIBXML_TREE_ENABLED - xmlDocPtr doc; -#endif /* LIBXML_TREE_ENABLED */ - if (node == NULL) - return(NULL); - - prop = node->properties; - while (prop != NULL) { - /* - * One need to have - * - same attribute names - * - and the attribute carrying that namespace - */ - if (xmlStrEqual(prop->name, name)) { - if (((prop->ns != NULL) && - (xmlStrEqual(prop->ns->href, nameSpace))) || - ((prop->ns == NULL) && (nameSpace == NULL))) { - return(prop); - } - } - prop = prop->next; - } - if (!xmlCheckDTD) return(NULL); - -#ifdef LIBXML_TREE_ENABLED - /* - * Check if there is a default declaration in the internal - * or external subsets - */ - doc = node->doc; - if (doc != NULL) { - if (doc->intSubset != NULL) { - xmlAttributePtr attrDecl = NULL; - xmlNsPtr *nsList, *cur; - xmlChar *ename; - - nsList = xmlGetNsList(node->doc, node); - if (nsList == NULL) - return(NULL); - if ((node->ns != NULL) && (node->ns->prefix != NULL)) { - ename = xmlStrdup(node->ns->prefix); - ename = xmlStrcat(ename, BAD_CAST ":"); - ename = xmlStrcat(ename, node->name); - } else { - ename = xmlStrdup(node->name); - } - if (ename == NULL) { - xmlFree(nsList); - return(NULL); - } - - if (nameSpace == NULL) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename, - name, NULL); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) { - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename, - name, NULL); - } - } else { - cur = nsList; - while (*cur != NULL) { - if (xmlStrEqual((*cur)->href, nameSpace)) { - attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, ename, - name, (*cur)->prefix); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, ename, - name, (*cur)->prefix); - } - cur++; - } - } - xmlFree(nsList); - xmlFree(ename); - return((xmlAttrPtr) attrDecl); - } - } -#endif /* LIBXML_TREE_ENABLED */ - return(NULL); + return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); } /** @@ -6030,44 +6210,12 @@ xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { */ xmlChar * xmlGetProp(xmlNodePtr node, const xmlChar *name) { - xmlAttrPtr prop; - xmlDocPtr doc; + xmlAttrPtr prop; - if ((node == NULL) || (name == NULL)) return(NULL); - /* - * Check on the properties attached to the node - */ - prop = node->properties; - while (prop != NULL) { - if (xmlStrEqual(prop->name, name)) { - xmlChar *ret; - - ret = xmlNodeListGetString(node->doc, prop->children, 1); - if (ret == NULL) return(xmlStrdup((xmlChar *)"")); - return(ret); - } - prop = prop->next; - } - if (!xmlCheckDTD) return(NULL); - - /* - * Check if there is a default declaration in the internal - * or external subsets - */ - doc = node->doc; - if (doc != NULL) { - xmlAttributePtr attrDecl; - if (doc->intSubset != NULL) { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, node->name, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, node->name, name); - if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) - /* return attribute declaration only if a default value is given - (that includes #FIXED declarations) */ - return(xmlStrdup(attrDecl->defaultValue)); - } - } - return(NULL); + prop = xmlHasProp(node, name); + if (prop == NULL) + return(NULL); + return(xmlGetPropNodeValueInternal(prop)); } /** @@ -6088,43 +6236,11 @@ xmlGetProp(xmlNodePtr node, const xmlChar *name) { xmlChar * xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; - xmlDocPtr doc; - - if ((node == NULL) || (name == NULL)) return(NULL); - /* - * Check on the properties attached to the node - */ - prop = node->properties; - while (prop != NULL) { - if ((prop->ns == NULL) && (xmlStrEqual(prop->name, name))) { - xmlChar *ret; - - ret = xmlNodeListGetString(node->doc, prop->children, 1); - if (ret == NULL) return(xmlStrdup((xmlChar *)"")); - return(ret); - } - prop = prop->next; - } - if (!xmlCheckDTD) return(NULL); - - /* - * Check if there is a default declaration in the internal - * or external subsets - */ - doc = node->doc; - if (doc != NULL) { - xmlAttributePtr attrDecl; - if (doc->intSubset != NULL) { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, node->name, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, node->name, name); - if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) - /* return attribute declaration only if a default value is given - (that includes #FIXED declarations) */ - return(xmlStrdup(attrDecl->defaultValue)); - } - } - return(NULL); + + prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); + if (prop == NULL) + return(NULL); + return(xmlGetPropNodeValueInternal(prop)); } /** @@ -6145,58 +6261,11 @@ xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { xmlChar * xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { xmlAttrPtr prop; - xmlDocPtr doc; - xmlNsPtr ns; - if (node == NULL) + prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); + if (prop == NULL) return(NULL); - - prop = node->properties; - if (nameSpace == NULL) - return(xmlGetNoNsProp(node, name)); - while (prop != NULL) { - /* - * One need to have - * - same attribute names - * - and the attribute carrying that namespace - */ - if ((xmlStrEqual(prop->name, name)) && - ((prop->ns != NULL) && - (xmlStrEqual(prop->ns->href, nameSpace)))) { - xmlChar *ret; - - ret = xmlNodeListGetString(node->doc, prop->children, 1); - if (ret == NULL) return(xmlStrdup((xmlChar *)"")); - return(ret); - } - prop = prop->next; - } - if (!xmlCheckDTD) return(NULL); - - /* - * Check if there is a default declaration in the internal - * or external subsets - */ - doc = node->doc; - if (doc != NULL) { - if (doc->intSubset != NULL) { - xmlAttributePtr attrDecl; - - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, node->name, name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, node->name, name); - - if ((attrDecl != NULL) && (attrDecl->prefix != NULL)) { - /* - * The DTD declaration only allows a prefix search - */ - ns = xmlSearchNs(doc, node, attrDecl->prefix); - if ((ns != NULL) && (xmlStrEqual(ns->href, nameSpace))) - return(xmlStrdup(attrDecl->defaultValue)); - } - } - } - return(NULL); + return(xmlGetPropNodeValueInternal(prop)); } #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) @@ -6206,26 +6275,19 @@ xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { * @name: the attribute name * * Remove an attribute carried by a node. + * This handles only attributes in no namespace. * Returns 0 if successful, -1 if not found */ int xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { - xmlAttrPtr prop, prev = NULL;; + xmlAttrPtr prop; - if ((node == NULL) || (name == NULL)) + prop = xmlGetPropNodeInternal(node, name, NULL, 0); + if (prop == NULL) return(-1); - prop = node->properties; - while (prop != NULL) { - if ((xmlStrEqual(prop->name, name)) && - (prop->ns == NULL)) { - xmlUnlinkNode((xmlNodePtr) prop); - xmlFreeProp(prop); - return(0); - } - prev = prop; - prop = prop->next; - } - return(-1); + xmlUnlinkNode((xmlNodePtr) prop); + xmlFreeProp(prop); + return(0); } /** @@ -6239,26 +6301,14 @@ xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { */ int xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { - xmlAttrPtr prop, prev = NULL;; - - if ((node == NULL) || (name == NULL)) + xmlAttrPtr prop; + + prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0); + if (prop == NULL) return(-1); - prop = node->properties; - if (ns == NULL) - return(xmlUnsetProp(node, name)); - if (ns->href == NULL) - return(-1); - while (prop != NULL) { - if ((xmlStrEqual(prop->name, name)) && - (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { - xmlUnlinkNode((xmlNodePtr) prop); - xmlFreeProp(prop); - return(0); - } - prev = prop; - prop = prop->next; - } - return(-1); + xmlUnlinkNode((xmlNodePtr) prop); + xmlFreeProp(prop); + return(0); } #endif @@ -6266,54 +6316,39 @@ xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { /** * xmlSetProp: * @node: the node - * @name: the attribute name + * @name: the attribute name (a QName) * @value: the attribute value * * Set (or reset) an attribute carried by a node. + * If @name has a prefix, then the corresponding + * namespace-binding will be used, if in scope; it is an + * error it there's no such ns-binding for the prefix in + * scope. * Returns the attribute pointer. + * */ xmlAttrPtr xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { - xmlAttrPtr prop; - xmlDocPtr doc; + int len; + const xmlChar *nqname; if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) return(NULL); - doc = node->doc; - prop = node->properties; - while (prop != NULL) { - if ((xmlStrEqual(prop->name, name)) && - (prop->ns == NULL)){ - xmlNodePtr oldprop = prop->children; - prop->children = NULL; - prop->last = NULL; - if (value != NULL) { - xmlChar *buffer; - xmlNodePtr tmp; - - buffer = xmlEncodeEntitiesReentrant(node->doc, value); - prop->children = xmlStringGetNodeList(node->doc, buffer); - prop->last = NULL; - prop->doc = doc; - tmp = prop->children; - while (tmp != NULL) { - tmp->parent = (xmlNodePtr) prop; - tmp->doc = doc; - if (tmp->next == NULL) - prop->last = tmp; - tmp = tmp->next; - } - xmlFree(buffer); - } - if (oldprop != NULL) - xmlFreeNodeList(oldprop); - return(prop); - } - prop = prop->next; + /* + * handle QNames + */ + nqname = xmlSplitQName3(name, &len); + if (nqname != NULL) { + xmlNsPtr ns; + xmlChar *prefix = xmlStrndup(name, len); + ns = xmlSearchNs(node->doc, node, prefix); + if (prefix != NULL) + xmlFree(prefix); + if (ns != NULL) + return(xmlSetNsProp(node, ns, nqname, value)); } - prop = xmlNewProp(node, name, value); - return(prop); + return(xmlSetNsProp(node, NULL, name, value)); } /** @@ -6324,59 +6359,56 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { * @value: the attribute value * * Set (or reset) an attribute carried by a node. - * The ns structure must be in scope, this is not checked. + * The ns structure must be in scope, this is not checked * * Returns the attribute pointer. */ xmlAttrPtr xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, - const xmlChar *value) { + const xmlChar *value) +{ xmlAttrPtr prop; - if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) + if (ns && (ns->href == NULL)) return(NULL); - - if (ns == NULL) - return(xmlSetProp(node, name, value)); - if (ns->href == NULL) - return(NULL); - prop = node->properties; - - while (prop != NULL) { + prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0); + if (prop != NULL) { /* - * One need to have - * - same attribute names - * - and the attribute carrying that namespace - */ - if ((xmlStrEqual(prop->name, name)) && - (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { - if (prop->children != NULL) - xmlFreeNodeList(prop->children); - prop->children = NULL; + * Modify the attribute's value. + */ + if (prop->atype == XML_ATTRIBUTE_ID) { + xmlRemoveID(node->doc, prop); + prop->atype = XML_ATTRIBUTE_ID; + } + if (prop->children != NULL) + xmlFreeNodeList(prop->children); + prop->children = NULL; + prop->last = NULL; + prop->ns = ns; + if (value != NULL) { + xmlChar *buffer; + xmlNodePtr tmp; + + buffer = xmlEncodeEntitiesReentrant(node->doc, value); + prop->children = xmlStringGetNodeList(node->doc, buffer); prop->last = NULL; - prop->ns = ns; - if (value != NULL) { - xmlChar *buffer; - xmlNodePtr tmp; - - buffer = xmlEncodeEntitiesReentrant(node->doc, value); - prop->children = xmlStringGetNodeList(node->doc, buffer); - prop->last = NULL; - tmp = prop->children; - while (tmp != NULL) { - tmp->parent = (xmlNodePtr) prop; - if (tmp->next == NULL) - prop->last = tmp; - tmp = tmp->next; - } - xmlFree(buffer); - } - return(prop); - } - prop = prop->next; + tmp = prop->children; + while (tmp != NULL) { + tmp->parent = (xmlNodePtr) prop; + if (tmp->next == NULL) + prop->last = tmp; + tmp = tmp->next; + } + xmlFree(buffer); + } + if (prop->atype == XML_ATTRIBUTE_ID) + xmlAddID(NULL, node->doc, value, prop); + return(prop); } - prop = xmlNewNsProp(node, ns, name, value); - return(prop); + /* + * No equal attr found; create a new one. + */ + return(xmlNewPropInternal(node, ns, name, value, 0)); } #endif /* LIBXML_TREE_ENABLED */ @@ -6435,7 +6467,7 @@ xmlIsBlankNode(xmlNodePtr node) { */ int -xmlTextConcat(xmlNodePtr node, const xmlChar *content, intptr_t len) { +xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { if (node == NULL) return(-1); if ((node->type != XML_TEXT_NODE) && @@ -6447,12 +6479,14 @@ xmlTextConcat(xmlNodePtr node, const xmlChar *content, intptr_t len) { return(-1); } /* need to check if content is currently in the dictionary */ - if ((node->doc != NULL) && (node->doc->dict != NULL) && - xmlDictOwns(node->doc->dict, node->content)) { + if ((node->content == (xmlChar *) &(node->properties)) || + ((node->doc != NULL) && (node->doc->dict != NULL) && + xmlDictOwns(node->doc->dict, node->content))) { node->content = xmlStrncatNew(node->content, content, len); } else { node->content = xmlStrncat(node->content, content, len); } + node->properties = NULL; if (node->content == NULL) return(-1); return(0); @@ -6627,8 +6661,8 @@ xmlBufferEmpty(xmlBufferPtr buf) { * * Returns the number of #xmlChar removed, or -1 in case of failure. */ -intptr_t -xmlBufferShrink(xmlBufferPtr buf, size_t len) { +int +xmlBufferShrink(xmlBufferPtr buf, unsigned int len) { if (buf == NULL) return(-1); if (len == 0) return(0); if (len > buf->use) return(-1); @@ -6652,9 +6686,9 @@ xmlBufferShrink(xmlBufferPtr buf, size_t len) { * * Returns the new available space or -1 in case of error */ -intptr_t -xmlBufferGrow(xmlBufferPtr buf, size_t len) { - intptr_t size; +int +xmlBufferGrow(xmlBufferPtr buf, unsigned int len) { + int size; xmlChar *newbuf; if (buf == NULL) return(-1); @@ -6693,9 +6727,9 @@ xmlBufferGrow(xmlBufferPtr buf, size_t len) { * Dumps an XML buffer to a FILE *. * Returns the number of #xmlChar written */ -intptr_t +int xmlBufferDump(FILE *file, xmlBufferPtr buf) { - intptr_t ret; + int ret; if (buf == NULL) { #ifdef DEBUG_BUFFER @@ -6744,7 +6778,7 @@ xmlBufferContent(const xmlBufferPtr buf) * Returns the length of data in the internal content */ -size_t +int xmlBufferLength(const xmlBufferPtr buf) { if(!buf) @@ -6763,9 +6797,9 @@ xmlBufferLength(const xmlBufferPtr buf) * Returns 0 in case of problems, 1 otherwise */ int -xmlBufferResize(xmlBufferPtr buf, size_t size) +xmlBufferResize(xmlBufferPtr buf, unsigned int size) { - size_t newSize; + unsigned int newSize; xmlChar* rebuf = NULL; if (buf == NULL) @@ -6833,8 +6867,8 @@ xmlBufferResize(xmlBufferPtr buf, size_t size) * and -1 in case of internal or API error. */ int -xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, intptr_t len) { - size_t needSize; +xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { + unsigned int needSize; if ((str == NULL) || (buf == NULL)) { return -1; @@ -6881,8 +6915,8 @@ xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, intptr_t len) { * and -1 in case of internal or API error. */ int -xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, intptr_t len) { - size_t needSize; +xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) { + unsigned int needSize; if (buf == NULL) return(-1); @@ -7119,5 +7153,2263 @@ xmlSetCompressMode(int mode) { else xmlCompressMode = mode; } +/* +* xmlDOMWrapNewCtxt: +* +* Allocates and initializes a new DOM-wrapper context. +* +* Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. +*/ +xmlDOMWrapCtxtPtr +xmlDOMWrapNewCtxt(void) +{ + xmlDOMWrapCtxtPtr ret; + + ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); + if (ret == NULL) { + xmlTreeErrMemory("allocating DOM-wrapper context"); + return (NULL); + } + memset(ret, 0, sizeof(xmlDOMWrapCtxt)); + return (ret); +} + +/* +* xmlDOMWrapFreeCtxt: +* @ctxt: the DOM-wrapper context +* +* Frees the DOM-wrapper context. +*/ +void +xmlDOMWrapFreeCtxt(xmlDOMWrapCtxtPtr ctxt) +{ + if (ctxt == NULL) + return; + xmlFree(ctxt); +} + +#define XML_TREE_NSMAP_PARENT -1 +#define XML_TREE_NSMAP_XML -2 +#define XML_TREE_NSMAP_DOC -3 +#define XML_TREE_NSMAP_CUSTOM -4 + +typedef struct xmlNsMapItem *xmlNsMapItemPtr; +struct xmlNsMapItem { + xmlNsMapItemPtr next; + xmlNsMapItemPtr prev; + xmlNsPtr oldNs; /* old ns decl reference */ + xmlNsPtr newNs; /* new ns decl reference */ + int shadowDepth; /* Shadowed at this depth */ + /* + * depth: + * >= 0 == @node's ns-decls + * -1 == @parent's ns-decls + * -2 == the doc->oldNs XML ns-decl + * -3 == the doc->oldNs storage ns-decls + * -4 == ns-decls provided via custom ns-handling + */ + int depth; +}; + +typedef struct xmlNsMap *xmlNsMapPtr; +struct xmlNsMap { + xmlNsMapItemPtr first; + xmlNsMapItemPtr last; + xmlNsMapItemPtr pool; +}; + +#define XML_NSMAP_NOTEMPTY(m) (((m) != NULL) && ((m)->first != NULL)) +#define XML_NSMAP_FOREACH(m, i) for (i = (m)->first; i != NULL; i = (i)->next) +#define XML_NSMAP_POP(m, i) \ + i = (m)->last; \ + (m)->last = (i)->prev; \ + if ((m)->last == NULL) \ + (m)->first = NULL; \ + else \ + (m)->last->next = NULL; \ + (i)->next = (m)->pool; \ + (m)->pool = i; + +/* +* xmlDOMWrapNsMapFree: +* @map: the ns-map +* +* Frees the ns-map +*/ +static void +xmlDOMWrapNsMapFree(xmlNsMapPtr nsmap) +{ + xmlNsMapItemPtr cur, tmp; + + if (nsmap == NULL) + return; + cur = nsmap->pool; + while (cur != NULL) { + tmp = cur; + cur = cur->next; + xmlFree(tmp); + } + cur = nsmap->first; + while (cur != NULL) { + tmp = cur; + cur = cur->next; + xmlFree(tmp); + } + xmlFree(nsmap); +} + +/* +* xmlDOMWrapNsMapAddItem: +* @map: the ns-map +* @cur: the current map entry to append a new entry to +* @oldNs: the old ns-struct +* @newNs: the new ns-struct +* @depth: depth and ns-kind information +* +* Adds an ns-mapping item. +*/ +static xmlNsMapItemPtr +xmlDOMWrapNsMapAddItem(xmlNsMapPtr *nsmap, int position, /* xmlNsMapItemPtr *cur, */ + xmlNsPtr oldNs, xmlNsPtr newNs, int depth) +{ + xmlNsMapItemPtr ret; + xmlNsMapPtr map; + + if (nsmap == NULL) + return(NULL); + if ((position != -1) && (position != 0)) + return(NULL); + map = *nsmap; + + if (map == NULL) { + /* + * Create the ns-map. + */ + map = (xmlNsMapPtr) xmlMalloc(sizeof(struct xmlNsMap)); + if (map == NULL) { + xmlTreeErrMemory("allocating namespace map"); + return (NULL); + } + memset(map, 0, sizeof(struct xmlNsMap)); + *nsmap = map; + } + + if (map->pool != NULL) { + /* + * Reuse an item from the pool. + */ + ret = map->pool; + map->pool = ret->next; + memset(ret, 0, sizeof(struct xmlNsMapItem)); + } else { + /* + * Create a new item. + */ + ret = (xmlNsMapItemPtr) xmlMalloc(sizeof(struct xmlNsMapItem)); + if (ret == NULL) { + xmlTreeErrMemory("allocating namespace map item"); + return (NULL); + } + memset(ret, 0, sizeof(struct xmlNsMapItem)); + } + + if (map->first == NULL) { + /* + * First ever. + */ + map->first = ret; + map->last = ret; + } else if (position == -1) { + /* + * Append. + */ + ret->prev = map->last; + map->last->next = ret; + map->last = ret; + } else if (position == 0) { + /* + * Set on first position. + */ + map->first->prev = ret; + ret->next = map->first; + map->first = ret; + } else + return(NULL); + + ret->oldNs = oldNs; + ret->newNs = newNs; + ret->shadowDepth = -1; + ret->depth = depth; + return (ret); +} + +/* +* xmlTreeEnsureXMLDecl: +* @doc: the doc +* +* Ensures that there is an XML namespace declaration on the doc. +* +* Returns the XML ns-struct or NULL on API and internal errors. +*/ +static xmlNsPtr +xmlTreeEnsureXMLDecl(xmlDocPtr doc) +{ + if (doc == NULL) + return (NULL); + if (doc->oldNs != NULL) + return (doc->oldNs); + { + xmlNsPtr ns; + ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); + if (ns == NULL) { + xmlTreeErrMemory( + "allocating the XML namespace"); + return (NULL); + } + memset(ns, 0, sizeof(xmlNs)); + ns->type = XML_LOCAL_NAMESPACE; + ns->href = xmlStrdup(XML_XML_NAMESPACE); + ns->prefix = xmlStrdup((const xmlChar *)"xml"); + doc->oldNs = ns; + return (ns); + } +} + +/* +* xmlDOMWrapStoreNs: +* @doc: the doc +* @nsName: the namespace name +* @prefix: the prefix +* +* Creates or reuses an xmlNs struct on doc->oldNs with +* the given prefix and namespace name. +* +* Returns the aquired ns struct or NULL in case of an API +* or internal error. +*/ +static xmlNsPtr +xmlDOMWrapStoreNs(xmlDocPtr doc, + const xmlChar *nsName, + const xmlChar *prefix) +{ + xmlNsPtr ns; + + if (doc == NULL) + return (NULL); + ns = xmlTreeEnsureXMLDecl(doc); + if (ns == NULL) + return (NULL); + if (ns->next != NULL) { + /* Reuse. */ + ns = ns->next; + while (ns != NULL) { + if (((ns->prefix == prefix) || + xmlStrEqual(ns->prefix, prefix)) && + xmlStrEqual(ns->href, nsName)) { + return (ns); + } + if (ns->next == NULL) + break; + ns = ns->next; + } + } + /* Create. */ + ns->next = xmlNewNs(NULL, nsName, prefix); + return (ns->next); +} + +/* +* xmlTreeLookupNsListByPrefix: +* @nsList: a list of ns-structs +* @prefix: the searched prefix +* +* Searches for a ns-decl with the given prefix in @nsList. +* +* Returns the ns-decl if found, NULL if not found and on +* API errors. +*/ +static xmlNsPtr +xmlTreeNSListLookupByPrefix(xmlNsPtr nsList, const xmlChar *prefix) +{ + if (nsList == NULL) + return (NULL); + { + xmlNsPtr ns; + ns = nsList; + do { + if ((prefix == ns->prefix) || + xmlStrEqual(prefix, ns->prefix)) { + return (ns); + } + ns = ns->next; + } while (ns != NULL); + } + return (NULL); +} + +/* +* +* xmlDOMWrapNSNormGatherInScopeNs: +* @map: the namespace map +* @node: the node to start with +* +* Puts in-scope namespaces into the ns-map. +* +* Returns 0 on success, -1 on API or internal errors. +*/ +static int +xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, + xmlNodePtr node) +{ + xmlNodePtr cur; + xmlNsPtr ns; + xmlNsMapItemPtr mi; + int shadowed; + + if ((map == NULL) || (*map != NULL)) + return (-1); + /* + * Get in-scope ns-decls of @parent. + */ + cur = node; + while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) { + if (cur->type == XML_ELEMENT_NODE) { + if (cur->nsDef != NULL) { + ns = cur->nsDef; + do { + shadowed = 0; + if (XML_NSMAP_NOTEMPTY(*map)) { + /* + * Skip shadowed prefixes. + */ + XML_NSMAP_FOREACH(*map, mi) { + if ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, mi->newNs->prefix)) { + shadowed = 1; + break; + } + } + } + /* + * Insert mapping. + */ + mi = xmlDOMWrapNsMapAddItem(map, 0, NULL, + ns, XML_TREE_NSMAP_PARENT); + if (mi == NULL) + return (-1); + if (shadowed) + mi->shadowDepth = 0; + ns = ns->next; + } while (ns != NULL); + } + } + cur = cur->parent; + } + return (0); +} + +/* +* XML_TREE_ADOPT_STR: If we have a dest-dict, put @str in the dict; +* otherwise copy it, when it was in the source-dict. +*/ +#define XML_TREE_ADOPT_STR(str) \ + if (adoptStr && (str != NULL)) { \ + if (destDoc->dict) { \ + const xmlChar *old = str; \ + str = xmlDictLookup(destDoc->dict, str, -1); \ + if ((sourceDoc == NULL) || (sourceDoc->dict == NULL) || \ + (!xmlDictOwns(sourceDoc->dict, old))) \ + xmlFree((char *)old); \ + } else if ((sourceDoc) && (sourceDoc->dict) && \ + xmlDictOwns(sourceDoc->dict, str)) { \ + str = BAD_CAST xmlStrdup(str); \ + } \ + } + +/* +* XML_TREE_ADOPT_STR_2: If @str was in the source-dict, then +* put it in dest-dict or copy it. +*/ +#define XML_TREE_ADOPT_STR_2(str) \ + if (adoptStr && (str != NULL) && (sourceDoc != NULL) && \ + (sourceDoc->dict != NULL) && \ + xmlDictOwns(sourceDoc->dict, cur->content)) { \ + if (destDoc->dict) \ + cur->content = (xmlChar *) \ + xmlDictLookup(destDoc->dict, cur->content, -1); \ + else \ + cur->content = xmlStrdup(BAD_CAST cur->content); \ + } + +/* +* xmlDOMWrapNSNormAddNsMapItem2: +* +* For internal use. Adds a ns-decl mapping. +* +* Returns 0 on success, -1 on internal errors. +*/ +static int +xmlDOMWrapNSNormAddNsMapItem2(xmlNsPtr **list, int *size, int *number, + xmlNsPtr oldNs, xmlNsPtr newNs) +{ + if (*list == NULL) { + *list = (xmlNsPtr *) xmlMalloc(6 * sizeof(xmlNsPtr)); + if (*list == NULL) { + xmlTreeErrMemory("alloc ns map item"); + return(-1); + } + *size = 3; + *number = 0; + } else if ((*number) >= (*size)) { + *size *= 2; + *list = (xmlNsPtr *) xmlRealloc(*list, + (*size) * 2 * sizeof(xmlNsPtr)); + if (*list == NULL) { + xmlTreeErrMemory("realloc ns map item"); + return(-1); + } + } + (*list)[2 * (*number)] = oldNs; + (*list)[2 * (*number) +1] = newNs; + (*number)++; + return (0); +} + +/* +* xmlDOMWrapRemoveNode: +* @ctxt: a DOM wrapper context +* @doc: the doc +* @node: the node to be removed. +* @options: set of options, unused at the moment +* +* Unlinks the given node from its owner. +* This will substitute ns-references to node->nsDef for +* ns-references to doc->oldNs, thus ensuring the removed +* branch to be autark wrt ns-references. +* WARNING: This function is in a experimental state. +* +* Returns 0 on success, 1 if the node is not supported, +* -1 on API and internal errors. +*/ +int +xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr node, int options ATTRIBUTE_UNUSED) +{ + xmlNsPtr *list = NULL; + int sizeList, nbList, i, j; + xmlNsPtr ns; + + if ((node == NULL) || (doc == NULL) || (node->doc != doc)) + return (-1); + + /* TODO: 0 or -1 ? */ + if (node->parent == NULL) + return (0); + + switch (node->type) { + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_ENTITY_REF_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + xmlUnlinkNode(node); + return (0); + case XML_ELEMENT_NODE: + case XML_ATTRIBUTE_NODE: + break; + default: + return (1); + } + xmlUnlinkNode(node); + /* + * Save out-of-scope ns-references in doc->oldNs. + */ + do { + switch (node->type) { + case XML_ELEMENT_NODE: + if ((ctxt == NULL) && (node->nsDef != NULL)) { + ns = node->nsDef; + do { + if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, + &nbList, ns, ns) == -1) + goto internal_error; + ns = ns->next; + } while (ns != NULL); + } + /* No break on purpose. */ + case XML_ATTRIBUTE_NODE: + if (node->ns != NULL) { + /* + * Find a mapping. + */ + if (list != NULL) { + for (i = 0, j = 0; i < nbList; i++, j += 2) { + if (node->ns == list[j]) { + node->ns = list[++j]; + goto next_node; + } + } + } + ns = NULL; + if (ctxt != NULL) { + /* + * User defined. + */ + } else { + /* + * Add to doc's oldNs. + */ + ns = xmlDOMWrapStoreNs(doc, node->ns->href, + node->ns->prefix); + if (ns == NULL) + goto internal_error; + } + if (ns != NULL) { + /* + * Add mapping. + */ + if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, + &nbList, node->ns, ns) == -1) + goto internal_error; + } + node->ns = ns; + } + if ((node->type == XML_ELEMENT_NODE) && + (node->properties != NULL)) { + node = (xmlNodePtr) node->properties; + continue; + } + break; + default: + goto next_sibling; + } +next_node: + if ((node->type == XML_ELEMENT_NODE) && + (node->children != NULL)) { + node = node->children; + continue; + } +next_sibling: + if (node == NULL) + break; + if (node->next != NULL) + node = node->next; + else { + node = node->parent; + goto next_sibling; + } + } while (node != NULL); + + if (list != NULL) + xmlFree(list); + return (0); + +internal_error: + if (list != NULL) + xmlFree(list); + return (-1); +} + +/* +* xmlSearchNsByNamespaceStrict: +* @doc: the document +* @node: the start node +* @nsName: the searched namespace name +* @retNs: the resulting ns-decl +* @prefixed: if the found ns-decl must have a prefix (for attributes) +* +* Dynamically searches for a ns-declaration which matches +* the given @nsName in the ancestor-or-self axis of @node. +* +* Returns 1 if a ns-decl was found, 0 if not and -1 on API +* and internal errors. +*/ +static int +xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, + const xmlChar* nsName, + xmlNsPtr *retNs, int prefixed) +{ + xmlNodePtr cur, prev = NULL, out = NULL; + xmlNsPtr ns, prevns; + + if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) + return (-1); + + *retNs = NULL; + if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { + *retNs = xmlTreeEnsureXMLDecl(doc); + if (*retNs == NULL) + return (-1); + return (1); + } + cur = node; + do { + if (cur->type == XML_ELEMENT_NODE) { + if (cur->nsDef != NULL) { + for (ns = cur->nsDef; ns != NULL; ns = ns->next) { + if (prefixed && (ns->prefix == NULL)) + continue; + if (prev != NULL) { + /* + * Check the last level of ns-decls for a + * shadowing prefix. + */ + prevns = prev->nsDef; + do { + if ((prevns->prefix == ns->prefix) || + ((prevns->prefix != NULL) && + (ns->prefix != NULL) && + xmlStrEqual(prevns->prefix, ns->prefix))) { + /* + * Shadowed. + */ + break; + } + prevns = prevns->next; + } while (prevns != NULL); + if (prevns != NULL) + continue; + } + /* + * Ns-name comparison. + */ + if ((nsName == ns->href) || + xmlStrEqual(nsName, ns->href)) { + /* + * At this point the prefix can only be shadowed, + * if we are the the (at least) 3rd level of + * ns-decls. + */ + if (out) { + int ret; + + ret = xmlNsInScope(doc, node, prev, ns->prefix); + if (ret < 0) + return (-1); + /* + * TODO: Should we try to find a matching ns-name + * only once? This here keeps on searching. + * I think we should try further since, there might + * be an other matching ns-decl with an unshadowed + * prefix. + */ + if (! ret) + continue; + } + *retNs = ns; + return (1); + } + } + out = prev; + prev = cur; + } + } else if ((cur->type == XML_ENTITY_NODE) || + (cur->type == XML_ENTITY_DECL)) + return (0); + cur = cur->parent; + } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); + return (0); +} + +/* +* xmlSearchNsByPrefixStrict: +* @doc: the document +* @node: the start node +* @prefix: the searched namespace prefix +* @retNs: the resulting ns-decl +* @prefixed: if the found ns-decl must have a prefix (for attributes) +* +* Dynamically searches for a ns-declaration which matches +* the given @nsName in the ancestor-or-self axis of @node. +* +* Returns 1 if a ns-decl was found, 0 if not and -1 on API +* and internal errors. +*/ +static int +xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, + const xmlChar* prefix, + xmlNsPtr *retNs) +{ + xmlNodePtr cur; + xmlNsPtr ns; + + if ((doc == NULL) || (node == NULL)) + return (-1); + + if (retNs) + *retNs = NULL; + if (IS_STR_XML(prefix)) { + if (retNs) { + *retNs = xmlTreeEnsureXMLDecl(doc); + if (*retNs == NULL) + return (-1); + } + return (1); + } + cur = node; + do { + if (cur->type == XML_ELEMENT_NODE) { + if (cur->nsDef != NULL) { + ns = cur->nsDef; + do { + if ((prefix == ns->prefix) || + xmlStrEqual(prefix, ns->prefix)) + { + /* + * Disabled namespaces, e.g. xmlns:abc="". + */ + if (ns->href == NULL) + return(0); + if (retNs) + *retNs = ns; + return (1); + } + ns = ns->next; + } while (ns != NULL); + } + } else if ((cur->type == XML_ENTITY_NODE) || + (cur->type == XML_ENTITY_DECL)) + return (0); + cur = cur->parent; + } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); + return (0); +} + +/* +* xmlDOMWrapNSNormDeclareNsForced: +* @doc: the doc +* @elem: the element-node to declare on +* @nsName: the namespace-name of the ns-decl +* @prefix: the preferred prefix of the ns-decl +* @checkShadow: ensure that the new ns-decl doesn't shadow ancestor ns-decls +* +* Declares a new namespace on @elem. It tries to use the +* given @prefix; if a ns-decl with the given prefix is already existent +* on @elem, it will generate an other prefix. +* +* Returns 1 if a ns-decl was found, 0 if not and -1 on API +* and internal errors. +*/ +static xmlNsPtr +xmlDOMWrapNSNormDeclareNsForced(xmlDocPtr doc, + xmlNodePtr elem, + const xmlChar *nsName, + const xmlChar *prefix, + int checkShadow) +{ + + xmlNsPtr ret; + char buf[50]; + const xmlChar *pref; + int counter = 0; + /* + * Create a ns-decl on @anchor. + */ + pref = prefix; + while (1) { + /* + * Lookup whether the prefix is unused in elem's ns-decls. + */ + if ((elem->nsDef != NULL) && + (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL)) + goto ns_next_prefix; + if (checkShadow && elem->parent && + ((xmlNodePtr) elem->parent->doc != elem->parent)) { + /* + * Does it shadow ancestor ns-decls? + */ + if (xmlSearchNsByPrefixStrict(doc, elem->parent, pref, NULL) == 1) + goto ns_next_prefix; + } + ret = xmlNewNs(NULL, nsName, pref); + if (ret == NULL) + return (NULL); + if (elem->nsDef == NULL) + elem->nsDef = ret; + else { + xmlNsPtr ns2 = elem->nsDef; + while (ns2->next != NULL) + ns2 = ns2->next; + ns2->next = ret; + } + return (ret); +ns_next_prefix: + counter++; + if (counter > 1000) + return (NULL); + if (prefix == NULL) { + snprintf((char *) buf, sizeof(buf), + "default%d", counter); + } else + snprintf((char *) buf, sizeof(buf), + "%.30s%d", (char *)prefix, counter); + pref = BAD_CAST buf; + } +} + +/* +* xmlDOMWrapNSNormAquireNormalizedNs: +* @doc: the doc +* @elem: the element-node to declare namespaces on +* @ns: the ns-struct to use for the search +* @retNs: the found/created ns-struct +* @nsMap: the ns-map +* @topmi: the last ns-map entry +* @depth: the current tree depth +* @ancestorsOnly: search in ancestor ns-decls only +* @prefixed: if the searched ns-decl must have a prefix (for attributes) +* +* Searches for a matching ns-name in the ns-decls of @nsMap, if not +* found it will either declare it on @elem, or store it in doc->oldNs. +* If a new ns-decl needs to be declared on @elem, it tries to use the +* @ns->prefix for it, if this prefix is already in use on @elem, it will +* change the prefix or the new ns-decl. +* +* Returns 0 if succeeded, -1 otherwise and on API/internal errors. +*/ +static int +xmlDOMWrapNSNormAquireNormalizedNs(xmlDocPtr doc, + xmlNodePtr elem, + xmlNsPtr ns, + xmlNsPtr *retNs, + xmlNsMapPtr *nsMap, + + int depth, + int ancestorsOnly, + int prefixed) +{ + xmlNsMapItemPtr mi; + + if ((doc == NULL) || (ns == NULL) || (retNs == NULL) || + (nsMap == NULL)) + return (-1); + + *retNs = NULL; + /* + * Handle XML namespace. + */ + if (IS_STR_XML(ns->prefix)) { + /* + * Insert XML namespace mapping. + */ + *retNs = xmlTreeEnsureXMLDecl(doc); + if (*retNs == NULL) + return (-1); + return (0); + } + /* + * If the search should be done in ancestors only and no + * @elem (the first ancestor) was specified, then skip the search. + */ + if ((! (ancestorsOnly && (elem == NULL))) && (XML_NSMAP_NOTEMPTY(*nsMap))) + { + /* + * Try to find an equal ns-name in in-scope ns-decls. + */ + XML_NSMAP_FOREACH(*nsMap, mi) { + if ((mi->depth >= XML_TREE_NSMAP_PARENT) && + /* + * ancestorsOnly: This should be turned on to gain speed, + * if one knows that the branch itself was already + * ns-wellformed and no stale references existed. + * I.e. it searches in the ancestor axis only. + */ + ((! ancestorsOnly) || (mi->depth == XML_TREE_NSMAP_PARENT)) && + /* Skip shadowed prefixes. */ + (mi->shadowDepth == -1) && + /* Skip xmlns="" or xmlns:foo="". */ + ((mi->newNs->href != NULL) && + (mi->newNs->href[0] != 0)) && + /* Ensure a prefix if wanted. */ + ((! prefixed) || (mi->newNs->prefix != NULL)) && + /* Equal ns name */ + ((mi->newNs->href == ns->href) || + xmlStrEqual(mi->newNs->href, ns->href))) { + /* Set the mapping. */ + mi->oldNs = ns; + *retNs = mi->newNs; + return (0); + } + } + } + /* + * No luck, the namespace is out of scope or shadowed. + */ + if (elem == NULL) { + xmlNsPtr tmpns; + + /* + * Store ns-decls in "oldNs" of the document-node. + */ + tmpns = xmlDOMWrapStoreNs(doc, ns->href, ns->prefix); + if (tmpns == NULL) + return (-1); + /* + * Insert mapping. + */ + if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, + tmpns, XML_TREE_NSMAP_DOC) == NULL) { + xmlFreeNs(tmpns); + return (-1); + } + *retNs = tmpns; + } else { + xmlNsPtr tmpns; + + tmpns = xmlDOMWrapNSNormDeclareNsForced(doc, elem, ns->href, + ns->prefix, 0); + if (tmpns == NULL) + return (-1); + + if (*nsMap != NULL) { + /* + * Does it shadow ancestor ns-decls? + */ + XML_NSMAP_FOREACH(*nsMap, mi) { + if ((mi->depth < depth) && + (mi->shadowDepth == -1) && + ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, mi->newNs->prefix))) { + /* + * Shadows. + */ + mi->shadowDepth = depth; + break; + } + } + } + if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, tmpns, depth) == NULL) { + xmlFreeNs(tmpns); + return (-1); + } + *retNs = tmpns; + } + return (0); +} + +typedef enum { + XML_DOM_RECONNS_REMOVEREDUND = 1<<0 +} xmlDOMReconcileNSOptions; + +/* +* xmlDOMWrapReconcileNamespaces: +* @ctxt: DOM wrapper context, unused at the moment +* @elem: the element-node +* @options: option flags +* +* Ensures that ns-references point to ns-decls hold on element-nodes. +* Ensures that the tree is namespace wellformed by creating additional +* ns-decls where needed. Note that, since prefixes of already existent +* ns-decls can be shadowed by this process, it could break QNames in +* attribute values or element content. +* WARNING: This function is in a experimental state. +* +* Returns 0 if succeeded, -1 otherwise and on API/internal errors. +*/ + +int +xmlDOMWrapReconcileNamespaces(xmlDOMWrapCtxtPtr ctxt ATTRIBUTE_UNUSED, + xmlNodePtr elem, + int options) +{ + int depth = -1, adoptns = 0, parnsdone = 0; + xmlNsPtr ns, prevns; + xmlDocPtr doc; + xmlNodePtr cur, curElem = NULL; + xmlNsMapPtr nsMap = NULL; + xmlNsMapItemPtr /* topmi = NULL, */ mi; + /* @ancestorsOnly should be set by an option flag. */ + int ancestorsOnly = 0; + int optRemoveDedundantNS = + ((xmlDOMReconcileNSOptions) options & XML_DOM_RECONNS_REMOVEREDUND) ? 1 : 0; + xmlNsPtr *listRedund = NULL; + int sizeRedund = 0, nbRedund = 0, ret, i, j; + + if ((elem == NULL) || (elem->doc == NULL) || + (elem->type != XML_ELEMENT_NODE)) + return (-1); + + doc = elem->doc; + cur = elem; + do { + switch (cur->type) { + case XML_ELEMENT_NODE: + adoptns = 1; + curElem = cur; + depth++; + /* + * Namespace declarations. + */ + if (cur->nsDef != NULL) { + prevns = NULL; + ns = cur->nsDef; + while (ns != NULL) { + if (! parnsdone) { + if ((elem->parent) && + ((xmlNodePtr) elem->parent->doc != elem->parent)) { + /* + * Gather ancestor in-scope ns-decls. + */ + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, + elem->parent) == -1) + goto internal_error; + } + parnsdone = 1; + } + + /* + * Lookup the ns ancestor-axis for equal ns-decls in scope. + */ + if (optRemoveDedundantNS && XML_NSMAP_NOTEMPTY(nsMap)) { + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->depth >= XML_TREE_NSMAP_PARENT) && + (mi->shadowDepth == -1) && + ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, mi->newNs->prefix)) && + ((ns->href == mi->newNs->href) || + xmlStrEqual(ns->href, mi->newNs->href))) + { + /* + * A redundant ns-decl was found. + * Add it to the list of redundant ns-decls. + */ + if (xmlDOMWrapNSNormAddNsMapItem2(&listRedund, + &sizeRedund, &nbRedund, ns, mi->newNs) == -1) + goto internal_error; + /* + * Remove the ns-decl from the element-node. + */ + if (prevns) + prevns->next = ns->next; + else + cur->nsDef = ns->next; + goto next_ns_decl; + } + } + } + + /* + * Skip ns-references handling if the referenced + * ns-decl is declared on the same element. + */ + if ((cur->ns != NULL) && adoptns && (cur->ns == ns)) + adoptns = 0; + /* + * Does it shadow any ns-decl? + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->depth >= XML_TREE_NSMAP_PARENT) && + (mi->shadowDepth == -1) && + ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, mi->newNs->prefix))) { + + mi->shadowDepth = depth; + } + } + } + /* + * Push mapping. + */ + if (xmlDOMWrapNsMapAddItem(&nsMap, -1, ns, ns, + depth) == NULL) + goto internal_error; + + prevns = ns; +next_ns_decl: + ns = ns->next; + } + } + if (! adoptns) + goto ns_end; + /* No break on purpose. */ + case XML_ATTRIBUTE_NODE: + /* No ns, no fun. */ + if (cur->ns == NULL) + goto ns_end; + + if (! parnsdone) { + if ((elem->parent) && + ((xmlNodePtr) elem->parent->doc != elem->parent)) { + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, + elem->parent) == -1) + goto internal_error; + } + parnsdone = 1; + } + /* + * Adjust the reference if this was a redundant ns-decl. + */ + if (listRedund) { + for (i = 0, j = 0; i < nbRedund; i++, j += 2) { + if (cur->ns == listRedund[j]) { + cur->ns = listRedund[++j]; + break; + } + } + } + /* + * Adopt ns-references. + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Search for a mapping. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->shadowDepth == -1) && + (cur->ns == mi->oldNs)) { + + cur->ns = mi->newNs; + goto ns_end; + } + } + } + /* + * Aquire a normalized ns-decl and add it to the map. + */ + if (xmlDOMWrapNSNormAquireNormalizedNs(doc, curElem, + cur->ns, &ns, + &nsMap, depth, + ancestorsOnly, + (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) + goto internal_error; + cur->ns = ns; + +ns_end: + if ((cur->type == XML_ELEMENT_NODE) && + (cur->properties != NULL)) { + /* + * Process attributes. + */ + cur = (xmlNodePtr) cur->properties; + continue; + } + break; + default: + goto next_sibling; + } +into_content: + if ((cur->type == XML_ELEMENT_NODE) && + (cur->children != NULL)) { + /* + * Process content of element-nodes only. + */ + cur = cur->children; + continue; + } +next_sibling: + if (cur == elem) + break; + if (cur->type == XML_ELEMENT_NODE) { + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Pop mappings. + */ + while ((nsMap->last != NULL) && + (nsMap->last->depth >= depth)) + { + XML_NSMAP_POP(nsMap, mi) + } + /* + * Unshadow. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if (mi->shadowDepth >= depth) + mi->shadowDepth = -1; + } + } + depth--; + } + if (cur->next != NULL) + cur = cur->next; + else { + if (cur->type == XML_ATTRIBUTE_NODE) { + cur = cur->parent; + goto into_content; + } + cur = cur->parent; + goto next_sibling; + } + } while (cur != NULL); + + ret = 0; + goto exit; +internal_error: + ret = -1; +exit: + if (listRedund) { + for (i = 0, j = 0; i < nbRedund; i++, j += 2) { + xmlFreeNs(listRedund[j]); + } + xmlFree(listRedund); + } + if (nsMap != NULL) + xmlDOMWrapNsMapFree(nsMap); + return (ret); +} + +/* +* xmlDOMWrapAdoptBranch: +* @ctxt: the optional context for custom processing +* @sourceDoc: the optional sourceDoc +* @node: the element-node to start with +* @destDoc: the destination doc for adoption +* @destParent: the optional new parent of @node in @destDoc +* @options: option flags +* +* Ensures that ns-references point to @destDoc: either to +* elements->nsDef entries if @destParent is given, or to +* @destDoc->oldNs otherwise. +* If @destParent is given, it ensures that the tree is namespace +* wellformed by creating additional ns-decls where needed. +* Note that, since prefixes of already existent ns-decls can be +* shadowed by this process, it could break QNames in attribute +* values or element content. +* +* Returns 0 if succeeded, -1 otherwise and on API/internal errors. +*/ +static int +xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlNodePtr node, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int options ATTRIBUTE_UNUSED) +{ + int ret = 0; + xmlNodePtr cur, curElem = NULL; + xmlNsMapPtr nsMap = NULL; + xmlNsMapItemPtr mi; + xmlNsPtr ns = NULL; + int depth = -1, adoptStr = 1; + /* gather @parent's ns-decls. */ + int parnsdone = 0; + /* @ancestorsOnly should be set per option. */ + int ancestorsOnly = 0; + + /* + * Optimize string adoption for equal or none dicts. + */ + if ((sourceDoc != NULL) && + (sourceDoc->dict == destDoc->dict)) + adoptStr = 0; + else + adoptStr = 1; + + cur = node; + while (cur != NULL) { + if (cur->doc != sourceDoc) { + /* + * We'll assume XIncluded nodes if the doc differs. + * TODO: Do we need to reconciliate XIncluded nodes? + * This here skips XIncluded nodes and tries to handle + * broken sequences. + */ + if (cur->next == NULL) + goto leave_node; + do { + cur = cur->next; + if ((cur->type == XML_XINCLUDE_END) || + (cur->doc == node->doc)) + break; + } while (cur->next != NULL); + + if (cur->doc != node->doc) + goto leave_node; + } + cur->doc = destDoc; + switch (cur->type) { + case XML_XINCLUDE_START: + case XML_XINCLUDE_END: + /* + * TODO + */ + return (-1); + case XML_ELEMENT_NODE: + curElem = cur; + depth++; + /* + * Namespace declarations. + */ + if ((ctxt == NULL) && (cur->nsDef != NULL)) { + if (! parnsdone) { + if (destParent && (ctxt == NULL)) { + /* + * Gather @parent's in-scope ns-decls. + */ + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, + destParent) == -1) + goto internal_error; + } + parnsdone = 1; + } + for (ns = cur->nsDef; ns != NULL; ns = ns->next) { + /* + * ns->prefix and ns->href seem not to be in the dict. + * XML_TREE_ADOPT_STR(ns->prefix) + * XML_TREE_ADOPT_STR(ns->href) + */ + /* + * Does it shadow any ns-decl? + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->depth >= XML_TREE_NSMAP_PARENT) && + (mi->shadowDepth == -1) && + ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, + mi->newNs->prefix))) { + + mi->shadowDepth = depth; + } + } + } + /* + * Push mapping. + */ + if (xmlDOMWrapNsMapAddItem(&nsMap, -1, + ns, ns, depth) == NULL) + goto internal_error; + } + } + /* No break on purpose. */ + case XML_ATTRIBUTE_NODE: + + if (cur->ns == NULL) + goto ns_end; + if (! parnsdone) { + if (destParent && (ctxt == NULL)) { + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, + destParent) == -1) + goto internal_error; + } + parnsdone = 1; + } + /* + * Adopt ns-references. + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Search for a mapping. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->shadowDepth == -1) && + (cur->ns == mi->oldNs)) { + + cur->ns = mi->newNs; + goto ns_end; + } + } + } + /* + * Start searching for an in-scope ns-decl. + */ + if (ctxt != NULL) { + /* + * User-defined behaviour. + */ +#if 0 + ctxt->aquireNsDecl(ctxt, cur->ns, &ns); +#endif + /* + * Insert mapping if ns is available; it's the users fault + * if not. + */ + if (xmlDOMWrapNsMapAddItem(&nsMap, -1, + ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) + goto internal_error; + cur->ns = ns; + } else { + /* + * Aquire a normalized ns-decl and add it to the map. + */ + if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, + /* ns-decls on curElem or on destDoc->oldNs */ + destParent ? curElem : NULL, + cur->ns, &ns, + &nsMap, depth, + ancestorsOnly, + /* ns-decls must be prefixed for attributes. */ + (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) + goto internal_error; + cur->ns = ns; + } +ns_end: + /* + * Further node properties. + * TODO: Is this all? + */ + XML_TREE_ADOPT_STR(cur->name) + if (cur->type == XML_ELEMENT_NODE) { + cur->psvi = NULL; + cur->line = 0; + cur->extra = 0; + /* + * Walk attributes. + */ + if (cur->properties != NULL) { + /* + * Process first attribute node. + */ + cur = (xmlNodePtr) cur->properties; + continue; + } + } else { + /* + * Attributes. + */ + if ((sourceDoc != NULL) && + (((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID)) + xmlRemoveID(sourceDoc, (xmlAttrPtr) cur); + ((xmlAttrPtr) cur)->atype = 0; + ((xmlAttrPtr) cur)->psvi = NULL; + } + break; + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + /* + * This puts the content in the dest dict, only if + * it was previously in the source dict. + */ + XML_TREE_ADOPT_STR_2(cur->content) + goto leave_node; + case XML_ENTITY_REF_NODE: + /* + * Remove reference to the entitity-node. + */ + cur->content = NULL; + cur->children = NULL; + cur->last = NULL; + if ((destDoc->intSubset) || (destDoc->extSubset)) { + xmlEntityPtr ent; + /* + * Assign new entity-node if available. + */ + ent = xmlGetDocEntity(destDoc, cur->name); + if (ent != NULL) { + cur->content = ent->content; + cur->children = (xmlNodePtr) ent; + cur->last = (xmlNodePtr) ent; + } + } + goto leave_node; + case XML_PI_NODE: + XML_TREE_ADOPT_STR(cur->name) + XML_TREE_ADOPT_STR_2(cur->content) + break; + case XML_COMMENT_NODE: + break; + default: + goto internal_error; + } + /* + * Walk the tree. + */ + if (cur->children != NULL) { + cur = cur->children; + continue; + } + +leave_node: + if (cur == node) + break; + if ((cur->type == XML_ELEMENT_NODE) || + (cur->type == XML_XINCLUDE_START) || + (cur->type == XML_XINCLUDE_END)) { + /* + * TODO: Do we expect nsDefs on XML_XINCLUDE_START? + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Pop mappings. + */ + while ((nsMap->last != NULL) && + (nsMap->last->depth >= depth)) + { + XML_NSMAP_POP(nsMap, mi) + } + /* + * Unshadow. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if (mi->shadowDepth >= depth) + mi->shadowDepth = -1; + } + } + depth--; + } + if (cur->next != NULL) + cur = cur->next; + else { + cur = cur->parent; + goto leave_node; + } + } + + goto exit; + +internal_error: + ret = -1; + +exit: + /* + * Cleanup. + */ + if (nsMap != NULL) + xmlDOMWrapNsMapFree(nsMap); + return(ret); +} + +/* +* xmlDOMWrapCloneNode: +* @ctxt: the optional context for custom processing +* @sourceDoc: the optional sourceDoc +* @node: the node to start with +* @resNode: the clone of the given @node +* @destDoc: the destination doc +* @destParent: the optional new parent of @node in @destDoc +* @deep: descend into child if set +* @options: option flags +* +* References of out-of scope ns-decls are remapped to point to @destDoc: +* 1) If @destParent is given, then nsDef entries on element-nodes are used +* 2) If *no* @destParent is given, then @destDoc->oldNs entries are used +* This is the case when you have an unliked node and just want to move it +* to the context of +* +* If @destParent is given, it ensures that the tree is namespace +* wellformed by creating additional ns-decls where needed. +* Note that, since prefixes of already existent ns-decls can be +* shadowed by this process, it could break QNames in attribute +* values or element content. +* TODO: +* 1) Support dicts +* Optimize string adoption for equal or none dicts. +* 2) XInclude +* WARNING: This function is in a experimental state and should only be currently +* only be used to test it. +* +* Returns 0 if the operation succeeded, +* 1 if a node of unsupported (or not yet supported) type was given, +* -1 on API/internal errors. +*/ + +int +xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlNodePtr node, + xmlNodePtr *resNode, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int deep, + int options ATTRIBUTE_UNUSED) +{ + int ret = 0; + xmlNodePtr cur, curElem = NULL; + xmlNsMapPtr nsMap = NULL; + xmlNsMapItemPtr mi; + xmlNsPtr ns; + int depth = -1; + /* int adoptStr = 1; */ + /* gather @parent's ns-decls. */ + int parnsdone = 0; + /* @ancestorsOnly should be set per option. */ + int ancestorsOnly = 0; + xmlNodePtr resultClone = NULL, clone = NULL, parentClone = NULL, prevClone = NULL; + xmlNsPtr cloneNs = NULL, *cloneNsDefSlot = NULL; + + if ((node == NULL) || (resNode == NULL) || (destDoc == NULL)) + return(-1); + /* + * TODO: Initially we support only element-nodes. + */ + if (node->type != XML_ELEMENT_NODE) + return(1); + /* + * Check node->doc sanity. + */ + if ((node->doc != NULL) && (sourceDoc != NULL) && + (node->doc != sourceDoc)) { + /* + * Might be an XIncluded node. + */ + return (-1); + } + if (sourceDoc == NULL) + sourceDoc = node->doc; + if (sourceDoc == NULL) + return (-1); + + *resNode = NULL; + + cur = node; + while (cur != NULL) { + if (cur->doc != sourceDoc) { + /* + * We'll assume XIncluded nodes if the doc differs. + * TODO: Do we need to reconciliate XIncluded nodes? + * TODO: This here returns -1 in this case. + */ + goto internal_error; + } + /* + * Create a new node. + */ + switch (cur->type) { + case XML_XINCLUDE_START: + case XML_XINCLUDE_END: + /* TODO: What to do with XInclude? */ + goto internal_error; + break; + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_ELEMENT_NODE: + case XML_DOCUMENT_FRAG_NODE: + case XML_ENTITY_REF_NODE: + case XML_ENTITY_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + /* + * Nodes of xmlNode structure. + */ + clone = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); + if (clone == NULL) { + xmlTreeErrMemory("xmlDOMWrapCloneBranch(): allocating a node"); + goto internal_error; + } + memset(clone, 0, sizeof(xmlNode)); + /* + * Set hierachical links. + */ + if (resultClone != NULL) { + clone->parent = parentClone; + if (prevClone) { + prevClone->next = clone; + clone->prev = prevClone; + } else + parentClone->children = clone; + } else + resultClone = clone; + + break; + case XML_ATTRIBUTE_NODE: + /* + * Attributes (xmlAttr). + */ + clone = (xmlNodePtr) xmlMalloc(sizeof(xmlAttr)); + if (clone == NULL) { + xmlTreeErrMemory("xmlDOMWrapCloneBranch(): allocating an attr-node"); + goto internal_error; + } + memset(clone, 0, sizeof(xmlAttr)); + /* + * Set hierachical links. + */ + if (resultClone != NULL) { + clone->parent = parentClone; + if (prevClone) { + prevClone->next = clone; + clone->prev = prevClone; + } else + parentClone->properties = (xmlAttrPtr) clone; + } else + resultClone = clone; + break; + default: + /* TODO */ + goto internal_error; + } + + clone->type = cur->type; + clone->doc = destDoc; + + if (cur->name == xmlStringText) + clone->name = xmlStringText; + else if (cur->name == xmlStringTextNoenc) + /* + * TODO: xmlStringTextNoenc is never assigned to a node + * in tree.c. + */ + clone->name = xmlStringTextNoenc; + else if (cur->name == xmlStringComment) + clone->name = xmlStringComment; + else if (cur->name != NULL) { + if ((destDoc != NULL) && (destDoc->dict != NULL)) + clone->name = xmlDictLookup(destDoc->dict, cur->name, -1); + else + clone->name = xmlStrdup(cur->name); + } + + switch (cur->type) { + case XML_XINCLUDE_START: + case XML_XINCLUDE_END: + /* + * TODO + */ + return (-1); + case XML_ELEMENT_NODE: + curElem = cur; + depth++; + /* + * Namespace declarations. + */ + if (cur->nsDef != NULL) { + if (! parnsdone) { + if (destParent && (ctxt == NULL)) { + /* + * Gather @parent's in-scope ns-decls. + */ + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, + destParent) == -1) + goto internal_error; + } + parnsdone = 1; + } + /* + * Clone namespace declarations. + */ + cloneNsDefSlot = &(clone->nsDef); + for (ns = cur->nsDef; ns != NULL; ns = ns->next) { + /* + * Create a new xmlNs. + */ + cloneNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); + if (cloneNs == NULL) { + xmlTreeErrMemory("xmlDOMWrapCloneBranch(): " + "allocating namespace"); + return(-1); + } + memset(cloneNs, 0, sizeof(xmlNs)); + cloneNs->type = XML_LOCAL_NAMESPACE; + + if (ns->href != NULL) + cloneNs->href = xmlStrdup(ns->href); + if (ns->prefix != NULL) + cloneNs->prefix = xmlStrdup(ns->prefix); + + *cloneNsDefSlot = cloneNs; + cloneNsDefSlot = &(cloneNs->next); + + if (ctxt == NULL) { + /* + * Does it shadow any ns-decl? + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->depth >= XML_TREE_NSMAP_PARENT) && + (mi->shadowDepth == -1) && + ((ns->prefix == mi->newNs->prefix) || + xmlStrEqual(ns->prefix, + mi->newNs->prefix))) { + /* + * Mark as shadowed at the current + * depth. + */ + mi->shadowDepth = depth; + } + } + } + /* + * Push mapping. + */ + if (xmlDOMWrapNsMapAddItem(&nsMap, -1, + ns, cloneNs, depth) == NULL) + goto internal_error; + } + } + } + /* cur->ns will be processed further down. */ + break; + case XML_ATTRIBUTE_NODE: + /* IDs will be processed further down. */ + /* cur->ns will be processed further down. */ + break; + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + if (cur->content) + clone->content = xmlStrdup(cur->content); + goto leave_node; + case XML_ENTITY_NODE: + /* TODO: What to do here? */ + goto leave_node; + case XML_ENTITY_REF_NODE: + if (sourceDoc != destDoc) { + if ((destDoc->intSubset) || (destDoc->extSubset)) { + xmlEntityPtr ent; + /* + * Different doc: Assign new entity-node if available. + */ + ent = xmlGetDocEntity(destDoc, cur->name); + if (ent != NULL) { + clone->content = ent->content; + clone->children = (xmlNodePtr) ent; + clone->last = (xmlNodePtr) ent; + } + } + } else { + /* + * Same doc: Use the current node's entity declaration + * and value. + */ + clone->content = cur->content; + clone->children = cur->children; + clone->last = cur->last; + } + goto leave_node; + case XML_PI_NODE: + if (cur->content) + clone->content = xmlStrdup(cur->content); + goto leave_node; + case XML_COMMENT_NODE: + if (cur->content) + clone->content = xmlStrdup(cur->content); + goto leave_node; + default: + goto internal_error; + } + + if (cur->ns == NULL) + goto end_ns_reference; + +/* handle_ns_reference: */ + /* + ** The following will take care of references to ns-decls ******** + ** and is intended only for element- and attribute-nodes. + ** + */ + if (! parnsdone) { + if (destParent && (ctxt == NULL)) { + if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, destParent) == -1) + goto internal_error; + } + parnsdone = 1; + } + /* + * Adopt ns-references. + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Search for a mapping. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if ((mi->shadowDepth == -1) && + (cur->ns == mi->oldNs)) { + /* + * This is the nice case: a mapping was found. + */ + clone->ns = mi->newNs; + goto end_ns_reference; + } + } + } + /* + * Start searching for an in-scope ns-decl. + */ + if (ctxt != NULL) { + /* + * User-defined behaviour. + */ +#if 0 + ctxt->aquireNsDecl(ctxt, cur->ns, &ns); +#endif + /* + * Add user's mapping. + */ + if (xmlDOMWrapNsMapAddItem(&nsMap, -1, + cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) + goto internal_error; + clone->ns = ns; + } else { + /* + * Aquire a normalized ns-decl and add it to the map. + */ + if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, + /* ns-decls on curElem or on destDoc->oldNs */ + destParent ? curElem : NULL, + cur->ns, &ns, + &nsMap, depth, + ancestorsOnly, + /* ns-decls must be prefixed for attributes. */ + (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) + goto internal_error; + clone->ns = ns; + } + +end_ns_reference: + + /* + * Some post-processing. + * + * Handle ID attributes. + */ + if ((clone->type == XML_ATTRIBUTE_NODE) && + (clone->parent != NULL)) { + if (xmlIsID(destDoc, clone->parent, (xmlAttrPtr) clone)) { + + xmlChar *idVal; + + idVal = xmlNodeListGetString(cur->doc, cur->children, 1); + if (idVal != NULL) { + if (xmlAddID(NULL, destDoc, idVal, (xmlAttrPtr) cur) == NULL) { + /* TODO: error message. */ + xmlFree(idVal); + goto internal_error; + } + xmlFree(idVal); + } + } + } + /* + ** + ** The following will traversing the tree ************************ + ** + * + * Walk the element's attributes before descending into child-nodes. + */ + if ((cur->type == XML_ELEMENT_NODE) && (cur->properties != NULL)) { + prevClone = NULL; + parentClone = clone; + cur = (xmlNodePtr) cur->properties; + continue; + } +into_content: + /* + * Descend into child-nodes. + */ + if (cur->children != NULL) { + if (deep || (cur->type == XML_ATTRIBUTE_NODE)) { + prevClone = NULL; + parentClone = clone; + cur = cur->children; + continue; + } + } + +leave_node: + /* + * At this point we are done with the node, its content + * and an element-nodes's attribute-nodes. + */ + if (cur == node) + break; + if ((cur->type == XML_ELEMENT_NODE) || + (cur->type == XML_XINCLUDE_START) || + (cur->type == XML_XINCLUDE_END)) { + /* + * TODO: Do we expect nsDefs on XML_XINCLUDE_START? + */ + if (XML_NSMAP_NOTEMPTY(nsMap)) { + /* + * Pop mappings. + */ + while ((nsMap->last != NULL) && + (nsMap->last->depth >= depth)) + { + XML_NSMAP_POP(nsMap, mi) + } + /* + * Unshadow. + */ + XML_NSMAP_FOREACH(nsMap, mi) { + if (mi->shadowDepth >= depth) + mi->shadowDepth = -1; + } + } + depth--; + } + if (cur->next != NULL) { + prevClone = clone; + cur = cur->next; + } else if (cur->type != XML_ATTRIBUTE_NODE) { + /* + * Set clone->last. + */ + if (clone->parent != NULL) + clone->parent->last = clone; + clone = clone->parent; + parentClone = clone->parent; + /* + * Process parent --> next; + */ + cur = cur->parent; + goto leave_node; + } else { + /* This is for attributes only. */ + clone = clone->parent; + parentClone = clone->parent; + /* + * Process parent-element --> children. + */ + cur = cur->parent; + goto into_content; + } + } + goto exit; + +internal_error: + ret = -1; + +exit: + /* + * Cleanup. + */ + if (nsMap != NULL) + xmlDOMWrapNsMapFree(nsMap); + /* + * TODO: Should we try a cleanup of the cloned node in case of a + * fatal error? + */ + *resNode = resultClone; + return (ret); +} + +/* +* xmlDOMWrapAdoptAttr: +* @ctxt: the optional context for custom processing +* @sourceDoc: the optional source document of attr +* @attr: the attribute-node to be adopted +* @destDoc: the destination doc for adoption +* @destParent: the optional new parent of @attr in @destDoc +* @options: option flags +* +* @attr is adopted by @destDoc. +* Ensures that ns-references point to @destDoc: either to +* elements->nsDef entries if @destParent is given, or to +* @destDoc->oldNs otherwise. +* +* Returns 0 if succeeded, -1 otherwise and on API/internal errors. +*/ +static int +xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlAttrPtr attr, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int options ATTRIBUTE_UNUSED) +{ + xmlNodePtr cur; + int adoptStr = 1; + + if ((attr == NULL) || (destDoc == NULL)) + return (-1); + + attr->doc = destDoc; + if (attr->ns != NULL) { + xmlNsPtr ns = NULL; + + if (ctxt != NULL) { + /* TODO: User defined. */ + } + /* XML Namespace. */ + if (IS_STR_XML(attr->ns->prefix)) { + ns = xmlTreeEnsureXMLDecl(destDoc); + } else if (destParent == NULL) { + /* + * Store in @destDoc->oldNs. + */ + ns = xmlDOMWrapStoreNs(destDoc, attr->ns->href, attr->ns->prefix); + } else { + /* + * Declare on @destParent. + */ + if (xmlSearchNsByNamespaceStrict(destDoc, destParent, attr->ns->href, + &ns, 1) == -1) + goto internal_error; + if (ns == NULL) { + ns = xmlDOMWrapNSNormDeclareNsForced(destDoc, destParent, + attr->ns->href, attr->ns->prefix, 1); + } + } + if (ns == NULL) + goto internal_error; + attr->ns = ns; + } + + XML_TREE_ADOPT_STR(attr->name); + attr->atype = 0; + attr->psvi = NULL; + /* + * Walk content. + */ + if (attr->children == NULL) + return (0); + cur = attr->children; + while (cur != NULL) { + cur->doc = destDoc; + switch (cur->type) { + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + XML_TREE_ADOPT_STR_2(cur->content) + break; + case XML_ENTITY_REF_NODE: + /* + * Remove reference to the entitity-node. + */ + cur->content = NULL; + cur->children = NULL; + cur->last = NULL; + if ((destDoc->intSubset) || (destDoc->extSubset)) { + xmlEntityPtr ent; + /* + * Assign new entity-node if available. + */ + ent = xmlGetDocEntity(destDoc, cur->name); + if (ent != NULL) { + cur->content = ent->content; + cur->children = (xmlNodePtr) ent; + cur->last = (xmlNodePtr) ent; + } + } + break; + default: + break; + } + if (cur->children != NULL) { + cur = cur->children; + continue; + } +next_sibling: + if (cur == (xmlNodePtr) attr) + break; + if (cur->next != NULL) + cur = cur->next; + else { + cur = cur->parent; + goto next_sibling; + } + } + return (0); +internal_error: + return (-1); +} + +/* +* xmlDOMWrapAdoptNode: +* @ctxt: the optional context for custom processing +* @sourceDoc: the optional sourceDoc +* @node: the node to start with +* @destDoc: the destination doc +* @destParent: the optional new parent of @node in @destDoc +* @options: option flags +* +* References of out-of scope ns-decls are remapped to point to @destDoc: +* 1) If @destParent is given, then nsDef entries on element-nodes are used +* 2) If *no* @destParent is given, then @destDoc->oldNs entries are used +* This is the case when you have an unliked node and just want to move it +* to the context of +* +* If @destParent is given, it ensures that the tree is namespace +* wellformed by creating additional ns-decls where needed. +* Note that, since prefixes of already existent ns-decls can be +* shadowed by this process, it could break QNames in attribute +* values or element content. +* WARNING: This function is in a experimental state. +* +* Returns 0 if the operation succeeded, +* 1 if a node of unsupported type was given, +* 2 if a node of not yet supported type was given and +* -1 on API/internal errors. +*/ +int +xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, + xmlDocPtr sourceDoc, + xmlNodePtr node, + xmlDocPtr destDoc, + xmlNodePtr destParent, + int options) +{ + if ((node == NULL) || (destDoc == NULL) || + ((destParent != NULL) && (destParent->doc != destDoc))) + return(-1); + /* + * Check node->doc sanity. + */ + if ((node->doc != NULL) && (sourceDoc != NULL) && + (node->doc != sourceDoc)) { + /* + * Might be an XIncluded node. + */ + return (-1); + } + if (sourceDoc == NULL) + sourceDoc = node->doc; + if (sourceDoc == destDoc) + return (-1); + switch (node->type) { + case XML_ELEMENT_NODE: + case XML_ATTRIBUTE_NODE: + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_ENTITY_REF_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + break; + case XML_DOCUMENT_FRAG_NODE: + /* TODO: Support document-fragment-nodes. */ + return (2); + default: + return (1); + } + /* + * Unlink only if @node was not already added to @destParent. + */ + if ((node->parent != NULL) && (destParent != node->parent)) + xmlUnlinkNode(node); + + if (node->type == XML_ELEMENT_NODE) { + return (xmlDOMWrapAdoptBranch(ctxt, sourceDoc, node, + destDoc, destParent, options)); + } else if (node->type == XML_ATTRIBUTE_NODE) { + return (xmlDOMWrapAdoptAttr(ctxt, sourceDoc, + (xmlAttrPtr) node, destDoc, destParent, options)); + } else { + xmlNodePtr cur = node; + int adoptStr = 1; + + cur->doc = destDoc; + /* + * Optimize string adoption. + */ + if ((sourceDoc != NULL) && + (sourceDoc->dict == destDoc->dict)) + adoptStr = 0; + switch (node->type) { + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + XML_TREE_ADOPT_STR_2(node->content) + break; + case XML_ENTITY_REF_NODE: + /* + * Remove reference to the entitity-node. + */ + node->content = NULL; + node->children = NULL; + node->last = NULL; + if ((destDoc->intSubset) || (destDoc->extSubset)) { + xmlEntityPtr ent; + /* + * Assign new entity-node if available. + */ + ent = xmlGetDocEntity(destDoc, node->name); + if (ent != NULL) { + node->content = ent->content; + node->children = (xmlNodePtr) ent; + node->last = (xmlNodePtr) ent; + } + } + XML_TREE_ADOPT_STR(node->name) + break; + case XML_PI_NODE: { + XML_TREE_ADOPT_STR(node->name) + XML_TREE_ADOPT_STR_2(node->content) + break; + } + default: + break; + } + } + return (0); +} + #define bottom_tree #include "elfgcchack.h" diff --git a/Extras/LibXML/uri.c b/Extras/LibXML/uri.c index 0349f0af8..7d60ffeab 100644 --- a/Extras/LibXML/uri.c +++ b/Extras/LibXML/uri.c @@ -185,6 +185,8 @@ * path = [ abs_path | opaque_part ] */ +#define STRNDUP(s, n) (char *) xmlStrndup((const xmlChar *)(s), (n)) + /************************************************************************ * * * Generic URI structure functions * @@ -224,8 +226,8 @@ xmlChar * xmlSaveUri(xmlURIPtr uri) { xmlChar *ret = NULL; const char *p; - intptr_t len; - intptr_t max; + int len; + int max; if (uri == NULL) return(NULL); @@ -809,7 +811,7 @@ static int is_hex(char c) { * Returns an copy of the string, but unescaped */ char * -xmlURIUnescapeString(const char *str, intptr_t len, char *target) { +xmlURIUnescapeString(const char *str, int len, char *target) { char *ret, *out; const char *in; @@ -872,7 +874,7 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) { xmlChar *ret, ch; const xmlChar *in; - size_t len, out; + unsigned int len, out; if (str == NULL) return(NULL); @@ -1076,17 +1078,22 @@ xmlURIEscape(const xmlChar * str) static int xmlParseURIFragment(xmlURIPtr uri, const char **str) { - const char *cur = *str; - + const char *cur; + if (str == NULL) return (-1); + cur = *str; + while (IS_URIC(cur) || IS_UNWISE(cur)) NEXT(cur); if (uri != NULL) { if (uri->fragment != NULL) xmlFree(uri->fragment); - uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->fragment = STRNDUP(*str, cur - *str); + else + uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL); } *str = cur; return (0); @@ -1106,17 +1113,23 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str) static int xmlParseURIQuery(xmlURIPtr uri, const char **str) { - const char *cur = *str; + const char *cur; if (str == NULL) return (-1); - while (IS_URIC(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur)))) + cur = *str; + + while ((IS_URIC(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); if (uri != NULL) { if (uri->query != NULL) xmlFree(uri->query); - uri->query = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->query = STRNDUP(*str, cur - *str); + else + uri->query = xmlURIUnescapeString(*str, cur - *str, NULL); } *str = cur; return (0); @@ -1147,8 +1160,7 @@ xmlParseURIScheme(xmlURIPtr uri, const char **str) { while (IS_SCHEME(*cur)) cur++; if (uri != NULL) { if (uri->scheme != NULL) xmlFree(uri->scheme); - /* !!! strndup */ - uri->scheme = xmlURIUnescapeString(*str, cur - *str, NULL); + uri->scheme = STRNDUP(*str, cur - *str); } *str = cur; return(0); @@ -1174,16 +1186,21 @@ xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) return (-1); cur = *str; - if (!(IS_URIC_NO_SLASH(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur))))) { + if (!((IS_URIC_NO_SLASH(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))) { return (3); } NEXT(cur); - while (IS_URIC(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur)))) + while ((IS_URIC(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); if (uri != NULL) { if (uri->opaque != NULL) xmlFree(uri->opaque); - uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->opaque = STRNDUP(*str, cur - *str); + else + uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL); } *str = cur; return (0); @@ -1235,7 +1252,10 @@ xmlParseURIServer(xmlURIPtr uri, const char **str) { if (*cur == '@') { if (uri != NULL) { if (uri->user != NULL) xmlFree(uri->user); - uri->user = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->path = STRNDUP(*str, cur - *str); + else + uri->user = xmlURIUnescapeString(*str, cur - *str, NULL); } cur++; } else { @@ -1349,7 +1369,10 @@ xmlParseURIServer(xmlURIPtr uri, const char **str) { uri->authority = NULL; if (host[0] != '[') { /* it's not an IPV6 addr */ if (uri->server != NULL) xmlFree(uri->server); - uri->server = xmlURIUnescapeString(host, cur - host, NULL); + if (uri->cleanup & 2) + uri->server = STRNDUP(host, cur - host); + else + uri->server = xmlURIUnescapeString(host, cur - host, NULL); } } /* @@ -1392,16 +1415,21 @@ xmlParseURIRelSegment(xmlURIPtr uri, const char **str) return (-1); cur = *str; - if (!(IS_SEGMENT(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur))))) { + if (!((IS_SEGMENT(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur))))) { return (3); } NEXT(cur); - while (IS_SEGMENT(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur)))) + while ((IS_SEGMENT(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); if (uri != NULL) { if (uri->path != NULL) xmlFree(uri->path); - uri->path = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->path = STRNDUP(*str, cur - *str); + else + uri->path = xmlURIUnescapeString(*str, cur - *str, NULL); } *str = cur; return (0); @@ -1432,11 +1460,13 @@ xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) cur = *str; do { - while (IS_PCHAR(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur)))) + while ((IS_PCHAR(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); while (*cur == ';') { cur++; - while (IS_PCHAR(cur) || ((uri != NULL) && (uri->cleanup) && (IS_UNWISE(cur)))) + while ((IS_PCHAR(cur)) || + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); } if (*cur != '/') @@ -1444,7 +1474,7 @@ xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) cur++; } while (1); if (uri != NULL) { - intptr_t len, len2 = 0; + int len, len2 = 0; char *path; /* @@ -1472,8 +1502,13 @@ xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) len2++; } path[len2] = 0; - if (cur - *str > 0) - xmlURIUnescapeString(*str, cur - *str, &path[len2]); + if (cur - *str > 0) { + if (uri->cleanup & 2) { + memcpy(&path[len2], *str, cur - *str); + path[len2 + (cur - *str)] = 0; + } else + xmlURIUnescapeString(*str, cur - *str, &path[len2]); + } if (uri->path != NULL) xmlFree(uri->path); uri->path = path; @@ -1538,7 +1573,10 @@ xmlParseURIAuthority(xmlURIPtr uri, const char **str) { if (uri->user != NULL) xmlFree(uri->user); uri->user = NULL; if (uri->authority != NULL) xmlFree(uri->authority); - uri->authority = xmlURIUnescapeString(*str, cur - *str, NULL); + if (uri->cleanup & 2) + uri->authority = STRNDUP(*str, cur - *str); + else + uri->authority = xmlURIUnescapeString(*str, cur - *str, NULL); } *str = cur; return(0); @@ -1761,6 +1799,38 @@ xmlParseURI(const char *str) { return(uri); } +/** + * xmlParseURIRaw: + * @str: the URI string to analyze + * @raw: if 1 unescaping of URI pieces are disabled + * + * Parse an URI but allows to keep intact the original fragments. + * + * URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ] + * + * Returns a newly built xmlURIPtr or NULL in case of error + */ +xmlURIPtr +xmlParseURIRaw(const char *str, int raw) { + xmlURIPtr uri; + int ret; + + if (str == NULL) + return(NULL); + uri = xmlCreateURI(); + if (uri != NULL) { + if (raw) { + uri->cleanup |= 2; + } + ret = xmlParseURIReference(uri, str); + if (ret) { + xmlFreeURI(uri); + return(NULL); + } + } + return(uri); +} + /************************************************************************ * * * Public functions * @@ -1785,7 +1855,7 @@ xmlParseURI(const char *str) { xmlChar * xmlBuildURI(const xmlChar *URI, const xmlChar *base) { xmlChar *val = NULL; - intptr_t ret, len, indx, cur, out; + int ret, len, indx, cur, out; xmlURIPtr ref = NULL; xmlURIPtr bas = NULL; xmlURIPtr res = NULL; @@ -2061,23 +2131,17 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) { xmlChar *val = NULL; int ret; - intptr_t ix; - intptr_t pos = 0; - intptr_t nbslash = 0; + int ix; + int pos = 0; + int nbslash = 0; + int len; xmlURIPtr ref = NULL; xmlURIPtr bas = NULL; xmlChar *bptr, *uptr, *vptr; + int remove_path = 0; if ((URI == NULL) || (*URI == 0)) return NULL; - /* - * Special case - if URI starts with '.', we assume it's already - * in relative form, so nothing to do. - */ - if (*URI == '.') { - val = xmlStrdup (URI); - goto done; - } /* * First parse URI into a standard form @@ -2085,9 +2149,13 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) ref = xmlCreateURI (); if (ref == NULL) return NULL; - ret = xmlParseURIReference (ref, (const char *) URI); - if (ret != 0) - goto done; /* Error in URI, return NULL */ + /* If URI not already in "relative" form */ + if (URI[0] != '.') { + ret = xmlParseURIReference (ref, (const char *) URI); + if (ret != 0) + goto done; /* Error in URI, return NULL */ + } else + ref->path = (char *)xmlStrdup(URI); /* * Next parse base into the same standard form @@ -2099,72 +2167,113 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) bas = xmlCreateURI (); if (bas == NULL) goto done; - ret = xmlParseURIReference (bas, (const char *) base); - if (ret != 0) - goto done; /* Error in base, return NULL */ + if (base[0] != '.') { + ret = xmlParseURIReference (bas, (const char *) base); + if (ret != 0) + goto done; /* Error in base, return NULL */ + } else + bas->path = (char *)xmlStrdup(base); /* * If the scheme / server on the URI differs from the base, * just return the URI */ if ((ref->scheme != NULL) && - ((bas->scheme == NULL) || - xmlStrcmp ((xmlChar *)bas->scheme, (xmlChar *)ref->scheme) || - xmlStrcmp ((xmlChar *)bas->server, (xmlChar *)ref->server))) { + ((bas->scheme == NULL) || + (xmlStrcmp ((xmlChar *)bas->scheme, (xmlChar *)ref->scheme)) || + (xmlStrcmp ((xmlChar *)bas->server, (xmlChar *)ref->server)))) { val = xmlStrdup (URI); goto done; } + if (xmlStrEqual((xmlChar *)bas->path, (xmlChar *)ref->path)) { + val = xmlStrdup(BAD_CAST ""); + goto done; + } + if (bas->path == NULL) { + val = xmlStrdup((xmlChar *)ref->path); + goto done; + } + if (ref->path == NULL) { + ref->path = (char *) "/"; + remove_path = 1; + } /* * At this point (at last!) we can compare the two paths * - * First we compare the two strings and find where they first differ + * First we take care of the special case where either of the + * two path components may be missing (bug 316224) */ + if (bas->path == NULL) { + if (ref->path != NULL) { + uptr = (xmlChar *) ref->path; + if (*uptr == '/') + uptr++; + val = xmlStrdup(uptr); + } + goto done; + } bptr = (xmlChar *)bas->path; - if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/')) - pos += 2; - if ((*bptr == '.') && (bptr[1] == '/')) - bptr += 2; - else if ((*bptr == '/') && (ref->path[pos] != '/')) - bptr++; - while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) - pos++; - - if (bptr[pos] == ref->path[pos]) { - val = NULL; /* if no differences, return NULL */ - goto done; /* (I can't imagine why anyone would do this) */ - } - - /* - * In URI, "back up" to the last '/' encountered. This will be the - * beginning of the "unique" suffix of URI - */ - ix = pos; - if ((ref->path[ix] == '/') && (ix > 0)) - ix--; - for (; ix > 0; ix--) { - if (ref->path[ix] == '/') - break; - } - if (ix == 0) { - uptr = (xmlChar *)ref->path; - } else { - ix++; - uptr = (xmlChar *)&ref->path[ix]; - } - - /* - * In base, count the number of '/' from the differing point - */ - if (bptr[pos] != ref->path[pos]) { /* check for trivial URI == base */ - for (; bptr[ix] != 0; ix++) { + if (ref->path == NULL) { + for (ix = 0; bptr[ix] != 0; ix++) { if (bptr[ix] == '/') nbslash++; } - } + uptr = NULL; + len = 1; /* this is for a string terminator only */ + } else { + /* + * Next we compare the two strings and find where they first differ + */ + if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/')) + pos += 2; + if ((*bptr == '.') && (bptr[1] == '/')) + bptr += 2; + else if ((*bptr == '/') && (ref->path[pos] != '/')) + bptr++; + while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) + pos++; + if (bptr[pos] == ref->path[pos]) { + val = xmlStrdup(BAD_CAST ""); + goto done; /* (I can't imagine why anyone would do this) */ + } + + /* + * In URI, "back up" to the last '/' encountered. This will be the + * beginning of the "unique" suffix of URI + */ + ix = pos; + if ((ref->path[ix] == '/') && (ix > 0)) + ix--; + else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/')) + ix -= 2; + for (; ix > 0; ix--) { + if (ref->path[ix] == '/') + break; + } + if (ix == 0) { + uptr = (xmlChar *)ref->path; + } else { + ix++; + uptr = (xmlChar *)&ref->path[ix]; + } + + /* + * In base, count the number of '/' from the differing point + */ + if (bptr[pos] != ref->path[pos]) {/* check for trivial URI == base */ + for (; bptr[ix] != 0; ix++) { + if (bptr[ix] == '/') + nbslash++; + } + } + len = xmlStrlen (uptr) + 1; + } + if (nbslash == 0) { - val = xmlStrdup (uptr); + if (uptr != NULL) + val = xmlStrdup (uptr); goto done; } @@ -2173,8 +2282,7 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) * length of the remainder of the URI, plus enough space * for the "../" groups, plus one for the terminator */ - ix = xmlStrlen (uptr) + 1; - val = (xmlChar *) xmlMalloc (ix + 3 * nbslash); + val = (xmlChar *) xmlMalloc (len + 3 * nbslash); if (val == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlBuildRelativeURI: out of memory\n"); @@ -2192,12 +2300,25 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) /* * Finish up with the end of the URI */ - memcpy (vptr, uptr, ix); + if (uptr != NULL) { + if ((vptr > val) && (len > 0) && + (uptr[0] == '/') && (vptr[-1] == '/')) { + memcpy (vptr, uptr + 1, len - 1); + vptr[len - 2] = 0; + } else { + memcpy (vptr, uptr, len); + vptr[len - 1] = 0; + } + } else { + vptr[len - 1] = 0; + } - done: +done: /* * Free the working variables */ + if (remove_path != 0) + ref->path = NULL; if (ref != NULL) xmlFreeURI (ref); if (bas != NULL) @@ -2226,12 +2347,13 @@ xmlChar* xmlCanonicPath(const xmlChar *path) { #if defined(_WIN32) && !defined(__CYGWIN__) - intptr_t len = 0; + int len = 0; int i = 0; xmlChar *p = NULL; #endif - xmlChar *ret; xmlURIPtr uri; + xmlChar *ret; + const xmlChar *absuri; if (path == NULL) return(NULL); @@ -2240,12 +2362,47 @@ xmlCanonicPath(const xmlChar *path) return xmlStrdup(path); } + absuri = xmlStrstr(path, BAD_CAST "://"); + if (absuri != NULL) { + int l, j; + unsigned char c; + xmlChar *escURI; + + /* + * this looks like an URI where some parts have not been + * escaped leading to a parsing problem check that the first + * part matches a protocol. + */ + l = absuri - path; + if ((l <= 0) || (l > 20)) + goto path_processing; + for (j = 0;j < l;j++) { + c = path[j]; + if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')))) + goto path_processing; + } + + escURI = xmlURIEscapeStr(path, BAD_CAST ":/?_.#&;="); + if (escURI != NULL) { + uri = xmlParseURI((const char *) escURI); + if (uri != NULL) { + xmlFreeURI(uri); + return escURI; + } + xmlFreeURI(uri); + } + } + +path_processing: +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * This really need to be cleaned up by someone with a Windows box + */ uri = xmlCreateURI(); if (uri == NULL) { return(NULL); } -#if defined(_WIN32) && !defined(__CYGWIN__) len = xmlStrlen(path); if ((len > 2) && IS_WINDOWS_PATH(path)) { uri->scheme = xmlStrdup(BAD_CAST "file"); @@ -2262,15 +2419,21 @@ xmlCanonicPath(const xmlChar *path) *p = '/'; p++; } -#else - uri->path = (char *) xmlStrdup((const xmlChar *) path); -#endif if (uri->path == NULL) { xmlFreeURI(uri); return(NULL); } - ret = xmlSaveUri(uri); + + if (uri->scheme == NULL) { + ret = xmlStrdup((const xmlChar *) path); + } else { + ret = xmlSaveUri(uri); + } + xmlFreeURI(uri); +#else + ret = xmlStrdup((const xmlChar *) path); +#endif return(ret); } diff --git a/Extras/LibXML/valid.c b/Extras/LibXML/valid.c index 2907b49bc..edf542612 100644 --- a/Extras/LibXML/valid.c +++ b/Extras/LibXML/valid.c @@ -453,14 +453,14 @@ nodeVPop(xmlValidCtxtPtr ctxt) xmlNodePtr ret; if (ctxt->nodeNr <= 0) - return (0); + return (NULL); ctxt->nodeNr--; if (ctxt->nodeNr > 0) ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1]; else ctxt->node = NULL; ret = ctxt->nodeTab[ctxt->nodeNr]; - ctxt->nodeTab[ctxt->nodeNr] = 0; + ctxt->nodeTab[ctxt->nodeNr] = NULL; return (ret); } @@ -1212,14 +1212,14 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) * xmlSprintfElementContent: * @buf: an output buffer * @content: An element table - * @glob: 1 if one must print the englobing parenthesis, 0 otherwise + * @englob: 1 if one must print the englobing parenthesis, 0 otherwise * * Deprecated, unsafe, use xmlSnprintfElementContent */ void xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED, xmlElementContentPtr content ATTRIBUTE_UNUSED, - int glob ATTRIBUTE_UNUSED) { + int englob ATTRIBUTE_UNUSED) { } #endif /* LIBXML_OUTPUT_ENABLED */ @@ -1228,14 +1228,14 @@ xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED, * @buf: an output buffer * @size: the buffer size * @content: An element table - * @glob: 1 if one must print the englobing parenthesis, 0 otherwise + * @englob: 1 if one must print the englobing parenthesis, 0 otherwise * * This will dump the content of the element content definition * Intended just for the debug routine */ void -xmlSnprintfElementContent(char *buf, size_t size, xmlElementContentPtr content, int glob) { - size_t len; +xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int englob) { + int len; if (content == NULL) return; len = strlen(buf); @@ -1244,21 +1244,21 @@ xmlSnprintfElementContent(char *buf, size_t size, xmlElementContentPtr content, strcat(buf, " ..."); return; } - if (glob) strcat(buf, "("); + if (englob) strcat(buf, "("); switch (content->type) { case XML_ELEMENT_CONTENT_PCDATA: strcat(buf, "#PCDATA"); break; case XML_ELEMENT_CONTENT_ELEMENT: if (content->prefix != NULL) { - if ((intptr_t)(size - len) < xmlStrlen(content->prefix) + 10) { + if (size - len < xmlStrlen(content->prefix) + 10) { strcat(buf, " ..."); return; } strcat(buf, (char *) content->prefix); strcat(buf, ":"); } - if ((intptr_t)(size - len) < xmlStrlen(content->name) + 10) { + if (size - len < xmlStrlen(content->name) + 10) { strcat(buf, " ..."); return; } @@ -1306,7 +1306,7 @@ xmlSnprintfElementContent(char *buf, size_t size, xmlElementContentPtr content, xmlSnprintfElementContent(buf, size, content->c2, 0); break; } - if (glob) + if (englob) strcat(buf, ")"); switch (content->ocur) { case XML_ELEMENT_CONTENT_ONCE: @@ -1485,6 +1485,10 @@ xmlAddElementDecl(xmlValidCtxtPtr ctxt, xmlFree(ns); return(NULL); } + if (ns != NULL) { + xmlFree(ns); + ns = NULL; + } } else { ret = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); if (ret == NULL) { @@ -1864,6 +1868,7 @@ xmlScanAttributeDecl(xmlDtdPtr dtd, const xmlChar *elem) { * xmlScanIDAttributeDecl: * @ctxt: the validation context * @elem: the element name + * @err: whether to raise errors here * * Verify that the element don't have too many ID attributes * declared. @@ -1871,7 +1876,7 @@ xmlScanAttributeDecl(xmlDtdPtr dtd, const xmlChar *elem) { * Returns the number of ID attributes found. */ static int -xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { +xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem, int err) { xmlAttributePtr cur; int ret = 0; @@ -1880,7 +1885,7 @@ xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { while (cur != NULL) { if (cur->atype == XML_ATTRIBUTE_ID) { ret ++; - if (ret > 1) + if ((ret > 1) && (err)) xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID, "Element %s has too many ID attributes defined : %s\n", elem->name, cur->name, NULL); @@ -2058,6 +2063,12 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, * fill the structure. */ ret->atype = type; + /* + * doc must be set before possible error causes call + * to xmlFreeAttribute (because it's used to check on + * dict use) + */ + ret->doc = dtd->doc; if (dict) { ret->name = xmlDictLookup(dict, name, -1); ret->prefix = xmlDictLookup(dict, ns, -1); @@ -2102,7 +2113,7 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, #ifdef LIBXML_VALID_ENABLED if ((type == XML_ATTRIBUTE_ID) && - (xmlScanIDAttributeDecl(NULL, elemDef) != 0)) { + (xmlScanIDAttributeDecl(NULL, elemDef, 1) != 0)) { xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_MULTIPLE_ID, "Element %s has too may ID attributes defined : %s\n", elem, name, NULL); @@ -2145,7 +2156,6 @@ xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, * Link it to the DTD */ ret->parent = dtd; - ret->doc = dtd->doc; if (dtd->last == NULL) { dtd->children = dtd->last = (xmlNodePtr) ret; } else { @@ -2693,42 +2703,49 @@ xmlFreeIDTable(xmlIDTablePtr table) { */ int xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { + if ((attr == NULL) || (attr->name == NULL)) return(0); + if ((attr->ns != NULL) && (attr->ns->prefix != NULL) && + (!strcmp((char *) attr->name, "id")) && + (!strcmp((char *) attr->ns->prefix, "xml"))) + return(1); if (doc == NULL) return(0); - if (attr == NULL) return(0); 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))) && - ((elem != NULL) && (!xmlStrEqual(elem->name, BAD_CAST "input")))) + 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 if (elem == NULL) { + return(0); } else { - xmlAttributePtr attrDecl; + xmlAttributePtr attrDecl = NULL; - if (elem == NULL) return(0); - if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { - xmlChar fn[50]; - xmlChar *fullname; - - fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); - if (fullname == NULL) - return(0); - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, - attr->name); + xmlChar felem[50], fattr[50]; + xmlChar *fullelemname, *fullattrname; + + fullelemname = (elem->ns != NULL && elem->ns->prefix != NULL) ? + xmlBuildQName(elem->name, elem->ns->prefix, felem, 50) : + (xmlChar *)elem->name; + + fullattrname = (attr->ns != NULL && attr->ns->prefix != NULL) ? + xmlBuildQName(attr->name, attr->ns->prefix, fattr, 50) : + (xmlChar *)attr->name; + + if (fullelemname != NULL && fullattrname != NULL) { + attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullelemname, + fullattrname); if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, - attr->name); - if ((fullname != fn) && (fullname != elem->name)) - xmlFree(fullname); - } else { - attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, - attr->name); - if ((attrDecl == NULL) && (doc->extSubset != NULL)) - attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, - attr->name); + attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullelemname, + fullattrname); } + if ((fullattrname != fattr) && (fullattrname != attr->name)) + xmlFree(fullattrname); + if ((fullelemname != felem) && (fullelemname != elem->name)) + xmlFree(fullelemname); + if ((attrDecl != NULL) && (attrDecl->atype == XML_ATTRIBUTE_ID)) return(1); } @@ -2768,6 +2785,7 @@ xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr) { } xmlHashRemoveEntry(table, ID, (xmlHashDeallocator) xmlFreeID); xmlFree(ID); + attr->atype = 0; return(0); } @@ -3855,7 +3873,7 @@ xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc, fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); if (fullname == NULL) - return(0); + return(NULL); attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name); if ((attrDecl == NULL) && (doc->extSubset != NULL)) { attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name); @@ -3940,7 +3958,7 @@ xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem, fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50); if (fullname == NULL) - return(0); + return(NULL); attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name); if ((attrDecl == NULL) && (doc->extSubset != NULL)) attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name); @@ -4037,7 +4055,7 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlElementPtr elem = xmlGetDtdElementDesc(doc->intSubset, attr->elem); if (elem != NULL) { - nbId = xmlScanIDAttributeDecl(NULL, elem); + nbId = xmlScanIDAttributeDecl(NULL, elem, 0); } else { xmlAttributeTablePtr table; @@ -4046,9 +4064,11 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, * element in the external subset. */ nbId = 0; - table = (xmlAttributeTablePtr) doc->intSubset->attributes; - xmlHashScan3(table, NULL, NULL, attr->elem, (xmlHashScanner) - xmlValidateAttributeIdCallback, &nbId); + if (doc->intSubset != NULL) { + table = (xmlAttributeTablePtr) doc->intSubset->attributes; + xmlHashScan3(table, NULL, NULL, attr->elem, (xmlHashScanner) + xmlValidateAttributeIdCallback, &nbId); + } } if (nbId > 1) { @@ -4059,7 +4079,7 @@ xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, int extId = 0; elem = xmlGetDtdElementDesc(doc->extSubset, attr->elem); if (elem != NULL) { - extId = xmlScanIDAttributeDecl(NULL, elem); + extId = xmlScanIDAttributeDecl(NULL, elem, 0); } if (extId > 1) { xmlErrValidNodeNr(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET, @@ -5846,24 +5866,12 @@ xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, NULL,NULL,NULL); return(0); } - if (elem->properties != NULL) { - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Text element has attribute !\n", - NULL,NULL,NULL); - return(0); - } if (elem->ns != NULL) { xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, "Text element has namespace !\n", NULL,NULL,NULL); return(0); } - if (elem->nsDef != NULL) { - xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, - "Text element has namespace !\n", - NULL,NULL,NULL); - return(0); - } if (elem->content == NULL) { xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR, "Text element has no content !\n", @@ -6288,23 +6296,25 @@ xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem) { } ret &= xmlValidateOneElement(ctxt, doc, elem); - attr = elem->properties; - while (attr != NULL) { - value = xmlNodeListGetString(doc, attr->children, 0); - ret &= xmlValidateOneAttribute(ctxt, doc, elem, attr, value); - if (value != NULL) - xmlFree((char *)value); - attr= attr->next; - } - ns = elem->nsDef; - while (ns != NULL) { - if (elem->ns == NULL) - ret &= xmlValidateOneNamespace(ctxt, doc, elem, NULL, - ns, ns->href); - else - ret &= xmlValidateOneNamespace(ctxt, doc, elem, elem->ns->prefix, - ns, ns->href); - ns = ns->next; + if (elem->type == XML_ELEMENT_NODE) { + attr = elem->properties; + while (attr != NULL) { + value = xmlNodeListGetString(doc, attr->children, 0); + ret &= xmlValidateOneAttribute(ctxt, doc, elem, attr, value); + if (value != NULL) + xmlFree((char *)value); + attr= attr->next; + } + ns = elem->nsDef; + while (ns != NULL) { + if (elem->ns == NULL) + ret &= xmlValidateOneNamespace(ctxt, doc, elem, NULL, + ns, ns->href); + else + ret &= xmlValidateOneNamespace(ctxt, doc, elem, + elem->ns->prefix, ns, ns->href); + ns = ns->next; + } } child = elem->children; while (child != NULL) { @@ -6752,7 +6762,7 @@ xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { /** * xmlValidGetPotentialChildren: * @ctree: an element content tree - * @list: an array to store the list of child names + * @names: an array to store the list of child names * @len: a pointer to the number of element in the list * @max: the size of the array * @@ -6762,32 +6772,33 @@ xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { */ int -xmlValidGetPotentialChildren(xmlElementContent *ctree, const xmlChar **list, +xmlValidGetPotentialChildren(xmlElementContent *ctree, + const xmlChar **names, int *len, int max) { int i; - if ((ctree == NULL) || (list == NULL) || (len == NULL)) + if ((ctree == NULL) || (names == NULL) || (len == NULL)) return(-1); if (*len >= max) return(*len); switch (ctree->type) { case XML_ELEMENT_CONTENT_PCDATA: for (i = 0; i < *len;i++) - if (xmlStrEqual(BAD_CAST "#PCDATA", list[i])) return(*len); - list[(*len)++] = BAD_CAST "#PCDATA"; + if (xmlStrEqual(BAD_CAST "#PCDATA", names[i])) return(*len); + names[(*len)++] = BAD_CAST "#PCDATA"; break; case XML_ELEMENT_CONTENT_ELEMENT: for (i = 0; i < *len;i++) - if (xmlStrEqual(ctree->name, list[i])) return(*len); - list[(*len)++] = ctree->name; + if (xmlStrEqual(ctree->name, names[i])) return(*len); + names[(*len)++] = ctree->name; break; case XML_ELEMENT_CONTENT_SEQ: - xmlValidGetPotentialChildren(ctree->c1, list, len, max); - xmlValidGetPotentialChildren(ctree->c2, list, len, max); + xmlValidGetPotentialChildren(ctree->c1, names, len, max); + xmlValidGetPotentialChildren(ctree->c2, names, len, max); break; case XML_ELEMENT_CONTENT_OR: - xmlValidGetPotentialChildren(ctree->c1, list, len, max); - xmlValidGetPotentialChildren(ctree->c2, list, len, max); + xmlValidGetPotentialChildren(ctree->c1, names, len, max); + xmlValidGetPotentialChildren(ctree->c2, names, len, max); break; } @@ -6797,7 +6808,7 @@ xmlValidGetPotentialChildren(xmlElementContent *ctree, const xmlChar **list, /* * Dummy function to suppress messages while we try out valid elements */ -static void xmlNoValidityErr(void *ctx ATTRIBUTE_UNUSED, +static void XMLCDECL xmlNoValidityErr(void *ctx ATTRIBUTE_UNUSED, const char *msg ATTRIBUTE_UNUSED, ...) { return; } diff --git a/Extras/LibXML/xinclude.c b/Extras/LibXML/xinclude.c index 2b2c3539e..d5bba6eb2 100644 --- a/Extras/LibXML/xinclude.c +++ b/Extras/LibXML/xinclude.c @@ -237,7 +237,7 @@ xmlXIncludeNewRef(xmlXIncludeCtxtPtr ctxt, const xmlChar *URI, ret->URI = xmlStrdup(URI); ret->fragment = NULL; ret->ref = ref; - ret->doc = 0; + ret->doc = NULL; ret->count = 0; ret->xml = 0; ret->inc = NULL; @@ -360,7 +360,7 @@ xmlXIncludeURLPop(xmlXIncludeCtxtPtr ctxt) else ctxt->url = NULL; ret = ctxt->urlTab[ctxt->urlNr]; - ctxt->urlTab[ctxt->urlNr] = 0; + ctxt->urlTab[ctxt->urlNr] = NULL; if (ret != NULL) xmlFree(ret); } @@ -388,9 +388,11 @@ xmlXIncludeFreeContext(xmlXIncludeCtxtPtr ctxt) { if (ctxt->incTab[i] != NULL) xmlXIncludeFreeRef(ctxt->incTab[i]); } - for (i = 0;i < ctxt->txtNr;i++) { - if (ctxt->txturlTab[i] != NULL) - xmlFree(ctxt->txturlTab[i]); + if (ctxt->txturlTab != NULL) { + for (i = 0;i < ctxt->txtNr;i++) { + if (ctxt->txturlTab[i] != NULL) + xmlFree(ctxt->txturlTab[i]); + } } if (ctxt->incTab != NULL) xmlFree(ctxt->incTab); @@ -609,7 +611,7 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) { /* * Check the URL against the stack for recursions */ - if (!local) { + if ((!local) && (xml == 1)) { for (i = 0;i < ctxt->urlNr;i++) { if (xmlStrEqual(URL, ctxt->urlTab[i])) { xmlXIncludeErr(ctxt, cur, XML_XINCLUDE_RECURSION, @@ -1401,9 +1403,14 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { URL = xmlSaveUri(uri); xmlFreeURI(uri); if (URL == NULL) { - xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, - XML_XINCLUDE_HREF_URI, - "invalid value URI %s\n", url); + if (ctxt->incTab != NULL) + xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, + XML_XINCLUDE_HREF_URI, + "invalid value URI %s\n", url); + else + xmlXIncludeErr(ctxt, NULL, + XML_XINCLUDE_HREF_URI, + "invalid value URI %s\n", url); if (fragment != NULL) xmlFree(fragment); return(-1); @@ -1663,32 +1670,81 @@ loaded: */ if ((doc != NULL) && (URL != NULL) && (xmlStrchr(URL, (xmlChar) '/'))) { xmlNodePtr node; - xmlChar *relURI; + xmlChar *base; xmlChar *curBase; /* - * The base is only adjusted if necessary for the existing base + * The base is only adjusted if "necessary", i.e. if the xinclude node + * has a base specified, or the URL is relative */ - relURI = xmlBuildRelativeURI(URL, ctxt->base); - if (relURI == NULL) { /* Error return */ - xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, + base = xmlGetNsProp(ctxt->incTab[nr]->ref, BAD_CAST "base", + XML_XML_NAMESPACE); + if (base == NULL) { + /* + * No xml:base on the xinclude node, so we check whether the + * URI base is different than (relative to) the context base + */ + curBase = xmlBuildRelativeURI(URL, ctxt->base); + if (curBase == NULL) { /* Error return */ + xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, XML_XINCLUDE_HREF_URI, "trying to build relative URI from %s\n", URL); - } else { - if (xmlStrchr(relURI, (xmlChar) '/')) { - node = ctxt->incTab[nr]->inc; - while (node != NULL) { - if (node->type == XML_ELEMENT_NODE) { - curBase = xmlNodeGetBase(node->doc, node); - if ((curBase == NULL) || xmlStrEqual(curBase, node->doc->URL)) - xmlNodeSetBase(node, relURI); - if (curBase != NULL) - xmlFree(curBase); - } - node = node->next; - } + } else { + /* If the URI doesn't contain a slash, it's not relative */ + if (!xmlStrchr(curBase, (xmlChar) '/')) + xmlFree(curBase); + else + base = curBase; } - xmlFree(relURI); + } + if (base != NULL) { /* Adjustment may be needed */ + node = ctxt->incTab[nr]->inc; + while (node != NULL) { + /* Only work on element nodes */ + if (node->type == XML_ELEMENT_NODE) { + curBase = xmlNodeGetBase(node->doc, node); + /* If no current base, set it */ + if (curBase == NULL) { + xmlNodeSetBase(node, base); + } else { + /* + * If the current base is the same as the + * URL of the document, then reset it to be + * the specified xml:base or the relative URI + */ + if (xmlStrEqual(curBase, node->doc->URL)) { + xmlNodeSetBase(node, base); + } else { + /* + * If the element already has an xml:base + * set, then relativise it if necessary + */ + xmlChar *xmlBase; + xmlBase = xmlGetNsProp(node, + BAD_CAST "base", + XML_XML_NAMESPACE); + if (xmlBase != NULL) { + xmlChar *relBase; + relBase = xmlBuildURI(xmlBase, base); + if (relBase == NULL) { /* error */ + xmlXIncludeErr(ctxt, + ctxt->incTab[nr]->ref, + XML_XINCLUDE_HREF_URI, + "trying to rebuild base from %s\n", + xmlBase); + } else { + xmlNodeSetBase(node, relBase); + xmlFree(relBase); + } + xmlFree(xmlBase); + } + } + xmlFree(curBase); + } + } + node = node->next; + } + xmlFree(base); } } if ((nr < ctxt->incNr) && (ctxt->incTab[nr]->doc != NULL) && @@ -1719,7 +1775,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { xmlNodePtr node; xmlURIPtr uri; xmlChar *URL; - size_t i; + int i; xmlChar *encoding = NULL; xmlCharEncoding enc = (xmlCharEncoding) 0; @@ -1807,7 +1863,7 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { * Scan all chars from the resource and add the to the node */ while (xmlParserInputBufferRead(buf, 128) > 0) { - size_t len; + int len; const xmlChar *content; content = xmlBufferContent(buf->buffer); @@ -1903,7 +1959,7 @@ xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) { static xmlNodePtr xmlXIncludePreProcessNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) { xmlXIncludeAddNode(ctxt, node); - return(0); + return(NULL); } /** @@ -2254,7 +2310,7 @@ static int xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) { xmlNodePtr cur; int ret = 0; - int i; + int i, start; if ((doc == NULL) || (tree == NULL)) return(-1); @@ -2266,6 +2322,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) { if (ret < 0) return(-1); } + start = ctxt->incNr; /* * First phase: lookup the elements in the document @@ -2306,7 +2363,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) { /* * Second Phase : collect the infosets fragments */ - for (i = ctxt->incBase;i < ctxt->incNr; i++) { + for (i = start;i < ctxt->incNr; i++) { xmlXIncludeLoadNode(ctxt, i); ret++; } diff --git a/Extras/LibXML/xmlIO.c b/Extras/LibXML/xmlIO.c index 9bbedf24c..60e0a50ae 100644 --- a/Extras/LibXML/xmlIO.c +++ b/Extras/LibXML/xmlIO.c @@ -36,6 +36,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + /* Figure a portable way to know if a file is a directory. */ #ifndef HAVE_STAT # ifdef HAVE__STAT @@ -189,6 +193,39 @@ static const char *IOerr[] = { "unknown address familly", /* EAFNOSUPPORT */ }; +#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) +/** + * __xmlIOWin32UTF8ToWChar: + * @u8String: uft-8 string + * + * Convert a string from utf-8 to wchar (WINDOWS ONLY!) + */ +static wchar_t * +__xmlIOWin32UTF8ToWChar(const char *u8String) +{ + wchar_t *wString = NULL; + + if (u8String) + { + int wLen = MultiByteToWideChar(CP_UTF8,0,u8String,-1,NULL,0); + if (wLen) + { + wString = malloc((wLen+1) * sizeof(wchar_t)); + if (wString) + { + if (MultiByteToWideChar(CP_UTF8,0,u8String,-1,wString,wLen+1) == 0) + { + free(wString); + wString = NULL; + } + } + } + } + + return wString; +} +#endif + /** * xmlIOErrMemory: * @extra: extra informations @@ -553,22 +590,44 @@ int xmlCheckFilename (const char *path) { #ifdef HAVE_STAT - struct stat stat_buffer; - - if (path == NULL) - return(0); + struct stat stat_buffer; +#endif + if (path == NULL) + return(0); + +#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) + { + int retval = 0; + + wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path); + if (wPath) + { + struct _stat stat_buffer; + + if (_wstat(wPath,&stat_buffer) == 0) + { + retval = 1; + + if (((stat_buffer.st_mode & S_IFDIR) == S_IFDIR)) + retval = 2; + } + + free(wPath); + } + return retval; + } +#else +#ifdef HAVE_STAT if (stat(path, &stat_buffer) == -1) return 0; #ifdef S_ISDIR - if (S_ISDIR(stat_buffer.st_mode)) { + if (S_ISDIR(stat_buffer.st_mode)) return 2; - } -#endif -#endif - if (path == NULL) - return(0); +#endif /* S_ISDIR */ +#endif /* HAVE_STAT */ +#endif /* WIN32 */ return 1; } @@ -588,11 +647,11 @@ xmlNop(void) { * * Returns the number of bytes written */ -static intptr_t -xmlFdRead (void * context, char * buffer, size_t len) { - intptr_t ret; +static int +xmlFdRead (void * context, char * buffer, int len) { + int ret; - ret = read((int) (size_t) context, &buffer[0], (unsigned int) len); + ret = read((int) (long) context, &buffer[0], len); if (ret < 0) xmlIOErr(0, "read()"); return(ret); } @@ -608,12 +667,14 @@ xmlFdRead (void * context, char * buffer, size_t len) { * * Returns the number of bytes written */ -static intptr_t -xmlFdWrite (void * context, const char * buffer, size_t len) { - intptr_t ret; +static int +xmlFdWrite (void * context, const char * buffer, int len) { + int ret = 0; - ret = write((int) (size_t) context, &buffer[0], (unsigned int) len); - if (ret < 0) xmlIOErr(0, "write()"); + if (len > 0) { + ret = write((int) (long) context, &buffer[0], len); + if (ret < 0) xmlIOErr(0, "write()"); + } return(ret); } #endif /* LIBXML_OUTPUT_ENABLED */ @@ -629,7 +690,7 @@ xmlFdWrite (void * context, const char * buffer, size_t len) { static int xmlFdClose (void * context) { int ret; - ret = close((int) (size_t) context); + ret = close((int) (long) context); if (ret < 0) xmlIOErr(0, "close()"); return(ret); } @@ -690,7 +751,18 @@ xmlFileOpen_real (const char *filename) { return(NULL); #if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) - fd = fopen(path, "rb"); + { + wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path); + if (wPath) + { + fd = _wfopen(wPath, L"rb"); + free(wPath); + } + else + { + fd = fopen(path, "rb"); + } + } #else fd = fopen(path, "r"); #endif /* WIN32 */ @@ -760,8 +832,24 @@ xmlFileOpenW (const char *filename) { if (path == NULL) return(NULL); - fd = fopen(path, "wb"); - if (fd == NULL) xmlIOErr(0, path); +#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) + { + wchar_t *wPath = __xmlIOWin32UTF8ToWChar(path); + if (wPath) + { + fd = _wfopen(wPath, L"wb"); + free(wPath); + } + else + { + fd = fopen(path, "wb"); + } + } +#else + fd = fopen(path, "wb"); +#endif /* WIN32 */ + + if (fd == NULL) xmlIOErr(0, path); return((void *) fd); } #endif /* LIBXML_OUTPUT_ENABLED */ @@ -776,9 +864,9 @@ xmlFileOpenW (const char *filename) { * * Returns the number of bytes written or < 0 in case of failure */ -intptr_t -xmlFileRead (void * context, char * buffer, size_t len) { - intptr_t ret; +int +xmlFileRead (void * context, char * buffer, int len) { + int ret; if ((context == NULL) || (buffer == NULL)) return(-1); ret = fread(&buffer[0], 1, len, (FILE *) context); @@ -797,9 +885,9 @@ xmlFileRead (void * context, char * buffer, size_t len) { * * Returns the number of bytes written */ -static intptr_t -xmlFileWrite (void * context, const char * buffer, size_t len) { - size_t items; +static int +xmlFileWrite (void * context, const char * buffer, int len) { + int items; if ((context == NULL) || (buffer == NULL)) return(-1); @@ -860,6 +948,28 @@ xmlFileFlush (void * context) { return(ret); } +#ifdef LIBXML_OUTPUT_ENABLED +/** + * xmlBufferWrite: + * @context: the xmlBuffer + * @buffer: the data to write + * @len: number of bytes to write + * + * Write @len bytes from @buffer to the xml buffer + * + * Returns the number of bytes written + */ +static int +xmlBufferWrite (void * context, const char * buffer, int len) { + int ret; + + ret = xmlBufferAdd((xmlBufferPtr) context, (const xmlChar *) buffer, len); + if (ret != 0) + return(-1); + return(len); +} +#endif + #ifdef HAVE_ZLIB_H /************************************************************************ * * @@ -1206,7 +1316,7 @@ xmlCreateZMemBuff( int compression ) { } /* Set the header data. The CRC will be needed for the trailer */ - buff->crc = crc32( 0L, Z_NULL, 0 ); + buff->crc = crc32( 0L, NULL, 0 ); hdr_lgth = snprintf( (char *)buff->zbuff, buff->size, "%c%c%c%c%c%c%c%c%c%c", GZ_MAGIC1, GZ_MAGIC2, Z_DEFLATED, @@ -2114,11 +2224,11 @@ xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { * * Returns the number of byte written or -1 in case of error. */ -intptr_t +int xmlOutputBufferClose(xmlOutputBufferPtr out) { - intptr_t written; - intptr_t err_rc = 0; + int written; + int err_rc = 0; if (out == NULL) return (-1); @@ -2250,9 +2360,9 @@ __xmlOutputBufferCreateFilename(const char *URI, puri = xmlParseURI(URI); if (puri != NULL) { +#ifdef HAVE_ZLIB_H if ((puri->scheme != NULL) && (!xmlStrEqual(BAD_CAST puri->scheme, BAD_CAST "file"))) -#ifdef HAVE_ZLIB_H is_file_uri = 0; #endif /* @@ -2436,6 +2546,31 @@ xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { return(ret); } + +/** + * xmlOutputBufferCreateBuffer: + * @buffer: a xmlBufferPtr + * @encoder: the encoding converter or NULL + * + * Create a buffered output for the progressive saving to a xmlBuffer + * + * Returns the new parser output or NULL + */ +xmlOutputBufferPtr +xmlOutputBufferCreateBuffer(xmlBufferPtr buffer, + xmlCharEncodingHandlerPtr encoder) { + xmlOutputBufferPtr ret; + + if (buffer == NULL) return(NULL); + + ret = xmlOutputBufferCreateIO((xmlOutputWriteCallback) + xmlBufferWrite, + (xmlOutputCloseCallback) + NULL, (void *) buffer, encoder); + + return(ret); +} + #endif /* LIBXML_OUTPUT_ENABLED */ /** @@ -2456,7 +2591,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) { ret = xmlAllocParserInputBuffer(enc); if (ret != NULL) { - ret->context = (void *) (intptr_t) fd; + ret->context = (void *) (long) fd; ret->readcallback = xmlFdRead; ret->closecallback = xmlFdClose; } @@ -2476,7 +2611,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) { * Returns the new parser input or NULL */ xmlParserInputBufferPtr -xmlParserInputBufferCreateMem(const char *mem, intptr_t size, xmlCharEncoding enc) { +xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; int errcode; @@ -2512,7 +2647,7 @@ xmlParserInputBufferCreateMem(const char *mem, intptr_t size, xmlCharEncoding en * Returns the new parser input or NULL */ xmlParserInputBufferPtr -xmlParserInputBufferCreateStatic(const char *mem, intptr_t size, +xmlParserInputBufferCreateStatic(const char *mem, int size, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; @@ -2536,11 +2671,11 @@ xmlParserInputBufferCreateStatic(const char *mem, intptr_t size, else ret->raw = NULL; ret->compressed = -1; - ret->context = (void*) mem; + ret->context = (void *) mem; ret->readcallback = NULL; ret->closecallback = NULL; - return ret; + return(ret); } #ifdef LIBXML_OUTPUT_ENABLED @@ -2562,7 +2697,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { ret = xmlAllocOutputBuffer(encoder); if (ret != NULL) { - ret->context = (void *) (intptr_t) fd; + ret->context = (void *) (long) fd; ret->writecallback = xmlFdWrite; ret->closecallback = NULL; } @@ -2686,16 +2821,16 @@ xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func) * Returns the number of chars read and stored in the buffer, or -1 * in case of error. */ -intptr_t +int xmlParserInputBufferPush(xmlParserInputBufferPtr in, - intptr_t len, const char *buf) { - intptr_t nbchars = 0; - intptr_t ret; + int len, const char *buf) { + int nbchars = 0; + int ret; if (len < 0) return(0); if ((in == NULL) || (in->error)) return(-1); if (in->encoder != NULL) { - size_t use; + unsigned int use; /* * Store the data in the incoming raw buffer @@ -2738,10 +2873,10 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in, * When reading from an Input channel indicated end of file or error * don't reread from it again. */ -static intptr_t +static int endOfInput (void * context ATTRIBUTE_UNUSED, char * buffer ATTRIBUTE_UNUSED, - size_t len ATTRIBUTE_UNUSED) { + int len ATTRIBUTE_UNUSED) { return(0); } @@ -2760,13 +2895,13 @@ endOfInput (void * context ATTRIBUTE_UNUSED, * Returns the number of chars read and stored in the buffer, or -1 * in case of error. */ -intptr_t -xmlParserInputBufferGrow(xmlParserInputBufferPtr in, intptr_t len) { +int +xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { char *buffer = NULL; - intptr_t res = 0; - intptr_t nbchars = 0; - intptr_t buffree; - size_t needSize; + int res = 0; + int nbchars = 0; + int buffree; + unsigned int needSize; if ((in == NULL) || (in->error)) return(-1); if ((len <= MINLEN) && (len != 4)) @@ -2806,7 +2941,7 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, intptr_t len) { } len = res; if (in->encoder != NULL) { - size_t use; + unsigned int use; /* * Store the data in the incoming raw buffer @@ -2854,8 +2989,8 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, intptr_t len) { * Returns the number of chars read and stored in the buffer, or -1 * in case of error. */ -intptr_t -xmlParserInputBufferRead(xmlParserInputBufferPtr in, intptr_t len) { +int +xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) { if ((in == NULL) || (in->error)) return(-1); if (in->readcallback != NULL) return(xmlParserInputBufferGrow(in, len)); @@ -2881,12 +3016,12 @@ xmlParserInputBufferRead(xmlParserInputBufferPtr in, intptr_t len) { * Returns the number of chars immediately written, or -1 * in case of error. */ -intptr_t -xmlOutputBufferWrite(xmlOutputBufferPtr out, intptr_t len, const char *buf) { - intptr_t nbchars = 0; /* number of chars to output to I/O */ - intptr_t ret; /* return from function call */ - intptr_t written = 0; /* number of char written to I/O so far */ - intptr_t chunk; /* number of byte curreent processed from buf */ +int +xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) { + int nbchars = 0; /* number of chars to output to I/O */ + int ret; /* return from function call */ + int written = 0; /* number of char written to I/O so far */ + int chunk; /* number of byte curreent processed from buf */ if ((out == NULL) || (out->error)) return(-1); if (len < 0) return(0); @@ -2982,9 +3117,9 @@ done: * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -static intptr_t -xmlEscapeContent(unsigned char* out, intptr_t* outlen, - const xmlChar* in, intptr_t* inlen) { +static int +xmlEscapeContent(unsigned char* out, int *outlen, + const xmlChar* in, int *inlen) { unsigned char* outstart = out; const unsigned char* base = in; unsigned char* outend = out + *outlen; @@ -3044,16 +3179,16 @@ xmlEscapeContent(unsigned char* out, intptr_t* outlen, * Returns the number of chars immediately written, or -1 * in case of error. */ -intptr_t +int xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str, xmlCharEncodingOutputFunc escaping) { - intptr_t nbchars = 0; /* number of chars to output to I/O */ - intptr_t ret; /* return from function call */ - intptr_t written = 0; /* number of char written to I/O so far */ - intptr_t oldwritten=0;/* loop guard */ - intptr_t chunk; /* number of byte currently processed from str */ - intptr_t len; /* number of bytes in str */ - intptr_t cons; /* byte from str consumed */ + int nbchars = 0; /* number of chars to output to I/O */ + int ret; /* return from function call */ + int written = 0; /* number of char written to I/O so far */ + int oldwritten=0;/* loop guard */ + int chunk; /* number of byte currently processed from str */ + int len; /* number of bytes in str */ + int cons; /* byte from str consumed */ if ((out == NULL) || (out->error) || (str == NULL) || (out->buffer == NULL) || @@ -3165,9 +3300,9 @@ done: * Returns the number of chars immediately written, or -1 * in case of error. */ -intptr_t +int xmlOutputBufferWriteString(xmlOutputBufferPtr out, const char *str) { - size_t len; + int len; if ((out == NULL) || (out->error)) return(-1); if (str == NULL) @@ -3187,9 +3322,9 @@ xmlOutputBufferWriteString(xmlOutputBufferPtr out, const char *str) { * * Returns the number of byte written or -1 in case of error. */ -intptr_t +int xmlOutputBufferFlush(xmlOutputBufferPtr out) { - intptr_t nbchars = 0, ret = 0; + int nbchars = 0, ret = 0; if ((out == NULL) || (out->error)) return(-1); /* @@ -3279,7 +3414,7 @@ xmlParserGetDirectory(const char *filename) { if (getcwd(dir, 1024) != NULL) { dir[1023] = 0; ret = xmlMemStrdup(dir); - } + } } return(ret); } @@ -3533,7 +3668,6 @@ xmlGetExternalEntityLoader(void) { * * Load an external entity, note that the use of this function for * unparsed entities may generate problems - * TODO: a more generic External entity API must be designed * * Returns the xmlParserInputPtr or NULL */ diff --git a/Extras/LibXML/xmlcatalog.c b/Extras/LibXML/xmlcatalog.c index 0597e888b..6f193b177 100644 --- a/Extras/LibXML/xmlcatalog.c +++ b/Extras/LibXML/xmlcatalog.c @@ -120,7 +120,10 @@ static void usershell(void) { command[i++] = *cur++; } command[i] = 0; - if (i == 0) continue; + if (i == 0) { + free(cmdline); + continue; + } nbargs++; /* diff --git a/Extras/LibXML/xmlmemory.c b/Extras/LibXML/xmlmemory.c index 64011aa15..18e0ff145 100644 --- a/Extras/LibXML/xmlmemory.c +++ b/Extras/LibXML/xmlmemory.c @@ -49,9 +49,9 @@ #include static int xmlMemInitialized = 0; -static size_t debugMemSize = 0; -static size_t debugMemBlocks = 0; -static size_t debugMaxMemSize = 0; +static unsigned long debugMemSize = 0; +static unsigned long debugMemBlocks = 0; +static unsigned long debugMaxMemSize = 0; static xmlMutexPtr xmlMemMutex = NULL; void xmlMallocBreakpoint(void); @@ -309,7 +309,7 @@ xmlMemMalloc(size_t size) */ void * -xmlReallocLoc(void *ptr, size_t size, const char * file, int line) +xmlReallocLoc(void *ptr,size_t size, const char * file, int line) { MEMHDR *p; unsigned long number; @@ -325,6 +325,7 @@ xmlReallocLoc(void *ptr, size_t size, const char * file, int line) p = CLIENT_2_HDR(ptr); number = p->mh_number; + if (xmlMemStopAtBlock == number) xmlMallocBreakpoint(); if (p->mh_tag != MEMTAG) { Mem_Tag_Err(p); goto error; @@ -429,6 +430,7 @@ xmlMemFree(void *ptr) Mem_Tag_Err(p); goto error; } + if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint(); p->mh_tag = ~MEMTAG; memset(target, -1, p->mh_size); xmlMutexLock(xmlMemMutex); @@ -455,7 +457,7 @@ xmlMemFree(void *ptr) error: xmlGenericError(xmlGenericErrorContext, - "xmlMemFree(%lX) error\n", (unsigned long) (size_t) ptr); + "xmlMemFree(%lX) error\n", (unsigned long) ptr); xmlMallocBreakpoint(); return; } @@ -545,7 +547,7 @@ xmlMemoryStrdup(const char *str) { * Returns an int representing the amount of memory allocated. */ -size_t +int xmlMemUsed(void) { return(debugMemSize); } @@ -558,7 +560,7 @@ xmlMemUsed(void) { * Returns an int representing the number of blocks */ -size_t +int xmlMemBlocks(void) { return(debugMemBlocks); } @@ -640,7 +642,18 @@ xmlMemDisplay(FILE *fp) time_t currentTime; char buf[500]; struct tm * tstruct; +#endif +#endif + FILE *old_fp = fp; + if (fp == NULL) { + fp = fopen(".memorylist", "w"); + if (fp == NULL) + return; + } + +#ifdef MEM_LIST +#if defined(HAVE_LOCALTIME) && defined(HAVE_STRFTIME) currentTime = time(NULL); tstruct = localtime(¤tTime); strftime(buf, sizeof(buf) - 1, "%I:%M:%S %p", tstruct); @@ -666,6 +679,8 @@ xmlMemDisplay(FILE *fp) default: fprintf(fp,"Unknown memory block, may be corrupted"); xmlMutexUnlock(xmlMemMutex); + if (old_fp == NULL) + fclose(fp); return; } if (p->mh_file != NULL) fprintf(fp,"%s(%u)", p->mh_file, p->mh_line); @@ -684,6 +699,8 @@ xmlMemDisplay(FILE *fp) #else fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n"); #endif + if (old_fp == NULL) + fclose(fp); } #ifdef MEM_LIST diff --git a/Extras/LibXML/xmlmodule.c b/Extras/LibXML/xmlmodule.c index 8b0fab979..15bcf077c 100644 --- a/Extras/LibXML/xmlmodule.c +++ b/Extras/LibXML/xmlmodule.c @@ -85,7 +85,7 @@ xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED) __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, name, NULL, 0, 0, "failed to open %s\n", name); - return 0; + return(NULL); } module->name = xmlStrdup((const xmlChar *) name); @@ -179,7 +179,7 @@ xmlModuleFree(xmlModulePtr module) { if (NULL == module) { __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, - XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, + XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, "null module pointer\n"); return -1; } @@ -195,6 +195,10 @@ xmlModuleFree(xmlModulePtr module) #include #endif +#ifndef RTLD_GLOBAL /* For Tru64 UNIX 4.0 */ +#define RTLD_GLOBAL 0 +#endif + /** * xmlModulePlatformOpen: * @name: path to the module @@ -277,10 +281,7 @@ xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) int rc; errno = 0; - rc = shl_findsym(handle, name, TYPE_PROCEDURE, symbol); - if ((-1 == rc) && (0 == errno)) { - rc = shl_findsym(handle, name, TYPE_DATA, symbol); - } + rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol); return rc; } diff --git a/Extras/LibXML/xmlreader.c b/Extras/LibXML/xmlreader.c index bedd7c832..c8bcf7b2a 100644 --- a/Extras/LibXML/xmlreader.c +++ b/Extras/LibXML/xmlreader.c @@ -32,7 +32,10 @@ #include #include #include +#ifdef LIBXML_SCHEMAS_ENABLED #include +#include +#endif #include #ifdef LIBXML_XINCLUDE_ENABLED #include @@ -85,7 +88,8 @@ typedef enum { typedef enum { XML_TEXTREADER_NOT_VALIDATE = 0, XML_TEXTREADER_VALIDATE_DTD = 1, - XML_TEXTREADER_VALIDATE_RNG = 2 + XML_TEXTREADER_VALIDATE_RNG = 2, + XML_TEXTREADER_VALIDATE_XSD = 4 } xmlTextReaderValidate; struct _xmlTextReader { @@ -103,13 +107,13 @@ struct _xmlTextReader { endElementNsSAX2Func endElementNs; /* idem */ charactersSAXFunc characters; cdataBlockSAXFunc cdataBlock; - unsigned int base; /* base of the segment in the input */ - size_t cur; /* current position in the input */ - xmlNodePtr node; /* current node */ - xmlNodePtr curnode;/* current attribute node */ - int depth; /* depth of the current node */ + unsigned int base; /* base of the segment in the input */ + unsigned int cur; /* current position in the input */ + xmlNodePtr node; /* current node */ + xmlNodePtr curnode;/* current attribute node */ + int depth; /* depth of the current node */ xmlNodePtr faketext;/* fake xmlNs chld */ - int preserve;/* preserve the resulting document */ + int preserve;/* preserve the resulting document */ xmlBufferPtr buffer; /* used to return const xmlChar * */ xmlDictPtr dict; /* the context dictionnary */ @@ -127,8 +131,14 @@ struct _xmlTextReader { /* Handling of RelaxNG validation */ xmlRelaxNGPtr rngSchemas; /* The Relax NG schemas */ xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */ - int rngValidErrors;/* The number of errors detected */ + int rngValidErrors;/* The number of errors detected */ xmlNodePtr rngFullNode; /* the node if RNG not progressive */ + /* Handling of Schemas validation */ + xmlSchemaPtr xsdSchemas; /* The Schemas schemas */ + xmlSchemaValidCtxtPtr xsdValidCtxt;/* The Schemas validation context */ + int xsdPreserveCtxt; /* 1 if the context was provided by the user */ + int xsdValidErrors;/* The number of errors detected */ + xmlSchemaSAXPlugPtr xsdPlug; /* the schemas plug in SAX pipeline */ #endif #ifdef LIBXML_XINCLUDE_ENABLED /* Handling of XInclude processing */ @@ -339,7 +349,8 @@ xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur) { (cur->type == XML_XINCLUDE_END)) && (cur->properties != NULL)) xmlTextReaderFreePropList(reader, cur->properties); - if ((cur->type != XML_ELEMENT_NODE) && + if ((cur->content != (xmlChar *) &(cur->properties)) && + (cur->type != XML_ELEMENT_NODE) && (cur->type != XML_XINCLUDE_START) && (cur->type != XML_XINCLUDE_END) && (cur->type != XML_ENTITY_REF_NODE)) { @@ -413,7 +424,8 @@ xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur) { (cur->type == XML_XINCLUDE_END)) && (cur->properties != NULL)) xmlTextReaderFreePropList(reader, cur->properties); - if ((cur->type != XML_ELEMENT_NODE) && + if ((cur->content != (xmlChar *) &(cur->properties)) && + (cur->type != XML_ELEMENT_NODE) && (cur->type != XML_XINCLUDE_START) && (cur->type != XML_XINCLUDE_END) && (cur->type != XML_ENTITY_REF_NODE)) { @@ -589,14 +601,14 @@ xmlTextReaderEntPop(xmlTextReaderPtr reader) xmlNodePtr ret; if (reader->entNr <= 0) - return (0); + return (NULL); reader->entNr--; if (reader->entNr > 0) reader->ent = reader->entTab[reader->entNr - 1]; else reader->ent = NULL; ret = reader->entTab[reader->entNr]; - reader->entTab[reader->entNr] = 0; + reader->entTab[reader->entNr] = NULL; return (ret); } @@ -751,7 +763,7 @@ xmlTextReaderCharacters(void *ctx, const xmlChar *ch, int len) * called when a pcdata block has been parsed */ static void -xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch, intptr_t len) +xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch, int len) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlTextReaderPtr reader = ctxt->_private; @@ -773,11 +785,10 @@ xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch, intptr_t len) * * Returns -1 in case of failure, 0 otherwise */ -static intptr_t +static int xmlTextReaderPushData(xmlTextReaderPtr reader) { xmlBufferPtr inbuf; - intptr_t val; - intptr_t s; + int val, s; xmlTextReaderState oldstate; if ((reader->input == NULL) || (reader->input->buffer == NULL)) @@ -1125,7 +1136,7 @@ xmlTextReaderGetSuccessor(xmlNodePtr cur) { if (cur->next != NULL) return(cur->next) ; do { cur = cur->parent; - if (cur == NULL) return(NULL); + if (cur == NULL) break; if (cur->next != NULL) return(cur->next); } while (cur != NULL); return(cur); @@ -1144,7 +1155,7 @@ xmlTextReaderGetSuccessor(xmlNodePtr cur) { */ static int xmlTextReaderDoExpand(xmlTextReaderPtr reader) { - intptr_t val; + int val; if ((reader == NULL) || (reader->node == NULL) || (reader->ctxt == NULL)) return(-1); @@ -1190,8 +1201,14 @@ xmlTextReaderCollectSiblings(xmlNodePtr node) case XML_CDATA_SECTION_NODE: xmlBufferCat(buffer, node->content); break; - case XML_ELEMENT_NODE: - xmlBufferCat(buffer, xmlTextReaderCollectSiblings(node->children)); + case XML_ELEMENT_NODE: { + xmlChar *tmp; + + tmp = xmlTextReaderCollectSiblings(node->children); + xmlBufferCat(buffer, tmp); + xmlFree(tmp); + break; + } default: break; } @@ -1214,8 +1231,7 @@ xmlTextReaderCollectSiblings(xmlNodePtr node) */ int xmlTextReaderRead(xmlTextReaderPtr reader) { - intptr_t val; - int olddepth = 0; + int val, olddepth = 0; xmlTextReaderState oldstate = XML_TEXTREADER_START; xmlNodePtr oldnode = NULL; @@ -1453,11 +1469,11 @@ node_found: return -1; xmlXIncludeProcessNode(reader->xincctxt, reader->node); } - if (reader->node->type == XML_XINCLUDE_START) { + if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_START)) { reader->in_xinclude++; goto get_next_node; } - if (reader->node->type == XML_XINCLUDE_END) { + if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_END)) { reader->in_xinclude--; goto get_next_node; } @@ -1524,6 +1540,13 @@ node_found: } } } +#endif /* LIBXML_PATTERN_ENABLED */ +#ifdef LIBXML_SCHEMAS_ENABLED + if ((reader->validate == XML_TEXTREADER_VALIDATE_XSD) && + (reader->xsdValidErrors == 0) && + (reader->xsdValidCtxt != NULL)) { + reader->xsdValidErrors = !xmlSchemaIsValid(reader->xsdValidCtxt); + } #endif /* LIBXML_PATTERN_ENABLED */ return(1); node_end: @@ -1603,6 +1626,7 @@ xmlTextReaderNext(xmlTextReaderPtr reader) { return(xmlTextReaderRead(reader)); } +#ifdef LIBXML_WRITER_ENABLED /** * xmlTextReaderReadInnerXml: * @reader: the xmlTextReaderPtr used @@ -1614,11 +1638,41 @@ xmlTextReaderNext(xmlTextReaderPtr reader) { * string must be deallocated by the caller. */ xmlChar * -xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { - TODO - return(NULL); -} +xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) +{ + xmlChar *resbuf; + xmlNodePtr node, cur_node; + xmlBufferPtr buff, buff2; + xmlDocPtr doc; + if (xmlTextReaderExpand(reader) == NULL) { + return NULL; + } + doc = reader->doc; + buff = xmlBufferCreate(); + for (cur_node = reader->node->children; cur_node != NULL; + cur_node = cur_node->next) { + node = xmlDocCopyNode(cur_node, doc, 1); + buff2 = xmlBufferCreate(); + if (xmlNodeDump(buff2, doc, node, 0, 0) == -1) { + xmlFreeNode(node); + xmlBufferFree(buff2); + xmlBufferFree(buff); + return NULL; + } + xmlBufferCat(buff, buff2->content); + xmlFreeNode(node); + xmlBufferFree(buff2); + } + resbuf = buff->content; + buff->content = NULL; + + xmlBufferFree(buff); + return resbuf; +} +#endif + +#ifdef LIBXML_WRITER_ENABLED /** * xmlTextReaderReadOuterXml: * @reader: the xmlTextReaderPtr used @@ -1630,10 +1684,34 @@ xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { * string must be deallocated by the caller. */ xmlChar * -xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { - TODO - return(NULL); +xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) +{ + xmlChar *resbuf; + xmlNodePtr node; + xmlBufferPtr buff; + xmlDocPtr doc; + + node = reader->node; + doc = reader->doc; + if (xmlTextReaderExpand(reader) == NULL) { + return NULL; + } + node = xmlDocCopyNode(node, doc, 1); + buff = xmlBufferCreate(); + if (xmlNodeDump(buff, doc, node, 0, 0) == -1) { + xmlFreeNode(node); + xmlBufferFree(buff); + return NULL; + } + + resbuf = buff->content; + buff->content = NULL; + + xmlFreeNode(node); + xmlBufferFree(buff); + return resbuf; } +#endif /** * xmlTextReaderReadString: @@ -2072,6 +2150,19 @@ xmlFreeTextReader(xmlTextReaderPtr reader) { xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); reader->rngValidCtxt = NULL; } + if (reader->xsdPlug != NULL) { + xmlSchemaSAXUnplug(reader->xsdPlug); + reader->xsdPlug = NULL; + } + if (reader->xsdValidCtxt != NULL) { + if (! reader->xsdPreserveCtxt) + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + } + if (reader->xsdSchemas != NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + } #endif #ifdef LIBXML_XINCLUDE_ENABLED if (reader->xincctxt != NULL) @@ -2098,7 +2189,7 @@ xmlFreeTextReader(xmlTextReaderPtr reader) { if ((reader->ctxt->vctxt.vstateTab != NULL) && (reader->ctxt->vctxt.vstateMax > 0)){ xmlFree(reader->ctxt->vctxt.vstateTab); - reader->ctxt->vctxt.vstateTab = 0; + reader->ctxt->vctxt.vstateTab = NULL; reader->ctxt->vctxt.vstateMax = 0; } if (reader->allocs & XML_TEXTREADER_CTXT) @@ -2235,15 +2326,42 @@ xmlTextReaderGetAttribute(xmlTextReaderPtr reader, const xmlChar *name) { return(NULL); localname = xmlSplitQName2(name, &prefix); - if (localname == NULL) - return(xmlGetProp(reader->node, name)); - - ns = xmlSearchNs(reader->node->doc, reader->node, prefix); - if (ns != NULL) - ret = xmlGetNsProp(reader->node, localname, ns->href); + if (localname == NULL) { + /* + * Namespace default decl + */ + if (xmlStrEqual(name, BAD_CAST "xmlns")) { + ns = reader->node->nsDef; + while (ns != NULL) { + if (ns->prefix == NULL) { + return(xmlStrdup(ns->href)); + } + ns = ns->next; + } + return NULL; + } + return(xmlGetNoNsProp(reader->node, name)); + } - if (localname != NULL) - xmlFree(localname); + /* + * Namespace default decl + */ + if (xmlStrEqual(prefix, BAD_CAST "xmlns")) { + ns = reader->node->nsDef; + while (ns != NULL) { + if ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localname))) { + ret = xmlStrdup(ns->href); + break; + } + ns = ns->next; + } + } else { + ns = xmlSearchNs(reader->node->doc, reader->node, prefix); + if (ns != NULL) + ret = xmlGetNsProp(reader->node, localname, ns->href); + } + + xmlFree(localname); if (prefix != NULL) xmlFree(prefix); return(ret); @@ -2264,6 +2382,9 @@ xmlTextReaderGetAttribute(xmlTextReaderPtr reader, const xmlChar *name) { xmlChar * xmlTextReaderGetAttributeNs(xmlTextReaderPtr reader, const xmlChar *localName, const xmlChar *namespaceURI) { + xmlChar *prefix = NULL; + xmlNsPtr ns; + if ((reader == NULL) || (localName == NULL)) return(NULL); if (reader->node == NULL) @@ -2275,6 +2396,21 @@ xmlTextReaderGetAttributeNs(xmlTextReaderPtr reader, const xmlChar *localName, if (reader->node->type != XML_ELEMENT_NODE) return(NULL); + if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) { + if (! xmlStrEqual(localName, BAD_CAST "xmlns")) { + prefix = BAD_CAST localName; + } + ns = reader->node->nsDef; + while (ns != NULL) { + if ((prefix == NULL && ns->prefix == NULL) || + ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localName)))) { + return xmlStrdup(ns->href); + } + ns = ns->next; + } + return NULL; + } + return(xmlGetNsProp(reader->node, localName, namespaceURI)); } @@ -2525,6 +2661,8 @@ xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader, const xmlChar *localName, const xmlChar *namespaceURI) { xmlAttrPtr prop; xmlNodePtr node; + xmlNsPtr ns; + xmlChar *prefix = NULL; if ((reader == NULL) || (localName == NULL) || (namespaceURI == NULL)) return(-1); @@ -2534,10 +2672,22 @@ xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader, return(0); node = reader->node; - /* - * A priori reading http://www.w3.org/TR/REC-xml-names/ there is no - * namespace name associated to "xmlns" - */ + if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) { + if (! xmlStrEqual(localName, BAD_CAST "xmlns")) { + prefix = BAD_CAST localName; + } + ns = reader->node->nsDef; + while (ns != NULL) { + if ((prefix == NULL && ns->prefix == NULL) || + ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localName)))) { + reader->curnode = (xmlNodePtr) ns; + return(1); + } + ns = ns->next; + } + return(0); + } + prop = node->properties; while (prop != NULL) { /* @@ -2677,7 +2827,9 @@ xmlTextReaderReadAttributeValue(xmlTextReaderPtr reader) { reader->faketext = xmlNewDocText(reader->node->doc, ns->href); } else { - if (reader->faketext->content != NULL) + if ((reader->faketext->content != NULL) && + (reader->faketext->content != + (xmlChar *) &(reader->faketext->properties))) xmlFree(reader->faketext->content); reader->faketext->content = xmlStrdup(ns->href); } @@ -3657,7 +3809,7 @@ xmlTextReaderGetParserLineNumber(xmlTextReaderPtr reader) * * Returns an int or 0 if not available */ -intptr_t +int xmlTextReaderGetParserColumnNumber(xmlTextReaderPtr reader) { if ((reader == NULL) || (reader->ctxt == NULL) || @@ -3806,6 +3958,66 @@ xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) { } #ifdef LIBXML_SCHEMAS_ENABLED + +static char * +xmlTextReaderBuildMessage(const char *msg, va_list ap); + +static void XMLCDECL +xmlTextReaderValidityError(void *ctxt, const char *msg, ...); + +static void XMLCDECL +xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...); + +static void XMLCDECL xmlTextReaderValidityErrorRelay(void *ctx, const char *msg, ...) +{ + xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx; + char * str; + va_list ap; + + va_start(ap,msg); + str = xmlTextReaderBuildMessage(msg,ap); + if (!reader->errorFunc) { + xmlTextReaderValidityError(ctx, "%s", str); + } else { + reader->errorFunc(reader->errorFuncArg, str, XML_PARSER_SEVERITY_VALIDITY_ERROR, NULL /* locator */); + } + if (str != NULL) + xmlFree(str); + va_end(ap); +} + +static void XMLCDECL xmlTextReaderValidityWarningRelay(void *ctx, const char *msg, ...) +{ + xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx; + char * str; + va_list ap; + + va_start(ap,msg); + str = xmlTextReaderBuildMessage(msg,ap); + if (!reader->errorFunc) { + xmlTextReaderValidityWarning(ctx, "%s", str); + } else { + reader->errorFunc(reader->errorFuncArg, str, XML_PARSER_SEVERITY_VALIDITY_WARNING, NULL /* locator */); + } + if (str != NULL) + xmlFree(str); + va_end(ap); +} + +static void +xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error); + +static void xmlTextReaderValidityStructuredRelay(void * userData, xmlErrorPtr error) +{ + xmlTextReaderPtr reader = (xmlTextReaderPtr) userData; + + if (reader->sErrorFunc) { + reader->sErrorFunc(reader->errorFuncArg, error); + } else { + xmlTextReaderStructuredError(reader, error); + } +} + /** * xmlTextReaderRelaxNGSetSchema: * @reader: the xmlTextReaderPtr used @@ -3850,9 +4062,14 @@ xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { return(-1); if (reader->errorFunc != NULL) { xmlRelaxNGSetValidErrors(reader->rngValidCtxt, - (xmlRelaxNGValidityErrorFunc)reader->errorFunc, - (xmlRelaxNGValidityWarningFunc) reader->errorFunc, - reader->errorFuncArg); + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + if (reader->sErrorFunc != NULL) { + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); } reader->rngValidErrors = 0; reader->rngFullNode = NULL; @@ -3860,6 +4077,89 @@ xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { return(0); } +/** + * xmlTextReaderSetSchema: + * @reader: the xmlTextReaderPtr used + * @schema: a precompiled Schema schema + * + * Use XSD Schema to validate the document as it is processed. + * Activation is only possible before the first Read(). + * if @schema is NULL, then Schema validation is desactivated. + @ The @schema should not be freed until the reader is deallocated + * or its use has been deactivated. + * + * Returns 0 in case the Schema validation could be (des)activated and + * -1 in case of error. + */ +int +xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSchemaPtr schema) { + if (reader == NULL) + return(-1); + if (schema == NULL) { + if (reader->xsdPlug != NULL) { + xmlSchemaSAXUnplug(reader->xsdPlug); + reader->xsdPlug = NULL; + } + if (reader->xsdValidCtxt != NULL) { + if (! reader->xsdPreserveCtxt) + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + } + reader->xsdPreserveCtxt = 0; + if (reader->xsdSchemas != NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + } + return(0); + } + if (reader->mode != XML_TEXTREADER_MODE_INITIAL) + return(-1); + if (reader->xsdPlug != NULL) { + xmlSchemaSAXUnplug(reader->xsdPlug); + reader->xsdPlug = NULL; + } + if (reader->xsdValidCtxt != NULL) { + if (! reader->xsdPreserveCtxt) + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + } + reader->xsdPreserveCtxt = 0; + if (reader->xsdSchemas != NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + } + reader->xsdValidCtxt = xmlSchemaNewValidCtxt(schema); + if (reader->xsdValidCtxt == NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + return(-1); + } + reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, + &(reader->ctxt->sax), + &(reader->ctxt->userData)); + if (reader->xsdPlug == NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + return(-1); + } + if (reader->errorFunc != NULL) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + if (reader->sErrorFunc != NULL) { + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); + } + reader->xsdValidErrors = 0; + reader->validate = XML_TEXTREADER_VALIDATE_XSD; + return(0); +} + /** * xmlTextReaderRelaxNGValidate: * @reader: the xmlTextReaderPtr used @@ -3880,14 +4180,14 @@ xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { return(-1); if (rng == NULL) { - if (reader->rngSchemas != NULL) { - xmlRelaxNGFree(reader->rngSchemas); - reader->rngSchemas = NULL; - } if (reader->rngValidCtxt != NULL) { xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); reader->rngValidCtxt = NULL; } + if (reader->rngSchemas != NULL) { + xmlRelaxNGFree(reader->rngSchemas); + reader->rngSchemas = NULL; + } return(0); } if (reader->mode != XML_TEXTREADER_MODE_INITIAL) @@ -3903,28 +4203,197 @@ xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { ctxt = xmlRelaxNGNewParserCtxt(rng); if (reader->errorFunc != NULL) { xmlRelaxNGSetParserErrors(ctxt, - (xmlRelaxNGValidityErrorFunc) reader->errorFunc, - (xmlRelaxNGValidityWarningFunc) reader->errorFunc, - reader->errorFuncArg); + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + if (reader->sErrorFunc != NULL) { + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); } reader->rngSchemas = xmlRelaxNGParse(ctxt); xmlRelaxNGFreeParserCtxt(ctxt); if (reader->rngSchemas == NULL) return(-1); reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); - if (reader->rngValidCtxt == NULL) + if (reader->rngValidCtxt == NULL) { + xmlRelaxNGFree(reader->rngSchemas); + reader->rngSchemas = NULL; return(-1); + } if (reader->errorFunc != NULL) { xmlRelaxNGSetValidErrors(reader->rngValidCtxt, - (xmlRelaxNGValidityErrorFunc)reader->errorFunc, - (xmlRelaxNGValidityWarningFunc) reader->errorFunc, - reader->errorFuncArg); + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + if (reader->sErrorFunc != NULL) { + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); } reader->rngValidErrors = 0; reader->rngFullNode = NULL; reader->validate = XML_TEXTREADER_VALIDATE_RNG; return(0); } + +/** + * xmlTextReaderSchemaValidateInternal: + * @reader: the xmlTextReaderPtr used + * @xsd: the path to a W3C XSD schema or NULL + * @ctxt: the XML Schema validation context or NULL + * @options: options (not used yet) + * + * Validate the document as it is processed using XML Schema. + * Activation is only possible before the first Read(). + * If both @xsd and @ctxt are NULL then XML Schema validation is deactivated. + * + * Returns 0 in case the schemas validation could be (de)activated and + * -1 in case of error. + */ +static int +xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr reader, + const char *xsd, + xmlSchemaValidCtxtPtr ctxt, + int options ATTRIBUTE_UNUSED) +{ + if (reader == NULL) + return(-1); + + if ((xsd != NULL) && (ctxt != NULL)) + return(-1); + + if (((xsd != NULL) || (ctxt != NULL)) && + ((reader->mode != XML_TEXTREADER_MODE_INITIAL) || + (reader->ctxt == NULL))) + return(-1); + + /* Cleanup previous validation stuff. */ + if (reader->xsdPlug != NULL) { + xmlSchemaSAXUnplug(reader->xsdPlug); + reader->xsdPlug = NULL; + } + if (reader->xsdValidCtxt != NULL) { + if (! reader->xsdPreserveCtxt) + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + } + reader->xsdPreserveCtxt = 0; + if (reader->xsdSchemas != NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + } + + if ((xsd == NULL) && (ctxt == NULL)) { + /* We just want to deactivate the validation, so get out. */ + return(0); + } + + if (xsd != NULL) { + xmlSchemaParserCtxtPtr pctxt; + /* Parse the schema and create validation environment. */ + pctxt = xmlSchemaNewParserCtxt(xsd); + if (reader->errorFunc != NULL) { + xmlSchemaSetParserErrors(pctxt, + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + reader->xsdSchemas = xmlSchemaParse(pctxt); + xmlSchemaFreeParserCtxt(pctxt); + if (reader->xsdSchemas == NULL) + return(-1); + reader->xsdValidCtxt = xmlSchemaNewValidCtxt(reader->xsdSchemas); + if (reader->xsdValidCtxt == NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + return(-1); + } + reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, + &(reader->ctxt->sax), + &(reader->ctxt->userData)); + if (reader->xsdPlug == NULL) { + xmlSchemaFree(reader->xsdSchemas); + reader->xsdSchemas = NULL; + xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); + reader->xsdValidCtxt = NULL; + return(-1); + } + } else { + /* Use the given validation context. */ + reader->xsdValidCtxt = ctxt; + reader->xsdPreserveCtxt = 1; + reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, + &(reader->ctxt->sax), + &(reader->ctxt->userData)); + if (reader->xsdPlug == NULL) { + reader->xsdValidCtxt = NULL; + reader->xsdPreserveCtxt = 0; + return(-1); + } + } + /* + * Redirect the validation context's error channels to use + * the reader channels. + * TODO: In case the user provides the validation context we + * could make this redirection optional. + */ + if (reader->errorFunc != NULL) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + } + if (reader->sErrorFunc != NULL) { + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); + } + reader->xsdValidErrors = 0; + reader->validate = XML_TEXTREADER_VALIDATE_XSD; + return(0); +} + +/** + * xmlTextReaderSchemaValidateCtxt: + * @reader: the xmlTextReaderPtr used + * @ctxt: the XML Schema validation context or NULL + * @options: options (not used yet) + * + * Use W3C XSD schema context to validate the document as it is processed. + * Activation is only possible before the first Read(). + * If @ctxt is NULL, then XML Schema validation is deactivated. + * + * Returns 0 in case the schemas validation could be (de)activated and + * -1 in case of error. + */ +int +xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader, + xmlSchemaValidCtxtPtr ctxt, + int options) +{ + return(xmlTextReaderSchemaValidateInternal(reader, NULL, ctxt, options)); +} + +/** + * xmlTextReaderSchemaValidate: + * @reader: the xmlTextReaderPtr used + * @xsd: the path to a W3C XSD schema or NULL + * + * Use W3C XSD schema to validate the document as it is processed. + * Activation is only possible before the first Read(). + * If @xsd is NULL, then XML Schema validation is deactivated. + * + * Returns 0 in case the schemas validation could be (de)activated and + * -1 in case of error. + */ +int +xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, const char *xsd) +{ + return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0)); +} #endif /** @@ -4147,7 +4616,7 @@ xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error) { } } -static void +static void XMLCDECL xmlTextReaderError(void *ctxt, const char *msg, ...) { va_list ap; @@ -4159,7 +4628,7 @@ xmlTextReaderError(void *ctxt, const char *msg, ...) { } -static void +static void XMLCDECL xmlTextReaderWarning(void *ctxt, const char *msg, ...) { va_list ap; @@ -4170,10 +4639,10 @@ xmlTextReaderWarning(void *ctxt, const char *msg, ...) { va_end(ap); } -static void +static void XMLCDECL xmlTextReaderValidityError(void *ctxt, const char *msg, ...) { va_list ap; - intptr_t len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlen((const xmlChar *) msg); if ((len > 1) && (msg[len - 2] != ':')) { /* @@ -4188,10 +4657,10 @@ xmlTextReaderValidityError(void *ctxt, const char *msg, ...) { } } -static void +static void XMLCDECL xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...) { va_list ap; - intptr_t len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlen((const xmlChar *) msg); if ((len != 0) && (msg[len - 1] != ':')) { /* @@ -4229,6 +4698,22 @@ xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader, reader->errorFunc = f; reader->sErrorFunc = NULL; reader->errorFuncArg = arg; +#ifdef LIBXML_SCHEMAS_ENABLED + if (reader->rngValidCtxt) { + xmlRelaxNGSetValidErrors(reader->rngValidCtxt, + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); + } + if (reader->xsdValidCtxt) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, + xmlTextReaderValidityErrorRelay, + xmlTextReaderValidityWarningRelay, + reader); + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); + } +#endif } else { /* restore defaults */ @@ -4239,6 +4724,16 @@ xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader, reader->errorFunc = NULL; reader->sErrorFunc = NULL; reader->errorFuncArg = NULL; +#ifdef LIBXML_SCHEMAS_ENABLED + if (reader->rngValidCtxt) { + xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL, reader); + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); + } + if (reader->xsdValidCtxt) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL, reader); + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); + } +#endif } } @@ -4265,6 +4760,20 @@ xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader, reader->sErrorFunc = f; reader->errorFunc = NULL; reader->errorFuncArg = arg; +#ifdef LIBXML_SCHEMAS_ENABLED + if (reader->rngValidCtxt) { + xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL, reader); + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); + } + if (reader->xsdValidCtxt) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL, reader); + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, + xmlTextReaderValidityStructuredRelay, + reader); + } +#endif } else { /* restore defaults */ @@ -4276,6 +4785,16 @@ xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader, reader->errorFunc = NULL; reader->sErrorFunc = NULL; reader->errorFuncArg = NULL; +#ifdef LIBXML_SCHEMAS_ENABLED + if (reader->rngValidCtxt) { + xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL, reader); + xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); + } + if (reader->xsdValidCtxt) { + xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL, reader); + xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); + } +#endif } } @@ -4293,6 +4812,8 @@ xmlTextReaderIsValid(xmlTextReaderPtr reader) { #ifdef LIBXML_SCHEMAS_ENABLED if (reader->validate == XML_TEXTREADER_VALIDATE_RNG) return(reader->rngValidErrors == 0); + if (reader->validate == XML_TEXTREADER_VALIDATE_XSD) + return(reader->xsdValidErrors == 0); #endif if ((reader->ctxt != NULL) && (reader->ctxt->validate == 1)) return(reader->ctxt->valid); @@ -4342,6 +4863,12 @@ xmlTextReaderSetup(xmlTextReaderPtr reader, if (reader == NULL) return (-1); + /* + * we force the generation of compact text nodes on the reader + * since usr applications should never modify the tree + */ + options |= XML_PARSE_COMPACT; + reader->doc = NULL; reader->entNr = 0; reader->parserFlags = options; @@ -4531,7 +5058,7 @@ xmlTextReaderSetup(xmlTextReaderPtr reader, * Returns the index in bytes from the beginning of the entity or -1 * in case the index could not be computed. */ -intptr_t +long xmlTextReaderByteConsumed(xmlTextReaderPtr reader) { if ((reader == NULL) || (reader->ctxt == NULL)) return(-1); @@ -4592,13 +5119,14 @@ xmlTextReaderPtr xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding, int options) { - intptr_t len; + int len; if (cur == NULL) return (NULL); len = xmlStrlen(cur); - return (xmlReaderForMemory((const char *) cur, len, URL, encoding, options)); + return (xmlReaderForMemory + ((const char *) cur, len, URL, encoding, options)); } /** @@ -4638,7 +5166,7 @@ xmlReaderForFile(const char *filename, const char *encoding, int options) * Returns the new reader or NULL in case of error. */ xmlTextReaderPtr -xmlReaderForMemory(const char *buffer, intptr_t size, const char *URL, +xmlReaderForMemory(const char *buffer, int size, const char *URL, const char *encoding, int options) { xmlTextReaderPtr reader; @@ -4798,7 +5326,7 @@ xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, const char *URL, const char *encoding, int options) { - intptr_t len; + int len; if (cur == NULL) return (-1); @@ -4806,7 +5334,8 @@ xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, return (-1); len = xmlStrlen(cur); - return (xmlReaderNewMemory(reader, (const char *)cur, len, URL, encoding, options)); + return (xmlReaderNewMemory(reader, (const char *)cur, len, + URL, encoding, options)); } /** @@ -4857,7 +5386,7 @@ xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename, * Returns 0 in case of success and -1 in case of error */ int -xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, intptr_t size, +xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size, const char *URL, const char *encoding, int options) { xmlParserInputBufferPtr input; diff --git a/Extras/LibXML/xmlregexp.c b/Extras/LibXML/xmlregexp.c index 495f1c578..58f480dac 100644 --- a/Extras/LibXML/xmlregexp.c +++ b/Extras/LibXML/xmlregexp.c @@ -38,10 +38,12 @@ #endif /* #define DEBUG_REGEXP_GRAPH */ -/* #define DEBUG_REGEXP_EXEC */ +/* #define DEBUG_REGEXP_EXEC */ /* #define DEBUG_PUSH */ /* #define DEBUG_COMPACTION */ +#define MAX_PUSH 10000000 + #define ERROR(str) \ ctxt->error = XML_REGEXP_COMPILE_ERROR; \ xmlRegexpErrCompile(ctxt, str); @@ -69,24 +71,27 @@ * * ************************************************************************/ +/* + * Note: the order of the enums below is significant, do not shuffle + */ typedef enum { XML_REGEXP_EPSILON = 1, XML_REGEXP_CHARVAL, XML_REGEXP_RANGES, - XML_REGEXP_SUBREG, + XML_REGEXP_SUBREG, /* used for () sub regexps */ XML_REGEXP_STRING, XML_REGEXP_ANYCHAR, /* . */ XML_REGEXP_ANYSPACE, /* \s */ XML_REGEXP_NOTSPACE, /* \S */ XML_REGEXP_INITNAME, /* \l */ - XML_REGEXP_NOTINITNAME, /* \l */ + XML_REGEXP_NOTINITNAME, /* \L */ XML_REGEXP_NAMECHAR, /* \c */ XML_REGEXP_NOTNAMECHAR, /* \C */ XML_REGEXP_DECIMAL, /* \d */ - XML_REGEXP_NOTDECIMAL, /* \d */ + XML_REGEXP_NOTDECIMAL, /* \D */ XML_REGEXP_REALCHAR, /* \w */ - XML_REGEXP_NOTREALCHAR, /* \w */ - XML_REGEXP_LETTER, + XML_REGEXP_NOTREALCHAR, /* \W */ + XML_REGEXP_LETTER = 100, XML_REGEXP_LETTER_UPPERCASE, XML_REGEXP_LETTER_LOWERCASE, XML_REGEXP_LETTER_TITLECASE, @@ -201,6 +206,7 @@ struct _xmlRegTrans { int to; int counter; int count; + int nd; }; struct _xmlAutomataState { @@ -211,6 +217,10 @@ struct _xmlAutomataState { int maxTrans; int nbTrans; xmlRegTrans *trans; + /* knowing states ponting to us can speed things up */ + int maxTransTo; + int nbTransTo; + int *transTo; }; typedef struct _xmlAutomata xmlRegParserCtxt; @@ -242,6 +252,7 @@ struct _xmlAutomata { xmlRegCounter *counters; int determinist; + int negs; }; struct _xmlRegexp { @@ -321,6 +332,7 @@ struct _xmlRegExecCtxt { xmlRegStatePtr errState; /* the error state */ xmlChar *errString; /* the string raising the error */ int *errCounts; /* counters at the error state */ + int nbPush; }; #define REGEXP_ALL_COUNTER 0x123456 @@ -329,6 +341,10 @@ struct _xmlRegExecCtxt { static void xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top); static void xmlRegFreeState(xmlRegStatePtr state); static void xmlRegFreeAtom(xmlRegAtomPtr atom); +static int xmlRegStrEqualWildcard(const xmlChar *expStr, const xmlChar *valStr); +static int xmlRegCheckCharacter(xmlRegAtomPtr atom, int codepoint); +static int xmlRegCheckCharacterRange(xmlRegAtomType type, int codepoint, + int neg, int start, int end, const xmlChar *blockName); /************************************************************************ * * @@ -411,9 +427,13 @@ xmlRegEpxFromParse(xmlRegParserCtxtPtr ctxt) { ret->nbCounters = ctxt->nbCounters; ret->counters = ctxt->counters; ret->determinist = ctxt->determinist; + if (ret->determinist == -1) { + xmlRegexpIsDeterminist(ret); + } if ((ret->determinist != 0) && (ret->nbCounters == 0) && + (ctxt->negs == 0) && (ret->atoms != NULL) && (ret->atoms[0] != NULL) && (ret->atoms[0]->type == XML_REGEXP_STRING)) { @@ -562,7 +582,6 @@ xmlRegEpxFromParse(xmlRegParserCtxtPtr ctxt) { i, j, trans->atom->no, trans->to, atomno, targetno); printf(" previous to is %d\n", prev); #endif - ret->determinist = 0; if (transdata != NULL) xmlFree(transdata); xmlFree(transitions); @@ -656,6 +675,7 @@ xmlRegNewParserCtxt(const xmlChar *string) { ret->string = xmlStrdup(string); ret->cur = ret->string; ret->neg = 0; + ret->negs = 0; ret->error = 0; ret->determinist = -1; return(ret); @@ -749,7 +769,11 @@ xmlRegFreeAtom(xmlRegAtomPtr atom) { xmlRegFreeRange(atom->ranges[i]); if (atom->ranges != NULL) xmlFree(atom->ranges); - if (atom->type == XML_REGEXP_STRING) + if ((atom->type == XML_REGEXP_STRING) && (atom->valuep != NULL)) + xmlFree(atom->valuep); + if ((atom->type == XML_REGEXP_STRING) && (atom->valuep2 != NULL)) + xmlFree(atom->valuep2); + if ((atom->type == XML_REGEXP_BLOCK_NAME) && (atom->valuep != NULL)) xmlFree(atom->valuep); xmlFree(atom); } @@ -782,6 +806,8 @@ xmlRegFreeState(xmlRegStatePtr state) { if (state->trans != NULL) xmlFree(state->trans); + if (state->transTo != NULL) + xmlFree(state->transTo); xmlFree(state); } @@ -969,6 +995,8 @@ xmlRegPrintAtom(FILE *output, xmlRegAtomPtr atom) { fprintf(output, "NULL\n"); return; } + if (atom->neg) + fprintf(output, "not "); xmlRegPrintAtomType(output, atom->type); xmlRegPrintQuantType(output, atom->quant); if (atom->quant == XML_REGEXP_QUANT_RANGE) @@ -1000,6 +1028,12 @@ xmlRegPrintTrans(FILE *output, xmlRegTransPtr trans) { fprintf(output, "removed\n"); return; } + if (trans->nd != 0) { + if (trans->nd == 2) + fprintf(output, "last not determinist, "); + else + fprintf(output, "not determinist, "); + } if (trans->counter >= 0) { fprintf(output, "counted %d, ", trans->counter); } @@ -1188,6 +1222,34 @@ xmlRegAtomPush(xmlRegParserCtxtPtr ctxt, xmlRegAtomPtr atom) { return(0); } +static void +xmlRegStateAddTransTo(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr target, + int from) { + if (target->maxTransTo == 0) { + target->maxTransTo = 8; + target->transTo = (int *) xmlMalloc(target->maxTransTo * + sizeof(int)); + if (target->transTo == NULL) { + xmlRegexpErrMemory(ctxt, "adding transition"); + target->maxTransTo = 0; + return; + } + } else if (target->nbTransTo >= target->maxTransTo) { + int *tmp; + target->maxTransTo *= 2; + tmp = (int *) xmlRealloc(target->transTo, target->maxTransTo * + sizeof(int)); + if (tmp == NULL) { + xmlRegexpErrMemory(ctxt, "adding transition"); + target->maxTransTo /= 2; + return; + } + target->transTo = tmp; + } + target->transTo[target->nbTransTo] = from; + target->nbTransTo++; +} + static void xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state, xmlRegAtomPtr atom, xmlRegStatePtr target, @@ -1209,21 +1271,22 @@ xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state, * so, silently ignore this request. */ - for (nrtrans=0; nrtransnbTrans; nrtrans++) { - if ((state->trans[nrtrans].atom == atom) && - (state->trans[nrtrans].to == target->no) && - (state->trans[nrtrans].counter == counter) && - (state->trans[nrtrans].count == count)) { + for (nrtrans = state->nbTrans - 1; nrtrans >= 0; nrtrans--) { + xmlRegTransPtr trans = &(state->trans[nrtrans]); + if ((trans->atom == atom) && + (trans->to == target->no) && + (trans->counter == counter) && + (trans->count == count)) { #ifdef DEBUG_REGEXP_GRAPH - printf("Ignoring duplicate transition from %d to %d\n", - state->no, target->no); + printf("Ignoring duplicate transition from %d to %d\n", + state->no, target->no); #endif - return; - } + return; + } } if (state->maxTrans == 0) { - state->maxTrans = 4; + state->maxTrans = 8; state->trans = (xmlRegTrans *) xmlMalloc(state->maxTrans * sizeof(xmlRegTrans)); if (state->trans == NULL) { @@ -1261,7 +1324,9 @@ xmlRegStateAddTrans(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state, state->trans[state->nbTrans].to = target->no; state->trans[state->nbTrans].counter = counter; state->trans[state->nbTrans].count = count; + state->trans[state->nbTrans].nd = 0; state->nbTrans++; + xmlRegStateAddTransTo(ctxt, target, state->no); } static int @@ -1402,11 +1467,25 @@ xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, * Generate an epsilon transition to link to the target */ xmlFAGenerateEpsilonTransition(ctxt, atom->stop, to); +#ifdef DV + } else if ((to == NULL) && (atom->quant != XML_REGEXP_QUANT_RANGE) && + (atom->quant != XML_REGEXP_QUANT_ONCE)) { + to = xmlRegNewState(ctxt); + xmlRegStatePush(ctxt, to); + ctxt->state = to; + xmlFAGenerateEpsilonTransition(ctxt, atom->stop, to); +#endif } switch (atom->quant) { case XML_REGEXP_QUANT_OPT: atom->quant = XML_REGEXP_QUANT_ONCE; - xmlFAGenerateEpsilonTransition(ctxt, atom->start, atom->stop); + /* + * transition done to the state after end of atom. + * 1. set transition from atom start to new state + * 2. set transition from atom end to this state. + */ + xmlFAGenerateEpsilonTransition(ctxt, atom->start, 0); + xmlFAGenerateEpsilonTransition(ctxt, atom->stop, ctxt->state); break; case XML_REGEXP_QUANT_MULT: atom->quant = XML_REGEXP_QUANT_ONCE; @@ -1449,23 +1528,33 @@ xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, atom->min = 0; atom->max = 0; atom->quant = XML_REGEXP_QUANT_ONCE; - xmlFAGenerateCountedEpsilonTransition(ctxt, atom->stop, - atom->start, counter); if (to != NULL) { newstate = to; } else { newstate = xmlRegNewState(ctxt); xmlRegStatePush(ctxt, newstate); - ctxt->state = newstate; } + ctxt->state = newstate; xmlFAGenerateCountedTransition(ctxt, atom->stop, newstate, counter); + + /* + * first check count and if OK jump forward; + * if checking fail increment count and jump back + */ + xmlFAGenerateCountedEpsilonTransition(ctxt, atom->stop, + atom->start, counter); } default: break; } return(0); - } else { + } + if ((atom->min == 0) && (atom->max == 0) && + (atom->quant == XML_REGEXP_QUANT_RANGE)) { + /* + * we can discard the atom and generate an epsilon transition instead + */ if (to == NULL) { to = xmlRegNewState(ctxt); if (to != NULL) @@ -1474,12 +1563,24 @@ xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, return(-1); } } - if (xmlRegAtomPush(ctxt, atom) < 0) { + xmlFAGenerateEpsilonTransition(ctxt, from, to); + ctxt->state = to; + xmlRegFreeAtom(atom); + return(0); + } + if (to == NULL) { + to = xmlRegNewState(ctxt); + if (to != NULL) + xmlRegStatePush(ctxt, to); + else { return(-1); } - xmlRegStateAddTrans(ctxt, from, atom, to, -1, -1); - ctxt->state = to; } + if (xmlRegAtomPush(ctxt, atom) < 0) { + return(-1); + } + xmlRegStateAddTrans(ctxt, from, atom, to, -1, -1); + ctxt->state = to; switch (atom->quant) { case XML_REGEXP_QUANT_OPT: atom->quant = XML_REGEXP_QUANT_ONCE; @@ -1536,6 +1637,8 @@ xmlFAReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int fromnr, from->type = XML_REGEXP_FINAL_STATE; } for (transnr = 0;transnr < to->nbTrans;transnr++) { + if (to->trans[transnr].to < 0) + continue; if (to->trans[transnr].atom == NULL) { /* * Don't remove counted transitions @@ -1580,6 +1683,89 @@ xmlFAReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int fromnr, to->mark = XML_REGEXP_MARK_NORMAL; } +/** + * xmlFAEliminateSimpleEpsilonTransitions: + * @ctxt: a regexp parser context + * + * Eliminating general epsilon transitions can get costly in the general + * algorithm due to the large amount of generated new transitions and + * associated comparisons. However for simple epsilon transition used just + * to separate building blocks when generating the automata this can be + * reduced to state elimination: + * - if there exists an epsilon from X to Y + * - if there is no other transition from X + * then X and Y are semantically equivalent and X can be eliminated + * If X is the start state then make Y the start state, else replace the + * target of all transitions to X by transitions to Y. + */ +static void +xmlFAEliminateSimpleEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { + int statenr, i, j, newto; + xmlRegStatePtr state, tmp; + + for (statenr = 0;statenr < ctxt->nbStates;statenr++) { + state = ctxt->states[statenr]; + if (state == NULL) + continue; + if (state->nbTrans != 1) + continue; + /* is the only transition out a basic transition */ + if ((state->trans[0].atom == NULL) && + (state->trans[0].to >= 0) && + (state->trans[0].to != statenr) && + (state->trans[0].counter < 0) && + (state->trans[0].count < 0)) { + newto = state->trans[0].to; + + if (state->type == XML_REGEXP_START_STATE) { +#ifdef DEBUG_REGEXP_GRAPH + printf("Found simple epsilon trans from start %d to %d\n", + statenr, newto); +#endif + } else { +#ifdef DEBUG_REGEXP_GRAPH + printf("Found simple epsilon trans from %d to %d\n", + statenr, newto); +#endif + for (i = 0;i < state->nbTransTo;i++) { + tmp = ctxt->states[state->transTo[i]]; + for (j = 0;j < tmp->nbTrans;j++) { + if (tmp->trans[j].to == statenr) { + tmp->trans[j].to = newto; +#ifdef DEBUG_REGEXP_GRAPH + printf("Changed transition %d on %d to go to %d\n", + j, tmp->no, newto); +#endif + xmlRegStateAddTransTo(ctxt, ctxt->states[newto], + tmp->no); + } + } + } +#if 0 + for (i = 0;i < ctxt->nbStates;i++) { + tmp = ctxt->states[i]; + for (j = 0;j < tmp->nbTrans;j++) { + if (tmp->trans[j].to == statenr) { + tmp->trans[j].to = newto; +#ifdef DEBUG_REGEXP_GRAPH + printf("Changed transition %d on %d to go to %d\n", + j, tmp->no, newto); +#endif + } + } + } +#endif + if (state->type == XML_REGEXP_FINAL_STATE) + ctxt->states[newto]->type = XML_REGEXP_FINAL_STATE; + /* eliminate the transition completely */ + state->nbTrans = 0; + + + } + + } + } +} /** * xmlFAEliminateEpsilonTransitions: * @ctxt: a regexp parser context @@ -1589,9 +1775,13 @@ static void xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { int statenr, transnr; xmlRegStatePtr state; + int has_epsilon; if (ctxt->states == NULL) return; + xmlFAEliminateSimpleEpsilonTransitions(ctxt); + + has_epsilon = 0; /* * build the completed transitions bypassing the epsilons @@ -1623,6 +1813,7 @@ xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { transnr, statenr, newto); #endif state->mark = XML_REGEXP_MARK_START; + has_epsilon = 1; xmlFAReduceEpsilonTransitions(ctxt, statenr, newto, state->trans[transnr].counter); state->mark = XML_REGEXP_MARK_NORMAL; @@ -1638,15 +1829,18 @@ xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { /* * Eliminate the epsilon transitions */ - for (statenr = 0;statenr < ctxt->nbStates;statenr++) { - state = ctxt->states[statenr]; - if (state == NULL) - continue; - for (transnr = 0;transnr < state->nbTrans;transnr++) { - if ((state->trans[transnr].atom == NULL) && - (state->trans[transnr].count < 0) && - (state->trans[transnr].to >= 0)) { - state->trans[transnr].to = -1; + if (has_epsilon) { + for (statenr = 0;statenr < ctxt->nbStates;statenr++) { + state = ctxt->states[statenr]; + if (state == NULL) + continue; + for (transnr = 0;transnr < state->nbTrans;transnr++) { + xmlRegTransPtr trans = &(state->trans[transnr]); + if ((trans->atom == NULL) && + (trans->count < 0) && + (trans->to >= 0)) { + trans->to = -1; + } } } } @@ -1711,38 +1905,493 @@ xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { } +static int +xmlFACompareRanges(xmlRegRangePtr range1, xmlRegRangePtr range2) { + int ret = 0; + + if ((range1->type == XML_REGEXP_RANGES) || + (range2->type == XML_REGEXP_RANGES) || + (range2->type == XML_REGEXP_SUBREG) || + (range1->type == XML_REGEXP_SUBREG) || + (range1->type == XML_REGEXP_STRING) || + (range2->type == XML_REGEXP_STRING)) + return(-1); + + /* put them in order */ + if (range1->type > range2->type) { + xmlRegRangePtr tmp; + + tmp = range1; + range1 = range2; + range2 = tmp; + } + if ((range1->type == XML_REGEXP_ANYCHAR) || + (range2->type == XML_REGEXP_ANYCHAR)) { + ret = 1; + } else if ((range1->type == XML_REGEXP_EPSILON) || + (range2->type == XML_REGEXP_EPSILON)) { + return(0); + } else if (range1->type == range2->type) { + if ((range1->type != XML_REGEXP_CHARVAL) || + (range1->end < range2->start) || + (range2->end < range1->start)) + ret = 1; + else + ret = 0; + } else if (range1->type == XML_REGEXP_CHARVAL) { + int codepoint; + int neg = 0; + + /* + * just check all codepoints in the range for acceptance, + * this is usually way cheaper since done only once at + * compilation than testing over and over at runtime or + * pushing too many states when evaluating. + */ + if (((range1->neg == 0) && (range2->neg != 0)) || + ((range1->neg != 0) && (range2->neg == 0))) + neg = 1; + + for (codepoint = range1->start;codepoint <= range1->end ;codepoint++) { + ret = xmlRegCheckCharacterRange(range2->type, codepoint, + 0, range2->start, range2->end, + range2->blockName); + if (ret < 0) + return(-1); + if (((neg == 1) && (ret == 0)) || + ((neg == 0) && (ret == 1))) + return(1); + } + return(0); + } else if ((range1->type == XML_REGEXP_BLOCK_NAME) || + (range2->type == XML_REGEXP_BLOCK_NAME)) { + if (range1->type == range2->type) { + ret = xmlStrEqual(range1->blockName, range2->blockName); + } else { + /* + * comparing a block range with anything else is way + * too costly, and maintining the table is like too much + * memory too, so let's force the automata to save state + * here. + */ + return(1); + } + } else if ((range1->type < XML_REGEXP_LETTER) || + (range2->type < XML_REGEXP_LETTER)) { + if ((range1->type == XML_REGEXP_ANYSPACE) && + (range2->type == XML_REGEXP_NOTSPACE)) + ret = 0; + else if ((range1->type == XML_REGEXP_INITNAME) && + (range2->type == XML_REGEXP_NOTINITNAME)) + ret = 0; + else if ((range1->type == XML_REGEXP_NAMECHAR) && + (range2->type == XML_REGEXP_NOTNAMECHAR)) + ret = 0; + else if ((range1->type == XML_REGEXP_DECIMAL) && + (range2->type == XML_REGEXP_NOTDECIMAL)) + ret = 0; + else if ((range1->type == XML_REGEXP_REALCHAR) && + (range2->type == XML_REGEXP_NOTREALCHAR)) + ret = 0; + else { + /* same thing to limit complexity */ + return(1); + } + } else { + ret = 0; + /* range1->type < range2->type here */ + switch (range1->type) { + case XML_REGEXP_LETTER: + /* all disjoint except in the subgroups */ + if ((range2->type == XML_REGEXP_LETTER_UPPERCASE) || + (range2->type == XML_REGEXP_LETTER_LOWERCASE) || + (range2->type == XML_REGEXP_LETTER_TITLECASE) || + (range2->type == XML_REGEXP_LETTER_MODIFIER) || + (range2->type == XML_REGEXP_LETTER_OTHERS)) + ret = 1; + break; + case XML_REGEXP_MARK: + if ((range2->type == XML_REGEXP_MARK_NONSPACING) || + (range2->type == XML_REGEXP_MARK_SPACECOMBINING) || + (range2->type == XML_REGEXP_MARK_ENCLOSING)) + ret = 1; + break; + case XML_REGEXP_NUMBER: + if ((range2->type == XML_REGEXP_NUMBER_DECIMAL) || + (range2->type == XML_REGEXP_NUMBER_LETTER) || + (range2->type == XML_REGEXP_NUMBER_OTHERS)) + ret = 1; + break; + case XML_REGEXP_PUNCT: + if ((range2->type == XML_REGEXP_PUNCT_CONNECTOR) || + (range2->type == XML_REGEXP_PUNCT_DASH) || + (range2->type == XML_REGEXP_PUNCT_OPEN) || + (range2->type == XML_REGEXP_PUNCT_CLOSE) || + (range2->type == XML_REGEXP_PUNCT_INITQUOTE) || + (range2->type == XML_REGEXP_PUNCT_FINQUOTE) || + (range2->type == XML_REGEXP_PUNCT_OTHERS)) + ret = 1; + break; + case XML_REGEXP_SEPAR: + if ((range2->type == XML_REGEXP_SEPAR_SPACE) || + (range2->type == XML_REGEXP_SEPAR_LINE) || + (range2->type == XML_REGEXP_SEPAR_PARA)) + ret = 1; + break; + case XML_REGEXP_SYMBOL: + if ((range2->type == XML_REGEXP_SYMBOL_MATH) || + (range2->type == XML_REGEXP_SYMBOL_CURRENCY) || + (range2->type == XML_REGEXP_SYMBOL_MODIFIER) || + (range2->type == XML_REGEXP_SYMBOL_OTHERS)) + ret = 1; + break; + case XML_REGEXP_OTHER: + if ((range2->type == XML_REGEXP_OTHER_CONTROL) || + (range2->type == XML_REGEXP_OTHER_FORMAT) || + (range2->type == XML_REGEXP_OTHER_PRIVATE)) + ret = 1; + break; + default: + if ((range2->type >= XML_REGEXP_LETTER) && + (range2->type < XML_REGEXP_BLOCK_NAME)) + ret = 0; + else { + /* safety net ! */ + return(1); + } + } + } + if (((range1->neg == 0) && (range2->neg != 0)) || + ((range1->neg != 0) && (range2->neg == 0))) + ret = !ret; + return(1); +} + /** - * xmlFACompareAtoms: + * xmlFACompareAtomTypes: + * @type1: an atom type + * @type2: an atom type + * + * Compares two atoms type to check whether they intersect in some ways, + * this is used by xmlFACompareAtoms only + * + * Returns 1 if they may intersect and 0 otherwise + */ +static int +xmlFACompareAtomTypes(xmlRegAtomType type1, xmlRegAtomType type2) { + if ((type1 == XML_REGEXP_EPSILON) || + (type1 == XML_REGEXP_CHARVAL) || + (type1 == XML_REGEXP_RANGES) || + (type1 == XML_REGEXP_SUBREG) || + (type1 == XML_REGEXP_STRING) || + (type1 == XML_REGEXP_ANYCHAR)) + return(1); + if ((type2 == XML_REGEXP_EPSILON) || + (type2 == XML_REGEXP_CHARVAL) || + (type2 == XML_REGEXP_RANGES) || + (type2 == XML_REGEXP_SUBREG) || + (type2 == XML_REGEXP_STRING) || + (type2 == XML_REGEXP_ANYCHAR)) + return(1); + + if (type1 == type2) return(1); + + /* simplify subsequent compares by making sure type1 < type2 */ + if (type1 > type2) { + xmlRegAtomType tmp = type1; + type1 = type2; + type2 = tmp; + } + switch (type1) { + case XML_REGEXP_ANYSPACE: /* \s */ + /* can't be a letter, number, mark, pontuation, symbol */ + if ((type2 == XML_REGEXP_NOTSPACE) || + ((type2 >= XML_REGEXP_LETTER) && + (type2 <= XML_REGEXP_LETTER_OTHERS)) || + ((type2 >= XML_REGEXP_NUMBER) && + (type2 <= XML_REGEXP_NUMBER_OTHERS)) || + ((type2 >= XML_REGEXP_MARK) && + (type2 <= XML_REGEXP_MARK_ENCLOSING)) || + ((type2 >= XML_REGEXP_PUNCT) && + (type2 <= XML_REGEXP_PUNCT_OTHERS)) || + ((type2 >= XML_REGEXP_SYMBOL) && + (type2 <= XML_REGEXP_SYMBOL_OTHERS)) + ) return(0); + break; + case XML_REGEXP_NOTSPACE: /* \S */ + break; + case XML_REGEXP_INITNAME: /* \l */ + /* can't be a number, mark, separator, pontuation, symbol or other */ + if ((type2 == XML_REGEXP_NOTINITNAME) || + ((type2 >= XML_REGEXP_NUMBER) && + (type2 <= XML_REGEXP_NUMBER_OTHERS)) || + ((type2 >= XML_REGEXP_MARK) && + (type2 <= XML_REGEXP_MARK_ENCLOSING)) || + ((type2 >= XML_REGEXP_SEPAR) && + (type2 <= XML_REGEXP_SEPAR_PARA)) || + ((type2 >= XML_REGEXP_PUNCT) && + (type2 <= XML_REGEXP_PUNCT_OTHERS)) || + ((type2 >= XML_REGEXP_SYMBOL) && + (type2 <= XML_REGEXP_SYMBOL_OTHERS)) || + ((type2 >= XML_REGEXP_OTHER) && + (type2 <= XML_REGEXP_OTHER_NA)) + ) return(0); + break; + case XML_REGEXP_NOTINITNAME: /* \L */ + break; + case XML_REGEXP_NAMECHAR: /* \c */ + /* can't be a mark, separator, pontuation, symbol or other */ + if ((type2 == XML_REGEXP_NOTNAMECHAR) || + ((type2 >= XML_REGEXP_MARK) && + (type2 <= XML_REGEXP_MARK_ENCLOSING)) || + ((type2 >= XML_REGEXP_PUNCT) && + (type2 <= XML_REGEXP_PUNCT_OTHERS)) || + ((type2 >= XML_REGEXP_SEPAR) && + (type2 <= XML_REGEXP_SEPAR_PARA)) || + ((type2 >= XML_REGEXP_SYMBOL) && + (type2 <= XML_REGEXP_SYMBOL_OTHERS)) || + ((type2 >= XML_REGEXP_OTHER) && + (type2 <= XML_REGEXP_OTHER_NA)) + ) return(0); + break; + case XML_REGEXP_NOTNAMECHAR: /* \C */ + break; + case XML_REGEXP_DECIMAL: /* \d */ + /* can't be a letter, mark, separator, pontuation, symbol or other */ + if ((type2 == XML_REGEXP_NOTDECIMAL) || + (type2 == XML_REGEXP_REALCHAR) || + ((type2 >= XML_REGEXP_LETTER) && + (type2 <= XML_REGEXP_LETTER_OTHERS)) || + ((type2 >= XML_REGEXP_MARK) && + (type2 <= XML_REGEXP_MARK_ENCLOSING)) || + ((type2 >= XML_REGEXP_PUNCT) && + (type2 <= XML_REGEXP_PUNCT_OTHERS)) || + ((type2 >= XML_REGEXP_SEPAR) && + (type2 <= XML_REGEXP_SEPAR_PARA)) || + ((type2 >= XML_REGEXP_SYMBOL) && + (type2 <= XML_REGEXP_SYMBOL_OTHERS)) || + ((type2 >= XML_REGEXP_OTHER) && + (type2 <= XML_REGEXP_OTHER_NA)) + )return(0); + break; + case XML_REGEXP_NOTDECIMAL: /* \D */ + break; + case XML_REGEXP_REALCHAR: /* \w */ + /* can't be a mark, separator, pontuation, symbol or other */ + if ((type2 == XML_REGEXP_NOTDECIMAL) || + ((type2 >= XML_REGEXP_MARK) && + (type2 <= XML_REGEXP_MARK_ENCLOSING)) || + ((type2 >= XML_REGEXP_PUNCT) && + (type2 <= XML_REGEXP_PUNCT_OTHERS)) || + ((type2 >= XML_REGEXP_SEPAR) && + (type2 <= XML_REGEXP_SEPAR_PARA)) || + ((type2 >= XML_REGEXP_SYMBOL) && + (type2 <= XML_REGEXP_SYMBOL_OTHERS)) || + ((type2 >= XML_REGEXP_OTHER) && + (type2 <= XML_REGEXP_OTHER_NA)) + )return(0); + break; + case XML_REGEXP_NOTREALCHAR: /* \W */ + break; + /* + * at that point we know both type 1 and type2 are from + * character categories are ordered and are different, + * it becomes simple because this is a partition + */ + case XML_REGEXP_LETTER: + if (type2 <= XML_REGEXP_LETTER_OTHERS) + return(1); + return(0); + case XML_REGEXP_LETTER_UPPERCASE: + case XML_REGEXP_LETTER_LOWERCASE: + case XML_REGEXP_LETTER_TITLECASE: + case XML_REGEXP_LETTER_MODIFIER: + case XML_REGEXP_LETTER_OTHERS: + return(0); + case XML_REGEXP_MARK: + if (type2 <= XML_REGEXP_MARK_ENCLOSING) + return(1); + return(0); + case XML_REGEXP_MARK_NONSPACING: + case XML_REGEXP_MARK_SPACECOMBINING: + case XML_REGEXP_MARK_ENCLOSING: + return(0); + case XML_REGEXP_NUMBER: + if (type2 <= XML_REGEXP_NUMBER_OTHERS) + return(1); + return(0); + case XML_REGEXP_NUMBER_DECIMAL: + case XML_REGEXP_NUMBER_LETTER: + case XML_REGEXP_NUMBER_OTHERS: + return(0); + case XML_REGEXP_PUNCT: + if (type2 <= XML_REGEXP_PUNCT_OTHERS) + return(1); + return(0); + case XML_REGEXP_PUNCT_CONNECTOR: + case XML_REGEXP_PUNCT_DASH: + case XML_REGEXP_PUNCT_OPEN: + case XML_REGEXP_PUNCT_CLOSE: + case XML_REGEXP_PUNCT_INITQUOTE: + case XML_REGEXP_PUNCT_FINQUOTE: + case XML_REGEXP_PUNCT_OTHERS: + return(0); + case XML_REGEXP_SEPAR: + if (type2 <= XML_REGEXP_SEPAR_PARA) + return(1); + return(0); + case XML_REGEXP_SEPAR_SPACE: + case XML_REGEXP_SEPAR_LINE: + case XML_REGEXP_SEPAR_PARA: + return(0); + case XML_REGEXP_SYMBOL: + if (type2 <= XML_REGEXP_SYMBOL_OTHERS) + return(1); + return(0); + case XML_REGEXP_SYMBOL_MATH: + case XML_REGEXP_SYMBOL_CURRENCY: + case XML_REGEXP_SYMBOL_MODIFIER: + case XML_REGEXP_SYMBOL_OTHERS: + return(0); + case XML_REGEXP_OTHER: + if (type2 <= XML_REGEXP_OTHER_NA) + return(1); + return(0); + case XML_REGEXP_OTHER_CONTROL: + case XML_REGEXP_OTHER_FORMAT: + case XML_REGEXP_OTHER_PRIVATE: + case XML_REGEXP_OTHER_NA: + return(0); + default: + break; + } + return(1); +} + +/** + * xmlFAEqualAtoms: * @atom1: an atom * @atom2: an atom * - * Compares two atoms to check whether they are equivalents + * Compares two atoms to check whether they are the same exactly + * this is used to remove equivalent transitions * - * Returns 1 if yes and 0 otherwise + * Returns 1 if same and 0 otherwise */ static int -xmlFACompareAtoms(xmlRegAtomPtr atom1, xmlRegAtomPtr atom2) { +xmlFAEqualAtoms(xmlRegAtomPtr atom1, xmlRegAtomPtr atom2) { + int ret = 0; + if (atom1 == atom2) return(1); if ((atom1 == NULL) || (atom2 == NULL)) return(0); if (atom1->type != atom2->type) - return(0); + return(0); switch (atom1->type) { - case XML_REGEXP_STRING: - return(xmlStrEqual((xmlChar *)atom1->valuep, - (xmlChar *)atom2->valuep)); case XML_REGEXP_EPSILON: - return(1); + ret = 0; + break; + case XML_REGEXP_STRING: + ret = xmlStrEqual((xmlChar *)atom1->valuep, + (xmlChar *)atom2->valuep); + break; case XML_REGEXP_CHARVAL: - return(atom1->codepoint == atom2->codepoint); - case XML_REGEXP_RANGES: - TODO; - return(0); + ret = (atom1->codepoint == atom2->codepoint); + break; + case XML_REGEXP_RANGES: + /* too hard to do in the general case */ + ret = 0; default: break; } + return(ret); +} + +/** + * xmlFACompareAtoms: + * @atom1: an atom + * @atom2: an atom + * + * Compares two atoms to check whether they intersect in some ways, + * this is used by xmlFAComputesDeterminism and xmlFARecurseDeterminism only + * + * Returns 1 if yes and 0 otherwise + */ +static int +xmlFACompareAtoms(xmlRegAtomPtr atom1, xmlRegAtomPtr atom2) { + int ret = 1; + + if (atom1 == atom2) + return(1); + if ((atom1 == NULL) || (atom2 == NULL)) + return(0); + + if ((atom1->type == XML_REGEXP_ANYCHAR) || + (atom2->type == XML_REGEXP_ANYCHAR)) + return(1); + + if (atom1->type > atom2->type) { + xmlRegAtomPtr tmp; + tmp = atom1; + atom1 = atom2; + atom2 = tmp; + } + if (atom1->type != atom2->type) { + ret = xmlFACompareAtomTypes(atom1->type, atom2->type); + /* if they can't intersect at the type level break now */ + if (ret == 0) + return(0); + } + switch (atom1->type) { + case XML_REGEXP_STRING: + ret = xmlRegStrEqualWildcard((xmlChar *)atom1->valuep, + (xmlChar *)atom2->valuep); + break; + case XML_REGEXP_EPSILON: + goto not_determinist; + case XML_REGEXP_CHARVAL: + if (atom2->type == XML_REGEXP_CHARVAL) { + ret = (atom1->codepoint == atom2->codepoint); + } else { + ret = xmlRegCheckCharacter(atom2, atom1->codepoint); + if (ret < 0) + ret = 1; + } + break; + case XML_REGEXP_RANGES: + if (atom2->type == XML_REGEXP_RANGES) { + int i, j, res; + xmlRegRangePtr r1, r2; + + /* + * need to check that none of the ranges eventually matches + */ + for (i = 0;i < atom1->nbRanges;i++) { + for (j = 0;j < atom2->nbRanges;j++) { + r1 = atom1->ranges[i]; + r2 = atom2->ranges[j]; + res = xmlFACompareRanges(r1, r2); + if (res == 1) { + ret = 1; + goto done; + } + } + } + ret = 0; + } + break; + default: + goto not_determinist; + } +done: + if (atom1->neg != atom2->neg) { + ret = !ret; + } + if (ret == 0) + return(0); +not_determinist: return(1); } @@ -1758,12 +2407,18 @@ static int xmlFARecurseDeterminism(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state, int to, xmlRegAtomPtr atom) { int ret = 1; - int transnr; + int res; + int transnr, nbTrans; xmlRegTransPtr t1; if (state == NULL) return(ret); - for (transnr = 0;transnr < state->nbTrans;transnr++) { + /* + * don't recurse on transitions potentially added in the course of + * the elimination. + */ + nbTrans = state->nbTrans; + for (transnr = 0;transnr < nbTrans;transnr++) { t1 = &(state->trans[transnr]); /* * check transitions conflicting with the one looked at @@ -1771,16 +2426,21 @@ xmlFARecurseDeterminism(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr state, if (t1->atom == NULL) { if (t1->to == -1) continue; - ret = xmlFARecurseDeterminism(ctxt, ctxt->states[t1->to], + res = xmlFARecurseDeterminism(ctxt, ctxt->states[t1->to], to, atom); - if (ret == 0) - return(0); + if (res == 0) { + ret = 0; + /* t1->nd = 1; */ + } continue; } if (t1->to != to) continue; - if (xmlFACompareAtoms(t1->atom, atom)) - return(0); + if (xmlFACompareAtoms(t1->atom, atom)) { + ret = 0; + /* mark the transition as non-deterministic */ + t1->nd = 1; + } } return(ret); } @@ -1797,7 +2457,7 @@ static int xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt) { int statenr, transnr; xmlRegStatePtr state; - xmlRegTransPtr t1, t2; + xmlRegTransPtr t1, t2, last; int i; int ret = 1; @@ -1809,21 +2469,24 @@ xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt) { return(ctxt->determinist); /* - * Check for all states that there aren't 2 transitions - * with the same atom and a different target. + * First cleanup the automata removing cancelled transitions */ for (statenr = 0;statenr < ctxt->nbStates;statenr++) { state = ctxt->states[statenr]; if (state == NULL) continue; + if (state->nbTrans < 2) + continue; for (transnr = 0;transnr < state->nbTrans;transnr++) { t1 = &(state->trans[transnr]); /* * Determinism checks in case of counted or all transitions * will have to be handled separately */ - if (t1->atom == NULL) + if (t1->atom == NULL) { + /* t1->nd = 1; */ continue; + } if (t1->to == -1) /* eliminated */ continue; for (i = 0;i < transnr;i++) { @@ -1832,12 +2495,48 @@ xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt) { continue; if (t2->atom != NULL) { if (t1->to == t2->to) { - if (xmlFACompareAtoms(t1->atom, t2->atom)) + if (xmlFAEqualAtoms(t1->atom, t2->atom)) t2->to = -1; /* eliminated */ - } else { - /* not determinist ! */ - if (xmlFACompareAtoms(t1->atom, t2->atom)) - ret = 0; + } + } + } + } + } + + /* + * Check for all states that there aren't 2 transitions + * with the same atom and a different target. + */ + for (statenr = 0;statenr < ctxt->nbStates;statenr++) { + state = ctxt->states[statenr]; + if (state == NULL) + continue; + if (state->nbTrans < 2) + continue; + last = NULL; + for (transnr = 0;transnr < state->nbTrans;transnr++) { + t1 = &(state->trans[transnr]); + /* + * Determinism checks in case of counted or all transitions + * will have to be handled separately + */ + if (t1->atom == NULL) { + continue; + } + if (t1->to == -1) /* eliminated */ + continue; + for (i = 0;i < transnr;i++) { + t2 = &(state->trans[i]); + if (t2->to == -1) /* eliminated */ + continue; + if (t2->atom != NULL) { + /* not determinist ! */ + if (xmlFACompareAtoms(t1->atom, t2->atom)) { + ret = 0; + /* mark the transitions as non-deterministic ones */ + t1->nd = 1; + t2->nd = 1; + last = t1; } } else if (t1->to != -1) { /* @@ -1846,16 +2545,39 @@ xmlFAComputesDeterminism(xmlRegParserCtxtPtr ctxt) { */ ret = xmlFARecurseDeterminism(ctxt, ctxt->states[t1->to], t2->to, t2->atom); + /* don't shortcut the computation so all non deterministic + transition get marked down if (ret == 0) return(0); + */ + if (ret == 0) { + t1->nd = 1; + /* t2->nd = 1; */ + last = t1; + } } } + /* don't shortcut the computation so all non deterministic + transition get marked down if (ret == 0) - break; + break; */ } + + /* + * mark specifically the last non-deterministic transition + * from a state since there is no need to set-up rollback + * from it + */ + if (last != NULL) { + last->nd = 2; + } + + /* don't shortcut the computation so all non deterministic + transition get marked down if (ret == 0) - break; + break; */ } + ctxt->determinist = ret; return(ret); } @@ -2169,6 +2891,12 @@ xmlFARegExecSave(xmlRegExecCtxtPtr exec) { xmlFARegDebugExec(exec); exec->transno--; #endif +#ifdef MAX_PUSH + if (exec->nbPush > MAX_PUSH) { + return; + } + exec->nbPush++; +#endif if (exec->maxRollbacks == 0) { exec->maxRollbacks = 4; @@ -2255,10 +2983,11 @@ static int xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { xmlRegExecCtxt execval; xmlRegExecCtxtPtr exec = &execval; - int ret, codepoint = 0, len; + int ret, codepoint = 0, len, deter; exec->inputString = content; exec->index = 0; + exec->nbPush = 0; exec->determinist = 1; exec->maxRollbacks = 0; exec->nbRollbacks = 0; @@ -2292,6 +3021,7 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { * if we are working on a range like "AB{0,2}", where B is not present, * we don't want to break. */ + len = 1; if ((exec->inputString[exec->index] == 0) && (exec->counts == NULL)) { /* * if there is a transition, we must check if @@ -2315,10 +3045,15 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { continue; atom = trans->atom; ret = 0; + deter = 1; if (trans->count >= 0) { int count; xmlRegCounterPtr counter; + if (exec->counts == NULL) { + exec->status = -1; + goto error; + } /* * A counted transition. */ @@ -2330,6 +3065,8 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { trans->count, count, counter->min, counter->max); #endif ret = ((count >= counter->min) && (count <= counter->max)); + if ((ret) && (counter->min != counter->max)) + deter = 0; } else if (atom == NULL) { fprintf(stderr, "epsilon transition left at runtime\n"); exec->status = -2; @@ -2342,7 +3079,19 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { /* * this is a multiple input sequence + * If there is a counter associated increment it now. + * before potentially saving and rollback */ + if (trans->counter >= 0) { + if (exec->counts == NULL) { + exec->status = -1; + goto error; + } +#ifdef DEBUG_REGEXP_EXEC + printf("Increasing count %d\n", trans->counter); +#endif + exec->counts[trans->counter]++; + } if (exec->state->nbTrans > exec->transno + 1) { xmlFARegExecSave(exec); } @@ -2392,6 +3141,16 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { if (ret == 0) { goto rollback; } + if (trans->counter >= 0) { + if (exec->counts == NULL) { + exec->status = -1; + goto error; + } +#ifdef DEBUG_REGEXP_EXEC + printf("Decreasing count %d\n", trans->counter); +#endif + exec->counts[trans->counter]--; + } } else if ((ret == 0) && (atom->min == 0) && (atom->max > 0)) { /* * we don't match on the codepoint, but minOccurs of 0 @@ -2409,15 +3168,41 @@ xmlFARegExec(xmlRegexpPtr comp, const xmlChar *content) { ret = 1; } if (ret == 1) { - if (exec->state->nbTrans > exec->transno + 1) { + if ((trans->nd == 1) || + ((trans->count >= 0) && (deter == 0) && + (exec->state->nbTrans > exec->transno + 1))) { +#ifdef DEBUG_REGEXP_EXEC + if (trans->nd == 1) + printf("Saving on nd transition atom %d for %c at %d\n", + trans->atom->no, codepoint, exec->index); + else + printf("Saving on counted transition count %d for %c at %d\n", + trans->count, codepoint, exec->index); +#endif xmlFARegExecSave(exec); } if (trans->counter >= 0) { + if (exec->counts == NULL) { + exec->status = -1; + goto error; + } #ifdef DEBUG_REGEXP_EXEC printf("Increasing count %d\n", trans->counter); #endif exec->counts[trans->counter]++; } + if ((trans->count >= 0) && + (trans->count < REGEXP_ALL_COUNTER)) { + if (exec->counts == NULL) { + exec->status = -1; + goto error; + } +#ifdef DEBUG_REGEXP_EXEC + printf("resetting count %d on transition\n", + trans->count); +#endif + exec->counts[trans->count] = 0; + } #ifdef DEBUG_REGEXP_EXEC printf("entering state %d\n", trans->to); #endif @@ -2438,11 +3223,16 @@ rollback: * Failed to find a way out */ exec->determinist = 0; +#ifdef DEBUG_REGEXP_EXEC + printf("rollback from state %d on %d:%c\n", exec->state->no, + codepoint,codepoint); +#endif xmlFARegExecRollBack(exec); } progress: continue; } +error: if (exec->rollbacks != NULL) { if (exec->counts != NULL) { int i; @@ -2457,8 +3247,11 @@ progress: xmlFree(exec->counts); if (exec->status == 0) return(1); - if (exec->status == -1) + if (exec->status == -1) { + if (exec->nbPush > MAX_PUSH) + return(-1); return(0); + } return(exec->status); } @@ -2533,6 +3326,7 @@ xmlRegNewExecCtxt(xmlRegexpPtr comp, xmlRegExecCallbacks callback, void *data) { exec->inputStack = NULL; exec->errStateNo = -1; exec->errString = NULL; + exec->nbPush = 0; return(exec); } @@ -2631,18 +3425,26 @@ xmlRegStrEqualWildcard(const xmlChar *expStr, const xmlChar *valStr) { * Eval if we have a wildcard for the current item. */ if (*expStr != *valStr) { + /* if one of them starts with a wildcard make valStr be it */ + if (*valStr == '*') { + const xmlChar *tmp; + + tmp = valStr; + valStr = expStr; + expStr = tmp; + } if ((*valStr != 0) && (*expStr != 0) && (*expStr++ == '*')) { do { if (*valStr == XML_REG_STRING_SEPARATOR) break; - *valStr++; + valStr++; } while (*valStr != 0); continue; } else return(0); } - *expStr++; - *valStr++; + expStr++; + valStr++; } while (*valStr != 0); if (*expStr != 0) return (0); @@ -2734,19 +3536,20 @@ error: } /** - * xmlRegExecPushString: + * xmlRegExecPushStringInternal: * @exec: a regexp execution context or NULL to indicate the end * @value: a string token input * @data: data associated to the token to reuse in callbacks + * @compound: value was assembled from 2 strings * * Push one input token in the execution context * * Returns: 1 if the regexp reached a final state, 0 if non-final, and * a negative value in case of error. */ -int -xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, - void *data) { +static int +xmlRegExecPushStringInternal(xmlRegExecCtxtPtr exec, const xmlChar *value, + void *data, int compound) { xmlRegTransPtr trans; xmlRegAtomPtr atom; int ret; @@ -2836,6 +3639,7 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, } if ((count >= counter->min) && (count < counter->max) && + (t->atom != NULL) && (xmlStrEqual(value, t->atom->valuep))) { ret = 1; break; @@ -2888,6 +3692,11 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, break; } else if (value != NULL) { ret = xmlRegStrEqualWildcard(atom->valuep, value); + if (atom->neg) { + ret = !ret; + if (!compound) + ret = 0; + } if ((ret == 1) && (trans->counter >= 0)) { xmlRegCounterPtr counter; int count; @@ -2983,6 +3792,14 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, #endif exec->counts[trans->counter]++; } + if ((trans->count >= 0) && + (trans->count < REGEXP_ALL_COUNTER)) { +#ifdef DEBUG_REGEXP_EXEC + printf("resetting count %d on transition\n", + trans->count); +#endif + exec->counts[trans->count] = 0; + } #ifdef DEBUG_PUSH printf("entering state %d\n", trans->to); #endif @@ -3078,6 +3895,23 @@ progress: return(exec->status); } +/** + * xmlRegExecPushString: + * @exec: a regexp execution context or NULL to indicate the end + * @value: a string token input + * @data: data associated to the token to reuse in callbacks + * + * Push one input token in the execution context + * + * Returns: 1 if the regexp reached a final state, 0 if non-final, and + * a negative value in case of error. + */ +int +xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, + void *data) { + return(xmlRegExecPushStringInternal(exec, value, data, 0)); +} + /** * xmlRegExecPushString2: * @exec: a regexp execution context or NULL to indicate the end @@ -3127,15 +3961,15 @@ xmlRegExecPushString2(xmlRegExecCtxtPtr exec, const xmlChar *value, if (exec->comp->compact != NULL) ret = xmlRegCompactPushString(exec, exec->comp, str, data); else - ret = xmlRegExecPushString(exec, str, data); + ret = xmlRegExecPushStringInternal(exec, str, data, 1); if (str != buf) - xmlFree(buf); + xmlFree(str); return(ret); } /** - * xmlRegExecGetalues: + * xmlRegExecGetValues: * @exec: a regexp execution context * @err: error extraction or normal one * @nbval: pointer to the number of accepted values IN/OUT @@ -3235,23 +4069,30 @@ xmlRegExecGetValues(xmlRegExecCtxtPtr exec, int err, /* this should not be reached but ... */ TODO; } else if (trans->counter >= 0) { - xmlRegCounterPtr counter; + xmlRegCounterPtr counter = NULL; int count; if (err) count = exec->errCounts[trans->counter]; else count = exec->counts[trans->counter]; - counter = &exec->comp->counters[trans->counter]; - if (count < counter->max) { - values[nb++] = (xmlChar *) atom->valuep; + if (exec->comp != NULL) + counter = &exec->comp->counters[trans->counter]; + if ((counter == NULL) || (count < counter->max)) { + if (atom->neg) + values[nb++] = (xmlChar *) atom->valuep2; + else + values[nb++] = (xmlChar *) atom->valuep; (*nbval)++; } } else { if ((exec->comp->states[trans->to] != NULL) && (exec->comp->states[trans->to]->type != XML_REGEXP_SINK_STATE)) { - values[nb++] = (xmlChar *) atom->valuep; + if (atom->neg) + values[nb++] = (xmlChar *) atom->valuep2; + else + values[nb++] = (xmlChar *) atom->valuep; (*nbval)++; } } @@ -3275,7 +4116,10 @@ xmlRegExecGetValues(xmlRegExecCtxtPtr exec, int err, if ((exec->comp->states[trans->to] != NULL) && (exec->comp->states[trans->to]->type == XML_REGEXP_SINK_STATE)) { - values[nb++] = (xmlChar *) atom->valuep; + if (atom->neg) + values[nb++] = (xmlChar *) atom->valuep2; + else + values[nb++] = (xmlChar *) atom->valuep; (*nbneg)++; } } @@ -3466,6 +4310,15 @@ xmlRegExecPushChar(xmlRegExecCtxtPtr exec, int UCS) { if (exec->state->nbTrans > exec->transno + 1) { xmlFARegExecSave(exec); } + /* + * restart count for expressions like this ((abc){2})* + */ + if (trans->count >= 0) { +#ifdef DEBUG_REGEXP_EXEC + printf("Reset count %d\n", trans->count); +#endif + exec->counts[trans->count] = 0; + } if (trans->counter >= 0) { #ifdef DEBUG_REGEXP_EXEC printf("Increasing count %d\n", trans->counter); @@ -3813,8 +4666,21 @@ xmlFAParseCharClassEsc(xmlRegParserCtxtPtr ctxt) { (cur == 0x5E)) { if (ctxt->atom == NULL) { ctxt->atom = xmlRegNewAtom(ctxt, XML_REGEXP_CHARVAL); - if (ctxt->atom != NULL) - ctxt->atom->codepoint = cur; + if (ctxt->atom != NULL) { + switch (cur) { + case 'n': + ctxt->atom->codepoint = '\n'; + break; + case 'r': + ctxt->atom->codepoint = '\r'; + break; + case 't': + ctxt->atom->codepoint = '\t'; + break; + default: + ctxt->atom->codepoint = cur; + } + } } else if (ctxt->atom->type == XML_REGEXP_RANGES) { xmlRegAtomAddRange(ctxt, ctxt->atom, ctxt->neg, XML_REGEXP_CHARVAL, cur, cur, NULL); @@ -3889,6 +4755,7 @@ xmlFAParseCharRef(xmlRegParserCtxtPtr ctxt) { ((cur >= 'a') && (cur <= 'f')) || ((cur >= 'A') && (cur <= 'F'))) { while (((cur >= '0') && (cur <= '9')) || + ((cur >= 'a') && (cur <= 'f')) || ((cur >= 'A') && (cur <= 'F'))) { if ((cur >= '0') && (cur <= '9')) ret = ret * 16 + cur - '0'; @@ -4265,19 +5132,23 @@ xmlFAParsePiece(xmlRegParserCtxtPtr ctxt) { /** * xmlFAParseBranch: * @ctxt: a regexp parser context + * @to: optional target to the end of the branch + * + * @to is used to optimize by removing duplicate path in automata + * in expressions like (a|b)(c|d) * * [2] branch ::= piece* - 8 */ static int -xmlFAParseBranch(xmlRegParserCtxtPtr ctxt) { +xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) { xmlRegStatePtr previous; int ret; previous = ctxt->state; ret = xmlFAParsePiece(ctxt); if (ret != 0) { - if (xmlFAGenerateTransitions(ctxt, previous, NULL, ctxt->atom) < 0) + if (xmlFAGenerateTransitions(ctxt, previous, + (CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0) return(-1); previous = ctxt->state; ctxt->atom = NULL; @@ -4285,8 +5156,8 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt) { while ((ret != 0) && (ctxt->error == 0)) { ret = xmlFAParsePiece(ctxt); if (ret != 0) { - if (xmlFAGenerateTransitions(ctxt, previous, NULL, - ctxt->atom) < 0) + if (xmlFAGenerateTransitions(ctxt, previous, + (CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0) return(-1); previous = ctxt->state; ctxt->atom = NULL; @@ -4309,7 +5180,7 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) { /* if not top start should have been generated by an epsilon trans */ start = ctxt->state; ctxt->end = NULL; - xmlFAParseBranch(ctxt); + xmlFAParseBranch(ctxt, NULL); if (top) { #ifdef DEBUG_REGEXP_GRAPH printf("State %d is final\n", ctxt->state->no); @@ -4325,15 +5196,7 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) { NEXT; ctxt->state = start; ctxt->end = NULL; - xmlFAParseBranch(ctxt); - if (top) { - ctxt->state->type = XML_REGEXP_FINAL_STATE; -#ifdef DEBUG_REGEXP_GRAPH - printf("State %d is final\n", ctxt->state->no); -#endif - } else { - xmlFAGenerateEpsilonTransition(ctxt, ctxt->state, end); - } + xmlFAParseBranch(ctxt, end); } if (!top) { ctxt->state = end; @@ -4552,6 +5415,7 @@ xmlNewAutomata(void) { xmlFreeAutomata(ctxt); return(NULL); } + ctxt->start->type = XML_REGEXP_START_STATE; if (xmlRegStatePush(ctxt, ctxt->start) < 0) { xmlRegFreeState(ctxt->start); xmlFreeAutomata(ctxt); @@ -4669,9 +5533,9 @@ xmlAutomataNewTransition2(xmlAutomataPtr am, xmlAutomataStatePtr from, if ((am == NULL) || (from == NULL) || (token == NULL)) return(NULL); atom = xmlRegNewAtom(am, XML_REGEXP_STRING); - atom->data = data; if (atom == NULL) return(NULL); + atom->data = data; if ((token2 == NULL) || (*token2 == 0)) { atom->valuep = xmlStrdup(token); } else { @@ -4703,6 +5567,72 @@ xmlAutomataNewTransition2(xmlAutomataPtr am, xmlAutomataStatePtr from, return(to); } +/** + * xmlAutomataNewNegTrans: + * @am: an automata + * @from: the starting point of the transition + * @to: the target point of the transition or NULL + * @token: the first input string associated to that transition + * @token2: the second input string associated to that transition + * @data: data passed to the callback function if the transition is activated + * + * If @to is NULL, this creates first a new target state in the automata + * and then adds a transition from the @from state to the target state + * activated by any value except (@token,@token2) + * Note that if @token2 is not NULL, then (X, NULL) won't match to follow + # the semantic of XSD ##other + * + * Returns the target state or NULL in case of error + */ +xmlAutomataStatePtr +xmlAutomataNewNegTrans(xmlAutomataPtr am, xmlAutomataStatePtr from, + xmlAutomataStatePtr to, const xmlChar *token, + const xmlChar *token2, void *data) { + xmlRegAtomPtr atom; + xmlChar err_msg[200]; + + if ((am == NULL) || (from == NULL) || (token == NULL)) + return(NULL); + atom = xmlRegNewAtom(am, XML_REGEXP_STRING); + if (atom == NULL) + return(NULL); + atom->data = data; + atom->neg = 1; + if ((token2 == NULL) || (*token2 == 0)) { + atom->valuep = xmlStrdup(token); + } else { + int lenn, lenp; + xmlChar *str; + + lenn = strlen((char *) token2); + lenp = strlen((char *) token); + + str = (xmlChar *) xmlMallocAtomic(lenn + lenp + 2); + if (str == NULL) { + xmlRegFreeAtom(atom); + return(NULL); + } + memcpy(&str[0], token, lenp); + str[lenp] = '|'; + memcpy(&str[lenp + 1], token2, lenn); + str[lenn + lenp + 1] = 0; + + atom->valuep = str; + } + snprintf((char *) err_msg, 199, "not %s", (const char *) atom->valuep); + err_msg[199] = 0; + atom->valuep2 = xmlStrdup(err_msg); + + if (xmlFAGenerateTransitions(am, from, to, atom) < 0) { + xmlRegFreeAtom(atom); + return(NULL); + } + am->negs++; + if (to == NULL) + return(am->state); + return(to); +} + /** * xmlAutomataNewCountTrans2: * @am: an automata @@ -4916,10 +5846,7 @@ xmlAutomataNewOnceTrans2(xmlAutomataPtr am, xmlAutomataStatePtr from, } atom->data = data; atom->quant = XML_REGEXP_QUANT_ONCEONLY; - if (min == 0) - atom->min = 1; - else - atom->min = min; + atom->min = min; atom->max = max; /* * associate a counter to the transition. @@ -4978,10 +5905,7 @@ xmlAutomataNewOnceTrans(xmlAutomataPtr am, xmlAutomataStatePtr from, atom->valuep = xmlStrdup(token); atom->data = data; atom->quant = XML_REGEXP_QUANT_ONCEONLY; - if (min == 0) - atom->min = 1; - else - atom->min = min; + atom->min = min; atom->max = max; /* * associate a counter to the transition. @@ -5181,6 +6105,1850 @@ xmlAutomataIsDeterminist(xmlAutomataPtr am) { return(ret); } #endif /* LIBXML_AUTOMATA_ENABLED */ + +#ifdef LIBXML_EXPR_ENABLED +/************************************************************************ + * * + * Formal Expression handling code * + * * + ************************************************************************/ +/************************************************************************ + * * + * Expression handling context * + * * + ************************************************************************/ + +struct _xmlExpCtxt { + xmlDictPtr dict; + xmlExpNodePtr *table; + int size; + int nbElems; + int nb_nodes; + const char *expr; + const char *cur; + int nb_cons; + int tabSize; +}; + +/** + * xmlExpNewCtxt: + * @maxNodes: the maximum number of nodes + * @dict: optional dictionnary to use internally + * + * Creates a new context for manipulating expressions + * + * Returns the context or NULL in case of error + */ +xmlExpCtxtPtr +xmlExpNewCtxt(int maxNodes, xmlDictPtr dict) { + xmlExpCtxtPtr ret; + int size = 256; + + if (maxNodes <= 4096) + maxNodes = 4096; + + ret = (xmlExpCtxtPtr) xmlMalloc(sizeof(xmlExpCtxt)); + if (ret == NULL) + return(NULL); + memset(ret, 0, sizeof(xmlExpCtxt)); + ret->size = size; + ret->nbElems = 0; + ret->table = xmlMalloc(size * sizeof(xmlExpNodePtr)); + if (ret->table == NULL) { + xmlFree(ret); + return(NULL); + } + memset(ret->table, 0, size * sizeof(xmlExpNodePtr)); + if (dict == NULL) { + ret->dict = xmlDictCreate(); + if (ret->dict == NULL) { + xmlFree(ret->table); + xmlFree(ret); + return(NULL); + } + } else { + ret->dict = dict; + xmlDictReference(ret->dict); + } + return(ret); +} + +/** + * xmlExpFreeCtxt: + * @ctxt: an expression context + * + * Free an expression context + */ +void +xmlExpFreeCtxt(xmlExpCtxtPtr ctxt) { + if (ctxt == NULL) + return; + xmlDictFree(ctxt->dict); + if (ctxt->table != NULL) + xmlFree(ctxt->table); + xmlFree(ctxt); +} + +/************************************************************************ + * * + * Structure associated to an expression node * + * * + ************************************************************************/ +#define MAX_NODES 10000 + +/* #define DEBUG_DERIV */ + +/* + * TODO: + * - Wildcards + * - public API for creation + * + * Started + * - regression testing + * + * Done + * - split into module and test tool + * - memleaks + */ + +typedef enum { + XML_EXP_NILABLE = (1 << 0) +} xmlExpNodeInfo; + +#define IS_NILLABLE(node) ((node)->info & XML_EXP_NILABLE) + +struct _xmlExpNode { + unsigned char type;/* xmlExpNodeType */ + unsigned char info;/* OR of xmlExpNodeInfo */ + unsigned short key; /* the hash key */ + unsigned int ref; /* The number of references */ + int c_max; /* the maximum length it can consume */ + xmlExpNodePtr exp_left; + xmlExpNodePtr next;/* the next node in the hash table or free list */ + union { + struct { + int f_min; + int f_max; + } count; + struct { + xmlExpNodePtr f_right; + } children; + const xmlChar *f_str; + } field; +}; + +#define exp_min field.count.f_min +#define exp_max field.count.f_max +/* #define exp_left field.children.f_left */ +#define exp_right field.children.f_right +#define exp_str field.f_str + +static xmlExpNodePtr xmlExpNewNode(xmlExpCtxtPtr ctxt, xmlExpNodeType type); +static xmlExpNode forbiddenExpNode = { + XML_EXP_FORBID, 0, 0, 0, 0, NULL, NULL, {{ 0, 0}} +}; +xmlExpNodePtr forbiddenExp = &forbiddenExpNode; +static xmlExpNode emptyExpNode = { + XML_EXP_EMPTY, 1, 0, 0, 0, NULL, NULL, {{ 0, 0}} +}; +xmlExpNodePtr emptyExp = &emptyExpNode; + +/************************************************************************ + * * + * The custom hash table for unicity and canonicalization * + * of sub-expressions pointers * + * * + ************************************************************************/ +/* + * xmlExpHashNameComputeKey: + * Calculate the hash key for a token + */ +static unsigned short +xmlExpHashNameComputeKey(const xmlChar *name) { + unsigned short value = 0L; + char ch; + + if (name != NULL) { + value += 30 * (*name); + while ((ch = *name++) != 0) { + value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); + } + } + return (value); +} + +/* + * xmlExpHashComputeKey: + * Calculate the hash key for a compound expression + */ +static unsigned short +xmlExpHashComputeKey(xmlExpNodeType type, xmlExpNodePtr left, + xmlExpNodePtr right) { + unsigned long value; + unsigned short ret; + + switch (type) { + case XML_EXP_SEQ: + value = left->key; + value += right->key; + value *= 3; + ret = (unsigned short) value; + break; + case XML_EXP_OR: + value = left->key; + value += right->key; + value *= 7; + ret = (unsigned short) value; + break; + case XML_EXP_COUNT: + value = left->key; + value += right->key; + ret = (unsigned short) value; + break; + default: + ret = 0; + } + return(ret); +} + + +static xmlExpNodePtr +xmlExpNewNode(xmlExpCtxtPtr ctxt, xmlExpNodeType type) { + xmlExpNodePtr ret; + + if (ctxt->nb_nodes >= MAX_NODES) + return(NULL); + ret = (xmlExpNodePtr) xmlMalloc(sizeof(xmlExpNode)); + if (ret == NULL) + return(NULL); + memset(ret, 0, sizeof(xmlExpNode)); + ret->type = type; + ret->next = NULL; + ctxt->nb_nodes++; + ctxt->nb_cons++; + return(ret); +} + +/** + * xmlExpHashGetEntry: + * @table: the hash table + * + * Get the unique entry from the hash table. The entry is created if + * needed. @left and @right are consumed, i.e. their ref count will + * be decremented by the operation. + * + * Returns the pointer or NULL in case of error + */ +static xmlExpNodePtr +xmlExpHashGetEntry(xmlExpCtxtPtr ctxt, xmlExpNodeType type, + xmlExpNodePtr left, xmlExpNodePtr right, + const xmlChar *name, int min, int max) { + unsigned short kbase, key; + xmlExpNodePtr entry; + xmlExpNodePtr insert; + + if (ctxt == NULL) + return(NULL); + + /* + * Check for duplicate and insertion location. + */ + if (type == XML_EXP_ATOM) { + kbase = xmlExpHashNameComputeKey(name); + } else if (type == XML_EXP_COUNT) { + /* COUNT reduction rule 1 */ + /* a{1} -> a */ + if (min == max) { + if (min == 1) { + return(left); + } + if (min == 0) { + xmlExpFree(ctxt, left); + return(emptyExp); + } + } + if (min < 0) { + xmlExpFree(ctxt, left); + return(forbiddenExp); + } + if (max == -1) + kbase = min + 79; + else + kbase = max - min; + kbase += left->key; + } else if (type == XML_EXP_OR) { + /* Forbid reduction rules */ + if (left->type == XML_EXP_FORBID) { + xmlExpFree(ctxt, left); + return(right); + } + if (right->type == XML_EXP_FORBID) { + xmlExpFree(ctxt, right); + return(left); + } + + /* OR reduction rule 1 */ + /* a | a reduced to a */ + if (left == right) { + left->ref--; + return(left); + } + /* OR canonicalization rule 1 */ + /* linearize (a | b) | c into a | (b | c) */ + if ((left->type == XML_EXP_OR) && (right->type != XML_EXP_OR)) { + xmlExpNodePtr tmp = left; + left = right; + right = tmp; + } + /* OR reduction rule 2 */ + /* a | (a | b) and b | (a | b) are reduced to a | b */ + if (right->type == XML_EXP_OR) { + if ((left == right->exp_left) || + (left == right->exp_right)) { + xmlExpFree(ctxt, left); + return(right); + } + } + /* OR canonicalization rule 2 */ + /* linearize (a | b) | c into a | (b | c) */ + if (left->type == XML_EXP_OR) { + xmlExpNodePtr tmp; + + /* OR canonicalization rule 2 */ + if ((left->exp_right->type != XML_EXP_OR) && + (left->exp_right->key < left->exp_left->key)) { + tmp = left->exp_right; + left->exp_right = left->exp_left; + left->exp_left = tmp; + } + left->exp_right->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, left->exp_right, right, + NULL, 0, 0); + left->exp_left->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, left->exp_left, tmp, + NULL, 0, 0); + + xmlExpFree(ctxt, left); + return(tmp); + } + if (right->type == XML_EXP_OR) { + /* Ordering in the tree */ + /* C | (A | B) -> A | (B | C) */ + if (left->key > right->exp_right->key) { + xmlExpNodePtr tmp; + right->exp_right->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_right, + left, NULL, 0, 0); + right->exp_left->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_left, + tmp, NULL, 0, 0); + xmlExpFree(ctxt, right); + return(tmp); + } + /* Ordering in the tree */ + /* B | (A | C) -> A | (B | C) */ + if (left->key > right->exp_left->key) { + xmlExpNodePtr tmp; + right->exp_right->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, left, + right->exp_right, NULL, 0, 0); + right->exp_left->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_OR, right->exp_left, + tmp, NULL, 0, 0); + xmlExpFree(ctxt, right); + return(tmp); + } + } + /* we know both types are != XML_EXP_OR here */ + else if (left->key > right->key) { + xmlExpNodePtr tmp = left; + left = right; + right = tmp; + } + kbase = xmlExpHashComputeKey(type, left, right); + } else if (type == XML_EXP_SEQ) { + /* Forbid reduction rules */ + if (left->type == XML_EXP_FORBID) { + xmlExpFree(ctxt, right); + return(left); + } + if (right->type == XML_EXP_FORBID) { + xmlExpFree(ctxt, left); + return(right); + } + /* Empty reduction rules */ + if (right->type == XML_EXP_EMPTY) { + return(left); + } + if (left->type == XML_EXP_EMPTY) { + return(right); + } + kbase = xmlExpHashComputeKey(type, left, right); + } else + return(NULL); + + key = kbase % ctxt->size; + if (ctxt->table[key] != NULL) { + for (insert = ctxt->table[key]; insert != NULL; + insert = insert->next) { + if ((insert->key == kbase) && + (insert->type == type)) { + if (type == XML_EXP_ATOM) { + if (name == insert->exp_str) { + insert->ref++; + return(insert); + } + } else if (type == XML_EXP_COUNT) { + if ((insert->exp_min == min) && (insert->exp_max == max) && + (insert->exp_left == left)) { + insert->ref++; + left->ref--; + return(insert); + } + } else if ((insert->exp_left == left) && + (insert->exp_right == right)) { + insert->ref++; + left->ref--; + right->ref--; + return(insert); + } + } + } + } + + entry = xmlExpNewNode(ctxt, type); + if (entry == NULL) + return(NULL); + entry->key = kbase; + if (type == XML_EXP_ATOM) { + entry->exp_str = name; + entry->c_max = 1; + } else if (type == XML_EXP_COUNT) { + entry->exp_min = min; + entry->exp_max = max; + entry->exp_left = left; + if ((min == 0) || (IS_NILLABLE(left))) + entry->info |= XML_EXP_NILABLE; + if (max < 0) + entry->c_max = -1; + else + entry->c_max = max * entry->exp_left->c_max; + } else { + entry->exp_left = left; + entry->exp_right = right; + if (type == XML_EXP_OR) { + if ((IS_NILLABLE(left)) || (IS_NILLABLE(right))) + entry->info |= XML_EXP_NILABLE; + if ((entry->exp_left->c_max == -1) || + (entry->exp_right->c_max == -1)) + entry->c_max = -1; + else if (entry->exp_left->c_max > entry->exp_right->c_max) + entry->c_max = entry->exp_left->c_max; + else + entry->c_max = entry->exp_right->c_max; + } else { + if ((IS_NILLABLE(left)) && (IS_NILLABLE(right))) + entry->info |= XML_EXP_NILABLE; + if ((entry->exp_left->c_max == -1) || + (entry->exp_right->c_max == -1)) + entry->c_max = -1; + else + entry->c_max = entry->exp_left->c_max + entry->exp_right->c_max; + } + } + entry->ref = 1; + if (ctxt->table[key] != NULL) + entry->next = ctxt->table[key]; + + ctxt->table[key] = entry; + ctxt->nbElems++; + + return(entry); +} + +/** + * xmlExpFree: + * @ctxt: the expression context + * @exp: the expression + * + * Dereference the expression + */ +void +xmlExpFree(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp) { + if ((exp == NULL) || (exp == forbiddenExp) || (exp == emptyExp)) + return; + exp->ref--; + if (exp->ref == 0) { + unsigned short key; + + /* Unlink it first from the hash table */ + key = exp->key % ctxt->size; + if (ctxt->table[key] == exp) { + ctxt->table[key] = exp->next; + } else { + xmlExpNodePtr tmp; + + tmp = ctxt->table[key]; + while (tmp != NULL) { + if (tmp->next == exp) { + tmp->next = exp->next; + break; + } + tmp = tmp->next; + } + } + + if ((exp->type == XML_EXP_SEQ) || (exp->type == XML_EXP_OR)) { + xmlExpFree(ctxt, exp->exp_left); + xmlExpFree(ctxt, exp->exp_right); + } else if (exp->type == XML_EXP_COUNT) { + xmlExpFree(ctxt, exp->exp_left); + } + xmlFree(exp); + ctxt->nb_nodes--; + } +} + +/** + * xmlExpRef: + * @exp: the expression + * + * Increase the reference count of the expression + */ +void +xmlExpRef(xmlExpNodePtr exp) { + if (exp != NULL) + exp->ref++; +} + +/** + * xmlExpNewAtom: + * @ctxt: the expression context + * @name: the atom name + * @len: the atom name lenght in byte (or -1); + * + * Get the atom associated to this name from that context + * + * Returns the node or NULL in case of error + */ +xmlExpNodePtr +xmlExpNewAtom(xmlExpCtxtPtr ctxt, const xmlChar *name, int len) { + if ((ctxt == NULL) || (name == NULL)) + return(NULL); + name = xmlDictLookup(ctxt->dict, name, len); + if (name == NULL) + return(NULL); + return(xmlExpHashGetEntry(ctxt, XML_EXP_ATOM, NULL, NULL, name, 0, 0)); +} + +/** + * xmlExpNewOr: + * @ctxt: the expression context + * @left: left expression + * @right: right expression + * + * Get the atom associated to the choice @left | @right + * Note that @left and @right are consumed in the operation, to keep + * an handle on them use xmlExpRef() and use xmlExpFree() to release them, + * this is true even in case of failure (unless ctxt == NULL). + * + * Returns the node or NULL in case of error + */ +xmlExpNodePtr +xmlExpNewOr(xmlExpCtxtPtr ctxt, xmlExpNodePtr left, xmlExpNodePtr right) { + if (ctxt == NULL) + return(NULL); + if ((left == NULL) || (right == NULL)) { + xmlExpFree(ctxt, left); + xmlExpFree(ctxt, right); + return(NULL); + } + return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, left, right, NULL, 0, 0)); +} + +/** + * xmlExpNewSeq: + * @ctxt: the expression context + * @left: left expression + * @right: right expression + * + * Get the atom associated to the sequence @left , @right + * Note that @left and @right are consumed in the operation, to keep + * an handle on them use xmlExpRef() and use xmlExpFree() to release them, + * this is true even in case of failure (unless ctxt == NULL). + * + * Returns the node or NULL in case of error + */ +xmlExpNodePtr +xmlExpNewSeq(xmlExpCtxtPtr ctxt, xmlExpNodePtr left, xmlExpNodePtr right) { + if (ctxt == NULL) + return(NULL); + if ((left == NULL) || (right == NULL)) { + xmlExpFree(ctxt, left); + xmlExpFree(ctxt, right); + return(NULL); + } + return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, left, right, NULL, 0, 0)); +} + +/** + * xmlExpNewRange: + * @ctxt: the expression context + * @subset: the expression to be repeated + * @min: the lower bound for the repetition + * @max: the upper bound for the repetition, -1 means infinite + * + * Get the atom associated to the range (@subset){@min, @max} + * Note that @subset is consumed in the operation, to keep + * an handle on it use xmlExpRef() and use xmlExpFree() to release it, + * this is true even in case of failure (unless ctxt == NULL). + * + * Returns the node or NULL in case of error + */ +xmlExpNodePtr +xmlExpNewRange(xmlExpCtxtPtr ctxt, xmlExpNodePtr subset, int min, int max) { + if (ctxt == NULL) + return(NULL); + if ((subset == NULL) || (min < 0) || (max < -1) || + ((max >= 0) && (min > max))) { + xmlExpFree(ctxt, subset); + return(NULL); + } + return(xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, subset, + NULL, NULL, min, max)); +} + +/************************************************************************ + * * + * Public API for operations on expressions * + * * + ************************************************************************/ + +static int +xmlExpGetLanguageInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + const xmlChar**list, int len, int nb) { + int tmp, tmp2; +tail: + switch (exp->type) { + case XML_EXP_EMPTY: + return(0); + case XML_EXP_ATOM: + for (tmp = 0;tmp < nb;tmp++) + if (list[tmp] == exp->exp_str) + return(0); + if (nb >= len) + return(-2); + list[nb++] = exp->exp_str; + return(1); + case XML_EXP_COUNT: + exp = exp->exp_left; + goto tail; + case XML_EXP_SEQ: + case XML_EXP_OR: + tmp = xmlExpGetLanguageInt(ctxt, exp->exp_left, list, len, nb); + if (tmp < 0) + return(tmp); + tmp2 = xmlExpGetLanguageInt(ctxt, exp->exp_right, list, len, + nb + tmp); + if (tmp2 < 0) + return(tmp2); + return(tmp + tmp2); + } + return(-1); +} + +/** + * xmlExpGetLanguage: + * @ctxt: the expression context + * @exp: the expression + * @langList: where to store the tokens + * @len: the allocated lenght of @list + * + * Find all the strings used in @exp and store them in @list + * + * Returns the number of unique strings found, -1 in case of errors and + * -2 if there is more than @len strings + */ +int +xmlExpGetLanguage(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + const xmlChar**langList, int len) { + if ((ctxt == NULL) || (exp == NULL) || (langList == NULL) || (len <= 0)) + return(-1); + return(xmlExpGetLanguageInt(ctxt, exp, langList, len, 0)); +} + +static int +xmlExpGetStartInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + const xmlChar**list, int len, int nb) { + int tmp, tmp2; +tail: + switch (exp->type) { + case XML_EXP_FORBID: + return(0); + case XML_EXP_EMPTY: + return(0); + case XML_EXP_ATOM: + for (tmp = 0;tmp < nb;tmp++) + if (list[tmp] == exp->exp_str) + return(0); + if (nb >= len) + return(-2); + list[nb++] = exp->exp_str; + return(1); + case XML_EXP_COUNT: + exp = exp->exp_left; + goto tail; + case XML_EXP_SEQ: + tmp = xmlExpGetStartInt(ctxt, exp->exp_left, list, len, nb); + if (tmp < 0) + return(tmp); + if (IS_NILLABLE(exp->exp_left)) { + tmp2 = xmlExpGetStartInt(ctxt, exp->exp_right, list, len, + nb + tmp); + if (tmp2 < 0) + return(tmp2); + tmp += tmp2; + } + return(tmp); + case XML_EXP_OR: + tmp = xmlExpGetStartInt(ctxt, exp->exp_left, list, len, nb); + if (tmp < 0) + return(tmp); + tmp2 = xmlExpGetStartInt(ctxt, exp->exp_right, list, len, + nb + tmp); + if (tmp2 < 0) + return(tmp2); + return(tmp + tmp2); + } + return(-1); +} + +/** + * xmlExpGetStart: + * @ctxt: the expression context + * @exp: the expression + * @tokList: where to store the tokens + * @len: the allocated lenght of @list + * + * Find all the strings that appears at the start of the languages + * accepted by @exp and store them in @list. E.g. for (a, b) | c + * it will return the list [a, c] + * + * Returns the number of unique strings found, -1 in case of errors and + * -2 if there is more than @len strings + */ +int +xmlExpGetStart(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + const xmlChar**tokList, int len) { + if ((ctxt == NULL) || (exp == NULL) || (tokList == NULL) || (len <= 0)) + return(-1); + return(xmlExpGetStartInt(ctxt, exp, tokList, len, 0)); +} + +/** + * xmlExpIsNillable: + * @exp: the expression + * + * Finds if the expression is nillable, i.e. if it accepts the empty sequqnce + * + * Returns 1 if nillable, 0 if not and -1 in case of error + */ +int +xmlExpIsNillable(xmlExpNodePtr exp) { + if (exp == NULL) + return(-1); + return(IS_NILLABLE(exp) != 0); +} + +static xmlExpNodePtr +xmlExpStringDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, const xmlChar *str) +{ + xmlExpNodePtr ret; + + switch (exp->type) { + case XML_EXP_EMPTY: + return(forbiddenExp); + case XML_EXP_FORBID: + return(forbiddenExp); + case XML_EXP_ATOM: + if (exp->exp_str == str) { +#ifdef DEBUG_DERIV + printf("deriv atom: equal => Empty\n"); +#endif + ret = emptyExp; + } else { +#ifdef DEBUG_DERIV + printf("deriv atom: mismatch => forbid\n"); +#endif + /* TODO wildcards here */ + ret = forbiddenExp; + } + return(ret); + case XML_EXP_OR: { + xmlExpNodePtr tmp; + +#ifdef DEBUG_DERIV + printf("deriv or: => or(derivs)\n"); +#endif + tmp = xmlExpStringDeriveInt(ctxt, exp->exp_left, str); + if (tmp == NULL) { + return(NULL); + } + ret = xmlExpStringDeriveInt(ctxt, exp->exp_right, str); + if (ret == NULL) { + xmlExpFree(ctxt, tmp); + return(NULL); + } + ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, tmp, ret, + NULL, 0, 0); + return(ret); + } + case XML_EXP_SEQ: +#ifdef DEBUG_DERIV + printf("deriv seq: starting with left\n"); +#endif + ret = xmlExpStringDeriveInt(ctxt, exp->exp_left, str); + if (ret == NULL) { + return(NULL); + } else if (ret == forbiddenExp) { + if (IS_NILLABLE(exp->exp_left)) { +#ifdef DEBUG_DERIV + printf("deriv seq: left failed but nillable\n"); +#endif + ret = xmlExpStringDeriveInt(ctxt, exp->exp_right, str); + } + } else { +#ifdef DEBUG_DERIV + printf("deriv seq: left match => sequence\n"); +#endif + exp->exp_right->ref++; + ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, exp->exp_right, + NULL, 0, 0); + } + return(ret); + case XML_EXP_COUNT: { + int min, max; + xmlExpNodePtr tmp; + + if (exp->exp_max == 0) + return(forbiddenExp); + ret = xmlExpStringDeriveInt(ctxt, exp->exp_left, str); + if (ret == NULL) + return(NULL); + if (ret == forbiddenExp) { +#ifdef DEBUG_DERIV + printf("deriv count: pattern mismatch => forbid\n"); +#endif + return(ret); + } + if (exp->exp_max == 1) + return(ret); + if (exp->exp_max < 0) /* unbounded */ + max = -1; + else + max = exp->exp_max - 1; + if (exp->exp_min > 0) + min = exp->exp_min - 1; + else + min = 0; + exp->exp_left->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left, NULL, + NULL, min, max); + if (ret == emptyExp) { +#ifdef DEBUG_DERIV + printf("deriv count: match to empty => new count\n"); +#endif + return(tmp); + } +#ifdef DEBUG_DERIV + printf("deriv count: match => sequence with new count\n"); +#endif + return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, tmp, + NULL, 0, 0)); + } + } + return(NULL); +} + +/** + * xmlExpStringDerive: + * @ctxt: the expression context + * @exp: the expression + * @str: the string + * @len: the string len in bytes if available + * + * Do one step of Brzozowski derivation of the expression @exp with + * respect to the input string + * + * Returns the resulting expression or NULL in case of internal error + */ +xmlExpNodePtr +xmlExpStringDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + const xmlChar *str, int len) { + const xmlChar *input; + + if ((exp == NULL) || (ctxt == NULL) || (str == NULL)) { + return(NULL); + } + /* + * check the string is in the dictionnary, if yes use an interned + * copy, otherwise we know it's not an acceptable input + */ + input = xmlDictExists(ctxt->dict, str, len); + if (input == NULL) { + return(forbiddenExp); + } + return(xmlExpStringDeriveInt(ctxt, exp, input)); +} + +static int +xmlExpCheckCard(xmlExpNodePtr exp, xmlExpNodePtr sub) { + int ret = 1; + + if (sub->c_max == -1) { + if (exp->c_max != -1) + ret = 0; + } else if ((exp->c_max >= 0) && (exp->c_max < sub->c_max)) { + ret = 0; + } +#if 0 + if ((IS_NILLABLE(sub)) && (!IS_NILLABLE(exp))) + ret = 0; +#endif + return(ret); +} + +static xmlExpNodePtr xmlExpExpDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, + xmlExpNodePtr sub); +/** + * xmlExpDivide: + * @ctxt: the expressions context + * @exp: the englobing expression + * @sub: the subexpression + * @mult: the multiple expression + * @remain: the remain from the derivation of the multiple + * + * Check if exp is a multiple of sub, i.e. if there is a finite number n + * so that sub{n} subsume exp + * + * Returns the multiple value if successful, 0 if it is not a multiple + * and -1 in case of internel error. + */ + +static int +xmlExpDivide(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub, + xmlExpNodePtr *mult, xmlExpNodePtr *remain) { + int i; + xmlExpNodePtr tmp, tmp2; + + if (mult != NULL) *mult = NULL; + if (remain != NULL) *remain = NULL; + if (exp->c_max == -1) return(0); + if (IS_NILLABLE(exp) && (!IS_NILLABLE(sub))) return(0); + + for (i = 1;i <= exp->c_max;i++) { + sub->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, + sub, NULL, NULL, i, i); + if (tmp == NULL) { + return(-1); + } + if (!xmlExpCheckCard(tmp, exp)) { + xmlExpFree(ctxt, tmp); + continue; + } + tmp2 = xmlExpExpDeriveInt(ctxt, tmp, exp); + if (tmp2 == NULL) { + xmlExpFree(ctxt, tmp); + return(-1); + } + if ((tmp2 != forbiddenExp) && (IS_NILLABLE(tmp2))) { + if (remain != NULL) + *remain = tmp2; + else + xmlExpFree(ctxt, tmp2); + if (mult != NULL) + *mult = tmp; + else + xmlExpFree(ctxt, tmp); +#ifdef DEBUG_DERIV + printf("Divide succeeded %d\n", i); +#endif + return(i); + } + xmlExpFree(ctxt, tmp); + xmlExpFree(ctxt, tmp2); + } +#ifdef DEBUG_DERIV + printf("Divide failed\n"); +#endif + return(0); +} + +/** + * xmlExpExpDeriveInt: + * @ctxt: the expressions context + * @exp: the englobing expression + * @sub: the subexpression + * + * Try to do a step of Brzozowski derivation but at a higher level + * the input being a subexpression. + * + * Returns the resulting expression or NULL in case of internal error + */ +static xmlExpNodePtr +xmlExpExpDeriveInt(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) { + xmlExpNodePtr ret, tmp, tmp2, tmp3; + const xmlChar **tab; + int len, i; + + /* + * In case of equality and if the expression can only consume a finite + * amount, then the derivation is empty + */ + if ((exp == sub) && (exp->c_max >= 0)) { +#ifdef DEBUG_DERIV + printf("Equal(exp, sub) and finite -> Empty\n"); +#endif + return(emptyExp); + } + /* + * decompose sub sequence first + */ + if (sub->type == XML_EXP_EMPTY) { +#ifdef DEBUG_DERIV + printf("Empty(sub) -> Empty\n"); +#endif + exp->ref++; + return(exp); + } + if (sub->type == XML_EXP_SEQ) { +#ifdef DEBUG_DERIV + printf("Seq(sub) -> decompose\n"); +#endif + tmp = xmlExpExpDeriveInt(ctxt, exp, sub->exp_left); + if (tmp == NULL) + return(NULL); + if (tmp == forbiddenExp) + return(tmp); + ret = xmlExpExpDeriveInt(ctxt, tmp, sub->exp_right); + xmlExpFree(ctxt, tmp); + return(ret); + } + if (sub->type == XML_EXP_OR) { +#ifdef DEBUG_DERIV + printf("Or(sub) -> decompose\n"); +#endif + tmp = xmlExpExpDeriveInt(ctxt, exp, sub->exp_left); + if (tmp == forbiddenExp) + return(tmp); + if (tmp == NULL) + return(NULL); + ret = xmlExpExpDeriveInt(ctxt, exp, sub->exp_right); + if ((ret == NULL) || (ret == forbiddenExp)) { + xmlExpFree(ctxt, tmp); + return(ret); + } + return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, tmp, ret, NULL, 0, 0)); + } + if (!xmlExpCheckCard(exp, sub)) { +#ifdef DEBUG_DERIV + printf("CheckCard(exp, sub) failed -> Forbid\n"); +#endif + return(forbiddenExp); + } + switch (exp->type) { + case XML_EXP_EMPTY: + if (sub == emptyExp) + return(emptyExp); +#ifdef DEBUG_DERIV + printf("Empty(exp) -> Forbid\n"); +#endif + return(forbiddenExp); + case XML_EXP_FORBID: +#ifdef DEBUG_DERIV + printf("Forbid(exp) -> Forbid\n"); +#endif + return(forbiddenExp); + case XML_EXP_ATOM: + if (sub->type == XML_EXP_ATOM) { + /* TODO: handle wildcards */ + if (exp->exp_str == sub->exp_str) { +#ifdef DEBUG_DERIV + printf("Atom match -> Empty\n"); +#endif + return(emptyExp); + } +#ifdef DEBUG_DERIV + printf("Atom mismatch -> Forbid\n"); +#endif + return(forbiddenExp); + } + if ((sub->type == XML_EXP_COUNT) && + (sub->exp_max == 1) && + (sub->exp_left->type == XML_EXP_ATOM)) { + /* TODO: handle wildcards */ + if (exp->exp_str == sub->exp_left->exp_str) { +#ifdef DEBUG_DERIV + printf("Atom match -> Empty\n"); +#endif + return(emptyExp); + } +#ifdef DEBUG_DERIV + printf("Atom mismatch -> Forbid\n"); +#endif + return(forbiddenExp); + } +#ifdef DEBUG_DERIV + printf("Compex exp vs Atom -> Forbid\n"); +#endif + return(forbiddenExp); + case XML_EXP_SEQ: + /* try to get the sequence consumed only if possible */ + if (xmlExpCheckCard(exp->exp_left, sub)) { + /* See if the sequence can be consumed directly */ +#ifdef DEBUG_DERIV + printf("Seq trying left only\n"); +#endif + ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub); + if ((ret != forbiddenExp) && (ret != NULL)) { +#ifdef DEBUG_DERIV + printf("Seq trying left only worked\n"); +#endif + /* + * TODO: assumption here that we are determinist + * i.e. we won't get to a nillable exp left + * subset which could be matched by the right + * part too. + * e.g.: (a | b)+,(a | c) and 'a+,a' + */ + exp->exp_right->ref++; + return(xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, + exp->exp_right, NULL, 0, 0)); + } +#ifdef DEBUG_DERIV + } else { + printf("Seq: left too short\n"); +#endif + } + /* Try instead to decompose */ + if (sub->type == XML_EXP_COUNT) { + int min, max; + +#ifdef DEBUG_DERIV + printf("Seq: sub is a count\n"); +#endif + ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub->exp_left); + if (ret == NULL) + return(NULL); + if (ret != forbiddenExp) { +#ifdef DEBUG_DERIV + printf("Seq , Count match on left\n"); +#endif + if (sub->exp_max < 0) + max = -1; + else + max = sub->exp_max -1; + if (sub->exp_min > 0) + min = sub->exp_min -1; + else + min = 0; + exp->exp_right->ref++; + tmp = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, + exp->exp_right, NULL, 0, 0); + if (tmp == NULL) + return(NULL); + + sub->exp_left->ref++; + tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, + sub->exp_left, NULL, NULL, min, max); + if (tmp2 == NULL) { + xmlExpFree(ctxt, tmp); + return(NULL); + } + ret = xmlExpExpDeriveInt(ctxt, tmp, tmp2); + xmlExpFree(ctxt, tmp); + xmlExpFree(ctxt, tmp2); + return(ret); + } + } + /* we made no progress on structured operations */ + break; + case XML_EXP_OR: +#ifdef DEBUG_DERIV + printf("Or , trying both side\n"); +#endif + ret = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub); + if (ret == NULL) + return(NULL); + tmp = xmlExpExpDeriveInt(ctxt, exp->exp_right, sub); + if (tmp == NULL) { + xmlExpFree(ctxt, ret); + return(NULL); + } + return(xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, tmp, NULL, 0, 0)); + case XML_EXP_COUNT: { + int min, max; + + if (sub->type == XML_EXP_COUNT) { + /* + * Try to see if the loop is completely subsumed + */ + tmp = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub->exp_left); + if (tmp == NULL) + return(NULL); + if (tmp == forbiddenExp) { + int mult; + +#ifdef DEBUG_DERIV + printf("Count, Count inner don't subsume\n"); +#endif + mult = xmlExpDivide(ctxt, sub->exp_left, exp->exp_left, + NULL, &tmp); + if (mult <= 0) { +#ifdef DEBUG_DERIV + printf("Count, Count not multiple => forbidden\n"); +#endif + return(forbiddenExp); + } + if (sub->exp_max == -1) { + max = -1; + if (exp->exp_max == -1) { + if (exp->exp_min <= sub->exp_min * mult) + min = 0; + else + min = exp->exp_min - sub->exp_min * mult; + } else { +#ifdef DEBUG_DERIV + printf("Count, Count finite can't subsume infinite\n"); +#endif + xmlExpFree(ctxt, tmp); + return(forbiddenExp); + } + } else { + if (exp->exp_max == -1) { +#ifdef DEBUG_DERIV + printf("Infinite loop consume mult finite loop\n"); +#endif + if (exp->exp_min > sub->exp_min * mult) { + max = -1; + min = exp->exp_min - sub->exp_min * mult; + } else { + max = -1; + min = 0; + } + } else { + if (exp->exp_max < sub->exp_max * mult) { +#ifdef DEBUG_DERIV + printf("loops max mult mismatch => forbidden\n"); +#endif + xmlExpFree(ctxt, tmp); + return(forbiddenExp); + } + if (sub->exp_max * mult > exp->exp_min) + min = 0; + else + min = exp->exp_min - sub->exp_max * mult; + max = exp->exp_max - sub->exp_max * mult; + } + } + } else if (!IS_NILLABLE(tmp)) { + /* + * TODO: loop here to try to grow if working on finite + * blocks. + */ +#ifdef DEBUG_DERIV + printf("Count, Count remain not nillable => forbidden\n"); +#endif + xmlExpFree(ctxt, tmp); + return(forbiddenExp); + } else if (sub->exp_max == -1) { + if (exp->exp_max == -1) { + if (exp->exp_min <= sub->exp_min) { +#ifdef DEBUG_DERIV + printf("Infinite loops Okay => COUNT(0,Inf)\n"); +#endif + max = -1; + min = 0; + } else { +#ifdef DEBUG_DERIV + printf("Infinite loops min => Count(X,Inf)\n"); +#endif + max = -1; + min = exp->exp_min - sub->exp_min; + } + } else if (exp->exp_min > sub->exp_min) { +#ifdef DEBUG_DERIV + printf("loops min mismatch 1 => forbidden ???\n"); +#endif + xmlExpFree(ctxt, tmp); + return(forbiddenExp); + } else { + max = -1; + min = 0; + } + } else { + if (exp->exp_max == -1) { +#ifdef DEBUG_DERIV + printf("Infinite loop consume finite loop\n"); +#endif + if (exp->exp_min > sub->exp_min) { + max = -1; + min = exp->exp_min - sub->exp_min; + } else { + max = -1; + min = 0; + } + } else { + if (exp->exp_max < sub->exp_max) { +#ifdef DEBUG_DERIV + printf("loops max mismatch => forbidden\n"); +#endif + xmlExpFree(ctxt, tmp); + return(forbiddenExp); + } + if (sub->exp_max > exp->exp_min) + min = 0; + else + min = exp->exp_min - sub->exp_max; + max = exp->exp_max - sub->exp_max; + } + } +#ifdef DEBUG_DERIV + printf("loops match => SEQ(COUNT())\n"); +#endif + exp->exp_left->ref++; + tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left, + NULL, NULL, min, max); + if (tmp2 == NULL) { + return(NULL); + } + ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, tmp, tmp2, + NULL, 0, 0); + return(ret); + } + tmp = xmlExpExpDeriveInt(ctxt, exp->exp_left, sub); + if (tmp == NULL) + return(NULL); + if (tmp == forbiddenExp) { +#ifdef DEBUG_DERIV + printf("loop mismatch => forbidden\n"); +#endif + return(forbiddenExp); + } + if (exp->exp_min > 0) + min = exp->exp_min - 1; + else + min = 0; + if (exp->exp_max < 0) + max = -1; + else + max = exp->exp_max - 1; + +#ifdef DEBUG_DERIV + printf("loop match => SEQ(COUNT())\n"); +#endif + exp->exp_left->ref++; + tmp2 = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, exp->exp_left, + NULL, NULL, min, max); + if (tmp2 == NULL) + return(NULL); + ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, tmp, tmp2, + NULL, 0, 0); + return(ret); + } + } + +#ifdef DEBUG_DERIV + printf("Fallback to derivative\n"); +#endif + if (IS_NILLABLE(sub)) { + if (!(IS_NILLABLE(exp))) + return(forbiddenExp); + else + ret = emptyExp; + } else + ret = NULL; + /* + * here the structured derivation made no progress so + * we use the default token based derivation to force one more step + */ + if (ctxt->tabSize == 0) + ctxt->tabSize = 40; + + tab = (const xmlChar **) xmlMalloc(ctxt->tabSize * + sizeof(const xmlChar *)); + if (tab == NULL) { + return(NULL); + } + + /* + * collect all the strings accepted by the subexpression on input + */ + len = xmlExpGetStartInt(ctxt, sub, tab, ctxt->tabSize, 0); + while (len < 0) { + const xmlChar **temp; + temp = (const xmlChar **) xmlRealloc((xmlChar **) tab, ctxt->tabSize * 2 * + sizeof(const xmlChar *)); + if (temp == NULL) { + xmlFree((xmlChar **) tab); + return(NULL); + } + tab = temp; + ctxt->tabSize *= 2; + len = xmlExpGetStartInt(ctxt, sub, tab, ctxt->tabSize, 0); + } + for (i = 0;i < len;i++) { + tmp = xmlExpStringDeriveInt(ctxt, exp, tab[i]); + if ((tmp == NULL) || (tmp == forbiddenExp)) { + xmlExpFree(ctxt, ret); + xmlFree((xmlChar **) tab); + return(tmp); + } + tmp2 = xmlExpStringDeriveInt(ctxt, sub, tab[i]); + if ((tmp2 == NULL) || (tmp2 == forbiddenExp)) { + xmlExpFree(ctxt, tmp); + xmlExpFree(ctxt, ret); + xmlFree((xmlChar **) tab); + return(tmp); + } + tmp3 = xmlExpExpDeriveInt(ctxt, tmp, tmp2); + xmlExpFree(ctxt, tmp); + xmlExpFree(ctxt, tmp2); + + if ((tmp3 == NULL) || (tmp3 == forbiddenExp)) { + xmlExpFree(ctxt, ret); + xmlFree((xmlChar **) tab); + return(tmp3); + } + + if (ret == NULL) + ret = tmp3; + else { + ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, tmp3, NULL, 0, 0); + if (ret == NULL) { + xmlFree((xmlChar **) tab); + return(NULL); + } + } + } + xmlFree((xmlChar **) tab); + return(ret); +} + +/** + * xmlExpExpDerive: + * @ctxt: the expressions context + * @exp: the englobing expression + * @sub: the subexpression + * + * Evaluates the expression resulting from @exp consuming a sub expression @sub + * Based on algebraic derivation and sometimes direct Brzozowski derivation + * it usually tatkes less than linear time and can handle expressions generating + * infinite languages. + * + * Returns the resulting expression or NULL in case of internal error, the + * result must be freed + */ +xmlExpNodePtr +xmlExpExpDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) { + if ((exp == NULL) || (ctxt == NULL) || (sub == NULL)) + return(NULL); + + /* + * O(1) speedups + */ + if (IS_NILLABLE(sub) && (!IS_NILLABLE(exp))) { +#ifdef DEBUG_DERIV + printf("Sub nillable and not exp : can't subsume\n"); +#endif + return(forbiddenExp); + } + if (xmlExpCheckCard(exp, sub) == 0) { +#ifdef DEBUG_DERIV + printf("sub generate longuer sequances than exp : can't subsume\n"); +#endif + return(forbiddenExp); + } + return(xmlExpExpDeriveInt(ctxt, exp, sub)); +} + +/** + * xmlExpSubsume: + * @ctxt: the expressions context + * @exp: the englobing expression + * @sub: the subexpression + * + * Check whether @exp accepts all the languages accexpted by @sub + * the input being a subexpression. + * + * Returns 1 if true 0 if false and -1 in case of failure. + */ +int +xmlExpSubsume(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, xmlExpNodePtr sub) { + xmlExpNodePtr tmp; + + if ((exp == NULL) || (ctxt == NULL) || (sub == NULL)) + return(-1); + + /* + * TODO: speedup by checking the language of sub is a subset of the + * language of exp + */ + /* + * O(1) speedups + */ + if (IS_NILLABLE(sub) && (!IS_NILLABLE(exp))) { +#ifdef DEBUG_DERIV + printf("Sub nillable and not exp : can't subsume\n"); +#endif + return(0); + } + if (xmlExpCheckCard(exp, sub) == 0) { +#ifdef DEBUG_DERIV + printf("sub generate longuer sequances than exp : can't subsume\n"); +#endif + return(0); + } + tmp = xmlExpExpDeriveInt(ctxt, exp, sub); +#ifdef DEBUG_DERIV + printf("Result derivation :\n"); + PRINT_EXP(tmp); +#endif + if (tmp == NULL) + return(-1); + if (tmp == forbiddenExp) + return(0); + if (tmp == emptyExp) + return(1); + if ((tmp != NULL) && (IS_NILLABLE(tmp))) { + xmlExpFree(ctxt, tmp); + return(1); + } + xmlExpFree(ctxt, tmp); + return(0); +} + +/************************************************************************ + * * + * Parsing expression * + * * + ************************************************************************/ + +static xmlExpNodePtr xmlExpParseExpr(xmlExpCtxtPtr ctxt); + +#undef CUR +#define CUR (*ctxt->cur) +#undef NEXT +#define NEXT ctxt->cur++; +#undef IS_BLANK +#define IS_BLANK(c) ((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t')) +#define SKIP_BLANKS while (IS_BLANK(*ctxt->cur)) ctxt->cur++; + +static int +xmlExpParseNumber(xmlExpCtxtPtr ctxt) { + int ret = 0; + + SKIP_BLANKS + if (CUR == '*') { + NEXT + return(-1); + } + if ((CUR < '0') || (CUR > '9')) + return(-1); + while ((CUR >= '0') && (CUR <= '9')) { + ret = ret * 10 + (CUR - '0'); + NEXT + } + return(ret); +} + +static xmlExpNodePtr +xmlExpParseOr(xmlExpCtxtPtr ctxt) { + const char *base; + xmlExpNodePtr ret; + const xmlChar *val; + + SKIP_BLANKS + base = ctxt->cur; + if (*ctxt->cur == '(') { + NEXT + ret = xmlExpParseExpr(ctxt); + SKIP_BLANKS + if (*ctxt->cur != ')') { + fprintf(stderr, "unbalanced '(' : %s\n", base); + xmlExpFree(ctxt, ret); + return(NULL); + } + NEXT; + SKIP_BLANKS + goto parse_quantifier; + } + while ((CUR != 0) && (!(IS_BLANK(CUR))) && (CUR != '(') && + (CUR != ')') && (CUR != '|') && (CUR != ',') && (CUR != '{') && + (CUR != '*') && (CUR != '+') && (CUR != '?') && (CUR != '}')) + NEXT; + val = xmlDictLookup(ctxt->dict, BAD_CAST base, ctxt->cur - base); + if (val == NULL) + return(NULL); + ret = xmlExpHashGetEntry(ctxt, XML_EXP_ATOM, NULL, NULL, val, 0, 0); + if (ret == NULL) + return(NULL); + SKIP_BLANKS +parse_quantifier: + if (CUR == '{') { + int min, max; + + NEXT + min = xmlExpParseNumber(ctxt); + if (min < 0) { + xmlExpFree(ctxt, ret); + return(NULL); + } + SKIP_BLANKS + if (CUR == ',') { + NEXT + max = xmlExpParseNumber(ctxt); + SKIP_BLANKS + } else + max = min; + if (CUR != '}') { + xmlExpFree(ctxt, ret); + return(NULL); + } + NEXT + ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL, + min, max); + SKIP_BLANKS + } else if (CUR == '?') { + NEXT + ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL, + 0, 1); + SKIP_BLANKS + } else if (CUR == '+') { + NEXT + ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL, + 1, -1); + SKIP_BLANKS + } else if (CUR == '*') { + NEXT + ret = xmlExpHashGetEntry(ctxt, XML_EXP_COUNT, ret, NULL, NULL, + 0, -1); + SKIP_BLANKS + } + return(ret); +} + + +static xmlExpNodePtr +xmlExpParseSeq(xmlExpCtxtPtr ctxt) { + xmlExpNodePtr ret, right; + + ret = xmlExpParseOr(ctxt); + SKIP_BLANKS + while (CUR == '|') { + NEXT + right = xmlExpParseOr(ctxt); + if (right == NULL) { + xmlExpFree(ctxt, ret); + return(NULL); + } + ret = xmlExpHashGetEntry(ctxt, XML_EXP_OR, ret, right, NULL, 0, 0); + if (ret == NULL) + return(NULL); + } + return(ret); +} + +static xmlExpNodePtr +xmlExpParseExpr(xmlExpCtxtPtr ctxt) { + xmlExpNodePtr ret, right; + + ret = xmlExpParseSeq(ctxt); + SKIP_BLANKS + while (CUR == ',') { + NEXT + right = xmlExpParseSeq(ctxt); + if (right == NULL) { + xmlExpFree(ctxt, ret); + return(NULL); + } + ret = xmlExpHashGetEntry(ctxt, XML_EXP_SEQ, ret, right, NULL, 0, 0); + if (ret == NULL) + return(NULL); + } + return(ret); +} + +/** + * xmlExpParse: + * @ctxt: the expressions context + * @expr: the 0 terminated string + * + * Minimal parser for regexps, it understand the following constructs + * - string terminals + * - choice operator | + * - sequence operator , + * - subexpressions (...) + * - usual cardinality operators + * and ? + * - finite sequences { min, max } + * - infinite sequences { min, * } + * There is minimal checkings made especially no checking on strings values + * + * Returns a new expression or NULL in case of failure + */ +xmlExpNodePtr +xmlExpParse(xmlExpCtxtPtr ctxt, const char *expr) { + xmlExpNodePtr ret; + + ctxt->expr = expr; + ctxt->cur = expr; + + ret = xmlExpParseExpr(ctxt); + SKIP_BLANKS + if (*ctxt->cur != 0) { + xmlExpFree(ctxt, ret); + return(NULL); + } + return(ret); +} + +static void +xmlExpDumpInt(xmlBufferPtr buf, xmlExpNodePtr expr, int glob) { + xmlExpNodePtr c; + + if (expr == NULL) return; + if (glob) xmlBufferWriteChar(buf, "("); + switch (expr->type) { + case XML_EXP_EMPTY: + xmlBufferWriteChar(buf, "empty"); + break; + case XML_EXP_FORBID: + xmlBufferWriteChar(buf, "forbidden"); + break; + case XML_EXP_ATOM: + xmlBufferWriteCHAR(buf, expr->exp_str); + break; + case XML_EXP_SEQ: + c = expr->exp_left; + if ((c->type == XML_EXP_SEQ) || (c->type == XML_EXP_OR)) + xmlExpDumpInt(buf, c, 1); + else + xmlExpDumpInt(buf, c, 0); + xmlBufferWriteChar(buf, " , "); + c = expr->exp_right; + if ((c->type == XML_EXP_SEQ) || (c->type == XML_EXP_OR)) + xmlExpDumpInt(buf, c, 1); + else + xmlExpDumpInt(buf, c, 0); + break; + case XML_EXP_OR: + c = expr->exp_left; + if ((c->type == XML_EXP_SEQ) || (c->type == XML_EXP_OR)) + xmlExpDumpInt(buf, c, 1); + else + xmlExpDumpInt(buf, c, 0); + xmlBufferWriteChar(buf, " | "); + c = expr->exp_right; + if ((c->type == XML_EXP_SEQ) || (c->type == XML_EXP_OR)) + xmlExpDumpInt(buf, c, 1); + else + xmlExpDumpInt(buf, c, 0); + break; + case XML_EXP_COUNT: { + char rep[40]; + + c = expr->exp_left; + if ((c->type == XML_EXP_SEQ) || (c->type == XML_EXP_OR)) + xmlExpDumpInt(buf, c, 1); + else + xmlExpDumpInt(buf, c, 0); + if ((expr->exp_min == 0) && (expr->exp_max == 1)) { + rep[0] = '?'; + rep[1] = 0; + } else if ((expr->exp_min == 0) && (expr->exp_max == -1)) { + rep[0] = '*'; + rep[1] = 0; + } else if ((expr->exp_min == 1) && (expr->exp_max == -1)) { + rep[0] = '+'; + rep[1] = 0; + } else if (expr->exp_max == expr->exp_min) { + snprintf(rep, 39, "{%d}", expr->exp_min); + } else if (expr->exp_max < 0) { + snprintf(rep, 39, "{%d,inf}", expr->exp_min); + } else { + snprintf(rep, 39, "{%d,%d}", expr->exp_min, expr->exp_max); + } + rep[39] = 0; + xmlBufferWriteChar(buf, rep); + break; + } + default: + fprintf(stderr, "Error in tree\n"); + } + if (glob) + xmlBufferWriteChar(buf, ")"); +} +/** + * xmlExpDump: + * @buf: a buffer to receive the output + * @expr: the compiled expression + * + * Serialize the expression as compiled to the buffer + */ +void +xmlExpDump(xmlBufferPtr buf, xmlExpNodePtr expr) { + if ((buf == NULL) || (expr == NULL)) + return; + xmlExpDumpInt(buf, expr, 0); +} + +/** + * xmlExpMaxToken: + * @expr: a compiled expression + * + * Indicate the maximum number of input a expression can accept + * + * Returns the maximum length or -1 in case of error + */ +int +xmlExpMaxToken(xmlExpNodePtr expr) { + if (expr == NULL) + return(-1); + return(expr->c_max); +} + +/** + * xmlExpCtxtNbNodes: + * @ctxt: an expression context + * + * Debugging facility provides the number of allocated nodes at a that point + * + * Returns the number of nodes in use or -1 in case of error + */ +int +xmlExpCtxtNbNodes(xmlExpCtxtPtr ctxt) { + if (ctxt == NULL) + return(-1); + return(ctxt->nb_nodes); +} + +/** + * xmlExpCtxtNbCons: + * @ctxt: an expression context + * + * Debugging facility provides the number of allocated nodes over lifetime + * + * Returns the number of nodes ever allocated or -1 in case of error + */ +int +xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt) { + if (ctxt == NULL) + return(-1); + return(ctxt->nb_cons); +} + +#endif /* LIBXML_EXPR_ENABLED */ #define bottom_xmlregexp #include "elfgcchack.h" #endif /* LIBXML_REGEXP_ENABLED */ diff --git a/Extras/LibXML/xmlsave.c b/Extras/LibXML/xmlsave.c index e7a0cb220..ba35f3219 100644 --- a/Extras/LibXML/xmlsave.c +++ b/Extras/LibXML/xmlsave.c @@ -84,8 +84,8 @@ struct _xmlSaveCtxt { int level; int format; char indent[MAX_INDENT + 1]; /* array for indenting output */ - intptr_t indent_nr; - intptr_t indent_size; + int indent_nr; + int indent_size; xmlCharEncodingOutputFunc escape; /* used for element content */ xmlCharEncodingOutputFunc escapeAttr;/* used for attribute content */ }; @@ -200,9 +200,9 @@ xmlSerializeHexCharRef(unsigned char *out, int val) { * if the return value is positive, else unpredictable. * The value of @outlen after return is the number of octets consumed. */ -static intptr_t -xmlEscapeEntities(unsigned char* out, intptr_t* outlen, - const xmlChar* in, intptr_t* inlen) { +static int +xmlEscapeEntities(unsigned char* out, int *outlen, + const xmlChar* in, int *inlen) { unsigned char* outstart = out; const unsigned char* base = in; unsigned char* outend = out + *outlen; @@ -326,7 +326,8 @@ error: static void xmlSaveCtxtInit(xmlSaveCtxtPtr ctxt) { - intptr_t i, len; + int i; + int len; if (ctxt == NULL) return; if ((ctxt->encoding == NULL) && (ctxt->escape == NULL)) @@ -342,6 +343,10 @@ xmlSaveCtxtInit(xmlSaveCtxtPtr ctxt) ctxt->indent_size); ctxt->indent[ctxt->indent_nr * ctxt->indent_size] = 0; } + + if (xmlSaveNoEmptyTags) { + ctxt->options |= XML_SAVE_NO_EMPTY; + } } /** @@ -379,13 +384,6 @@ xmlNewSaveCtxt(const char *encoding, int options) } memset(ret, 0, sizeof(xmlSaveCtxt)); - /* - * Use the options - */ - ret->options = options; - if (options & XML_SAVE_FORMAT) - ret->format = 1; - if (encoding != NULL) { ret->handler = xmlFindCharEncodingHandler(encoding); if (ret->handler == NULL) { @@ -398,6 +396,19 @@ xmlNewSaveCtxt(const char *encoding, int options) } xmlSaveCtxtInit(ret); + /* + * Use the options + */ + + /* Re-check this option as it may already have been set */ + if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { + options |= XML_SAVE_NO_EMPTY; + } + + ret->options = options; + if (options & XML_SAVE_FORMAT) + ret->format = 1; + return(ret); } @@ -714,21 +725,26 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { return; } if (cur->type == XML_CDATA_SECTION_NODE) { - start = end = cur->content; - while (*end != '\0') { - if ((*end == ']') && (*(end + 1) == ']') && (*(end + 2) == '>')) { - end = end + 2; - xmlOutputBufferWrite(buf, 9, ""); - start = end; + if (cur->content == NULL) { + xmlOutputBufferWrite(buf, 12, ""); + } else { + start = end = cur->content; + while (*end != '\0') { + if ((*end == ']') && (*(end + 1) == ']') && + (*(end + 2) == '>')) { + end = end + 2; + xmlOutputBufferWrite(buf, 9, ""); + start = end; + } + end++; + } + if (start != end) { + xmlOutputBufferWrite(buf, 9, ""); } - end++; - } - if (start != end) { - xmlOutputBufferWrite(buf, 9, ""); } return; } @@ -767,7 +783,7 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { xmlAttrListDumpOutput(ctxt, cur->properties); if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) && - (cur->children == NULL) && (!xmlSaveNoEmptyTags)) { + (cur->children == NULL) && ((ctxt->options & XML_SAVE_NO_EMPTY) == 0)) { xmlOutputBufferWrite(buf, 2, "/>"); ctxt->format = format; return; @@ -820,43 +836,41 @@ xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur) { cur->encoding = BAD_CAST ctxt->encoding; buf = ctxt->buf; - xmlOutputBufferWrite(buf, 14, "version != NULL) - xmlBufferWriteQuotedString(buf->buffer, cur->version); - else - xmlOutputBufferWrite(buf, 5, "\"1.0\""); - if (ctxt->encoding == NULL) { - if (cur->encoding != NULL) - encoding = cur->encoding; - else if (cur->charset != XML_CHAR_ENCODING_UTF8) - encoding = (const xmlChar *) - xmlGetCharEncodingName((xmlCharEncoding) cur->charset); + if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { + xmlOutputBufferWrite(buf, 14, "version != NULL) + xmlBufferWriteQuotedString(buf->buffer, cur->version); + else + xmlOutputBufferWrite(buf, 5, "\"1.0\""); + if (ctxt->encoding == NULL) { + if (cur->encoding != NULL) + encoding = cur->encoding; + else if (cur->charset != XML_CHAR_ENCODING_UTF8) + encoding = (const xmlChar *) + xmlGetCharEncodingName((xmlCharEncoding) cur->charset); + } + if (encoding != NULL) { + xmlOutputBufferWrite(buf, 10, " encoding="); + xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); + } + switch (cur->standalone) { + case 0: + xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); + break; + case 1: + xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); + break; + } + xmlOutputBufferWrite(buf, 3, "?>\n"); } - if (encoding != NULL) { - xmlOutputBufferWrite(buf, 10, " encoding="); - xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); - } - switch (cur->standalone) { - case 0: - xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); - break; - case 1: - xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); - break; - } - xmlOutputBufferWrite(buf, 3, "?>\n"); #ifdef LIBXML_HTML_ENABLED - dtd = xmlGetIntSubset(cur); - if (dtd != NULL) { - is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); - if (is_xhtml < 0) is_xhtml = 0; - } - if (is_xhtml) { - if (encoding != NULL) - htmlSetMetaEncoding(cur, (const xmlChar *) ctxt->encoding); - else - htmlSetMetaEncoding(cur, BAD_CAST "UTF-8"); + if ((ctxt->options & XML_SAVE_NO_XHTML) == 0) { + dtd = xmlGetIntSubset(cur); + if (dtd != NULL) { + is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); + if (is_xhtml < 0) is_xhtml = 0; + } } #endif if (cur->children != NULL) { @@ -1078,12 +1092,17 @@ xhtmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { */ static void xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { - int format; + int format, addmeta = 0; xmlNodePtr tmp; xmlChar *start, *end; xmlOutputBufferPtr buf; if (cur == NULL) return; + if ((cur->type == XML_DOCUMENT_NODE) || + (cur->type == XML_HTML_DOCUMENT_NODE)) { + xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); + return; + } if (cur->type == XML_XINCLUDE_START) return; if (cur->type == XML_XINCLUDE_END) @@ -1092,6 +1111,10 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); return; } + if (cur->type == XML_DOCUMENT_FRAG_NODE) { + xhtmlNodeListDumpOutput(ctxt, cur->children); + return; + } buf = ctxt->buf; if (cur->type == XML_ELEMENT_DECL) { xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); @@ -1202,18 +1225,66 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { if (cur->properties != NULL) xhtmlAttrListDumpOutput(ctxt, cur->properties); + if ((cur->type == XML_ELEMENT_NODE) && + (cur->parent != NULL) && + (cur->parent->parent == (xmlNodePtr) cur->doc) && + xmlStrEqual(cur->name, BAD_CAST"head") && + xmlStrEqual(cur->parent->name, BAD_CAST"html")) { + + tmp = cur->children; + while (tmp != NULL) { + if (xmlStrEqual(tmp->name, BAD_CAST"meta")) { + xmlChar *httpequiv; + + httpequiv = xmlGetProp(tmp, BAD_CAST"http-equiv"); + if (httpequiv != NULL) { + if (xmlStrcasecmp(httpequiv, BAD_CAST"Content-Type") == 0) { + xmlFree(httpequiv); + break; + } + xmlFree(httpequiv); + } + } + tmp = tmp->next; + } + if (tmp == NULL) + addmeta = 1; + } + if ((cur->type == XML_ELEMENT_NODE) && (cur->children == NULL)) { if (((cur->ns == NULL) || (cur->ns->prefix == NULL)) && - (xhtmlIsEmpty(cur) == 1)) { + ((xhtmlIsEmpty(cur) == 1) && (addmeta == 0))) { /* * C.2. Empty Elements */ xmlOutputBufferWrite(buf, 3, " />"); } else { + if (addmeta == 1) { + xmlOutputBufferWrite(buf, 1, ">"); + if (ctxt->format) { + xmlOutputBufferWrite(buf, 1, "\n"); + if (xmlIndentTreeOutput) + xmlOutputBufferWrite(buf, ctxt->indent_size * + (ctxt->level + 1 > ctxt->indent_nr ? + ctxt->indent_nr : ctxt->level + 1), ctxt->indent); + } + xmlOutputBufferWriteString(buf, + ""); + if (ctxt->format) + xmlOutputBufferWrite(buf, 1, "\n"); + } else { + xmlOutputBufferWrite(buf, 1, ">"); + } /* * C.3. Element Minimization and Empty Element Content */ - xmlOutputBufferWrite(buf, 3, ">ns != NULL) && (cur->ns->prefix != NULL)) { xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); xmlOutputBufferWrite(buf, 1, ":"); @@ -1224,6 +1295,23 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { return; } xmlOutputBufferWrite(buf, 1, ">"); + if (addmeta == 1) { + if (ctxt->format) { + xmlOutputBufferWrite(buf, 1, "\n"); + if (xmlIndentTreeOutput) + xmlOutputBufferWrite(buf, ctxt->indent_size * + (ctxt->level + 1 > ctxt->indent_nr ? + ctxt->indent_nr : ctxt->level + 1), ctxt->indent); + } + xmlOutputBufferWriteString(buf, + ""); + } if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); } @@ -1239,25 +1327,26 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { xmlNodePtr child = cur->children; while (child != NULL) { - if ((child->type == XML_TEXT_NODE) || - (child->type == XML_CDATA_SECTION_NODE)) { - /* - * Apparently CDATA escaping for style just break on IE, - * mozilla and galeon, so ... - */ - if (xmlStrEqual(cur->name, BAD_CAST "style") && - (xmlStrchr(child->content, '<') == NULL) && - (xmlStrchr(child->content, '>') == NULL) && - (xmlStrchr(child->content, '&') == NULL)) { + if (child->type == XML_TEXT_NODE) { + if ((xmlStrchr(child->content, '<') == NULL) && + (xmlStrchr(child->content, '&') == NULL) && + (xmlStrstr(child->content, BAD_CAST "]]>") == NULL)) { + /* Nothing to escape, so just output as is... */ + /* FIXME: Should we do something about "--" also? */ int level = ctxt->level; int indent = ctxt->format; ctxt->level = 0; ctxt->format = 0; - xhtmlNodeDumpOutput(ctxt, child); + xmlOutputBufferWriteString(buf, (const char *) child->content); + /* (We cannot use xhtmlNodeDumpOutput() here because + * we wish to leave '>' unescaped!) */ ctxt->level = level; ctxt->format = indent; } else { + /* We must use a CDATA section. Unfortunately, + * this will break CSS and JavaScript when read by + * a browser in HTML4-compliant mode. :-( */ start = end = child->content; while (*end != '\0') { if (*end == ']' && @@ -1388,13 +1477,36 @@ xmlSaveToFilename(const char *filename, const char *encoding, int options) * with the encoding and the options given * * Returns a new serialization context or NULL in case of error. + */ + xmlSaveCtxtPtr xmlSaveToBuffer(xmlBufferPtr buffer, const char *encoding, int options) { - TODO - return(NULL); + xmlSaveCtxtPtr ret; + xmlOutputBufferPtr out_buff; + xmlCharEncodingHandlerPtr handler; + + ret = xmlNewSaveCtxt(encoding, options); + if (ret == NULL) return(NULL); + + if (encoding != NULL) { + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + xmlFree(ret); + return(NULL); + } + } else + handler = NULL; + out_buff = xmlOutputBufferCreateBuffer(buffer, handler); + if (out_buff == NULL) { + xmlFree(ret); + if (handler) xmlCharEncCloseFunc(handler); + return(NULL); + } + + ret->buf = out_buff; + return(ret); } - */ /** * xmlSaveToIO: @@ -1477,7 +1589,7 @@ xmlSaveTree(xmlSaveCtxtPtr ctxt, xmlNodePtr node) * * Returns the number of byte written or -1 in case of error. */ -intptr_t +int xmlSaveFlush(xmlSaveCtxtPtr ctxt) { if (ctxt == NULL) return(-1); @@ -1494,10 +1606,10 @@ xmlSaveFlush(xmlSaveCtxtPtr ctxt) * * Returns the number of byte written or -1 in case of error. */ -intptr_t +int xmlSaveClose(xmlSaveCtxtPtr ctxt) { - intptr_t ret; + int ret; if (ctxt == NULL) return(-1); ret = xmlSaveFlush(ctxt); @@ -1687,12 +1799,12 @@ xmlAttrSerializeTxtContent(xmlBufferPtr buf, xmlDocPtr doc, * * Returns the number of bytes written to the buffer or -1 in case of error */ -intptr_t +int xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, int format) { - size_t use; - intptr_t ret; + unsigned int use; + int ret; xmlOutputBufferPtr outbuf; xmlInitParser(); @@ -1716,7 +1828,7 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, xmlSaveErrMemory("creating buffer"); return (-1); } - memset(outbuf, 0, sizeof(xmlOutputBuffer)); + memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer)); outbuf->buffer = buf; outbuf->encoder = NULL; outbuf->writecallback = NULL; @@ -1728,7 +1840,7 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL); xmlFree(outbuf); ret = buf->use - use; - return ret; + return (ret); } /** @@ -1821,18 +1933,9 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, #ifdef LIBXML_HTML_ENABLED dtd = xmlGetIntSubset(doc); if (dtd != NULL) { - is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); - if (is_xhtml < 0) - is_xhtml = 0; - if ((is_xhtml) && (cur->parent == (xmlNodePtr) doc) && - (cur->type == XML_ELEMENT_NODE) && - (xmlStrEqual(cur->name, BAD_CAST "html"))) { - if (encoding != NULL) - htmlSetMetaEncoding((htmlDocPtr) doc, - (const xmlChar *) encoding); - else - htmlSetMetaEncoding((htmlDocPtr) doc, BAD_CAST "UTF-8"); - } + is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); + if (is_xhtml < 0) + is_xhtml = 0; } if (is_xhtml) @@ -1859,7 +1962,7 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, void xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - intptr_t * doc_txt_len, const char * txt_encoding, + int * doc_txt_len, const char * txt_encoding, int format) { xmlSaveCtxt ctxt; int dummy = 0; @@ -1978,7 +2081,7 @@ xmlDocDumpFormatMemory(xmlDocPtr cur, xmlChar**mem, int *size, int format) { void xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - intptr_t * doc_txt_len, const char * txt_encoding) { + int * doc_txt_len, const char * txt_encoding) { xmlDocDumpFormatMemoryEnc(out_doc, doc_txt_ptr, doc_txt_len, txt_encoding, 0); } @@ -1995,13 +2098,13 @@ xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 * or xmlKeepBlanksDefault(0) was called */ -intptr_t +int xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) { xmlSaveCtxt ctxt; xmlOutputBufferPtr buf; const char * encoding; xmlCharEncodingHandlerPtr handler = NULL; - intptr_t ret; + int ret; if (cur == NULL) { #ifdef DEBUG_TREE @@ -2043,7 +2146,7 @@ xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) { * * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlDocDump(FILE *f, xmlDocPtr cur) { return(xmlDocFormatDump (f, cur, 0)); } @@ -2060,10 +2163,10 @@ xmlDocDump(FILE *f, xmlDocPtr cur) { * * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlSaveFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding) { xmlSaveCtxt ctxt; - intptr_t ret; + int ret; if (buf == NULL) return(-1); if (cur == NULL) { @@ -2095,12 +2198,12 @@ xmlSaveFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding) { * * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding, int format) { xmlSaveCtxt ctxt; - intptr_t ret; + int ret; if (buf == NULL) return(-1); if ((cur == NULL) || @@ -2134,13 +2237,13 @@ xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 * or xmlKeepBlanksDefault(0) was called */ -intptr_t +int xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur, const char * encoding, int format ) { xmlSaveCtxt ctxt; xmlOutputBufferPtr buf; xmlCharEncodingHandlerPtr handler = NULL; - intptr_t ret; + int ret; if (cur == NULL) return(-1); @@ -2188,7 +2291,7 @@ xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur, * * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlSaveFileEnc(const char *filename, xmlDocPtr cur, const char *encoding) { return ( xmlSaveFormatFileEnc( filename, cur, encoding, 0 ) ); } @@ -2207,7 +2310,7 @@ xmlSaveFileEnc(const char *filename, xmlDocPtr cur, const char *encoding) { * * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format) { return ( xmlSaveFormatFileEnc( filename, cur, NULL, format ) ); } @@ -2222,7 +2325,7 @@ xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format) { * used. * returns: the number of bytes written or -1 in case of failure. */ -intptr_t +int xmlSaveFile(const char *filename, xmlDocPtr cur) { return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); } diff --git a/Extras/LibXML/xmlstring.c b/Extras/LibXML/xmlstring.c index 763753118..4f3b37391 100644 --- a/Extras/LibXML/xmlstring.c +++ b/Extras/LibXML/xmlstring.c @@ -38,7 +38,7 @@ * Returns a new xmlChar * or NULL */ xmlChar * -xmlStrndup(const xmlChar *cur, intptr_t len) { +xmlStrndup(const xmlChar *cur, int len) { xmlChar *ret; if ((cur == NULL) || (len < 0)) return(NULL); @@ -82,8 +82,8 @@ xmlStrdup(const xmlChar *cur) { */ xmlChar * -xmlCharStrndup(const char *cur, intptr_t len) { - intptr_t i; +xmlCharStrndup(const char *cur, int len) { + int i; xmlChar *ret; if ((cur == NULL) || (len < 0)) return(NULL); @@ -128,9 +128,9 @@ xmlCharStrdup(const char *cur) { * Returns the integer result of the comparison */ -intptr_t +int xmlStrcmp(const xmlChar *str1, const xmlChar *str2) { - register intptr_t tmp; + register int tmp; if (str1 == str2) return(0); if (str1 == NULL) return(-1); @@ -147,13 +147,13 @@ xmlStrcmp(const xmlChar *str1, const xmlChar *str2) { * @str1: the first xmlChar * * @str2: the second xmlChar * * - * Check if both string are equal of have same content - * Should be a bit more readable and faster than xmlStrEqual() + * Check if both strings are equal of have same content. + * Should be a bit more readable and faster than xmlStrcmp() * * Returns 1 if they are equal, 0 if they are different */ -intptr_t +int xmlStrEqual(const xmlChar *str1, const xmlChar *str2) { if (str1 == str2) return(1); if (str1 == NULL) return(0); @@ -175,7 +175,7 @@ xmlStrEqual(const xmlChar *str1, const xmlChar *str2) { * Returns 1 if they are equal, 0 if they are different */ -intptr_t +int xmlStrQEqual(const xmlChar *pref, const xmlChar *name, const xmlChar *str) { if (pref == NULL) return(xmlStrEqual(name, str)); if (name == NULL) return(0); @@ -202,9 +202,9 @@ xmlStrQEqual(const xmlChar *pref, const xmlChar *name, const xmlChar *str) { * Returns the integer result of the comparison */ -intptr_t -xmlStrncmp(const xmlChar *str1, const xmlChar *str2, intptr_t len) { - register intptr_t tmp; +int +xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len) { + register int tmp; if (len <= 0) return(0); if (str1 == str2) return(0); @@ -267,9 +267,9 @@ static const xmlChar casemap[256] = { * Returns the integer result of the comparison */ -intptr_t +int xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2) { - register intptr_t tmp; + register int tmp; if (str1 == str2) return(0); if (str1 == NULL) return(-1); @@ -292,9 +292,9 @@ xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2) { * Returns the integer result of the comparison */ -intptr_t -xmlStrncasecmp(const xmlChar *str1, const xmlChar *str2, intptr_t len) { - register intptr_t tmp; +int +xmlStrncasecmp(const xmlChar *str1, const xmlChar *str2, int len) { + register int tmp; if (len <= 0) return(0); if (str1 == str2) return(0); @@ -339,7 +339,7 @@ xmlStrchr(const xmlChar *str, xmlChar val) { const xmlChar * xmlStrstr(const xmlChar *str, const xmlChar *val) { - intptr_t n; + int n; if (str == NULL) return(NULL); if (val == NULL) return(NULL); @@ -367,7 +367,7 @@ xmlStrstr(const xmlChar *str, const xmlChar *val) { const xmlChar * xmlStrcasestr(const xmlChar *str, xmlChar *val) { - intptr_t n; + int n; if (str == NULL) return(NULL); if (val == NULL) return(NULL); @@ -394,8 +394,8 @@ xmlStrcasestr(const xmlChar *str, xmlChar *val) { */ xmlChar * -xmlStrsub(const xmlChar *str, intptr_t start, intptr_t len) { - intptr_t i; +xmlStrsub(const xmlChar *str, int start, int len) { + int i; if (str == NULL) return(NULL); if (start < 0) return(NULL); @@ -418,9 +418,9 @@ xmlStrsub(const xmlChar *str, intptr_t start, intptr_t len) { * Returns the number of xmlChar contained in the ARRAY. */ -intptr_t +int xmlStrlen(const xmlChar *str) { - intptr_t len = 0; + int len = 0; if (str == NULL) return(0); while (*str != 0) { /* non input consuming */ @@ -437,19 +437,22 @@ xmlStrlen(const xmlChar *str) { * @len: the length of @add * * a strncat for array of xmlChar's, it will extend @cur with the len - * first bytes of @add. + * first bytes of @add. Note that if @len < 0 then this is an API error + * and NULL will be returned. * * Returns a new xmlChar *, the original @cur is reallocated if needed * and should not be freed */ xmlChar * -xmlStrncat(xmlChar *cur, const xmlChar *add, intptr_t len) { - intptr_t size; +xmlStrncat(xmlChar *cur, const xmlChar *add, int len) { + int size; xmlChar *ret; if ((add == NULL) || (len == 0)) return(cur); + if (len < 0) + return(NULL); if (cur == NULL) return(xmlStrndup(add, len)); @@ -468,16 +471,17 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, intptr_t len) { * xmlStrncatNew: * @str1: first xmlChar string * @str2: second xmlChar string - * @len: the len of @str2 + * @len: the len of @str2 or < 0 * * same as xmlStrncat, but creates a new string. The original - * two strings are not freed. + * two strings are not freed. If @len is < 0 then the length + * will be calculated automatically. * * Returns a new xmlChar * or NULL */ xmlChar * -xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, intptr_t len) { - intptr_t size; +xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) { + int size; xmlChar *ret; if (len < 0) @@ -533,10 +537,10 @@ xmlStrcat(xmlChar *cur, const xmlChar *add) { * * Returns the number of characters written to @buf or -1 if an error occurs. */ -intptr_t -xmlStrPrintf(xmlChar *buf, intptr_t len, const xmlChar *msg, ...) { +int XMLCDECL +xmlStrPrintf(xmlChar *buf, int len, const xmlChar *msg, ...) { va_list args; - intptr_t ret; + int ret; if((buf == NULL) || (msg == NULL)) { return(-1); @@ -561,9 +565,9 @@ xmlStrPrintf(xmlChar *buf, intptr_t len, const xmlChar *msg, ...) { * * Returns the number of characters written to @buf or -1 if an error occurs. */ -intptr_t -xmlStrVPrintf(xmlChar *buf, intptr_t len, const xmlChar *msg, va_list ap) { - intptr_t ret; +int +xmlStrVPrintf(xmlChar *buf, int len, const xmlChar *msg, va_list ap) { + int ret; if((buf == NULL) || (msg == NULL)) { return(-1); @@ -599,10 +603,10 @@ xmlStrVPrintf(xmlChar *buf, intptr_t len, const xmlChar *msg, va_list ap) { * * returns the numbers of bytes in the character, -1 on format error */ -intptr_t +int xmlUTF8Size(const xmlChar *utf) { xmlChar mask; - intptr_t len; + int len; if (utf == NULL) return -1; @@ -630,7 +634,7 @@ xmlUTF8Size(const xmlChar *utf) { * * returns result of the compare as with xmlStrncmp */ -intptr_t +int xmlUTF8Charcmp(const xmlChar *utf1, const xmlChar *utf2) { if (utf1 == NULL ) { @@ -650,9 +654,9 @@ xmlUTF8Charcmp(const xmlChar *utf1, const xmlChar *utf2) { * * Returns the number of characters in the string or -1 in case of error */ -intptr_t +int xmlUTF8Strlen(const xmlChar *utf) { - intptr_t ret = 0; + int ret = 0; if (utf == NULL) return(-1); @@ -694,11 +698,16 @@ xmlUTF8Strlen(const xmlChar *utf) { * Returns the char value or -1 in case of error, and sets *len to * the actual number of bytes consumed (0 in case of error) */ -intptr_t -xmlGetUTF8Char(const unsigned char* utf, intptr_t* len) { - size_t c; +int +xmlGetUTF8Char(const unsigned char *utf, int *len) { + unsigned int c; - if (utf == NULL || len == NULL || *len < 1) goto error; + if (utf == NULL) + goto error; + if (len == NULL) + goto error; + if (*len < 1) + goto error; c = utf[0]; if (c & 0x80) { @@ -760,10 +769,10 @@ error: * * Return value: true if @utf is valid. **/ -intptr_t +int xmlCheckUTF8(const unsigned char *utf) { - intptr_t ix; + int ix; unsigned char c; if (utf == NULL) @@ -812,8 +821,8 @@ xmlCheckUTF8(const unsigned char *utf) * the first 'len' characters of ARRAY */ -intptr_t -xmlUTF8Strsize(const xmlChar *utf, intptr_t len) { +int +xmlUTF8Strsize(const xmlChar *utf, int len) { const xmlChar *ptr=utf; xmlChar ch; @@ -846,9 +855,9 @@ xmlUTF8Strsize(const xmlChar *utf, intptr_t len) { * Returns a new UTF8 * or NULL */ xmlChar * -xmlUTF8Strndup(const xmlChar *utf, intptr_t len) { +xmlUTF8Strndup(const xmlChar *utf, int len) { xmlChar *ret; - intptr_t i; + int i; if ((utf == NULL) || (len < 0)) return(NULL); i = xmlUTF8Strsize(utf, len); @@ -875,7 +884,7 @@ xmlUTF8Strndup(const xmlChar *utf, intptr_t len) { * Returns a pointer to the UTF8 character or NULL */ const xmlChar * -xmlUTF8Strpos(const xmlChar *utf, intptr_t pos) { +xmlUTF8Strpos(const xmlChar *utf, int pos) { xmlChar ch; if (utf == NULL) return(NULL); @@ -906,9 +915,9 @@ xmlUTF8Strpos(const xmlChar *utf, intptr_t pos) { * Returns the relative character position of the desired char * or -1 if not found */ -intptr_t +int xmlUTF8Strloc(const xmlChar *utf, const xmlChar *utfchar) { - intptr_t i, size; + int i, size; xmlChar ch; if (utf==NULL || utfchar==NULL) return -1; @@ -944,8 +953,8 @@ xmlUTF8Strloc(const xmlChar *utf, const xmlChar *utfchar) { */ xmlChar * -xmlUTF8Strsub(const xmlChar *utf, intptr_t start, intptr_t len) { - intptr_t i; +xmlUTF8Strsub(const xmlChar *utf, int start, int len) { + int i; xmlChar ch; if (utf == NULL) return(NULL); diff --git a/Extras/LibXML/xmlunicode.c b/Extras/LibXML/xmlunicode.c index af91f479c..450d0f093 100644 --- a/Extras/LibXML/xmlunicode.c +++ b/Extras/LibXML/xmlunicode.c @@ -3,11 +3,11 @@ * * This file is automatically generated from the * UCS description files of the Unicode Character Database - * http://www.unicode.org/Public/4.0-Update1/UCD-4.0.1d5b.html + * http://www.unicode.org/Public/4.0-Update1/UCD-4.0.1.html * using the genUnicode.py Python script. * - * Generation date: Mon Nov 10 22:35:10 2003 - * Sources: Blocks-4.0.1d1b.txt UnicodeData-4.0.1d1b.txt + * Generation date: Mon Mar 27 11:09:52 2006 + * Sources: Blocks-4.0.1.txt UnicodeData-4.0.1.txt * Daniel Veillard */ @@ -204,95 +204,95 @@ static xmlUnicodeRange xmlUnicodeCats[] = { {"Zp", xmlUCSIsCatZp}, {"Zs", xmlUCSIsCatZs}}; -static xmlChSRange xmlCS[] = {{0x0, 0x1f}, {0x7f, 0x9f}, {0xad, 0xad}, - {0x600, 0x603}, {0x6dd, 0x6dd}, {0x70f, 0x70f}, {0x17b4, 0x17b5}, - {0x200c, 0x200f}, {0x202a, 0x202e}, {0x2060, 0x2063}, {0x206a, 0x206f}, - {0xd800, 0xd800}, {0xdb7f, 0xdb80}, {0xdbff, 0xdc00}, {0xdfff, 0xe000}, - {0xf8ff, 0xf8ff}, {0xfeff, 0xfeff}, {0xfff9, 0xfffb} }; -static xmlChLRange xmlCL[] = {{0x1d173, 0x1d17a}, {0xe0001, 0xe0001}, +static const xmlChSRange xmlCS[] = {{0x0, 0x1f}, {0x7f, 0x9f}, + {0xad, 0xad}, {0x600, 0x603}, {0x6dd, 0x6dd}, {0x70f, 0x70f}, + {0x17b4, 0x17b5}, {0x200b, 0x200f}, {0x202a, 0x202e}, {0x2060, 0x2063}, + {0x206a, 0x206f}, {0xd800, 0xd800}, {0xdb7f, 0xdb80}, {0xdbff, 0xdc00}, + {0xdfff, 0xe000}, {0xf8ff, 0xf8ff}, {0xfeff, 0xfeff}, {0xfff9, 0xfffb} }; +static const xmlChLRange xmlCL[] = {{0x1d173, 0x1d17a}, {0xe0001, 0xe0001}, {0xe0020, 0xe007f}, {0xf0000, 0xf0000}, {0xffffd, 0xffffd}, {0x100000, 0x100000}, {0x10fffd, 0x10fffd} }; static xmlChRangeGroup xmlCG = {18,7,xmlCS,xmlCL}; -static xmlChSRange xmlCfS[] = {{0xad, 0xad}, {0x600, 0x603}, - {0x6dd, 0x6dd}, {0x70f, 0x70f}, {0x17b4, 0x17b5}, {0x200c, 0x200f}, +static const xmlChSRange xmlCfS[] = {{0xad, 0xad}, {0x600, 0x603}, + {0x6dd, 0x6dd}, {0x70f, 0x70f}, {0x17b4, 0x17b5}, {0x200b, 0x200f}, {0x202a, 0x202e}, {0x2060, 0x2063}, {0x206a, 0x206f}, {0xfeff, 0xfeff}, {0xfff9, 0xfffb} }; -static xmlChLRange xmlCfL[] = {{0x1d173, 0x1d17a}, {0xe0001, 0xe0001}, +static const xmlChLRange xmlCfL[] = {{0x1d173, 0x1d17a}, {0xe0001, 0xe0001}, {0xe0020, 0xe007f} }; static xmlChRangeGroup xmlCfG = {11,3,xmlCfS,xmlCfL}; -static xmlChSRange xmlLS[] = {{0x41, 0x5a}, {0x61, 0x7a}, {0xaa, 0xaa}, - {0xb5, 0xb5}, {0xba, 0xba}, {0xc0, 0xd6}, {0xd8, 0xf6}, {0xf8, 0x236}, - {0x250, 0x2c1}, {0x2c6, 0x2d1}, {0x2e0, 0x2e4}, {0x2ee, 0x2ee}, - {0x37a, 0x37a}, {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c}, - {0x38e, 0x3a1}, {0x3a3, 0x3ce}, {0x3d0, 0x3f5}, {0x3f7, 0x3fb}, - {0x400, 0x481}, {0x48a, 0x4ce}, {0x4d0, 0x4f5}, {0x4f8, 0x4f9}, - {0x500, 0x50f}, {0x531, 0x556}, {0x559, 0x559}, {0x561, 0x587}, - {0x5d0, 0x5ea}, {0x5f0, 0x5f2}, {0x621, 0x63a}, {0x640, 0x64a}, - {0x66e, 0x66f}, {0x671, 0x6d3}, {0x6d5, 0x6d5}, {0x6e5, 0x6e6}, - {0x6ee, 0x6ef}, {0x6fa, 0x6fc}, {0x6ff, 0x6ff}, {0x710, 0x710}, - {0x712, 0x72f}, {0x74d, 0x74f}, {0x780, 0x7a5}, {0x7b1, 0x7b1}, - {0x904, 0x939}, {0x93d, 0x93d}, {0x950, 0x950}, {0x958, 0x961}, - {0x985, 0x98c}, {0x98f, 0x990}, {0x993, 0x9a8}, {0x9aa, 0x9b0}, - {0x9b2, 0x9b2}, {0x9b6, 0x9b9}, {0x9bd, 0x9bd}, {0x9dc, 0x9dd}, - {0x9df, 0x9e1}, {0x9f0, 0x9f1}, {0xa05, 0xa0a}, {0xa0f, 0xa10}, - {0xa13, 0xa28}, {0xa2a, 0xa30}, {0xa32, 0xa33}, {0xa35, 0xa36}, - {0xa38, 0xa39}, {0xa59, 0xa5c}, {0xa5e, 0xa5e}, {0xa72, 0xa74}, - {0xa85, 0xa8d}, {0xa8f, 0xa91}, {0xa93, 0xaa8}, {0xaaa, 0xab0}, - {0xab2, 0xab3}, {0xab5, 0xab9}, {0xabd, 0xabd}, {0xad0, 0xad0}, - {0xae0, 0xae1}, {0xb05, 0xb0c}, {0xb0f, 0xb10}, {0xb13, 0xb28}, - {0xb2a, 0xb30}, {0xb32, 0xb33}, {0xb35, 0xb39}, {0xb3d, 0xb3d}, - {0xb5c, 0xb5d}, {0xb5f, 0xb61}, {0xb71, 0xb71}, {0xb83, 0xb83}, - {0xb85, 0xb8a}, {0xb8e, 0xb90}, {0xb92, 0xb95}, {0xb99, 0xb9a}, - {0xb9c, 0xb9c}, {0xb9e, 0xb9f}, {0xba3, 0xba4}, {0xba8, 0xbaa}, - {0xbae, 0xbb5}, {0xbb7, 0xbb9}, {0xc05, 0xc0c}, {0xc0e, 0xc10}, - {0xc12, 0xc28}, {0xc2a, 0xc33}, {0xc35, 0xc39}, {0xc60, 0xc61}, - {0xc85, 0xc8c}, {0xc8e, 0xc90}, {0xc92, 0xca8}, {0xcaa, 0xcb3}, - {0xcb5, 0xcb9}, {0xcbd, 0xcbd}, {0xcde, 0xcde}, {0xce0, 0xce1}, - {0xd05, 0xd0c}, {0xd0e, 0xd10}, {0xd12, 0xd28}, {0xd2a, 0xd39}, - {0xd60, 0xd61}, {0xd85, 0xd96}, {0xd9a, 0xdb1}, {0xdb3, 0xdbb}, - {0xdbd, 0xdbd}, {0xdc0, 0xdc6}, {0xe01, 0xe30}, {0xe32, 0xe33}, - {0xe40, 0xe46}, {0xe81, 0xe82}, {0xe84, 0xe84}, {0xe87, 0xe88}, - {0xe8a, 0xe8a}, {0xe8d, 0xe8d}, {0xe94, 0xe97}, {0xe99, 0xe9f}, - {0xea1, 0xea3}, {0xea5, 0xea5}, {0xea7, 0xea7}, {0xeaa, 0xeab}, - {0xead, 0xeb0}, {0xeb2, 0xeb3}, {0xebd, 0xebd}, {0xec0, 0xec4}, - {0xec6, 0xec6}, {0xedc, 0xedd}, {0xf00, 0xf00}, {0xf40, 0xf47}, - {0xf49, 0xf6a}, {0xf88, 0xf8b}, {0x1000, 0x1021}, {0x1023, 0x1027}, - {0x1029, 0x102a}, {0x1050, 0x1055}, {0x10a0, 0x10c5}, {0x10d0, 0x10f8}, - {0x1100, 0x1159}, {0x115f, 0x11a2}, {0x11a8, 0x11f9}, {0x1200, 0x1206}, - {0x1208, 0x1246}, {0x1248, 0x1248}, {0x124a, 0x124d}, {0x1250, 0x1256}, - {0x1258, 0x1258}, {0x125a, 0x125d}, {0x1260, 0x1286}, {0x1288, 0x1288}, - {0x128a, 0x128d}, {0x1290, 0x12ae}, {0x12b0, 0x12b0}, {0x12b2, 0x12b5}, - {0x12b8, 0x12be}, {0x12c0, 0x12c0}, {0x12c2, 0x12c5}, {0x12c8, 0x12ce}, - {0x12d0, 0x12d6}, {0x12d8, 0x12ee}, {0x12f0, 0x130e}, {0x1310, 0x1310}, - {0x1312, 0x1315}, {0x1318, 0x131e}, {0x1320, 0x1346}, {0x1348, 0x135a}, - {0x13a0, 0x13f4}, {0x1401, 0x166c}, {0x166f, 0x1676}, {0x1681, 0x169a}, - {0x16a0, 0x16ea}, {0x1700, 0x170c}, {0x170e, 0x1711}, {0x1720, 0x1731}, - {0x1740, 0x1751}, {0x1760, 0x176c}, {0x176e, 0x1770}, {0x1780, 0x17b3}, - {0x17d7, 0x17d7}, {0x17dc, 0x17dc}, {0x1820, 0x1877}, {0x1880, 0x18a8}, - {0x1900, 0x191c}, {0x1950, 0x196d}, {0x1970, 0x1974}, {0x1d00, 0x1d6b}, - {0x1e00, 0x1e9b}, {0x1ea0, 0x1ef9}, {0x1f00, 0x1f15}, {0x1f18, 0x1f1d}, - {0x1f20, 0x1f45}, {0x1f48, 0x1f4d}, {0x1f50, 0x1f57}, {0x1f59, 0x1f59}, - {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f7d}, {0x1f80, 0x1fb4}, - {0x1fb6, 0x1fbc}, {0x1fbe, 0x1fbe}, {0x1fc2, 0x1fc4}, {0x1fc6, 0x1fcc}, - {0x1fd0, 0x1fd3}, {0x1fd6, 0x1fdb}, {0x1fe0, 0x1fec}, {0x1ff2, 0x1ff4}, - {0x1ff6, 0x1ffc}, {0x2071, 0x2071}, {0x207f, 0x207f}, {0x2102, 0x2102}, - {0x2107, 0x2107}, {0x210a, 0x2113}, {0x2115, 0x2115}, {0x2119, 0x211d}, - {0x2124, 0x2124}, {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212a, 0x212d}, - {0x212f, 0x2131}, {0x2133, 0x2139}, {0x213d, 0x213f}, {0x2145, 0x2149}, - {0x3005, 0x3006}, {0x3031, 0x3035}, {0x303b, 0x303c}, {0x3041, 0x3096}, - {0x309d, 0x309f}, {0x30a1, 0x30fa}, {0x30fc, 0x30ff}, {0x3105, 0x312c}, - {0x3131, 0x318e}, {0x31a0, 0x31b7}, {0x31f0, 0x31ff}, {0x3400, 0x3400}, - {0x4db5, 0x4db5}, {0x4e00, 0x4e00}, {0x9fa5, 0x9fa5}, {0xa000, 0xa48c}, - {0xac00, 0xac00}, {0xd7a3, 0xd7a3}, {0xf900, 0xfa2d}, {0xfa30, 0xfa6a}, - {0xfb00, 0xfb06}, {0xfb13, 0xfb17}, {0xfb1d, 0xfb1d}, {0xfb1f, 0xfb28}, - {0xfb2a, 0xfb36}, {0xfb38, 0xfb3c}, {0xfb3e, 0xfb3e}, {0xfb40, 0xfb41}, - {0xfb43, 0xfb44}, {0xfb46, 0xfbb1}, {0xfbd3, 0xfd3d}, {0xfd50, 0xfd8f}, - {0xfd92, 0xfdc7}, {0xfdf0, 0xfdfb}, {0xfe70, 0xfe74}, {0xfe76, 0xfefc}, - {0xff21, 0xff3a}, {0xff41, 0xff5a}, {0xff66, 0xffbe}, {0xffc2, 0xffc7}, - {0xffca, 0xffcf}, {0xffd2, 0xffd7}, {0xffda, 0xffdc} }; -static xmlChLRange xmlLL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, +static const xmlChSRange xmlLS[] = {{0x41, 0x5a}, {0x61, 0x7a}, + {0xaa, 0xaa}, {0xb5, 0xb5}, {0xba, 0xba}, {0xc0, 0xd6}, {0xd8, 0xf6}, + {0xf8, 0x236}, {0x250, 0x2c1}, {0x2c6, 0x2d1}, {0x2e0, 0x2e4}, + {0x2ee, 0x2ee}, {0x37a, 0x37a}, {0x386, 0x386}, {0x388, 0x38a}, + {0x38c, 0x38c}, {0x38e, 0x3a1}, {0x3a3, 0x3ce}, {0x3d0, 0x3f5}, + {0x3f7, 0x3fb}, {0x400, 0x481}, {0x48a, 0x4ce}, {0x4d0, 0x4f5}, + {0x4f8, 0x4f9}, {0x500, 0x50f}, {0x531, 0x556}, {0x559, 0x559}, + {0x561, 0x587}, {0x5d0, 0x5ea}, {0x5f0, 0x5f2}, {0x621, 0x63a}, + {0x640, 0x64a}, {0x66e, 0x66f}, {0x671, 0x6d3}, {0x6d5, 0x6d5}, + {0x6e5, 0x6e6}, {0x6ee, 0x6ef}, {0x6fa, 0x6fc}, {0x6ff, 0x6ff}, + {0x710, 0x710}, {0x712, 0x72f}, {0x74d, 0x74f}, {0x780, 0x7a5}, + {0x7b1, 0x7b1}, {0x904, 0x939}, {0x93d, 0x93d}, {0x950, 0x950}, + {0x958, 0x961}, {0x985, 0x98c}, {0x98f, 0x990}, {0x993, 0x9a8}, + {0x9aa, 0x9b0}, {0x9b2, 0x9b2}, {0x9b6, 0x9b9}, {0x9bd, 0x9bd}, + {0x9dc, 0x9dd}, {0x9df, 0x9e1}, {0x9f0, 0x9f1}, {0xa05, 0xa0a}, + {0xa0f, 0xa10}, {0xa13, 0xa28}, {0xa2a, 0xa30}, {0xa32, 0xa33}, + {0xa35, 0xa36}, {0xa38, 0xa39}, {0xa59, 0xa5c}, {0xa5e, 0xa5e}, + {0xa72, 0xa74}, {0xa85, 0xa8d}, {0xa8f, 0xa91}, {0xa93, 0xaa8}, + {0xaaa, 0xab0}, {0xab2, 0xab3}, {0xab5, 0xab9}, {0xabd, 0xabd}, + {0xad0, 0xad0}, {0xae0, 0xae1}, {0xb05, 0xb0c}, {0xb0f, 0xb10}, + {0xb13, 0xb28}, {0xb2a, 0xb30}, {0xb32, 0xb33}, {0xb35, 0xb39}, + {0xb3d, 0xb3d}, {0xb5c, 0xb5d}, {0xb5f, 0xb61}, {0xb71, 0xb71}, + {0xb83, 0xb83}, {0xb85, 0xb8a}, {0xb8e, 0xb90}, {0xb92, 0xb95}, + {0xb99, 0xb9a}, {0xb9c, 0xb9c}, {0xb9e, 0xb9f}, {0xba3, 0xba4}, + {0xba8, 0xbaa}, {0xbae, 0xbb5}, {0xbb7, 0xbb9}, {0xc05, 0xc0c}, + {0xc0e, 0xc10}, {0xc12, 0xc28}, {0xc2a, 0xc33}, {0xc35, 0xc39}, + {0xc60, 0xc61}, {0xc85, 0xc8c}, {0xc8e, 0xc90}, {0xc92, 0xca8}, + {0xcaa, 0xcb3}, {0xcb5, 0xcb9}, {0xcbd, 0xcbd}, {0xcde, 0xcde}, + {0xce0, 0xce1}, {0xd05, 0xd0c}, {0xd0e, 0xd10}, {0xd12, 0xd28}, + {0xd2a, 0xd39}, {0xd60, 0xd61}, {0xd85, 0xd96}, {0xd9a, 0xdb1}, + {0xdb3, 0xdbb}, {0xdbd, 0xdbd}, {0xdc0, 0xdc6}, {0xe01, 0xe30}, + {0xe32, 0xe33}, {0xe40, 0xe46}, {0xe81, 0xe82}, {0xe84, 0xe84}, + {0xe87, 0xe88}, {0xe8a, 0xe8a}, {0xe8d, 0xe8d}, {0xe94, 0xe97}, + {0xe99, 0xe9f}, {0xea1, 0xea3}, {0xea5, 0xea5}, {0xea7, 0xea7}, + {0xeaa, 0xeab}, {0xead, 0xeb0}, {0xeb2, 0xeb3}, {0xebd, 0xebd}, + {0xec0, 0xec4}, {0xec6, 0xec6}, {0xedc, 0xedd}, {0xf00, 0xf00}, + {0xf40, 0xf47}, {0xf49, 0xf6a}, {0xf88, 0xf8b}, {0x1000, 0x1021}, + {0x1023, 0x1027}, {0x1029, 0x102a}, {0x1050, 0x1055}, {0x10a0, 0x10c5}, + {0x10d0, 0x10f8}, {0x1100, 0x1159}, {0x115f, 0x11a2}, {0x11a8, 0x11f9}, + {0x1200, 0x1206}, {0x1208, 0x1246}, {0x1248, 0x1248}, {0x124a, 0x124d}, + {0x1250, 0x1256}, {0x1258, 0x1258}, {0x125a, 0x125d}, {0x1260, 0x1286}, + {0x1288, 0x1288}, {0x128a, 0x128d}, {0x1290, 0x12ae}, {0x12b0, 0x12b0}, + {0x12b2, 0x12b5}, {0x12b8, 0x12be}, {0x12c0, 0x12c0}, {0x12c2, 0x12c5}, + {0x12c8, 0x12ce}, {0x12d0, 0x12d6}, {0x12d8, 0x12ee}, {0x12f0, 0x130e}, + {0x1310, 0x1310}, {0x1312, 0x1315}, {0x1318, 0x131e}, {0x1320, 0x1346}, + {0x1348, 0x135a}, {0x13a0, 0x13f4}, {0x1401, 0x166c}, {0x166f, 0x1676}, + {0x1681, 0x169a}, {0x16a0, 0x16ea}, {0x1700, 0x170c}, {0x170e, 0x1711}, + {0x1720, 0x1731}, {0x1740, 0x1751}, {0x1760, 0x176c}, {0x176e, 0x1770}, + {0x1780, 0x17b3}, {0x17d7, 0x17d7}, {0x17dc, 0x17dc}, {0x1820, 0x1877}, + {0x1880, 0x18a8}, {0x1900, 0x191c}, {0x1950, 0x196d}, {0x1970, 0x1974}, + {0x1d00, 0x1d6b}, {0x1e00, 0x1e9b}, {0x1ea0, 0x1ef9}, {0x1f00, 0x1f15}, + {0x1f18, 0x1f1d}, {0x1f20, 0x1f45}, {0x1f48, 0x1f4d}, {0x1f50, 0x1f57}, + {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f7d}, + {0x1f80, 0x1fb4}, {0x1fb6, 0x1fbc}, {0x1fbe, 0x1fbe}, {0x1fc2, 0x1fc4}, + {0x1fc6, 0x1fcc}, {0x1fd0, 0x1fd3}, {0x1fd6, 0x1fdb}, {0x1fe0, 0x1fec}, + {0x1ff2, 0x1ff4}, {0x1ff6, 0x1ffc}, {0x2071, 0x2071}, {0x207f, 0x207f}, + {0x2102, 0x2102}, {0x2107, 0x2107}, {0x210a, 0x2113}, {0x2115, 0x2115}, + {0x2119, 0x211d}, {0x2124, 0x2124}, {0x2126, 0x2126}, {0x2128, 0x2128}, + {0x212a, 0x212d}, {0x212f, 0x2131}, {0x2133, 0x2139}, {0x213d, 0x213f}, + {0x2145, 0x2149}, {0x3005, 0x3006}, {0x3031, 0x3035}, {0x303b, 0x303c}, + {0x3041, 0x3096}, {0x309d, 0x309f}, {0x30a1, 0x30fa}, {0x30fc, 0x30ff}, + {0x3105, 0x312c}, {0x3131, 0x318e}, {0x31a0, 0x31b7}, {0x31f0, 0x31ff}, + {0x3400, 0x3400}, {0x4db5, 0x4db5}, {0x4e00, 0x4e00}, {0x9fa5, 0x9fa5}, + {0xa000, 0xa48c}, {0xac00, 0xac00}, {0xd7a3, 0xd7a3}, {0xf900, 0xfa2d}, + {0xfa30, 0xfa6a}, {0xfb00, 0xfb06}, {0xfb13, 0xfb17}, {0xfb1d, 0xfb1d}, + {0xfb1f, 0xfb28}, {0xfb2a, 0xfb36}, {0xfb38, 0xfb3c}, {0xfb3e, 0xfb3e}, + {0xfb40, 0xfb41}, {0xfb43, 0xfb44}, {0xfb46, 0xfbb1}, {0xfbd3, 0xfd3d}, + {0xfd50, 0xfd8f}, {0xfd92, 0xfdc7}, {0xfdf0, 0xfdfb}, {0xfe70, 0xfe74}, + {0xfe76, 0xfefc}, {0xff21, 0xff3a}, {0xff41, 0xff5a}, {0xff66, 0xffbe}, + {0xffc2, 0xffc7}, {0xffca, 0xffcf}, {0xffd2, 0xffd7}, {0xffda, 0xffdc} }; +static const xmlChLRange xmlLL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, {0x10028, 0x1003a}, {0x1003c, 0x1003d}, {0x1003f, 0x1004d}, {0x10050, 0x1005d}, {0x10080, 0x100fa}, {0x10300, 0x1031e}, {0x10330, 0x10349}, {0x10380, 0x1039d}, {0x10400, 0x1049d}, @@ -311,8 +311,8 @@ static xmlChLRange xmlLL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, {0x20000, 0x20000}, {0x2a6d6, 0x2a6d6}, {0x2f800, 0x2fa1d} }; static xmlChRangeGroup xmlLG = {279,50,xmlLS,xmlLL}; -static xmlChSRange xmlLlS[] = {{0x61, 0x7a}, {0xaa, 0xaa}, {0xb5, 0xb5}, - {0xba, 0xba}, {0xdf, 0xf6}, {0xf8, 0xff}, {0x101, 0x101}, +static const xmlChSRange xmlLlS[] = {{0x61, 0x7a}, {0xaa, 0xaa}, + {0xb5, 0xb5}, {0xba, 0xba}, {0xdf, 0xf6}, {0xf8, 0xff}, {0x101, 0x101}, {0x103, 0x103}, {0x105, 0x105}, {0x107, 0x107}, {0x109, 0x109}, {0x10b, 0x10b}, {0x10d, 0x10d}, {0x10f, 0x10f}, {0x111, 0x111}, {0x113, 0x113}, {0x115, 0x115}, {0x117, 0x117}, {0x119, 0x119}, @@ -411,7 +411,7 @@ static xmlChSRange xmlLlS[] = {{0x61, 0x7a}, {0xaa, 0xaa}, {0xb5, 0xb5}, {0x2113, 0x2113}, {0x212f, 0x212f}, {0x2134, 0x2134}, {0x2139, 0x2139}, {0x213d, 0x213d}, {0x2146, 0x2149}, {0xfb00, 0xfb06}, {0xfb13, 0xfb17}, {0xff41, 0xff5a} }; -static xmlChLRange xmlLlL[] = {{0x10428, 0x1044f}, {0x1d41a, 0x1d433}, +static const xmlChLRange xmlLlL[] = {{0x10428, 0x1044f}, {0x1d41a, 0x1d433}, {0x1d44e, 0x1d454}, {0x1d456, 0x1d467}, {0x1d482, 0x1d49b}, {0x1d4b6, 0x1d4b9}, {0x1d4bb, 0x1d4bb}, {0x1d4bd, 0x1d4c3}, {0x1d4c5, 0x1d4cf}, {0x1d4ea, 0x1d503}, {0x1d51e, 0x1d537}, @@ -423,7 +423,7 @@ static xmlChLRange xmlLlL[] = {{0x10428, 0x1044f}, {0x1d41a, 0x1d433}, {0x1d7aa, 0x1d7c2}, {0x1d7c4, 0x1d7c9} }; static xmlChRangeGroup xmlLlG = {396,28,xmlLlS,xmlLlL}; -static xmlChSRange xmlLmS[] = {{0x2b0, 0x2c1}, {0x2c6, 0x2d1}, +static const xmlChSRange xmlLmS[] = {{0x2b0, 0x2c1}, {0x2c6, 0x2d1}, {0x2e0, 0x2e4}, {0x2ee, 0x2ee}, {0x37a, 0x37a}, {0x559, 0x559}, {0x640, 0x640}, {0x6e5, 0x6e6}, {0xe46, 0xe46}, {0xec6, 0xec6}, {0x17d7, 0x17d7}, {0x1843, 0x1843}, {0x1d2c, 0x1d61}, {0x3005, 0x3005}, @@ -431,7 +431,7 @@ static xmlChSRange xmlLmS[] = {{0x2b0, 0x2c1}, {0x2c6, 0x2d1}, {0xff70, 0xff70}, {0xff9e, 0xff9f} }; static xmlChRangeGroup xmlLmG = {20,0,xmlLmS,NULL}; -static xmlChSRange xmlLoS[] = {{0x1bb, 0x1bb}, {0x1c0, 0x1c3}, +static const xmlChSRange xmlLoS[] = {{0x1bb, 0x1bb}, {0x1c0, 0x1c3}, {0x5d0, 0x5ea}, {0x5f0, 0x5f2}, {0x621, 0x63a}, {0x641, 0x64a}, {0x66e, 0x66f}, {0x671, 0x6d3}, {0x6d5, 0x6d5}, {0x6ee, 0x6ef}, {0x6fa, 0x6fc}, {0x6ff, 0x6ff}, {0x710, 0x710}, {0x712, 0x72f}, @@ -485,7 +485,7 @@ static xmlChSRange xmlLoS[] = {{0x1bb, 0x1bb}, {0x1c0, 0x1c3}, {0xfe70, 0xfe74}, {0xfe76, 0xfefc}, {0xff66, 0xff6f}, {0xff71, 0xff9d}, {0xffa0, 0xffbe}, {0xffc2, 0xffc7}, {0xffca, 0xffcf}, {0xffd2, 0xffd7}, {0xffda, 0xffdc} }; -static xmlChLRange xmlLoL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, +static const xmlChLRange xmlLoL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, {0x10028, 0x1003a}, {0x1003c, 0x1003d}, {0x1003f, 0x1004d}, {0x10050, 0x1005d}, {0x10080, 0x100fa}, {0x10300, 0x1031e}, {0x10330, 0x10349}, {0x10380, 0x1039d}, {0x10450, 0x1049d}, @@ -494,110 +494,110 @@ static xmlChLRange xmlLoL[] = {{0x10000, 0x1000b}, {0x1000d, 0x10026}, {0x20000, 0x20000}, {0x2a6d6, 0x2a6d6}, {0x2f800, 0x2fa1d} }; static xmlChRangeGroup xmlLoG = {211,20,xmlLoS,xmlLoL}; -static xmlChSRange xmlLtS[] = {{0x1c5, 0x1c5}, {0x1c8, 0x1c8}, +static const xmlChSRange xmlLtS[] = {{0x1c5, 0x1c5}, {0x1c8, 0x1c8}, {0x1cb, 0x1cb}, {0x1f2, 0x1f2}, {0x1f88, 0x1f8f}, {0x1f98, 0x1f9f}, {0x1fa8, 0x1faf}, {0x1fbc, 0x1fbc}, {0x1fcc, 0x1fcc}, {0x1ffc, 0x1ffc} }; static xmlChRangeGroup xmlLtG = {10,0,xmlLtS,NULL}; -static xmlChSRange xmlLuS[] = {{0x41, 0x5a}, {0xc0, 0xd6}, {0xd8, 0xde}, - {0x100, 0x100}, {0x102, 0x102}, {0x104, 0x104}, {0x106, 0x106}, - {0x108, 0x108}, {0x10a, 0x10a}, {0x10c, 0x10c}, {0x10e, 0x10e}, - {0x110, 0x110}, {0x112, 0x112}, {0x114, 0x114}, {0x116, 0x116}, - {0x118, 0x118}, {0x11a, 0x11a}, {0x11c, 0x11c}, {0x11e, 0x11e}, - {0x120, 0x120}, {0x122, 0x122}, {0x124, 0x124}, {0x126, 0x126}, - {0x128, 0x128}, {0x12a, 0x12a}, {0x12c, 0x12c}, {0x12e, 0x12e}, - {0x130, 0x130}, {0x132, 0x132}, {0x134, 0x134}, {0x136, 0x136}, - {0x139, 0x139}, {0x13b, 0x13b}, {0x13d, 0x13d}, {0x13f, 0x13f}, - {0x141, 0x141}, {0x143, 0x143}, {0x145, 0x145}, {0x147, 0x147}, - {0x14a, 0x14a}, {0x14c, 0x14c}, {0x14e, 0x14e}, {0x150, 0x150}, - {0x152, 0x152}, {0x154, 0x154}, {0x156, 0x156}, {0x158, 0x158}, - {0x15a, 0x15a}, {0x15c, 0x15c}, {0x15e, 0x15e}, {0x160, 0x160}, - {0x162, 0x162}, {0x164, 0x164}, {0x166, 0x166}, {0x168, 0x168}, - {0x16a, 0x16a}, {0x16c, 0x16c}, {0x16e, 0x16e}, {0x170, 0x170}, - {0x172, 0x172}, {0x174, 0x174}, {0x176, 0x176}, {0x178, 0x179}, - {0x17b, 0x17b}, {0x17d, 0x17d}, {0x181, 0x182}, {0x184, 0x184}, - {0x186, 0x187}, {0x189, 0x18b}, {0x18e, 0x191}, {0x193, 0x194}, - {0x196, 0x198}, {0x19c, 0x19d}, {0x19f, 0x1a0}, {0x1a2, 0x1a2}, - {0x1a4, 0x1a4}, {0x1a6, 0x1a7}, {0x1a9, 0x1a9}, {0x1ac, 0x1ac}, - {0x1ae, 0x1af}, {0x1b1, 0x1b3}, {0x1b5, 0x1b5}, {0x1b7, 0x1b8}, - {0x1bc, 0x1bc}, {0x1c4, 0x1c4}, {0x1c7, 0x1c7}, {0x1ca, 0x1ca}, - {0x1cd, 0x1cd}, {0x1cf, 0x1cf}, {0x1d1, 0x1d1}, {0x1d3, 0x1d3}, - {0x1d5, 0x1d5}, {0x1d7, 0x1d7}, {0x1d9, 0x1d9}, {0x1db, 0x1db}, - {0x1de, 0x1de}, {0x1e0, 0x1e0}, {0x1e2, 0x1e2}, {0x1e4, 0x1e4}, - {0x1e6, 0x1e6}, {0x1e8, 0x1e8}, {0x1ea, 0x1ea}, {0x1ec, 0x1ec}, - {0x1ee, 0x1ee}, {0x1f1, 0x1f1}, {0x1f4, 0x1f4}, {0x1f6, 0x1f8}, - {0x1fa, 0x1fa}, {0x1fc, 0x1fc}, {0x1fe, 0x1fe}, {0x200, 0x200}, - {0x202, 0x202}, {0x204, 0x204}, {0x206, 0x206}, {0x208, 0x208}, - {0x20a, 0x20a}, {0x20c, 0x20c}, {0x20e, 0x20e}, {0x210, 0x210}, - {0x212, 0x212}, {0x214, 0x214}, {0x216, 0x216}, {0x218, 0x218}, - {0x21a, 0x21a}, {0x21c, 0x21c}, {0x21e, 0x21e}, {0x220, 0x220}, - {0x222, 0x222}, {0x224, 0x224}, {0x226, 0x226}, {0x228, 0x228}, - {0x22a, 0x22a}, {0x22c, 0x22c}, {0x22e, 0x22e}, {0x230, 0x230}, - {0x232, 0x232}, {0x386, 0x386}, {0x388, 0x38a}, {0x38c, 0x38c}, - {0x38e, 0x38f}, {0x391, 0x3a1}, {0x3a3, 0x3ab}, {0x3d2, 0x3d4}, - {0x3d8, 0x3d8}, {0x3da, 0x3da}, {0x3dc, 0x3dc}, {0x3de, 0x3de}, - {0x3e0, 0x3e0}, {0x3e2, 0x3e2}, {0x3e4, 0x3e4}, {0x3e6, 0x3e6}, - {0x3e8, 0x3e8}, {0x3ea, 0x3ea}, {0x3ec, 0x3ec}, {0x3ee, 0x3ee}, - {0x3f4, 0x3f4}, {0x3f7, 0x3f7}, {0x3f9, 0x3fa}, {0x400, 0x42f}, - {0x460, 0x460}, {0x462, 0x462}, {0x464, 0x464}, {0x466, 0x466}, - {0x468, 0x468}, {0x46a, 0x46a}, {0x46c, 0x46c}, {0x46e, 0x46e}, - {0x470, 0x470}, {0x472, 0x472}, {0x474, 0x474}, {0x476, 0x476}, - {0x478, 0x478}, {0x47a, 0x47a}, {0x47c, 0x47c}, {0x47e, 0x47e}, - {0x480, 0x480}, {0x48a, 0x48a}, {0x48c, 0x48c}, {0x48e, 0x48e}, - {0x490, 0x490}, {0x492, 0x492}, {0x494, 0x494}, {0x496, 0x496}, - {0x498, 0x498}, {0x49a, 0x49a}, {0x49c, 0x49c}, {0x49e, 0x49e}, - {0x4a0, 0x4a0}, {0x4a2, 0x4a2}, {0x4a4, 0x4a4}, {0x4a6, 0x4a6}, - {0x4a8, 0x4a8}, {0x4aa, 0x4aa}, {0x4ac, 0x4ac}, {0x4ae, 0x4ae}, - {0x4b0, 0x4b0}, {0x4b2, 0x4b2}, {0x4b4, 0x4b4}, {0x4b6, 0x4b6}, - {0x4b8, 0x4b8}, {0x4ba, 0x4ba}, {0x4bc, 0x4bc}, {0x4be, 0x4be}, - {0x4c0, 0x4c1}, {0x4c3, 0x4c3}, {0x4c5, 0x4c5}, {0x4c7, 0x4c7}, - {0x4c9, 0x4c9}, {0x4cb, 0x4cb}, {0x4cd, 0x4cd}, {0x4d0, 0x4d0}, - {0x4d2, 0x4d2}, {0x4d4, 0x4d4}, {0x4d6, 0x4d6}, {0x4d8, 0x4d8}, - {0x4da, 0x4da}, {0x4dc, 0x4dc}, {0x4de, 0x4de}, {0x4e0, 0x4e0}, - {0x4e2, 0x4e2}, {0x4e4, 0x4e4}, {0x4e6, 0x4e6}, {0x4e8, 0x4e8}, - {0x4ea, 0x4ea}, {0x4ec, 0x4ec}, {0x4ee, 0x4ee}, {0x4f0, 0x4f0}, - {0x4f2, 0x4f2}, {0x4f4, 0x4f4}, {0x4f8, 0x4f8}, {0x500, 0x500}, - {0x502, 0x502}, {0x504, 0x504}, {0x506, 0x506}, {0x508, 0x508}, - {0x50a, 0x50a}, {0x50c, 0x50c}, {0x50e, 0x50e}, {0x531, 0x556}, - {0x10a0, 0x10c5}, {0x1e00, 0x1e00}, {0x1e02, 0x1e02}, {0x1e04, 0x1e04}, - {0x1e06, 0x1e06}, {0x1e08, 0x1e08}, {0x1e0a, 0x1e0a}, {0x1e0c, 0x1e0c}, - {0x1e0e, 0x1e0e}, {0x1e10, 0x1e10}, {0x1e12, 0x1e12}, {0x1e14, 0x1e14}, - {0x1e16, 0x1e16}, {0x1e18, 0x1e18}, {0x1e1a, 0x1e1a}, {0x1e1c, 0x1e1c}, - {0x1e1e, 0x1e1e}, {0x1e20, 0x1e20}, {0x1e22, 0x1e22}, {0x1e24, 0x1e24}, - {0x1e26, 0x1e26}, {0x1e28, 0x1e28}, {0x1e2a, 0x1e2a}, {0x1e2c, 0x1e2c}, - {0x1e2e, 0x1e2e}, {0x1e30, 0x1e30}, {0x1e32, 0x1e32}, {0x1e34, 0x1e34}, - {0x1e36, 0x1e36}, {0x1e38, 0x1e38}, {0x1e3a, 0x1e3a}, {0x1e3c, 0x1e3c}, - {0x1e3e, 0x1e3e}, {0x1e40, 0x1e40}, {0x1e42, 0x1e42}, {0x1e44, 0x1e44}, - {0x1e46, 0x1e46}, {0x1e48, 0x1e48}, {0x1e4a, 0x1e4a}, {0x1e4c, 0x1e4c}, - {0x1e4e, 0x1e4e}, {0x1e50, 0x1e50}, {0x1e52, 0x1e52}, {0x1e54, 0x1e54}, - {0x1e56, 0x1e56}, {0x1e58, 0x1e58}, {0x1e5a, 0x1e5a}, {0x1e5c, 0x1e5c}, - {0x1e5e, 0x1e5e}, {0x1e60, 0x1e60}, {0x1e62, 0x1e62}, {0x1e64, 0x1e64}, - {0x1e66, 0x1e66}, {0x1e68, 0x1e68}, {0x1e6a, 0x1e6a}, {0x1e6c, 0x1e6c}, - {0x1e6e, 0x1e6e}, {0x1e70, 0x1e70}, {0x1e72, 0x1e72}, {0x1e74, 0x1e74}, - {0x1e76, 0x1e76}, {0x1e78, 0x1e78}, {0x1e7a, 0x1e7a}, {0x1e7c, 0x1e7c}, - {0x1e7e, 0x1e7e}, {0x1e80, 0x1e80}, {0x1e82, 0x1e82}, {0x1e84, 0x1e84}, - {0x1e86, 0x1e86}, {0x1e88, 0x1e88}, {0x1e8a, 0x1e8a}, {0x1e8c, 0x1e8c}, - {0x1e8e, 0x1e8e}, {0x1e90, 0x1e90}, {0x1e92, 0x1e92}, {0x1e94, 0x1e94}, - {0x1ea0, 0x1ea0}, {0x1ea2, 0x1ea2}, {0x1ea4, 0x1ea4}, {0x1ea6, 0x1ea6}, - {0x1ea8, 0x1ea8}, {0x1eaa, 0x1eaa}, {0x1eac, 0x1eac}, {0x1eae, 0x1eae}, - {0x1eb0, 0x1eb0}, {0x1eb2, 0x1eb2}, {0x1eb4, 0x1eb4}, {0x1eb6, 0x1eb6}, - {0x1eb8, 0x1eb8}, {0x1eba, 0x1eba}, {0x1ebc, 0x1ebc}, {0x1ebe, 0x1ebe}, - {0x1ec0, 0x1ec0}, {0x1ec2, 0x1ec2}, {0x1ec4, 0x1ec4}, {0x1ec6, 0x1ec6}, - {0x1ec8, 0x1ec8}, {0x1eca, 0x1eca}, {0x1ecc, 0x1ecc}, {0x1ece, 0x1ece}, - {0x1ed0, 0x1ed0}, {0x1ed2, 0x1ed2}, {0x1ed4, 0x1ed4}, {0x1ed6, 0x1ed6}, - {0x1ed8, 0x1ed8}, {0x1eda, 0x1eda}, {0x1edc, 0x1edc}, {0x1ede, 0x1ede}, - {0x1ee0, 0x1ee0}, {0x1ee2, 0x1ee2}, {0x1ee4, 0x1ee4}, {0x1ee6, 0x1ee6}, - {0x1ee8, 0x1ee8}, {0x1eea, 0x1eea}, {0x1eec, 0x1eec}, {0x1eee, 0x1eee}, - {0x1ef0, 0x1ef0}, {0x1ef2, 0x1ef2}, {0x1ef4, 0x1ef4}, {0x1ef6, 0x1ef6}, - {0x1ef8, 0x1ef8}, {0x1f08, 0x1f0f}, {0x1f18, 0x1f1d}, {0x1f28, 0x1f2f}, - {0x1f38, 0x1f3f}, {0x1f48, 0x1f4d}, {0x1f59, 0x1f59}, {0x1f5b, 0x1f5b}, - {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f5f}, {0x1f68, 0x1f6f}, {0x1fb8, 0x1fbb}, - {0x1fc8, 0x1fcb}, {0x1fd8, 0x1fdb}, {0x1fe8, 0x1fec}, {0x1ff8, 0x1ffb}, - {0x2102, 0x2102}, {0x2107, 0x2107}, {0x210b, 0x210d}, {0x2110, 0x2112}, - {0x2115, 0x2115}, {0x2119, 0x211d}, {0x2124, 0x2124}, {0x2126, 0x2126}, - {0x2128, 0x2128}, {0x212a, 0x212d}, {0x2130, 0x2131}, {0x2133, 0x2133}, - {0x213e, 0x213f}, {0x2145, 0x2145}, {0xff21, 0xff3a} }; -static xmlChLRange xmlLuL[] = {{0x10400, 0x10427}, {0x1d400, 0x1d419}, +static const xmlChSRange xmlLuS[] = {{0x41, 0x5a}, {0xc0, 0xd6}, + {0xd8, 0xde}, {0x100, 0x100}, {0x102, 0x102}, {0x104, 0x104}, + {0x106, 0x106}, {0x108, 0x108}, {0x10a, 0x10a}, {0x10c, 0x10c}, + {0x10e, 0x10e}, {0x110, 0x110}, {0x112, 0x112}, {0x114, 0x114}, + {0x116, 0x116}, {0x118, 0x118}, {0x11a, 0x11a}, {0x11c, 0x11c}, + {0x11e, 0x11e}, {0x120, 0x120}, {0x122, 0x122}, {0x124, 0x124}, + {0x126, 0x126}, {0x128, 0x128}, {0x12a, 0x12a}, {0x12c, 0x12c}, + {0x12e, 0x12e}, {0x130, 0x130}, {0x132, 0x132}, {0x134, 0x134}, + {0x136, 0x136}, {0x139, 0x139}, {0x13b, 0x13b}, {0x13d, 0x13d}, + {0x13f, 0x13f}, {0x141, 0x141}, {0x143, 0x143}, {0x145, 0x145}, + {0x147, 0x147}, {0x14a, 0x14a}, {0x14c, 0x14c}, {0x14e, 0x14e}, + {0x150, 0x150}, {0x152, 0x152}, {0x154, 0x154}, {0x156, 0x156}, + {0x158, 0x158}, {0x15a, 0x15a}, {0x15c, 0x15c}, {0x15e, 0x15e}, + {0x160, 0x160}, {0x162, 0x162}, {0x164, 0x164}, {0x166, 0x166}, + {0x168, 0x168}, {0x16a, 0x16a}, {0x16c, 0x16c}, {0x16e, 0x16e}, + {0x170, 0x170}, {0x172, 0x172}, {0x174, 0x174}, {0x176, 0x176}, + {0x178, 0x179}, {0x17b, 0x17b}, {0x17d, 0x17d}, {0x181, 0x182}, + {0x184, 0x184}, {0x186, 0x187}, {0x189, 0x18b}, {0x18e, 0x191}, + {0x193, 0x194}, {0x196, 0x198}, {0x19c, 0x19d}, {0x19f, 0x1a0}, + {0x1a2, 0x1a2}, {0x1a4, 0x1a4}, {0x1a6, 0x1a7}, {0x1a9, 0x1a9}, + {0x1ac, 0x1ac}, {0x1ae, 0x1af}, {0x1b1, 0x1b3}, {0x1b5, 0x1b5}, + {0x1b7, 0x1b8}, {0x1bc, 0x1bc}, {0x1c4, 0x1c4}, {0x1c7, 0x1c7}, + {0x1ca, 0x1ca}, {0x1cd, 0x1cd}, {0x1cf, 0x1cf}, {0x1d1, 0x1d1}, + {0x1d3, 0x1d3}, {0x1d5, 0x1d5}, {0x1d7, 0x1d7}, {0x1d9, 0x1d9}, + {0x1db, 0x1db}, {0x1de, 0x1de}, {0x1e0, 0x1e0}, {0x1e2, 0x1e2}, + {0x1e4, 0x1e4}, {0x1e6, 0x1e6}, {0x1e8, 0x1e8}, {0x1ea, 0x1ea}, + {0x1ec, 0x1ec}, {0x1ee, 0x1ee}, {0x1f1, 0x1f1}, {0x1f4, 0x1f4}, + {0x1f6, 0x1f8}, {0x1fa, 0x1fa}, {0x1fc, 0x1fc}, {0x1fe, 0x1fe}, + {0x200, 0x200}, {0x202, 0x202}, {0x204, 0x204}, {0x206, 0x206}, + {0x208, 0x208}, {0x20a, 0x20a}, {0x20c, 0x20c}, {0x20e, 0x20e}, + {0x210, 0x210}, {0x212, 0x212}, {0x214, 0x214}, {0x216, 0x216}, + {0x218, 0x218}, {0x21a, 0x21a}, {0x21c, 0x21c}, {0x21e, 0x21e}, + {0x220, 0x220}, {0x222, 0x222}, {0x224, 0x224}, {0x226, 0x226}, + {0x228, 0x228}, {0x22a, 0x22a}, {0x22c, 0x22c}, {0x22e, 0x22e}, + {0x230, 0x230}, {0x232, 0x232}, {0x386, 0x386}, {0x388, 0x38a}, + {0x38c, 0x38c}, {0x38e, 0x38f}, {0x391, 0x3a1}, {0x3a3, 0x3ab}, + {0x3d2, 0x3d4}, {0x3d8, 0x3d8}, {0x3da, 0x3da}, {0x3dc, 0x3dc}, + {0x3de, 0x3de}, {0x3e0, 0x3e0}, {0x3e2, 0x3e2}, {0x3e4, 0x3e4}, + {0x3e6, 0x3e6}, {0x3e8, 0x3e8}, {0x3ea, 0x3ea}, {0x3ec, 0x3ec}, + {0x3ee, 0x3ee}, {0x3f4, 0x3f4}, {0x3f7, 0x3f7}, {0x3f9, 0x3fa}, + {0x400, 0x42f}, {0x460, 0x460}, {0x462, 0x462}, {0x464, 0x464}, + {0x466, 0x466}, {0x468, 0x468}, {0x46a, 0x46a}, {0x46c, 0x46c}, + {0x46e, 0x46e}, {0x470, 0x470}, {0x472, 0x472}, {0x474, 0x474}, + {0x476, 0x476}, {0x478, 0x478}, {0x47a, 0x47a}, {0x47c, 0x47c}, + {0x47e, 0x47e}, {0x480, 0x480}, {0x48a, 0x48a}, {0x48c, 0x48c}, + {0x48e, 0x48e}, {0x490, 0x490}, {0x492, 0x492}, {0x494, 0x494}, + {0x496, 0x496}, {0x498, 0x498}, {0x49a, 0x49a}, {0x49c, 0x49c}, + {0x49e, 0x49e}, {0x4a0, 0x4a0}, {0x4a2, 0x4a2}, {0x4a4, 0x4a4}, + {0x4a6, 0x4a6}, {0x4a8, 0x4a8}, {0x4aa, 0x4aa}, {0x4ac, 0x4ac}, + {0x4ae, 0x4ae}, {0x4b0, 0x4b0}, {0x4b2, 0x4b2}, {0x4b4, 0x4b4}, + {0x4b6, 0x4b6}, {0x4b8, 0x4b8}, {0x4ba, 0x4ba}, {0x4bc, 0x4bc}, + {0x4be, 0x4be}, {0x4c0, 0x4c1}, {0x4c3, 0x4c3}, {0x4c5, 0x4c5}, + {0x4c7, 0x4c7}, {0x4c9, 0x4c9}, {0x4cb, 0x4cb}, {0x4cd, 0x4cd}, + {0x4d0, 0x4d0}, {0x4d2, 0x4d2}, {0x4d4, 0x4d4}, {0x4d6, 0x4d6}, + {0x4d8, 0x4d8}, {0x4da, 0x4da}, {0x4dc, 0x4dc}, {0x4de, 0x4de}, + {0x4e0, 0x4e0}, {0x4e2, 0x4e2}, {0x4e4, 0x4e4}, {0x4e6, 0x4e6}, + {0x4e8, 0x4e8}, {0x4ea, 0x4ea}, {0x4ec, 0x4ec}, {0x4ee, 0x4ee}, + {0x4f0, 0x4f0}, {0x4f2, 0x4f2}, {0x4f4, 0x4f4}, {0x4f8, 0x4f8}, + {0x500, 0x500}, {0x502, 0x502}, {0x504, 0x504}, {0x506, 0x506}, + {0x508, 0x508}, {0x50a, 0x50a}, {0x50c, 0x50c}, {0x50e, 0x50e}, + {0x531, 0x556}, {0x10a0, 0x10c5}, {0x1e00, 0x1e00}, {0x1e02, 0x1e02}, + {0x1e04, 0x1e04}, {0x1e06, 0x1e06}, {0x1e08, 0x1e08}, {0x1e0a, 0x1e0a}, + {0x1e0c, 0x1e0c}, {0x1e0e, 0x1e0e}, {0x1e10, 0x1e10}, {0x1e12, 0x1e12}, + {0x1e14, 0x1e14}, {0x1e16, 0x1e16}, {0x1e18, 0x1e18}, {0x1e1a, 0x1e1a}, + {0x1e1c, 0x1e1c}, {0x1e1e, 0x1e1e}, {0x1e20, 0x1e20}, {0x1e22, 0x1e22}, + {0x1e24, 0x1e24}, {0x1e26, 0x1e26}, {0x1e28, 0x1e28}, {0x1e2a, 0x1e2a}, + {0x1e2c, 0x1e2c}, {0x1e2e, 0x1e2e}, {0x1e30, 0x1e30}, {0x1e32, 0x1e32}, + {0x1e34, 0x1e34}, {0x1e36, 0x1e36}, {0x1e38, 0x1e38}, {0x1e3a, 0x1e3a}, + {0x1e3c, 0x1e3c}, {0x1e3e, 0x1e3e}, {0x1e40, 0x1e40}, {0x1e42, 0x1e42}, + {0x1e44, 0x1e44}, {0x1e46, 0x1e46}, {0x1e48, 0x1e48}, {0x1e4a, 0x1e4a}, + {0x1e4c, 0x1e4c}, {0x1e4e, 0x1e4e}, {0x1e50, 0x1e50}, {0x1e52, 0x1e52}, + {0x1e54, 0x1e54}, {0x1e56, 0x1e56}, {0x1e58, 0x1e58}, {0x1e5a, 0x1e5a}, + {0x1e5c, 0x1e5c}, {0x1e5e, 0x1e5e}, {0x1e60, 0x1e60}, {0x1e62, 0x1e62}, + {0x1e64, 0x1e64}, {0x1e66, 0x1e66}, {0x1e68, 0x1e68}, {0x1e6a, 0x1e6a}, + {0x1e6c, 0x1e6c}, {0x1e6e, 0x1e6e}, {0x1e70, 0x1e70}, {0x1e72, 0x1e72}, + {0x1e74, 0x1e74}, {0x1e76, 0x1e76}, {0x1e78, 0x1e78}, {0x1e7a, 0x1e7a}, + {0x1e7c, 0x1e7c}, {0x1e7e, 0x1e7e}, {0x1e80, 0x1e80}, {0x1e82, 0x1e82}, + {0x1e84, 0x1e84}, {0x1e86, 0x1e86}, {0x1e88, 0x1e88}, {0x1e8a, 0x1e8a}, + {0x1e8c, 0x1e8c}, {0x1e8e, 0x1e8e}, {0x1e90, 0x1e90}, {0x1e92, 0x1e92}, + {0x1e94, 0x1e94}, {0x1ea0, 0x1ea0}, {0x1ea2, 0x1ea2}, {0x1ea4, 0x1ea4}, + {0x1ea6, 0x1ea6}, {0x1ea8, 0x1ea8}, {0x1eaa, 0x1eaa}, {0x1eac, 0x1eac}, + {0x1eae, 0x1eae}, {0x1eb0, 0x1eb0}, {0x1eb2, 0x1eb2}, {0x1eb4, 0x1eb4}, + {0x1eb6, 0x1eb6}, {0x1eb8, 0x1eb8}, {0x1eba, 0x1eba}, {0x1ebc, 0x1ebc}, + {0x1ebe, 0x1ebe}, {0x1ec0, 0x1ec0}, {0x1ec2, 0x1ec2}, {0x1ec4, 0x1ec4}, + {0x1ec6, 0x1ec6}, {0x1ec8, 0x1ec8}, {0x1eca, 0x1eca}, {0x1ecc, 0x1ecc}, + {0x1ece, 0x1ece}, {0x1ed0, 0x1ed0}, {0x1ed2, 0x1ed2}, {0x1ed4, 0x1ed4}, + {0x1ed6, 0x1ed6}, {0x1ed8, 0x1ed8}, {0x1eda, 0x1eda}, {0x1edc, 0x1edc}, + {0x1ede, 0x1ede}, {0x1ee0, 0x1ee0}, {0x1ee2, 0x1ee2}, {0x1ee4, 0x1ee4}, + {0x1ee6, 0x1ee6}, {0x1ee8, 0x1ee8}, {0x1eea, 0x1eea}, {0x1eec, 0x1eec}, + {0x1eee, 0x1eee}, {0x1ef0, 0x1ef0}, {0x1ef2, 0x1ef2}, {0x1ef4, 0x1ef4}, + {0x1ef6, 0x1ef6}, {0x1ef8, 0x1ef8}, {0x1f08, 0x1f0f}, {0x1f18, 0x1f1d}, + {0x1f28, 0x1f2f}, {0x1f38, 0x1f3f}, {0x1f48, 0x1f4d}, {0x1f59, 0x1f59}, + {0x1f5b, 0x1f5b}, {0x1f5d, 0x1f5d}, {0x1f5f, 0x1f5f}, {0x1f68, 0x1f6f}, + {0x1fb8, 0x1fbb}, {0x1fc8, 0x1fcb}, {0x1fd8, 0x1fdb}, {0x1fe8, 0x1fec}, + {0x1ff8, 0x1ffb}, {0x2102, 0x2102}, {0x2107, 0x2107}, {0x210b, 0x210d}, + {0x2110, 0x2112}, {0x2115, 0x2115}, {0x2119, 0x211d}, {0x2124, 0x2124}, + {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212a, 0x212d}, {0x2130, 0x2131}, + {0x2133, 0x2133}, {0x213e, 0x213f}, {0x2145, 0x2145}, {0xff21, 0xff3a} }; +static const xmlChLRange xmlLuL[] = {{0x10400, 0x10427}, {0x1d400, 0x1d419}, {0x1d434, 0x1d44d}, {0x1d468, 0x1d481}, {0x1d49c, 0x1d49c}, {0x1d49e, 0x1d49f}, {0x1d4a2, 0x1d4a2}, {0x1d4a5, 0x1d4a6}, {0x1d4a9, 0x1d4ac}, {0x1d4ae, 0x1d4b5}, {0x1d4d0, 0x1d4e9}, @@ -610,7 +610,7 @@ static xmlChLRange xmlLuL[] = {{0x10400, 0x10427}, {0x1d400, 0x1d419}, {0x1d756, 0x1d76e}, {0x1d790, 0x1d7a8} }; static xmlChRangeGroup xmlLuG = {390,31,xmlLuS,xmlLuL}; -static xmlChSRange xmlMS[] = {{0x300, 0x357}, {0x35d, 0x36f}, +static const xmlChSRange xmlMS[] = {{0x300, 0x357}, {0x35d, 0x36f}, {0x483, 0x486}, {0x488, 0x489}, {0x591, 0x5a1}, {0x5a3, 0x5b9}, {0x5bb, 0x5bd}, {0x5bf, 0x5bf}, {0x5c1, 0x5c2}, {0x5c4, 0x5c4}, {0x610, 0x615}, {0x64b, 0x658}, {0x670, 0x670}, {0x6d6, 0x6dc}, @@ -639,12 +639,12 @@ static xmlChSRange xmlMS[] = {{0x300, 0x357}, {0x35d, 0x36f}, {0x17dd, 0x17dd}, {0x180b, 0x180d}, {0x18a9, 0x18a9}, {0x1920, 0x192b}, {0x1930, 0x193b}, {0x20d0, 0x20ea}, {0x302a, 0x302f}, {0x3099, 0x309a}, {0xfb1e, 0xfb1e}, {0xfe00, 0xfe0f}, {0xfe20, 0xfe23} }; -static xmlChLRange xmlML[] = {{0x1d165, 0x1d169}, {0x1d16d, 0x1d172}, +static const xmlChLRange xmlML[] = {{0x1d165, 0x1d169}, {0x1d16d, 0x1d172}, {0x1d17b, 0x1d182}, {0x1d185, 0x1d18b}, {0x1d1aa, 0x1d1ad}, {0xe0100, 0xe01ef} }; static xmlChRangeGroup xmlMG = {113,6,xmlMS,xmlML}; -static xmlChSRange xmlMcS[] = {{0x903, 0x903}, {0x93e, 0x940}, +static const xmlChSRange xmlMcS[] = {{0x903, 0x903}, {0x93e, 0x940}, {0x949, 0x94c}, {0x982, 0x983}, {0x9be, 0x9c0}, {0x9c7, 0x9c8}, {0x9cb, 0x9cc}, {0x9d7, 0x9d7}, {0xa03, 0xa03}, {0xa3e, 0xa40}, {0xa83, 0xa83}, {0xabe, 0xac0}, {0xac9, 0xac9}, {0xacb, 0xacc}, @@ -659,10 +659,10 @@ static xmlChSRange xmlMcS[] = {{0x903, 0x903}, {0x93e, 0x940}, {0x1038, 0x1038}, {0x1056, 0x1057}, {0x17b6, 0x17b6}, {0x17be, 0x17c5}, {0x17c7, 0x17c8}, {0x1923, 0x1926}, {0x1929, 0x192b}, {0x1930, 0x1931}, {0x1933, 0x1938} }; -static xmlChLRange xmlMcL[] = {{0x1d165, 0x1d166}, {0x1d16d, 0x1d172} }; +static const xmlChLRange xmlMcL[] = {{0x1d165, 0x1d166}, {0x1d16d, 0x1d172} }; static xmlChRangeGroup xmlMcG = {55,2,xmlMcS,xmlMcL}; -static xmlChSRange xmlMnS[] = {{0x300, 0x357}, {0x35d, 0x36f}, +static const xmlChSRange xmlMnS[] = {{0x300, 0x357}, {0x35d, 0x36f}, {0x483, 0x486}, {0x591, 0x5a1}, {0x5a3, 0x5b9}, {0x5bb, 0x5bd}, {0x5bf, 0x5bf}, {0x5c1, 0x5c2}, {0x5c4, 0x5c4}, {0x610, 0x615}, {0x64b, 0x658}, {0x670, 0x670}, {0x6d6, 0x6dc}, {0x6df, 0x6e4}, @@ -690,94 +690,95 @@ static xmlChSRange xmlMnS[] = {{0x300, 0x357}, {0x35d, 0x36f}, {0x1932, 0x1932}, {0x1939, 0x193b}, {0x20d0, 0x20dc}, {0x20e1, 0x20e1}, {0x20e5, 0x20ea}, {0x302a, 0x302f}, {0x3099, 0x309a}, {0xfb1e, 0xfb1e}, {0xfe00, 0xfe0f}, {0xfe20, 0xfe23} }; -static xmlChLRange xmlMnL[] = {{0x1d167, 0x1d169}, {0x1d17b, 0x1d182}, +static const xmlChLRange xmlMnL[] = {{0x1d167, 0x1d169}, {0x1d17b, 0x1d182}, {0x1d185, 0x1d18b}, {0x1d1aa, 0x1d1ad}, {0xe0100, 0xe01ef} }; static xmlChRangeGroup xmlMnG = {108,5,xmlMnS,xmlMnL}; -static xmlChSRange xmlNS[] = {{0x30, 0x39}, {0xb2, 0xb3}, {0xb9, 0xb9}, - {0xbc, 0xbe}, {0x660, 0x669}, {0x6f0, 0x6f9}, {0x966, 0x96f}, - {0x9e6, 0x9ef}, {0x9f4, 0x9f9}, {0xa66, 0xa6f}, {0xae6, 0xaef}, - {0xb66, 0xb6f}, {0xbe7, 0xbf2}, {0xc66, 0xc6f}, {0xce6, 0xcef}, - {0xd66, 0xd6f}, {0xe50, 0xe59}, {0xed0, 0xed9}, {0xf20, 0xf33}, - {0x1040, 0x1049}, {0x1369, 0x137c}, {0x16ee, 0x16f0}, {0x17e0, 0x17e9}, - {0x17f0, 0x17f9}, {0x1810, 0x1819}, {0x1946, 0x194f}, {0x2070, 0x2070}, - {0x2074, 0x2079}, {0x2080, 0x2089}, {0x2153, 0x2183}, {0x2460, 0x249b}, - {0x24ea, 0x24ff}, {0x2776, 0x2793}, {0x3007, 0x3007}, {0x3021, 0x3029}, - {0x3038, 0x303a}, {0x3192, 0x3195}, {0x3220, 0x3229}, {0x3251, 0x325f}, - {0x3280, 0x3289}, {0x32b1, 0x32bf}, {0xff10, 0xff19} }; -static xmlChLRange xmlNL[] = {{0x10107, 0x10133}, {0x10320, 0x10323}, +static const xmlChSRange xmlNS[] = {{0x30, 0x39}, {0xb2, 0xb3}, + {0xb9, 0xb9}, {0xbc, 0xbe}, {0x660, 0x669}, {0x6f0, 0x6f9}, + {0x966, 0x96f}, {0x9e6, 0x9ef}, {0x9f4, 0x9f9}, {0xa66, 0xa6f}, + {0xae6, 0xaef}, {0xb66, 0xb6f}, {0xbe7, 0xbf2}, {0xc66, 0xc6f}, + {0xce6, 0xcef}, {0xd66, 0xd6f}, {0xe50, 0xe59}, {0xed0, 0xed9}, + {0xf20, 0xf33}, {0x1040, 0x1049}, {0x1369, 0x137c}, {0x16ee, 0x16f0}, + {0x17e0, 0x17e9}, {0x17f0, 0x17f9}, {0x1810, 0x1819}, {0x1946, 0x194f}, + {0x2070, 0x2070}, {0x2074, 0x2079}, {0x2080, 0x2089}, {0x2153, 0x2183}, + {0x2460, 0x249b}, {0x24ea, 0x24ff}, {0x2776, 0x2793}, {0x3007, 0x3007}, + {0x3021, 0x3029}, {0x3038, 0x303a}, {0x3192, 0x3195}, {0x3220, 0x3229}, + {0x3251, 0x325f}, {0x3280, 0x3289}, {0x32b1, 0x32bf}, {0xff10, 0xff19} }; +static const xmlChLRange xmlNL[] = {{0x10107, 0x10133}, {0x10320, 0x10323}, {0x1034a, 0x1034a}, {0x104a0, 0x104a9}, {0x1d7ce, 0x1d7ff} }; static xmlChRangeGroup xmlNG = {42,5,xmlNS,xmlNL}; -static xmlChSRange xmlNdS[] = {{0x30, 0x39}, {0x660, 0x669}, +static const xmlChSRange xmlNdS[] = {{0x30, 0x39}, {0x660, 0x669}, {0x6f0, 0x6f9}, {0x966, 0x96f}, {0x9e6, 0x9ef}, {0xa66, 0xa6f}, {0xae6, 0xaef}, {0xb66, 0xb6f}, {0xbe7, 0xbef}, {0xc66, 0xc6f}, {0xce6, 0xcef}, {0xd66, 0xd6f}, {0xe50, 0xe59}, {0xed0, 0xed9}, {0xf20, 0xf29}, {0x1040, 0x1049}, {0x1369, 0x1371}, {0x17e0, 0x17e9}, {0x1810, 0x1819}, {0x1946, 0x194f}, {0xff10, 0xff19} }; -static xmlChLRange xmlNdL[] = {{0x104a0, 0x104a9}, {0x1d7ce, 0x1d7ff} }; +static const xmlChLRange xmlNdL[] = {{0x104a0, 0x104a9}, {0x1d7ce, 0x1d7ff} }; static xmlChRangeGroup xmlNdG = {21,2,xmlNdS,xmlNdL}; -static xmlChSRange xmlNoS[] = {{0xb2, 0xb3}, {0xb9, 0xb9}, {0xbc, 0xbe}, - {0x9f4, 0x9f9}, {0xbf0, 0xbf2}, {0xf2a, 0xf33}, {0x1372, 0x137c}, - {0x17f0, 0x17f9}, {0x2070, 0x2070}, {0x2074, 0x2079}, {0x2080, 0x2089}, - {0x2153, 0x215f}, {0x2460, 0x249b}, {0x24ea, 0x24ff}, {0x2776, 0x2793}, - {0x3192, 0x3195}, {0x3220, 0x3229}, {0x3251, 0x325f}, {0x3280, 0x3289}, - {0x32b1, 0x32bf} }; -static xmlChLRange xmlNoL[] = {{0x10107, 0x10133}, {0x10320, 0x10323} }; +static const xmlChSRange xmlNoS[] = {{0xb2, 0xb3}, {0xb9, 0xb9}, + {0xbc, 0xbe}, {0x9f4, 0x9f9}, {0xbf0, 0xbf2}, {0xf2a, 0xf33}, + {0x1372, 0x137c}, {0x17f0, 0x17f9}, {0x2070, 0x2070}, {0x2074, 0x2079}, + {0x2080, 0x2089}, {0x2153, 0x215f}, {0x2460, 0x249b}, {0x24ea, 0x24ff}, + {0x2776, 0x2793}, {0x3192, 0x3195}, {0x3220, 0x3229}, {0x3251, 0x325f}, + {0x3280, 0x3289}, {0x32b1, 0x32bf} }; +static const xmlChLRange xmlNoL[] = {{0x10107, 0x10133}, {0x10320, 0x10323} }; static xmlChRangeGroup xmlNoG = {20,2,xmlNoS,xmlNoL}; -static xmlChSRange xmlPS[] = {{0x21, 0x23}, {0x25, 0x2a}, {0x2c, 0x2f}, - {0x3a, 0x3b}, {0x3f, 0x40}, {0x5b, 0x5d}, {0x5f, 0x5f}, {0x7b, 0x7b}, - {0x7d, 0x7d}, {0xa1, 0xa1}, {0xab, 0xab}, {0xb7, 0xb7}, {0xbb, 0xbb}, - {0xbf, 0xbf}, {0x37e, 0x37e}, {0x387, 0x387}, {0x55a, 0x55f}, - {0x589, 0x58a}, {0x5be, 0x5be}, {0x5c0, 0x5c0}, {0x5c3, 0x5c3}, - {0x5f3, 0x5f4}, {0x60c, 0x60d}, {0x61b, 0x61b}, {0x61f, 0x61f}, - {0x66a, 0x66d}, {0x6d4, 0x6d4}, {0x700, 0x70d}, {0x964, 0x965}, - {0x970, 0x970}, {0xdf4, 0xdf4}, {0xe4f, 0xe4f}, {0xe5a, 0xe5b}, - {0xf04, 0xf12}, {0xf3a, 0xf3d}, {0xf85, 0xf85}, {0x104a, 0x104f}, - {0x10fb, 0x10fb}, {0x1361, 0x1368}, {0x166d, 0x166e}, {0x169b, 0x169c}, - {0x16eb, 0x16ed}, {0x1735, 0x1736}, {0x17d4, 0x17d6}, {0x17d8, 0x17da}, - {0x1800, 0x180a}, {0x1944, 0x1945}, {0x2010, 0x2027}, {0x2030, 0x2043}, - {0x2045, 0x2051}, {0x2053, 0x2054}, {0x2057, 0x2057}, {0x207d, 0x207e}, - {0x208d, 0x208e}, {0x2329, 0x232a}, {0x23b4, 0x23b6}, {0x2768, 0x2775}, - {0x27e6, 0x27eb}, {0x2983, 0x2998}, {0x29d8, 0x29db}, {0x29fc, 0x29fd}, - {0x3001, 0x3003}, {0x3008, 0x3011}, {0x3014, 0x301f}, {0x3030, 0x3030}, - {0x303d, 0x303d}, {0x30a0, 0x30a0}, {0x30fb, 0x30fb}, {0xfd3e, 0xfd3f}, - {0xfe30, 0xfe52}, {0xfe54, 0xfe61}, {0xfe63, 0xfe63}, {0xfe68, 0xfe68}, - {0xfe6a, 0xfe6b}, {0xff01, 0xff03}, {0xff05, 0xff0a}, {0xff0c, 0xff0f}, - {0xff1a, 0xff1b}, {0xff1f, 0xff20}, {0xff3b, 0xff3d}, {0xff3f, 0xff3f}, - {0xff5b, 0xff5b}, {0xff5d, 0xff5d}, {0xff5f, 0xff65} }; -static xmlChLRange xmlPL[] = {{0x10100, 0x10101}, {0x1039f, 0x1039f} }; +static const xmlChSRange xmlPS[] = {{0x21, 0x23}, {0x25, 0x2a}, + {0x2c, 0x2f}, {0x3a, 0x3b}, {0x3f, 0x40}, {0x5b, 0x5d}, {0x5f, 0x5f}, + {0x7b, 0x7b}, {0x7d, 0x7d}, {0xa1, 0xa1}, {0xab, 0xab}, {0xb7, 0xb7}, + {0xbb, 0xbb}, {0xbf, 0xbf}, {0x37e, 0x37e}, {0x387, 0x387}, + {0x55a, 0x55f}, {0x589, 0x58a}, {0x5be, 0x5be}, {0x5c0, 0x5c0}, + {0x5c3, 0x5c3}, {0x5f3, 0x5f4}, {0x60c, 0x60d}, {0x61b, 0x61b}, + {0x61f, 0x61f}, {0x66a, 0x66d}, {0x6d4, 0x6d4}, {0x700, 0x70d}, + {0x964, 0x965}, {0x970, 0x970}, {0xdf4, 0xdf4}, {0xe4f, 0xe4f}, + {0xe5a, 0xe5b}, {0xf04, 0xf12}, {0xf3a, 0xf3d}, {0xf85, 0xf85}, + {0x104a, 0x104f}, {0x10fb, 0x10fb}, {0x1361, 0x1368}, {0x166d, 0x166e}, + {0x169b, 0x169c}, {0x16eb, 0x16ed}, {0x1735, 0x1736}, {0x17d4, 0x17d6}, + {0x17d8, 0x17da}, {0x1800, 0x180a}, {0x1944, 0x1945}, {0x2010, 0x2027}, + {0x2030, 0x2043}, {0x2045, 0x2051}, {0x2053, 0x2054}, {0x2057, 0x2057}, + {0x207d, 0x207e}, {0x208d, 0x208e}, {0x2329, 0x232a}, {0x23b4, 0x23b6}, + {0x2768, 0x2775}, {0x27e6, 0x27eb}, {0x2983, 0x2998}, {0x29d8, 0x29db}, + {0x29fc, 0x29fd}, {0x3001, 0x3003}, {0x3008, 0x3011}, {0x3014, 0x301f}, + {0x3030, 0x3030}, {0x303d, 0x303d}, {0x30a0, 0x30a0}, {0x30fb, 0x30fb}, + {0xfd3e, 0xfd3f}, {0xfe30, 0xfe52}, {0xfe54, 0xfe61}, {0xfe63, 0xfe63}, + {0xfe68, 0xfe68}, {0xfe6a, 0xfe6b}, {0xff01, 0xff03}, {0xff05, 0xff0a}, + {0xff0c, 0xff0f}, {0xff1a, 0xff1b}, {0xff1f, 0xff20}, {0xff3b, 0xff3d}, + {0xff3f, 0xff3f}, {0xff5b, 0xff5b}, {0xff5d, 0xff5d}, {0xff5f, 0xff65} }; +static const xmlChLRange xmlPL[] = {{0x10100, 0x10101}, {0x1039f, 0x1039f} }; static xmlChRangeGroup xmlPG = {84,2,xmlPS,xmlPL}; -static xmlChSRange xmlPdS[] = {{0x2d, 0x2d}, {0x58a, 0x58a}, +static const xmlChSRange xmlPdS[] = {{0x2d, 0x2d}, {0x58a, 0x58a}, {0x1806, 0x1806}, {0x2010, 0x2015}, {0x301c, 0x301c}, {0x3030, 0x3030}, {0x30a0, 0x30a0}, {0xfe31, 0xfe32}, {0xfe58, 0xfe58}, {0xfe63, 0xfe63}, {0xff0d, 0xff0d} }; static xmlChRangeGroup xmlPdG = {11,0,xmlPdS,NULL}; -static xmlChSRange xmlPeS[] = {{0x29, 0x29}, {0x5d, 0x5d}, {0x7d, 0x7d}, - {0xf3b, 0xf3b}, {0xf3d, 0xf3d}, {0x169c, 0x169c}, {0x2046, 0x2046}, - {0x207e, 0x207e}, {0x208e, 0x208e}, {0x232a, 0x232a}, {0x23b5, 0x23b5}, - {0x2769, 0x2769}, {0x276b, 0x276b}, {0x276d, 0x276d}, {0x276f, 0x276f}, - {0x2771, 0x2771}, {0x2773, 0x2773}, {0x2775, 0x2775}, {0x27e7, 0x27e7}, - {0x27e9, 0x27e9}, {0x27eb, 0x27eb}, {0x2984, 0x2984}, {0x2986, 0x2986}, - {0x2988, 0x2988}, {0x298a, 0x298a}, {0x298c, 0x298c}, {0x298e, 0x298e}, - {0x2990, 0x2990}, {0x2992, 0x2992}, {0x2994, 0x2994}, {0x2996, 0x2996}, - {0x2998, 0x2998}, {0x29d9, 0x29d9}, {0x29db, 0x29db}, {0x29fd, 0x29fd}, - {0x3009, 0x3009}, {0x300b, 0x300b}, {0x300d, 0x300d}, {0x300f, 0x300f}, - {0x3011, 0x3011}, {0x3015, 0x3015}, {0x3017, 0x3017}, {0x3019, 0x3019}, - {0x301b, 0x301b}, {0x301e, 0x301f}, {0xfd3f, 0xfd3f}, {0xfe36, 0xfe36}, - {0xfe38, 0xfe38}, {0xfe3a, 0xfe3a}, {0xfe3c, 0xfe3c}, {0xfe3e, 0xfe3e}, - {0xfe40, 0xfe40}, {0xfe42, 0xfe42}, {0xfe44, 0xfe44}, {0xfe48, 0xfe48}, - {0xfe5a, 0xfe5a}, {0xfe5c, 0xfe5c}, {0xfe5e, 0xfe5e}, {0xff09, 0xff09}, - {0xff3d, 0xff3d}, {0xff5d, 0xff5d}, {0xff60, 0xff60}, {0xff63, 0xff63} }; +static const xmlChSRange xmlPeS[] = {{0x29, 0x29}, {0x5d, 0x5d}, + {0x7d, 0x7d}, {0xf3b, 0xf3b}, {0xf3d, 0xf3d}, {0x169c, 0x169c}, + {0x2046, 0x2046}, {0x207e, 0x207e}, {0x208e, 0x208e}, {0x232a, 0x232a}, + {0x23b5, 0x23b5}, {0x2769, 0x2769}, {0x276b, 0x276b}, {0x276d, 0x276d}, + {0x276f, 0x276f}, {0x2771, 0x2771}, {0x2773, 0x2773}, {0x2775, 0x2775}, + {0x27e7, 0x27e7}, {0x27e9, 0x27e9}, {0x27eb, 0x27eb}, {0x2984, 0x2984}, + {0x2986, 0x2986}, {0x2988, 0x2988}, {0x298a, 0x298a}, {0x298c, 0x298c}, + {0x298e, 0x298e}, {0x2990, 0x2990}, {0x2992, 0x2992}, {0x2994, 0x2994}, + {0x2996, 0x2996}, {0x2998, 0x2998}, {0x29d9, 0x29d9}, {0x29db, 0x29db}, + {0x29fd, 0x29fd}, {0x3009, 0x3009}, {0x300b, 0x300b}, {0x300d, 0x300d}, + {0x300f, 0x300f}, {0x3011, 0x3011}, {0x3015, 0x3015}, {0x3017, 0x3017}, + {0x3019, 0x3019}, {0x301b, 0x301b}, {0x301e, 0x301f}, {0xfd3f, 0xfd3f}, + {0xfe36, 0xfe36}, {0xfe38, 0xfe38}, {0xfe3a, 0xfe3a}, {0xfe3c, 0xfe3c}, + {0xfe3e, 0xfe3e}, {0xfe40, 0xfe40}, {0xfe42, 0xfe42}, {0xfe44, 0xfe44}, + {0xfe48, 0xfe48}, {0xfe5a, 0xfe5a}, {0xfe5c, 0xfe5c}, {0xfe5e, 0xfe5e}, + {0xff09, 0xff09}, {0xff3d, 0xff3d}, {0xff5d, 0xff5d}, {0xff60, 0xff60}, + {0xff63, 0xff63} }; static xmlChRangeGroup xmlPeG = {63,0,xmlPeS,NULL}; -static xmlChSRange xmlPoS[] = {{0x21, 0x23}, {0x25, 0x27}, {0x2a, 0x2a}, - {0x2c, 0x2c}, {0x2e, 0x2f}, {0x3a, 0x3b}, {0x3f, 0x40}, {0x5c, 0x5c}, - {0xa1, 0xa1}, {0xb7, 0xb7}, {0xbf, 0xbf}, {0x37e, 0x37e}, +static const xmlChSRange xmlPoS[] = {{0x21, 0x23}, {0x25, 0x27}, + {0x2a, 0x2a}, {0x2c, 0x2c}, {0x2e, 0x2f}, {0x3a, 0x3b}, {0x3f, 0x40}, + {0x5c, 0x5c}, {0xa1, 0xa1}, {0xb7, 0xb7}, {0xbf, 0xbf}, {0x37e, 0x37e}, {0x387, 0x387}, {0x55a, 0x55f}, {0x589, 0x589}, {0x5be, 0x5be}, {0x5c0, 0x5c0}, {0x5c3, 0x5c3}, {0x5f3, 0x5f4}, {0x60c, 0x60d}, {0x61b, 0x61b}, {0x61f, 0x61f}, {0x66a, 0x66d}, {0x6d4, 0x6d4}, @@ -793,62 +794,63 @@ static xmlChSRange xmlPoS[] = {{0x21, 0x23}, {0x25, 0x27}, {0x2a, 0x2a}, {0xfe68, 0xfe68}, {0xfe6a, 0xfe6b}, {0xff01, 0xff03}, {0xff05, 0xff07}, {0xff0a, 0xff0a}, {0xff0c, 0xff0c}, {0xff0e, 0xff0f}, {0xff1a, 0xff1b}, {0xff1f, 0xff20}, {0xff3c, 0xff3c}, {0xff61, 0xff61}, {0xff64, 0xff64} }; -static xmlChLRange xmlPoL[] = {{0x10100, 0x10101}, {0x1039f, 0x1039f} }; +static const xmlChLRange xmlPoL[] = {{0x10100, 0x10101}, {0x1039f, 0x1039f} }; static xmlChRangeGroup xmlPoG = {72,2,xmlPoS,xmlPoL}; -static xmlChSRange xmlPsS[] = {{0x28, 0x28}, {0x5b, 0x5b}, {0x7b, 0x7b}, - {0xf3a, 0xf3a}, {0xf3c, 0xf3c}, {0x169b, 0x169b}, {0x201a, 0x201a}, - {0x201e, 0x201e}, {0x2045, 0x2045}, {0x207d, 0x207d}, {0x208d, 0x208d}, - {0x2329, 0x2329}, {0x23b4, 0x23b4}, {0x2768, 0x2768}, {0x276a, 0x276a}, - {0x276c, 0x276c}, {0x276e, 0x276e}, {0x2770, 0x2770}, {0x2772, 0x2772}, - {0x2774, 0x2774}, {0x27e6, 0x27e6}, {0x27e8, 0x27e8}, {0x27ea, 0x27ea}, - {0x2983, 0x2983}, {0x2985, 0x2985}, {0x2987, 0x2987}, {0x2989, 0x2989}, - {0x298b, 0x298b}, {0x298d, 0x298d}, {0x298f, 0x298f}, {0x2991, 0x2991}, - {0x2993, 0x2993}, {0x2995, 0x2995}, {0x2997, 0x2997}, {0x29d8, 0x29d8}, - {0x29da, 0x29da}, {0x29fc, 0x29fc}, {0x3008, 0x3008}, {0x300a, 0x300a}, - {0x300c, 0x300c}, {0x300e, 0x300e}, {0x3010, 0x3010}, {0x3014, 0x3014}, - {0x3016, 0x3016}, {0x3018, 0x3018}, {0x301a, 0x301a}, {0x301d, 0x301d}, - {0xfd3e, 0xfd3e}, {0xfe35, 0xfe35}, {0xfe37, 0xfe37}, {0xfe39, 0xfe39}, - {0xfe3b, 0xfe3b}, {0xfe3d, 0xfe3d}, {0xfe3f, 0xfe3f}, {0xfe41, 0xfe41}, - {0xfe43, 0xfe43}, {0xfe47, 0xfe47}, {0xfe59, 0xfe59}, {0xfe5b, 0xfe5b}, - {0xfe5d, 0xfe5d}, {0xff08, 0xff08}, {0xff3b, 0xff3b}, {0xff5b, 0xff5b}, - {0xff5f, 0xff5f}, {0xff62, 0xff62} }; +static const xmlChSRange xmlPsS[] = {{0x28, 0x28}, {0x5b, 0x5b}, + {0x7b, 0x7b}, {0xf3a, 0xf3a}, {0xf3c, 0xf3c}, {0x169b, 0x169b}, + {0x201a, 0x201a}, {0x201e, 0x201e}, {0x2045, 0x2045}, {0x207d, 0x207d}, + {0x208d, 0x208d}, {0x2329, 0x2329}, {0x23b4, 0x23b4}, {0x2768, 0x2768}, + {0x276a, 0x276a}, {0x276c, 0x276c}, {0x276e, 0x276e}, {0x2770, 0x2770}, + {0x2772, 0x2772}, {0x2774, 0x2774}, {0x27e6, 0x27e6}, {0x27e8, 0x27e8}, + {0x27ea, 0x27ea}, {0x2983, 0x2983}, {0x2985, 0x2985}, {0x2987, 0x2987}, + {0x2989, 0x2989}, {0x298b, 0x298b}, {0x298d, 0x298d}, {0x298f, 0x298f}, + {0x2991, 0x2991}, {0x2993, 0x2993}, {0x2995, 0x2995}, {0x2997, 0x2997}, + {0x29d8, 0x29d8}, {0x29da, 0x29da}, {0x29fc, 0x29fc}, {0x3008, 0x3008}, + {0x300a, 0x300a}, {0x300c, 0x300c}, {0x300e, 0x300e}, {0x3010, 0x3010}, + {0x3014, 0x3014}, {0x3016, 0x3016}, {0x3018, 0x3018}, {0x301a, 0x301a}, + {0x301d, 0x301d}, {0xfd3e, 0xfd3e}, {0xfe35, 0xfe35}, {0xfe37, 0xfe37}, + {0xfe39, 0xfe39}, {0xfe3b, 0xfe3b}, {0xfe3d, 0xfe3d}, {0xfe3f, 0xfe3f}, + {0xfe41, 0xfe41}, {0xfe43, 0xfe43}, {0xfe47, 0xfe47}, {0xfe59, 0xfe59}, + {0xfe5b, 0xfe5b}, {0xfe5d, 0xfe5d}, {0xff08, 0xff08}, {0xff3b, 0xff3b}, + {0xff5b, 0xff5b}, {0xff5f, 0xff5f}, {0xff62, 0xff62} }; static xmlChRangeGroup xmlPsG = {65,0,xmlPsS,NULL}; -static xmlChSRange xmlSS[] = {{0x24, 0x24}, {0x2b, 0x2b}, {0x3c, 0x3e}, - {0x5e, 0x5e}, {0x60, 0x60}, {0x7c, 0x7c}, {0x7e, 0x7e}, {0xa2, 0xa9}, - {0xac, 0xac}, {0xae, 0xb1}, {0xb4, 0xb4}, {0xb6, 0xb6}, {0xb8, 0xb8}, - {0xd7, 0xd7}, {0xf7, 0xf7}, {0x2c2, 0x2c5}, {0x2d2, 0x2df}, - {0x2e5, 0x2ed}, {0x2ef, 0x2ff}, {0x374, 0x375}, {0x384, 0x385}, - {0x3f6, 0x3f6}, {0x482, 0x482}, {0x60e, 0x60f}, {0x6e9, 0x6e9}, - {0x6fd, 0x6fe}, {0x9f2, 0x9f3}, {0x9fa, 0x9fa}, {0xaf1, 0xaf1}, - {0xb70, 0xb70}, {0xbf3, 0xbfa}, {0xe3f, 0xe3f}, {0xf01, 0xf03}, - {0xf13, 0xf17}, {0xf1a, 0xf1f}, {0xf34, 0xf34}, {0xf36, 0xf36}, - {0xf38, 0xf38}, {0xfbe, 0xfc5}, {0xfc7, 0xfcc}, {0xfcf, 0xfcf}, - {0x17db, 0x17db}, {0x1940, 0x1940}, {0x19e0, 0x19ff}, {0x1fbd, 0x1fbd}, - {0x1fbf, 0x1fc1}, {0x1fcd, 0x1fcf}, {0x1fdd, 0x1fdf}, {0x1fed, 0x1fef}, - {0x1ffd, 0x1ffe}, {0x2044, 0x2044}, {0x2052, 0x2052}, {0x207a, 0x207c}, - {0x208a, 0x208c}, {0x20a0, 0x20b1}, {0x2100, 0x2101}, {0x2103, 0x2106}, - {0x2108, 0x2109}, {0x2114, 0x2114}, {0x2116, 0x2118}, {0x211e, 0x2123}, - {0x2125, 0x2125}, {0x2127, 0x2127}, {0x2129, 0x2129}, {0x212e, 0x212e}, - {0x2132, 0x2132}, {0x213a, 0x213b}, {0x2140, 0x2144}, {0x214a, 0x214b}, - {0x2190, 0x2328}, {0x232b, 0x23b3}, {0x23b7, 0x23d0}, {0x2400, 0x2426}, - {0x2440, 0x244a}, {0x249c, 0x24e9}, {0x2500, 0x2617}, {0x2619, 0x267d}, - {0x2680, 0x2691}, {0x26a0, 0x26a1}, {0x2701, 0x2704}, {0x2706, 0x2709}, - {0x270c, 0x2727}, {0x2729, 0x274b}, {0x274d, 0x274d}, {0x274f, 0x2752}, - {0x2756, 0x2756}, {0x2758, 0x275e}, {0x2761, 0x2767}, {0x2794, 0x2794}, - {0x2798, 0x27af}, {0x27b1, 0x27be}, {0x27d0, 0x27e5}, {0x27f0, 0x2982}, - {0x2999, 0x29d7}, {0x29dc, 0x29fb}, {0x29fe, 0x2b0d}, {0x2e80, 0x2e99}, - {0x2e9b, 0x2ef3}, {0x2f00, 0x2fd5}, {0x2ff0, 0x2ffb}, {0x3004, 0x3004}, - {0x3012, 0x3013}, {0x3020, 0x3020}, {0x3036, 0x3037}, {0x303e, 0x303f}, - {0x309b, 0x309c}, {0x3190, 0x3191}, {0x3196, 0x319f}, {0x3200, 0x321e}, - {0x322a, 0x3243}, {0x3250, 0x3250}, {0x3260, 0x327d}, {0x327f, 0x327f}, - {0x328a, 0x32b0}, {0x32c0, 0x32fe}, {0x3300, 0x33ff}, {0x4dc0, 0x4dff}, - {0xa490, 0xa4c6}, {0xfb29, 0xfb29}, {0xfdfc, 0xfdfd}, {0xfe62, 0xfe62}, - {0xfe64, 0xfe66}, {0xfe69, 0xfe69}, {0xff04, 0xff04}, {0xff0b, 0xff0b}, - {0xff1c, 0xff1e}, {0xff3e, 0xff3e}, {0xff40, 0xff40}, {0xff5c, 0xff5c}, - {0xff5e, 0xff5e}, {0xffe0, 0xffe6}, {0xffe8, 0xffee}, {0xfffc, 0xfffd} }; -static xmlChLRange xmlSL[] = {{0x10102, 0x10102}, {0x10137, 0x1013f}, +static const xmlChSRange xmlSS[] = {{0x24, 0x24}, {0x2b, 0x2b}, + {0x3c, 0x3e}, {0x5e, 0x5e}, {0x60, 0x60}, {0x7c, 0x7c}, {0x7e, 0x7e}, + {0xa2, 0xa9}, {0xac, 0xac}, {0xae, 0xb1}, {0xb4, 0xb4}, {0xb6, 0xb6}, + {0xb8, 0xb8}, {0xd7, 0xd7}, {0xf7, 0xf7}, {0x2c2, 0x2c5}, + {0x2d2, 0x2df}, {0x2e5, 0x2ed}, {0x2ef, 0x2ff}, {0x374, 0x375}, + {0x384, 0x385}, {0x3f6, 0x3f6}, {0x482, 0x482}, {0x60e, 0x60f}, + {0x6e9, 0x6e9}, {0x6fd, 0x6fe}, {0x9f2, 0x9f3}, {0x9fa, 0x9fa}, + {0xaf1, 0xaf1}, {0xb70, 0xb70}, {0xbf3, 0xbfa}, {0xe3f, 0xe3f}, + {0xf01, 0xf03}, {0xf13, 0xf17}, {0xf1a, 0xf1f}, {0xf34, 0xf34}, + {0xf36, 0xf36}, {0xf38, 0xf38}, {0xfbe, 0xfc5}, {0xfc7, 0xfcc}, + {0xfcf, 0xfcf}, {0x17db, 0x17db}, {0x1940, 0x1940}, {0x19e0, 0x19ff}, + {0x1fbd, 0x1fbd}, {0x1fbf, 0x1fc1}, {0x1fcd, 0x1fcf}, {0x1fdd, 0x1fdf}, + {0x1fed, 0x1fef}, {0x1ffd, 0x1ffe}, {0x2044, 0x2044}, {0x2052, 0x2052}, + {0x207a, 0x207c}, {0x208a, 0x208c}, {0x20a0, 0x20b1}, {0x2100, 0x2101}, + {0x2103, 0x2106}, {0x2108, 0x2109}, {0x2114, 0x2114}, {0x2116, 0x2118}, + {0x211e, 0x2123}, {0x2125, 0x2125}, {0x2127, 0x2127}, {0x2129, 0x2129}, + {0x212e, 0x212e}, {0x2132, 0x2132}, {0x213a, 0x213b}, {0x2140, 0x2144}, + {0x214a, 0x214b}, {0x2190, 0x2328}, {0x232b, 0x23b3}, {0x23b7, 0x23d0}, + {0x2400, 0x2426}, {0x2440, 0x244a}, {0x249c, 0x24e9}, {0x2500, 0x2617}, + {0x2619, 0x267d}, {0x2680, 0x2691}, {0x26a0, 0x26a1}, {0x2701, 0x2704}, + {0x2706, 0x2709}, {0x270c, 0x2727}, {0x2729, 0x274b}, {0x274d, 0x274d}, + {0x274f, 0x2752}, {0x2756, 0x2756}, {0x2758, 0x275e}, {0x2761, 0x2767}, + {0x2794, 0x2794}, {0x2798, 0x27af}, {0x27b1, 0x27be}, {0x27d0, 0x27e5}, + {0x27f0, 0x2982}, {0x2999, 0x29d7}, {0x29dc, 0x29fb}, {0x29fe, 0x2b0d}, + {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, {0x2f00, 0x2fd5}, {0x2ff0, 0x2ffb}, + {0x3004, 0x3004}, {0x3012, 0x3013}, {0x3020, 0x3020}, {0x3036, 0x3037}, + {0x303e, 0x303f}, {0x309b, 0x309c}, {0x3190, 0x3191}, {0x3196, 0x319f}, + {0x3200, 0x321e}, {0x322a, 0x3243}, {0x3250, 0x3250}, {0x3260, 0x327d}, + {0x327f, 0x327f}, {0x328a, 0x32b0}, {0x32c0, 0x32fe}, {0x3300, 0x33ff}, + {0x4dc0, 0x4dff}, {0xa490, 0xa4c6}, {0xfb29, 0xfb29}, {0xfdfc, 0xfdfd}, + {0xfe62, 0xfe62}, {0xfe64, 0xfe66}, {0xfe69, 0xfe69}, {0xff04, 0xff04}, + {0xff0b, 0xff0b}, {0xff1c, 0xff1e}, {0xff3e, 0xff3e}, {0xff40, 0xff40}, + {0xff5c, 0xff5c}, {0xff5e, 0xff5e}, {0xffe0, 0xffe6}, {0xffe8, 0xffee}, + {0xfffc, 0xfffd} }; +static const xmlChLRange xmlSL[] = {{0x10102, 0x10102}, {0x10137, 0x1013f}, {0x1d000, 0x1d0f5}, {0x1d100, 0x1d126}, {0x1d12a, 0x1d164}, {0x1d16a, 0x1d16c}, {0x1d183, 0x1d184}, {0x1d18c, 0x1d1a9}, {0x1d1ae, 0x1d1dd}, {0x1d300, 0x1d356}, {0x1d6c1, 0x1d6c1}, @@ -857,77 +859,79 @@ static xmlChLRange xmlSL[] = {{0x10102, 0x10102}, {0x10137, 0x1013f}, {0x1d789, 0x1d789}, {0x1d7a9, 0x1d7a9}, {0x1d7c3, 0x1d7c3} }; static xmlChRangeGroup xmlSG = {133,20,xmlSS,xmlSL}; -static xmlChSRange xmlScS[] = {{0x24, 0x24}, {0xa2, 0xa5}, {0x9f2, 0x9f3}, - {0xaf1, 0xaf1}, {0xbf9, 0xbf9}, {0xe3f, 0xe3f}, {0x17db, 0x17db}, - {0x20a0, 0x20b1}, {0xfdfc, 0xfdfc}, {0xfe69, 0xfe69}, {0xff04, 0xff04}, - {0xffe0, 0xffe1}, {0xffe5, 0xffe6} }; +static const xmlChSRange xmlScS[] = {{0x24, 0x24}, {0xa2, 0xa5}, + {0x9f2, 0x9f3}, {0xaf1, 0xaf1}, {0xbf9, 0xbf9}, {0xe3f, 0xe3f}, + {0x17db, 0x17db}, {0x20a0, 0x20b1}, {0xfdfc, 0xfdfc}, {0xfe69, 0xfe69}, + {0xff04, 0xff04}, {0xffe0, 0xffe1}, {0xffe5, 0xffe6} }; static xmlChRangeGroup xmlScG = {13,0,xmlScS,NULL}; -static xmlChSRange xmlSkS[] = {{0x5e, 0x5e}, {0x60, 0x60}, {0xa8, 0xa8}, - {0xaf, 0xaf}, {0xb4, 0xb4}, {0xb8, 0xb8}, {0x2c2, 0x2c5}, +static const xmlChSRange xmlSkS[] = {{0x5e, 0x5e}, {0x60, 0x60}, + {0xa8, 0xa8}, {0xaf, 0xaf}, {0xb4, 0xb4}, {0xb8, 0xb8}, {0x2c2, 0x2c5}, {0x2d2, 0x2df}, {0x2e5, 0x2ed}, {0x2ef, 0x2ff}, {0x374, 0x375}, {0x384, 0x385}, {0x1fbd, 0x1fbd}, {0x1fbf, 0x1fc1}, {0x1fcd, 0x1fcf}, {0x1fdd, 0x1fdf}, {0x1fed, 0x1fef}, {0x1ffd, 0x1ffe}, {0x309b, 0x309c}, {0xff3e, 0xff3e}, {0xff40, 0xff40}, {0xffe3, 0xffe3} }; static xmlChRangeGroup xmlSkG = {22,0,xmlSkS,NULL}; -static xmlChSRange xmlSmS[] = {{0x2b, 0x2b}, {0x3c, 0x3e}, {0x7c, 0x7c}, - {0x7e, 0x7e}, {0xac, 0xac}, {0xb1, 0xb1}, {0xd7, 0xd7}, {0xf7, 0xf7}, - {0x3f6, 0x3f6}, {0x2044, 0x2044}, {0x2052, 0x2052}, {0x207a, 0x207c}, - {0x208a, 0x208c}, {0x2140, 0x2144}, {0x214b, 0x214b}, {0x2190, 0x2194}, - {0x219a, 0x219b}, {0x21a0, 0x21a0}, {0x21a3, 0x21a3}, {0x21a6, 0x21a6}, - {0x21ae, 0x21ae}, {0x21ce, 0x21cf}, {0x21d2, 0x21d2}, {0x21d4, 0x21d4}, - {0x21f4, 0x22ff}, {0x2308, 0x230b}, {0x2320, 0x2321}, {0x237c, 0x237c}, - {0x239b, 0x23b3}, {0x25b7, 0x25b7}, {0x25c1, 0x25c1}, {0x25f8, 0x25ff}, - {0x266f, 0x266f}, {0x27d0, 0x27e5}, {0x27f0, 0x27ff}, {0x2900, 0x2982}, - {0x2999, 0x29d7}, {0x29dc, 0x29fb}, {0x29fe, 0x2aff}, {0xfb29, 0xfb29}, - {0xfe62, 0xfe62}, {0xfe64, 0xfe66}, {0xff0b, 0xff0b}, {0xff1c, 0xff1e}, - {0xff5c, 0xff5c}, {0xff5e, 0xff5e}, {0xffe2, 0xffe2}, {0xffe9, 0xffec} }; -static xmlChLRange xmlSmL[] = {{0x1d6c1, 0x1d6c1}, {0x1d6db, 0x1d6db}, +static const xmlChSRange xmlSmS[] = {{0x2b, 0x2b}, {0x3c, 0x3e}, + {0x7c, 0x7c}, {0x7e, 0x7e}, {0xac, 0xac}, {0xb1, 0xb1}, {0xd7, 0xd7}, + {0xf7, 0xf7}, {0x3f6, 0x3f6}, {0x2044, 0x2044}, {0x2052, 0x2052}, + {0x207a, 0x207c}, {0x208a, 0x208c}, {0x2140, 0x2144}, {0x214b, 0x214b}, + {0x2190, 0x2194}, {0x219a, 0x219b}, {0x21a0, 0x21a0}, {0x21a3, 0x21a3}, + {0x21a6, 0x21a6}, {0x21ae, 0x21ae}, {0x21ce, 0x21cf}, {0x21d2, 0x21d2}, + {0x21d4, 0x21d4}, {0x21f4, 0x22ff}, {0x2308, 0x230b}, {0x2320, 0x2321}, + {0x237c, 0x237c}, {0x239b, 0x23b3}, {0x25b7, 0x25b7}, {0x25c1, 0x25c1}, + {0x25f8, 0x25ff}, {0x266f, 0x266f}, {0x27d0, 0x27e5}, {0x27f0, 0x27ff}, + {0x2900, 0x2982}, {0x2999, 0x29d7}, {0x29dc, 0x29fb}, {0x29fe, 0x2aff}, + {0xfb29, 0xfb29}, {0xfe62, 0xfe62}, {0xfe64, 0xfe66}, {0xff0b, 0xff0b}, + {0xff1c, 0xff1e}, {0xff5c, 0xff5c}, {0xff5e, 0xff5e}, {0xffe2, 0xffe2}, + {0xffe9, 0xffec} }; +static const xmlChLRange xmlSmL[] = {{0x1d6c1, 0x1d6c1}, {0x1d6db, 0x1d6db}, {0x1d6fb, 0x1d6fb}, {0x1d715, 0x1d715}, {0x1d735, 0x1d735}, {0x1d74f, 0x1d74f}, {0x1d76f, 0x1d76f}, {0x1d789, 0x1d789}, {0x1d7a9, 0x1d7a9}, {0x1d7c3, 0x1d7c3} }; static xmlChRangeGroup xmlSmG = {48,10,xmlSmS,xmlSmL}; -static xmlChSRange xmlSoS[] = {{0xa6, 0xa7}, {0xa9, 0xa9}, {0xae, 0xae}, - {0xb0, 0xb0}, {0xb6, 0xb6}, {0x482, 0x482}, {0x60e, 0x60f}, - {0x6e9, 0x6e9}, {0x6fd, 0x6fe}, {0x9fa, 0x9fa}, {0xb70, 0xb70}, - {0xbf3, 0xbf8}, {0xbfa, 0xbfa}, {0xf01, 0xf03}, {0xf13, 0xf17}, - {0xf1a, 0xf1f}, {0xf34, 0xf34}, {0xf36, 0xf36}, {0xf38, 0xf38}, - {0xfbe, 0xfc5}, {0xfc7, 0xfcc}, {0xfcf, 0xfcf}, {0x1940, 0x1940}, - {0x19e0, 0x19ff}, {0x2100, 0x2101}, {0x2103, 0x2106}, {0x2108, 0x2109}, - {0x2114, 0x2114}, {0x2116, 0x2118}, {0x211e, 0x2123}, {0x2125, 0x2125}, - {0x2127, 0x2127}, {0x2129, 0x2129}, {0x212e, 0x212e}, {0x2132, 0x2132}, - {0x213a, 0x213b}, {0x214a, 0x214a}, {0x2195, 0x2199}, {0x219c, 0x219f}, - {0x21a1, 0x21a2}, {0x21a4, 0x21a5}, {0x21a7, 0x21ad}, {0x21af, 0x21cd}, - {0x21d0, 0x21d1}, {0x21d3, 0x21d3}, {0x21d5, 0x21f3}, {0x2300, 0x2307}, - {0x230c, 0x231f}, {0x2322, 0x2328}, {0x232b, 0x237b}, {0x237d, 0x239a}, - {0x23b7, 0x23d0}, {0x2400, 0x2426}, {0x2440, 0x244a}, {0x249c, 0x24e9}, - {0x2500, 0x25b6}, {0x25b8, 0x25c0}, {0x25c2, 0x25f7}, {0x2600, 0x2617}, - {0x2619, 0x266e}, {0x2670, 0x267d}, {0x2680, 0x2691}, {0x26a0, 0x26a1}, - {0x2701, 0x2704}, {0x2706, 0x2709}, {0x270c, 0x2727}, {0x2729, 0x274b}, - {0x274d, 0x274d}, {0x274f, 0x2752}, {0x2756, 0x2756}, {0x2758, 0x275e}, - {0x2761, 0x2767}, {0x2794, 0x2794}, {0x2798, 0x27af}, {0x27b1, 0x27be}, - {0x2800, 0x28ff}, {0x2b00, 0x2b0d}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, - {0x2f00, 0x2fd5}, {0x2ff0, 0x2ffb}, {0x3004, 0x3004}, {0x3012, 0x3013}, - {0x3020, 0x3020}, {0x3036, 0x3037}, {0x303e, 0x303f}, {0x3190, 0x3191}, - {0x3196, 0x319f}, {0x3200, 0x321e}, {0x322a, 0x3243}, {0x3250, 0x3250}, - {0x3260, 0x327d}, {0x327f, 0x327f}, {0x328a, 0x32b0}, {0x32c0, 0x32fe}, - {0x3300, 0x33ff}, {0x4dc0, 0x4dff}, {0xa490, 0xa4c6}, {0xfdfd, 0xfdfd}, - {0xffe4, 0xffe4}, {0xffe8, 0xffe8}, {0xffed, 0xffee}, {0xfffc, 0xfffd} }; -static xmlChLRange xmlSoL[] = {{0x10102, 0x10102}, {0x10137, 0x1013f}, +static const xmlChSRange xmlSoS[] = {{0xa6, 0xa7}, {0xa9, 0xa9}, + {0xae, 0xae}, {0xb0, 0xb0}, {0xb6, 0xb6}, {0x482, 0x482}, + {0x60e, 0x60f}, {0x6e9, 0x6e9}, {0x6fd, 0x6fe}, {0x9fa, 0x9fa}, + {0xb70, 0xb70}, {0xbf3, 0xbf8}, {0xbfa, 0xbfa}, {0xf01, 0xf03}, + {0xf13, 0xf17}, {0xf1a, 0xf1f}, {0xf34, 0xf34}, {0xf36, 0xf36}, + {0xf38, 0xf38}, {0xfbe, 0xfc5}, {0xfc7, 0xfcc}, {0xfcf, 0xfcf}, + {0x1940, 0x1940}, {0x19e0, 0x19ff}, {0x2100, 0x2101}, {0x2103, 0x2106}, + {0x2108, 0x2109}, {0x2114, 0x2114}, {0x2116, 0x2118}, {0x211e, 0x2123}, + {0x2125, 0x2125}, {0x2127, 0x2127}, {0x2129, 0x2129}, {0x212e, 0x212e}, + {0x2132, 0x2132}, {0x213a, 0x213b}, {0x214a, 0x214a}, {0x2195, 0x2199}, + {0x219c, 0x219f}, {0x21a1, 0x21a2}, {0x21a4, 0x21a5}, {0x21a7, 0x21ad}, + {0x21af, 0x21cd}, {0x21d0, 0x21d1}, {0x21d3, 0x21d3}, {0x21d5, 0x21f3}, + {0x2300, 0x2307}, {0x230c, 0x231f}, {0x2322, 0x2328}, {0x232b, 0x237b}, + {0x237d, 0x239a}, {0x23b7, 0x23d0}, {0x2400, 0x2426}, {0x2440, 0x244a}, + {0x249c, 0x24e9}, {0x2500, 0x25b6}, {0x25b8, 0x25c0}, {0x25c2, 0x25f7}, + {0x2600, 0x2617}, {0x2619, 0x266e}, {0x2670, 0x267d}, {0x2680, 0x2691}, + {0x26a0, 0x26a1}, {0x2701, 0x2704}, {0x2706, 0x2709}, {0x270c, 0x2727}, + {0x2729, 0x274b}, {0x274d, 0x274d}, {0x274f, 0x2752}, {0x2756, 0x2756}, + {0x2758, 0x275e}, {0x2761, 0x2767}, {0x2794, 0x2794}, {0x2798, 0x27af}, + {0x27b1, 0x27be}, {0x2800, 0x28ff}, {0x2b00, 0x2b0d}, {0x2e80, 0x2e99}, + {0x2e9b, 0x2ef3}, {0x2f00, 0x2fd5}, {0x2ff0, 0x2ffb}, {0x3004, 0x3004}, + {0x3012, 0x3013}, {0x3020, 0x3020}, {0x3036, 0x3037}, {0x303e, 0x303f}, + {0x3190, 0x3191}, {0x3196, 0x319f}, {0x3200, 0x321e}, {0x322a, 0x3243}, + {0x3250, 0x3250}, {0x3260, 0x327d}, {0x327f, 0x327f}, {0x328a, 0x32b0}, + {0x32c0, 0x32fe}, {0x3300, 0x33ff}, {0x4dc0, 0x4dff}, {0xa490, 0xa4c6}, + {0xfdfd, 0xfdfd}, {0xffe4, 0xffe4}, {0xffe8, 0xffe8}, {0xffed, 0xffee}, + {0xfffc, 0xfffd} }; +static const xmlChLRange xmlSoL[] = {{0x10102, 0x10102}, {0x10137, 0x1013f}, {0x1d000, 0x1d0f5}, {0x1d100, 0x1d126}, {0x1d12a, 0x1d164}, {0x1d16a, 0x1d16c}, {0x1d183, 0x1d184}, {0x1d18c, 0x1d1a9}, {0x1d1ae, 0x1d1dd}, {0x1d300, 0x1d356} }; static xmlChRangeGroup xmlSoG = {103,10,xmlSoS,xmlSoL}; -static xmlChSRange xmlZS[] = {{0x20, 0x20}, {0xa0, 0xa0}, {0x1680, 0x1680}, - {0x180e, 0x180e}, {0x2000, 0x200b}, {0x2028, 0x2029}, {0x202f, 0x202f}, - {0x205f, 0x205f}, {0x3000, 0x3000} }; +static const xmlChSRange xmlZS[] = {{0x20, 0x20}, {0xa0, 0xa0}, + {0x1680, 0x1680}, {0x180e, 0x180e}, {0x2000, 0x200a}, {0x2028, 0x2029}, + {0x202f, 0x202f}, {0x205f, 0x205f}, {0x3000, 0x3000} }; static xmlChRangeGroup xmlZG = {9,0,xmlZS,NULL}; -xmlUnicodeNameTable xmlUnicodeBlockTbl = {xmlUnicodeBlocks, 128}; -xmlUnicodeNameTable xmlUnicodeCatTbl = {xmlUnicodeCats, 36}; +static xmlUnicodeNameTable xmlUnicodeBlockTbl = {xmlUnicodeBlocks, 128}; +static xmlUnicodeNameTable xmlUnicodeCatTbl = {xmlUnicodeCats, 36}; /** * xmlUnicodeLookup: @@ -3145,7 +3149,7 @@ xmlUCSIsCatZs(int code) { (code == 0xa0) || (code == 0x1680) || (code == 0x180e) || - ((code >= 0x2000) && (code <= 0x200b)) || + ((code >= 0x2000) && (code <= 0x200a)) || (code == 0x202f) || (code == 0x205f) || (code == 0x3000)); @@ -3170,7 +3174,6 @@ xmlUCSIsCat(int code, const char *cat) { return (func(code)); } - #define bottom_xmlunicode #include "elfgcchack.h" #endif /* LIBXML_UNICODE_ENABLED */ diff --git a/Extras/LibXML/xmlwriter.c b/Extras/LibXML/xmlwriter.c index a974dffcd..43934b36b 100644 --- a/Extras/LibXML/xmlwriter.c +++ b/Extras/LibXML/xmlwriter.c @@ -24,6 +24,25 @@ #define B64LINELEN 72 #define B64CRLF "\r\n" +/* + * The following VA_COPY was coded following an example in + * the Samba project. It may not be sufficient for some + * esoteric implementations of va_list (i.e. it may need + * something involving a memcpy) but (hopefully) will be + * sufficient for libxml2. + */ +#ifndef VA_COPY + #ifdef HAVE_VA_COPY + #define VA_COPY(dest, src) va_copy(dest, src) + #else + #ifdef HAVE___VA_COPY + #define VA_COPY(dest,src) __va_copy(dest, src) + #else + #define VA_COPY(dest,src) (dest) = (src) + #endif + #endif +#endif + /* * Types are kept private */ @@ -65,34 +84,31 @@ struct _xmlTextWriter { xmlOutputBufferPtr out; /* output buffer */ xmlListPtr nodes; /* element name stack */ xmlListPtr nsstack; /* name spaces stack */ - intptr_t level; - intptr_t indent; /* enable indent */ - intptr_t doindent; /* internal indent flag */ + int level; + int indent; /* enable indent */ + int doindent; /* internal indent flag */ xmlChar *ichar; /* indent character */ char qchar; /* character used for quoting attribute values */ xmlParserCtxtPtr ctxt; - intptr_t no_doc_free; + int no_doc_free; }; static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk); -static intptr_t xmlCmpTextWriterStackEntry(const void *data0, +static int xmlCmpTextWriterStackEntry(const void *data0, const void *data1); static void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk); -static intptr_t xmlCmpTextWriterNsStackEntry(const void *data0, +static int xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1); -static intptr_t xmlTextWriterWriteMemCallback(void *context, - const xmlChar * str, intptr_t len); -static intptr_t xmlTextWriterCloseMemCallback(void *context); -static intptr_t xmlTextWriterWriteDocCallback(void *context, - const xmlChar * str, intptr_t len); -static intptr_t xmlTextWriterCloseDocCallback(void *context); +static int xmlTextWriterWriteDocCallback(void *context, + const xmlChar * str, int len); +static int xmlTextWriterCloseDocCallback(void *context); static xmlChar *xmlTextWriterVSprintf(const char *format, va_list argptr); -static intptr_t xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, intptr_t len, +static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len, const unsigned char *data); static void xmlTextWriterStartDocumentCallback(void *ctx); -static intptr_t xmlTextWriterWriteIndent(xmlTextWriterPtr writer); -static intptr_t +static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer); +static int xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer, xmlTextWriterStackEntry * p); @@ -123,7 +139,7 @@ xmlWriterErrMsg(xmlTextWriterPtr ctxt, xmlParserErrors error, * @ctxt: a writer context * @error: the error number * @msg: the error message - * @val: an integer + * @val: an int * * Handle a writer error */ @@ -256,11 +272,8 @@ xmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED) xmlOutputBufferPtr out; /*::todo handle compression */ - out = xmlOutputBufferCreateIO((xmlOutputWriteCallback) - xmlTextWriterWriteMemCallback, - (xmlOutputCloseCallback) - xmlTextWriterCloseMemCallback, - (void *) buf, NULL); + out = xmlOutputBufferCreateBuffer(buf, NULL); + if (out == NULL) { xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY, "xmlNewTextWriterMemory : out of memory!\n"); @@ -490,12 +503,12 @@ xmlFreeTextWriter(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version, const char *encoding, const char *standalone) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlCharEncodingHandlerPtr encoder; @@ -605,11 +618,11 @@ xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndDocument(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -688,11 +701,11 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartComment(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -739,7 +752,7 @@ xmlTextWriterStartComment(xmlTextWriterPtr writer) return -1; } - p->name = 0; + p->name = NULL; p->state = XML_TEXTWRITER_COMMENT; xmlListPushFront(writer->nodes, p); @@ -767,11 +780,11 @@ xmlTextWriterStartComment(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndComment(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -825,11 +838,11 @@ xmlTextWriterEndComment(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -850,11 +863,11 @@ xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) { @@ -882,11 +895,11 @@ xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartComment(writer); @@ -914,11 +927,11 @@ xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1006,19 +1019,19 @@ xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlChar *buf; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; - buf = 0; + buf = NULL; if (prefix != 0) { buf = xmlStrdup(prefix); buf = xmlStrcat(buf, BAD_CAST ":"); @@ -1057,11 +1070,11 @@ xmlTextWriterStartElementNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndElement(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1134,11 +1147,11 @@ xmlTextWriterEndElement(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterFullEndElement(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1200,11 +1213,11 @@ xmlTextWriterFullEndElement(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -1225,11 +1238,11 @@ xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -1256,12 +1269,12 @@ xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content, - intptr_t len) + int len) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1310,7 +1323,7 @@ xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content) { return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content)); @@ -1326,11 +1339,11 @@ xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; if ((writer == NULL) || (format == NULL)) @@ -1354,11 +1367,11 @@ xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if ((writer == NULL) || (format == NULL)) @@ -1383,11 +1396,11 @@ xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; xmlChar *buf; @@ -1445,8 +1458,8 @@ xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -static intptr_t -xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, intptr_t len, +static int +xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len, const unsigned char *data) { static unsigned char dtable[64] = @@ -1456,10 +1469,10 @@ xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, intptr_t len, 'n','o','p','q','r','s','t','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9','+','/'}; - intptr_t i; - intptr_t linelen; - intptr_t count; - intptr_t sum; + int i; + int linelen; + int count; + int sum; if ((out == NULL) || (len < 0) || (data == NULL)) return(-1); @@ -1471,8 +1484,8 @@ xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, intptr_t len, while (1) { unsigned char igroup[3]; unsigned char ogroup[4]; - intptr_t c; - intptr_t n; + int c; + int n; igroup[0] = igroup[1] = igroup[2] = 0; for (n = 0; n < 3 && i < len; n++, i++) { @@ -1527,12 +1540,12 @@ xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, intptr_t len, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data, - intptr_t start, intptr_t len) + int start, int len) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1576,15 +1589,15 @@ xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data, * Returns the bytes written (may be 0 because of buffering) * or -1 in case of error */ -static intptr_t +static int xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out, - intptr_t len, const unsigned char *data) + int len, const unsigned char *data) { - intptr_t count; - intptr_t sum; + int count; + int sum; static char hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; - intptr_t i; + int i; if ((out == NULL) || (data == NULL) || (len < 0)) { return -1; @@ -1620,12 +1633,12 @@ xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data, - intptr_t start, intptr_t len) + int start, int len) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1666,11 +1679,11 @@ xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -1732,20 +1745,20 @@ xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlChar *buf; xmlTextWriterNsStackEntry *p; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; - buf = 0; + buf = NULL; if (prefix != 0) { buf = xmlStrdup(prefix); buf = xmlStrcat(buf, BAD_CAST ":"); @@ -1798,11 +1811,11 @@ xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndAttribute(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; xmlTextWriterNsStackEntry *np; @@ -1887,12 +1900,12 @@ xmlTextWriterEndAttribute(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -1914,12 +1927,12 @@ xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -1945,12 +1958,12 @@ xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartAttribute(writer, name); @@ -1982,14 +1995,14 @@ xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2014,14 +2027,14 @@ xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -2050,20 +2063,20 @@ xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlChar *buf; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; - buf = 0; + buf = NULL; if (prefix != NULL) { buf = xmlStrdup(prefix); buf = xmlStrcat(buf, BAD_CAST ":"); @@ -2078,7 +2091,7 @@ xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, sum += count; if (namespaceURI != NULL) { - buf = 0; + buf = NULL; buf = xmlStrdup(BAD_CAST "xmlns"); if (prefix != NULL) { buf = xmlStrcat(buf, BAD_CAST ":"); @@ -2104,12 +2117,12 @@ xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2131,12 +2144,12 @@ xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -2162,12 +2175,12 @@ xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartElement(writer, name); @@ -2199,14 +2212,14 @@ xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2231,14 +2244,14 @@ xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -2267,14 +2280,14 @@ xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, const xmlChar * name, const xmlChar * namespaceURI, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; if ((writer == NULL) || (name == NULL) || (*name == '\0')) return -1; @@ -2306,11 +2319,11 @@ xmlTextWriterWriteElementNS(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2397,11 +2410,11 @@ xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndPI(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2429,6 +2442,13 @@ xmlTextWriterEndPI(xmlTextWriterPtr writer) return -1; } + if (writer->indent) { + count = xmlOutputBufferWriteString(writer->out, "\n"); + if (count < 0) + return -1; + sum += count; + } + xmlListPopFront(writer->nodes); return sum; } @@ -2444,11 +2464,11 @@ xmlTextWriterEndPI(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2470,12 +2490,12 @@ xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer, const xmlChar * target, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -2501,12 +2521,12 @@ xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartPI(writer, target); @@ -2535,11 +2555,11 @@ xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartCDATA(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2587,7 +2607,7 @@ xmlTextWriterStartCDATA(xmlTextWriterPtr writer) return -1; } - p->name = 0; + p->name = NULL; p->state = XML_TEXTWRITER_CDATA; xmlListPushFront(writer->nodes, p); @@ -2608,11 +2628,11 @@ xmlTextWriterStartCDATA(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndCDATA(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2653,11 +2673,11 @@ xmlTextWriterEndCDATA(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2678,11 +2698,11 @@ xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -2707,11 +2727,11 @@ xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartCDATA(writer); @@ -2743,13 +2763,13 @@ xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2842,8 +2862,11 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, if (count < 0) return -1; sum += count; - } else if (writer->indent) { + } else { + if (writer->indent) count = xmlOutputBufferWriteString(writer->out, "\n "); + else + count = xmlOutputBufferWrite(writer->out, 1, " "); if (count < 0) return -1; sum += count; @@ -2877,12 +2900,12 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndDTD(xmlTextWriterPtr writer) { - intptr_t loop; - intptr_t count; - intptr_t sum; + int loop; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -2959,13 +2982,13 @@ xmlTextWriterEndDTD(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -2990,14 +3013,14 @@ xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -3025,14 +3048,14 @@ xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTD(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const xmlChar * subset) { - intptr_t count; - intptr_t sum; + int count; + int sum; sum = 0; count = xmlTextWriterStartDTD(writer, name, pubid, sysid); @@ -3062,11 +3085,11 @@ xmlTextWriterWriteDTD(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3149,11 +3172,11 @@ xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndDTDElement(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3203,12 +3226,12 @@ xmlTextWriterEndDTDElement(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -3230,12 +3253,12 @@ xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -3261,12 +3284,12 @@ xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; if (content == NULL) return -1; @@ -3299,11 +3322,11 @@ xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3386,11 +3409,11 @@ xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3440,12 +3463,12 @@ xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -3467,12 +3490,12 @@ xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -3498,12 +3521,12 @@ xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; if (content == NULL) return -1; @@ -3537,12 +3560,12 @@ xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, - intptr_t pe, const xmlChar * name) + int pe, const xmlChar * name) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3637,11 +3660,11 @@ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -3697,13 +3720,13 @@ xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer) * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int XMLCDECL xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const char *format, ...) { - intptr_t rc; + int rc; va_list ap; va_start(ap, format); @@ -3727,14 +3750,14 @@ xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const char *format, va_list argptr) { - intptr_t rc; + int rc; xmlChar *buf; if (writer == NULL) @@ -3764,9 +3787,9 @@ xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, @@ -3797,14 +3820,14 @@ xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const xmlChar * content) { - intptr_t count; - intptr_t sum; + int count; + int sum; if ((name == NULL) || (*name == '\0') || (content == NULL)) return -1; @@ -3841,16 +3864,16 @@ xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, - intptr_t pe, + int pe, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid, const xmlChar * ndataid) { - intptr_t count; - intptr_t sum; + int count; + int sum; if (((pubid == NULL) && (sysid == NULL))) return -1; @@ -3889,14 +3912,14 @@ xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer, const xmlChar * pubid, const xmlChar * sysid, const xmlChar * ndataid) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -4021,13 +4044,13 @@ xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer, const xmlChar * name, const xmlChar * pubid, const xmlChar * sysid) { - intptr_t count; - intptr_t sum; + int count; + int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; @@ -4141,10 +4164,10 @@ xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer, * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ -intptr_t +int xmlTextWriterFlush(xmlTextWriterPtr writer) { - intptr_t count; + int count; if (writer == NULL) return -1; @@ -4190,7 +4213,7 @@ xmlFreeTextWriterStackEntry(xmlLinkPtr lk) * * Returns -1, 0, 1 */ -static intptr_t +static int xmlCmpTextWriterStackEntry(const void *data0, const void *data1) { xmlTextWriterStackEntry *p0; @@ -4247,12 +4270,12 @@ xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk) * * Returns -1, 0, 1 */ -static intptr_t +static int xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1) { xmlTextWriterNsStackEntry *p0; xmlTextWriterNsStackEntry *p1; - intptr_t rc; + int rc; if (data0 == data1) return 0; @@ -4274,40 +4297,6 @@ xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1) return rc; } -/** - * xmlTextWriterWriteMemCallback: - * @context: the xmlBufferPtr - * @str: the data to write - * @len: the length of the data - * - * Write callback for the xmlOutputBuffer with target xmlBuffer - * - * Returns -1, 0, 1 - */ -static intptr_t -xmlTextWriterWriteMemCallback(void *context, const xmlChar * str, intptr_t len) -{ - xmlBufferPtr buf = (xmlBufferPtr) context; - - xmlBufferAdd(buf, str, len); - - return len; -} - -/** - * xmlTextWriterCloseMemCallback: - * @context: the xmlBufferPtr - * - * Close callback for the xmlOutputBuffer with target xmlBuffer - * - * Returns -1, 0, 1 - */ -static intptr_t -xmlTextWriterCloseMemCallback(void *context ATTRIBUTE_UNUSED) -{ - return 0; -} - /** * xmlTextWriterWriteDocCallback: * @context: the xmlBufferPtr @@ -4318,8 +4307,8 @@ xmlTextWriterCloseMemCallback(void *context ATTRIBUTE_UNUSED) * * Returns -1, 0, 1 */ -static intptr_t -xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, intptr_t len) +static int +xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context; int rc; @@ -4342,7 +4331,7 @@ xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, intptr_t len) * * Returns -1, 0, 1 */ -static intptr_t +static int xmlTextWriterCloseDocCallback(void *context) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context; @@ -4370,9 +4359,10 @@ xmlTextWriterCloseDocCallback(void *context) static xmlChar * xmlTextWriterVSprintf(const char *format, va_list argptr) { - intptr_t size; - intptr_t count; + int size; + int count; xmlChar *buf; + va_list locarg; size = BUFSIZ; buf = (xmlChar *) xmlMalloc(size); @@ -4382,8 +4372,10 @@ xmlTextWriterVSprintf(const char *format, va_list argptr) return NULL; } - while (((count = vsnprintf((char *) buf, size, format, argptr)) < 0) + VA_COPY(locarg, argptr); + while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0) || (count == size - 1) || (count == size) || (count > size)) { + va_end(locarg); xmlFree(buf); size += BUFSIZ; buf = (xmlChar *) xmlMalloc(size); @@ -4392,7 +4384,9 @@ xmlTextWriterVSprintf(const char *format, va_list argptr) "xmlTextWriterVSprintf : out of memory!\n"); return NULL; } + VA_COPY(locarg, argptr); } + va_end(locarg); return buf; } @@ -4471,8 +4465,8 @@ xmlTextWriterStartDocumentCallback(void *ctx) * * Returns -1 on error or 0 otherwise. */ -intptr_t -xmlTextWriterSetIndent(xmlTextWriterPtr writer, intptr_t indent) +int +xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent) { if ((writer == NULL) || (indent < 0)) return -1; @@ -4492,7 +4486,7 @@ xmlTextWriterSetIndent(xmlTextWriterPtr writer, intptr_t indent) * * Returns -1 on error or 0 otherwise. */ -intptr_t +int xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str) { if ((writer == NULL) || (!str)) @@ -4516,12 +4510,12 @@ xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str) * * Returns -1 on error or the number of strings written. */ -static intptr_t +static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer) { - intptr_t lksize; - intptr_t i; - intptr_t ret; + int lksize; + int i; + int ret; lksize = xmlListSize(writer->nodes); if (lksize < 1) @@ -4545,12 +4539,12 @@ xmlTextWriterWriteIndent(xmlTextWriterPtr writer) * * Returns -1 on error or the number of characters written. */ -static intptr_t +static int xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer, xmlTextWriterStackEntry * p) { - intptr_t count; - intptr_t sum; + int count; + int sum; char extra[3]; if (writer == NULL)