rolled back to 2.9.2 because 2.9.4 doesn't work with XML validator
[platform/upstream/libxml2.git] / xmlschemas.c
index e1b3a4f..0657b66 100644 (file)
@@ -617,7 +617,7 @@ struct _xmlSchemaParserCtxt {
     xmlAutomataStatePtr end;
     xmlAutomataStatePtr state;
 
-    xmlDictPtr dict;           /* dictionary for interned string names */
+    xmlDictPtr dict;           /* dictionnary for interned string names */
     xmlSchemaTypePtr ctxtType; /* The current context simple/complex type */
     int options;
     xmlSchemaValidCtxtPtr vctxt;
@@ -1085,7 +1085,7 @@ xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
 static void
 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
-                    const char *message) LIBXML_ATTR_FORMAT(3,0);
+                    const char *message);
 static int
 xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
                             xmlSchemaTypePtr type,
@@ -1769,7 +1769,7 @@ xmlSchemaFormatItemForReport(xmlChar **buf,
     }
     FREE_AND_NULL(str)
 
-    return (xmlEscapeFormatString(buf));
+    return (*buf);
 }
 
 /**
@@ -1889,7 +1889,7 @@ xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
  *
  * Handle a parser error
  */
-static void LIBXML_ATTR_FORMAT(4,0)
+static void
 xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
               const char *msg, const xmlChar * str1, const xmlChar * str2)
 {
@@ -1922,7 +1922,7 @@ xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
  *
  * Handle a parser error
  */
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
                xmlNodePtr child, int error,
                const char *msg, const xmlChar * str1, const xmlChar * str2)
@@ -1951,7 +1951,7 @@ xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
  *
  * Handle a parser error
  */
-static void LIBXML_ATTR_FORMAT(7,0)
+static void
 xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
                const xmlChar * strData1, const xmlChar * strData2,
                const xmlChar * strData3, const char *msg, const xmlChar * str1,
@@ -2002,7 +2002,7 @@ xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
                      extra);
 }
 
-static void LIBXML_ATTR_FORMAT(2,0)
+static void
 xmlSchemaPSimpleInternalErr(xmlNodePtr node,
                            const char *msg, const xmlChar *str)
 {
@@ -2013,21 +2013,18 @@ xmlSchemaPSimpleInternalErr(xmlNodePtr node,
 #define WXS_ERROR_TYPE_ERROR 1
 #define WXS_ERROR_TYPE_WARNING 2
 /**
- * xmlSchemaErr4Line:
+ * xmlSchemaErr3:
  * @ctxt: the validation context
- * @errorLevel: the error level
- * @error: the error code
  * @node: the context node
- * @line: the line number
+ * @error: the error code
  * @msg: the error message
  * @str1: extra data
  * @str2: extra data
  * @str3: extra data
- * @str4: extra data
  *
  * Handle a validation error
  */
-static void LIBXML_ATTR_FORMAT(6,0)
+static void
 xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
                  xmlErrorLevel errorLevel,
                  int error, xmlNodePtr node, int line, const char *msg,
@@ -2142,7 +2139,7 @@ xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
  *
  * Handle a validation error
  */
-static void LIBXML_ATTR_FORMAT(4,0)
+static void
 xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
              int error, xmlNodePtr node, const char *msg,
              const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
@@ -2151,7 +2148,7 @@ xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
        msg, str1, str2, str3, NULL);
 }
 
-static void LIBXML_ATTR_FORMAT(4,0)
+static void
 xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
              int error, xmlNodePtr node, const char *msg,
              const xmlChar *str1, const xmlChar *str2,
@@ -2161,7 +2158,7 @@ xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
        msg, str1, str2, str3, str4);
 }
 
-static void LIBXML_ATTR_FORMAT(4,0)
+static void
 xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
             int error, xmlNodePtr node, const char *msg,
             const xmlChar *str1, const xmlChar *str2)
@@ -2184,7 +2181,7 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
        /*
        * Don't try to format other nodes than element and
        * attribute nodes.
-       * Play safe and return an empty string.
+       * Play save and return an empty string.
        */
        *msg = xmlStrdup(BAD_CAST "");
        return(*msg);
@@ -2249,13 +2246,6 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
        TODO
        return (NULL);
     }
-
-    /*
-     * xmlSchemaFormatItemForReport() also returns an escaped format
-     * string, so do this before calling it below (in the future).
-     */
-    xmlEscapeFormatString(msg);
-
     /*
     * VAL TODO: The output of the given schema component is currently
     * disabled.
@@ -2272,7 +2262,7 @@ xmlSchemaFormatNodeForError(xmlChar ** msg,
     return (*msg);
 }
 
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
                     const char *message,
@@ -2283,21 +2273,24 @@ xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
 
     if (actxt == NULL)
         return;
-    msg = xmlStrdup(BAD_CAST "Internal error: %s, ");
+    msg = xmlStrdup(BAD_CAST "Internal error: ");
+    msg = xmlStrcat(msg, BAD_CAST funcName);
+    msg = xmlStrcat(msg, BAD_CAST ", ");
     msg = xmlStrcat(msg, BAD_CAST message);
     msg = xmlStrcat(msg, BAD_CAST ".\n");
 
     if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
-       xmlSchemaErr3(actxt, XML_SCHEMAV_INTERNAL, NULL,
-           (const char *) msg, (const xmlChar *) funcName, str1, str2);
+       xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL,
+           (const char *) msg, str1, str2);
+
     else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
-       xmlSchemaErr3(actxt, XML_SCHEMAP_INTERNAL, NULL,
-           (const char *) msg, (const xmlChar *) funcName, str1, str2);
+       xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL,
+           (const char *) msg, str1, str2);
 
     FREE_AND_NULL(msg)
 }
 
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
                     const char *funcName,
                     const char *message)
@@ -2306,7 +2299,7 @@ xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
 }
 
 #if 0
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
                     const char *funcName,
                     const char *message,
@@ -2318,7 +2311,7 @@ xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
 }
 #endif
 
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2343,7 +2336,7 @@ xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
     FREE_AND_NULL(msg)
 }
 
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2358,7 +2351,7 @@ xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
 
 
 
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
                   xmlParserErrors error,
                   xmlNodePtr node,
@@ -2383,7 +2376,7 @@ xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
 
 
 
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
                   xmlParserErrors error,
                   xmlSchemaPSVIIDCNodePtr idcNode,
@@ -2483,13 +2476,11 @@ xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
        msg = xmlStrcat(msg, BAD_CAST " '");
        if (type->builtInType != 0) {
            msg = xmlStrcat(msg, BAD_CAST "xs:");
-           str = xmlStrdup(type->name);
-       } else {
-           const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
-           if (!str)
-               str = xmlStrdup(qName);
-       }
-       msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
+           msg = xmlStrcat(msg, type->name);
+       } else
+           msg = xmlStrcat(msg,
+               xmlSchemaFormatQName(&str,
+                   type->targetNamespace, type->name));
        msg = xmlStrcat(msg, BAD_CAST "'");
        FREE_AND_NULL(str);
     }
@@ -2534,7 +2525,7 @@ xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
     FREE_AND_NULL(msg)
 }
 
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
                        xmlParserErrors error,
                        xmlNodePtr node,
@@ -2626,7 +2617,7 @@ xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
                str = xmlStrcat(str, BAD_CAST ", ");
        }
        str = xmlStrcat(str, BAD_CAST " ).\n");
-       msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
+       msg = xmlStrcat(msg, BAD_CAST str);
        FREE_AND_NULL(str)
     } else
       msg = xmlStrcat(msg, BAD_CAST "\n");
@@ -2634,7 +2625,7 @@ xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
     xmlFree(msg);
 }
 
-static void LIBXML_ATTR_FORMAT(8,0)
+static void
 xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
                  xmlParserErrors error,
                  xmlNodePtr node,
@@ -2925,7 +2916,7 @@ xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an error during parsing.
  */
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlSchemaBasicItemPtr item,
@@ -2961,7 +2952,7 @@ xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an error during parsing.
  */
-static void LIBXML_ATTR_FORMAT(5,0)
+static void
 xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlSchemaBasicItemPtr item,
@@ -2986,7 +2977,7 @@ xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
  *
  * Reports an attribute use error during parsing.
  */
-static void LIBXML_ATTR_FORMAT(6,0)
+static void
 xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
                    xmlParserErrors error,
                    xmlNodePtr node,
@@ -3108,7 +3099,7 @@ xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
  * Reports a simple type validation error.
  * TODO: Should this report the value of an element as well?
  */
-static void LIBXML_ATTR_FORMAT(8,0)
+static void
 xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
                        xmlParserErrors error,
                        xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
@@ -3150,13 +3141,11 @@ xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
                msg = xmlStrcat(msg, BAD_CAST " '");
                if (type->builtInType != 0) {
                    msg = xmlStrcat(msg, BAD_CAST "xs:");
-                   str = xmlStrdup(type->name);
-               } else {
-                   const xmlChar *qName = xmlSchemaFormatQName(&str, type->targetNamespace, type->name);
-                   if (!str)
-                       str = xmlStrdup(qName);
-               }
-               msg = xmlStrcat(msg, xmlEscapeFormatString(&str));
+                   msg = xmlStrcat(msg, type->name);
+               } else
+                   msg = xmlStrcat(msg,
+                       xmlSchemaFormatQName(&str,
+                           type->targetNamespace, type->name));
                msg = xmlStrcat(msg, BAD_CAST "'.");
                FREE_AND_NULL(str);
            }
@@ -3169,9 +3158,7 @@ xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
        }
        if (expected) {
            msg = xmlStrcat(msg, BAD_CAST " Expected is '");
-           xmlChar *expectedEscaped = xmlCharStrdup(expected);
-           msg = xmlStrcat(msg, xmlEscapeFormatString(&expectedEscaped));
-           FREE_AND_NULL(expectedEscaped);
+           msg = xmlStrcat(msg, BAD_CAST expected);
            msg = xmlStrcat(msg, BAD_CAST "'.\n");
        } else
            msg = xmlStrcat(msg, BAD_CAST "\n");
@@ -24199,7 +24186,6 @@ xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
        else
            goto pattern_and_enum;
     }
-
     /*
     * Whitespace handling is only of importance for string-based
     * types.
@@ -24210,13 +24196,14 @@ xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
        ws = xmlSchemaGetWhiteSpaceFacetValue(type);
     } else
        ws = XML_SCHEMA_WHITESPACE_COLLAPSE;
-
     /*
     * If the value was not computed (for string or
     * anySimpleType based types), then use the provided
     * type.
     */
-    if (val != NULL)
+    if (val == NULL)
+       valType = valType;
+    else
        valType = xmlSchemaGetValType(val);
 
     ret = 0;
@@ -25559,7 +25546,7 @@ xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
                    if (xmlNewProp(defAttrOwnerElem,
                        iattr->localName, value) == NULL) {
                        VERROR_INT("xmlSchemaVAttributesComplex",
-                           "calling xmlNewProp()");
+                           "callling xmlNewProp()");
                        if (normValue != NULL)
                            xmlFree(normValue);
                        goto internal_error;
@@ -27395,17 +27382,10 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
 
         for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
            /*
-           * Duplicate the value, changing any &#38; to a literal ampersand.
-           *
-           * libxml2 differs from normal SAX here in that it escapes all ampersands
-           * as &#38; instead of delivering the raw converted string. Changing the
-           * behavior at this point would break applications that use this API, so
-           * we are forced to work around it. There is no danger of accidentally
-           * decoding some entity other than &#38; in this step because without
-           * unescaped ampersands there can be no other entities in the string.
+           * Duplicate the value.
            */
-           value = xmlStringLenDecodeEntities(vctxt->parserCtxt, attributes[j+3],
-               attributes[j+4] - attributes[j+3], XML_SUBSTITUTE_REF, 0, 0, 0);
+           value = xmlStrndup(attributes[j+3],
+               attributes[j+4] - attributes[j+3]);
            /*
            * TODO: Set the node line.
            */