Diff for /embedaddon/libxml2/xmlreader.c between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 23:37:58 version 1.1.1.3, 2014/06/15 19:53:29
Line 44 Line 44
 #include <libxml/pattern.h>  #include <libxml/pattern.h>
 #endif  #endif
   
   #include "buf.h"
   
 #define MAX_ERR_MSG_SIZE 64000  #define MAX_ERR_MSG_SIZE 64000
   
 /*  /*
Line 135  struct _xmlTextReader { Line 137  struct _xmlTextReader {
     int                         depth;  /* depth of the current node */      int                         depth;  /* depth of the current node */
     xmlNodePtr                  faketext;/* fake xmlNs chld */      xmlNodePtr                  faketext;/* fake xmlNs chld */
     int                         preserve;/* preserve the resulting document */      int                         preserve;/* preserve the resulting document */
    xmlBufferPtr             buffer; /* used to return const xmlChar * */    xmlBufPtr                     buffer; /* used to return const xmlChar * */
     xmlDictPtr                  dict;   /* the context dictionnary */      xmlDictPtr                  dict;   /* the context dictionnary */
   
     /* entity stack when traversing entities content */      /* entity stack when traversing entities content */
Line 152  struct _xmlTextReader { Line 154  struct _xmlTextReader {
     /* Handling of RelaxNG validation */      /* Handling of RelaxNG validation */
     xmlRelaxNGPtr          rngSchemas;  /* The Relax NG schemas */      xmlRelaxNGPtr          rngSchemas;  /* The Relax NG schemas */
     xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */      xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */
       int                    rngPreserveCtxt; /* 1 if the context was provided by the user */
     int                    rngValidErrors;/* The number of errors detected */      int                    rngValidErrors;/* The number of errors detected */
     xmlNodePtr             rngFullNode; /* the node if RNG not progressive */      xmlNodePtr             rngFullNode; /* the node if RNG not progressive */
     /* Handling of Schemas validation */      /* Handling of Schemas validation */
Line 806  xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch,  Line 809  xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch, 
  */   */
 static int  static int
 xmlTextReaderPushData(xmlTextReaderPtr reader) {  xmlTextReaderPushData(xmlTextReaderPtr reader) {
    xmlBufferPtr inbuf;    xmlBufPtr inbuf;
     int val, s;      int val, s;
     xmlTextReaderState oldstate;      xmlTextReaderState oldstate;
       int alloc;
   
     if ((reader->input == NULL) || (reader->input->buffer == NULL))      if ((reader->input == NULL) || (reader->input->buffer == NULL))
         return(-1);          return(-1);
Line 816  xmlTextReaderPushData(xmlTextReaderPtr reader) { Line 820  xmlTextReaderPushData(xmlTextReaderPtr reader) {
     oldstate = reader->state;      oldstate = reader->state;
     reader->state = XML_TEXTREADER_NONE;      reader->state = XML_TEXTREADER_NONE;
     inbuf = reader->input->buffer;      inbuf = reader->input->buffer;
       alloc = xmlBufGetAllocationScheme(inbuf);
   
     while (reader->state == XML_TEXTREADER_NONE) {      while (reader->state == XML_TEXTREADER_NONE) {
        if (inbuf->use < reader->cur + CHUNK_SIZE) {        if (xmlBufUse(inbuf) < reader->cur + CHUNK_SIZE) {
             /*              /*
              * Refill the buffer unless we are at the end of the stream               * Refill the buffer unless we are at the end of the stream
              */               */
             if (reader->mode != XML_TEXTREADER_MODE_EOF) {              if (reader->mode != XML_TEXTREADER_MODE_EOF) {
                 val = xmlParserInputBufferRead(reader->input, 4096);                  val = xmlParserInputBufferRead(reader->input, 4096);
                 if ((val == 0) &&                  if ((val == 0) &&
                    (inbuf->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) {                    (alloc == XML_BUFFER_ALLOC_IMMUTABLE)) {
                    if (inbuf->use == reader->cur) {                    if (xmlBufUse(inbuf) == reader->cur) {
                         reader->mode = XML_TEXTREADER_MODE_EOF;                          reader->mode = XML_TEXTREADER_MODE_EOF;
                         reader->state = oldstate;                          reader->state = oldstate;
                     }                      }
Line 849  xmlTextReaderPushData(xmlTextReaderPtr reader) { Line 854  xmlTextReaderPushData(xmlTextReaderPtr reader) {
          * parse by block of CHUNK_SIZE bytes, various tests show that           * parse by block of CHUNK_SIZE bytes, various tests show that
          * it's the best tradeoff at least on a 1.2GH Duron           * it's the best tradeoff at least on a 1.2GH Duron
          */           */
        if (inbuf->use >= reader->cur + CHUNK_SIZE) {        if (xmlBufUse(inbuf) >= reader->cur + CHUNK_SIZE) {
             val = xmlParseChunk(reader->ctxt,              val = xmlParseChunk(reader->ctxt,
                          (const char *) &inbuf->content[reader->cur],                 (const char *) xmlBufContent(inbuf) + reader->cur,
                          CHUNK_SIZE, 0);                                CHUNK_SIZE, 0);
             reader->cur += CHUNK_SIZE;              reader->cur += CHUNK_SIZE;
            if ((val != 0) || (reader->ctxt->wellFormed == 0))            if (val != 0)
                return(-1);                reader->ctxt->wellFormed = 0;
             if (reader->ctxt->wellFormed == 0)
                 break;
         } else {          } else {
            s = inbuf->use - reader->cur;            s = xmlBufUse(inbuf) - reader->cur;
             val = xmlParseChunk(reader->ctxt,              val = xmlParseChunk(reader->ctxt,
                          (const char *) &inbuf->content[reader->cur],                 (const char *) xmlBufContent(inbuf) + reader->cur,
                          s, 0);                                s, 0);
             reader->cur += s;              reader->cur += s;
            if ((val != 0) || (reader->ctxt->wellFormed == 0))            if (val != 0)
                return(-1);                reader->ctxt->wellFormed = 0;
             break;              break;
         }          }
     }      }
Line 872  xmlTextReaderPushData(xmlTextReaderPtr reader) { Line 879  xmlTextReaderPushData(xmlTextReaderPtr reader) {
      * Discard the consumed input when needed and possible       * Discard the consumed input when needed and possible
      */       */
     if (reader->mode == XML_TEXTREADER_MODE_INTERACTIVE) {      if (reader->mode == XML_TEXTREADER_MODE_INTERACTIVE) {
        if (inbuf->alloc != XML_BUFFER_ALLOC_IMMUTABLE) {        if (alloc != XML_BUFFER_ALLOC_IMMUTABLE) {
             if ((reader->cur >= 4096) &&              if ((reader->cur >= 4096) &&
                (inbuf->use - reader->cur <= CHUNK_SIZE)) {                (xmlBufUse(inbuf) - reader->cur <= CHUNK_SIZE)) {
                val = xmlBufferShrink(inbuf, reader->cur);                val = xmlBufShrink(inbuf, reader->cur);
                 if (val >= 0) {                  if (val >= 0) {
                     reader->cur -= val;                      reader->cur -= val;
                 }                  }
Line 889  xmlTextReaderPushData(xmlTextReaderPtr reader) { Line 896  xmlTextReaderPushData(xmlTextReaderPtr reader) {
      */       */
     else if (reader->mode == XML_TEXTREADER_MODE_EOF) {      else if (reader->mode == XML_TEXTREADER_MODE_EOF) {
         if (reader->state != XML_TEXTREADER_DONE) {          if (reader->state != XML_TEXTREADER_DONE) {
            s = inbuf->use - reader->cur;            s = xmlBufUse(inbuf) - reader->cur;
             val = xmlParseChunk(reader->ctxt,              val = xmlParseChunk(reader->ctxt,
                    (const char *) &inbuf->content[reader->cur],                 (const char *) xmlBufContent(inbuf) + reader->cur,
                    s, 1);                                s, 1);
            reader->cur = inbuf->use;            reader->cur = xmlBufUse(inbuf);
             reader->state  = XML_TEXTREADER_DONE;              reader->state  = XML_TEXTREADER_DONE;
            if ((val != 0) || (reader->ctxt->wellFormed == 0))            if (val != 0) {
                return(-1);                if (reader->ctxt->wellFormed)
                     reader->ctxt->wellFormed = 0;
                 else
                     return(-1);
             }
         }          }
     }      }
     reader->state = oldstate;      reader->state = oldstate;
       if (reader->ctxt->wellFormed == 0) {
           reader->mode = XML_TEXTREADER_MODE_EOF;
           return(-1);
       }
   
     return(0);      return(0);
 }  }
   
Line 968  printf("Expand failed !\n"); Line 984  printf("Expand failed !\n");
  * xmlTextReaderValidateCData:   * xmlTextReaderValidateCData:
  * @reader:  the xmlTextReaderPtr used   * @reader:  the xmlTextReaderPtr used
  * @data:  pointer to the CData   * @data:  pointer to the CData
 * @len:  lenght of the CData block in bytes. * @len:  length of the CData block in bytes.
  *   *
  * Push some CData for validation   * Push some CData for validation
  */   */
Line 1212  xmlTextReaderCollectSiblings(xmlNodePtr node) Line 1228  xmlTextReaderCollectSiblings(xmlNodePtr node)
     xmlBufferPtr buffer;      xmlBufferPtr buffer;
     xmlChar *ret;      xmlChar *ret;
   
       if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
           return(NULL);
   
     buffer = xmlBufferCreate();      buffer = xmlBufferCreate();
     if (buffer == NULL)      if (buffer == NULL)
        return NULL;         return NULL;
Line 1264  xmlTextReaderRead(xmlTextReaderPtr reader) { Line 1283  xmlTextReaderRead(xmlTextReaderPtr reader) {
         return(xmlTextReaderReadTree(reader));          return(xmlTextReaderReadTree(reader));
     if (reader->ctxt == NULL)      if (reader->ctxt == NULL)
         return(-1);          return(-1);
     if (reader->ctxt->wellFormed != 1)  
         return(-1);  
   
 #ifdef DEBUG_READER  #ifdef DEBUG_READER
     fprintf(stderr, "\nREAD ");      fprintf(stderr, "\nREAD ");
Line 1392  get_next_node: Line 1409  get_next_node:
 #endif  #endif
             (reader->entNr == 0) &&              (reader->entNr == 0) &&
             (reader->node->prev != NULL) &&              (reader->node->prev != NULL) &&
            (reader->node->prev->type != XML_DTD_NODE) &&            (reader->node->prev->type != XML_DTD_NODE)) {
            (reader->entNr == 0)) { 
             xmlNodePtr tmp = reader->node->prev;              xmlNodePtr tmp = reader->node->prev;
             if ((tmp->extra & NODE_IS_PRESERVED) == 0) {              if ((tmp->extra & NODE_IS_PRESERVED) == 0) {
                 xmlUnlinkNode(tmp);                  xmlUnlinkNode(tmp);
Line 1442  get_next_node: Line 1458  get_next_node:
 #endif  #endif
             (reader->entNr == 0) &&              (reader->entNr == 0) &&
             (oldnode->type != XML_DTD_NODE) &&              (oldnode->type != XML_DTD_NODE) &&
            ((oldnode->extra & NODE_IS_PRESERVED) == 0) &&            ((oldnode->extra & NODE_IS_PRESERVED) == 0)) {
            (reader->entNr == 0)) { 
             xmlUnlinkNode(oldnode);              xmlUnlinkNode(oldnode);
             xmlTextReaderFreeNode(reader, oldnode);              xmlTextReaderFreeNode(reader, oldnode);
         }          }
Line 1709  xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTR Line 1724  xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTR
  *   *
  * Reads the contents of the current node, including child nodes and markup.   * Reads the contents of the current node, including child nodes and markup.
  *   *
 * Returns a string containing the node and any XML content, or NULL if the  * Returns a string containing the node and any XML content, or NULL if the
 *         current node cannot be serialized. The string must be deallocated  *         current node cannot be serialized. The string must be deallocated
  *         by the caller.   *         by the caller.
  */   */
 xmlChar *  xmlChar *
Line 2055  xmlNewTextReader(xmlParserInputBufferPtr input, const  Line 2070  xmlNewTextReader(xmlParserInputBufferPtr input, const 
     ret->entMax = 0;      ret->entMax = 0;
     ret->entNr = 0;      ret->entNr = 0;
     ret->input = input;      ret->input = input;
    ret->buffer = xmlBufferCreateSize(100);    ret->buffer = xmlBufCreateSize(100);
     if (ret->buffer == NULL) {      if (ret->buffer == NULL) {
         xmlFree(ret);          xmlFree(ret);
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
Line 2064  xmlNewTextReader(xmlParserInputBufferPtr input, const  Line 2079  xmlNewTextReader(xmlParserInputBufferPtr input, const 
     }      }
     ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));      ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
     if (ret->sax == NULL) {      if (ret->sax == NULL) {
        xmlBufferFree(ret->buffer);        xmlBufFree(ret->buffer);
         xmlFree(ret);          xmlFree(ret);
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
                 "xmlNewTextReader : malloc failed\n");                  "xmlNewTextReader : malloc failed\n");
Line 2097  xmlNewTextReader(xmlParserInputBufferPtr input, const  Line 2112  xmlNewTextReader(xmlParserInputBufferPtr input, const 
     ret->mode = XML_TEXTREADER_MODE_INITIAL;      ret->mode = XML_TEXTREADER_MODE_INITIAL;
     ret->node = NULL;      ret->node = NULL;
     ret->curnode = NULL;      ret->curnode = NULL;
    if (ret->input->buffer->use < 4) {    if (xmlBufUse(ret->input->buffer) < 4) {
         xmlParserInputBufferRead(input, 4);          xmlParserInputBufferRead(input, 4);
     }      }
    if (ret->input->buffer->use >= 4) {    if (xmlBufUse(ret->input->buffer) >= 4) {
         ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL,          ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL,
                        (const char *) ret->input->buffer->content, 4, URI);                             (const char *) xmlBufContent(ret->input->buffer),
                                             4, URI);
         ret->base = 0;          ret->base = 0;
         ret->cur = 4;          ret->cur = 4;
     } else {      } else {
Line 2114  xmlNewTextReader(xmlParserInputBufferPtr input, const  Line 2130  xmlNewTextReader(xmlParserInputBufferPtr input, const 
     if (ret->ctxt == NULL) {      if (ret->ctxt == NULL) {
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
                 "xmlNewTextReader : malloc failed\n");                  "xmlNewTextReader : malloc failed\n");
        xmlBufferFree(ret->buffer);        xmlBufFree(ret->buffer);
         xmlFree(ret->sax);          xmlFree(ret->sax);
         xmlFree(ret);          xmlFree(ret);
         return(NULL);          return(NULL);
Line 2187  xmlFreeTextReader(xmlTextReaderPtr reader) { Line 2203  xmlFreeTextReader(xmlTextReaderPtr reader) {
         reader->rngSchemas = NULL;          reader->rngSchemas = NULL;
     }      }
     if (reader->rngValidCtxt != NULL) {      if (reader->rngValidCtxt != NULL) {
        xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);        if (! reader->rngPreserveCtxt)
             xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
         reader->rngValidCtxt = NULL;          reader->rngValidCtxt = NULL;
     }      }
     if (reader->xsdPlug != NULL) {      if (reader->xsdPlug != NULL) {
Line 2243  xmlFreeTextReader(xmlTextReaderPtr reader) { Line 2260  xmlFreeTextReader(xmlTextReaderPtr reader) {
     if ((reader->input != NULL)  && (reader->allocs & XML_TEXTREADER_INPUT))      if ((reader->input != NULL)  && (reader->allocs & XML_TEXTREADER_INPUT))
         xmlFreeParserInputBuffer(reader->input);          xmlFreeParserInputBuffer(reader->input);
     if (reader->buffer != NULL)      if (reader->buffer != NULL)
        xmlBufferFree(reader->buffer);        xmlBufFree(reader->buffer);
     if (reader->entTab != NULL)      if (reader->entTab != NULL)
         xmlFree(reader->entTab);          xmlFree(reader->entTab);
     if (reader->dict != NULL)      if (reader->dict != NULL)
Line 3591  xmlTextReaderConstValue(xmlTextReaderPtr reader) { Line 3608  xmlTextReaderConstValue(xmlTextReaderPtr reader) {
                 (attr->children->next == NULL))                  (attr->children->next == NULL))
                 return(attr->children->content);                  return(attr->children->content);
             else {              else {
                 if (reader->buffer == NULL)  
                     reader->buffer = xmlBufferCreateSize(100);  
                 if (reader->buffer == NULL) {                  if (reader->buffer == NULL) {
                    xmlGenericError(xmlGenericErrorContext,                    reader->buffer = xmlBufCreateSize(100);
                                    "xmlTextReaderSetup : malloc failed\n");                    if (reader->buffer == NULL) {
                    return (NULL);                        xmlGenericError(xmlGenericErrorContext,
                }                                        "xmlTextReaderSetup : malloc failed\n");
                reader->buffer->use = 0;                        return (NULL);
                xmlNodeBufGetContent(reader->buffer, node);                    }
                return(reader->buffer->content);                } else
                     xmlBufEmpty(reader->buffer);
                 xmlBufGetNodeContent(reader->buffer, node);
                 return(xmlBufContent(reader->buffer));
             }              }
             break;              break;
         }          }
Line 4095  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, Line 4113  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
             reader->rngSchemas = NULL;              reader->rngSchemas = NULL;
         }          }
         if (reader->rngValidCtxt != NULL) {          if (reader->rngValidCtxt != NULL) {
            xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);            if (! reader->rngPreserveCtxt)
                 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
             reader->rngValidCtxt = NULL;              reader->rngValidCtxt = NULL;
         }          }
           reader->rngPreserveCtxt = 0;
         return(0);          return(0);
     }      }
     if (reader->mode != XML_TEXTREADER_MODE_INITIAL)      if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
Line 4107  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, Line 4127  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
         reader->rngSchemas = NULL;          reader->rngSchemas = NULL;
     }      }
     if (reader->rngValidCtxt != NULL) {      if (reader->rngValidCtxt != NULL) {
        xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);        if (! reader->rngPreserveCtxt)
             xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
         reader->rngValidCtxt = NULL;          reader->rngValidCtxt = NULL;
     }      }
       reader->rngPreserveCtxt = 0;
     reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema);      reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema);
     if (reader->rngValidCtxt == NULL)      if (reader->rngValidCtxt == NULL)
         return(-1);          return(-1);
Line 4131  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, Line 4153  xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
 }  }
   
 /**  /**
    * xmlTextReaderLocator:
    * @ctx: the xmlTextReaderPtr used
    * @file: returned file information
    * @line: returned line information
    *
    * Internal locator function for the readers
    *
    * Returns 0 in case the Schema validation could be (des)activated and
    *         -1 in case of error.
    */
   static int
   xmlTextReaderLocator(void *ctx, const char **file, unsigned long *line) {
       xmlTextReaderPtr reader;
   
       if ((ctx == NULL) || ((file == NULL) && (line == NULL)))
           return(-1);
   
       if (file != NULL)
           *file = NULL;
       if (line != NULL)
           *line = 0;
   
       reader = (xmlTextReaderPtr) ctx;
       if ((reader->ctxt != NULL) && (reader->ctxt->input != NULL)) {
           if (file != NULL)
               *file = reader->ctxt->input->filename;
           if (line != NULL)
               *line = reader->ctxt->input->line;
           return(0);
       }
       if (reader->node != NULL) {
           long res;
           int ret = 0;
   
           if (line != NULL) {
               res = xmlGetLineNo(reader->node);
               if (res > 0)
                   *line = (unsigned long) res;
               else
                   ret = -1;
           }
           if (file != NULL) {
               xmlDocPtr doc = reader->node->doc;
               if ((doc != NULL) && (doc->URL != NULL))
                   *file = (const char *) doc->URL;
               else
                   ret = -1;
           }
           return(ret);
       }
       return(-1);
   }
   
   /**
  * xmlTextReaderSetSchema:   * xmlTextReaderSetSchema:
  * @reader:  the xmlTextReaderPtr used   * @reader:  the xmlTextReaderPtr used
  * @schema:  a precompiled Schema schema   * @schema:  a precompiled Schema schema
Line 4197  xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch Line 4273  xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch
         reader->xsdValidCtxt = NULL;          reader->xsdValidCtxt = NULL;
         return(-1);          return(-1);
     }      }
       xmlSchemaValidateSetLocator(reader->xsdValidCtxt,
                                   xmlTextReaderLocator,
                                   (void *) reader);
   
     if (reader->errorFunc != NULL) {      if (reader->errorFunc != NULL) {
         xmlSchemaSetValidErrors(reader->xsdValidCtxt,          xmlSchemaSetValidErrors(reader->xsdValidCtxt,
                         xmlTextReaderValidityErrorRelay,                          xmlTextReaderValidityErrorRelay,
Line 4214  xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch Line 4294  xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch
 }  }
   
 /**  /**
 * xmlTextReaderRelaxNGValidate: * xmlTextReaderRelaxNGValidateInternal:
  * @reader:  the xmlTextReaderPtr used   * @reader:  the xmlTextReaderPtr used
  * @rng:  the path to a RelaxNG schema or NULL   * @rng:  the path to a RelaxNG schema or NULL
    * @ctxt: the RelaxNG schema validation context or NULL
    * @options: options (not yet used)
  *   *
  * Use RelaxNG to validate the document as it is processed.   * Use RelaxNG to validate the document as it is processed.
  * Activation is only possible before the first Read().   * Activation is only possible before the first Read().
 * if @rng is NULL, then RelaxNG validation is deactivated. * If both @rng and @ctxt are NULL, then RelaxNG validation is deactivated.
  *   *
  * Returns 0 in case the RelaxNG validation could be (de)activated and   * Returns 0 in case the RelaxNG validation could be (de)activated and
 *         -1 in case of error. *         -1 in case of error.
  */   */
intstatic int
xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) {xmlTextReaderRelaxNGValidateInternal(xmlTextReaderPtr reader,
    xmlRelaxNGParserCtxtPtr ctxt;                                     const char *rng,
                                     xmlRelaxNGValidCtxtPtr ctxt,
                                      int options ATTRIBUTE_UNUSED)
 {
     if (reader == NULL)      if (reader == NULL)
        return(-1);        return(-1);
   
    if (rng == NULL) {    if ((rng != NULL) && (ctxt != NULL))
        if (reader->rngValidCtxt != NULL) {        return (-1);
 
     if (((rng != NULL) || (ctxt != NULL)) &&
         ((reader->mode != XML_TEXTREADER_MODE_INITIAL) ||
          (reader->ctxt == NULL)))
         return(-1);
 
     /* Cleanup previous validation stuff. */
     if (reader->rngValidCtxt != NULL) {
         if ( !reader->rngPreserveCtxt)
             xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);              xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
            reader->rngValidCtxt = NULL;        reader->rngValidCtxt = NULL;
        } 
        if (reader->rngSchemas != NULL) { 
            xmlRelaxNGFree(reader->rngSchemas); 
            reader->rngSchemas = NULL; 
        } 
        return(0); 
     }      }
    if (reader->mode != XML_TEXTREADER_MODE_INITIAL)    reader->rngPreserveCtxt = 0;
        return(-1); 
     if (reader->rngSchemas != NULL) {      if (reader->rngSchemas != NULL) {
         xmlRelaxNGFree(reader->rngSchemas);          xmlRelaxNGFree(reader->rngSchemas);
         reader->rngSchemas = NULL;          reader->rngSchemas = NULL;
     }      }
    if (reader->rngValidCtxt != NULL) {
        xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);    if ((rng == NULL) && (ctxt == NULL)) {
        reader->rngValidCtxt = NULL;        /* We just want to deactivate the validation, so get out. */
         return(0);
     }      }
    ctxt = xmlRelaxNGNewParserCtxt(rng);
    if (reader->errorFunc != NULL) {
        xmlRelaxNGSetParserErrors(ctxt,    if (rng != NULL) {
                         xmlTextReaderValidityErrorRelay,        xmlRelaxNGParserCtxtPtr pctxt;
                         xmlTextReaderValidityWarningRelay,        /* Parse the schema and create validation environment. */
                         reader);
         pctxt = xmlRelaxNGNewParserCtxt(rng);
         if (reader->errorFunc != NULL) {
             xmlRelaxNGSetParserErrors(pctxt,
                 xmlTextReaderValidityErrorRelay,
                 xmlTextReaderValidityWarningRelay,
                 reader);
         }
         if (reader->sErrorFunc != NULL) {
             xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
                 xmlTextReaderValidityStructuredRelay,
                 reader);
         }
         reader->rngSchemas = xmlRelaxNGParse(pctxt);
         xmlRelaxNGFreeParserCtxt(pctxt);
         if (reader->rngSchemas == NULL)
             return(-1);
         reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas);
         if (reader->rngValidCtxt == NULL) {
             xmlRelaxNGFree(reader->rngSchemas);
             reader->rngSchemas = NULL;
             return(-1);
         }
     } else {
         /* Use the given validation context. */
         reader->rngValidCtxt = ctxt;
         reader->rngPreserveCtxt = 1;
     }      }
    if (reader->sErrorFunc != NULL) {    /*
        xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,    * Redirect the validation context's error channels to use
                        xmlTextReaderValidityStructuredRelay,    * the reader channels.
                        reader);    * TODO: In case the user provides the validation context we
    }    *   could make this redirection optional.
    reader->rngSchemas = xmlRelaxNGParse(ctxt);    */
    xmlRelaxNGFreeParserCtxt(ctxt); 
    if (reader->rngSchemas == NULL) 
        return(-1); 
    reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); 
    if (reader->rngValidCtxt == NULL) { 
        xmlRelaxNGFree(reader->rngSchemas); 
        reader->rngSchemas = NULL; 
        return(-1); 
    } 
     if (reader->errorFunc != NULL) {      if (reader->errorFunc != NULL) {
         xmlRelaxNGSetValidErrors(reader->rngValidCtxt,          xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
                          xmlTextReaderValidityErrorRelay,                           xmlTextReaderValidityErrorRelay,
Line 4387  xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr r Line 4491  xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr r
             return(-1);              return(-1);
         }          }
     }      }
       xmlSchemaValidateSetLocator(reader->xsdValidCtxt,
                                   xmlTextReaderLocator,
                                   (void *) reader);
     /*      /*
     * Redirect the validation context's error channels to use      * Redirect the validation context's error channels to use
     * the reader channels.      * the reader channels.
Line 4447  xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, c Line 4554  xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, c
 {  {
     return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0));      return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0));
 }  }
   
   /**
    * xmlTextReaderRelaxNGValidateCtxt:
    * @reader:  the xmlTextReaderPtr used
    * @ctxt: the RelaxNG schema validation context or NULL
    * @options: options (not used yet)
    *
    * Use RelaxNG schema context to validate the document as it is processed.
    * Activation is only possible before the first Read().
    * If @ctxt is NULL, then RelaxNG schema validation is deactivated.
    *
    * Returns 0 in case the schemas validation could be (de)activated and
    *         -1 in case of error.
    */
   int
   xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader,
                                    xmlRelaxNGValidCtxtPtr ctxt,
                                    int options)
   {
       return(xmlTextReaderRelaxNGValidateInternal(reader, NULL, ctxt, options));
   }
   
   /**
    * xmlTextReaderRelaxNGValidate:
    * @reader:  the xmlTextReaderPtr used
    * @rng:  the path to a RelaxNG schema or NULL
    *
    * Use RelaxNG schema to validate the document as it is processed.
    * Activation is only possible before the first Read().
    * If @rng is NULL, then RelaxNG schema validation is deactivated.
    *
    * Returns 0 in case the schemas validation could be (de)activated and
    *         -1 in case of error.
    */
   int
   xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng)
   {
       return(xmlTextReaderRelaxNGValidateInternal(reader, rng, NULL, 0));
   }
   
 #endif  #endif
   
 /**  /**
Line 4964  xmlTextReaderSetup(xmlTextReaderPtr reader, Line 5111  xmlTextReaderSetup(xmlTextReaderPtr reader,
         reader->allocs |= XML_TEXTREADER_INPUT;          reader->allocs |= XML_TEXTREADER_INPUT;
     }      }
     if (reader->buffer == NULL)      if (reader->buffer == NULL)
        reader->buffer = xmlBufferCreateSize(100);        reader->buffer = xmlBufCreateSize(100);
     if (reader->buffer == NULL) {      if (reader->buffer == NULL) {
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
                         "xmlTextReaderSetup : malloc failed\n");                          "xmlTextReaderSetup : malloc failed\n");
Line 5005  xmlTextReaderSetup(xmlTextReaderPtr reader, Line 5152  xmlTextReaderSetup(xmlTextReaderPtr reader,
     reader->node = NULL;      reader->node = NULL;
     reader->curnode = NULL;      reader->curnode = NULL;
     if (input != NULL) {      if (input != NULL) {
        if (reader->input->buffer->use < 4) {        if (xmlBufUse(reader->input->buffer) < 4) {
             xmlParserInputBufferRead(input, 4);              xmlParserInputBufferRead(input, 4);
         }          }
         if (reader->ctxt == NULL) {          if (reader->ctxt == NULL) {
            if (reader->input->buffer->use >= 4) {            if (xmlBufUse(reader->input->buffer) >= 4) {
                 reader->ctxt = xmlCreatePushParserCtxt(reader->sax, NULL,                  reader->ctxt = xmlCreatePushParserCtxt(reader->sax, NULL,
                       (const char *) reader->input->buffer->content, 4, URL);                       (const char *) xmlBufContent(reader->input->buffer),
                                       4, URL);
                 reader->base = 0;                  reader->base = 0;
                 reader->cur = 4;                  reader->cur = 4;
             } else {              } else {
Line 5040  xmlTextReaderSetup(xmlTextReaderPtr reader, Line 5188  xmlTextReaderSetup(xmlTextReaderPtr reader,
                 inputStream->filename = (char *)                  inputStream->filename = (char *)
                     xmlCanonicPath((const xmlChar *) URL);                      xmlCanonicPath((const xmlChar *) URL);
             inputStream->buf = buf;              inputStream->buf = buf;
            inputStream->base = inputStream->buf->buffer->content;            xmlBufResetInput(buf->buffer, inputStream);
            inputStream->cur = inputStream->buf->buffer->content; 
            inputStream->end = 
            &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; 
   
             inputPush(reader->ctxt, inputStream);              inputPush(reader->ctxt, inputStream);
             reader->cur = 0;              reader->cur = 0;
Line 5331  xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCl Line 5476  xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCl
   
     input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,      input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
                                          XML_CHAR_ENCODING_NONE);                                           XML_CHAR_ENCODING_NONE);
    if (input == NULL)    if (input == NULL) {
         if (ioclose != NULL)
             ioclose(ioctx);
         return (NULL);          return (NULL);
       }
     reader = xmlNewTextReader(input, URL);      reader = xmlNewTextReader(input, URL);
     if (reader == NULL) {      if (reader == NULL) {
         xmlFreeParserInputBuffer(input);          xmlFreeParserInputBuffer(input);
Line 5549  xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCa Line 5697  xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCa
   
     input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,      input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
                                          XML_CHAR_ENCODING_NONE);                                           XML_CHAR_ENCODING_NONE);
    if (input == NULL)    if (input == NULL) {
         if (ioclose != NULL)
             ioclose(ioctx);
         return (-1);          return (-1);
       }
     return (xmlTextReaderSetup(reader, input, URL, encoding, options));      return (xmlTextReaderSetup(reader, input, URL, encoding, options));
 }  }
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
  *                      Utilities                                       *   *                      Utilities                                       *

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>