2002-12-09 17:13:43 +03:00
/*
* xmlreader . c : implements the xmlTextReader streaming node API
*
2009-08-11 20:31:42 +04:00
* NOTE :
2002-12-17 01:04:11 +03:00
* XmlTextReader . Normalization Property won ' t be supported , since
* it makes the parser non compliant to the XML recommendation
*
2002-12-09 17:13:43 +03:00
* See Copyright for the status of this software .
*
* daniel @ veillard . com
*/
2003-01-03 19:19:51 +03:00
/*
* TODOs :
2003-01-05 04:27:54 +03:00
* - XML Schemas validation
2003-01-03 19:19:51 +03:00
*/
2002-12-09 17:13:43 +03:00
# define IN_LIBXML
# include "libxml.h"
2003-09-30 04:43:48 +04:00
# ifdef LIBXML_READER_ENABLED
2002-12-09 17:13:43 +03:00
# include <string.h> /* for memset() only ! */
2003-01-17 01:45:08 +03:00
# include <stdarg.h>
2002-12-09 17:13:43 +03:00
# include <ctype.h>
# include <stdlib.h>
# include <libxml/xmlmemory.h>
# include <libxml/xmlIO.h>
# include <libxml/xmlreader.h>
2003-10-18 13:07:46 +04:00
# include <libxml/parserInternals.h>
2005-07-10 23:03:16 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2003-04-16 03:32:22 +04:00
# include <libxml/relaxng.h>
2005-07-10 23:03:16 +04:00
# include <libxml/xmlschemas.h>
# endif
2003-10-20 21:07:41 +04:00
# include <libxml/uri.h>
2003-11-03 15:31:38 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
# include <libxml/xinclude.h>
# endif
2003-12-05 17:57:46 +03:00
# ifdef LIBXML_PATTERN_ENABLED
# include <libxml/pattern.h>
# endif
2002-12-09 17:13:43 +03:00
2022-08-26 02:22:33 +03:00
# include "private/buf.h"
2024-05-05 19:16:44 +03:00
# include "private/error.h"
2022-08-26 02:22:33 +03:00
# include "private/tree.h"
2023-12-10 20:23:53 +03:00
# include "private/parser.h"
2022-10-30 14:21:20 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
# include "private/xinclude.h"
# endif
2012-07-16 10:42:31 +04:00
2020-08-26 01:16:38 +03:00
# ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
/* Keeping free objects can hide memory errors. */
# define MAX_FREE_NODES 1
# else
# define MAX_FREE_NODES 100
# endif
2023-11-28 17:34:28 +03:00
# ifndef va_copy
# ifdef __va_copy
# define va_copy(dest, src) __va_copy(dest, src)
2008-09-25 18:55:21 +04:00
# else
2023-11-28 17:34:28 +03:00
# define va_copy(dest, src) memcpy(dest, src, sizeof(va_list))
2008-09-25 18:55:21 +04:00
# endif
# endif
2003-04-22 01:36:41 +04:00
# define CHUNK_SIZE 512
2002-12-09 17:13:43 +03:00
/************************************************************************
* *
* The parser : maps the Text Reader API on top of the existing *
* parsing routines building a tree *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# define XML_TEXTREADER_INPUT 1
# define XML_TEXTREADER_CTXT 2
typedef enum {
XML_TEXTREADER_NONE = - 1 ,
XML_TEXTREADER_START = 0 ,
XML_TEXTREADER_ELEMENT = 1 ,
XML_TEXTREADER_END = 2 ,
XML_TEXTREADER_EMPTY = 3 ,
2002-12-20 03:16:24 +03:00
XML_TEXTREADER_BACKTRACK = 4 ,
2003-04-24 20:06:47 +04:00
XML_TEXTREADER_DONE = 5 ,
XML_TEXTREADER_ERROR = 6
2002-12-09 17:13:43 +03:00
} xmlTextReaderState ;
2003-04-16 03:32:22 +04:00
typedef enum {
XML_TEXTREADER_NOT_VALIDATE = 0 ,
XML_TEXTREADER_VALIDATE_DTD = 1 ,
2005-07-10 23:03:16 +04:00
XML_TEXTREADER_VALIDATE_RNG = 2 ,
XML_TEXTREADER_VALIDATE_XSD = 4
2003-04-16 03:32:22 +04:00
} xmlTextReaderValidate ;
2002-12-09 17:13:43 +03:00
struct _xmlTextReader {
int mode ; /* the parsing mode */
2003-10-20 21:07:41 +04:00
xmlDocPtr doc ; /* when walking an existing doc */
2003-04-16 03:32:22 +04:00
xmlTextReaderValidate validate ; /* is there any validation */
2002-12-09 17:13:43 +03:00
int allocs ; /* what structure were deallocated */
xmlTextReaderState state ;
xmlParserCtxtPtr ctxt ; /* the parser context */
xmlSAXHandlerPtr sax ; /* the parser SAX callbacks */
xmlParserInputBufferPtr input ; /* the input */
startElementSAXFunc startElement ; /* initial SAX callbacks */
endElementSAXFunc endElement ; /* idem */
2003-09-10 14:51:05 +04:00
startElementNsSAX2Func startElementNs ; /* idem */
2003-09-28 04:19:54 +04:00
endElementNsSAX2Func endElementNs ; /* idem */
2002-12-20 03:16:24 +03:00
charactersSAXFunc characters ;
cdataBlockSAXFunc cdataBlock ;
2009-08-11 20:31:42 +04:00
unsigned int base ; /* base of the segment in the input */
unsigned int cur ; /* current position in the input */
2002-12-09 17:13:43 +03:00
xmlNodePtr node ; /* current node */
2002-12-16 02:36:49 +03:00
xmlNodePtr curnode ; /* current attribute node */
2002-12-09 17:13:43 +03:00
int depth ; /* depth of the current node */
2002-12-18 17:53:54 +03:00
xmlNodePtr faketext ; /* fake xmlNs chld */
2003-09-28 04:19:54 +04:00
int preserve ; /* preserve the resulting document */
2012-07-16 10:42:31 +04:00
xmlBufPtr buffer ; /* used to return const xmlChar * */
2016-04-13 17:56:07 +03:00
xmlDictPtr dict ; /* the context dictionary */
2003-01-03 04:18:43 +03:00
/* entity stack when traversing entities content */
xmlNodePtr ent ; /* Current Entity Ref Node */
int entNr ; /* Depth of the entities stack */
int entMax ; /* Max depth of the entities stack */
xmlNodePtr * entTab ; /* array of entities */
2003-01-17 01:45:08 +03:00
/* error handling */
xmlTextReaderErrorFunc errorFunc ; /* callback function */
void * errorFuncArg ; /* callback function user argument */
2003-04-16 03:32:22 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
/* Handling of RelaxNG validation */
2003-11-03 15:31:38 +03:00
xmlRelaxNGPtr rngSchemas ; /* The Relax NG schemas */
xmlRelaxNGValidCtxtPtr rngValidCtxt ; /* The Relax NG validation context */
2012-03-19 12:08:16 +04:00
int rngPreserveCtxt ; /* 1 if the context was provided by the user */
2005-12-07 17:02:42 +03:00
int rngValidErrors ; /* The number of errors detected */
2003-11-03 15:31:38 +03:00
xmlNodePtr rngFullNode ; /* the node if RNG not progressive */
2005-07-10 23:03:16 +04:00
/* Handling of Schemas validation */
xmlSchemaPtr xsdSchemas ; /* The Schemas schemas */
xmlSchemaValidCtxtPtr xsdValidCtxt ; /* The Schemas validation context */
2005-12-07 17:02:42 +03:00
int xsdPreserveCtxt ; /* 1 if the context was provided by the user */
int xsdValidErrors ; /* The number of errors detected */
2005-07-10 23:03:16 +04:00
xmlSchemaSAXPlugPtr xsdPlug ; /* the schemas plug in SAX pipeline */
2003-11-03 15:31:38 +03:00
# endif
# ifdef LIBXML_XINCLUDE_ENABLED
/* Handling of XInclude processing */
int xinclude ; /* is xinclude asked for */
const xmlChar * xinclude_name ; /* the xinclude name from dict */
xmlXIncludeCtxtPtr xincctxt ; /* the xinclude context */
int in_xinclude ; /* counts for xinclude */
2003-04-16 03:32:22 +04:00
# endif
2003-12-05 17:57:46 +03:00
# ifdef LIBXML_PATTERN_ENABLED
int patternNr ; /* number of preserve patterns */
int patternMax ; /* max preserve patterns */
xmlPatternPtr * patternTab ; /* array of preserve patterns */
# endif
int preserves ; /* level of preserves */
2003-12-09 14:35:37 +03:00
int parserFlags ; /* the set of options set */
2004-02-03 03:14:10 +03:00
/* Structured error handling */
xmlStructuredErrorFunc sErrorFunc ; /* callback function */
2024-06-11 15:47:03 +03:00
xmlResourceLoader resourceLoader ;
void * resourceCtxt ;
2002-12-09 17:13:43 +03:00
} ;
2003-10-27 14:25:13 +03:00
# define NODE_IS_EMPTY 0x1
# define NODE_IS_PRESERVED 0x2
2003-12-05 17:57:46 +03:00
# define NODE_IS_SPRESERVED 0x4
2003-01-05 04:27:54 +03:00
2003-10-20 21:07:41 +04:00
static int xmlTextReaderReadTree ( xmlTextReaderPtr reader ) ;
static int xmlTextReaderNextTree ( xmlTextReaderPtr reader ) ;
2003-09-19 16:44:05 +04:00
2003-09-28 04:19:54 +04:00
/**
* DICT_FREE :
* @ str : a string
*
2016-04-13 17:56:07 +03:00
* Free a string if it is not owned by the " dict " dictionary in the
2003-09-28 04:19:54 +04:00
* current scope
*/
# define DICT_FREE(str) \
2009-08-11 20:31:42 +04:00
if ( ( str ) & & ( ( ! dict ) | | \
2003-09-28 04:19:54 +04:00
( xmlDictOwns ( dict , ( const xmlChar * ) ( str ) ) = = 0 ) ) ) \
xmlFree ( ( char * ) ( str ) ) ;
static void xmlTextReaderFreeNode ( xmlTextReaderPtr reader , xmlNodePtr cur ) ;
static void xmlTextReaderFreeNodeList ( xmlTextReaderPtr reader , xmlNodePtr cur ) ;
2023-12-10 20:23:53 +03:00
static void
xmlTextReaderErrMemory ( xmlTextReaderPtr reader ) {
2024-05-05 19:16:44 +03:00
if ( reader - > ctxt ! = NULL )
xmlCtxtErrMemory ( reader - > ctxt ) ;
else
xmlRaiseMemoryError ( NULL , NULL , NULL , XML_FROM_PARSER , NULL ) ;
2023-12-10 20:23:53 +03:00
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
}
2024-04-22 13:23:06 +03:00
static xmlChar *
readerStrdup ( xmlTextReaderPtr reader , const xmlChar * string ) {
xmlChar * copy ;
if ( string = = NULL )
return ( NULL ) ;
copy = xmlStrdup ( string ) ;
if ( copy = = NULL )
xmlTextReaderErrMemory ( reader ) ;
return ( copy ) ;
}
static const xmlChar *
constString ( xmlTextReaderPtr reader , const xmlChar * string ) {
const xmlChar * dictString ;
if ( string = = NULL )
return ( NULL ) ;
dictString = xmlDictLookup ( reader - > dict , string , - 1 ) ;
if ( dictString = = NULL )
xmlTextReaderErrMemory ( reader ) ;
return ( dictString ) ;
}
static const xmlChar *
constQString ( xmlTextReaderPtr reader , const xmlChar * prefix ,
const xmlChar * name ) {
const xmlChar * dictString ;
if ( name = = NULL )
return ( NULL ) ;
dictString = xmlDictQLookup ( reader - > dict , prefix , name ) ;
if ( dictString = = NULL )
xmlTextReaderErrMemory ( reader ) ;
return ( dictString ) ;
}
/************************************************************************
* *
* Our own version of the freeing routines as we recycle nodes *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-09-28 04:19:54 +04:00
/**
* xmlTextReaderFreeProp :
* @ reader : the xmlTextReaderPtr used
* @ cur : the node
*
* Free a node .
*/
static void
xmlTextReaderFreeProp ( xmlTextReaderPtr reader , xmlAttrPtr cur ) {
xmlDictPtr dict ;
2014-10-06 16:07:19 +04:00
if ( ( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) )
dict = reader - > ctxt - > dict ;
else
dict = NULL ;
2003-09-28 04:19:54 +04:00
if ( cur = = NULL ) return ;
2004-05-01 02:25:59 +04:00
if ( ( __xmlRegisterCallbacks ) & & ( xmlDeregisterNodeDefaultValue ) )
xmlDeregisterNodeDefaultValue ( ( xmlNodePtr ) cur ) ;
2003-09-28 04:19:54 +04:00
if ( cur - > children ! = NULL )
xmlTextReaderFreeNodeList ( reader , cur - > children ) ;
2024-02-29 21:38:29 +03:00
if ( cur - > id ! = NULL ) {
/*
* Operating in streaming mode , attr is gonna disappear
*/
cur - > id - > attr = NULL ;
2024-03-17 17:05:42 +03:00
if ( cur - > id - > name ! = NULL )
DICT_FREE ( cur - > id - > name ) ;
2024-02-29 21:38:29 +03:00
cur - > id - > name = cur - > name ;
cur - > name = NULL ;
} else {
DICT_FREE ( cur - > name ) ;
}
2003-09-28 04:19:54 +04:00
if ( ( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) & &
2020-08-26 01:16:38 +03:00
( reader - > ctxt - > freeAttrsNr < MAX_FREE_NODES ) ) {
2003-09-28 04:19:54 +04:00
cur - > next = reader - > ctxt - > freeAttrs ;
reader - > ctxt - > freeAttrs = cur ;
reader - > ctxt - > freeAttrsNr + + ;
} else {
xmlFree ( cur ) ;
}
}
/**
* xmlTextReaderFreePropList :
* @ reader : the xmlTextReaderPtr used
* @ cur : the first property in the list
*
* Free a property and all its siblings , all the children are freed too .
*/
static void
xmlTextReaderFreePropList ( xmlTextReaderPtr reader , xmlAttrPtr cur ) {
xmlAttrPtr next ;
2014-10-06 16:07:19 +04:00
2003-09-28 04:19:54 +04:00
while ( cur ! = NULL ) {
next = cur - > next ;
xmlTextReaderFreeProp ( reader , cur ) ;
cur = next ;
}
}
/**
* xmlTextReaderFreeNodeList :
* @ reader : the xmlTextReaderPtr used
* @ cur : the first node in the list
*
* Free a node and all its siblings , this is a recursive behaviour , all
* the children are freed too .
*/
static void
xmlTextReaderFreeNodeList ( xmlTextReaderPtr reader , xmlNodePtr cur ) {
xmlNodePtr next ;
2019-09-23 18:13:05 +03:00
xmlNodePtr parent ;
2003-09-28 04:19:54 +04:00
xmlDictPtr dict ;
2019-09-23 18:13:05 +03:00
size_t depth = 0 ;
2003-09-28 04:19:54 +04:00
2014-10-06 16:07:19 +04:00
if ( ( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) )
dict = reader - > ctxt - > dict ;
else
dict = NULL ;
2003-09-28 04:19:54 +04:00
if ( cur = = NULL ) return ;
if ( cur - > type = = XML_NAMESPACE_DECL ) {
xmlFreeNsList ( ( xmlNsPtr ) cur ) ;
return ;
}
if ( ( cur - > type = = XML_DOCUMENT_NODE ) | |
( cur - > type = = XML_HTML_DOCUMENT_NODE ) ) {
xmlFreeDoc ( ( xmlDocPtr ) cur ) ;
return ;
}
2019-09-23 18:13:05 +03:00
while ( 1 ) {
2019-09-26 12:01:58 +03:00
while ( ( cur - > type ! = XML_DTD_NODE ) & &
( cur - > type ! = XML_ENTITY_REF_NODE ) & &
( cur - > children ! = NULL ) & &
( cur - > children - > parent = = cur ) ) {
2019-09-23 18:13:05 +03:00
cur = cur - > children ;
depth + = 1 ;
}
2003-09-28 04:19:54 +04:00
next = cur - > next ;
2019-09-23 18:13:05 +03:00
parent = cur - > parent ;
2003-09-28 04:19:54 +04:00
/* unroll to speed up freeing the document */
if ( cur - > type ! = XML_DTD_NODE ) {
2004-05-01 02:25:59 +04:00
if ( ( __xmlRegisterCallbacks ) & & ( xmlDeregisterNodeDefaultValue ) )
xmlDeregisterNodeDefaultValue ( cur ) ;
2003-09-28 04:19:54 +04:00
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_XINCLUDE_START ) | |
( cur - > type = = XML_XINCLUDE_END ) ) & &
( cur - > properties ! = NULL ) )
xmlTextReaderFreePropList ( reader , cur - > properties ) ;
2005-08-25 17:19:21 +04:00
if ( ( cur - > content ! = ( xmlChar * ) & ( cur - > properties ) ) & &
( cur - > type ! = XML_ELEMENT_NODE ) & &
2003-09-28 04:19:54 +04:00
( cur - > type ! = XML_XINCLUDE_START ) & &
( cur - > type ! = XML_XINCLUDE_END ) & &
( cur - > type ! = XML_ENTITY_REF_NODE ) ) {
DICT_FREE ( cur - > content ) ;
}
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_XINCLUDE_START ) | |
( cur - > type = = XML_XINCLUDE_END ) ) & &
( cur - > nsDef ! = NULL ) )
xmlFreeNsList ( cur - > nsDef ) ;
/*
* we don ' t free element names here they are interned now
*/
if ( ( cur - > type ! = XML_TEXT_NODE ) & &
( cur - > type ! = XML_COMMENT_NODE ) )
DICT_FREE ( cur - > name ) ;
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_TEXT_NODE ) ) & &
( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) & &
2020-08-26 01:16:38 +03:00
( reader - > ctxt - > freeElemsNr < MAX_FREE_NODES ) ) {
2003-09-28 04:19:54 +04:00
cur - > next = reader - > ctxt - > freeElems ;
reader - > ctxt - > freeElems = cur ;
reader - > ctxt - > freeElemsNr + + ;
} else {
xmlFree ( cur ) ;
}
}
2019-09-23 18:13:05 +03:00
if ( next ! = NULL ) {
cur = next ;
} else {
if ( ( depth = = 0 ) | | ( parent = = NULL ) )
break ;
depth - = 1 ;
cur = parent ;
cur - > children = NULL ;
}
2003-09-28 04:19:54 +04:00
}
}
/**
* xmlTextReaderFreeNode :
* @ reader : the xmlTextReaderPtr used
* @ cur : the node
*
* Free a node , this is a recursive behaviour , all the children are freed too .
* This doesn ' t unlink the child from the list , use xmlUnlinkNode ( ) first .
*/
static void
xmlTextReaderFreeNode ( xmlTextReaderPtr reader , xmlNodePtr cur ) {
xmlDictPtr dict ;
2014-10-06 16:07:19 +04:00
if ( ( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) )
dict = reader - > ctxt - > dict ;
else
dict = NULL ;
2003-09-28 04:19:54 +04:00
if ( cur - > type = = XML_DTD_NODE ) {
xmlFreeDtd ( ( xmlDtdPtr ) cur ) ;
return ;
}
if ( cur - > type = = XML_NAMESPACE_DECL ) {
xmlFreeNs ( ( xmlNsPtr ) cur ) ;
return ;
}
if ( cur - > type = = XML_ATTRIBUTE_NODE ) {
xmlTextReaderFreeProp ( reader , ( xmlAttrPtr ) cur ) ;
return ;
}
if ( ( cur - > children ! = NULL ) & &
2003-10-21 02:32:39 +04:00
( cur - > type ! = XML_ENTITY_REF_NODE ) ) {
if ( cur - > children - > parent = = cur )
xmlTextReaderFreeNodeList ( reader , cur - > children ) ;
cur - > children = NULL ;
}
2004-05-01 02:25:59 +04:00
if ( ( __xmlRegisterCallbacks ) & & ( xmlDeregisterNodeDefaultValue ) )
xmlDeregisterNodeDefaultValue ( cur ) ;
2003-09-28 04:19:54 +04:00
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_XINCLUDE_START ) | |
( cur - > type = = XML_XINCLUDE_END ) ) & &
( cur - > properties ! = NULL ) )
xmlTextReaderFreePropList ( reader , cur - > properties ) ;
2005-08-25 17:19:21 +04:00
if ( ( cur - > content ! = ( xmlChar * ) & ( cur - > properties ) ) & &
( cur - > type ! = XML_ELEMENT_NODE ) & &
2003-09-28 04:19:54 +04:00
( cur - > type ! = XML_XINCLUDE_START ) & &
( cur - > type ! = XML_XINCLUDE_END ) & &
( cur - > type ! = XML_ENTITY_REF_NODE ) ) {
DICT_FREE ( cur - > content ) ;
}
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_XINCLUDE_START ) | |
( cur - > type = = XML_XINCLUDE_END ) ) & &
( cur - > nsDef ! = NULL ) )
xmlFreeNsList ( cur - > nsDef ) ;
/*
* we don ' t free names here they are interned now
*/
if ( ( cur - > type ! = XML_TEXT_NODE ) & &
( cur - > type ! = XML_COMMENT_NODE ) )
DICT_FREE ( cur - > name ) ;
2004-05-01 02:25:59 +04:00
2003-09-28 04:19:54 +04:00
if ( ( ( cur - > type = = XML_ELEMENT_NODE ) | |
( cur - > type = = XML_TEXT_NODE ) ) & &
( reader ! = NULL ) & & ( reader - > ctxt ! = NULL ) & &
2020-08-26 01:16:38 +03:00
( reader - > ctxt - > freeElemsNr < MAX_FREE_NODES ) ) {
2003-09-28 04:19:54 +04:00
cur - > next = reader - > ctxt - > freeElems ;
reader - > ctxt - > freeElems = cur ;
reader - > ctxt - > freeElemsNr + + ;
} else {
xmlFree ( cur ) ;
}
}
/**
* xmlTextReaderFreeDoc :
* @ reader : the xmlTextReaderPtr used
* @ cur : pointer to the document
*
* Free up all the structures used by a document , tree included .
*/
static void
xmlTextReaderFreeDoc ( xmlTextReaderPtr reader , xmlDocPtr cur ) {
xmlDtdPtr extSubset , intSubset ;
if ( cur = = NULL ) return ;
2004-05-01 02:25:59 +04:00
if ( ( __xmlRegisterCallbacks ) & & ( xmlDeregisterNodeDefaultValue ) )
xmlDeregisterNodeDefaultValue ( ( xmlNodePtr ) cur ) ;
2003-09-28 04:19:54 +04:00
/*
* Do this before freeing the children list to avoid ID lookups
*/
2022-02-20 18:05:53 +03:00
if ( cur - > ids ! = NULL ) xmlFreeIDTable ( ( xmlIDTablePtr ) cur - > ids ) ;
2003-09-28 04:19:54 +04:00
cur - > ids = NULL ;
if ( cur - > refs ! = NULL ) xmlFreeRefTable ( ( xmlRefTablePtr ) cur - > refs ) ;
cur - > refs = NULL ;
extSubset = cur - > extSubset ;
intSubset = cur - > intSubset ;
if ( intSubset = = extSubset )
extSubset = NULL ;
if ( extSubset ! = NULL ) {
xmlUnlinkNode ( ( xmlNodePtr ) cur - > extSubset ) ;
cur - > extSubset = NULL ;
xmlFreeDtd ( extSubset ) ;
}
if ( intSubset ! = NULL ) {
xmlUnlinkNode ( ( xmlNodePtr ) cur - > intSubset ) ;
cur - > intSubset = NULL ;
xmlFreeDtd ( intSubset ) ;
}
if ( cur - > children ! = NULL ) xmlTextReaderFreeNodeList ( reader , cur - > children ) ;
if ( cur - > version ! = NULL ) xmlFree ( ( char * ) cur - > version ) ;
if ( cur - > name ! = NULL ) xmlFree ( ( char * ) cur - > name ) ;
if ( cur - > encoding ! = NULL ) xmlFree ( ( char * ) cur - > encoding ) ;
if ( cur - > oldNs ! = NULL ) xmlFreeNsList ( cur - > oldNs ) ;
if ( cur - > URL ! = NULL ) xmlFree ( ( char * ) cur - > URL ) ;
2004-03-22 18:22:58 +03:00
if ( cur - > dict ! = NULL ) xmlDictFree ( cur - > dict ) ;
2004-05-01 02:25:59 +04:00
2003-09-28 04:19:54 +04:00
xmlFree ( cur ) ;
}
2003-09-17 14:26:25 +04:00
/************************************************************************
* *
* The reader core parser *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-12-09 17:13:43 +03:00
2023-12-18 21:47:47 +03:00
static void
xmlTextReaderStructuredRelay ( void * userData , const xmlError * error )
{
xmlTextReaderPtr reader = ( xmlTextReaderPtr ) userData ;
if ( reader - > sErrorFunc ! = NULL ) {
reader - > sErrorFunc ( reader - > errorFuncArg , error ) ;
} else if ( reader - > errorFunc ! = NULL ) {
xmlParserSeverities severity ;
if ( ( error - > domain = = XML_FROM_VALID ) | |
( error - > domain = = XML_FROM_DTD ) ) {
if ( error - > level = = XML_ERR_WARNING )
severity = XML_PARSER_SEVERITY_VALIDITY_WARNING ;
else
severity = XML_PARSER_SEVERITY_VALIDITY_ERROR ;
} else {
if ( error - > level = = XML_ERR_WARNING )
severity = XML_PARSER_SEVERITY_WARNING ;
else
severity = XML_PARSER_SEVERITY_ERROR ;
}
reader - > errorFunc ( reader - > errorFuncArg , error - > message , severity ,
reader - > ctxt ) ;
}
}
2003-01-03 04:18:43 +03:00
/**
* xmlTextReaderEntPush :
* @ reader : the xmlTextReaderPtr used
* @ value : the entity reference node
*
* Pushes a new entity reference node on top of the entities stack
*
2023-01-22 20:18:00 +03:00
* Returns - 1 in case of error , the index in the stack otherwise
2003-01-03 04:18:43 +03:00
*/
static int
xmlTextReaderEntPush ( xmlTextReaderPtr reader , xmlNodePtr value )
{
if ( reader - > entNr > = reader - > entMax ) {
2023-01-22 20:18:00 +03:00
size_t newSize = reader - > entMax = = 0 ? 10 : reader - > entMax * 2 ;
xmlNodePtr * tmp ;
tmp = ( xmlNodePtr * ) xmlRealloc ( reader - > entTab ,
newSize * sizeof ( * tmp ) ) ;
if ( tmp = = NULL ) {
2023-12-10 20:23:53 +03:00
xmlTextReaderErrMemory ( reader ) ;
2023-01-22 20:18:00 +03:00
return ( - 1 ) ;
2003-01-03 04:18:43 +03:00
}
2023-01-22 20:18:00 +03:00
reader - > entTab = tmp ;
reader - > entMax = newSize ;
2003-01-03 04:18:43 +03:00
}
reader - > entTab [ reader - > entNr ] = value ;
reader - > ent = value ;
return ( reader - > entNr + + ) ;
}
/**
* xmlTextReaderEntPop :
* @ reader : the xmlTextReaderPtr used
*
* Pops the top element entity from the entities stack
*
* Returns the entity just removed
*/
static xmlNodePtr
xmlTextReaderEntPop ( xmlTextReaderPtr reader )
{
xmlNodePtr ret ;
if ( reader - > entNr < = 0 )
2005-07-30 02:02:24 +04:00
return ( NULL ) ;
2003-01-03 04:18:43 +03:00
reader - > entNr - - ;
if ( reader - > entNr > 0 )
reader - > ent = reader - > entTab [ reader - > entNr - 1 ] ;
else
reader - > ent = NULL ;
ret = reader - > entTab [ reader - > entNr ] ;
2005-07-30 02:02:24 +04:00
reader - > entTab [ reader - > entNr ] = NULL ;
2003-01-03 04:18:43 +03:00
return ( ret ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderStartElement :
* @ ctx : the user data ( XML parser context )
* @ fullname : The element name , including namespace prefix
* @ atts : An array of name / value attributes pairs , NULL terminated
*
* called when an opening tag has been processed .
*/
static void
xmlTextReaderStartElement ( void * ctx , const xmlChar * fullname ,
const xmlChar * * atts ) {
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
2002-12-20 03:16:24 +03:00
if ( ( reader ! = NULL ) & & ( reader - > startElement ! = NULL ) ) {
2002-12-09 17:13:43 +03:00
reader - > startElement ( ctx , fullname , atts ) ;
2003-01-05 04:27:54 +03:00
if ( ( ctxt - > node ! = NULL ) & & ( ctxt - > input ! = NULL ) & &
( ctxt - > input - > cur ! = NULL ) & & ( ctxt - > input - > cur [ 0 ] = = ' / ' ) & &
( ctxt - > input - > cur [ 1 ] = = ' > ' ) )
2003-10-27 14:25:13 +03:00
ctxt - > node - > extra = NODE_IS_EMPTY ;
2002-12-20 03:16:24 +03:00
}
2003-01-01 17:50:44 +03:00
if ( reader ! = NULL )
reader - > state = XML_TEXTREADER_ELEMENT ;
2002-12-09 17:13:43 +03:00
}
/**
* xmlTextReaderEndElement :
* @ ctx : the user data ( XML parser context )
* @ fullname : The element name , including namespace prefix
*
* called when an ending tag has been processed .
*/
static void
xmlTextReaderEndElement ( void * ctx , const xmlChar * fullname ) {
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
2002-12-20 03:16:24 +03:00
if ( ( reader ! = NULL ) & & ( reader - > endElement ! = NULL ) ) {
2002-12-09 17:13:43 +03:00
reader - > endElement ( ctx , fullname ) ;
2002-12-20 03:16:24 +03:00
}
2002-12-09 17:13:43 +03:00
}
2003-09-10 14:51:05 +04:00
/**
* xmlTextReaderStartElementNs :
* @ ctx : the user data ( XML parser context )
* @ localname : the local name of the element
* @ prefix : the element namespace prefix if available
* @ URI : the element namespace name if available
* @ nb_namespaces : number of namespace definitions on that node
* @ namespaces : pointer to the array of prefix / URI pairs namespace definitions
* @ nb_attributes : the number of attributes on that node
* nb_defaulted : the number of defaulted attributes .
* @ attributes : pointer to the array of ( localname / prefix / URI / value / end )
* attribute values .
*
* called when an opening tag has been processed .
*/
static void
xmlTextReaderStartElementNs ( void * ctx ,
const xmlChar * localname ,
const xmlChar * prefix ,
const xmlChar * URI ,
int nb_namespaces ,
const xmlChar * * namespaces ,
int nb_attributes ,
int nb_defaulted ,
const xmlChar * * attributes )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
if ( ( reader ! = NULL ) & & ( reader - > startElementNs ! = NULL ) ) {
reader - > startElementNs ( ctx , localname , prefix , URI , nb_namespaces ,
namespaces , nb_attributes , nb_defaulted ,
attributes ) ;
if ( ( ctxt - > node ! = NULL ) & & ( ctxt - > input ! = NULL ) & &
( ctxt - > input - > cur ! = NULL ) & & ( ctxt - > input - > cur [ 0 ] = = ' / ' ) & &
( ctxt - > input - > cur [ 1 ] = = ' > ' ) )
2003-10-27 14:25:13 +03:00
ctxt - > node - > extra = NODE_IS_EMPTY ;
2003-09-10 14:51:05 +04:00
}
if ( reader ! = NULL )
reader - > state = XML_TEXTREADER_ELEMENT ;
}
/**
* xmlTextReaderEndElementNs :
* @ ctx : the user data ( XML parser context )
* @ localname : the local name of the element
* @ prefix : the element namespace prefix if available
* @ URI : the element namespace name if available
*
* called when an ending tag has been processed .
*/
static void
xmlTextReaderEndElementNs ( void * ctx ,
const xmlChar * localname ,
const xmlChar * prefix ,
const xmlChar * URI )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
if ( ( reader ! = NULL ) & & ( reader - > endElementNs ! = NULL ) ) {
reader - > endElementNs ( ctx , localname , prefix , URI ) ;
}
}
2002-12-20 03:16:24 +03:00
/**
* xmlTextReaderCharacters :
* @ ctx : the user data ( XML parser context )
* @ ch : a xmlChar string
* @ len : the number of xmlChar
*
* receiving some chars from the parser .
*/
static void
xmlTextReaderCharacters ( void * ctx , const xmlChar * ch , int len )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
if ( ( reader ! = NULL ) & & ( reader - > characters ! = NULL ) ) {
reader - > characters ( ctx , ch , len ) ;
}
}
/**
* xmlTextReaderCDataBlock :
* @ ctx : the user data ( XML parser context )
* @ value : The pcdata content
* @ len : the block length
*
* called when a pcdata block has been parsed
*/
static void
xmlTextReaderCDataBlock ( void * ctx , const xmlChar * ch , int len )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlTextReaderPtr reader = ctxt - > _private ;
if ( ( reader ! = NULL ) & & ( reader - > cdataBlock ! = NULL ) ) {
reader - > cdataBlock ( ctx , ch , len ) ;
}
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderPushData :
* @ reader : the xmlTextReaderPtr used
*
* Push data down the progressive parser until a significant callback
* got raised .
*
* Returns - 1 in case of failure , 0 otherwise
*/
static int
xmlTextReaderPushData ( xmlTextReaderPtr reader ) {
2012-07-16 10:42:31 +04:00
xmlBufPtr inbuf ;
2003-04-22 01:36:41 +04:00
int val , s ;
2003-08-01 19:55:39 +04:00
xmlTextReaderState oldstate ;
2002-12-09 17:13:43 +03:00
if ( ( reader - > input = = NULL ) | | ( reader - > input - > buffer = = NULL ) )
return ( - 1 ) ;
2002-12-20 03:16:24 +03:00
oldstate = reader - > state ;
2002-12-09 17:13:43 +03:00
reader - > state = XML_TEXTREADER_NONE ;
inbuf = reader - > input - > buffer ;
2003-04-22 01:36:41 +04:00
2002-12-09 17:13:43 +03:00
while ( reader - > state = = XML_TEXTREADER_NONE ) {
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( inbuf ) < reader - > cur + CHUNK_SIZE ) {
2002-12-09 17:13:43 +03:00
/*
* Refill the buffer unless we are at the end of the stream
*/
if ( reader - > mode ! = XML_TEXTREADER_MODE_EOF ) {
val = xmlParserInputBufferRead ( reader - > input , 4096 ) ;
2023-09-21 17:29:28 +03:00
if ( val = = 0 ) {
2022-12-17 02:14:56 +03:00
if ( xmlBufUse ( inbuf ) = = reader - > cur ) {
reader - > mode = XML_TEXTREADER_MODE_EOF ;
2023-09-21 17:29:28 +03:00
break ;
2022-12-17 02:14:56 +03:00
}
} else if ( val < 0 ) {
2023-12-19 21:52:28 +03:00
xmlCtxtErrIO ( reader - > ctxt , reader - > input - > error , NULL ) ;
2023-12-10 20:23:53 +03:00
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
return ( - 1 ) ;
2002-12-09 17:13:43 +03:00
}
2003-04-22 01:36:41 +04:00
2009-08-11 20:31:42 +04:00
} else
2002-12-09 17:13:43 +03:00
break ;
}
2003-01-05 04:27:54 +03:00
/*
2003-04-22 01:36:41 +04:00
* parse by block of CHUNK_SIZE bytes , various tests show that
* it ' s the best tradeoff at least on a 1.2 GH Duron
2003-01-05 04:27:54 +03:00
*/
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( inbuf ) > = reader - > cur + CHUNK_SIZE ) {
2002-12-09 17:13:43 +03:00
val = xmlParseChunk ( reader - > ctxt ,
2012-07-16 10:42:31 +04:00
( const char * ) xmlBufContent ( inbuf ) + reader - > cur ,
CHUNK_SIZE , 0 ) ;
2003-04-22 01:36:41 +04:00
reader - > cur + = CHUNK_SIZE ;
2012-05-15 16:10:25 +04:00
if ( val ! = 0 )
reader - > ctxt - > wellFormed = 0 ;
if ( reader - > ctxt - > wellFormed = = 0 )
break ;
2002-12-09 17:13:43 +03:00
} else {
2012-07-16 10:42:31 +04:00
s = xmlBufUse ( inbuf ) - reader - > cur ;
2003-04-22 01:36:41 +04:00
val = xmlParseChunk ( reader - > ctxt ,
2012-07-16 10:42:31 +04:00
( const char * ) xmlBufContent ( inbuf ) + reader - > cur ,
s , 0 ) ;
2003-04-22 01:36:41 +04:00
reader - > cur + = s ;
2012-05-15 16:10:25 +04:00
if ( val ! = 0 )
reader - > ctxt - > wellFormed = 0 ;
2003-04-22 01:36:41 +04:00
break ;
2002-12-09 17:13:43 +03:00
}
}
2023-09-21 17:29:28 +03:00
reader - > state = oldstate ;
2003-04-22 01:36:41 +04:00
2002-12-09 17:13:43 +03:00
/*
* Discard the consumed input when needed and possible
*/
2002-12-17 01:04:11 +03:00
if ( reader - > mode = = XML_TEXTREADER_MODE_INTERACTIVE ) {
2022-11-14 22:16:22 +03:00
if ( reader - > input - > readcallback ! = NULL ) {
2004-02-19 19:37:07 +03:00
if ( ( reader - > cur > = 4096 ) & &
2012-07-16 10:42:31 +04:00
( xmlBufUse ( inbuf ) - reader - > cur < = CHUNK_SIZE ) ) {
val = xmlBufShrink ( inbuf , reader - > cur ) ;
2004-02-19 19:37:07 +03:00
if ( val > = 0 ) {
reader - > cur - = val ;
}
2002-12-09 17:13:43 +03:00
}
}
}
/*
* At the end of the stream signal that the work is done to the Push
* parser .
*/
2003-04-22 01:36:41 +04:00
else if ( reader - > mode = = XML_TEXTREADER_MODE_EOF ) {
2007-03-09 19:59:05 +03:00
if ( reader - > state ! = XML_TEXTREADER_DONE ) {
2012-07-16 10:42:31 +04:00
s = xmlBufUse ( inbuf ) - reader - > cur ;
2002-12-20 03:16:24 +03:00
val = xmlParseChunk ( reader - > ctxt ,
2012-07-16 10:42:31 +04:00
( const char * ) xmlBufContent ( inbuf ) + reader - > cur ,
s , 1 ) ;
reader - > cur = xmlBufUse ( inbuf ) ;
2007-03-09 19:59:05 +03:00
reader - > state = XML_TEXTREADER_DONE ;
2012-05-15 16:10:25 +04:00
if ( val ! = 0 ) {
if ( reader - > ctxt - > wellFormed )
reader - > ctxt - > wellFormed = 0 ;
else
return ( - 1 ) ;
}
2002-12-20 03:16:24 +03:00
}
2002-12-09 17:13:43 +03:00
}
2012-07-18 13:39:56 +04:00
if ( reader - > ctxt - > wellFormed = = 0 ) {
2012-05-15 16:10:25 +04:00
reader - > mode = XML_TEXTREADER_MODE_EOF ;
2012-07-18 13:39:56 +04:00
return ( - 1 ) ;
}
2002-12-09 17:13:43 +03:00
return ( 0 ) ;
}
2003-09-29 17:20:24 +04:00
# ifdef LIBXML_REGEXP_ENABLED
2003-01-03 04:18:43 +03:00
/**
* xmlTextReaderValidatePush :
* @ reader : the xmlTextReaderPtr used
*
* Push the current node for validation
*/
2023-12-10 20:23:53 +03:00
static int
xmlTextReaderValidatePush ( xmlTextReaderPtr reader ) {
2003-01-03 04:18:43 +03:00
xmlNodePtr node = reader - > node ;
2004-02-25 14:52:31 +03:00
# ifdef LIBXML_VALID_ENABLED
2003-04-16 03:32:22 +04:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_DTD ) & &
( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > validate = = 1 ) ) {
if ( ( node - > ns = = NULL ) | | ( node - > ns - > prefix = = NULL ) ) {
reader - > ctxt - > valid & = xmlValidatePushElement ( & reader - > ctxt - > vctxt ,
reader - > ctxt - > myDoc , node , node - > name ) ;
} else {
2024-04-22 13:23:06 +03:00
xmlChar buf [ 50 ] ;
2003-04-16 03:32:22 +04:00
xmlChar * qname ;
2024-04-22 13:23:06 +03:00
qname = xmlBuildQName ( node - > name , node - > ns - > prefix , buf , 50 ) ;
2023-12-10 20:23:53 +03:00
if ( qname = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
2003-04-16 03:32:22 +04:00
reader - > ctxt - > valid & = xmlValidatePushElement ( & reader - > ctxt - > vctxt ,
reader - > ctxt - > myDoc , node , qname ) ;
2024-04-22 13:23:06 +03:00
if ( qname ! = buf )
xmlFree ( qname ) ;
2003-04-16 03:32:22 +04:00
}
2023-12-10 20:23:53 +03:00
/*if (reader->ctxt->errNo == XML_ERR_NO_MEMORY) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
return ( - 1 ) ;
} */
2004-02-25 14:52:31 +03:00
}
# endif /* LIBXML_VALID_ENABLED */
2003-04-16 03:32:22 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2004-02-25 14:52:31 +03:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_RNG ) & &
2003-04-16 03:32:22 +04:00
( reader - > rngValidCtxt ! = NULL ) ) {
int ret ;
2023-12-10 20:23:53 +03:00
if ( reader - > rngFullNode ! = NULL ) return ( 0 ) ;
2003-04-16 03:32:22 +04:00
ret = xmlRelaxNGValidatePushElement ( reader - > rngValidCtxt ,
reader - > ctxt - > myDoc ,
node ) ;
if ( ret = = 0 ) {
/*
* this element requires a full tree
*/
node = xmlTextReaderExpand ( reader ) ;
if ( node = = NULL ) {
ret = - 1 ;
} else {
ret = xmlRelaxNGValidateFullElement ( reader - > rngValidCtxt ,
reader - > ctxt - > myDoc ,
node ) ;
reader - > rngFullNode = node ;
}
}
if ( ret ! = 1 )
reader - > rngValidErrors + + ;
}
2004-02-25 14:52:31 +03:00
# endif
2023-12-10 20:23:53 +03:00
return ( 0 ) ;
2003-04-16 03:32:22 +04:00
}
2003-01-03 04:18:43 +03:00
2003-04-16 03:32:22 +04:00
/**
* xmlTextReaderValidateCData :
* @ reader : the xmlTextReaderPtr used
* @ data : pointer to the CData
2012-09-28 10:59:33 +04:00
* @ len : length of the CData block in bytes .
2003-04-16 03:32:22 +04:00
*
* Push some CData for validation
*/
static void
xmlTextReaderValidateCData ( xmlTextReaderPtr reader ,
const xmlChar * data , int len ) {
2004-02-25 14:52:31 +03:00
# ifdef LIBXML_VALID_ENABLED
2003-04-16 03:32:22 +04:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_DTD ) & &
( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > validate = = 1 ) ) {
reader - > ctxt - > valid & = xmlValidatePushCData ( & reader - > ctxt - > vctxt ,
data , len ) ;
2004-02-25 14:52:31 +03:00
}
# endif /* LIBXML_VALID_ENABLED */
2003-04-16 03:32:22 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2004-02-25 14:52:31 +03:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_RNG ) & &
2003-04-16 03:32:22 +04:00
( reader - > rngValidCtxt ! = NULL ) ) {
int ret ;
if ( reader - > rngFullNode ! = NULL ) return ;
ret = xmlRelaxNGValidatePushCData ( reader - > rngValidCtxt , data , len ) ;
if ( ret ! = 1 )
reader - > rngValidErrors + + ;
2003-01-03 04:18:43 +03:00
}
2004-02-25 14:52:31 +03:00
# endif
2003-01-03 04:18:43 +03:00
}
2003-04-16 03:32:22 +04:00
2003-01-03 04:18:43 +03:00
/**
* xmlTextReaderValidatePop :
* @ reader : the xmlTextReaderPtr used
*
* Pop the current node from validation
*/
2023-12-10 20:23:53 +03:00
static int
2003-01-03 04:18:43 +03:00
xmlTextReaderValidatePop ( xmlTextReaderPtr reader ) {
xmlNodePtr node = reader - > node ;
2004-02-25 14:52:31 +03:00
# ifdef LIBXML_VALID_ENABLED
2003-04-16 03:32:22 +04:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_DTD ) & &
( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > validate = = 1 ) ) {
if ( ( node - > ns = = NULL ) | | ( node - > ns - > prefix = = NULL ) ) {
reader - > ctxt - > valid & = xmlValidatePopElement ( & reader - > ctxt - > vctxt ,
reader - > ctxt - > myDoc , node , node - > name ) ;
} else {
2024-04-22 13:23:06 +03:00
xmlChar buf [ 50 ] ;
2003-04-16 03:32:22 +04:00
xmlChar * qname ;
2024-04-22 13:23:06 +03:00
qname = xmlBuildQName ( node - > name , node - > ns - > prefix , buf , 50 ) ;
2023-12-10 20:23:53 +03:00
if ( qname = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
2003-04-16 03:32:22 +04:00
reader - > ctxt - > valid & = xmlValidatePopElement ( & reader - > ctxt - > vctxt ,
reader - > ctxt - > myDoc , node , qname ) ;
2024-04-22 13:23:06 +03:00
if ( qname ! = buf )
xmlFree ( qname ) ;
2003-04-16 03:32:22 +04:00
}
2023-12-10 20:23:53 +03:00
/*if (reader->ctxt->errNo == XML_ERR_NO_MEMORY) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
return ( - 1 ) ;
} */
2004-02-25 14:52:31 +03:00
}
# endif /* LIBXML_VALID_ENABLED */
2003-04-16 03:32:22 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2004-02-25 14:52:31 +03:00
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_RNG ) & &
2003-04-16 03:32:22 +04:00
( reader - > rngValidCtxt ! = NULL ) ) {
int ret ;
if ( reader - > rngFullNode ! = NULL ) {
2009-08-11 20:31:42 +04:00
if ( node = = reader - > rngFullNode )
2003-04-16 03:32:22 +04:00
reader - > rngFullNode = NULL ;
2023-12-10 20:23:53 +03:00
return ( 0 ) ;
2003-04-16 03:32:22 +04:00
}
ret = xmlRelaxNGValidatePopElement ( reader - > rngValidCtxt ,
reader - > ctxt - > myDoc ,
node ) ;
if ( ret ! = 1 )
reader - > rngValidErrors + + ;
2003-01-03 04:18:43 +03:00
}
2004-02-25 14:52:31 +03:00
# endif
2023-12-10 20:23:53 +03:00
return ( 0 ) ;
2003-01-03 04:18:43 +03:00
}
2003-09-29 17:20:24 +04:00
2003-01-03 15:52:08 +03:00
/**
* xmlTextReaderValidateEntity :
* @ reader : the xmlTextReaderPtr used
*
* Handle the validation when an entity reference is encountered and
* entity substitution is not activated . As a result the parser interface
* must walk through the entity and do the validation calls
*/
2024-02-06 14:53:03 +03:00
static int
2003-01-03 15:52:08 +03:00
xmlTextReaderValidateEntity ( xmlTextReaderPtr reader ) {
xmlNodePtr oldnode = reader - > node ;
xmlNodePtr node = reader - > node ;
do {
if ( node - > type = = XML_ENTITY_REF_NODE ) {
if ( ( node - > children ! = NULL ) & &
( node - > children - > type = = XML_ENTITY_DECL ) & &
( node - > children - > children ! = NULL ) ) {
2023-01-22 20:18:00 +03:00
if ( xmlTextReaderEntPush ( reader , node ) < 0 ) {
if ( node = = oldnode )
break ;
goto skip_children ;
}
2003-01-03 15:52:08 +03:00
node = node - > children - > children ;
continue ;
} else {
/*
2018-11-24 17:46:00 +03:00
* The error has probably been raised already .
2003-01-03 15:52:08 +03:00
*/
if ( node = = oldnode )
break ;
2018-11-24 17:46:00 +03:00
goto skip_children ;
2003-01-03 15:52:08 +03:00
}
2003-09-29 17:20:24 +04:00
# ifdef LIBXML_REGEXP_ENABLED
2003-01-03 15:52:08 +03:00
} else if ( node - > type = = XML_ELEMENT_NODE ) {
reader - > node = node ;
2023-12-10 20:23:53 +03:00
if ( xmlTextReaderValidatePush ( reader ) < 0 )
2024-02-06 14:53:03 +03:00
return ( - 1 ) ;
2003-01-03 15:52:08 +03:00
} else if ( ( node - > type = = XML_TEXT_NODE ) | |
( node - > type = = XML_CDATA_SECTION_NODE ) ) {
2003-04-16 03:32:22 +04:00
xmlTextReaderValidateCData ( reader , node - > content ,
xmlStrlen ( node - > content ) ) ;
2003-09-29 17:20:24 +04:00
# endif
2003-01-03 15:52:08 +03:00
}
/*
* go to next node
*/
if ( node - > children ! = NULL ) {
node = node - > children ;
continue ;
2003-03-23 15:02:56 +03:00
} else if ( node - > type = = XML_ELEMENT_NODE ) {
2023-12-10 20:23:53 +03:00
if ( xmlTextReaderValidatePop ( reader ) < 0 )
2024-02-06 14:53:03 +03:00
return ( - 1 ) ;
2003-01-03 15:52:08 +03:00
}
2018-11-24 17:46:00 +03:00
skip_children :
2003-01-03 15:52:08 +03:00
if ( node - > next ! = NULL ) {
node = node - > next ;
continue ;
}
do {
node = node - > parent ;
if ( node - > type = = XML_ELEMENT_NODE ) {
2003-09-28 04:19:54 +04:00
xmlNodePtr tmp ;
2003-10-21 02:32:39 +04:00
if ( reader - > entNr = = 0 ) {
while ( ( tmp = node - > last ) ! = NULL ) {
2003-10-27 14:25:13 +03:00
if ( ( tmp - > extra & NODE_IS_PRESERVED ) = = 0 ) {
2003-10-21 02:32:39 +04:00
xmlUnlinkNode ( tmp ) ;
xmlTextReaderFreeNode ( reader , tmp ) ;
} else
break ;
}
2003-09-28 04:19:54 +04:00
}
2003-01-03 15:52:08 +03:00
reader - > node = node ;
2023-12-10 20:23:53 +03:00
if ( xmlTextReaderValidatePop ( reader ) < 0 )
2024-02-06 14:53:03 +03:00
return ( - 1 ) ;
2003-01-03 15:52:08 +03:00
}
if ( ( node - > type = = XML_ENTITY_DECL ) & &
( reader - > ent ! = NULL ) & & ( reader - > ent - > children = = node ) ) {
node = xmlTextReaderEntPop ( reader ) ;
}
if ( node = = oldnode )
break ;
if ( node - > next ! = NULL ) {
node = node - > next ;
break ;
}
} while ( ( node ! = NULL ) & & ( node ! = oldnode ) ) ;
} while ( ( node ! = NULL ) & & ( node ! = oldnode ) ) ;
reader - > node = oldnode ;
2024-02-06 14:53:03 +03:00
return ( 0 ) ;
2003-01-03 15:52:08 +03:00
}
2003-09-29 17:20:24 +04:00
# endif /* LIBXML_REGEXP_ENABLED */
2003-01-03 04:18:43 +03:00
2003-04-11 13:02:11 +04:00
/**
* xmlTextReaderGetSuccessor :
* @ cur : the current node
*
* Get the successor of a node if available .
*
* Returns the successor node or NULL
*/
static xmlNodePtr
xmlTextReaderGetSuccessor ( xmlNodePtr cur ) {
if ( cur = = NULL ) return ( NULL ) ; /* ERROR */
if ( cur - > next ! = NULL ) return ( cur - > next ) ;
do {
cur = cur - > parent ;
2006-03-10 03:36:23 +03:00
if ( cur = = NULL ) break ;
2003-04-11 13:02:11 +04:00
if ( cur - > next ! = NULL ) return ( cur - > next ) ;
} while ( cur ! = NULL ) ;
return ( cur ) ;
}
/**
* xmlTextReaderDoExpand :
* @ reader : the xmlTextReaderPtr used
*
* Makes sure that the current node is fully read as well as all its
* descendant . It means the full DOM subtree must be available at the
* end of the call .
*
* Returns 1 if the node was expanded successfully , 0 if there is no more
* nodes to read , or - 1 in case of error
*/
static int
xmlTextReaderDoExpand ( xmlTextReaderPtr reader ) {
int val ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
do {
2023-12-10 20:23:53 +03:00
if ( PARSER_STOPPED ( reader - > ctxt ) )
return ( 1 ) ;
2003-10-01 13:05:25 +04:00
2003-04-11 13:02:11 +04:00
if ( xmlTextReaderGetSuccessor ( reader - > node ) ! = NULL )
return ( 1 ) ;
2003-10-01 13:05:25 +04:00
if ( reader - > ctxt - > nodeNr < reader - > depth )
2003-06-09 13:10:36 +04:00
return ( 1 ) ;
2003-04-11 13:02:11 +04:00
if ( reader - > mode = = XML_TEXTREADER_MODE_EOF )
return ( 1 ) ;
val = xmlTextReaderPushData ( reader ) ;
2007-03-09 19:59:05 +03:00
if ( val < 0 ) {
2007-03-14 15:40:21 +03:00
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
2023-10-15 14:56:34 +03:00
reader - > state = XML_TEXTREADER_ERROR ;
2003-04-11 13:02:11 +04:00
return ( - 1 ) ;
2007-03-09 19:59:05 +03:00
}
2003-04-11 13:02:11 +04:00
} while ( reader - > mode ! = XML_TEXTREADER_MODE_EOF ) ;
return ( 1 ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderRead :
* @ reader : the xmlTextReaderPtr used
*
* Moves the position of the current instance to the next node in
* the stream , exposing its properties .
*
* Returns 1 if the node was read successfully , 0 if there is no more
* nodes to read , or - 1 in case of error
*/
int
xmlTextReaderRead ( xmlTextReaderPtr reader ) {
2003-01-05 04:27:54 +03:00
int val , olddepth = 0 ;
2003-09-26 22:03:42 +04:00
xmlTextReaderState oldstate = XML_TEXTREADER_START ;
2003-01-03 04:18:43 +03:00
xmlNodePtr oldnode = NULL ;
2002-12-09 17:13:43 +03:00
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
return ( - 1 ) ;
2024-05-10 13:00:12 +03:00
if ( reader - > state = = XML_TEXTREADER_ERROR )
return ( - 1 ) ;
2004-07-22 21:18:00 +04:00
reader - > curnode = NULL ;
2003-10-20 21:07:41 +04:00
if ( reader - > doc ! = NULL )
return ( xmlTextReaderReadTree ( reader ) ) ;
if ( reader - > ctxt = = NULL )
2002-12-09 17:13:43 +03:00
return ( - 1 ) ;
2002-12-17 01:04:11 +03:00
if ( reader - > mode = = XML_TEXTREADER_MODE_INITIAL ) {
reader - > mode = XML_TEXTREADER_MODE_INTERACTIVE ;
2002-12-09 17:13:43 +03:00
/*
* Initial state
*/
do {
val = xmlTextReaderPushData ( reader ) ;
2023-10-15 14:56:34 +03:00
if ( val < 0 ) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
return ( - 1 ) ;
}
2002-12-09 17:13:43 +03:00
} while ( ( reader - > ctxt - > node = = NULL ) & &
2003-01-05 04:27:54 +03:00
( ( reader - > mode ! = XML_TEXTREADER_MODE_EOF ) & &
2007-03-09 19:59:05 +03:00
( reader - > state ! = XML_TEXTREADER_DONE ) ) ) ;
2002-12-09 17:13:43 +03:00
if ( reader - > ctxt - > node = = NULL ) {
2003-01-02 17:16:45 +03:00
if ( reader - > ctxt - > myDoc ! = NULL ) {
2002-12-09 17:13:43 +03:00
reader - > node = reader - > ctxt - > myDoc - > children ;
2003-01-02 17:16:45 +03:00
}
2023-10-15 14:56:34 +03:00
if ( reader - > node = = NULL ) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
2002-12-09 17:13:43 +03:00
return ( - 1 ) ;
2023-10-15 14:56:34 +03:00
}
2003-01-02 17:16:45 +03:00
reader - > state = XML_TEXTREADER_ELEMENT ;
2002-12-09 17:13:43 +03:00
} else {
2003-03-22 15:38:15 +03:00
if ( reader - > ctxt - > myDoc ! = NULL ) {
reader - > node = reader - > ctxt - > myDoc - > children ;
}
if ( reader - > node = = NULL )
reader - > node = reader - > ctxt - > nodeTab [ 0 ] ;
2003-01-04 19:35:29 +03:00
reader - > state = XML_TEXTREADER_ELEMENT ;
2002-12-09 17:13:43 +03:00
}
2002-12-30 21:40:42 +03:00
reader - > depth = 0 ;
2004-06-08 16:03:41 +04:00
reader - > ctxt - > parseMode = XML_PARSE_READER ;
2003-01-03 04:18:43 +03:00
goto node_found ;
2002-12-09 17:13:43 +03:00
}
oldstate = reader - > state ;
olddepth = reader - > ctxt - > nodeNr ;
oldnode = reader - > node ;
2002-12-23 18:56:21 +03:00
2003-01-03 04:18:43 +03:00
get_next_node :
2004-04-29 22:45:42 +04:00
if ( reader - > node = = NULL ) {
2023-10-15 14:56:34 +03:00
if ( reader - > mode = = XML_TEXTREADER_MODE_EOF ) {
2004-04-29 22:45:42 +04:00
return ( 0 ) ;
2023-10-15 14:56:34 +03:00
} else {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
2004-04-29 22:45:42 +04:00
return ( - 1 ) ;
2023-10-15 14:56:34 +03:00
}
2004-04-29 22:45:42 +04:00
}
2004-04-29 21:14:25 +04:00
2002-12-09 17:13:43 +03:00
/*
* If we are not backtracking on ancestors or examined nodes ,
2019-09-30 18:04:54 +03:00
* that the parser didn ' t finished or that we aren ' t at the end
2002-12-09 17:13:43 +03:00
* of stream , continue processing .
*/
2004-04-29 21:14:25 +04:00
while ( ( reader - > node ! = NULL ) & & ( reader - > node - > next = = NULL ) & &
2003-04-22 01:36:41 +04:00
( reader - > ctxt - > nodeNr = = olddepth ) & &
( ( oldstate = = XML_TEXTREADER_BACKTRACK ) | |
2002-12-20 03:16:24 +03:00
( reader - > node - > children = = NULL ) | |
( reader - > node - > type = = XML_ENTITY_REF_NODE ) | |
2003-07-18 19:16:57 +04:00
( ( reader - > node - > children ! = NULL ) & &
( reader - > node - > children - > type = = XML_TEXT_NODE ) & &
( reader - > node - > children - > next = = NULL ) ) | |
2003-01-14 03:17:42 +03:00
( reader - > node - > type = = XML_DTD_NODE ) | |
( reader - > node - > type = = XML_DOCUMENT_NODE ) | |
( reader - > node - > type = = XML_HTML_DOCUMENT_NODE ) ) & &
( ( reader - > ctxt - > node = = NULL ) | |
( reader - > ctxt - > node = = reader - > node ) | |
( reader - > ctxt - > node = = reader - > node - > parent ) ) & &
2023-12-10 20:23:53 +03:00
( reader - > ctxt - > instate ! = XML_PARSER_EOF ) & &
( PARSER_STOPPED ( reader - > ctxt ) = = 0 ) ) {
2002-12-20 03:16:24 +03:00
val = xmlTextReaderPushData ( reader ) ;
2023-10-15 14:56:34 +03:00
if ( val < 0 ) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
2002-12-20 03:16:24 +03:00
return ( - 1 ) ;
2023-10-15 14:56:34 +03:00
}
2002-12-20 03:16:24 +03:00
if ( reader - > node = = NULL )
2003-01-03 04:18:43 +03:00
goto node_end ;
2002-12-20 03:16:24 +03:00
}
2002-12-09 17:13:43 +03:00
if ( oldstate ! = XML_TEXTREADER_BACKTRACK ) {
if ( ( reader - > node - > children ! = NULL ) & &
( reader - > node - > type ! = XML_ENTITY_REF_NODE ) & &
2003-11-03 15:31:38 +03:00
( reader - > node - > type ! = XML_XINCLUDE_START ) & &
2002-12-09 17:13:43 +03:00
( reader - > node - > type ! = XML_DTD_NODE ) ) {
reader - > node = reader - > node - > children ;
reader - > depth + + ;
2002-12-23 18:56:21 +03:00
reader - > state = XML_TEXTREADER_ELEMENT ;
2003-01-03 04:18:43 +03:00
goto node_found ;
2002-12-09 17:13:43 +03:00
}
}
if ( reader - > node - > next ! = NULL ) {
if ( ( oldstate = = XML_TEXTREADER_ELEMENT ) & &
2002-12-23 18:56:21 +03:00
( reader - > node - > type = = XML_ELEMENT_NODE ) & &
2003-01-05 04:27:54 +03:00
( reader - > node - > children = = NULL ) & &
2004-01-08 19:49:50 +03:00
( ( reader - > node - > extra & NODE_IS_EMPTY ) = = 0 )
# ifdef LIBXML_XINCLUDE_ENABLED
& & ( reader - > in_xinclude < = 0 )
# endif
) {
2002-12-09 17:13:43 +03:00
reader - > state = XML_TEXTREADER_END ;
2003-01-03 04:18:43 +03:00
goto node_found ;
2002-12-09 17:13:43 +03:00
}
2003-09-29 17:20:24 +04:00
# ifdef LIBXML_REGEXP_ENABLED
2003-04-16 03:32:22 +04:00
if ( ( reader - > validate ) & &
2003-01-03 04:18:43 +03:00
( reader - > node - > type = = XML_ELEMENT_NODE ) )
2023-12-10 20:23:53 +03:00
if ( xmlTextReaderValidatePop ( reader ) < 0 )
return ( - 1 ) ;
2003-09-29 17:20:24 +04:00
# endif /* LIBXML_REGEXP_ENABLED */
2003-12-05 17:57:46 +03:00
if ( ( reader - > preserves > 0 ) & &
( reader - > node - > extra & NODE_IS_SPRESERVED ) )
reader - > preserves - - ;
2002-12-09 17:13:43 +03:00
reader - > node = reader - > node - > next ;
reader - > state = XML_TEXTREADER_ELEMENT ;
2003-01-03 04:18:43 +03:00
2002-12-09 17:13:43 +03:00
/*
* Cleanup of the old node
*/
2003-12-05 17:57:46 +03:00
if ( ( reader - > preserves = = 0 ) & &
2004-01-08 19:49:50 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
2003-12-05 17:57:46 +03:00
( reader - > in_xinclude = = 0 ) & &
2004-01-08 19:49:50 +03:00
# endif
2003-12-05 17:57:46 +03:00
( reader - > entNr = = 0 ) & &
( reader - > node - > prev ! = NULL ) & &
2013-01-28 19:55:30 +04:00
( reader - > node - > prev - > type ! = XML_DTD_NODE ) ) {
2003-01-14 03:17:42 +03:00
xmlNodePtr tmp = reader - > node - > prev ;
2003-10-27 14:25:13 +03:00
if ( ( tmp - > extra & NODE_IS_PRESERVED ) = = 0 ) {
2020-08-26 00:50:39 +03:00
if ( oldnode = = tmp )
oldnode = NULL ;
2003-09-28 04:19:54 +04:00
xmlUnlinkNode ( tmp ) ;
xmlTextReaderFreeNode ( reader , tmp ) ;
}
2002-12-09 17:13:43 +03:00
}
2003-01-03 04:18:43 +03:00
goto node_found ;
2002-12-09 17:13:43 +03:00
}
2002-12-20 03:16:24 +03:00
if ( ( oldstate = = XML_TEXTREADER_ELEMENT ) & &
2002-12-30 15:37:59 +03:00
( reader - > node - > type = = XML_ELEMENT_NODE ) & &
2003-01-05 04:27:54 +03:00
( reader - > node - > children = = NULL ) & &
2003-10-27 14:25:13 +03:00
( ( reader - > node - > extra & NODE_IS_EMPTY ) = = 0 ) ) { ;
2002-12-20 03:16:24 +03:00
reader - > state = XML_TEXTREADER_END ;
2003-01-03 04:18:43 +03:00
goto node_found ;
2002-12-20 03:16:24 +03:00
}
2003-09-29 17:20:24 +04:00
# ifdef LIBXML_REGEXP_ENABLED
2023-12-10 20:23:53 +03:00
if ( ( reader - > validate ! = XML_TEXTREADER_NOT_VALIDATE ) & &
( reader - > node - > type = = XML_ELEMENT_NODE ) ) {
if ( xmlTextReaderValidatePop ( reader ) < 0 )
return ( - 1 ) ;
}
2003-09-29 17:20:24 +04:00
# endif /* LIBXML_REGEXP_ENABLED */
2003-12-05 17:57:46 +03:00
if ( ( reader - > preserves > 0 ) & &
( reader - > node - > extra & NODE_IS_SPRESERVED ) )
reader - > preserves - - ;
2002-12-09 17:13:43 +03:00
reader - > node = reader - > node - > parent ;
if ( ( reader - > node = = NULL ) | |
( reader - > node - > type = = XML_DOCUMENT_NODE ) | |
( reader - > node - > type = = XML_HTML_DOCUMENT_NODE ) ) {
2007-03-09 19:59:05 +03:00
if ( reader - > mode ! = XML_TEXTREADER_MODE_EOF ) {
2002-12-20 03:16:24 +03:00
val = xmlParseChunk ( reader - > ctxt , " " , 0 , 1 ) ;
2007-03-09 19:59:05 +03:00
reader - > state = XML_TEXTREADER_DONE ;
2023-10-15 14:56:34 +03:00
if ( val ! = 0 ) {
reader - > mode = XML_TEXTREADER_MODE_ERROR ;
reader - > state = XML_TEXTREADER_ERROR ;
2004-07-28 11:40:12 +04:00
return ( - 1 ) ;
2023-10-15 14:56:34 +03:00
}
2002-12-20 03:16:24 +03:00
}
2002-12-09 17:13:43 +03:00
reader - > node = NULL ;
2002-12-30 21:40:42 +03:00
reader - > depth = - 1 ;
2002-12-09 17:13:43 +03:00
/*
* Cleanup of the old node
*/
2009-09-07 13:19:33 +04:00
if ( ( oldnode ! = NULL ) & & ( reader - > preserves = = 0 ) & &
2004-01-08 19:49:50 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
2003-12-05 17:57:46 +03:00
( reader - > in_xinclude = = 0 ) & &
2004-01-08 19:49:50 +03:00
# endif
2003-12-05 17:57:46 +03:00
( reader - > entNr = = 0 ) & &
( oldnode - > type ! = XML_DTD_NODE ) & &
2013-01-28 19:55:30 +04:00
( ( oldnode - > extra & NODE_IS_PRESERVED ) = = 0 ) ) {
2002-12-09 17:13:43 +03:00
xmlUnlinkNode ( oldnode ) ;
2003-09-28 04:19:54 +04:00
xmlTextReaderFreeNode ( reader , oldnode ) ;
2002-12-09 17:13:43 +03:00
}
2003-01-03 04:18:43 +03:00
goto node_end ;
2002-12-09 17:13:43 +03:00
}
2003-12-05 17:57:46 +03:00
if ( ( reader - > preserves = = 0 ) & &
2004-01-08 19:49:50 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
2003-12-05 17:57:46 +03:00
( reader - > in_xinclude = = 0 ) & &
2004-01-08 19:49:50 +03:00
# endif
2003-12-05 17:57:46 +03:00
( reader - > entNr = = 0 ) & &
( reader - > node - > last ! = NULL ) & &
( ( reader - > node - > last - > extra & NODE_IS_PRESERVED ) = = 0 ) ) {
xmlNodePtr tmp = reader - > node - > last ;
xmlUnlinkNode ( tmp ) ;
xmlTextReaderFreeNode ( reader , tmp ) ;
}
2002-12-09 17:13:43 +03:00
reader - > depth - - ;
reader - > state = XML_TEXTREADER_BACKTRACK ;
2003-01-03 04:18:43 +03:00
node_found :
2003-04-22 01:36:41 +04:00
/*
* If we are in the middle of a piece of CDATA make sure it ' s finished
*/
if ( ( reader - > node ! = NULL ) & &
2003-09-18 01:27:31 +04:00
( reader - > node - > next = = NULL ) & &
2003-04-22 01:36:41 +04:00
( ( reader - > node - > type = = XML_TEXT_NODE ) | |
( reader - > node - > type = = XML_CDATA_SECTION_NODE ) ) ) {
2004-07-29 11:07:16 +04:00
if ( xmlTextReaderExpand ( reader ) = = NULL )
return - 1 ;
2003-04-22 01:36:41 +04:00
}
2003-11-03 15:31:38 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
/*
* Handle XInclude if asked for
*/
2020-11-09 19:55:44 +03:00
if ( ( reader - > xinclude ) & & ( reader - > in_xinclude = = 0 ) & &
2023-10-14 23:45:54 +03:00
( reader - > state ! = XML_TEXTREADER_BACKTRACK ) & &
2020-11-09 19:55:44 +03:00
( reader - > node ! = NULL ) & &
2003-11-03 15:31:38 +03:00
( reader - > node - > type = = XML_ELEMENT_NODE ) & &
( reader - > node - > ns ! = NULL ) & &
2003-12-08 20:41:29 +03:00
( ( xmlStrEqual ( reader - > node - > ns - > href , XINCLUDE_NS ) ) | |
( xmlStrEqual ( reader - > node - > ns - > href , XINCLUDE_OLD_NS ) ) ) ) {
2003-11-03 15:31:38 +03:00
if ( reader - > xincctxt = = NULL ) {
reader - > xincctxt = xmlXIncludeNewContext ( reader - > ctxt - > myDoc ) ;
2023-12-10 20:23:53 +03:00
if ( reader - > xincctxt = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
2009-08-11 20:31:42 +04:00
xmlXIncludeSetFlags ( reader - > xincctxt ,
2004-08-16 16:34:50 +04:00
reader - > parserFlags & ( ~ XML_PARSE_NOXINCNODE ) ) ;
2022-10-30 14:21:20 +03:00
xmlXIncludeSetStreamingMode ( reader - > xincctxt , 1 ) ;
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlXIncludeSetErrorHandler ( reader - > xincctxt ,
xmlTextReaderStructuredRelay , reader ) ;
2024-06-11 15:47:03 +03:00
if ( reader - > resourceLoader ! = NULL )
xmlXIncludeSetResourceLoader ( reader - > xincctxt ,
reader - > resourceLoader , reader - > resourceCtxt ) ;
2003-11-03 15:31:38 +03:00
}
/*
* expand that node and process it
*/
2004-07-29 11:07:16 +04:00
if ( xmlTextReaderExpand ( reader ) = = NULL )
2023-12-10 20:23:53 +03:00
return ( - 1 ) ;
if ( xmlXIncludeProcessNode ( reader - > xincctxt , reader - > node ) < 0 ) {
int err = xmlXIncludeGetLastError ( reader - > xincctxt ) ;
if ( err = = XML_ERR_NO_MEMORY )
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
2003-11-03 15:31:38 +03:00
}
2006-03-10 03:36:23 +03:00
if ( ( reader - > node ! = NULL ) & & ( reader - > node - > type = = XML_XINCLUDE_START ) ) {
2003-11-03 15:31:38 +03:00
reader - > in_xinclude + + ;
goto get_next_node ;
2009-08-11 20:31:42 +04:00
}
2006-03-10 03:36:23 +03:00
if ( ( reader - > node ! = NULL ) & & ( reader - > node - > type = = XML_XINCLUDE_END ) ) {
2003-11-03 15:31:38 +03:00
reader - > in_xinclude - - ;
goto get_next_node ;
}
# endif
2003-01-03 04:18:43 +03:00
/*
2003-01-03 15:52:08 +03:00
* Handle entities enter and exit when in entity replacement mode
2003-01-03 04:18:43 +03:00
*/
if ( ( reader - > node ! = NULL ) & &
( reader - > node - > type = = XML_ENTITY_REF_NODE ) & &
( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > replaceEntities = = 1 ) ) {
if ( ( reader - > node - > children ! = NULL ) & &
( reader - > node - > children - > type = = XML_ENTITY_DECL ) & &
( reader - > node - > children - > children ! = NULL ) ) {
2023-01-22 20:18:00 +03:00
if ( xmlTextReaderEntPush ( reader , reader - > node ) < 0 )
goto get_next_node ;
2003-01-03 04:18:43 +03:00
reader - > node = reader - > node - > children - > children ;
}
2003-09-29 17:20:24 +04:00
# ifdef LIBXML_REGEXP_ENABLED
2003-01-03 15:52:08 +03:00
} else if ( ( reader - > node ! = NULL ) & &
( reader - > node - > type = = XML_ENTITY_REF_NODE ) & &
2003-04-16 03:32:22 +04:00
( reader - > ctxt ! = NULL ) & & ( reader - > validate ) ) {
2024-02-06 14:53:03 +03:00
if ( xmlTextReaderValidateEntity ( reader ) < 0 )
return ( - 1 ) ;
2003-09-29 17:20:24 +04:00
# endif /* LIBXML_REGEXP_ENABLED */
2003-01-03 04:18:43 +03:00
}
if ( ( reader - > node ! = NULL ) & &
( reader - > node - > type = = XML_ENTITY_DECL ) & &
( reader - > ent ! = NULL ) & & ( reader - > ent - > children = = reader - > node ) ) {
reader - > node = xmlTextReaderEntPop ( reader ) ;
reader - > depth + + ;
goto get_next_node ;
}
2003-02-04 19:14:33 +03:00
# ifdef LIBXML_REGEXP_ENABLED
2014-10-06 08:24:17 +04:00
if ( ( reader - > validate ! = XML_TEXTREADER_NOT_VALIDATE ) & & ( reader - > node ! = NULL ) ) {
2003-01-03 04:18:43 +03:00
xmlNodePtr node = reader - > node ;
2009-08-11 20:31:42 +04:00
if ( ( node - > type = = XML_ELEMENT_NODE ) & &
2003-01-03 04:18:43 +03:00
( ( reader - > state ! = XML_TEXTREADER_END ) & &
( reader - > state ! = XML_TEXTREADER_BACKTRACK ) ) ) {
2023-12-10 20:23:53 +03:00
if ( xmlTextReaderValidatePush ( reader ) < 0 )
return ( - 1 ) ;
2003-01-03 04:18:43 +03:00
} else if ( ( node - > type = = XML_TEXT_NODE ) | |
( node - > type = = XML_CDATA_SECTION_NODE ) ) {
2003-04-16 03:32:22 +04:00
xmlTextReaderValidateCData ( reader , node - > content ,
xmlStrlen ( node - > content ) ) ;
2003-01-03 04:18:43 +03:00
}
}
2003-02-04 19:14:33 +03:00
# endif /* LIBXML_REGEXP_ENABLED */
2003-12-05 17:57:46 +03:00
# ifdef LIBXML_PATTERN_ENABLED
if ( ( reader - > patternNr > 0 ) & & ( reader - > state ! = XML_TEXTREADER_END ) & &
( reader - > state ! = XML_TEXTREADER_BACKTRACK ) ) {
int i ;
for ( i = 0 ; i < reader - > patternNr ; i + + ) {
if ( xmlPatternMatch ( reader - > patternTab [ i ] , reader - > node ) = = 1 ) {
xmlTextReaderPreserve ( reader ) ;
break ;
}
}
}
2005-07-10 23:03:16 +04:00
# endif /* LIBXML_PATTERN_ENABLED */
# ifdef LIBXML_SCHEMAS_ENABLED
if ( ( reader - > validate = = XML_TEXTREADER_VALIDATE_XSD ) & &
2009-08-11 20:31:42 +04:00
( reader - > xsdValidErrors = = 0 ) & &
2005-07-10 23:03:16 +04:00
( reader - > xsdValidCtxt ! = NULL ) ) {
reader - > xsdValidErrors = ! xmlSchemaIsValid ( reader - > xsdValidCtxt ) ;
}
2003-12-05 17:57:46 +03:00
# endif /* LIBXML_PATTERN_ENABLED */
2002-12-09 17:13:43 +03:00
return ( 1 ) ;
2003-01-03 04:18:43 +03:00
node_end :
2007-03-09 19:59:05 +03:00
reader - > state = XML_TEXTREADER_DONE ;
2003-01-03 04:18:43 +03:00
return ( 0 ) ;
2002-12-09 17:13:43 +03:00
}
2002-12-17 01:04:11 +03:00
/**
* xmlTextReaderReadState :
* @ reader : the xmlTextReaderPtr used
*
* Gets the read state of the reader .
*
* Returns the state value , or - 1 in case of error
*/
int
xmlTextReaderReadState ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
return ( reader - > mode ) ;
}
2003-04-11 13:02:11 +04:00
/**
* xmlTextReaderExpand :
* @ reader : the xmlTextReaderPtr used
*
* Reads the contents of the current node and the full subtree . It then makes
2003-04-30 16:20:34 +04:00
* the subtree available until the next xmlTextReaderRead ( ) call
2003-04-11 13:02:11 +04:00
*
* Returns a node pointer valid until the next xmlTextReaderRead ( ) call
* or NULL in case of error .
*/
xmlNodePtr
xmlTextReaderExpand ( xmlTextReaderPtr reader ) {
2003-12-19 20:26:28 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
2003-04-11 13:02:11 +04:00
return ( NULL ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > doc ! = NULL )
return ( reader - > node ) ;
2003-12-19 20:26:28 +03:00
if ( reader - > ctxt = = NULL )
return ( NULL ) ;
2003-04-11 13:02:11 +04:00
if ( xmlTextReaderDoExpand ( reader ) < 0 )
return ( NULL ) ;
return ( reader - > node ) ;
}
/**
* xmlTextReaderNext :
* @ reader : the xmlTextReaderPtr used
*
* Skip to the node following the current one in document order while
* avoiding the subtree if any .
*
* Returns 1 if the node was read successfully , 0 if there is no more
* nodes to read , or - 1 in case of error
*/
int
xmlTextReaderNext ( xmlTextReaderPtr reader ) {
int ret ;
xmlNodePtr cur ;
if ( reader = = NULL )
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > doc ! = NULL )
return ( xmlTextReaderNextTree ( reader ) ) ;
2003-04-11 13:02:11 +04:00
cur = reader - > node ;
if ( ( cur = = NULL ) | | ( cur - > type ! = XML_ELEMENT_NODE ) )
return ( xmlTextReaderRead ( reader ) ) ;
2005-03-10 15:23:24 +03:00
if ( reader - > state = = XML_TEXTREADER_END | | reader - > state = = XML_TEXTREADER_BACKTRACK )
2003-04-11 13:02:11 +04:00
return ( xmlTextReaderRead ( reader ) ) ;
2003-10-27 14:25:13 +03:00
if ( cur - > extra & NODE_IS_EMPTY )
2003-09-28 04:19:54 +04:00
return ( xmlTextReaderRead ( reader ) ) ;
2003-04-11 13:02:11 +04:00
do {
ret = xmlTextReaderRead ( reader ) ;
if ( ret ! = 1 )
return ( ret ) ;
} while ( reader - > node ! = cur ) ;
return ( xmlTextReaderRead ( reader ) ) ;
}
2006-01-02 13:22:02 +03:00
# ifdef LIBXML_WRITER_ENABLED
2024-04-22 13:23:39 +03:00
static void
xmlTextReaderDumpCopy ( xmlTextReaderPtr reader , xmlOutputBufferPtr output ,
xmlNodePtr node ) {
if ( ( node - > type = = XML_DTD_NODE ) | |
( node - > type = = XML_ELEMENT_DECL ) | |
( node - > type = = XML_ATTRIBUTE_DECL ) | |
( node - > type = = XML_ENTITY_DECL ) )
return ;
if ( ( node - > type = = XML_DOCUMENT_NODE ) | |
( node - > type = = XML_HTML_DOCUMENT_NODE ) ) {
xmlNodeDumpOutput ( output , node - > doc , node , 0 , 0 , NULL ) ;
} else {
xmlNodePtr copy ;
/*
* Create a copy to make sure that namespace declarations from
* ancestors are added .
*/
copy = xmlDocCopyNode ( node , node - > doc , 1 ) ;
if ( copy = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ;
}
xmlNodeDumpOutput ( output , copy - > doc , copy , 0 , 0 , NULL ) ;
xmlFreeNode ( copy ) ;
}
}
2002-12-17 01:04:11 +03:00
/**
* xmlTextReaderReadInnerXml :
* @ reader : the xmlTextReaderPtr used
*
* Reads the contents of the current node , including child nodes and markup .
*
* Returns a string containing the XML content , or NULL if the current node
2009-08-11 20:31:42 +04:00
* is neither an element nor attribute , or has no child nodes . The
2002-12-17 01:04:11 +03:00
* string must be deallocated by the caller .
*/
xmlChar *
2024-04-22 13:23:39 +03:00
xmlTextReaderReadInnerXml ( xmlTextReaderPtr reader )
2005-06-20 21:17:54 +04:00
{
2024-04-22 13:23:39 +03:00
xmlOutputBufferPtr output ;
xmlNodePtr cur ;
xmlChar * ret ;
2005-06-20 21:17:54 +04:00
2024-04-22 13:23:39 +03:00
if ( xmlTextReaderExpand ( reader ) = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
output = xmlAllocOutputBuffer ( NULL ) ;
if ( output = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( NULL ) ;
2005-06-20 21:17:54 +04:00
}
2005-12-12 16:26:56 +03:00
2024-04-22 13:23:39 +03:00
for ( cur = reader - > node - > children ; cur ! = NULL ; cur = cur - > next )
xmlTextReaderDumpCopy ( reader , output , cur ) ;
if ( output - > error )
xmlCtxtErrIO ( reader - > ctxt , output - > error , NULL ) ;
ret = xmlBufDetach ( output - > buffer ) ;
xmlOutputBufferClose ( output ) ;
return ( ret ) ;
2002-12-17 01:04:11 +03:00
}
/**
* xmlTextReaderReadOuterXml :
* @ reader : the xmlTextReaderPtr used
*
* Reads the contents of the current node , including child nodes and markup .
*
2012-09-11 09:26:36 +04:00
* Returns a string containing the node and any XML content , or NULL if the
* current node cannot be serialized . The string must be deallocated
2010-05-05 15:59:44 +04:00
* by the caller .
2002-12-17 01:04:11 +03:00
*/
xmlChar *
2024-04-22 13:23:39 +03:00
xmlTextReaderReadOuterXml ( xmlTextReaderPtr reader )
2005-06-20 21:17:54 +04:00
{
2024-04-22 13:23:39 +03:00
xmlOutputBufferPtr output ;
2005-06-20 21:17:54 +04:00
xmlNodePtr node ;
2024-04-22 13:23:39 +03:00
xmlChar * ret ;
if ( xmlTextReaderExpand ( reader ) = = NULL )
return ( NULL ) ;
2005-06-20 21:17:54 +04:00
2019-02-25 14:00:50 +03:00
node = reader - > node ;
2024-04-22 13:23:39 +03:00
if ( node = = NULL )
return ( NULL ) ;
output = xmlAllocOutputBuffer ( NULL ) ;
if ( output = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( NULL ) ;
2005-06-20 21:17:54 +04:00
}
2024-04-22 13:23:39 +03:00
xmlTextReaderDumpCopy ( reader , output , node ) ;
if ( output - > error )
xmlCtxtErrIO ( reader - > ctxt , output - > error , NULL ) ;
2005-06-20 21:17:54 +04:00
2024-04-22 13:23:39 +03:00
ret = xmlBufDetach ( output - > buffer ) ;
xmlOutputBufferClose ( output ) ;
return ( ret ) ;
2002-12-17 01:04:11 +03:00
}
2006-01-02 13:22:02 +03:00
# endif
2002-12-17 01:04:11 +03:00
/**
* xmlTextReaderReadString :
* @ reader : the xmlTextReaderPtr used
*
* Reads the contents of an element or a text node as a string .
*
* Returns a string containing the contents of the Element or Text node ,
* or NULL if the reader is positioned on any other type of node .
* The string must be deallocated by the caller .
*/
xmlChar *
2005-01-28 20:39:49 +03:00
xmlTextReaderReadString ( xmlTextReaderPtr reader )
{
2024-04-18 13:57:15 +03:00
xmlNodePtr node , cur ;
xmlBufPtr buf ;
xmlChar * ret ;
2005-01-28 20:39:49 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
node = ( reader - > curnode ! = NULL ) ? reader - > curnode : reader - > node ;
switch ( node - > type ) {
2024-04-18 13:57:15 +03:00
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_ELEMENT_NODE :
break ;
case XML_ATTRIBUTE_NODE :
/* TODO */
break ;
default :
break ;
}
buf = xmlBufCreateSize ( 30 ) ;
if ( buf = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( NULL ) ;
2005-01-28 20:39:49 +03:00
}
2024-04-18 13:57:15 +03:00
xmlBufSetAllocationScheme ( buf , XML_BUFFER_ALLOC_DOUBLEIT ) ;
cur = node ;
while ( cur ! = NULL ) {
switch ( cur - > type ) {
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
xmlBufCat ( buf , cur - > content ) ;
break ;
case XML_ELEMENT_NODE :
if ( cur - > children ! = NULL ) {
cur = cur - > children ;
continue ;
}
break ;
default :
break ;
}
if ( cur = = node )
goto done ;
while ( cur - > next = = NULL ) {
cur = cur - > parent ;
if ( cur = = node )
goto done ;
}
cur = cur - > next ;
}
done :
ret = xmlBufDetach ( buf ) ;
if ( ret = = NULL )
xmlTextReaderErrMemory ( reader ) ;
xmlBufFree ( buf ) ;
return ( ret ) ;
2002-12-17 01:04:11 +03:00
}
2003-09-17 14:26:25 +04:00
#if 0
2002-12-18 17:53:54 +03:00
/**
* xmlTextReaderReadBase64 :
* @ reader : the xmlTextReaderPtr used
* @ array : a byte array to store the content .
* @ offset : the zero - based index into array where the method should
* begin to write .
* @ len : the number of bytes to write .
*
* Reads and decodes the Base64 encoded contents of an element and
* stores the result in a byte buffer .
*
* Returns the number of bytes written to array , or zero if the current
* instance is not positioned on an element or - 1 in case of error .
*/
int
2003-09-17 14:26:25 +04:00
xmlTextReaderReadBase64 ( xmlTextReaderPtr reader ,
unsigned char * array ATTRIBUTE_UNUSED ,
int offset ATTRIBUTE_UNUSED ,
int len ATTRIBUTE_UNUSED ) {
2002-12-18 17:53:54 +03:00
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
if ( reader - > ctxt - > wellFormed ! = 1 )
return ( - 1 ) ;
if ( ( reader - > node = = NULL ) | | ( reader - > node - > type = = XML_ELEMENT_NODE ) )
return ( 0 ) ;
return ( 0 ) ;
}
/**
* xmlTextReaderReadBinHex :
* @ reader : the xmlTextReaderPtr used
* @ array : a byte array to store the content .
* @ offset : the zero - based index into array where the method should
* begin to write .
* @ len : the number of bytes to write .
*
* Reads and decodes the BinHex encoded contents of an element and
* stores the result in a byte buffer .
*
* Returns the number of bytes written to array , or zero if the current
* instance is not positioned on an element or - 1 in case of error .
*/
int
2003-09-17 14:26:25 +04:00
xmlTextReaderReadBinHex ( xmlTextReaderPtr reader ,
unsigned char * array ATTRIBUTE_UNUSED ,
int offset ATTRIBUTE_UNUSED ,
int len ATTRIBUTE_UNUSED ) {
2002-12-18 17:53:54 +03:00
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
if ( reader - > ctxt - > wellFormed ! = 1 )
return ( - 1 ) ;
if ( ( reader - > node = = NULL ) | | ( reader - > node - > type = = XML_ELEMENT_NODE ) )
return ( 0 ) ;
return ( 0 ) ;
}
2003-09-17 14:26:25 +04:00
# endif
2002-12-18 17:53:54 +03:00
2003-10-20 21:07:41 +04:00
/************************************************************************
* *
* Operating on a preparsed tree *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int
xmlTextReaderNextTree ( xmlTextReaderPtr reader )
{
2003-11-03 15:31:38 +03:00
if ( reader = = NULL )
2003-10-20 21:07:41 +04:00
return ( - 1 ) ;
if ( reader - > state = = XML_TEXTREADER_END )
return ( 0 ) ;
2003-11-03 15:31:38 +03:00
if ( reader - > node = = NULL ) {
if ( reader - > doc - > children = = NULL ) {
2003-10-20 21:07:41 +04:00
reader - > state = XML_TEXTREADER_END ;
return ( 0 ) ;
}
reader - > node = reader - > doc - > children ;
reader - > state = XML_TEXTREADER_START ;
return ( 1 ) ;
}
if ( reader - > state ! = XML_TEXTREADER_BACKTRACK ) {
2008-08-27 19:33:28 +04:00
/* Here removed traversal to child, because we want to skip the subtree,
2008-08-25 18:53:31 +04:00
replace with traversal to sibling to skip subtree */
if ( reader - > node - > next ! = 0 ) {
2008-08-27 19:33:28 +04:00
/* Move to sibling if present,skipping sub-tree */
reader - > node = reader - > node - > next ;
2003-10-20 21:07:41 +04:00
reader - > state = XML_TEXTREADER_START ;
return ( 1 ) ;
}
2008-08-27 19:33:28 +04:00
/* if reader->node->next is NULL mean no subtree for current node,
2008-08-25 18:53:31 +04:00
so need to move to sibling of parent node if present */
2018-06-23 14:08:46 +03:00
reader - > state = XML_TEXTREADER_BACKTRACK ;
/* This will move to parent if present */
xmlTextReaderRead ( reader ) ;
2003-10-20 21:07:41 +04:00
}
if ( reader - > node - > next ! = 0 ) {
reader - > node = reader - > node - > next ;
reader - > state = XML_TEXTREADER_START ;
return ( 1 ) ;
}
if ( reader - > node - > parent ! = 0 ) {
if ( reader - > node - > parent - > type = = XML_DOCUMENT_NODE ) {
reader - > state = XML_TEXTREADER_END ;
return ( 0 ) ;
}
reader - > node = reader - > node - > parent ;
reader - > depth - - ;
reader - > state = XML_TEXTREADER_BACKTRACK ;
2008-08-27 19:33:28 +04:00
/* Repeat process to move to sibling of parent node if present */
xmlTextReaderNextTree ( reader ) ;
2003-10-20 21:07:41 +04:00
}
reader - > state = XML_TEXTREADER_END ;
return ( 1 ) ;
}
/**
* xmlTextReaderReadTree :
* @ reader : the xmlTextReaderPtr used
*
* Moves the position of the current instance to the next node in
* the stream , exposing its properties .
*
* Returns 1 if the node was read successfully , 0 if there is no more
* nodes to read , or - 1 in case of error
*/
static int
xmlTextReaderReadTree ( xmlTextReaderPtr reader ) {
if ( reader - > state = = XML_TEXTREADER_END )
return ( 0 ) ;
2003-11-03 15:31:38 +03:00
next_node :
2003-10-20 21:07:41 +04:00
if ( reader - > node = = NULL ) {
if ( reader - > doc - > children = = NULL ) {
reader - > state = XML_TEXTREADER_END ;
return ( 0 ) ;
}
reader - > node = reader - > doc - > children ;
reader - > state = XML_TEXTREADER_START ;
2003-11-03 15:31:38 +03:00
goto found_node ;
2003-10-20 21:07:41 +04:00
}
2003-11-03 15:31:38 +03:00
if ( ( reader - > state ! = XML_TEXTREADER_BACKTRACK ) & &
( reader - > node - > type ! = XML_DTD_NODE ) & &
( reader - > node - > type ! = XML_XINCLUDE_START ) & &
( reader - > node - > type ! = XML_ENTITY_REF_NODE ) ) {
if ( reader - > node - > children ! = NULL ) {
2003-10-20 21:07:41 +04:00
reader - > node = reader - > node - > children ;
reader - > depth + + ;
reader - > state = XML_TEXTREADER_START ;
2003-11-03 15:31:38 +03:00
goto found_node ;
2003-10-20 21:07:41 +04:00
}
2003-11-03 15:31:38 +03:00
if ( reader - > node - > type = = XML_ATTRIBUTE_NODE ) {
2003-10-20 21:07:41 +04:00
reader - > state = XML_TEXTREADER_BACKTRACK ;
2003-11-03 15:31:38 +03:00
goto found_node ;
2003-10-20 21:07:41 +04:00
}
}
2003-11-03 15:31:38 +03:00
if ( reader - > node - > next ! = NULL ) {
2003-10-20 21:07:41 +04:00
reader - > node = reader - > node - > next ;
reader - > state = XML_TEXTREADER_START ;
2003-11-03 15:31:38 +03:00
goto found_node ;
2003-10-20 21:07:41 +04:00
}
2003-11-03 15:31:38 +03:00
if ( reader - > node - > parent ! = NULL ) {
2003-10-20 21:07:41 +04:00
if ( ( reader - > node - > parent - > type = = XML_DOCUMENT_NODE ) | |
( reader - > node - > parent - > type = = XML_HTML_DOCUMENT_NODE ) ) {
reader - > state = XML_TEXTREADER_END ;
return ( 0 ) ;
}
reader - > node = reader - > node - > parent ;
reader - > depth - - ;
reader - > state = XML_TEXTREADER_BACKTRACK ;
2003-11-03 15:31:38 +03:00
goto found_node ;
2003-10-20 21:07:41 +04:00
}
reader - > state = XML_TEXTREADER_END ;
2003-11-03 15:31:38 +03:00
found_node :
if ( ( reader - > node - > type = = XML_XINCLUDE_START ) | |
( reader - > node - > type = = XML_XINCLUDE_END ) )
goto next_node ;
2003-10-20 21:07:41 +04:00
return ( 1 ) ;
}
/**
2003-11-18 09:54:40 +03:00
* xmlTextReaderNextSibling :
2003-10-20 21:07:41 +04:00
* @ reader : the xmlTextReaderPtr used
*
* Skip to the node following the current one in document order while
* avoiding the subtree if any .
2018-11-24 00:56:03 +03:00
* Currently implemented only for Readers built on a document
2003-10-20 21:07:41 +04:00
*
* Returns 1 if the node was read successfully , 0 if there is no more
* nodes to read , or - 1 in case of error
*/
int
xmlTextReaderNextSibling ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
2018-11-24 00:56:03 +03:00
if ( reader - > doc = = NULL ) {
/* TODO */
return ( - 1 ) ;
}
2003-10-20 21:07:41 +04:00
if ( reader - > state = = XML_TEXTREADER_END )
return ( 0 ) ;
2018-11-24 00:56:03 +03:00
if ( reader - > node = = NULL )
return ( xmlTextReaderNextTree ( reader ) ) ;
2003-10-20 21:07:41 +04:00
2003-11-03 15:31:38 +03:00
if ( reader - > node - > next ! = NULL ) {
2003-10-20 21:07:41 +04:00
reader - > node = reader - > node - > next ;
reader - > state = XML_TEXTREADER_START ;
return ( 1 ) ;
}
return ( 0 ) ;
}
2002-12-09 17:13:43 +03:00
/************************************************************************
* *
* Constructor and destructors *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlNewTextReader :
* @ input : the xmlParserInputBufferPtr used to read data
2002-12-20 03:16:24 +03:00
* @ URI : the URI information for the source if available
2002-12-09 17:13:43 +03:00
*
* Create an xmlTextReader structure fed with @ input
*
* Returns the new xmlTextReaderPtr or NULL in case of error
*/
xmlTextReaderPtr
2002-12-20 03:16:24 +03:00
xmlNewTextReader ( xmlParserInputBufferPtr input , const char * URI ) {
2002-12-09 17:13:43 +03:00
xmlTextReaderPtr ret ;
if ( input = = NULL )
return ( NULL ) ;
ret = xmlMalloc ( sizeof ( xmlTextReader ) ) ;
2023-12-10 20:23:53 +03:00
if ( ret = = NULL )
2002-12-09 17:13:43 +03:00
return ( NULL ) ;
memset ( ret , 0 , sizeof ( xmlTextReader ) ) ;
2003-10-20 21:07:41 +04:00
ret - > doc = NULL ;
2003-01-03 04:18:43 +03:00
ret - > entTab = NULL ;
ret - > entMax = 0 ;
ret - > entNr = 0 ;
2002-12-09 17:13:43 +03:00
ret - > input = input ;
2012-07-16 10:42:31 +04:00
ret - > buffer = xmlBufCreateSize ( 100 ) ;
2004-07-31 20:24:01 +04:00
if ( ret - > buffer = = NULL ) {
xmlFree ( ret ) ;
return ( NULL ) ;
}
2015-04-14 12:41:48 +03:00
/* no operation on a reader should require a huge buffer */
xmlBufSetAllocationScheme ( ret - > buffer ,
2022-03-05 23:46:40 +03:00
XML_BUFFER_ALLOC_DOUBLEIT ) ;
2002-12-09 17:13:43 +03:00
ret - > sax = ( xmlSAXHandler * ) xmlMalloc ( sizeof ( xmlSAXHandler ) ) ;
if ( ret - > sax = = NULL ) {
2012-07-16 10:42:31 +04:00
xmlBufFree ( ret - > buffer ) ;
2002-12-09 17:13:43 +03:00
xmlFree ( ret ) ;
return ( NULL ) ;
}
2003-09-30 04:43:48 +04:00
xmlSAXVersion ( ret - > sax , 2 ) ;
2002-12-09 17:13:43 +03:00
ret - > startElement = ret - > sax - > startElement ;
ret - > sax - > startElement = xmlTextReaderStartElement ;
ret - > endElement = ret - > sax - > endElement ;
ret - > sax - > endElement = xmlTextReaderEndElement ;
2003-09-30 04:43:48 +04:00
# ifdef LIBXML_SAX1_ENABLED
2003-09-10 14:51:05 +04:00
if ( ret - > sax - > initialized = = XML_SAX2_MAGIC ) {
2003-09-30 04:43:48 +04:00
# endif /* LIBXML_SAX1_ENABLED */
2003-09-10 14:51:05 +04:00
ret - > startElementNs = ret - > sax - > startElementNs ;
ret - > sax - > startElementNs = xmlTextReaderStartElementNs ;
ret - > endElementNs = ret - > sax - > endElementNs ;
ret - > sax - > endElementNs = xmlTextReaderEndElementNs ;
2003-09-30 04:43:48 +04:00
# ifdef LIBXML_SAX1_ENABLED
2003-09-10 14:51:05 +04:00
} else {
ret - > startElementNs = NULL ;
ret - > endElementNs = NULL ;
}
2003-09-30 04:43:48 +04:00
# endif /* LIBXML_SAX1_ENABLED */
2002-12-20 03:16:24 +03:00
ret - > characters = ret - > sax - > characters ;
ret - > sax - > characters = xmlTextReaderCharacters ;
2003-09-03 17:28:32 +04:00
ret - > sax - > ignorableWhitespace = xmlTextReaderCharacters ;
2002-12-20 03:16:24 +03:00
ret - > cdataBlock = ret - > sax - > cdataBlock ;
ret - > sax - > cdataBlock = xmlTextReaderCDataBlock ;
2002-12-09 17:13:43 +03:00
2002-12-17 01:04:11 +03:00
ret - > mode = XML_TEXTREADER_MODE_INITIAL ;
2002-12-09 17:13:43 +03:00
ret - > node = NULL ;
2002-12-16 02:36:49 +03:00
ret - > curnode = NULL ;
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( ret - > input - > buffer ) < 4 ) {
2003-09-26 22:03:42 +04:00
xmlParserInputBufferRead ( input , 4 ) ;
2003-09-18 17:35:51 +04:00
}
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( ret - > input - > buffer ) > = 4 ) {
2002-12-09 17:13:43 +03:00
ret - > ctxt = xmlCreatePushParserCtxt ( ret - > sax , NULL ,
2012-07-16 10:42:31 +04:00
( const char * ) xmlBufContent ( ret - > input - > buffer ) ,
4 , URI ) ;
2002-12-09 17:13:43 +03:00
ret - > base = 0 ;
ret - > cur = 4 ;
} else {
2002-12-20 03:16:24 +03:00
ret - > ctxt = xmlCreatePushParserCtxt ( ret - > sax , NULL , NULL , 0 , URI ) ;
2002-12-09 17:13:43 +03:00
ret - > base = 0 ;
ret - > cur = 0 ;
}
2009-08-11 20:31:42 +04:00
2003-04-24 20:06:47 +04:00
if ( ret - > ctxt = = NULL ) {
2012-07-16 10:42:31 +04:00
xmlBufFree ( ret - > buffer ) ;
2003-04-24 20:06:47 +04:00
xmlFree ( ret - > sax ) ;
xmlFree ( ret ) ;
return ( NULL ) ;
}
2004-06-08 16:03:41 +04:00
ret - > ctxt - > parseMode = XML_PARSE_READER ;
2002-12-09 17:13:43 +03:00
ret - > ctxt - > _private = ret ;
2002-12-20 03:16:24 +03:00
ret - > ctxt - > linenumbers = 1 ;
2003-09-17 14:26:25 +04:00
ret - > ctxt - > dictNames = 1 ;
2002-12-09 17:13:43 +03:00
ret - > allocs = XML_TEXTREADER_CTXT ;
2003-09-03 17:28:32 +04:00
/*
2016-04-13 17:56:07 +03:00
* use the parser dictionary to allocate all elements and attributes names
2003-09-03 17:28:32 +04:00
*/
2003-10-20 21:07:41 +04:00
ret - > dict = ret - > ctxt - > dict ;
2003-11-03 15:31:38 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
ret - > xinclude = 0 ;
2003-12-05 17:57:46 +03:00
# endif
# ifdef LIBXML_PATTERN_ENABLED
ret - > patternMax = 0 ;
ret - > patternTab = NULL ;
2003-11-03 15:31:38 +03:00
# endif
2002-12-09 17:13:43 +03:00
return ( ret ) ;
}
/**
* xmlNewTextReaderFilename :
* @ URI : the URI of the resource to process
*
* Create an xmlTextReader structure fed with the resource at @ URI
*
* Returns the new xmlTextReaderPtr or NULL in case of error
*/
xmlTextReaderPtr
xmlNewTextReaderFilename ( const char * URI ) {
xmlParserInputBufferPtr input ;
xmlTextReaderPtr ret ;
input = xmlParserInputBufferCreateFilename ( URI , XML_CHAR_ENCODING_NONE ) ;
if ( input = = NULL )
return ( NULL ) ;
2002-12-20 03:16:24 +03:00
ret = xmlNewTextReader ( input , URI ) ;
2002-12-09 17:13:43 +03:00
if ( ret = = NULL ) {
xmlFreeParserInputBuffer ( input ) ;
return ( NULL ) ;
}
ret - > allocs | = XML_TEXTREADER_INPUT ;
return ( ret ) ;
}
/**
* xmlFreeTextReader :
* @ reader : the xmlTextReaderPtr
*
* Deallocate all the resources associated to the reader
*/
void
xmlFreeTextReader ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ;
2003-05-09 23:38:15 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2003-04-16 03:32:22 +04:00
if ( reader - > rngSchemas ! = NULL ) {
xmlRelaxNGFree ( reader - > rngSchemas ) ;
reader - > rngSchemas = NULL ;
}
if ( reader - > rngValidCtxt ! = NULL ) {
2012-03-19 12:08:16 +04:00
if ( ! reader - > rngPreserveCtxt )
xmlRelaxNGFreeValidCtxt ( reader - > rngValidCtxt ) ;
2003-04-16 03:32:22 +04:00
reader - > rngValidCtxt = NULL ;
}
2005-07-10 23:03:16 +04:00
if ( reader - > xsdPlug ! = NULL ) {
xmlSchemaSAXUnplug ( reader - > xsdPlug ) ;
reader - > xsdPlug = NULL ;
}
if ( reader - > xsdValidCtxt ! = NULL ) {
2005-12-07 17:02:42 +03:00
if ( ! reader - > xsdPreserveCtxt )
xmlSchemaFreeValidCtxt ( reader - > xsdValidCtxt ) ;
2005-07-10 23:03:16 +04:00
reader - > xsdValidCtxt = NULL ;
}
if ( reader - > xsdSchemas ! = NULL ) {
xmlSchemaFree ( reader - > xsdSchemas ) ;
reader - > xsdSchemas = NULL ;
}
2003-11-03 15:31:38 +03:00
# endif
# ifdef LIBXML_XINCLUDE_ENABLED
if ( reader - > xincctxt ! = NULL )
xmlXIncludeFreeContext ( reader - > xincctxt ) ;
2003-12-05 17:57:46 +03:00
# endif
# ifdef LIBXML_PATTERN_ENABLED
if ( reader - > patternTab ! = NULL ) {
int i ;
for ( i = 0 ; i < reader - > patternNr ; i + + ) {
if ( reader - > patternTab [ i ] ! = NULL )
xmlFreePattern ( reader - > patternTab [ i ] ) ;
}
xmlFree ( reader - > patternTab ) ;
}
2003-05-09 23:38:15 +04:00
# endif
2022-04-11 06:02:47 +03:00
if ( reader - > mode ! = XML_TEXTREADER_MODE_CLOSED )
xmlTextReaderClose ( reader ) ;
2002-12-09 17:13:43 +03:00
if ( reader - > ctxt ! = NULL ) {
2003-10-20 21:07:41 +04:00
if ( reader - > dict = = reader - > ctxt - > dict )
reader - > dict = NULL ;
2002-12-09 17:13:43 +03:00
if ( reader - > allocs & XML_TEXTREADER_CTXT )
xmlFreeParserCtxt ( reader - > ctxt ) ;
}
if ( reader - > sax ! = NULL )
xmlFree ( reader - > sax ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > buffer ! = NULL )
2012-07-16 10:42:31 +04:00
xmlBufFree ( reader - > buffer ) ;
2003-01-03 04:18:43 +03:00
if ( reader - > entTab ! = NULL )
xmlFree ( reader - > entTab ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > dict ! = NULL )
xmlDictFree ( reader - > dict ) ;
2002-12-09 17:13:43 +03:00
xmlFree ( reader ) ;
}
2002-12-15 02:00:35 +03:00
/************************************************************************
* *
* Methods for XmlTextReader *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2024-04-22 13:23:06 +03:00
2002-12-15 02:00:35 +03:00
/**
* xmlTextReaderClose :
* @ reader : the xmlTextReaderPtr used
*
* This method releases any resources allocated by the current instance
* changes the state to Closed and close any underlying input .
*
* Returns 0 or - 1 in case of error
*/
int
xmlTextReaderClose ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
reader - > node = NULL ;
2002-12-16 02:36:49 +03:00
reader - > curnode = NULL ;
2002-12-15 02:00:35 +03:00
reader - > mode = XML_TEXTREADER_MODE_CLOSED ;
2022-04-11 06:02:47 +03:00
if ( reader - > faketext ! = NULL ) {
xmlFreeNode ( reader - > faketext ) ;
reader - > faketext = NULL ;
}
2002-12-15 02:00:35 +03:00
if ( reader - > ctxt ! = NULL ) {
2022-04-11 06:02:47 +03:00
# ifdef LIBXML_VALID_ENABLED
if ( ( reader - > ctxt - > vctxt . vstateTab ! = NULL ) & &
( reader - > ctxt - > vctxt . vstateMax > 0 ) ) {
# ifdef LIBXML_REGEXP_ENABLED
while ( reader - > ctxt - > vctxt . vstateNr > 0 )
xmlValidatePopElement ( & reader - > ctxt - > vctxt , NULL , NULL , NULL ) ;
# endif /* LIBXML_REGEXP_ENABLED */
xmlFree ( reader - > ctxt - > vctxt . vstateTab ) ;
reader - > ctxt - > vctxt . vstateTab = NULL ;
reader - > ctxt - > vctxt . vstateMax = 0 ;
}
# endif /* LIBXML_VALID_ENABLED */
2004-04-18 18:58:57 +04:00
xmlStopParser ( reader - > ctxt ) ;
2002-12-15 02:00:35 +03:00
if ( reader - > ctxt - > myDoc ! = NULL ) {
2003-09-28 04:19:54 +04:00
if ( reader - > preserve = = 0 )
xmlTextReaderFreeDoc ( reader , reader - > ctxt - > myDoc ) ;
2002-12-15 02:00:35 +03:00
reader - > ctxt - > myDoc = NULL ;
}
}
if ( ( reader - > input ! = NULL ) & & ( reader - > allocs & XML_TEXTREADER_INPUT ) ) {
xmlFreeParserInputBuffer ( reader - > input ) ;
reader - > allocs - = XML_TEXTREADER_INPUT ;
}
return ( 0 ) ;
}
/**
* xmlTextReaderGetAttributeNo :
* @ reader : the xmlTextReaderPtr used
* @ no : the zero - based index of the attribute relative to the containing element
*
* Provides the value of the attribute with the specified index relative
* to the containing element .
*
* Returns a string containing the value of the specified attribute , or NULL
* in case of error . The string must be deallocated by the caller .
*/
xmlChar *
xmlTextReaderGetAttributeNo ( xmlTextReaderPtr reader , int no ) {
xmlChar * ret ;
int i ;
xmlAttrPtr cur ;
xmlNsPtr ns ;
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
return ( NULL ) ;
2002-12-15 02:00:35 +03:00
/* TODO: handle the xmlDecl */
2009-08-11 20:31:42 +04:00
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
2002-12-15 02:00:35 +03:00
return ( NULL ) ;
ns = reader - > node - > nsDef ;
for ( i = 0 ; ( i < no ) & & ( ns ! = NULL ) ; i + + ) {
ns = ns - > next ;
}
if ( ns ! = NULL )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , ns - > href ) ) ;
2002-12-15 02:00:35 +03:00
cur = reader - > node - > properties ;
if ( cur = = NULL )
return ( NULL ) ;
for ( ; i < no ; i + + ) {
cur = cur - > next ;
if ( cur = = NULL )
return ( NULL ) ;
}
/* TODO walk the DTD if present */
ret = xmlNodeListGetString ( reader - > node - > doc , cur - > children , 1 ) ;
2024-04-22 13:23:06 +03:00
if ( ret = = NULL )
xmlTextReaderErrMemory ( reader ) ;
2002-12-15 02:00:35 +03:00
return ( ret ) ;
}
/**
* xmlTextReaderGetAttribute :
* @ reader : the xmlTextReaderPtr used
* @ name : the qualified name of the attribute .
*
* Provides the value of the attribute with the specified qualified name .
*
* Returns a string containing the value of the specified attribute , or NULL
* in case of error . The string must be deallocated by the caller .
*/
xmlChar *
xmlTextReaderGetAttribute ( xmlTextReaderPtr reader , const xmlChar * name ) {
xmlChar * prefix = NULL ;
2024-04-22 13:23:06 +03:00
const xmlChar * localname ;
2002-12-15 02:00:35 +03:00
xmlNsPtr ns ;
xmlChar * ret = NULL ;
2024-04-22 13:23:06 +03:00
int result ;
2002-12-15 02:00:35 +03:00
if ( ( reader = = NULL ) | | ( name = = NULL ) )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
return ( NULL ) ;
2002-12-15 02:00:35 +03:00
/* TODO: handle the xmlDecl */
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
localname = xmlSplitQName4 ( name , & prefix ) ;
2005-08-17 11:07:44 +04:00
if ( localname = = NULL ) {
2024-04-22 13:23:06 +03:00
xmlTextReaderErrMemory ( reader ) ;
return ( NULL ) ;
}
if ( prefix = = NULL ) {
/*
* Namespace default decl
*/
if ( xmlStrEqual ( name , BAD_CAST " xmlns " ) ) {
ns = reader - > node - > nsDef ;
while ( ns ! = NULL ) {
if ( ns - > prefix = = NULL ) {
return ( readerStrdup ( reader , ns - > href ) ) ;
}
ns = ns - > next ;
}
return NULL ;
}
result = xmlNodeGetAttrValue ( reader - > node , name , NULL , & ret ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
return ( ret ) ;
}
2005-08-17 11:07:44 +04:00
/*
* Namespace default decl
*/
if ( xmlStrEqual ( prefix , BAD_CAST " xmlns " ) ) {
2024-04-22 13:23:06 +03:00
ns = reader - > node - > nsDef ;
while ( ns ! = NULL ) {
if ( ( ns - > prefix ! = NULL ) & & ( xmlStrEqual ( ns - > prefix , localname ) ) ) {
ret = readerStrdup ( reader , ns - > href ) ;
break ;
}
ns = ns - > next ;
}
2005-08-17 11:07:44 +04:00
} else {
2024-04-22 13:23:06 +03:00
result = xmlSearchNsSafe ( reader - > node , prefix , & ns ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
if ( ns ! = NULL ) {
result = xmlNodeGetAttrValue ( reader - > node , localname , ns - > href ,
& ret ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
}
}
2002-12-15 02:00:35 +03:00
if ( prefix ! = NULL )
xmlFree ( prefix ) ;
return ( ret ) ;
}
/**
* xmlTextReaderGetAttributeNs :
* @ reader : the xmlTextReaderPtr used
* @ localName : the local name of the attribute .
* @ namespaceURI : the namespace URI of the attribute .
*
* Provides the value of the specified attribute
*
* Returns a string containing the value of the specified attribute , or NULL
* in case of error . The string must be deallocated by the caller .
*/
xmlChar *
xmlTextReaderGetAttributeNs ( xmlTextReaderPtr reader , const xmlChar * localName ,
const xmlChar * namespaceURI ) {
2024-04-22 13:23:06 +03:00
xmlChar * ret = NULL ;
2005-08-21 01:14:28 +04:00
xmlChar * prefix = NULL ;
xmlNsPtr ns ;
2024-04-22 13:23:06 +03:00
int result ;
2005-08-21 01:14:28 +04:00
2002-12-15 02:00:35 +03:00
if ( ( reader = = NULL ) | | ( localName = = NULL ) )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
return ( NULL ) ;
2002-12-15 02:00:35 +03:00
/* TODO: handle the xmlDecl */
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( NULL ) ;
2005-08-21 01:14:28 +04:00
if ( xmlStrEqual ( namespaceURI , BAD_CAST " http://www.w3.org/2000/xmlns/ " ) ) {
2024-04-22 13:23:06 +03:00
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 readerStrdup ( reader , ns - > href ) ;
}
ns = ns - > next ;
}
return NULL ;
2005-08-21 01:14:28 +04:00
}
2024-04-22 13:23:06 +03:00
result = xmlNodeGetAttrValue ( reader - > node , localName , namespaceURI , & ret ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
return ( ret ) ;
2002-12-15 02:00:35 +03:00
}
2002-12-16 02:36:49 +03:00
/**
* xmlTextReaderGetRemainder :
* @ reader : the xmlTextReaderPtr used
*
* Method to get the remainder of the buffered XML . this method stops the
* parser , set its state to End Of File and return the input stream with
* what is left that the parser did not use .
*
2019-09-30 18:04:54 +03:00
* The implementation is not good , the parser certainly progressed past
2004-04-18 18:58:57 +04:00
* what ' s left in reader - > input , and there is an allocation problem . Best
* would be to rewrite it differently .
*
2002-12-16 02:36:49 +03:00
* Returns the xmlParserInputBufferPtr attached to the XML or NULL
* in case of error .
*/
xmlParserInputBufferPtr
xmlTextReaderGetRemainder ( xmlTextReaderPtr reader ) {
xmlParserInputBufferPtr ret = NULL ;
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
reader - > node = NULL ;
reader - > curnode = NULL ;
reader - > mode = XML_TEXTREADER_MODE_EOF ;
if ( reader - > ctxt ! = NULL ) {
2004-04-18 18:58:57 +04:00
xmlStopParser ( reader - > ctxt ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > ctxt - > myDoc ! = NULL ) {
2003-09-28 04:19:54 +04:00
if ( reader - > preserve = = 0 )
xmlTextReaderFreeDoc ( reader , reader - > ctxt - > myDoc ) ;
2002-12-16 02:36:49 +03:00
reader - > ctxt - > myDoc = NULL ;
}
}
if ( reader - > allocs & XML_TEXTREADER_INPUT ) {
ret = reader - > input ;
2004-04-18 18:58:57 +04:00
reader - > input = NULL ;
2002-12-16 02:36:49 +03:00
reader - > allocs - = XML_TEXTREADER_INPUT ;
} else {
/*
* Hum , one may need to duplicate the data structure because
* without reference counting the input may be freed twice :
* - by the layer which allocated it .
* - by the layer to which would have been returned to .
*/
return ( NULL ) ;
}
return ( ret ) ;
}
/**
* xmlTextReaderLookupNamespace :
* @ reader : the xmlTextReaderPtr used
* @ prefix : the prefix whose namespace URI is to be resolved . To return
* the default namespace , specify NULL
*
* Resolves a namespace prefix in the scope of the current element .
*
* Returns a string containing the namespace URI to which the prefix maps
* or NULL in case of error . The string must be deallocated by the caller .
*/
xmlChar *
xmlTextReaderLookupNamespace ( xmlTextReaderPtr reader , const xmlChar * prefix ) {
xmlNsPtr ns ;
2024-04-22 13:23:06 +03:00
int result ;
2002-12-16 02:36:49 +03:00
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
result = xmlSearchNsSafe ( reader - > node , prefix , & ns ) ;
if ( result < 0 ) {
xmlTextReaderErrMemory ( reader ) ;
return ( NULL ) ;
}
2002-12-16 02:36:49 +03:00
if ( ns = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , ns - > href ) ) ;
2002-12-16 02:36:49 +03:00
}
/**
* xmlTextReaderMoveToAttributeNo :
* @ reader : the xmlTextReaderPtr used
* @ no : the zero - based index of the attribute relative to the containing
* element .
*
* Moves the position of the current instance to the attribute with
* the specified index relative to the containing element .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not found
*/
int
xmlTextReaderMoveToAttributeNo ( xmlTextReaderPtr reader , int no ) {
int i ;
xmlAttrPtr cur ;
xmlNsPtr ns ;
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
/* TODO: handle the xmlDecl */
2009-08-11 20:31:42 +04:00
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
2002-12-16 02:36:49 +03:00
return ( - 1 ) ;
reader - > curnode = NULL ;
ns = reader - > node - > nsDef ;
for ( i = 0 ; ( i < no ) & & ( ns ! = NULL ) ; i + + ) {
ns = ns - > next ;
}
if ( ns ! = NULL ) {
reader - > curnode = ( xmlNodePtr ) ns ;
return ( 1 ) ;
}
cur = reader - > node - > properties ;
if ( cur = = NULL )
return ( 0 ) ;
for ( ; i < no ; i + + ) {
cur = cur - > next ;
if ( cur = = NULL )
return ( 0 ) ;
}
/* TODO walk the DTD if present */
reader - > curnode = ( xmlNodePtr ) cur ;
return ( 1 ) ;
}
/**
* xmlTextReaderMoveToAttribute :
* @ reader : the xmlTextReaderPtr used
* @ name : the qualified name of the attribute .
*
* Moves the position of the current instance to the attribute with
* the specified qualified name .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not found
*/
int
xmlTextReaderMoveToAttribute ( xmlTextReaderPtr reader , const xmlChar * name ) {
xmlChar * prefix = NULL ;
2024-04-22 13:23:06 +03:00
const xmlChar * localname ;
2002-12-16 02:36:49 +03:00
xmlNsPtr ns ;
xmlAttrPtr prop ;
if ( ( reader = = NULL ) | | ( name = = NULL ) )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
/* TODO: handle the xmlDecl */
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
2024-04-22 13:23:06 +03:00
localname = xmlSplitQName4 ( name , & prefix ) ;
2002-12-16 02:36:49 +03:00
if ( localname = = NULL ) {
2024-04-22 13:23:06 +03:00
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
if ( prefix = = NULL ) {
2002-12-16 02:36:49 +03:00
/*
* Namespace default decl
*/
if ( xmlStrEqual ( name , BAD_CAST " xmlns " ) ) {
ns = reader - > node - > nsDef ;
while ( ns ! = NULL ) {
if ( ns - > prefix = = NULL ) {
reader - > curnode = ( xmlNodePtr ) ns ;
return ( 1 ) ;
}
ns = ns - > next ;
}
return ( 0 ) ;
}
prop = reader - > node - > properties ;
while ( prop ! = NULL ) {
/*
* One need to have
* - same attribute names
* - and the attribute carrying that namespace
*/
if ( ( xmlStrEqual ( prop - > name , name ) ) & &
( ( prop - > ns = = NULL ) | | ( prop - > ns - > prefix = = NULL ) ) ) {
reader - > curnode = ( xmlNodePtr ) prop ;
return ( 1 ) ;
}
prop = prop - > next ;
}
return ( 0 ) ;
}
2009-08-11 20:31:42 +04:00
2002-12-16 02:36:49 +03:00
/*
* Namespace default decl
*/
if ( xmlStrEqual ( prefix , BAD_CAST " xmlns " ) ) {
ns = reader - > node - > nsDef ;
while ( ns ! = NULL ) {
if ( ( ns - > prefix ! = NULL ) & & ( xmlStrEqual ( ns - > prefix , localname ) ) ) {
reader - > curnode = ( xmlNodePtr ) ns ;
goto found ;
}
ns = ns - > next ;
}
goto not_found ;
}
prop = reader - > node - > properties ;
while ( prop ! = NULL ) {
/*
* One need to have
* - same attribute names
* - and the attribute carrying that namespace
*/
if ( ( xmlStrEqual ( prop - > name , localname ) ) & &
( prop - > ns ! = NULL ) & & ( xmlStrEqual ( prop - > ns - > prefix , prefix ) ) ) {
reader - > curnode = ( xmlNodePtr ) prop ;
goto found ;
}
prop = prop - > next ;
}
not_found :
if ( prefix ! = NULL )
xmlFree ( prefix ) ;
return ( 0 ) ;
found :
if ( prefix ! = NULL )
xmlFree ( prefix ) ;
return ( 1 ) ;
}
/**
* xmlTextReaderMoveToAttributeNs :
* @ reader : the xmlTextReaderPtr used
* @ localName : the local name of the attribute .
* @ namespaceURI : the namespace URI of the attribute .
*
* Moves the position of the current instance to the attribute with the
* specified local name and namespace URI .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not found
*/
int
xmlTextReaderMoveToAttributeNs ( xmlTextReaderPtr reader ,
const xmlChar * localName , const xmlChar * namespaceURI ) {
xmlAttrPtr prop ;
xmlNodePtr node ;
2005-08-21 01:14:28 +04:00
xmlNsPtr ns ;
xmlChar * prefix = NULL ;
2002-12-16 02:36:49 +03:00
if ( ( reader = = NULL ) | | ( localName = = NULL ) | | ( namespaceURI = = NULL ) )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
node = reader - > node ;
2005-08-21 01:14:28 +04:00
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 ) {
2009-08-11 20:31:42 +04:00
if ( ( prefix = = NULL & & ns - > prefix = = NULL ) | |
2005-08-21 01:14:28 +04:00
( ( ns - > prefix ! = NULL ) & & ( xmlStrEqual ( ns - > prefix , localName ) ) ) ) {
reader - > curnode = ( xmlNodePtr ) ns ;
return ( 1 ) ;
}
ns = ns - > next ;
}
return ( 0 ) ;
}
2002-12-16 02:36:49 +03:00
prop = node - > properties ;
while ( prop ! = NULL ) {
/*
* One need to have
* - same attribute names
* - and the attribute carrying that namespace
*/
if ( xmlStrEqual ( prop - > name , localName ) & &
( ( prop - > ns ! = NULL ) & &
( xmlStrEqual ( prop - > ns - > href , namespaceURI ) ) ) ) {
reader - > curnode = ( xmlNodePtr ) prop ;
return ( 1 ) ;
}
prop = prop - > next ;
}
return ( 0 ) ;
}
/**
* xmlTextReaderMoveToFirstAttribute :
* @ reader : the xmlTextReaderPtr used
*
* Moves the position of the current instance to the first attribute
* associated with the current node .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not found
*/
int
xmlTextReaderMoveToFirstAttribute ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
if ( reader - > node - > nsDef ! = NULL ) {
reader - > curnode = ( xmlNodePtr ) reader - > node - > nsDef ;
return ( 1 ) ;
}
if ( reader - > node - > properties ! = NULL ) {
reader - > curnode = ( xmlNodePtr ) reader - > node - > properties ;
return ( 1 ) ;
}
return ( 0 ) ;
}
/**
* xmlTextReaderMoveToNextAttribute :
* @ reader : the xmlTextReaderPtr used
*
* Moves the position of the current instance to the next attribute
* associated with the current node .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not found
*/
int
xmlTextReaderMoveToNextAttribute ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
if ( reader - > curnode = = NULL )
return ( xmlTextReaderMoveToFirstAttribute ( reader ) ) ;
if ( reader - > curnode - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) reader - > curnode ;
if ( ns - > next ! = NULL ) {
reader - > curnode = ( xmlNodePtr ) ns - > next ;
return ( 1 ) ;
}
if ( reader - > node - > properties ! = NULL ) {
reader - > curnode = ( xmlNodePtr ) reader - > node - > properties ;
return ( 1 ) ;
}
return ( 0 ) ;
} else if ( ( reader - > curnode - > type = = XML_ATTRIBUTE_NODE ) & &
( reader - > curnode - > next ! = NULL ) ) {
reader - > curnode = reader - > curnode - > next ;
return ( 1 ) ;
}
return ( 0 ) ;
}
/**
* xmlTextReaderMoveToElement :
* @ reader : the xmlTextReaderPtr used
*
* Moves the position of the current instance to the node that
* contains the current Attribute node .
*
* Returns 1 in case of success , - 1 in case of error , 0 if not moved
*/
int
xmlTextReaderMoveToElement ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
if ( reader - > curnode ! = NULL ) {
reader - > curnode = NULL ;
return ( 1 ) ;
}
return ( 0 ) ;
}
2002-12-18 17:53:54 +03:00
/**
* xmlTextReaderReadAttributeValue :
* @ reader : the xmlTextReaderPtr used
*
* Parses an attribute value into one or more Text and EntityReference nodes .
*
2019-09-30 18:04:54 +03:00
* Returns 1 in case of success , 0 if the reader was not positioned on an
* attribute node or all the attribute values have been read , or - 1
2002-12-18 17:53:54 +03:00
* in case of error .
*/
int
xmlTextReaderReadAttributeValue ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > curnode = = NULL )
return ( 0 ) ;
if ( reader - > curnode - > type = = XML_ATTRIBUTE_NODE ) {
if ( reader - > curnode - > children = = NULL )
return ( 0 ) ;
reader - > curnode = reader - > curnode - > children ;
} else if ( reader - > curnode - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) reader - > curnode ;
if ( reader - > faketext = = NULL ) {
2009-08-11 20:31:42 +04:00
reader - > faketext = xmlNewDocText ( reader - > node - > doc ,
2002-12-18 17:53:54 +03:00
ns - > href ) ;
2023-12-10 20:23:53 +03:00
if ( reader - > faketext = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
2002-12-18 17:53:54 +03:00
} else {
2005-08-25 17:19:21 +04:00
if ( ( reader - > faketext - > content ! = NULL ) & &
( reader - > faketext - > content ! =
( xmlChar * ) & ( reader - > faketext - > properties ) ) )
2002-12-18 17:53:54 +03:00
xmlFree ( reader - > faketext - > content ) ;
2023-12-10 20:23:53 +03:00
if ( ns - > href = = NULL ) {
reader - > faketext - > content = NULL ;
} else {
reader - > faketext - > content = xmlStrdup ( ns - > href ) ;
if ( reader - > faketext - > content = = NULL ) {
xmlTextReaderErrMemory ( reader ) ;
return ( - 1 ) ;
}
}
2002-12-18 17:53:54 +03:00
}
reader - > curnode = reader - > faketext ;
} else {
if ( reader - > curnode - > next = = NULL )
return ( 0 ) ;
reader - > curnode = reader - > curnode - > next ;
}
return ( 1 ) ;
}
2004-10-19 13:04:23 +04:00
/**
* xmlTextReaderConstEncoding :
* @ reader : the xmlTextReaderPtr used
*
* Determine the encoding of the document being read .
*
* Returns a string containing the encoding of the document or NULL in
* case of error . The string is deallocated with the reader .
*/
const xmlChar *
xmlTextReaderConstEncoding ( xmlTextReaderPtr reader ) {
2024-02-26 17:14:28 +03:00
const xmlChar * encoding = NULL ;
2004-10-19 13:04:23 +04:00
if ( reader = = NULL )
2024-02-26 17:14:28 +03:00
return ( NULL ) ;
2009-08-11 20:31:42 +04:00
2024-02-26 17:14:28 +03:00
if ( reader - > ctxt ! = NULL )
encoding = xmlGetActualEncoding ( reader - > ctxt ) ;
else if ( reader - > doc ! = NULL )
encoding = reader - > doc - > encoding ;
2024-04-22 13:23:06 +03:00
return ( constString ( reader , encoding ) ) ;
2004-10-19 13:04:23 +04:00
}
2002-12-09 17:13:43 +03:00
/************************************************************************
* *
2020-03-08 19:19:42 +03:00
* Access API to the current node *
2002-12-09 17:13:43 +03:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlTextReaderAttributeCount :
* @ reader : the xmlTextReaderPtr used
*
2002-12-11 17:23:49 +03:00
* Provides the number of attributes of the current node
2002-12-09 17:13:43 +03:00
*
* Returns 0 i no attributes , - 1 in case of error or the attribute count
*/
int
xmlTextReaderAttributeCount ( xmlTextReaderPtr reader ) {
int ret ;
xmlAttrPtr attr ;
2002-12-17 01:04:11 +03:00
xmlNsPtr ns ;
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( 0 ) ;
2009-08-11 20:31:42 +04:00
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type ! = XML_ELEMENT_NODE )
2002-12-09 17:13:43 +03:00
return ( 0 ) ;
if ( ( reader - > state = = XML_TEXTREADER_END ) | |
( reader - > state = = XML_TEXTREADER_BACKTRACK ) )
return ( 0 ) ;
ret = 0 ;
2002-12-16 02:36:49 +03:00
attr = node - > properties ;
2002-12-09 17:13:43 +03:00
while ( attr ! = NULL ) {
ret + + ;
attr = attr - > next ;
}
2002-12-17 01:04:11 +03:00
ns = node - > nsDef ;
while ( ns ! = NULL ) {
ret + + ;
ns = ns - > next ;
}
2002-12-09 17:13:43 +03:00
return ( ret ) ;
}
/**
* xmlTextReaderNodeType :
* @ reader : the xmlTextReaderPtr used
*
* Get the node type of the current node
* Reference :
2008-04-07 16:46:48 +04:00
* http : //www.gnu.org/software/dotgnu/pnetlib-doc/System/Xml/XmlNodeType.html
2002-12-09 17:13:43 +03:00
*
2018-11-03 18:49:13 +03:00
* Returns the xmlReaderTypes of the current node or - 1 in case of error
2002-12-09 17:13:43 +03:00
*/
int
xmlTextReaderNodeType ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2009-08-11 20:31:42 +04:00
2002-12-09 17:13:43 +03:00
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_NONE ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
switch ( node - > type ) {
2002-12-09 17:13:43 +03:00
case XML_ELEMENT_NODE :
if ( ( reader - > state = = XML_TEXTREADER_END ) | |
( reader - > state = = XML_TEXTREADER_BACKTRACK ) )
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_END_ELEMENT ) ;
return ( XML_READER_TYPE_ELEMENT ) ;
2002-12-30 13:55:29 +03:00
case XML_NAMESPACE_DECL :
2002-12-09 17:13:43 +03:00
case XML_ATTRIBUTE_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_ATTRIBUTE ) ;
2002-12-09 17:13:43 +03:00
case XML_TEXT_NODE :
2003-07-30 20:37:18 +04:00
if ( xmlIsBlankNode ( reader - > node ) ) {
if ( xmlNodeGetSpacePreserve ( reader - > node ) )
return ( XML_READER_TYPE_SIGNIFICANT_WHITESPACE ) ;
else
return ( XML_READER_TYPE_WHITESPACE ) ;
} else {
return ( XML_READER_TYPE_TEXT ) ;
}
2002-12-09 17:13:43 +03:00
case XML_CDATA_SECTION_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_CDATA ) ;
2002-12-09 17:13:43 +03:00
case XML_ENTITY_REF_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_ENTITY_REFERENCE ) ;
2002-12-09 17:13:43 +03:00
case XML_ENTITY_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_ENTITY ) ;
2002-12-09 17:13:43 +03:00
case XML_PI_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_PROCESSING_INSTRUCTION ) ;
2002-12-09 17:13:43 +03:00
case XML_COMMENT_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_COMMENT ) ;
2002-12-09 17:13:43 +03:00
case XML_DOCUMENT_NODE :
case XML_HTML_DOCUMENT_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_DOCUMENT ) ;
2002-12-09 17:13:43 +03:00
case XML_DOCUMENT_FRAG_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_DOCUMENT_FRAGMENT ) ;
2002-12-09 17:13:43 +03:00
case XML_NOTATION_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_NOTATION ) ;
2002-12-09 17:13:43 +03:00
case XML_DOCUMENT_TYPE_NODE :
case XML_DTD_NODE :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_DOCUMENT_TYPE ) ;
2002-12-09 17:13:43 +03:00
case XML_ELEMENT_DECL :
case XML_ATTRIBUTE_DECL :
case XML_ENTITY_DECL :
case XML_XINCLUDE_START :
case XML_XINCLUDE_END :
2003-07-30 20:37:18 +04:00
return ( XML_READER_TYPE_NONE ) ;
2002-12-09 17:13:43 +03:00
}
return ( - 1 ) ;
}
/**
2002-12-10 18:19:08 +03:00
* xmlTextReaderIsEmptyElement :
2002-12-09 17:13:43 +03:00
* @ reader : the xmlTextReaderPtr used
*
* Check if the current node is empty
*
* Returns 1 if empty , 0 if not and - 1 in case of error
*/
int
xmlTextReaderIsEmptyElement ( xmlTextReaderPtr reader ) {
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( - 1 ) ;
2002-12-23 18:56:21 +03:00
if ( reader - > node - > type ! = XML_ELEMENT_NODE )
return ( 0 ) ;
2003-01-01 18:11:05 +03:00
if ( reader - > curnode ! = NULL )
return ( 0 ) ;
2002-12-09 17:13:43 +03:00
if ( reader - > node - > children ! = NULL )
return ( 0 ) ;
2003-01-02 17:16:45 +03:00
if ( reader - > state = = XML_TEXTREADER_END )
return ( 0 ) ;
2003-11-03 15:31:38 +03:00
if ( reader - > doc ! = NULL )
return ( 1 ) ;
2004-01-08 19:49:50 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
2003-11-03 15:31:38 +03:00
if ( reader - > in_xinclude > 0 )
return ( 1 ) ;
2004-01-08 19:49:50 +03:00
# endif
2003-10-27 14:25:13 +03:00
return ( ( reader - > node - > extra & NODE_IS_EMPTY ) ! = 0 ) ;
2002-12-09 17:13:43 +03:00
}
/**
* xmlTextReaderLocalName :
* @ reader : the xmlTextReaderPtr used
*
* The local name of the node .
*
2009-08-11 20:31:42 +04:00
* Returns the local name or NULL if not available ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderLocalName ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " xmlns " ) ) ;
2002-12-16 02:36:49 +03:00
else
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , ns - > prefix ) ) ;
2002-12-16 02:36:49 +03:00
}
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
2002-12-11 22:28:47 +03:00
return ( xmlTextReaderName ( reader ) ) ;
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2002-12-09 17:13:43 +03:00
}
2003-09-19 16:44:05 +04:00
/**
* xmlTextReaderConstLocalName :
* @ reader : the xmlTextReaderPtr used
*
* The local name of the node .
*
* Returns the local name or NULL if not available , the
* string will be deallocated with the reader .
*/
const xmlChar *
xmlTextReaderConstLocalName ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " xmlns " ) ) ;
2003-09-19 16:44:05 +04:00
else
return ( ns - > prefix ) ;
}
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
return ( xmlTextReaderConstName ( reader ) ) ;
return ( node - > name ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderName :
* @ reader : the xmlTextReaderPtr used
*
* The qualified name of the node , equal to Prefix : LocalName .
*
2009-08-11 20:31:42 +04:00
* Returns the local name or NULL if not available ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderName ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
xmlChar * ret ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
switch ( node - > type ) {
2002-12-11 22:28:47 +03:00
case XML_ELEMENT_NODE :
case XML_ATTRIBUTE_NODE :
2002-12-16 02:36:49 +03:00
if ( ( node - > ns = = NULL ) | |
( node - > ns - > prefix = = NULL ) )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2009-08-11 20:31:42 +04:00
2024-04-22 13:23:06 +03:00
ret = xmlBuildQName ( node - > name , node - > ns - > prefix , NULL , 0 ) ;
if ( ret = = NULL )
xmlTextReaderErrMemory ( reader ) ;
2002-12-11 22:28:47 +03:00
return ( ret ) ;
case XML_TEXT_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " #text " ) ) ;
2002-12-11 22:28:47 +03:00
case XML_CDATA_SECTION_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " #cdata-section " ) ) ;
2002-12-11 22:28:47 +03:00
case XML_ENTITY_NODE :
case XML_ENTITY_REF_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2002-12-11 22:28:47 +03:00
case XML_PI_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2002-12-11 22:28:47 +03:00
case XML_COMMENT_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " #comment " ) ) ;
2002-12-11 22:28:47 +03:00
case XML_DOCUMENT_NODE :
case XML_HTML_DOCUMENT_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " #document " ) ) ;
2002-12-11 22:28:47 +03:00
case XML_DOCUMENT_FRAG_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " #document-fragment " ) ) ;
2002-12-11 22:28:47 +03:00
case XML_NOTATION_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2002-12-11 22:28:47 +03:00
case XML_DOCUMENT_TYPE_NODE :
case XML_DTD_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > name ) ) ;
2002-12-16 02:36:49 +03:00
case XML_NAMESPACE_DECL : {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " xmlns " ) ) ;
ret = xmlBuildQName ( ns - > prefix , BAD_CAST " xmlns " , NULL , 0 ) ;
if ( ret = = NULL )
xmlTextReaderErrMemory ( reader ) ;
2002-12-16 02:36:49 +03:00
return ( ret ) ;
}
2002-12-11 22:28:47 +03:00
case XML_ELEMENT_DECL :
case XML_ATTRIBUTE_DECL :
case XML_ENTITY_DECL :
case XML_XINCLUDE_START :
case XML_XINCLUDE_END :
return ( NULL ) ;
}
return ( NULL ) ;
2002-12-09 17:13:43 +03:00
}
2003-09-19 16:44:05 +04:00
/**
* xmlTextReaderConstName :
* @ reader : the xmlTextReaderPtr used
*
* The qualified name of the node , equal to Prefix : LocalName .
*
* Returns the local name or NULL if not available , the string is
* deallocated with the reader .
*/
const xmlChar *
xmlTextReaderConstName ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
switch ( node - > type ) {
case XML_ELEMENT_NODE :
case XML_ATTRIBUTE_NODE :
if ( ( node - > ns = = NULL ) | |
( node - > ns - > prefix = = NULL ) )
return ( node - > name ) ;
2024-04-22 13:23:06 +03:00
return ( constQString ( reader , node - > ns - > prefix , node - > name ) ) ;
2003-09-19 16:44:05 +04:00
case XML_TEXT_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " #text " ) ) ;
2003-09-19 16:44:05 +04:00
case XML_CDATA_SECTION_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " #cdata-section " ) ) ;
2003-09-19 16:44:05 +04:00
case XML_ENTITY_NODE :
case XML_ENTITY_REF_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > name ) ) ;
2003-09-19 16:44:05 +04:00
case XML_PI_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > name ) ) ;
2003-09-19 16:44:05 +04:00
case XML_COMMENT_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " #comment " ) ) ;
2003-09-19 16:44:05 +04:00
case XML_DOCUMENT_NODE :
case XML_HTML_DOCUMENT_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " #document " ) ) ;
2003-09-19 16:44:05 +04:00
case XML_DOCUMENT_FRAG_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " #document-fragment " ) ) ;
2003-09-19 16:44:05 +04:00
case XML_NOTATION_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > name ) ) ;
2003-09-19 16:44:05 +04:00
case XML_DOCUMENT_TYPE_NODE :
case XML_DTD_NODE :
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > name ) ) ;
2003-09-19 16:44:05 +04:00
case XML_NAMESPACE_DECL : {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " xmlns " ) ) ;
return ( constQString ( reader , BAD_CAST " xmlns " , ns - > prefix ) ) ;
2003-09-19 16:44:05 +04:00
}
case XML_ELEMENT_DECL :
case XML_ATTRIBUTE_DECL :
case XML_ENTITY_DECL :
case XML_XINCLUDE_START :
case XML_XINCLUDE_END :
return ( NULL ) ;
}
return ( NULL ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderPrefix :
* @ reader : the xmlTextReaderPtr used
*
* A shorthand reference to the namespace associated with the node .
*
2009-08-11 20:31:42 +04:00
* Returns the prefix or NULL if not available ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderPrefix ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " xmlns " ) ) ;
2002-12-16 02:36:49 +03:00
}
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
2002-12-09 17:13:43 +03:00
return ( NULL ) ;
2003-03-17 18:37:12 +03:00
if ( ( node - > ns ! = NULL ) & & ( node - > ns - > prefix ! = NULL ) )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > ns - > prefix ) ) ;
2002-12-09 17:13:43 +03:00
return ( NULL ) ;
}
2003-09-19 16:44:05 +04:00
/**
* xmlTextReaderConstPrefix :
* @ reader : the xmlTextReaderPtr used
*
* A shorthand reference to the namespace associated with the node .
*
* Returns the prefix or NULL if not available , the string is deallocated
* with the reader .
*/
const xmlChar *
xmlTextReaderConstPrefix ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type = = XML_NAMESPACE_DECL ) {
xmlNsPtr ns = ( xmlNsPtr ) node ;
if ( ns - > prefix = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " xmlns " ) ) ;
2003-09-19 16:44:05 +04:00
}
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
return ( NULL ) ;
if ( ( node - > ns ! = NULL ) & & ( node - > ns - > prefix ! = NULL ) )
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > ns - > prefix ) ) ;
2003-09-19 16:44:05 +04:00
return ( NULL ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderNamespaceUri :
* @ reader : the xmlTextReaderPtr used
*
* The URI defining the namespace associated with the node .
*
2009-08-11 20:31:42 +04:00
* Returns the namespace URI or NULL if not available ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderNamespaceUri ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
2002-12-30 13:55:29 +03:00
if ( node - > type = = XML_NAMESPACE_DECL )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , BAD_CAST " http://www.w3.org/2000/xmlns/ " ) ) ;
2002-12-16 02:36:49 +03:00
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
2002-12-09 17:13:43 +03:00
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( node - > ns ! = NULL )
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > ns - > href ) ) ;
2002-12-09 17:13:43 +03:00
return ( NULL ) ;
}
2003-09-19 16:44:05 +04:00
/**
* xmlTextReaderConstNamespaceUri :
* @ reader : the xmlTextReaderPtr used
*
* The URI defining the namespace associated with the node .
*
* Returns the namespace URI or NULL if not available , the string
* will be deallocated with the reader
*/
const xmlChar *
xmlTextReaderConstNamespaceUri ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
if ( node - > type = = XML_NAMESPACE_DECL )
2024-04-22 13:23:06 +03:00
return ( constString ( reader , BAD_CAST " http://www.w3.org/2000/xmlns/ " ) ) ;
2003-09-19 16:44:05 +04:00
if ( ( node - > type ! = XML_ELEMENT_NODE ) & &
( node - > type ! = XML_ATTRIBUTE_NODE ) )
return ( NULL ) ;
if ( node - > ns ! = NULL )
2024-04-22 13:23:06 +03:00
return ( constString ( reader , node - > ns - > href ) ) ;
2003-09-19 16:44:05 +04:00
return ( NULL ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderBaseUri :
* @ reader : the xmlTextReaderPtr used
*
* The base URI of the node .
*
2009-08-11 20:31:42 +04:00
* Returns the base URI or NULL if not available ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderBaseUri ( xmlTextReaderPtr reader ) {
2024-04-22 13:23:06 +03:00
xmlChar * ret = NULL ;
int result ;
2002-12-09 17:13:43 +03:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
result = xmlNodeGetBaseSafe ( NULL , reader - > node , & ret ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
return ( ret ) ;
2002-12-09 17:13:43 +03:00
}
2003-09-19 16:44:05 +04:00
/**
* xmlTextReaderConstBaseUri :
* @ reader : the xmlTextReaderPtr used
*
* The base URI of the node .
*
* Returns the base URI or NULL if not available , the string
* will be deallocated with the reader
*/
const xmlChar *
xmlTextReaderConstBaseUri ( xmlTextReaderPtr reader ) {
xmlChar * tmp ;
const xmlChar * ret ;
2024-04-22 13:23:06 +03:00
int result ;
2003-09-19 16:44:05 +04:00
if ( ( reader = = NULL ) | | ( reader - > node = = NULL ) )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
result = xmlNodeGetBaseSafe ( NULL , reader - > node , & tmp ) ;
if ( result < 0 )
xmlTextReaderErrMemory ( reader ) ;
2003-09-19 16:44:05 +04:00
if ( tmp = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
ret = constString ( reader , tmp ) ;
2003-09-19 16:44:05 +04:00
xmlFree ( tmp ) ;
return ( ret ) ;
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderDepth :
* @ reader : the xmlTextReaderPtr used
*
* The depth of the node in the tree .
*
* Returns the depth or - 1 in case of error
*/
int
xmlTextReaderDepth ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( 0 ) ;
2002-12-18 17:53:54 +03:00
if ( reader - > curnode ! = NULL ) {
if ( ( reader - > curnode - > type = = XML_ATTRIBUTE_NODE ) | |
( reader - > curnode - > type = = XML_NAMESPACE_DECL ) )
return ( reader - > depth + 1 ) ;
return ( reader - > depth + 2 ) ;
}
2002-12-09 17:13:43 +03:00
return ( reader - > depth ) ;
}
/**
* xmlTextReaderHasAttributes :
* @ reader : the xmlTextReaderPtr used
*
* Whether the node has attributes .
*
* Returns 1 if true , 0 if false , and - 1 in case or error
*/
int
xmlTextReaderHasAttributes ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( 0 ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
2002-12-09 17:13:43 +03:00
2002-12-16 02:36:49 +03:00
if ( ( node - > type = = XML_ELEMENT_NODE ) & &
2004-11-24 15:39:00 +03:00
( ( node - > properties ! = NULL ) | | ( node - > nsDef ! = NULL ) ) )
2002-12-09 17:13:43 +03:00
return ( 1 ) ;
/* TODO: handle the xmlDecl */
return ( 0 ) ;
}
/**
* xmlTextReaderHasValue :
* @ reader : the xmlTextReaderPtr used
*
* Whether the node can have a text value .
*
* Returns 1 if true , 0 if false , and - 1 in case or error
*/
int
xmlTextReaderHasValue ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-09 17:13:43 +03:00
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( 0 ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
2002-12-09 17:13:43 +03:00
2002-12-16 02:36:49 +03:00
switch ( node - > type ) {
2002-12-11 22:28:47 +03:00
case XML_ATTRIBUTE_NODE :
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
2003-04-10 17:36:54 +04:00
case XML_NAMESPACE_DECL :
2002-12-11 22:28:47 +03:00
return ( 1 ) ;
default :
2003-03-23 01:39:16 +03:00
break ;
2002-12-11 22:28:47 +03:00
}
2002-12-09 17:13:43 +03:00
return ( 0 ) ;
}
2002-12-11 22:28:47 +03:00
/**
* xmlTextReaderValue :
* @ reader : the xmlTextReaderPtr used
*
* Provides the text value of the node if present
*
2003-10-20 21:07:41 +04:00
* Returns the string or NULL if not available . The result must be deallocated
2002-12-11 22:28:47 +03:00
* with xmlFree ( )
2002-12-09 17:13:43 +03:00
*/
2002-12-11 22:28:47 +03:00
xmlChar *
xmlTextReaderValue ( xmlTextReaderPtr reader ) {
2002-12-16 02:36:49 +03:00
xmlNodePtr node ;
2002-12-11 22:28:47 +03:00
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
2002-12-16 02:36:49 +03:00
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
2002-12-11 22:28:47 +03:00
2002-12-16 02:36:49 +03:00
switch ( node - > type ) {
case XML_NAMESPACE_DECL :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , ( ( xmlNsPtr ) node ) - > href ) ) ;
2002-12-11 22:28:47 +03:00
case XML_ATTRIBUTE_NODE : {
2002-12-16 02:36:49 +03:00
xmlAttrPtr attr = ( xmlAttrPtr ) node ;
2024-04-22 13:23:06 +03:00
xmlDocPtr doc = NULL ;
xmlChar * ret ;
2002-12-11 22:28:47 +03:00
if ( attr - > parent ! = NULL )
2024-04-22 13:23:06 +03:00
doc = attr - > parent - > doc ;
ret = xmlNodeListGetString ( doc , attr - > children , 1 ) ;
if ( ret = = NULL )
xmlTextReaderErrMemory ( reader ) ;
return ( ret ) ;
2002-12-11 22:28:47 +03:00
}
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
2024-04-22 13:23:06 +03:00
return ( readerStrdup ( reader , node - > content ) ) ;
2002-12-11 22:28:47 +03:00
default :
2003-03-23 01:39:16 +03:00
break ;
2002-12-11 22:28:47 +03:00
}
return ( NULL ) ;
}
2003-10-20 21:07:41 +04:00
/**
* xmlTextReaderConstValue :
* @ reader : the xmlTextReaderPtr used
*
* Provides the text value of the node if present
*
* Returns the string or NULL if not available . The result will be
* deallocated on the next Read ( ) operation .
*/
const xmlChar *
xmlTextReaderConstValue ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
switch ( node - > type ) {
case XML_NAMESPACE_DECL :
return ( ( ( xmlNsPtr ) node ) - > href ) ;
case XML_ATTRIBUTE_NODE : {
xmlAttrPtr attr = ( xmlAttrPtr ) node ;
2015-04-14 12:41:48 +03:00
const xmlChar * ret ;
2003-10-20 21:07:41 +04:00
if ( ( attr - > children ! = NULL ) & &
( attr - > children - > type = = XML_TEXT_NODE ) & &
( attr - > children - > next = = NULL ) )
return ( attr - > children - > content ) ;
else {
2004-07-01 15:20:33 +04:00
if ( reader - > buffer = = NULL ) {
2012-07-16 10:42:31 +04:00
reader - > buffer = xmlBufCreateSize ( 100 ) ;
2023-12-10 20:23:53 +03:00
if ( reader - > buffer = = NULL )
2012-07-16 10:42:31 +04:00
return ( NULL ) ;
2015-04-14 12:41:48 +03:00
xmlBufSetAllocationScheme ( reader - > buffer ,
2022-03-05 23:46:40 +03:00
XML_BUFFER_ALLOC_DOUBLEIT ) ;
2012-07-16 10:42:31 +04:00
} else
xmlBufEmpty ( reader - > buffer ) ;
xmlBufGetNodeContent ( reader - > buffer , node ) ;
2015-04-14 12:41:48 +03:00
ret = xmlBufContent ( reader - > buffer ) ;
if ( ret = = NULL ) {
2024-04-30 17:36:44 +03:00
xmlTextReaderErrMemory ( reader ) ;
2015-04-14 12:41:48 +03:00
/* error on the buffer best to reallocate */
xmlBufFree ( reader - > buffer ) ;
reader - > buffer = xmlBufCreateSize ( 100 ) ;
xmlBufSetAllocationScheme ( reader - > buffer ,
2022-03-05 23:46:40 +03:00
XML_BUFFER_ALLOC_DOUBLEIT ) ;
2015-04-14 12:41:48 +03:00
}
return ( ret ) ;
2003-10-20 21:07:41 +04:00
}
break ;
}
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
return ( node - > content ) ;
default :
break ;
}
return ( NULL ) ;
}
2002-12-11 22:28:47 +03:00
/**
* xmlTextReaderIsDefault :
* @ reader : the xmlTextReaderPtr used
*
* Whether an Attribute node was generated from the default value
* defined in the DTD or schema .
*
* Returns 0 if not defaulted , 1 if defaulted , and - 1 in case of error
*/
int
xmlTextReaderIsDefault ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
return ( 0 ) ;
}
/**
* xmlTextReaderQuoteChar :
* @ reader : the xmlTextReaderPtr used
*
* The quotation mark character used to enclose the value of an attribute .
*
* Returns " or ' and -1 in case of error
*/
int
xmlTextReaderQuoteChar ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
/* TODO maybe lookup the attribute value for " first */
2022-09-01 02:18:30 +03:00
return ( ' " ' ) ;
2002-12-11 22:28:47 +03:00
}
2002-12-09 17:13:43 +03:00
/**
* xmlTextReaderXmlLang :
* @ reader : the xmlTextReaderPtr used
*
* The xml : lang scope within which the node resides .
*
2009-08-11 20:31:42 +04:00
* Returns the xml : lang value or NULL if none exists . ,
* if non NULL it need to be freed by the caller .
2002-12-09 17:13:43 +03:00
*/
xmlChar *
xmlTextReaderXmlLang ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
return ( xmlNodeGetLang ( reader - > node ) ) ;
}
2003-09-19 16:44:05 +04:00
/**
2003-09-25 16:18:34 +04:00
* xmlTextReaderConstXmlLang :
2003-09-19 16:44:05 +04:00
* @ reader : the xmlTextReaderPtr used
*
* The xml : lang scope within which the node resides .
*
* Returns the xml : lang value or NULL if none exists .
*/
const xmlChar *
xmlTextReaderConstXmlLang ( xmlTextReaderPtr reader ) {
xmlChar * tmp ;
const xmlChar * ret ;
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > node = = NULL )
return ( NULL ) ;
tmp = xmlNodeGetLang ( reader - > node ) ;
if ( tmp = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
ret = constString ( reader , tmp ) ;
2003-09-19 16:44:05 +04:00
xmlFree ( tmp ) ;
return ( ret ) ;
}
2003-09-22 14:24:45 +04:00
/**
* xmlTextReaderConstString :
* @ reader : the xmlTextReaderPtr used
* @ str : the string to intern .
*
* Get an interned string from the reader , allows for example to
* speedup string name comparisons
*
* Returns an interned copy of the string or NULL in case of error . The
* string will be deallocated with the reader .
*/
const xmlChar *
xmlTextReaderConstString ( xmlTextReaderPtr reader , const xmlChar * str ) {
if ( reader = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
return ( constString ( reader , str ) ) ;
2003-09-22 14:24:45 +04:00
}
2002-12-17 01:04:11 +03:00
/**
* xmlTextReaderNormalization :
* @ reader : the xmlTextReaderPtr used
*
* The value indicating whether to normalize white space and attribute values .
* Since attribute value and end of line normalizations are a MUST in the XML
2020-03-08 19:19:42 +03:00
* specification only the value true is accepted . The broken behaviour of
2002-12-17 01:04:11 +03:00
* accepting out of range character entities like & # 0 ; is of course not
* supported either .
*
* Returns 1 or - 1 in case of error .
*/
int
xmlTextReaderNormalization ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( - 1 ) ;
return ( 1 ) ;
}
2002-12-18 17:53:54 +03:00
/************************************************************************
* *
* Extensions to the base APIs *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlTextReaderSetParserProp :
* @ reader : the xmlTextReaderPtr used
* @ prop : the xmlParserProperties to set
* @ value : usually 0 or 1 to ( de ) activate it
*
* Change the parser processing behaviour by changing some of its internal
* properties . Note that some properties can only be changed before any
* read has been done .
*
* Returns 0 if the call was successful , or - 1 in case of error
*/
int
xmlTextReaderSetParserProp ( xmlTextReaderPtr reader , int prop , int value ) {
xmlParserProperties p = ( xmlParserProperties ) prop ;
xmlParserCtxtPtr ctxt ;
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
ctxt = reader - > ctxt ;
switch ( p ) {
case XML_PARSER_LOADDTD :
if ( value ! = 0 ) {
if ( ctxt - > loadsubset = = 0 ) {
if ( reader - > mode ! = XML_TEXTREADER_MODE_INITIAL )
return ( - 1 ) ;
2024-01-05 03:14:28 +03:00
ctxt - > options | = XML_PARSE_DTDLOAD ;
ctxt - > loadsubset | = XML_DETECT_IDS ;
2002-12-18 17:53:54 +03:00
}
} else {
2024-01-05 03:14:28 +03:00
ctxt - > options & = ~ XML_PARSE_DTDLOAD ;
ctxt - > loadsubset & = ~ XML_DETECT_IDS ;
2002-12-18 17:53:54 +03:00
}
return ( 0 ) ;
case XML_PARSER_DEFAULTATTRS :
if ( value ! = 0 ) {
2024-01-05 03:14:28 +03:00
ctxt - > options | = XML_PARSE_DTDATTR ;
2002-12-18 17:53:54 +03:00
ctxt - > loadsubset | = XML_COMPLETE_ATTRS ;
} else {
2024-01-05 03:14:28 +03:00
ctxt - > options & = ~ XML_PARSE_DTDATTR ;
ctxt - > loadsubset & = ~ XML_COMPLETE_ATTRS ;
2002-12-18 17:53:54 +03:00
}
return ( 0 ) ;
case XML_PARSER_VALIDATE :
if ( value ! = 0 ) {
2020-02-11 18:29:30 +03:00
ctxt - > options | = XML_PARSE_DTDVALID ;
2002-12-18 17:53:54 +03:00
ctxt - > validate = 1 ;
2003-04-16 03:32:22 +04:00
reader - > validate = XML_TEXTREADER_VALIDATE_DTD ;
2002-12-18 17:53:54 +03:00
} else {
2020-02-11 18:29:30 +03:00
ctxt - > options & = ~ XML_PARSE_DTDVALID ;
2002-12-18 17:53:54 +03:00
ctxt - > validate = 0 ;
}
return ( 0 ) ;
2002-12-29 01:56:33 +03:00
case XML_PARSER_SUBST_ENTITIES :
if ( value ! = 0 ) {
2020-02-11 18:29:30 +03:00
ctxt - > options | = XML_PARSE_NOENT ;
2002-12-29 01:56:33 +03:00
ctxt - > replaceEntities = 1 ;
} else {
2020-02-11 18:29:30 +03:00
ctxt - > options & = ~ XML_PARSE_NOENT ;
2002-12-29 01:56:33 +03:00
ctxt - > replaceEntities = 0 ;
}
return ( 0 ) ;
2002-12-18 17:53:54 +03:00
}
return ( - 1 ) ;
}
/**
* xmlTextReaderGetParserProp :
* @ reader : the xmlTextReaderPtr used
* @ prop : the xmlParserProperties to get
*
* Read the parser internal property .
*
* Returns the value , usually 0 or 1 , or - 1 in case of error .
*/
int
xmlTextReaderGetParserProp ( xmlTextReaderPtr reader , int prop ) {
xmlParserProperties p = ( xmlParserProperties ) prop ;
xmlParserCtxtPtr ctxt ;
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
ctxt = reader - > ctxt ;
switch ( p ) {
case XML_PARSER_LOADDTD :
if ( ( ctxt - > loadsubset ! = 0 ) | | ( ctxt - > validate ! = 0 ) )
return ( 1 ) ;
return ( 0 ) ;
case XML_PARSER_DEFAULTATTRS :
if ( ctxt - > loadsubset & XML_COMPLETE_ATTRS )
return ( 1 ) ;
return ( 0 ) ;
case XML_PARSER_VALIDATE :
2003-04-16 03:32:22 +04:00
return ( reader - > validate ) ;
2002-12-29 01:56:33 +03:00
case XML_PARSER_SUBST_ENTITIES :
return ( ctxt - > replaceEntities ) ;
2002-12-18 17:53:54 +03:00
}
return ( - 1 ) ;
}
2005-01-04 20:50:14 +03:00
2005-01-04 00:58:59 +03:00
/**
* xmlTextReaderGetParserLineNumber :
2005-01-04 20:50:14 +03:00
* @ reader : the user data ( XML reader context )
2005-01-04 00:58:59 +03:00
*
* Provide the line number of the current parsing point .
*
2005-01-04 20:50:14 +03:00
* Returns an int or 0 if not available
2005-01-04 00:58:59 +03:00
*/
int
xmlTextReaderGetParserLineNumber ( xmlTextReaderPtr reader )
{
2005-01-04 20:50:14 +03:00
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) | |
( reader - > ctxt - > input = = NULL ) ) {
return ( 0 ) ;
2005-01-04 00:58:59 +03:00
}
2005-01-04 20:50:14 +03:00
return ( reader - > ctxt - > input - > line ) ;
2005-01-04 00:58:59 +03:00
}
/**
* xmlTextReaderGetParserColumnNumber :
2005-01-04 20:50:14 +03:00
* @ reader : the user data ( XML reader context )
2005-01-04 00:58:59 +03:00
*
* Provide the column number of the current parsing point .
*
2005-01-04 20:50:14 +03:00
* Returns an int or 0 if not available
2005-01-04 00:58:59 +03:00
*/
int
xmlTextReaderGetParserColumnNumber ( xmlTextReaderPtr reader )
{
2005-01-04 20:50:14 +03:00
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) | |
( reader - > ctxt - > input = = NULL ) ) {
return ( 0 ) ;
2005-01-04 00:58:59 +03:00
}
2005-01-04 20:50:14 +03:00
return ( reader - > ctxt - > input - > col ) ;
2005-01-04 00:58:59 +03:00
}
2002-12-29 01:56:33 +03:00
/**
* xmlTextReaderCurrentNode :
* @ reader : the xmlTextReaderPtr used
*
2019-09-30 18:04:54 +03:00
* Hacking interface allowing to get the xmlNodePtr corresponding to the
2002-12-29 01:56:33 +03:00
* current node being accessed by the xmlTextReader . This is dangerous
* because the underlying node may be destroyed on the next Reads .
*
* Returns the xmlNodePtr or NULL in case of error .
*/
xmlNodePtr
xmlTextReaderCurrentNode ( xmlTextReaderPtr reader ) {
if ( reader = = NULL )
return ( NULL ) ;
2009-08-11 20:31:42 +04:00
2002-12-29 01:56:33 +03:00
if ( reader - > curnode ! = NULL )
return ( reader - > curnode ) ;
return ( reader - > node ) ;
}
2003-09-28 04:19:54 +04:00
/**
* xmlTextReaderPreserve :
* @ reader : the xmlTextReaderPtr used
*
2004-06-14 23:58:20 +04:00
* This tells the XML Reader to preserve the current node .
* The caller must also use xmlTextReaderCurrentDoc ( ) to
* keep an handle on the resulting document once parsing has finished
2003-09-28 04:19:54 +04:00
*
* Returns the xmlNodePtr or NULL in case of error .
*/
xmlNodePtr
xmlTextReaderPreserve ( xmlTextReaderPtr reader ) {
xmlNodePtr cur , parent ;
if ( reader = = NULL )
return ( NULL ) ;
2009-08-11 20:31:42 +04:00
2024-04-16 15:53:07 +03:00
cur = reader - > node ;
2003-09-28 04:19:54 +04:00
if ( cur = = NULL )
return ( NULL ) ;
2003-12-05 17:57:46 +03:00
2004-06-14 23:58:20 +04:00
if ( ( cur - > type ! = XML_DOCUMENT_NODE ) & & ( cur - > type ! = XML_DTD_NODE ) ) {
2003-12-05 17:57:46 +03:00
cur - > extra | = NODE_IS_PRESERVED ;
cur - > extra | = NODE_IS_SPRESERVED ;
}
reader - > preserves + + ;
2009-08-11 20:31:42 +04:00
2003-09-28 04:19:54 +04:00
parent = cur - > parent ; ;
while ( parent ! = NULL ) {
2003-12-05 17:57:46 +03:00
if ( parent - > type = = XML_ELEMENT_NODE )
parent - > extra | = NODE_IS_PRESERVED ;
2003-09-28 04:19:54 +04:00
parent = parent - > parent ;
}
return ( cur ) ;
}
2003-12-05 17:57:46 +03:00
# ifdef LIBXML_PATTERN_ENABLED
/**
* xmlTextReaderPreservePattern :
* @ reader : the xmlTextReaderPtr used
* @ pattern : an XPath subset pattern
2003-12-05 19:10:21 +03:00
* @ namespaces : the prefix definitions , array of [ URI , prefix ] or NULL
2009-08-11 20:31:42 +04:00
*
2003-12-05 17:57:46 +03:00
* This tells the XML Reader to preserve all nodes matched by the
* pattern . The caller must also use xmlTextReaderCurrentDoc ( ) to
* keep an handle on the resulting document once parsing has finished
*
2017-06-18 00:20:38 +03:00
* Returns a non - negative number in case of success and - 1 in case of error
2003-12-05 17:57:46 +03:00
*/
int
2003-12-05 19:10:21 +03:00
xmlTextReaderPreservePattern ( xmlTextReaderPtr reader , const xmlChar * pattern ,
const xmlChar * * namespaces )
{
2003-12-05 17:57:46 +03:00
xmlPatternPtr comp ;
if ( ( reader = = NULL ) | | ( pattern = = NULL ) )
return ( - 1 ) ;
2009-08-11 20:31:42 +04:00
2003-12-05 19:10:21 +03:00
comp = xmlPatterncompile ( pattern , reader - > dict , 0 , namespaces ) ;
2003-12-05 17:57:46 +03:00
if ( comp = = NULL )
return ( - 1 ) ;
if ( reader - > patternMax < = 0 ) {
reader - > patternMax = 4 ;
reader - > patternTab = ( xmlPatternPtr * ) xmlMalloc ( reader - > patternMax *
sizeof ( reader - > patternTab [ 0 ] ) ) ;
if ( reader - > patternTab = = NULL ) {
2023-12-10 20:23:53 +03:00
xmlTextReaderErrMemory ( reader ) ;
2003-12-05 17:57:46 +03:00
return ( - 1 ) ;
}
}
if ( reader - > patternNr > = reader - > patternMax ) {
xmlPatternPtr * tmp ;
reader - > patternMax * = 2 ;
tmp = ( xmlPatternPtr * ) xmlRealloc ( reader - > patternTab ,
reader - > patternMax *
sizeof ( reader - > patternTab [ 0 ] ) ) ;
if ( tmp = = NULL ) {
2023-12-10 20:23:53 +03:00
xmlTextReaderErrMemory ( reader ) ;
2003-12-05 17:57:46 +03:00
reader - > patternMax / = 2 ;
return ( - 1 ) ;
}
reader - > patternTab = tmp ;
}
reader - > patternTab [ reader - > patternNr ] = comp ;
return ( reader - > patternNr + + ) ;
}
# endif
2002-12-29 01:56:33 +03:00
/**
* xmlTextReaderCurrentDoc :
* @ reader : the xmlTextReaderPtr used
*
2019-09-30 18:04:54 +03:00
* Hacking interface allowing to get the xmlDocPtr corresponding to the
2009-08-11 20:31:42 +04:00
* current document being accessed by the xmlTextReader .
2003-09-28 04:19:54 +04:00
* NOTE : as a result of this call , the reader will not destroy the
* associated XML document and calling xmlFreeDoc ( ) on the result
* is needed once the reader parsing has finished .
2002-12-29 01:56:33 +03:00
*
* Returns the xmlDocPtr or NULL in case of error .
*/
xmlDocPtr
xmlTextReaderCurrentDoc ( xmlTextReaderPtr reader ) {
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > doc ! = NULL )
return ( reader - > doc ) ;
2008-03-14 17:29:40 +03:00
if ( ( reader - > ctxt = = NULL ) | | ( reader - > ctxt - > myDoc = = NULL ) )
2002-12-29 01:56:33 +03:00
return ( NULL ) ;
2009-08-11 20:31:42 +04:00
2003-09-28 04:19:54 +04:00
reader - > preserve = 1 ;
2002-12-29 01:56:33 +03:00
return ( reader - > ctxt - > myDoc ) ;
}
2003-05-09 23:38:15 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2003-04-17 13:09:19 +04:00
/**
* xmlTextReaderRelaxNGSetSchema :
* @ reader : the xmlTextReaderPtr used
* @ schema : a precompiled RelaxNG schema
*
* Use RelaxNG to validate the document as it is processed .
* Activation is only possible before the first Read ( ) .
2019-09-30 18:04:54 +03:00
* if @ schema is NULL , then RelaxNG validation is deactivated .
2003-04-17 13:09:19 +04:00
@ The @ schema should not be freed until the reader is deallocated
* or its use has been deactivated .
*
2019-09-30 18:04:54 +03:00
* Returns 0 in case the RelaxNG validation could be ( de ) activated and
2003-04-17 13:09:19 +04:00
* - 1 in case of error .
*/
int
xmlTextReaderRelaxNGSetSchema ( xmlTextReaderPtr reader , xmlRelaxNGPtr schema ) {
2004-11-05 20:22:25 +03:00
if ( reader = = NULL )
return ( - 1 ) ;
2003-04-17 13:09:19 +04:00
if ( schema = = NULL ) {
if ( reader - > rngSchemas ! = NULL ) {
xmlRelaxNGFree ( reader - > rngSchemas ) ;
reader - > rngSchemas = NULL ;
}
if ( reader - > rngValidCtxt ! = NULL ) {
2012-03-19 12:08:16 +04:00
if ( ! reader - > rngPreserveCtxt )
xmlRelaxNGFreeValidCtxt ( reader - > rngValidCtxt ) ;
2003-04-17 13:09:19 +04:00
reader - > rngValidCtxt = NULL ;
}
2012-03-19 12:08:16 +04:00
reader - > rngPreserveCtxt = 0 ;
2003-04-17 13:09:19 +04:00
return ( 0 ) ;
}
if ( reader - > mode ! = XML_TEXTREADER_MODE_INITIAL )
return ( - 1 ) ;
if ( reader - > rngSchemas ! = NULL ) {
xmlRelaxNGFree ( reader - > rngSchemas ) ;
reader - > rngSchemas = NULL ;
}
if ( reader - > rngValidCtxt ! = NULL ) {
2012-03-19 12:08:16 +04:00
if ( ! reader - > rngPreserveCtxt )
xmlRelaxNGFreeValidCtxt ( reader - > rngValidCtxt ) ;
2003-04-17 13:09:19 +04:00
reader - > rngValidCtxt = NULL ;
}
2012-03-19 12:08:16 +04:00
reader - > rngPreserveCtxt = 0 ;
2003-04-17 13:09:19 +04:00
reader - > rngValidCtxt = xmlRelaxNGNewValidCtxt ( schema ) ;
if ( reader - > rngValidCtxt = = NULL )
return ( - 1 ) ;
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2003-04-17 13:09:19 +04:00
reader - > rngValidErrors = 0 ;
reader - > rngFullNode = NULL ;
reader - > validate = XML_TEXTREADER_VALIDATE_RNG ;
return ( 0 ) ;
}
2012-08-14 07:01:07 +04:00
/**
* xmlTextReaderLocator :
* @ ctx : the xmlTextReaderPtr used
* @ file : returned file information
* @ line : returned line information
*
* Internal locator function for the readers
*
2019-09-30 18:04:54 +03:00
* Returns 0 in case the Schema validation could be ( de ) activated and
2012-08-14 07:01:07 +04:00
* - 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 ) ;
}
2005-07-10 23:03:16 +04:00
/**
* 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 ( ) .
2019-09-30 18:04:54 +03:00
* if @ schema is NULL , then Schema validation is deactivated .
* The @ schema should not be freed until the reader is deallocated
2005-07-10 23:03:16 +04:00
* or its use has been deactivated .
*
2019-09-30 18:04:54 +03:00
* Returns 0 in case the Schema validation could be ( de ) activated and
2005-07-10 23:03:16 +04:00
* - 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 ) {
2005-12-07 17:02:42 +03:00
if ( ! reader - > xsdPreserveCtxt )
xmlSchemaFreeValidCtxt ( reader - > xsdValidCtxt ) ;
2009-08-11 20:31:42 +04:00
reader - > xsdValidCtxt = NULL ;
2005-07-10 23:03:16 +04:00
}
2005-12-07 17:02:42 +03:00
reader - > xsdPreserveCtxt = 0 ;
2005-07-10 23:03:16 +04:00
if ( reader - > xsdSchemas ! = NULL ) {
xmlSchemaFree ( reader - > xsdSchemas ) ;
reader - > xsdSchemas = NULL ;
2009-08-11 20:31:42 +04:00
}
2005-07-10 23:03:16 +04:00
return ( 0 ) ;
2009-08-11 20:31:42 +04:00
}
2005-07-10 23:03:16 +04:00
if ( reader - > mode ! = XML_TEXTREADER_MODE_INITIAL )
return ( - 1 ) ;
if ( reader - > xsdPlug ! = NULL ) {
xmlSchemaSAXUnplug ( reader - > xsdPlug ) ;
reader - > xsdPlug = NULL ;
}
if ( reader - > xsdValidCtxt ! = NULL ) {
2005-12-07 17:02:42 +03:00
if ( ! reader - > xsdPreserveCtxt )
2009-08-11 20:31:42 +04:00
xmlSchemaFreeValidCtxt ( reader - > xsdValidCtxt ) ;
2005-07-10 23:03:16 +04:00
reader - > xsdValidCtxt = NULL ;
}
2005-12-07 17:02:42 +03:00
reader - > xsdPreserveCtxt = 0 ;
2005-07-10 23:03:16 +04:00
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 ) ;
}
2012-08-14 07:01:07 +04:00
xmlSchemaValidateSetLocator ( reader - > xsdValidCtxt ,
xmlTextReaderLocator ,
( void * ) reader ) ;
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2005-07-10 23:03:16 +04:00
reader - > xsdValidErrors = 0 ;
reader - > validate = XML_TEXTREADER_VALIDATE_XSD ;
return ( 0 ) ;
}
2003-04-16 03:32:22 +04:00
/**
2012-03-19 12:08:16 +04:00
* xmlTextReaderRelaxNGValidateInternal :
2003-04-16 03:32:22 +04:00
* @ reader : the xmlTextReaderPtr used
* @ rng : the path to a RelaxNG schema or NULL
2012-03-19 12:08:16 +04:00
* @ ctxt : the RelaxNG schema validation context or NULL
* @ options : options ( not yet used )
2003-04-16 03:32:22 +04:00
*
* Use RelaxNG to validate the document as it is processed .
* Activation is only possible before the first Read ( ) .
2012-03-19 12:08:16 +04:00
* If both @ rng and @ ctxt are NULL , then RelaxNG validation is deactivated .
2003-04-16 03:32:22 +04:00
*
2007-02-09 02:34:34 +03:00
* Returns 0 in case the RelaxNG validation could be ( de ) activated and
2012-03-19 12:08:16 +04:00
* - 1 in case of error .
2003-04-16 03:32:22 +04:00
*/
2012-03-19 12:08:16 +04:00
static int
xmlTextReaderRelaxNGValidateInternal ( xmlTextReaderPtr reader ,
const char * rng ,
xmlRelaxNGValidCtxtPtr ctxt ,
int options ATTRIBUTE_UNUSED )
{
2003-04-16 03:32:22 +04:00
if ( reader = = NULL )
2012-03-19 12:08:16 +04:00
return ( - 1 ) ;
2009-08-11 20:31:42 +04:00
2012-03-19 12:08:16 +04:00
if ( ( rng ! = NULL ) & & ( ctxt ! = 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 )
2003-04-16 03:32:22 +04:00
xmlRelaxNGFreeValidCtxt ( reader - > rngValidCtxt ) ;
2012-03-19 12:08:16 +04:00
reader - > rngValidCtxt = NULL ;
2003-04-16 03:32:22 +04:00
}
2012-03-19 12:08:16 +04:00
reader - > rngPreserveCtxt = 0 ;
2003-04-17 13:09:19 +04:00
if ( reader - > rngSchemas ! = NULL ) {
xmlRelaxNGFree ( reader - > rngSchemas ) ;
reader - > rngSchemas = NULL ;
}
2012-03-19 12:08:16 +04:00
if ( ( rng = = NULL ) & & ( ctxt = = NULL ) ) {
/* We just want to deactivate the validation, so get out. */
return ( 0 ) ;
2003-04-16 03:32:22 +04:00
}
2012-03-19 12:08:16 +04:00
if ( rng ! = NULL ) {
xmlRelaxNGParserCtxtPtr pctxt ;
/* Parse the schema and create validation environment. */
pctxt = xmlRelaxNGNewParserCtxt ( rng ) ;
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlRelaxNGSetParserStructuredErrors ( pctxt ,
xmlTextReaderStructuredRelay , reader ) ;
2012-03-19 12:08:16 +04:00
reader - > rngSchemas = xmlRelaxNGParse ( pctxt ) ;
xmlRelaxNGFreeParserCtxt ( pctxt ) ;
if ( reader - > rngSchemas = = NULL )
return ( - 1 ) ;
2023-12-18 21:47:47 +03:00
2012-03-19 12:08:16 +04:00
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 ;
2005-07-10 23:03:16 +04:00
}
2012-03-19 12:08:16 +04:00
/*
* 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 .
*/
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2003-04-16 03:32:22 +04:00
reader - > rngValidErrors = 0 ;
reader - > rngFullNode = NULL ;
reader - > validate = XML_TEXTREADER_VALIDATE_RNG ;
return ( 0 ) ;
}
2005-07-10 23:03:16 +04:00
/**
2005-12-07 17:02:42 +03:00
* xmlTextReaderSchemaValidateInternal :
2005-07-10 23:03:16 +04:00
* @ reader : the xmlTextReaderPtr used
* @ xsd : the path to a W3C XSD schema or NULL
2005-12-07 17:02:42 +03:00
* @ ctxt : the XML Schema validation context or NULL
* @ options : options ( not used yet )
2005-07-10 23:03:16 +04:00
*
2005-12-07 17:02:42 +03:00
* Validate the document as it is processed using XML Schema .
2005-07-10 23:03:16 +04:00
* Activation is only possible before the first Read ( ) .
2005-12-07 17:02:42 +03:00
* If both @ xsd and @ ctxt are NULL then XML Schema validation is deactivated .
2005-07-10 23:03:16 +04:00
*
2005-12-07 17:02:42 +03:00
* Returns 0 in case the schemas validation could be ( de ) activated and
2005-07-10 23:03:16 +04:00
* - 1 in case of error .
*/
2005-12-07 17:02:42 +03:00
static int
xmlTextReaderSchemaValidateInternal ( xmlTextReaderPtr reader ,
const char * xsd ,
xmlSchemaValidCtxtPtr ctxt ,
int options ATTRIBUTE_UNUSED )
2009-08-11 20:31:42 +04:00
{
2005-07-10 23:03:16 +04:00
if ( reader = = NULL )
return ( - 1 ) ;
2005-12-07 17:02:42 +03:00
if ( ( xsd ! = NULL ) & & ( ctxt ! = NULL ) )
2005-07-10 23:03:16 +04:00
return ( - 1 ) ;
2005-12-07 17:02:42 +03:00
if ( ( ( xsd ! = NULL ) | | ( ctxt ! = NULL ) ) & &
( ( reader - > mode ! = XML_TEXTREADER_MODE_INITIAL ) | |
( reader - > ctxt = = NULL ) ) )
return ( - 1 ) ;
2009-08-11 20:31:42 +04:00
2005-12-07 17:02:42 +03:00
/* Cleanup previous validation stuff. */
2005-07-10 23:03:16 +04:00
if ( reader - > xsdPlug ! = NULL ) {
xmlSchemaSAXUnplug ( reader - > xsdPlug ) ;
reader - > xsdPlug = NULL ;
}
if ( reader - > xsdValidCtxt ! = NULL ) {
2005-12-07 17:02:42 +03:00
if ( ! reader - > xsdPreserveCtxt )
2009-08-11 20:31:42 +04:00
xmlSchemaFreeValidCtxt ( reader - > xsdValidCtxt ) ;
2005-07-10 23:03:16 +04:00
reader - > xsdValidCtxt = NULL ;
}
2005-12-07 17:02:42 +03:00
reader - > xsdPreserveCtxt = 0 ;
2005-07-10 23:03:16 +04:00
if ( reader - > xsdSchemas ! = NULL ) {
xmlSchemaFree ( reader - > xsdSchemas ) ;
reader - > xsdSchemas = NULL ;
2009-08-11 20:31:42 +04:00
}
2005-12-07 17:02:42 +03:00
if ( ( xsd = = NULL ) & & ( ctxt = = NULL ) ) {
/* We just want to deactivate the validation, so get out. */
return ( 0 ) ;
2009-08-11 20:31:42 +04:00
}
2005-12-07 17:02:42 +03:00
if ( xsd ! = NULL ) {
xmlSchemaParserCtxtPtr pctxt ;
/* Parse the schema and create validation environment. */
pctxt = xmlSchemaNewParserCtxt ( xsd ) ;
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlSchemaSetParserStructuredErrors ( pctxt ,
xmlTextReaderStructuredRelay , reader ) ;
2005-12-07 17:02:42 +03:00
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 {
2009-08-11 20:31:42 +04:00
/* Use the given validation context. */
2005-12-07 17:02:42 +03:00
reader - > xsdValidCtxt = ctxt ;
reader - > xsdPreserveCtxt = 1 ;
reader - > xsdPlug = xmlSchemaSAXPlug ( reader - > xsdValidCtxt ,
& ( reader - > ctxt - > sax ) ,
& ( reader - > ctxt - > userData ) ) ;
2009-08-11 20:31:42 +04:00
if ( reader - > xsdPlug = = NULL ) {
2005-12-07 17:02:42 +03:00
reader - > xsdValidCtxt = NULL ;
reader - > xsdPreserveCtxt = 0 ;
return ( - 1 ) ;
}
2005-07-10 23:03:16 +04:00
}
2012-08-14 07:01:07 +04:00
xmlSchemaValidateSetLocator ( reader - > xsdValidCtxt ,
xmlTextReaderLocator ,
( void * ) reader ) ;
2005-12-07 17:02:42 +03:00
/*
* 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 .
*/
2023-12-18 21:47:47 +03:00
if ( ( reader - > errorFunc ! = NULL ) | | ( reader - > sErrorFunc ! = NULL ) )
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2005-07-10 23:03:16 +04:00
reader - > xsdValidErrors = 0 ;
reader - > validate = XML_TEXTREADER_VALIDATE_XSD ;
return ( 0 ) ;
}
2005-12-07 17:02:42 +03:00
/**
* 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 ) ) ;
}
2012-03-19 12:08:16 +04:00
/**
* 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 ) ) ;
}
2003-05-09 23:38:15 +04:00
# endif
2003-04-16 03:32:22 +04:00
2004-10-19 13:04:23 +04:00
/**
* xmlTextReaderIsNamespaceDecl :
* @ reader : the xmlTextReaderPtr used
*
* Determine whether the current node is a namespace declaration
* rather than a regular attribute .
*
* Returns 1 if the current node is a namespace declaration , 0 if it
* is a regular attribute or other type of node , or - 1 in case of
* error .
*/
int
xmlTextReaderIsNamespaceDecl ( xmlTextReaderPtr reader ) {
xmlNodePtr node ;
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > node = = NULL )
return ( - 1 ) ;
if ( reader - > curnode ! = NULL )
node = reader - > curnode ;
else
node = reader - > node ;
2009-08-11 20:31:42 +04:00
2004-10-19 13:04:23 +04:00
if ( XML_NAMESPACE_DECL = = node - > type )
return ( 1 ) ;
else
return ( 0 ) ;
}
/**
* xmlTextReaderConstXmlVersion :
* @ reader : the xmlTextReaderPtr used
*
* Determine the XML version of the document being read .
*
* Returns a string containing the XML version of the document or NULL
* in case of error . The string is deallocated with the reader .
*/
const xmlChar *
xmlTextReaderConstXmlVersion ( xmlTextReaderPtr reader ) {
xmlDocPtr doc = NULL ;
if ( reader = = NULL )
return ( NULL ) ;
if ( reader - > doc ! = NULL )
doc = reader - > doc ;
else if ( reader - > ctxt ! = NULL )
2009-08-11 20:31:42 +04:00
doc = reader - > ctxt - > myDoc ;
2004-10-19 13:04:23 +04:00
if ( doc = = NULL )
return ( NULL ) ;
2009-08-11 20:31:42 +04:00
2004-10-19 13:04:23 +04:00
if ( doc - > version = = NULL )
return ( NULL ) ;
else
2024-04-22 13:23:06 +03:00
return ( constString ( reader , doc - > version ) ) ;
2004-10-19 13:04:23 +04:00
}
/**
* xmlTextReaderStandalone :
* @ reader : the xmlTextReaderPtr used
*
* Determine the standalone status of the document being read .
*
* Returns 1 if the document was declared to be standalone , 0 if it
* was declared to be not standalone , or - 1 if the document did not
* specify its standalone status or in case of error .
*/
int
xmlTextReaderStandalone ( xmlTextReaderPtr reader ) {
xmlDocPtr doc = NULL ;
if ( reader = = NULL )
return ( - 1 ) ;
if ( reader - > doc ! = NULL )
doc = reader - > doc ;
else if ( reader - > ctxt ! = NULL )
doc = reader - > ctxt - > myDoc ;
if ( doc = = NULL )
return ( - 1 ) ;
return ( doc - > standalone ) ;
}
2003-01-17 01:45:08 +03:00
/************************************************************************
* *
* Error Handling Extensions *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-21 00:26:34 +03:00
/**
2003-01-21 14:21:07 +03:00
* xmlTextReaderLocatorLineNumber :
2003-01-21 00:26:34 +03:00
* @ locator : the xmlTextReaderLocatorPtr used
*
* Obtain the line number for the given locator .
*
* Returns the line number or - 1 in case of error .
*/
int
xmlTextReaderLocatorLineNumber ( xmlTextReaderLocatorPtr locator ) {
/* we know that locator is a xmlParserCtxtPtr */
xmlParserCtxtPtr ctx = ( xmlParserCtxtPtr ) locator ;
int ret = - 1 ;
2004-11-05 20:22:25 +03:00
if ( locator = = NULL )
return ( - 1 ) ;
2003-01-21 00:26:34 +03:00
if ( ctx - > node ! = NULL ) {
ret = xmlGetLineNo ( ctx - > node ) ;
}
else {
/* inspired from error.c */
xmlParserInputPtr input ;
input = ctx - > input ;
if ( ( input - > filename = = NULL ) & & ( ctx - > inputNr > 1 ) )
input = ctx - > inputTab [ ctx - > inputNr - 2 ] ;
if ( input ! = NULL ) {
ret = input - > line ;
2009-08-11 20:31:42 +04:00
}
2003-01-21 00:26:34 +03:00
else {
ret = - 1 ;
}
}
return ret ;
}
/**
2003-01-21 14:21:07 +03:00
* xmlTextReaderLocatorBaseURI :
2003-01-21 00:26:34 +03:00
* @ locator : the xmlTextReaderLocatorPtr used
*
* Obtain the base URI for the given locator .
*
2009-08-11 20:31:42 +04:00
* Returns the base URI or NULL in case of error ,
* if non NULL it need to be freed by the caller .
2003-01-21 00:26:34 +03:00
*/
xmlChar *
xmlTextReaderLocatorBaseURI ( xmlTextReaderLocatorPtr locator ) {
/* we know that locator is a xmlParserCtxtPtr */
xmlParserCtxtPtr ctx = ( xmlParserCtxtPtr ) locator ;
xmlChar * ret = NULL ;
2004-11-05 20:22:25 +03:00
if ( locator = = NULL )
return ( NULL ) ;
2003-01-21 00:26:34 +03:00
if ( ctx - > node ! = NULL ) {
ret = xmlNodeGetBase ( NULL , ctx - > node ) ;
}
else {
/* inspired from error.c */
xmlParserInputPtr input ;
input = ctx - > input ;
if ( ( input - > filename = = NULL ) & & ( ctx - > inputNr > 1 ) )
input = ctx - > inputTab [ ctx - > inputNr - 2 ] ;
if ( input ! = NULL ) {
2003-03-22 00:22:48 +03:00
ret = xmlStrdup ( BAD_CAST input - > filename ) ;
2009-08-11 20:31:42 +04:00
}
2003-01-21 00:26:34 +03:00
else {
ret = NULL ;
}
}
return ret ;
}
2003-01-17 01:45:08 +03:00
/**
* xmlTextReaderSetErrorHandler :
* @ reader : the xmlTextReaderPtr used
* @ f : the callback function to call on error and warnings
* @ arg : a user argument to pass to the callback function
*
2023-12-21 19:30:38 +03:00
* DEPRECATED : Use xmlTextReaderSetStructuredErrorHandler .
*
2003-01-21 00:26:34 +03:00
* Register a callback function that will be called on error and warnings .
*
2003-01-17 01:45:08 +03:00
* If @ f is NULL , the default error and warning handlers are restored .
*/
void
2009-08-11 20:31:42 +04:00
xmlTextReaderSetErrorHandler ( xmlTextReaderPtr reader ,
xmlTextReaderErrorFunc f , void * arg )
{
2003-01-17 01:45:08 +03:00
if ( f ! = NULL ) {
2009-08-11 20:31:42 +04:00
reader - > errorFunc = f ;
reader - > sErrorFunc = NULL ;
reader - > errorFuncArg = arg ;
2023-12-18 21:47:47 +03:00
xmlCtxtSetErrorHandler ( reader - > ctxt ,
xmlTextReaderStructuredRelay , reader ) ;
2005-07-14 03:07:49 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2009-08-11 20:31:42 +04:00
if ( reader - > rngValidCtxt ) {
2023-12-18 21:47:47 +03:00
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2009-08-11 20:31:42 +04:00
}
if ( reader - > xsdValidCtxt ) {
2023-12-18 21:47:47 +03:00
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt ,
xmlTextReaderStructuredRelay , reader ) ;
2009-08-11 20:31:42 +04:00
}
2005-07-14 03:07:49 +04:00
# endif
2009-08-11 20:31:42 +04:00
} else {
/* restore defaults */
reader - > errorFunc = NULL ;
reader - > sErrorFunc = NULL ;
reader - > errorFuncArg = NULL ;
2023-12-18 21:47:47 +03:00
xmlCtxtSetErrorHandler ( reader - > ctxt , NULL , NULL ) ;
2005-07-14 03:07:49 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2009-08-11 20:31:42 +04:00
if ( reader - > rngValidCtxt ) {
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt , NULL ,
2023-12-18 21:47:47 +03:00
NULL ) ;
2009-08-11 20:31:42 +04:00
}
if ( reader - > xsdValidCtxt ) {
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt , NULL ,
2023-12-18 21:47:47 +03:00
NULL ) ;
2009-08-11 20:31:42 +04:00
}
2005-07-14 03:07:49 +04:00
# endif
2003-01-17 01:45:08 +03:00
}
}
2004-02-03 03:14:10 +03:00
/**
* xmlTextReaderSetStructuredErrorHandler :
* @ reader : the xmlTextReaderPtr used
* @ f : the callback function to call on error and warnings
* @ arg : a user argument to pass to the callback function
*
* Register a callback function that will be called on error and warnings .
*
* If @ f is NULL , the default error and warning handlers are restored .
*/
void
2009-08-11 20:31:42 +04:00
xmlTextReaderSetStructuredErrorHandler ( xmlTextReaderPtr reader ,
xmlStructuredErrorFunc f , void * arg )
{
if ( f ! = NULL ) {
reader - > sErrorFunc = f ;
reader - > errorFunc = NULL ;
reader - > errorFuncArg = arg ;
2023-12-18 21:47:47 +03:00
xmlCtxtSetErrorHandler ( reader - > ctxt ,
xmlTextReaderStructuredRelay , reader ) ;
2005-07-14 03:07:49 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2009-08-11 20:31:42 +04:00
if ( reader - > rngValidCtxt ) {
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt ,
2023-12-18 21:47:47 +03:00
xmlTextReaderStructuredRelay , reader ) ;
2009-08-11 20:31:42 +04:00
}
if ( reader - > xsdValidCtxt ) {
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt ,
2023-12-18 21:47:47 +03:00
xmlTextReaderStructuredRelay , reader ) ;
2009-08-11 20:31:42 +04:00
}
2005-07-14 03:07:49 +04:00
# endif
2009-08-11 20:31:42 +04:00
} else {
/* restore defaults */
reader - > errorFunc = NULL ;
reader - > sErrorFunc = NULL ;
reader - > errorFuncArg = NULL ;
2023-12-18 21:47:47 +03:00
xmlCtxtSetErrorHandler ( reader - > ctxt , NULL , NULL ) ;
2005-07-14 03:07:49 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
2009-08-11 20:31:42 +04:00
if ( reader - > rngValidCtxt ) {
xmlRelaxNGSetValidStructuredErrors ( reader - > rngValidCtxt , NULL ,
2023-12-18 21:47:47 +03:00
NULL ) ;
2009-08-11 20:31:42 +04:00
}
if ( reader - > xsdValidCtxt ) {
xmlSchemaSetValidStructuredErrors ( reader - > xsdValidCtxt , NULL ,
2023-12-18 21:47:47 +03:00
NULL ) ;
2009-08-11 20:31:42 +04:00
}
2005-07-14 03:07:49 +04:00
# endif
2009-08-11 20:31:42 +04:00
}
2004-02-03 03:14:10 +03:00
}
2024-06-11 15:47:03 +03:00
/**
* xmlTextReaderGetErrorHandler :
* @ reader : the xmlTextReaderPtr used
* @ f : the callback function or NULL is no callback has been registered
* @ arg : a user argument
*
* Retrieve the error callback function and user argument .
*/
void
xmlTextReaderGetErrorHandler ( xmlTextReaderPtr reader ,
xmlTextReaderErrorFunc * f , void * * arg )
{
if ( f ! = NULL )
* f = reader - > errorFunc ;
if ( arg ! = NULL )
* arg = reader - > errorFuncArg ;
}
/**
* xmlTextReaderSetResourceLoader :
* @ reader : thr reader
* @ loader : resource loader
* @ data : user data which will be passed to the loader
*
* Register a callback function that will be called to load external
* resources like entities .
*
* Available since 2.14 .0 .
*/
void
xmlTextReaderSetResourceLoader ( xmlTextReaderPtr reader ,
xmlResourceLoader loader , void * data ) {
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ;
reader - > resourceLoader = loader ;
reader - > resourceCtxt = data ;
xmlCtxtSetResourceLoader ( reader - > ctxt , loader , data ) ;
}
2003-04-11 23:38:54 +04:00
/**
* xmlTextReaderIsValid :
* @ reader : the xmlTextReaderPtr used
*
* Retrieve the validity status from the parser context
*
* Returns the flag value 1 if valid , 0 if no , and - 1 in case of error
*/
int
2009-08-11 20:31:42 +04:00
xmlTextReaderIsValid ( xmlTextReaderPtr reader )
{
if ( reader = = NULL )
return ( - 1 ) ;
2003-04-16 03:32:22 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
if ( reader - > validate = = XML_TEXTREADER_VALIDATE_RNG )
2009-08-11 20:31:42 +04:00
return ( reader - > rngValidErrors = = 0 ) ;
2005-07-10 23:03:16 +04:00
if ( reader - > validate = = XML_TEXTREADER_VALIDATE_XSD )
2009-08-11 20:31:42 +04:00
return ( reader - > xsdValidErrors = = 0 ) ;
2003-04-16 03:32:22 +04:00
# endif
2003-11-20 21:22:31 +03:00
if ( ( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > validate = = 1 ) )
2009-08-11 20:31:42 +04:00
return ( reader - > ctxt - > valid ) ;
return ( 0 ) ;
2003-04-11 23:38:54 +04:00
}
2003-10-18 13:07:46 +04:00
/************************************************************************
* *
* New set ( 2.6 .0 ) of simpler and more flexible APIs *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlTextReaderSetup :
* @ reader : an XML reader
2007-01-04 20:28:35 +03:00
* @ input : xmlParserInputBufferPtr used to feed the reader , will
* be destroyed with it .
2003-10-18 13:07:46 +04:00
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Setup an XML reader with new options
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error .
*/
2007-01-04 02:13:12 +03:00
int
2003-10-20 21:07:41 +04:00
xmlTextReaderSetup ( xmlTextReaderPtr reader ,
xmlParserInputBufferPtr input , const char * URL ,
2003-10-18 13:07:46 +04:00
const char * encoding , int options )
{
2007-02-09 02:34:34 +03:00
if ( reader = = NULL ) {
2007-02-09 03:07:07 +03:00
if ( input ! = NULL )
2007-02-09 02:34:34 +03:00
xmlFreeParserInputBuffer ( input ) ;
2007-02-09 03:07:07 +03:00
return ( - 1 ) ;
2007-02-09 02:34:34 +03:00
}
2003-10-20 21:07:41 +04:00
2005-08-25 17:19:21 +04:00
/*
* we force the generation of compact text nodes on the reader
* since usr applications should never modify the tree
*/
options | = XML_PARSE_COMPACT ;
2003-10-20 21:07:41 +04:00
reader - > doc = NULL ;
reader - > entNr = 0 ;
2003-12-09 14:35:37 +03:00
reader - > parserFlags = options ;
2003-12-02 13:28:48 +03:00
reader - > validate = XML_TEXTREADER_NOT_VALIDATE ;
2003-10-20 21:07:41 +04:00
if ( ( input ! = NULL ) & & ( reader - > input ! = NULL ) & &
( reader - > allocs & XML_TEXTREADER_INPUT ) ) {
xmlFreeParserInputBuffer ( reader - > input ) ;
reader - > input = NULL ;
reader - > allocs - = XML_TEXTREADER_INPUT ;
}
if ( input ! = NULL ) {
reader - > input = input ;
reader - > allocs | = XML_TEXTREADER_INPUT ;
}
if ( reader - > buffer = = NULL )
2012-07-16 10:42:31 +04:00
reader - > buffer = xmlBufCreateSize ( 100 ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > buffer = = NULL ) {
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
}
2015-04-14 12:41:48 +03:00
/* no operation on a reader should require a huge buffer */
xmlBufSetAllocationScheme ( reader - > buffer ,
2022-03-05 23:46:40 +03:00
XML_BUFFER_ALLOC_DOUBLEIT ) ;
2003-10-20 21:07:41 +04:00
if ( reader - > sax = = NULL )
reader - > sax = ( xmlSAXHandler * ) xmlMalloc ( sizeof ( xmlSAXHandler ) ) ;
if ( reader - > sax = = NULL ) {
return ( - 1 ) ;
}
xmlSAXVersion ( reader - > sax , 2 ) ;
reader - > startElement = reader - > sax - > startElement ;
reader - > sax - > startElement = xmlTextReaderStartElement ;
reader - > endElement = reader - > sax - > endElement ;
reader - > sax - > endElement = xmlTextReaderEndElement ;
# ifdef LIBXML_SAX1_ENABLED
if ( reader - > sax - > initialized = = XML_SAX2_MAGIC ) {
# endif /* LIBXML_SAX1_ENABLED */
reader - > startElementNs = reader - > sax - > startElementNs ;
reader - > sax - > startElementNs = xmlTextReaderStartElementNs ;
reader - > endElementNs = reader - > sax - > endElementNs ;
reader - > sax - > endElementNs = xmlTextReaderEndElementNs ;
# ifdef LIBXML_SAX1_ENABLED
} else {
reader - > startElementNs = NULL ;
reader - > endElementNs = NULL ;
}
# endif /* LIBXML_SAX1_ENABLED */
reader - > characters = reader - > sax - > characters ;
reader - > sax - > characters = xmlTextReaderCharacters ;
reader - > sax - > ignorableWhitespace = xmlTextReaderCharacters ;
reader - > cdataBlock = reader - > sax - > cdataBlock ;
reader - > sax - > cdataBlock = xmlTextReaderCDataBlock ;
reader - > mode = XML_TEXTREADER_MODE_INITIAL ;
reader - > node = NULL ;
reader - > curnode = NULL ;
if ( input ! = NULL ) {
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( reader - > input - > buffer ) < 4 ) {
2003-10-20 21:07:41 +04:00
xmlParserInputBufferRead ( input , 4 ) ;
}
if ( reader - > ctxt = = NULL ) {
2012-07-16 10:42:31 +04:00
if ( xmlBufUse ( reader - > input - > buffer ) > = 4 ) {
2003-10-20 21:07:41 +04:00
reader - > ctxt = xmlCreatePushParserCtxt ( reader - > sax , NULL ,
2012-07-16 10:42:31 +04:00
( const char * ) xmlBufContent ( reader - > input - > buffer ) ,
4 , URL ) ;
2003-10-20 21:07:41 +04:00
reader - > base = 0 ;
reader - > cur = 4 ;
} else {
reader - > ctxt =
xmlCreatePushParserCtxt ( reader - > sax , NULL , NULL , 0 , URL ) ;
reader - > base = 0 ;
reader - > cur = 0 ;
}
2023-12-10 20:23:53 +03:00
if ( reader - > ctxt = = NULL ) {
return ( - 1 ) ;
}
2003-10-20 21:07:41 +04:00
} else {
xmlParserInputPtr inputStream ;
xmlParserInputBufferPtr buf ;
xmlCtxtReset ( reader - > ctxt ) ;
2023-12-10 20:23:53 +03:00
buf = xmlAllocParserInputBuffer ( XML_CHAR_ENCODING_NONE ) ;
2003-10-20 21:07:41 +04:00
if ( buf = = NULL ) return ( - 1 ) ;
inputStream = xmlNewInputStream ( reader - > ctxt ) ;
if ( inputStream = = NULL ) {
xmlFreeParserInputBuffer ( buf ) ;
return ( - 1 ) ;
}
if ( URL = = NULL )
inputStream - > filename = NULL ;
else
inputStream - > filename = ( char * )
xmlCanonicPath ( ( const xmlChar * ) URL ) ;
inputStream - > buf = buf ;
2012-07-16 12:28:47 +04:00
xmlBufResetInput ( buf - > buffer , inputStream ) ;
2003-10-20 21:07:41 +04:00
inputPush ( reader - > ctxt , inputStream ) ;
reader - > cur = 0 ;
}
}
if ( reader - > dict ! = NULL ) {
if ( reader - > ctxt - > dict ! = NULL ) {
if ( reader - > dict ! = reader - > ctxt - > dict ) {
xmlDictFree ( reader - > dict ) ;
reader - > dict = reader - > ctxt - > dict ;
}
} else {
reader - > ctxt - > dict = reader - > dict ;
}
} else {
if ( reader - > ctxt - > dict = = NULL )
reader - > ctxt - > dict = xmlDictCreate ( ) ;
reader - > dict = reader - > ctxt - > dict ;
}
reader - > ctxt - > _private = reader ;
reader - > ctxt - > linenumbers = 1 ;
reader - > ctxt - > dictNames = 1 ;
/*
2016-04-13 17:56:07 +03:00
* use the parser dictionary to allocate all elements and attributes names
2003-10-20 21:07:41 +04:00
*/
2004-06-08 16:03:41 +04:00
reader - > ctxt - > parseMode = XML_PARSE_READER ;
2003-10-18 13:07:46 +04:00
2003-11-03 15:31:38 +03:00
# ifdef LIBXML_XINCLUDE_ENABLED
if ( reader - > xincctxt ! = NULL ) {
xmlXIncludeFreeContext ( reader - > xincctxt ) ;
reader - > xincctxt = NULL ;
}
if ( options & XML_PARSE_XINCLUDE ) {
reader - > xinclude = 1 ;
reader - > xinclude_name = xmlDictLookup ( reader - > dict , XINCLUDE_NODE , - 1 ) ;
2024-04-22 13:23:06 +03:00
if ( reader - > xinclude_name = = NULL )
return ( - 1 ) ;
2003-11-03 15:31:38 +03:00
options - = XML_PARSE_XINCLUDE ;
} else
reader - > xinclude = 0 ;
reader - > in_xinclude = 0 ;
# endif
2003-12-05 17:57:46 +03:00
# ifdef LIBXML_PATTERN_ENABLED
if ( reader - > patternTab = = NULL ) {
reader - > patternNr = 0 ;
reader - > patternMax = 0 ;
}
while ( reader - > patternNr > 0 ) {
reader - > patternNr - - ;
if ( reader - > patternTab [ reader - > patternNr ] ! = NULL ) {
xmlFreePattern ( reader - > patternTab [ reader - > patternNr ] ) ;
reader - > patternTab [ reader - > patternNr ] = NULL ;
}
}
# endif
2003-12-02 13:28:48 +03:00
if ( options & XML_PARSE_DTDVALID )
reader - > validate = XML_TEXTREADER_VALIDATE_DTD ;
2003-10-18 13:07:46 +04:00
xmlCtxtUseOptions ( reader - > ctxt , options ) ;
2023-12-10 20:23:53 +03:00
if ( encoding ! = NULL )
xmlSwitchEncodingName ( reader - > ctxt , encoding ) ;
2003-10-18 13:07:46 +04:00
if ( ( URL ! = NULL ) & & ( reader - > ctxt - > input ! = NULL ) & &
2024-04-22 13:23:06 +03:00
( reader - > ctxt - > input - > filename = = NULL ) ) {
2003-10-18 13:07:46 +04:00
reader - > ctxt - > input - > filename = ( char * )
xmlStrdup ( ( const xmlChar * ) URL ) ;
2024-04-22 13:23:06 +03:00
if ( reader - > ctxt - > input - > filename = = NULL )
return ( - 1 ) ;
}
2003-10-20 21:07:41 +04:00
reader - > doc = NULL ;
2003-10-18 13:07:46 +04:00
return ( 0 ) ;
}
2023-08-20 21:48:10 +03:00
/**
* xmlTextReaderSetMaxAmplification :
* @ reader : an XML reader
* @ maxAmpl : maximum amplification factor
*
* Set the maximum amplification factor . See xmlCtxtSetMaxAmplification .
*/
void
xmlTextReaderSetMaxAmplification ( xmlTextReaderPtr reader , unsigned maxAmpl )
{
xmlCtxtSetMaxAmplification ( reader - > ctxt , maxAmpl ) ;
}
2024-05-20 14:58:22 +03:00
/**
* xmlTextReaderGetLastError :
* @ reader : an XML reader
*
* Available since 2.13 .0 .
*
* Returns the last error .
*/
2023-12-10 20:23:53 +03:00
const xmlError *
xmlTextReaderGetLastError ( xmlTextReaderPtr reader )
{
if ( reader = = NULL )
return ( NULL ) ;
return ( & reader - > ctxt - > lastError ) ;
}
2005-02-18 22:36:12 +03:00
/**
* xmlTextReaderByteConsumed :
* @ reader : an XML reader
*
* This function provides the current index of the parser used
* by the reader , relative to the start of the current entity .
* This function actually just wraps a call to xmlBytesConsumed ( )
* for the parser context associated with the reader .
* See xmlBytesConsumed ( ) for more information .
*
* Returns the index in bytes from the beginning of the entity or - 1
* in case the index could not be computed .
*/
long
xmlTextReaderByteConsumed ( xmlTextReaderPtr reader ) {
if ( ( reader = = NULL ) | | ( reader - > ctxt = = NULL ) )
return ( - 1 ) ;
return ( xmlByteConsumed ( reader - > ctxt ) ) ;
}
2009-08-11 20:31:42 +04:00
2005-02-18 22:36:12 +03:00
2003-10-20 21:07:41 +04:00
/**
* xmlReaderWalker :
* @ doc : a preparsed document
*
* Create an xmltextReader for a preparsed document .
2009-08-11 20:31:42 +04:00
*
2003-10-20 21:07:41 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderWalker ( xmlDocPtr doc )
{
xmlTextReaderPtr ret ;
if ( doc = = NULL )
return ( NULL ) ;
ret = xmlMalloc ( sizeof ( xmlTextReader ) ) ;
if ( ret = = NULL ) {
return ( NULL ) ;
}
memset ( ret , 0 , sizeof ( xmlTextReader ) ) ;
ret - > entNr = 0 ;
ret - > input = NULL ;
ret - > mode = XML_TEXTREADER_MODE_INITIAL ;
ret - > node = NULL ;
ret - > curnode = NULL ;
ret - > base = 0 ;
ret - > cur = 0 ;
ret - > allocs = XML_TEXTREADER_CTXT ;
ret - > doc = doc ;
ret - > state = XML_TEXTREADER_START ;
ret - > dict = xmlDictCreate ( ) ;
return ( ret ) ;
}
2003-10-18 13:07:46 +04:00
/**
* xmlReaderForDoc :
* @ cur : a pointer to a zero terminated string
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Create an xmltextReader for an XML in - memory document .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderForDoc ( const xmlChar * cur , const char * URL , const char * encoding ,
int options )
{
int len ;
if ( cur = = NULL )
return ( NULL ) ;
len = xmlStrlen ( cur ) ;
return ( xmlReaderForMemory
( ( const char * ) cur , len , URL , encoding , options ) ) ;
}
/**
* xmlReaderForFile :
* @ filename : a file or URL
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* parse an XML file from the filesystem or the network .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderForFile ( const char * filename , const char * encoding , int options )
{
xmlTextReaderPtr reader ;
reader = xmlNewTextReaderFilename ( filename ) ;
if ( reader = = NULL )
return ( NULL ) ;
2024-04-22 13:23:06 +03:00
if ( xmlTextReaderSetup ( reader , NULL , NULL , encoding , options ) < 0 ) {
xmlFreeTextReader ( reader ) ;
return ( NULL ) ;
}
2003-10-18 13:07:46 +04:00
return ( reader ) ;
}
/**
* xmlReaderForMemory :
* @ buffer : a pointer to a char array
* @ size : the size of the array
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Create an xmltextReader for an XML in - memory document .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderForMemory ( const char * buffer , int size , const char * URL ,
const char * encoding , int options )
{
xmlTextReaderPtr reader ;
xmlParserInputBufferPtr buf ;
2022-11-15 00:00:50 +03:00
buf = xmlParserInputBufferCreateMem ( buffer , size , XML_CHAR_ENCODING_NONE ) ;
2003-10-18 13:07:46 +04:00
if ( buf = = NULL ) {
return ( NULL ) ;
}
reader = xmlNewTextReader ( buf , URL ) ;
if ( reader = = NULL ) {
xmlFreeParserInputBuffer ( buf ) ;
return ( NULL ) ;
}
2003-10-20 21:07:41 +04:00
reader - > allocs | = XML_TEXTREADER_INPUT ;
2024-04-22 13:23:06 +03:00
if ( xmlTextReaderSetup ( reader , NULL , URL , encoding , options ) < 0 ) {
xmlFreeTextReader ( reader ) ;
return ( NULL ) ;
}
2003-10-18 13:07:46 +04:00
return ( reader ) ;
}
/**
* xmlReaderForFd :
* @ fd : an open file descriptor
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Create an xmltextReader for an XML from a file descriptor .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-12-22 21:13:12 +03:00
* NOTE that the file descriptor will not be closed when the
* reader is closed or reset .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderForFd ( int fd , const char * URL , const char * encoding , int options )
{
xmlTextReaderPtr reader ;
xmlParserInputBufferPtr input ;
if ( fd < 0 )
return ( NULL ) ;
input = xmlParserInputBufferCreateFd ( fd , XML_CHAR_ENCODING_NONE ) ;
if ( input = = NULL )
return ( NULL ) ;
2003-12-22 21:13:12 +03:00
input - > closecallback = NULL ;
2003-10-18 13:07:46 +04:00
reader = xmlNewTextReader ( input , URL ) ;
if ( reader = = NULL ) {
xmlFreeParserInputBuffer ( input ) ;
return ( NULL ) ;
}
2003-10-20 21:07:41 +04:00
reader - > allocs | = XML_TEXTREADER_INPUT ;
2024-04-22 13:23:06 +03:00
if ( xmlTextReaderSetup ( reader , NULL , URL , encoding , options ) < 0 ) {
xmlFreeTextReader ( reader ) ;
return ( NULL ) ;
}
2003-10-18 13:07:46 +04:00
return ( reader ) ;
}
/**
* xmlReaderForIO :
* @ ioread : an I / O read function
* @ ioclose : an I / O close function
* @ ioctx : an I / O handler
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Create an xmltextReader for an XML document from I / O functions and source .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns the new reader or NULL in case of error .
*/
xmlTextReaderPtr
xmlReaderForIO ( xmlInputReadCallback ioread , xmlInputCloseCallback ioclose ,
void * ioctx , const char * URL , const char * encoding ,
int options )
{
xmlTextReaderPtr reader ;
xmlParserInputBufferPtr input ;
if ( ioread = = NULL )
return ( NULL ) ;
input = xmlParserInputBufferCreateIO ( ioread , ioclose , ioctx ,
XML_CHAR_ENCODING_NONE ) ;
2012-05-10 12:14:55 +04:00
if ( input = = NULL ) {
if ( ioclose ! = NULL )
ioclose ( ioctx ) ;
2003-10-18 13:07:46 +04:00
return ( NULL ) ;
2012-05-10 12:14:55 +04:00
}
2003-10-18 13:07:46 +04:00
reader = xmlNewTextReader ( input , URL ) ;
if ( reader = = NULL ) {
xmlFreeParserInputBuffer ( input ) ;
return ( NULL ) ;
}
2003-10-20 21:07:41 +04:00
reader - > allocs | = XML_TEXTREADER_INPUT ;
2024-04-22 13:23:06 +03:00
if ( xmlTextReaderSetup ( reader , NULL , URL , encoding , options ) < 0 ) {
xmlFreeTextReader ( reader ) ;
return ( NULL ) ;
}
2003-10-18 13:07:46 +04:00
return ( reader ) ;
}
2003-10-20 21:07:41 +04:00
/**
* xmlReaderNewWalker :
* @ reader : an XML reader
* @ doc : a preparsed document
*
* Setup an xmltextReader to parse a preparsed XML document .
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-20 21:07:41 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewWalker ( xmlTextReaderPtr reader , xmlDocPtr doc )
{
if ( doc = = NULL )
return ( - 1 ) ;
if ( reader = = NULL )
return ( - 1 ) ;
2004-11-03 17:20:29 +03:00
if ( reader - > input ! = NULL ) {
xmlFreeParserInputBuffer ( reader - > input ) ;
}
2003-10-20 21:07:41 +04:00
if ( reader - > ctxt ! = NULL ) {
xmlCtxtReset ( reader - > ctxt ) ;
}
reader - > entNr = 0 ;
reader - > input = NULL ;
reader - > mode = XML_TEXTREADER_MODE_INITIAL ;
reader - > node = NULL ;
reader - > curnode = NULL ;
reader - > base = 0 ;
reader - > cur = 0 ;
reader - > allocs = XML_TEXTREADER_CTXT ;
reader - > doc = doc ;
reader - > state = XML_TEXTREADER_START ;
if ( reader - > dict = = NULL ) {
if ( ( reader - > ctxt ! = NULL ) & & ( reader - > ctxt - > dict ! = NULL ) )
reader - > dict = reader - > ctxt - > dict ;
else
reader - > dict = xmlDictCreate ( ) ;
}
return ( 0 ) ;
}
2003-10-18 13:07:46 +04:00
/**
* xmlReaderNewDoc :
* @ reader : an XML reader
* @ cur : a pointer to a zero terminated string
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Setup an xmltextReader to parse an XML in - memory document .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-10-18 13:07:46 +04:00
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewDoc ( xmlTextReaderPtr reader , const xmlChar * cur ,
const char * URL , const char * encoding , int options )
{
2003-10-20 21:07:41 +04:00
int len ;
2003-10-18 13:07:46 +04:00
if ( cur = = NULL )
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
len = xmlStrlen ( cur ) ;
return ( xmlReaderNewMemory ( reader , ( const char * ) cur , len ,
URL , encoding , options ) ) ;
2003-10-18 13:07:46 +04:00
}
/**
* xmlReaderNewFile :
* @ reader : an XML reader
* @ filename : a file or URL
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* parse an XML file from the filesystem or the network .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-10-18 13:07:46 +04:00
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewFile ( xmlTextReaderPtr reader , const char * filename ,
const char * encoding , int options )
{
2003-10-20 21:07:41 +04:00
xmlParserInputBufferPtr input ;
2003-10-18 13:07:46 +04:00
if ( filename = = NULL )
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
input =
xmlParserInputBufferCreateFilename ( filename ,
XML_CHAR_ENCODING_NONE ) ;
if ( input = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
return ( xmlTextReaderSetup ( reader , input , filename , encoding , options ) ) ;
2003-10-18 13:07:46 +04:00
}
/**
* xmlReaderNewMemory :
* @ reader : an XML reader
* @ buffer : a pointer to a char array
* @ size : the size of the array
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Setup an xmltextReader to parse an XML in - memory document .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-10-18 13:07:46 +04:00
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewMemory ( xmlTextReaderPtr reader , const char * buffer , int size ,
const char * URL , const char * encoding , int options )
{
xmlParserInputBufferPtr input ;
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
if ( buffer = = NULL )
return ( - 1 ) ;
2022-11-15 00:00:50 +03:00
input = xmlParserInputBufferCreateMem ( buffer , size ,
2003-10-18 13:07:46 +04:00
XML_CHAR_ENCODING_NONE ) ;
if ( input = = NULL ) {
return ( - 1 ) ;
}
2003-10-20 21:07:41 +04:00
return ( xmlTextReaderSetup ( reader , input , URL , encoding , options ) ) ;
2003-10-18 13:07:46 +04:00
}
/**
* xmlReaderNewFd :
* @ reader : an XML reader
* @ fd : an open file descriptor
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Setup an xmltextReader to parse an XML from a file descriptor .
2003-12-22 21:13:12 +03:00
* NOTE that the file descriptor will not be closed when the
* reader is closed or reset .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-10-18 13:07:46 +04:00
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewFd ( xmlTextReaderPtr reader , int fd ,
const char * URL , const char * encoding , int options )
{
xmlParserInputBufferPtr input ;
if ( fd < 0 )
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
input = xmlParserInputBufferCreateFd ( fd , XML_CHAR_ENCODING_NONE ) ;
if ( input = = NULL )
return ( - 1 ) ;
2003-12-22 21:13:12 +03:00
input - > closecallback = NULL ;
2003-10-20 21:07:41 +04:00
return ( xmlTextReaderSetup ( reader , input , URL , encoding , options ) ) ;
2003-10-18 13:07:46 +04:00
}
/**
* xmlReaderNewIO :
* @ reader : an XML reader
* @ ioread : an I / O read function
* @ ioclose : an I / O close function
* @ ioctx : an I / O handler
* @ URL : the base URL to use for the document
* @ encoding : the document encoding , or NULL
2003-12-21 16:01:56 +03:00
* @ options : a combination of xmlParserOption
2003-10-18 13:07:46 +04:00
*
* Setup an xmltextReader to parse an XML document from I / O functions
* and source .
2003-12-21 16:01:56 +03:00
* The parsing flags @ options are a combination of xmlParserOption .
2003-10-18 13:07:46 +04:00
* This reuses the existing @ reader xmlTextReader .
2009-08-11 20:31:42 +04:00
*
2003-10-18 13:07:46 +04:00
* Returns 0 in case of success and - 1 in case of error
*/
int
xmlReaderNewIO ( xmlTextReaderPtr reader , xmlInputReadCallback ioread ,
xmlInputCloseCallback ioclose , void * ioctx ,
const char * URL , const char * encoding , int options )
{
xmlParserInputBufferPtr input ;
if ( ioread = = NULL )
return ( - 1 ) ;
2003-10-20 21:07:41 +04:00
if ( reader = = NULL )
2003-10-18 13:07:46 +04:00
return ( - 1 ) ;
input = xmlParserInputBufferCreateIO ( ioread , ioclose , ioctx ,
XML_CHAR_ENCODING_NONE ) ;
2012-05-10 12:14:55 +04:00
if ( input = = NULL ) {
if ( ioclose ! = NULL )
ioclose ( ioctx ) ;
2012-05-11 08:08:15 +04:00
return ( - 1 ) ;
2012-05-10 12:14:55 +04:00
}
2003-10-20 21:07:41 +04:00
return ( xmlTextReaderSetup ( reader , input , URL , encoding , options ) ) ;
2003-10-18 13:07:46 +04:00
}
2012-05-10 12:14:55 +04:00
2002-12-18 17:53:54 +03:00
/************************************************************************
* *
* Utilities *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-09-17 14:26:25 +04:00
# ifdef NOT_USED_YET
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
/**
* xmlBase64Decode :
* @ in : the input buffer
* @ inlen : the size of the input ( in ) , the size read from it ( out )
* @ to : the output buffer
* @ tolen : the size of the output ( in ) , the size written to ( out )
*
* Base64 decoder , reads from @ in and save in @ to
2003-02-19 00:12:46 +03:00
* TODO : tell jody when this is actually exported
2002-12-18 17:53:54 +03:00
*
* Returns 0 if all the input was consumer , 1 if the Base64 end was reached ,
* 2 if there wasn ' t enough space on the output or - 1 in case of error .
*/
static int
xmlBase64Decode ( const unsigned char * in , unsigned long * inlen ,
2009-08-11 20:31:42 +04:00
unsigned char * to , unsigned long * tolen )
{
unsigned long incur ; /* current index in in[] */
unsigned long inblk ; /* last block index in in[] */
unsigned long outcur ; /* current index in out[] */
unsigned long inmax ; /* size of in[] */
unsigned long outmax ; /* size of out[] */
unsigned char cur ; /* the current value read from in[] */
unsigned char intmp [ 4 ] , outtmp [ 4 ] ; /* temporary buffers for the convert */
int nbintmp ; /* number of byte in intmp[] */
int is_ignore ; /* cur should be ignored */
int is_end = 0 ; /* the end of the base64 was found */
2002-12-18 17:53:54 +03:00
int retval = 1 ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
int i ;
if ( ( in = = NULL ) | | ( inlen = = NULL ) | | ( to = = NULL ) | | ( tolen = = NULL ) )
2009-08-11 20:31:42 +04:00
return ( - 1 ) ;
2002-12-18 17:53:54 +03:00
incur = 0 ;
inblk = 0 ;
outcur = 0 ;
inmax = * inlen ;
outmax = * tolen ;
nbintmp = 0 ;
while ( 1 ) {
if ( incur > = inmax )
break ;
cur = in [ incur + + ] ;
is_ignore = 0 ;
if ( ( cur > = ' A ' ) & & ( cur < = ' Z ' ) )
cur = cur - ' A ' ;
else if ( ( cur > = ' a ' ) & & ( cur < = ' z ' ) )
cur = cur - ' a ' + 26 ;
else if ( ( cur > = ' 0 ' ) & & ( cur < = ' 9 ' ) )
cur = cur - ' 0 ' + 52 ;
else if ( cur = = ' + ' )
cur = 62 ;
else if ( cur = = ' / ' )
cur = 63 ;
else if ( cur = = ' . ' )
cur = 0 ;
2009-08-11 20:31:42 +04:00
else if ( cur = = ' = ' ) /*no op , end of the base64 stream */
2002-12-18 17:53:54 +03:00
is_end = 1 ;
else {
is_ignore = 1 ;
2009-08-11 20:31:42 +04:00
if ( nbintmp = = 0 )
inblk = incur ;
}
2002-12-18 17:53:54 +03:00
if ( ! is_ignore ) {
int nbouttmp = 3 ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
int is_break = 0 ;
if ( is_end ) {
if ( nbintmp = = 0 )
break ;
if ( ( nbintmp = = 1 ) | | ( nbintmp = = 2 ) )
nbouttmp = 1 ;
else
nbouttmp = 2 ;
nbintmp = 3 ;
is_break = 1 ;
}
intmp [ nbintmp + + ] = cur ;
2009-08-11 20:31:42 +04:00
/*
* if intmp is full , push the 4 byte sequence as a 3 byte
* sequence out
*/
2002-12-18 17:53:54 +03:00
if ( nbintmp = = 4 ) {
nbintmp = 0 ;
outtmp [ 0 ] = ( intmp [ 0 ] < < 2 ) | ( ( intmp [ 1 ] & 0x30 ) > > 4 ) ;
outtmp [ 1 ] =
( ( intmp [ 1 ] & 0x0F ) < < 4 ) | ( ( intmp [ 2 ] & 0x3C ) > > 2 ) ;
outtmp [ 2 ] = ( ( intmp [ 2 ] & 0x03 ) < < 6 ) | ( intmp [ 3 ] & 0x3F ) ;
2009-08-11 20:31:42 +04:00
if ( outcur + 3 > = outmax ) {
retval = 2 ;
break ;
}
2002-12-18 17:53:54 +03:00
for ( i = 0 ; i < nbouttmp ; i + + )
2009-08-11 20:31:42 +04:00
to [ outcur + + ] = outtmp [ i ] ;
inblk = incur ;
2002-12-18 17:53:54 +03:00
}
if ( is_break ) {
2009-08-11 20:31:42 +04:00
retval = 0 ;
2002-12-18 17:53:54 +03:00
break ;
2009-08-11 20:31:42 +04:00
}
2002-12-18 17:53:54 +03:00
}
}
* tolen = outcur ;
* inlen = inblk ;
return ( retval ) ;
}
/*
* Test routine for the xmlBase64Decode function
*/
#if 0
2009-08-11 20:31:42 +04:00
int
main ( int argc , char * * argv )
{
2002-12-18 17:53:54 +03:00
char * input = " VW4 gcGV0 \n aXQgdGVzdCAuCg== " ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
char output [ 100 ] ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
char output2 [ 100 ] ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
char output3 [ 100 ] ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
unsigned long inlen = strlen ( input ) ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
unsigned long outlen = 100 ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
int ret ;
2009-08-11 20:31:42 +04:00
2002-12-18 17:53:54 +03:00
unsigned long cons , tmp , tmp2 , prod ;
/*
* Direct
*/
ret = xmlBase64Decode ( input , & inlen , output , & outlen ) ;
output [ outlen ] = 0 ;
2009-08-11 20:31:42 +04:00
printf ( " ret: %d, inlen: %ld , outlen: %ld, output: '%s' \n " , ret , inlen ,
outlen , output ) indent : Standard input : 179 : Error : Unmatched # endif
;
2002-12-18 17:53:54 +03:00
/*
* output chunking
*/
cons = 0 ;
prod = 0 ;
while ( cons < inlen ) {
2009-08-11 20:31:42 +04:00
tmp = 5 ;
tmp2 = inlen - cons ;
2002-12-18 17:53:54 +03:00
2009-08-11 20:31:42 +04:00
printf ( " %ld %ld \n " , cons , prod ) ;
ret = xmlBase64Decode ( & input [ cons ] , & tmp2 , & output2 [ prod ] , & tmp ) ;
cons + = tmp2 ;
prod + = tmp ;
printf ( " %ld %ld \n " , cons , prod ) ;
2002-12-18 17:53:54 +03:00
}
output2 [ outlen ] = 0 ;
2009-08-11 20:31:42 +04:00
printf ( " ret: %d, cons: %ld , prod: %ld, output: '%s' \n " , ret , cons ,
prod , output2 ) ;
2002-12-18 17:53:54 +03:00
/*
* input chunking
*/
cons = 0 ;
prod = 0 ;
while ( cons < inlen ) {
2009-08-11 20:31:42 +04:00
tmp = 100 - prod ;
tmp2 = inlen - cons ;
if ( tmp2 > 5 )
tmp2 = 5 ;
2002-12-18 17:53:54 +03:00
2009-08-11 20:31:42 +04:00
printf ( " %ld %ld \n " , cons , prod ) ;
ret = xmlBase64Decode ( & input [ cons ] , & tmp2 , & output3 [ prod ] , & tmp ) ;
cons + = tmp2 ;
prod + = tmp ;
printf ( " %ld %ld \n " , cons , prod ) ;
2002-12-18 17:53:54 +03:00
}
output3 [ outlen ] = 0 ;
2009-08-11 20:31:42 +04:00
printf ( " ret: %d, cons: %ld , prod: %ld, output: '%s' \n " , ret , cons ,
prod , output3 ) ;
return ( 0 ) ;
2002-12-18 17:53:54 +03:00
}
# endif
2003-09-17 14:26:25 +04:00
# endif /* NOT_USED_YET */
2022-02-20 20:46:42 +03:00
2003-09-30 04:43:48 +04:00
# endif /* LIBXML_READER_ENABLED */