ReactOS 0.4.15-dev-7942-gd23573b
parser.c File Reference
#include "libxml.h"
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <ctype.h>
#include <libxml/xmlmemory.h>
#include <libxml/threads.h>
#include <libxml/globals.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/valid.h>
#include <libxml/entities.h>
#include <libxml/xmlerror.h>
#include <libxml/encoding.h>
#include <libxml/xmlIO.h>
#include <libxml/uri.h>
#include "buf.h"
#include "enc.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Classes

struct  _xmlStartTag
 
struct  _xmlDefAttrs
 

Macros

#define IN_LIBXML
 
#define XML_DIR_SEP   '/'
 
#define XML_MAX_HUGE_LENGTH   1000000000
 
#define XML_PARSER_BIG_ENTITY   1000
 
#define XML_PARSER_LOT_ENTITY   5000
 
#define XML_PARSER_NON_LINEAR   10
 
#define SAX2   1
 
#define XML_PARSER_BIG_BUFFER_SIZE   300
 
#define XML_PARSER_BUFFER_SIZE   100
 
#define SAX_COMPAT_MODE   BAD_CAST "SAX compatibility mode document"
 
#define XML_PARSER_CHUNK_SIZE   100
 
#define RAW   (*ctxt->input->cur)
 
#define CUR   (*ctxt->input->cur)
 
#define NXT(val)   ctxt->input->cur[(val)]
 
#define CUR_PTR   ctxt->input->cur
 
#define BASE_PTR   ctxt->input->base
 
#define CMP4(s, c1, c2, c3, c4)
 
#define CMP5(s, c1, c2, c3, c4, c5)    ( CMP4( s, c1, c2, c3, c4 ) && ((unsigned char *) s)[ 4 ] == c5 )
 
#define CMP6(s, c1, c2, c3, c4, c5, c6)    ( CMP5( s, c1, c2, c3, c4, c5 ) && ((unsigned char *) s)[ 5 ] == c6 )
 
#define CMP7(s, c1, c2, c3, c4, c5, c6, c7)    ( CMP6( s, c1, c2, c3, c4, c5, c6 ) && ((unsigned char *) s)[ 6 ] == c7 )
 
#define CMP8(s, c1, c2, c3, c4, c5, c6, c7, c8)    ( CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) && ((unsigned char *) s)[ 7 ] == c8 )
 
#define CMP9(s, c1, c2, c3, c4, c5, c6, c7, c8, c9)
 
#define CMP10(s, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)
 
#define SKIP(val)
 
#define SKIPL(val)
 
#define SHRINK
 
#define GROW
 
#define SKIP_BLANKS   xmlSkipBlankChars(ctxt)
 
#define NEXT   xmlNextChar(ctxt)
 
#define NEXT1
 
#define NEXTL(l)
 
#define CUR_CHAR(l)   xmlCurrentChar(ctxt, &l)
 
#define CUR_SCHAR(s, l)   xmlStringCurrentChar(ctxt, s, &l)
 
#define COPY_BUF(l, b, i, v)
 
#define CUR_CONSUMED    (ctxt->input->consumed + (ctxt->input->cur - ctxt->input->base))
 
#define growBuffer(buffer, n)
 

Typedefs

typedef struct _xmlDefAttrs xmlDefAttrs
 
typedef xmlDefAttrsxmlDefAttrsPtr
 

Functions

static void xmlFatalErr (xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
 
static int xmlParserEntityCheck (xmlParserCtxtPtr ctxt, size_t size, xmlEntityPtr ent, size_t replacement)
 
static void xmlErrAttributeDup (xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *localname)
 
static void LIBXML_ATTR_FORMAT (3, 0)
 
int xmlHasFeature (xmlFeature feature)
 
static void xmlDetectSAX2 (xmlParserCtxtPtr ctxt)
 
static xmlCharxmlAttrNormalizeSpace (const xmlChar *src, xmlChar *dst)
 
static const xmlCharxmlAttrNormalizeSpace2 (xmlParserCtxtPtr ctxt, xmlChar *src, int *len)
 
static void xmlAddDefAttrs (xmlParserCtxtPtr ctxt, const xmlChar *fullname, const xmlChar *fullattr, const xmlChar *value)
 
static void xmlAddSpecialAttr (xmlParserCtxtPtr ctxt, const xmlChar *fullname, const xmlChar *fullattr, int type)
 
static void xmlCleanSpecialAttrCallback (void *payload, void *data, const xmlChar *fullname, const xmlChar *fullattr, const xmlChar *unused ATTRIBUTE_UNUSED)
 
static void xmlCleanSpecialAttr (xmlParserCtxtPtr ctxt)
 
int xmlCheckLanguageID (const xmlChar *lang)
 
static int nsPush (xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *URL)
 
static int nsPop (xmlParserCtxtPtr ctxt, int nr)
 
static int xmlCtxtGrowAttrs (xmlParserCtxtPtr ctxt, int nr)
 
int inputPush (xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
 
xmlParserInputPtr inputPop (xmlParserCtxtPtr ctxt)
 
int nodePush (xmlParserCtxtPtr ctxt, xmlNodePtr value)
 
xmlNodePtr nodePop (xmlParserCtxtPtr ctxt)
 
static int nameNsPush (xmlParserCtxtPtr ctxt, const xmlChar *value, const xmlChar *prefix, const xmlChar *URI, int line, int nsNr)
 
int namePush (xmlParserCtxtPtr ctxt, const xmlChar *value)
 
const xmlCharnamePop (xmlParserCtxtPtr ctxt)
 
static int spacePush (xmlParserCtxtPtr ctxt, int val)
 
static int spacePop (xmlParserCtxtPtr ctxt)
 
static void xmlSHRINK (xmlParserCtxtPtr ctxt)
 
static void xmlGROW (xmlParserCtxtPtr ctxt)
 
int xmlSkipBlankChars (xmlParserCtxtPtr ctxt)
 
xmlChar xmlPopInput (xmlParserCtxtPtr ctxt)
 
int xmlPushInput (xmlParserCtxtPtr ctxt, xmlParserInputPtr input)
 
int xmlParseCharRef (xmlParserCtxtPtr ctxt)
 
static int xmlParseStringCharRef (xmlParserCtxtPtr ctxt, const xmlChar **str)
 
void xmlParserHandlePEReference (xmlParserCtxtPtr ctxt)
 
xmlCharxmlStringLenDecodeEntities (xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int what, xmlChar end, xmlChar end2, xmlChar end3)
 
xmlCharxmlStringDecodeEntities (xmlParserCtxtPtr ctxt, const xmlChar *str, int what, xmlChar end, xmlChar end2, xmlChar end3)
 
static int areBlanks (xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int blank_chars)
 
: the name of the element being defined.

xmlParseElementContentDecl: @ctxt: an XML parser context

Returns
: the Element Content pointer will be stored here if any

parse the declaration for an Element content either Mixed or Children, the cases EMPTY and ANY are handled directly in xmlParseElementDecl

[46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children

returns: the type of element content XML_ELEMENT_TYPE_xxx

static xmlEntityPtr xmlParseStringPEReference (xmlParserCtxtPtr ctxt, const xmlChar **str)
 
static int xmlLoadEntityContent (xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
 
static xmlEntityPtr xmlParseStringEntityRef (xmlParserCtxtPtr ctxt, const xmlChar **str)
 
int xmlParseElementContentDecl (xmlParserCtxtPtr ctxt, const xmlChar *name, xmlElementContentPtr *result)
 
int xmlParseElementDecl (xmlParserCtxtPtr ctxt)
 
static void xmlParseConditionalSections (xmlParserCtxtPtr ctxt)
 
void xmlParseMarkupDecl (xmlParserCtxtPtr ctxt)
 
void xmlParseTextDecl (xmlParserCtxtPtr ctxt)
 
void xmlParseExternalSubset (xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, const xmlChar *SystemID)
 
void xmlParseReference (xmlParserCtxtPtr ctxt)
 
xmlEntityPtr xmlParseEntityRef (xmlParserCtxtPtr ctxt)
 
void xmlParsePEReference (xmlParserCtxtPtr ctxt)
 
void xmlParseDocTypeDecl (xmlParserCtxtPtr ctxt)
 
static void xmlParseInternalSubset (xmlParserCtxtPtr ctxt)
 
static const xmlCharxmlGetNamespace (xmlParserCtxtPtr ctxt, const xmlChar *prefix)
 
static const xmlCharxmlParseQName (xmlParserCtxtPtr ctxt, const xmlChar **prefix)
 

Variables

unsigned int xmlParserMaxDepth = 256
 
static const char *const xmlW3CPIs []
 

: the localname

xmlParseQNameAndCompare: @ctxt: an XML parser context

@prefix: the prefix, if any.

parse an XML name and compares for match (specialized for endtag parsing)

Returns NULL for an illegal name, (xmlChar*) 1 for success and the name for mismatch

#define GROW_PARSE_ATT_VALUE_INTERNAL(ctxt, in, start, end)
 
#define DICT_FREE(str)
 
static int xmlParserInitialized = 0
 
static xmlParserCtxtPtr xmlCreateEntityParserCtxtInternal (const xmlChar *URL, const xmlChar *ID, const xmlChar *base, xmlParserCtxtPtr pctx)
 
static void xmlHaltParser (xmlParserCtxtPtr ctxt)
 
static int xmlParseElementStart (xmlParserCtxtPtr ctxt)
 
static void xmlParseElementEnd (xmlParserCtxtPtr ctxt)
 
static xmlParserErrors xmlParseExternalEntityPrivate (xmlDocPtr doc, xmlParserCtxtPtr oldctxt, xmlSAXHandlerPtr sax, void *user_data, int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *list)
 
static int xmlCtxtUseOptionsInternal (xmlParserCtxtPtr ctxt, int options, const char *encoding)
 
static xmlParserErrors xmlParseBalancedChunkMemoryInternal (xmlParserCtxtPtr oldctxt, const xmlChar *string, void *user_data, xmlNodePtr *lst)
 
static const xmlCharxmlParseQNameAndCompare (xmlParserCtxtPtr ctxt, xmlChar const *name, xmlChar const *prefix)
 
static const xmlCharxmlParseAttribute2 (xmlParserCtxtPtr ctxt, const xmlChar *pref, const xmlChar *elem, const xmlChar **prefix, xmlChar **value, int *len, int *alloc)
 
static const xmlCharxmlParseStartTag2 (xmlParserCtxtPtr ctxt, const xmlChar **pref, const xmlChar **URI, int *tlen)
 
static void xmlParseEndTag2 (xmlParserCtxtPtr ctxt, const xmlStartTag *tag)
 
void xmlParseCDSect (xmlParserCtxtPtr ctxt)
 
static void xmlParseContentInternal (xmlParserCtxtPtr ctxt)
 
void xmlParseContent (xmlParserCtxtPtr ctxt)
 
void xmlParseElement (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParseVersionNum (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParseVersionInfo (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParseEncName (xmlParserCtxtPtr ctxt)
 
const xmlCharxmlParseEncodingDecl (xmlParserCtxtPtr ctxt)
 
int xmlParseSDDecl (xmlParserCtxtPtr ctxt)
 
void xmlParseXMLDecl (xmlParserCtxtPtr ctxt)
 
void xmlParseMisc (xmlParserCtxtPtr ctxt)
 
int xmlParseDocument (xmlParserCtxtPtr ctxt)
 
int xmlParseExtParsedEnt (xmlParserCtxtPtr ctxt)
 
void xmlStopParser (xmlParserCtxtPtr ctxt)
 
xmlParserCtxtPtr xmlCreateIOParserCtxt (xmlSAXHandlerPtr sax, void *user_data, xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, xmlCharEncoding enc)
 
int xmlParseCtxtExternalEntity (xmlParserCtxtPtr ctx, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *lst)
 
xmlParserErrors xmlParseInNodeContext (xmlNodePtr node, const char *data, int datalen, int options, xmlNodePtr *lst)
 
xmlParserCtxtPtr xmlCreateEntityParserCtxt (const xmlChar *URL, const xmlChar *ID, const xmlChar *base)
 
xmlParserCtxtPtr xmlCreateURLParserCtxt (const char *filename, int options)
 
xmlParserCtxtPtr xmlCreateFileParserCtxt (const char *filename)
 
xmlParserCtxtPtr xmlCreateMemoryParserCtxt (const char *buffer, int size)
 
xmlParserCtxtPtr xmlCreateDocParserCtxt (const xmlChar *cur)
 
void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx, const char *msg,...)
 
void xmlInitParser (void)
 
void xmlCleanupParser (void)
 
void xmlCtxtReset (xmlParserCtxtPtr ctxt)
 
int xmlCtxtResetPush (xmlParserCtxtPtr ctxt, const char *chunk, int size, const char *filename, const char *encoding)
 
int xmlCtxtUseOptions (xmlParserCtxtPtr ctxt, int options)
 
static xmlDocPtr xmlDoRead (xmlParserCtxtPtr ctxt, const char *URL, const char *encoding, int options, int reuse)
 
xmlDocPtr xmlReadDoc (const xmlChar *cur, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlReadFile (const char *filename, const char *encoding, int options)
 
xmlDocPtr xmlReadMemory (const char *buffer, int size, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlReadFd (int fd, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlReadIO (xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlCtxtReadDoc (xmlParserCtxtPtr ctxt, const xmlChar *cur, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlCtxtReadFile (xmlParserCtxtPtr ctxt, const char *filename, const char *encoding, int options)
 
xmlDocPtr xmlCtxtReadMemory (xmlParserCtxtPtr ctxt, const char *buffer, int size, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlCtxtReadFd (xmlParserCtxtPtr ctxt, int fd, const char *URL, const char *encoding, int options)
 
xmlDocPtr xmlCtxtReadIO (xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, const char *URL, const char *encoding, int options)
 

: an XML parser context

xmlSplitQName: @ctxt: an XML parser context

@prefix: a xmlChar **

parse an UTF8 encoded XML qualified name string

[NS 5] QName ::= (Prefix ':')? LocalPart

[NS 6] Prefix ::= NCName

[NS 7] LocalPart ::= NCName

Returns the local part, and prefix is updated to get the Prefix if any.

static const unsigned char test_char_data [256]
 
xmlCharxmlSplitQName (xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix)
 
static int xmlIsNameStartChar (xmlParserCtxtPtr ctxt, int c)
 
static int xmlIsNameChar (xmlParserCtxtPtr ctxt, int c)
 
static xmlCharxmlParseAttValueInternal (xmlParserCtxtPtr ctxt, int *len, int *alloc, int normalize)
 
static const xmlCharxmlParseNameComplex (xmlParserCtxtPtr ctxt)
 
const xmlCharxmlParseName (xmlParserCtxtPtr ctxt)
 
static const xmlCharxmlParseNCNameComplex (xmlParserCtxtPtr ctxt)
 
static const xmlCharxmlParseNCName (xmlParserCtxtPtr ctxt)
 
static const xmlCharxmlParseNameAndCompare (xmlParserCtxtPtr ctxt, xmlChar const *other)
 
static xmlCharxmlParseStringName (xmlParserCtxtPtr ctxt, const xmlChar **str)
 
xmlCharxmlParseNmtoken (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParseEntityValue (xmlParserCtxtPtr ctxt, xmlChar **orig)
 
static xmlCharxmlParseAttValueComplex (xmlParserCtxtPtr ctxt, int *attlen, int normalize)
 
xmlCharxmlParseAttValue (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParseSystemLiteral (xmlParserCtxtPtr ctxt)
 
xmlCharxmlParsePubidLiteral (xmlParserCtxtPtr ctxt)
 
static void xmlParseCharDataComplex (xmlParserCtxtPtr ctxt, int cdata)
 
void xmlParseCharData (xmlParserCtxtPtr ctxt, int cdata)
 
xmlCharxmlParseExternalID (xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict)
 
static void xmlParseCommentComplex (xmlParserCtxtPtr ctxt, xmlChar *buf, size_t len, size_t size)
 
void xmlParseComment (xmlParserCtxtPtr ctxt)
 
const xmlCharxmlParsePITarget (xmlParserCtxtPtr ctxt)
 
void xmlParsePI (xmlParserCtxtPtr ctxt)
 
void xmlParseNotationDecl (xmlParserCtxtPtr ctxt)
 
void xmlParseEntityDecl (xmlParserCtxtPtr ctxt)
 
int xmlParseDefaultDecl (xmlParserCtxtPtr ctxt, xmlChar **value)
 
xmlEnumerationPtr xmlParseNotationType (xmlParserCtxtPtr ctxt)
 
xmlEnumerationPtr xmlParseEnumerationType (xmlParserCtxtPtr ctxt)
 
int xmlParseEnumeratedType (xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree)
 
int xmlParseAttributeType (xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree)
 
void xmlParseAttributeListDecl (xmlParserCtxtPtr ctxt)
 
xmlElementContentPtr xmlParseElementMixedContentDecl (xmlParserCtxtPtr ctxt, int inputchk)
 
static xmlElementContentPtr xmlParseElementChildrenContentDeclPriv (xmlParserCtxtPtr ctxt, int inputchk, int depth)
 
xmlElementContentPtr xmlParseElementChildrenContentDecl (xmlParserCtxtPtr ctxt, int inputchk)
 

Macro Definition Documentation

◆ BASE_PTR

#define BASE_PTR   ctxt->input->base

Definition at line 2068 of file parser.c.

◆ CMP10

#define CMP10 (   s,
  c1,
  c2,
  c3,
  c4,
  c5,
  c6,
  c7,
  c8,
  c9,
  c10 
)
Value:
( CMP9( s, c1, c2, c3, c4, c5, c6, c7, c8, c9 ) && \
((unsigned char *) s)[ 9 ] == c10 )
GLdouble s
Definition: gl.h:2039
#define CMP9(s, c1, c2, c3, c4, c5, c6, c7, c8, c9)
Definition: parser.c:2081

Definition at line 2084 of file parser.c.

◆ CMP4

#define CMP4 (   s,
  c1,
  c2,
  c3,
  c4 
)
Value:
( ((unsigned char *) s)[ 0 ] == c1 && ((unsigned char *) s)[ 1 ] == c2 && \
((unsigned char *) s)[ 2 ] == c3 && ((unsigned char *) s)[ 3 ] == c4 )

Definition at line 2070 of file parser.c.

◆ CMP5

#define CMP5 (   s,
  c1,
  c2,
  c3,
  c4,
  c5 
)     ( CMP4( s, c1, c2, c3, c4 ) && ((unsigned char *) s)[ 4 ] == c5 )

Definition at line 2073 of file parser.c.

◆ CMP6

#define CMP6 (   s,
  c1,
  c2,
  c3,
  c4,
  c5,
  c6 
)     ( CMP5( s, c1, c2, c3, c4, c5 ) && ((unsigned char *) s)[ 5 ] == c6 )

Definition at line 2075 of file parser.c.

◆ CMP7

#define CMP7 (   s,
  c1,
  c2,
  c3,
  c4,
  c5,
  c6,
  c7 
)     ( CMP6( s, c1, c2, c3, c4, c5, c6 ) && ((unsigned char *) s)[ 6 ] == c7 )

Definition at line 2077 of file parser.c.

◆ CMP8

#define CMP8 (   s,
  c1,
  c2,
  c3,
  c4,
  c5,
  c6,
  c7,
  c8 
)     ( CMP7( s, c1, c2, c3, c4, c5, c6, c7 ) && ((unsigned char *) s)[ 7 ] == c8 )

Definition at line 2079 of file parser.c.

◆ CMP9

#define CMP9 (   s,
  c1,
  c2,
  c3,
  c4,
  c5,
  c6,
  c7,
  c8,
  c9 
)
Value:
( CMP8( s, c1, c2, c3, c4, c5, c6, c7, c8 ) && \
((unsigned char *) s)[ 8 ] == c9 )
#define CMP8(s, c1, c2, c3, c4, c5, c6, c7, c8)
Definition: parser.c:2079

Definition at line 2081 of file parser.c.

◆ COPY_BUF

#define COPY_BUF (   l,
  b,
  i,
  v 
)
Value:
if (l == 1) b[i++] = (xmlChar) v; \
else i += xmlCopyCharMultiByte(&b[i],v)
r l[0]
Definition: byte_order.h:168
const GLdouble * v
Definition: gl.h:2040
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
XMLPUBFUN int XMLCALL xmlCopyCharMultiByte(xmlChar *out, int val)
unsigned char xmlChar
Definition: xmlstring.h:28

Definition at line 2166 of file parser.c.

◆ CUR

#define CUR   (*ctxt->input->cur)

Definition at line 2065 of file parser.c.

◆ CUR_CHAR

#define CUR_CHAR (   l)    xmlCurrentChar(ctxt, &l)

Definition at line 2163 of file parser.c.

◆ CUR_CONSUMED

#define CUR_CONSUMED    (ctxt->input->consumed + (ctxt->input->cur - ctxt->input->base))

Definition at line 2170 of file parser.c.

◆ CUR_PTR

#define CUR_PTR   ctxt->input->cur

Definition at line 2067 of file parser.c.

◆ CUR_SCHAR

#define CUR_SCHAR (   s,
  l 
)    xmlStringCurrentChar(ctxt, s, &l)

Definition at line 2164 of file parser.c.

◆ DICT_FREE

#define DICT_FREE (   str)
Value:
if ((str) && ((!dict) || \
(xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
xmlFree((char *)(str));
const WCHAR * str
XMLPUBFUN int XMLCALL xmlDictOwns(xmlDictPtr dict, const xmlChar *str)
Definition: dict.c:1220

DICT_FREE: @str: a string

Free a string if it is not owned by the "dict" dictionary in the current scope

Definition at line 14789 of file parser.c.

◆ GROW

#define GROW
Value:
if ((ctxt->progressive == 0) && \
(ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \
xmlGROW (ctxt);
#define INPUT_CHUNK

Definition at line 2117 of file parser.c.

◆ GROW_PARSE_ATT_VALUE_INTERNAL

#define GROW_PARSE_ATT_VALUE_INTERNAL (   ctxt,
  in,
  start,
  end 
)
Value:
const xmlChar *oldbase = ctxt->input->base;\
GROW;\
if (ctxt->instate == XML_PARSER_EOF)\
return(NULL);\
if (oldbase != ctxt->input->base) {\
ptrdiff_t delta = ctxt->input->base - oldbase;\
start = start + delta;\
in = in + delta;\
}\
end = ctxt->input->end;
#define NULL
Definition: types.h:112
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint in
Definition: glext.h:9616
@ XML_PARSER_EOF
Definition: parser.h:111
#define GROW
Definition: parser.c:2117

xmlParseAttValueInternal: @ctxt: an XML parser context @len: attribute len result @alloc: whether the attribute was reallocated as a new string @normalize: if 1 then further non-CDATA normalization must be done

parse a value for an attribute. NOTE: if no normalization is needed, the routine will return pointers directly from the data buffer.

3.3.3 Attribute-Value Normalization: Before the value of an attribute is passed to the application or checked for validity, the XML processor must normalize it as follows:

  • a character reference is processed by appending the referenced character to the attribute value
  • an entity reference is processed by recursively processing the replacement text of the entity
  • a whitespace character (#x20, #xD, #xA, #x9) is processed by appending #x20 to the normalized value, except that only a single #x20 is appended for a "#xD#xA" sequence that is part of an external parsed entity or the literal entity value of an internal parsed entity
  • other characters are processed by appending them to the normalized value If the declared value is not CDATA, then the XML processor must further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character. All attributes for which no declaration has been read should be treated by a non-validating parser as if declared CDATA.

Returns the AttValue parsed or NULL. The value has to be freed by the caller if it was copied, this can be detected by val[*len] == 0.

Definition at line 8947 of file parser.c.

◆ growBuffer

#define growBuffer (   buffer,
  n 
)
Value:
{ \
xmlChar *tmp; \
size_t new_size = buffer##_size * 2 + n; \
if (new_size < buffer##_size) goto mem_error; \
tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
if (tmp == NULL) goto mem_error; \
buffer = tmp; \
buffer##_size = new_size; \
}
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250

Definition at line 2613 of file parser.c.

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 38 of file parser.c.

◆ NEXT

#define NEXT   xmlNextChar(ctxt)

Definition at line 2147 of file parser.c.

◆ NEXT1

#define NEXT1
Value:
{ \
ctxt->input->col++; \
ctxt->input->cur++; \
if (*ctxt->input->cur == 0) \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
}

Definition at line 2149 of file parser.c.

◆ NEXTL

#define NEXTL (   l)
Value:
do { \
if (*(ctxt->input->cur) == '\n') { \
ctxt->input->line++; ctxt->input->col = 1; \
} else ctxt->input->col++; \
ctxt->input->cur += l; \
} while (0)

Definition at line 2156 of file parser.c.

◆ NXT

#define NXT (   val)    ctxt->input->cur[(val)]

Definition at line 2066 of file parser.c.

◆ RAW

#define RAW   (*ctxt->input->cur)

Definition at line 2064 of file parser.c.

◆ SAX2

#define SAX2   1

Definition at line 274 of file parser.c.

◆ SAX_COMPAT_MODE

#define SAX_COMPAT_MODE   BAD_CAST "SAX compatibility mode document"

Definition at line 277 of file parser.c.

◆ SHRINK

#define SHRINK
Value:
if ((ctxt->progressive == 0) && \
(ctxt->input->cur - ctxt->input->base > 2 * INPUT_CHUNK) && \
(ctxt->input->end - ctxt->input->cur < 2 * INPUT_CHUNK)) \
xmlSHRINK (ctxt);

Definition at line 2106 of file parser.c.

◆ SKIP

#define SKIP (   val)
Value:
do { \
ctxt->input->cur += (val),ctxt->input->col+=(val); \
if (*ctxt->input->cur == 0) \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
} while (0)
GLuint GLfloat * val
Definition: glext.h:7180

Definition at line 2088 of file parser.c.

◆ SKIP_BLANKS

#define SKIP_BLANKS   xmlSkipBlankChars(ctxt)

Definition at line 2145 of file parser.c.

◆ SKIPL

#define SKIPL (   val)
Value:
do { \
int skipl; \
for(skipl=0; skipl<val; skipl++) { \
if (*(ctxt->input->cur) == '\n') { \
ctxt->input->line++; ctxt->input->col = 1; \
} else ctxt->input->col++; \
ctxt->input->cur++; \
} \
if (*ctxt->input->cur == 0) \
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \
} while (0)

Definition at line 2094 of file parser.c.

◆ XML_DIR_SEP

#define XML_DIR_SEP   '/'

Definition at line 44 of file parser.c.

◆ XML_MAX_HUGE_LENGTH

#define XML_MAX_HUGE_LENGTH   1000000000

Definition at line 105 of file parser.c.

◆ XML_PARSER_BIG_BUFFER_SIZE

#define XML_PARSER_BIG_BUFFER_SIZE   300

Definition at line 275 of file parser.c.

◆ XML_PARSER_BIG_ENTITY

#define XML_PARSER_BIG_ENTITY   1000

Definition at line 107 of file parser.c.

◆ XML_PARSER_BUFFER_SIZE

#define XML_PARSER_BUFFER_SIZE   100

Definition at line 276 of file parser.c.

◆ XML_PARSER_CHUNK_SIZE

#define XML_PARSER_CHUNK_SIZE   100

XML_PARSER_CHUNK_SIZE

When calling GROW that's the minimal amount of data the parser expected to have received. It is not a hard limit but an optimization when reading strings like Names It is not strictly needed as long as inputs available characters are followed by 0, which should be provided by the I/O level

Definition at line 288 of file parser.c.

◆ XML_PARSER_LOT_ENTITY

#define XML_PARSER_LOT_ENTITY   5000

Definition at line 108 of file parser.c.

◆ XML_PARSER_NON_LINEAR

#define XML_PARSER_NON_LINEAR   10

Definition at line 116 of file parser.c.

Typedef Documentation

◆ xmlDefAttrs

Definition at line 1121 of file parser.c.

◆ xmlDefAttrsPtr

Definition at line 1122 of file parser.c.

Function Documentation

◆ areBlanks()

static int areBlanks ( xmlParserCtxtPtr  ctxt,
const xmlChar str,
int  len,
int  blank_chars 
)
static

areBlanks: @ctxt: an XML parser context @str: a xmlChar * @len: the size of @str @blank_chars: we know the chars are blanks

Is this a sequence of blank chars that one can ignore ?

Returns 1 if ignorable 0 otherwise.

Definition at line 2864 of file parser.c.

2865 {
2866 int i, ret;
2867 xmlNodePtr lastChild;
2868
2869 /*
2870 * Don't spend time trying to differentiate them, the same callback is
2871 * used !
2872 */
2873 if (ctxt->sax->ignorableWhitespace == ctxt->sax->characters)
2874 return(0);
2875
2876 /*
2877 * Check for xml:space value.
2878 */
2879 if ((ctxt->space == NULL) || (*(ctxt->space) == 1) ||
2880 (*(ctxt->space) == -2))
2881 return(0);
2882
2883 /*
2884 * Check that the string is made of blanks
2885 */
2886 if (blank_chars == 0) {
2887 for (i = 0;i < len;i++)
2888 if (!(IS_BLANK_CH(str[i]))) return(0);
2889 }
2890
2891 /*
2892 * Look if the element is mixed content in the DTD if available
2893 */
2894 if (ctxt->node == NULL) return(0);
2895 if (ctxt->myDoc != NULL) {
2896 ret = xmlIsMixedElement(ctxt->myDoc, ctxt->node->name);
2897 if (ret == 0) return(1);
2898 if (ret == 1) return(0);
2899 }
2900
2901 /*
2902 * Otherwise, heuristic :-\
2903 */
2904 if ((RAW != '<') && (RAW != 0xD)) return(0);
2905 if ((ctxt->node->children == NULL) &&
2906 (RAW == '<') && (NXT(1) == '/')) return(0);
2907
2908 lastChild = xmlGetLastChild(ctxt->node);
2909 if (lastChild == NULL) {
2910 if ((ctxt->node->type != XML_ELEMENT_NODE) &&
2911 (ctxt->node->content != NULL)) return(0);
2912 } else if (xmlNodeIsText(lastChild))
2913 return(0);
2914 else if ((ctxt->node->children != NULL) &&
2915 (xmlNodeIsText(ctxt->node->children)))
2916 return(0);
2917 return(1);
2918}
GLenum GLsizei len
Definition: glext.h:6722
#define IS_BLANK_CH(c)
XMLPUBFUN xmlNodePtr XMLCALL xmlGetLastChild(const xmlNode *parent)
XMLPUBFUN int XMLCALL xmlNodeIsText(const xmlNode *node)
@ XML_ELEMENT_NODE
Definition: tree.h:160
#define RAW
Definition: parser.c:2064
#define NXT(val)
Definition: parser.c:2066
Definition: tree.h:489
xmlChar * content
Definition: tree.h:502
struct _xmlNode * children
Definition: tree.h:493
const xmlChar * name
Definition: tree.h:492
xmlElementType type
Definition: tree.h:491
int * space
Definition: parser.h:244
struct _xmlSAXHandler * sax
Definition: parser.h:185
xmlDocPtr myDoc
Definition: parser.h:187
xmlNodePtr node
Definition: parser.h:205
XMLPUBFUN int XMLCALL xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name)
Definition: valid.c:3494
int ret

Referenced by xmlParseCharData(), and xmlParseCharDataComplex().

◆ inputPop()

xmlParserInputPtr inputPop ( xmlParserCtxtPtr  ctxt)

inputPop: @ctxt: an XML parser context

Pops the top parser input from the input stack

Returns the input just removed

Definition at line 1774 of file parser.c.

1775{
1777
1778 if (ctxt == NULL)
1779 return(NULL);
1780 if (ctxt->inputNr <= 0)
1781 return (NULL);
1782 ctxt->inputNr--;
1783 if (ctxt->inputNr > 0)
1784 ctxt->input = ctxt->inputTab[ctxt->inputNr - 1];
1785 else
1786 ctxt->input = NULL;
1787 ret = ctxt->inputTab[ctxt->inputNr];
1788 ctxt->inputTab[ctxt->inputNr] = NULL;
1789 return (ret);
1790}
xmlParserInputPtr * inputTab
Definition: parser.h:202
xmlParserInputPtr input
Definition: parser.h:199

Referenced by xmlCtxtReset(), xmlFreeParserCtxt(), xmlHaltParser(), xmlInitParserCtxt(), xmlPopInput(), and xmlPushInput().

◆ inputPush()

int inputPush ( xmlParserCtxtPtr  ctxt,
xmlParserInputPtr  value 
)

inputPush: @ctxt: an XML parser context @value: the parser input

Pushes a new parser input on top of the input stack

Returns -1 in case of error, the index in the stack otherwise

Definition at line 1745 of file parser.c.

1746{
1747 if ((ctxt == NULL) || (value == NULL))
1748 return(-1);
1749 if (ctxt->inputNr >= ctxt->inputMax) {
1750 ctxt->inputMax *= 2;
1751 ctxt->inputTab =
1753 ctxt->inputMax *
1754 sizeof(ctxt->inputTab[0]));
1755 if (ctxt->inputTab == NULL) {
1756 xmlErrMemory(ctxt, NULL);
1757 ctxt->inputMax /= 2;
1758 return (-1);
1759 }
1760 }
1761 ctxt->inputTab[ctxt->inputNr] = value;
1762 ctxt->input = value;
1763 return (ctxt->inputNr++);
1764}
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
int inputMax
Definition: parser.h:201
Definition: pdh_main.c:94

Referenced by testSAX(), xmlCreateEntityParserCtxtInternal(), xmlCreateIOParserCtxt(), xmlCreateMemoryParserCtxt(), xmlCreateURLParserCtxt(), xmlCtxtReadFd(), xmlCtxtReadFile(), xmlCtxtReadIO(), xmlCtxtReadMemory(), xmlCtxtResetPush(), xmlPushInput(), xmlReadFd(), xmlReadIO(), and xsltDocDefaultLoaderFunc().

◆ LIBXML_ATTR_FORMAT()

static void LIBXML_ATTR_FORMAT ( ,
 
)
static

xmlFatalErrMsg: @ctxt: an XML parser context @error: the error number @msg: the error message

Handle a fatal parser error, i.e. violating Well-Formedness constraints

xmlWarningMsg: @ctxt: an XML parser context @error: the error number @msg: the error message @str1: extra data @str2: extra data

Handle a warning.

xmlValidityError: @ctxt: an XML parser context @error: the error number @msg: the error message @str1: extra data

Handle a validity error.

xmlFatalErrMsgInt: @ctxt: an XML parser context @error: the error number @msg: the error message @val: an integer value

Handle a fatal parser error, i.e. violating Well-Formedness constraints

xmlFatalErrMsgStrIntStr: @ctxt: an XML parser context @error: the error number @msg: the error message @str1: an string info @val: an integer value @str2: an string info

Handle a fatal parser error, i.e. violating Well-Formedness constraints

xmlFatalErrMsgStr: @ctxt: an XML parser context @error: the error number @msg: the error message @val: a string value

Handle a fatal parser error, i.e. violating Well-Formedness constraints

xmlErrMsgStr: @ctxt: an XML parser context @error: the error number @msg: the error message @val: a string value

Handle a non fatal parser error

xmlNsErr: @ctxt: an XML parser context @error: the error number @msg: the message @info1: extra information string @info2: extra information string

Handle a fatal parser error, i.e. violating Well-Formedness constraints

xmlNsWarn @ctxt: an XML parser context @error: the error number @msg: the message @info1: extra information string @info2: extra information string

Handle a namespace warning error

Definition at line 593 of file parser.c.

596{
597 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
598 (ctxt->instate == XML_PARSER_EOF))
599 return;
600 if (ctxt != NULL)
601 ctxt->errNo = error;
602 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
603 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, "%s", msg);
604 if (ctxt != NULL) {
605 ctxt->wellFormed = 0;
606 if (ctxt->recovery == 0)
607 ctxt->disableSAX = 1;
608 }
609}
#define msg(x)
Definition: auth_time.c:54
#define error(str)
Definition: mkdosfs.c:1605
@ XML_ERR_FATAL
Definition: xmlerror.h:28
@ XML_FROM_PARSER
Definition: xmlerror.h:38

◆ nameNsPush()

static int nameNsPush ( xmlParserCtxtPtr  ctxt,
const xmlChar value,
const xmlChar prefix,
const xmlChar URI,
int  line,
int  nsNr 
)
static

nameNsPush: @ctxt: an XML parser context @value: the element name @prefix: the element prefix @URI: the element namespace name the current line number for error messages @nsNr: the number of namespaces pushed on the namespace table

Pushes a new element name/prefix/URL on top of the name stack

Returns -1 in case of error, the index in the stack otherwise

Definition at line 1870 of file parser.c.

1872{
1874
1875 if (ctxt->nameNr >= ctxt->nameMax) {
1876 const xmlChar * *tmp;
1877 xmlStartTag *tmp2;
1878 ctxt->nameMax *= 2;
1879 tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab,
1880 ctxt->nameMax *
1881 sizeof(ctxt->nameTab[0]));
1882 if (tmp == NULL) {
1883 ctxt->nameMax /= 2;
1884 goto mem_error;
1885 }
1886 ctxt->nameTab = tmp;
1887 tmp2 = (xmlStartTag *) xmlRealloc((void * *)ctxt->pushTab,
1888 ctxt->nameMax *
1889 sizeof(ctxt->pushTab[0]));
1890 if (tmp2 == NULL) {
1891 ctxt->nameMax /= 2;
1892 goto mem_error;
1893 }
1894 ctxt->pushTab = tmp2;
1895 } else if (ctxt->pushTab == NULL) {
1896 ctxt->pushTab = (xmlStartTag *) xmlMalloc(ctxt->nameMax *
1897 sizeof(ctxt->pushTab[0]));
1898 if (ctxt->pushTab == NULL)
1899 goto mem_error;
1900 }
1901 ctxt->nameTab[ctxt->nameNr] = value;
1902 ctxt->name = value;
1903 tag = &ctxt->pushTab[ctxt->nameNr];
1904 tag->prefix = prefix;
1905 tag->URI = URI;
1906 tag->line = line;
1907 tag->nsNr = nsNr;
1908 return (ctxt->nameNr++);
1909mem_error:
1910 xmlErrMemory(ctxt, NULL);
1911 return (-1);
1912}
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248
xmlStartTag * pushTab
Definition: parser.h:283
const xmlChar * name
Definition: parser.h:229
const xmlChar ** nameTab
Definition: parser.h:232
Definition: parser.c:49
Definition: ecma_167.h:138

Referenced by xmlParseElementStart().

◆ namePop()

const xmlChar * namePop ( xmlParserCtxtPtr  ctxt)

namePop: @ctxt: an XML parser context

Pops the top element name from the name stack

Returns the name just removed

Definition at line 1981 of file parser.c.

1982{
1983 const xmlChar *ret;
1984
1985 if ((ctxt == NULL) || (ctxt->nameNr <= 0))
1986 return (NULL);
1987 ctxt->nameNr--;
1988 if (ctxt->nameNr > 0)
1989 ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
1990 else
1991 ctxt->name = NULL;
1992 ret = ctxt->nameTab[ctxt->nameNr];
1993 ctxt->nameTab[ctxt->nameNr] = NULL;
1994 return (ret);
1995}

Referenced by xmlParseElementEnd(), and xmlParseElementStart().

◆ namePush()

int namePush ( xmlParserCtxtPtr  ctxt,
const xmlChar value 
)

namePush: @ctxt: an XML parser context @value: the element name

Pushes a new element name on top of the name stack

Returns -1 in case of error, the index in the stack otherwise

Definition at line 1950 of file parser.c.

1951{
1952 if (ctxt == NULL) return (-1);
1953
1954 if (ctxt->nameNr >= ctxt->nameMax) {
1955 const xmlChar * *tmp;
1956 tmp = (const xmlChar * *) xmlRealloc((xmlChar * *)ctxt->nameTab,
1957 ctxt->nameMax * 2 *
1958 sizeof(ctxt->nameTab[0]));
1959 if (tmp == NULL) {
1960 goto mem_error;
1961 }
1962 ctxt->nameTab = tmp;
1963 ctxt->nameMax *= 2;
1964 }
1965 ctxt->nameTab[ctxt->nameNr] = value;
1966 ctxt->name = value;
1967 return (ctxt->nameNr++);
1968mem_error:
1969 xmlErrMemory(ctxt, NULL);
1970 return (-1);
1971}

◆ nodePop()

xmlNodePtr nodePop ( xmlParserCtxtPtr  ctxt)

nodePop: @ctxt: an XML parser context

Pops the top element node from the node stack

Returns the node just removed

Definition at line 1839 of file parser.c.

1840{
1842
1843 if (ctxt == NULL) return(NULL);
1844 if (ctxt->nodeNr <= 0)
1845 return (NULL);
1846 ctxt->nodeNr--;
1847 if (ctxt->nodeNr > 0)
1848 ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1];
1849 else
1850 ctxt->node = NULL;
1851 ret = ctxt->nodeTab[ctxt->nodeNr];
1852 ctxt->nodeTab[ctxt->nodeNr] = NULL;
1853 return (ret);
1854}
xmlNodePtr * nodeTab
Definition: parser.h:208

Referenced by xmlParseElementStart(), and xmlSAX2EndElementNs().

◆ nodePush()

int nodePush ( xmlParserCtxtPtr  ctxt,
xmlNodePtr  value 
)

nodePush: @ctxt: an XML parser context @value: the element node

Pushes a new element node on top of the node stack

Returns -1 in case of error, the index in the stack otherwise

Definition at line 1801 of file parser.c.

1802{
1803 if (ctxt == NULL) return(0);
1804 if (ctxt->nodeNr >= ctxt->nodeMax) {
1805 xmlNodePtr *tmp;
1806
1807 tmp = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab,
1808 ctxt->nodeMax * 2 *
1809 sizeof(ctxt->nodeTab[0]));
1810 if (tmp == NULL) {
1811 xmlErrMemory(ctxt, NULL);
1812 return (-1);
1813 }
1814 ctxt->nodeTab = tmp;
1815 ctxt->nodeMax *= 2;
1816 }
1817 if ((((unsigned int) ctxt->nodeNr) > xmlParserMaxDepth) &&
1818 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
1819 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
1820 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
1822 xmlHaltParser(ctxt);
1823 return(-1);
1824 }
1825 ctxt->nodeTab[ctxt->nodeNr] = value;
1826 ctxt->node = value;
1827 return (ctxt->nodeNr++);
1828}
@ XML_PARSE_HUGE
Definition: parser.h:1114
unsigned int xmlParserMaxDepth
Definition: parser.c:270
static void xmlHaltParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12549
@ XML_ERR_INTERNAL_ERROR
Definition: xmlerror.h:101

Referenced by xmlParseBalancedChunkMemoryInternal(), xmlParseExternalEntityPrivate(), xmlParseInNodeContext(), and xmlSAX2StartElementNs().

◆ nsPop()

static int nsPop ( xmlParserCtxtPtr  ctxt,
int  nr 
)
static

nsPop: @ctxt: an XML parser context @nr: the number to pop

Pops the top @nr parser prefix/namespace from the ns stack

Returns the number of namespaces removed

Definition at line 1681 of file parser.c.

1682{
1683 int i;
1684
1685 if (ctxt->nsTab == NULL) return(0);
1686 if (ctxt->nsNr < nr) {
1687 xmlGenericError(xmlGenericErrorContext, "Pbm popping %d NS\n", nr);
1688 nr = ctxt->nsNr;
1689 }
1690 if (ctxt->nsNr <= 0)
1691 return (0);
1692
1693 for (i = 0;i < nr;i++) {
1694 ctxt->nsNr--;
1695 ctxt->nsTab[ctxt->nsNr] = NULL;
1696 }
1697 return(nr);
1698}
ULONG nr
Definition: thread.c:7
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
const xmlChar ** nsTab
Definition: parser.h:281

Referenced by xmlParseElementStart(), xmlParseEndTag2(), and xmlParseInNodeContext().

◆ nsPush()

static int nsPush ( xmlParserCtxtPtr  ctxt,
const xmlChar prefix,
const xmlChar URL 
)
static

nsPush: @ctxt: an XML parser context @prefix: the namespace prefix or NULL @URL: the namespace name

Pushes a new parser namespace on top of the ns stack

Returns -1 in case of error, -2 if the namespace should be discarded and the index in the stack otherwise.

Definition at line 1631 of file parser.c.

1632{
1633 if (ctxt->options & XML_PARSE_NSCLEAN) {
1634 int i;
1635 for (i = ctxt->nsNr - 2;i >= 0;i -= 2) {
1636 if (ctxt->nsTab[i] == prefix) {
1637 /* in scope */
1638 if (ctxt->nsTab[i + 1] == URL)
1639 return(-2);
1640 /* out of scope keep it */
1641 break;
1642 }
1643 }
1644 }
1645 if ((ctxt->nsMax == 0) || (ctxt->nsTab == NULL)) {
1646 ctxt->nsMax = 10;
1647 ctxt->nsNr = 0;
1648 ctxt->nsTab = (const xmlChar **)
1649 xmlMalloc(ctxt->nsMax * sizeof(xmlChar *));
1650 if (ctxt->nsTab == NULL) {
1651 xmlErrMemory(ctxt, NULL);
1652 ctxt->nsMax = 0;
1653 return (-1);
1654 }
1655 } else if (ctxt->nsNr >= ctxt->nsMax) {
1656 const xmlChar ** tmp;
1657 ctxt->nsMax *= 2;
1658 tmp = (const xmlChar **) xmlRealloc((char *) ctxt->nsTab,
1659 ctxt->nsMax * sizeof(ctxt->nsTab[0]));
1660 if (tmp == NULL) {
1661 xmlErrMemory(ctxt, NULL);
1662 ctxt->nsMax /= 2;
1663 return (-1);
1664 }
1665 ctxt->nsTab = tmp;
1666 }
1667 ctxt->nsTab[ctxt->nsNr++] = prefix;
1668 ctxt->nsTab[ctxt->nsNr++] = URL;
1669 return (ctxt->nsNr);
1670}
@ XML_PARSE_NSCLEAN
Definition: parser.h:1106

Referenced by xmlParseBalancedChunkMemoryInternal(), xmlParseInNodeContext(), and xmlParseStartTag2().

◆ spacePop()

static int spacePop ( xmlParserCtxtPtr  ctxt)
static

Definition at line 2016 of file parser.c.

2016 {
2017 int ret;
2018 if (ctxt->spaceNr <= 0) return(0);
2019 ctxt->spaceNr--;
2020 if (ctxt->spaceNr > 0)
2021 ctxt->space = &ctxt->spaceTab[ctxt->spaceNr - 1];
2022 else
2023 ctxt->space = &ctxt->spaceTab[0];
2024 ret = ctxt->spaceTab[ctxt->spaceNr];
2025 ctxt->spaceTab[ctxt->spaceNr] = -1;
2026 return(ret);
2027}
int * spaceTab
Definition: parser.h:247

Referenced by xmlParseElementStart(), and xmlParseEndTag2().

◆ spacePush()

static int spacePush ( xmlParserCtxtPtr  ctxt,
int  val 
)
static

Definition at line 1997 of file parser.c.

1997 {
1998 if (ctxt->spaceNr >= ctxt->spaceMax) {
1999 int *tmp;
2000
2001 ctxt->spaceMax *= 2;
2002 tmp = (int *) xmlRealloc(ctxt->spaceTab,
2003 ctxt->spaceMax * sizeof(ctxt->spaceTab[0]));
2004 if (tmp == NULL) {
2005 xmlErrMemory(ctxt, NULL);
2006 ctxt->spaceMax /=2;
2007 return(-1);
2008 }
2009 ctxt->spaceTab = tmp;
2010 }
2011 ctxt->spaceTab[ctxt->spaceNr] = val;
2012 ctxt->space = &ctxt->spaceTab[ctxt->spaceNr];
2013 return(ctxt->spaceNr++);
2014}
int spaceMax
Definition: parser.h:246

Referenced by xmlParseElementStart().

◆ xmlAddDefAttrs()

static void xmlAddDefAttrs ( xmlParserCtxtPtr  ctxt,
const xmlChar fullname,
const xmlChar fullattr,
const xmlChar value 
)
static

xmlAddDefAttrs: @ctxt: an XML parser context @fullname: the element fullname @fullattr: the attribute fullname @value: the attribute value

Add a defaulted attribute for an element

Definition at line 1242 of file parser.c.

1245 {
1247 int len;
1248 const xmlChar *name;
1249 const xmlChar *prefix;
1250
1251 /*
1252 * Allows to detect attribute redefinitions
1253 */
1254 if (ctxt->attsSpecial != NULL) {
1255 if (xmlHashLookup2(ctxt->attsSpecial, fullname, fullattr) != NULL)
1256 return;
1257 }
1258
1259 if (ctxt->attsDefault == NULL) {
1260 ctxt->attsDefault = xmlHashCreateDict(10, ctxt->dict);
1261 if (ctxt->attsDefault == NULL)
1262 goto mem_error;
1263 }
1264
1265 /*
1266 * split the element name into prefix:localname , the string found
1267 * are within the DTD and then not associated to namespace names.
1268 */
1270 if (name == NULL) {
1271 name = xmlDictLookup(ctxt->dict, fullname, -1);
1272 prefix = NULL;
1273 } else {
1274 name = xmlDictLookup(ctxt->dict, name, -1);
1275 prefix = xmlDictLookup(ctxt->dict, fullname, len);
1276 }
1277
1278 /*
1279 * make sure there is some storage
1280 */
1281 defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix);
1282 if (defaults == NULL) {
1284 (4 * 5) * sizeof(const xmlChar *));
1285 if (defaults == NULL)
1286 goto mem_error;
1287 defaults->nbAttrs = 0;
1288 defaults->maxAttrs = 4;
1289 if (xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix,
1290 defaults, NULL) < 0) {
1292 goto mem_error;
1293 }
1294 } else if (defaults->nbAttrs >= defaults->maxAttrs) {
1296
1298 (2 * defaults->maxAttrs * 5) * sizeof(const xmlChar *));
1299 if (temp == NULL)
1300 goto mem_error;
1301 defaults = temp;
1302 defaults->maxAttrs *= 2;
1303 if (xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix,
1304 defaults, NULL) < 0) {
1306 goto mem_error;
1307 }
1308 }
1309
1310 /*
1311 * Split the element name into prefix:localname , the string found
1312 * are within the DTD and hen not associated to namespace names.
1313 */
1314 name = xmlSplitQName3(fullattr, &len);
1315 if (name == NULL) {
1316 name = xmlDictLookup(ctxt->dict, fullattr, -1);
1317 prefix = NULL;
1318 } else {
1319 name = xmlDictLookup(ctxt->dict, name, -1);
1320 prefix = xmlDictLookup(ctxt->dict, fullattr, len);
1321 }
1322
1323 defaults->values[5 * defaults->nbAttrs] = name;
1324 defaults->values[5 * defaults->nbAttrs + 1] = prefix;
1325 /* intern the string and precompute the end */
1326 len = xmlStrlen(value);
1327 value = xmlDictLookup(ctxt->dict, value, len);
1328 defaults->values[5 * defaults->nbAttrs + 2] = value;
1329 defaults->values[5 * defaults->nbAttrs + 3] = value + len;
1330 if (ctxt->external)
1331 defaults->values[5 * defaults->nbAttrs + 4] = BAD_CAST "external";
1332 else
1333 defaults->values[5 * defaults->nbAttrs + 4] = NULL;
1334 defaults->nbAttrs++;
1335
1336 return;
1337
1338mem_error:
1339 xmlErrMemory(ctxt, NULL);
1340 return;
1341}
const char * fullname
Definition: shader.c:1766
static const ASMPROP_RES defaults[ASM_NAME_MAX_PARAMS]
Definition: asmname.c:82
static calc_node_t temp
Definition: rpn_ieee.c:38
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
Definition: dict.c:867
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
XMLPUBFUN int XMLCALL xmlHashUpdateEntry2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, void *userdata, xmlHashDeallocator f)
Definition: hash.c:445
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreateDict(int size, xmlDictPtr dict)
Definition: hash.c:210
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:476
XMLPUBFUN const xmlChar *XMLCALL xmlSplitQName3(const xmlChar *name, int *len)
xmlDefAttrs * xmlDefAttrsPtr
Definition: parser.c:1122
int external
Definition: parser.h:217
xmlDictPtr dict
Definition: parser.h:263
xmlHashTablePtr attsSpecial
Definition: parser.h:285
xmlHashTablePtr attsDefault
Definition: parser.h:284
Definition: name.c:39
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426

Referenced by xmlParseAttributeListDecl().

◆ xmlAddSpecialAttr()

static void xmlAddSpecialAttr ( xmlParserCtxtPtr  ctxt,
const xmlChar fullname,
const xmlChar fullattr,
int  type 
)
static

xmlAddSpecialAttr: @ctxt: an XML parser context @fullname: the element fullname @fullattr: the attribute fullname @type: the attribute type

Register this attribute type

Definition at line 1353 of file parser.c.

1357{
1358 if (ctxt->attsSpecial == NULL) {
1359 ctxt->attsSpecial = xmlHashCreateDict(10, ctxt->dict);
1360 if (ctxt->attsSpecial == NULL)
1361 goto mem_error;
1362 }
1363
1364 if (xmlHashLookup2(ctxt->attsSpecial, fullname, fullattr) != NULL)
1365 return;
1366
1367 xmlHashAddEntry2(ctxt->attsSpecial, fullname, fullattr,
1368 (void *) (ptrdiff_t) type);
1369 return;
1370
1371mem_error:
1372 xmlErrMemory(ctxt, NULL);
1373 return;
1374}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
XMLPUBFUN int XMLCALL xmlHashAddEntry2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, void *userdata)
Definition: hash.c:406

Referenced by xmlParseAttributeListDecl().

◆ xmlAttrNormalizeSpace()

static xmlChar * xmlAttrNormalizeSpace ( const xmlChar src,
xmlChar dst 
)
static

xmlAttrNormalizeSpace: @src: the source string @dst: the target string

Normalize the space in non CDATA attribute values: If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character. Note that the size of dst need to be at least src, and if one doesn't need to preserve dst (and it doesn't come from a dictionary or read-only) then passing src as dst is just fine.

Returns a pointer to the normalized value (dst) or NULL if no conversion is needed.

Definition at line 1152 of file parser.c.

1153{
1154 if ((src == NULL) || (dst == NULL))
1155 return(NULL);
1156
1157 while (*src == 0x20) src++;
1158 while (*src != 0) {
1159 if (*src == 0x20) {
1160 while (*src == 0x20) src++;
1161 if (*src != 0)
1162 *dst++ = 0x20;
1163 } else {
1164 *dst++ = *src++;
1165 }
1166 }
1167 *dst = 0;
1168 if (dst == src)
1169 return(NULL);
1170 return(dst);
1171}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by xmlAttrNormalizeSpace2(), and xmlParseAttributeListDecl().

◆ xmlAttrNormalizeSpace2()

static const xmlChar * xmlAttrNormalizeSpace2 ( xmlParserCtxtPtr  ctxt,
xmlChar src,
int len 
)
static

xmlAttrNormalizeSpace2: @src: the source string

Normalize the space in non CDATA attribute values, a slightly more complex front end to avoid allocation problems when running on attribute values coming from the input.

Returns a pointer to the normalized value (dst) or NULL if no conversion is needed.

Definition at line 1185 of file parser.c.

1186{
1187 int i;
1188 int remove_head = 0;
1189 int need_realloc = 0;
1190 const xmlChar *cur;
1191
1192 if ((ctxt == NULL) || (src == NULL) || (len == NULL))
1193 return(NULL);
1194 i = *len;
1195 if (i <= 0)
1196 return(NULL);
1197
1198 cur = src;
1199 while (*cur == 0x20) {
1200 cur++;
1201 remove_head++;
1202 }
1203 while (*cur != 0) {
1204 if (*cur == 0x20) {
1205 cur++;
1206 if ((*cur == 0x20) || (*cur == 0)) {
1207 need_realloc = 1;
1208 break;
1209 }
1210 } else
1211 cur++;
1212 }
1213 if (need_realloc) {
1214 xmlChar *ret;
1215
1216 ret = xmlStrndup(src + remove_head, i - remove_head + 1);
1217 if (ret == NULL) {
1218 xmlErrMemory(ctxt, NULL);
1219 return(NULL);
1220 }
1222 *len = (int) strlen((const char *)ret);
1223 return(ret);
1224 } else if (remove_head) {
1225 *len -= remove_head;
1226 memmove(src, src + remove_head, 1 + *len);
1227 return(src);
1228 }
1229 return(NULL);
1230}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
FxCollectionEntry * cur
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static xmlChar * xmlAttrNormalizeSpace(const xmlChar *src, xmlChar *dst)
Definition: parser.c:1152
XMLPUBFUN xmlChar *XMLCALL xmlStrndup(const xmlChar *cur, int len)
Definition: xmlstring.c:42

Referenced by xmlParseAttribute2().

◆ xmlCheckLanguageID()

int xmlCheckLanguageID ( const xmlChar lang)

xmlCheckLanguageID: @lang: pointer to the string value

Checks that the value conforms to the LanguageID production:

NOTE: this is somewhat deprecated, those productions were removed from the XML Second edition.

[33] LanguageID ::= Langcode ('-' Subcode)* [34] Langcode ::= ISO639Code | IanaCode | UserCode [35] ISO639Code ::= ([a-z] | [A-Z]) ([a-z] | [A-Z]) [36] IanaCode ::= ('i' | 'I') '-' ([a-z] | [A-Z])+ [37] UserCode ::= ('x' | 'X') '-' ([a-z] | [A-Z])+ [38] Subcode ::= ([a-z] | [A-Z])+

The current REC reference the successors of RFC 1766, currently 5646

http://www.rfc-editor.org/rfc/rfc5646.txt langtag = language ["-" script] ["-" region] *("-" variant) *("-" extension) ["-" privateuse] language = 2*3ALPHA ; shortest ISO 639 code ["-" extlang] ; sometimes followed by ; extended language subtags / 4ALPHA ; or reserved for future use / 5*8ALPHA ; or registered language subtag

extlang = 3ALPHA ; selected ISO 639 codes *2("-" 3ALPHA) ; permanently reserved

script = 4ALPHA ; ISO 15924 code

region = 2ALPHA ; ISO 3166-1 code / 3DIGIT ; UN M.49 code

variant = 5*8alphanum ; registered variants / (DIGIT 3alphanum)

extension = singleton 1*("-" (2*8alphanum))

                                ; Single alphanumerics
                                ; "x" reserved for private use

singleton = DIGIT ; 0 - 9 / x41-57 ; A - W / x59-5A ; Y - Z / x61-77 ; a - w / x79-7A ; y - z

it sounds right to still allow Irregular i-xxx IANA and user codes too The parser below doesn't try to cope with extension or privateuse that could be added but that's not interoperable anyway

Returns 1 if correct 0 otherwise

Definition at line 1474 of file parser.c.

1475{
1476 const xmlChar *cur = lang, *nxt;
1477
1478 if (cur == NULL)
1479 return (0);
1480 if (((cur[0] == 'i') && (cur[1] == '-')) ||
1481 ((cur[0] == 'I') && (cur[1] == '-')) ||
1482 ((cur[0] == 'x') && (cur[1] == '-')) ||
1483 ((cur[0] == 'X') && (cur[1] == '-'))) {
1484 /*
1485 * Still allow IANA code and user code which were coming
1486 * from the previous version of the XML-1.0 specification
1487 * it's deprecated but we should not fail
1488 */
1489 cur += 2;
1490 while (((cur[0] >= 'A') && (cur[0] <= 'Z')) ||
1491 ((cur[0] >= 'a') && (cur[0] <= 'z')))
1492 cur++;
1493 return(cur[0] == 0);
1494 }
1495 nxt = cur;
1496 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1497 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1498 nxt++;
1499 if (nxt - cur >= 4) {
1500 /*
1501 * Reserved
1502 */
1503 if ((nxt - cur > 8) || (nxt[0] != 0))
1504 return(0);
1505 return(1);
1506 }
1507 if (nxt - cur < 2)
1508 return(0);
1509 /* we got an ISO 639 code */
1510 if (nxt[0] == 0)
1511 return(1);
1512 if (nxt[0] != '-')
1513 return(0);
1514
1515 nxt++;
1516 cur = nxt;
1517 /* now we can have extlang or script or region or variant */
1518 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1519 goto region_m49;
1520
1521 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1522 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1523 nxt++;
1524 if (nxt - cur == 4)
1525 goto script;
1526 if (nxt - cur == 2)
1527 goto region;
1528 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1529 goto variant;
1530 if (nxt - cur != 3)
1531 return(0);
1532 /* we parsed an extlang */
1533 if (nxt[0] == 0)
1534 return(1);
1535 if (nxt[0] != '-')
1536 return(0);
1537
1538 nxt++;
1539 cur = nxt;
1540 /* now we can have script or region or variant */
1541 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1542 goto region_m49;
1543
1544 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1545 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1546 nxt++;
1547 if (nxt - cur == 2)
1548 goto region;
1549 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1550 goto variant;
1551 if (nxt - cur != 4)
1552 return(0);
1553 /* we parsed a script */
1554script:
1555 if (nxt[0] == 0)
1556 return(1);
1557 if (nxt[0] != '-')
1558 return(0);
1559
1560 nxt++;
1561 cur = nxt;
1562 /* now we can have region or variant */
1563 if ((nxt[0] >= '0') && (nxt[0] <= '9'))
1564 goto region_m49;
1565
1566 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1567 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1568 nxt++;
1569
1570 if ((nxt - cur >= 5) && (nxt - cur <= 8))
1571 goto variant;
1572 if (nxt - cur != 2)
1573 return(0);
1574 /* we parsed a region */
1575region:
1576 if (nxt[0] == 0)
1577 return(1);
1578 if (nxt[0] != '-')
1579 return(0);
1580
1581 nxt++;
1582 cur = nxt;
1583 /* now we can just have a variant */
1584 while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) ||
1585 ((nxt[0] >= 'a') && (nxt[0] <= 'z')))
1586 nxt++;
1587
1588 if ((nxt - cur < 5) || (nxt - cur > 8))
1589 return(0);
1590
1591 /* we parsed a variant */
1592variant:
1593 if (nxt[0] == 0)
1594 return(1);
1595 if (nxt[0] != '-')
1596 return(0);
1597 /* extensions and private use subtags not checked */
1598 return (1);
1599
1600region_m49:
1601 if (((nxt[1] >= '0') && (nxt[1] <= '9')) &&
1602 ((nxt[2] >= '0') && (nxt[2] <= '9'))) {
1603 nxt += 3;
1604 goto region;
1605 }
1606 return(0);
1607}
script
Definition: msipriv.h:383
static const WCHAR lang[]
Definition: wbemdisp.c:287

Referenced by xmlParseAttribute2().

◆ xmlCleanSpecialAttr()

static void xmlCleanSpecialAttr ( xmlParserCtxtPtr  ctxt)
static

xmlCleanSpecialAttr: @ctxt: an XML parser context

Trim the list of attributes defined to remove all those of type CDATA as they are not special. This call should be done when finishing to parse the DTD and before starting to parse the document root.

Definition at line 1401 of file parser.c.

1402{
1403 if (ctxt->attsSpecial == NULL)
1404 return;
1405
1407
1408 if (xmlHashSize(ctxt->attsSpecial) == 0) {
1410 ctxt->attsSpecial = NULL;
1411 }
1412 return;
1413}
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
Definition: hash.c:322
XMLPUBFUN void XMLCALL xmlHashScanFull(xmlHashTablePtr table, xmlHashScannerFull f, void *data)
Definition: hash.c:875
XMLPUBFUN int XMLCALL xmlHashSize(xmlHashTablePtr table)
Definition: hash.c:1034
static void xmlCleanSpecialAttrCallback(void *payload, void *data, const xmlChar *fullname, const xmlChar *fullattr, const xmlChar *unused ATTRIBUTE_UNUSED)
Definition: parser.c:1382

Referenced by xmlParseDocument().

◆ xmlCleanSpecialAttrCallback()

static void xmlCleanSpecialAttrCallback ( void payload,
void data,
const xmlChar fullname,
const xmlChar fullattr,
const xmlChar *unused  ATTRIBUTE_UNUSED 
)
static

xmlCleanSpecialAttrCallback:

Removes CDATA attributes from the special attribute table

Definition at line 1382 of file parser.c.

1384 {
1386
1387 if (((ptrdiff_t) payload) == XML_ATTRIBUTE_CDATA) {
1388 xmlHashRemoveEntry2(ctxt->attsSpecial, fullname, fullattr, NULL);
1389 }
1390}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
XMLPUBFUN int XMLCALL xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, xmlHashDeallocator f)
Definition: hash.c:1071
@ XML_ATTRIBUTE_CDATA
Definition: tree.h:207
xmlParserCtxt * xmlParserCtxtPtr
Definition: tree.h:39

Referenced by xmlCleanSpecialAttr().

◆ xmlCleanupParser()

void xmlCleanupParser ( void  )

xmlCleanupParser:

This function name is somewhat misleading. It does not clean up parser state, it cleans up memory allocated by the library itself. It is a cleanup function for the XML library. It tries to reclaim all related global memory allocated for the library processing. It doesn't deallocate any document related memory. One should call xmlCleanupParser() only when the process has finished using the library and all XML/HTML documents built with it. See also xmlInitParser() which has the opposite function of preparing the library for operations.

WARNING: if your application is multithreaded or has plugin support calling this may crash the application if another thread or a plugin is still using libxml2. It's sometimes very hard to guess if libxml2 is in use in the application, some libraries or plugins may use it without notice. In case of doubt abstain from calling this function or do it just before calling exit() to avoid leak reports from valgrind !

Definition at line 14739 of file parser.c.

14739 {
14741 return;
14742
14744#ifdef LIBXML_CATALOG_ENABLED
14745 xmlCatalogCleanup();
14746#endif
14749#ifdef LIBXML_OUTPUT_ENABLED
14750 xmlCleanupOutputCallbacks();
14751#endif
14752#ifdef LIBXML_SCHEMAS_ENABLED
14753 xmlSchemaCleanupTypes();
14754 xmlRelaxNGCleanupTypes();
14755#endif
14757 xmlCleanupThreads(); /* must be last if called not from the main thread */
14760}
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlCleanupCharEncodingHandlers(void)
Definition: encoding.c:1483
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlDictCleanup(void)
Definition: dict.c:224
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlCleanupGlobals(void)
Definition: globals.c:535
static int xmlParserInitialized
Definition: parser.c:14665
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlCleanupThreads(void)
Definition: threads.c:900
XMLPUBFUN void XMLCALL xmlCleanupInputCallbacks(void)
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlCleanupMemory(void)
Definition: xmlmemory.c:989

Referenced by DllMain(), main(), and xmlInitParser().

◆ xmlCreateDocParserCtxt()

xmlParserCtxtPtr xmlCreateDocParserCtxt ( const xmlChar cur)

xmlCreateDocParserCtxt: @cur: a pointer to an array of xmlChar

Creates a parser context for an XML in-memory document.

Returns the new parser context or NULL

Definition at line 14542 of file parser.c.

14542 {
14543 int len;
14544
14545 if (cur == NULL)
14546 return(NULL);
14547 len = xmlStrlen(cur);
14548 return(xmlCreateMemoryParserCtxt((const char *)cur, len));
14549}
xmlParserCtxtPtr xmlCreateMemoryParserCtxt(const char *buffer, int size)
Definition: parser.c:14339

Referenced by xmlReadDoc().

◆ xmlCreateEntityParserCtxt()

xmlParserCtxtPtr xmlCreateEntityParserCtxt ( const xmlChar URL,
const xmlChar ID,
const xmlChar base 
)

xmlCreateEntityParserCtxt: @URL: the entity URL @ID: the entity PUBLIC ID @base: a possible base for the target URI

Create a parser context for an external entity Automatic support for ZLIB/Compress compressed document is provided by default if found at compile-time.

Returns the new parser context or NULL

Definition at line 14027 of file parser.c.

14028 {
14030
14031}
#define ID
Definition: ruserpass.c:36
static xmlParserCtxtPtr xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID, const xmlChar *base, xmlParserCtxtPtr pctx)
Definition: parser.c:13954

◆ xmlCreateEntityParserCtxtInternal()

static xmlParserCtxtPtr xmlCreateEntityParserCtxtInternal ( const xmlChar URL,
const xmlChar ID,
const xmlChar base,
xmlParserCtxtPtr  pctx 
)
static

xmlCreateEntityParserCtxtInternal: @URL: the entity URL @ID: the entity PUBLIC ID @base: a possible base for the target URI @pctx: parser context used to set options on new context

Create a parser context for an external entity Automatic support for ZLIB/Compress compressed document is provided by default if found at compile-time.

Returns the new parser context or NULL

Definition at line 13954 of file parser.c.

13955 {
13956 xmlParserCtxtPtr ctxt;
13957 xmlParserInputPtr inputStream;
13958 char *directory = NULL;
13959 xmlChar *uri;
13960
13961 ctxt = xmlNewParserCtxt();
13962 if (ctxt == NULL) {
13963 return(NULL);
13964 }
13965
13966 if (pctx != NULL) {
13967 ctxt->options = pctx->options;
13968 ctxt->_private = pctx->_private;
13969 /*
13970 * this is a subparser of pctx, so the input_id should be
13971 * incremented to distinguish from main entity
13972 */
13973 ctxt->input_id = pctx->input_id + 1;
13974 }
13975
13976 /* Don't read from stdin. */
13977 if (xmlStrcmp(URL, BAD_CAST "-") == 0)
13978 URL = BAD_CAST "./-";
13979
13980 uri = xmlBuildURI(URL, base);
13981
13982 if (uri == NULL) {
13983 inputStream = xmlLoadExternalEntity((char *)URL, (char *)ID, ctxt);
13984 if (inputStream == NULL) {
13985 xmlFreeParserCtxt(ctxt);
13986 return(NULL);
13987 }
13988
13989 inputPush(ctxt, inputStream);
13990
13991 if ((ctxt->directory == NULL) && (directory == NULL))
13992 directory = xmlParserGetDirectory((char *)URL);
13993 if ((ctxt->directory == NULL) && (directory != NULL))
13994 ctxt->directory = directory;
13995 } else {
13996 inputStream = xmlLoadExternalEntity((char *)uri, (char *)ID, ctxt);
13997 if (inputStream == NULL) {
13998 xmlFree(uri);
13999 xmlFreeParserCtxt(ctxt);
14000 return(NULL);
14001 }
14002
14003 inputPush(ctxt, inputStream);
14004
14005 if ((ctxt->directory == NULL) && (directory == NULL))
14007 if ((ctxt->directory == NULL) && (directory != NULL))
14008 ctxt->directory = directory;
14009 xmlFree(uri);
14010 }
14011 return(ctxt);
14012}
const char * uri
Definition: sec_mgr.c:1588
XMLPUBFUN void XMLCALL xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
XMLPUBFUN xmlParserInputPtr XMLCALL xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
XMLPUBFUN xmlParserCtxtPtr XMLCALL xmlNewParserCtxt(void)
int inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
Definition: parser.c:1745
char * directory
Definition: parser.h:226
void * _private
Definition: parser.h:256
int input_id
Definition: parser.h:312
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1892
XMLPUBFUN char *XMLCALL xmlParserGetDirectory(const char *filename)
XMLPUBFUN int XMLCALL xmlStrcmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:133

Referenced by xmlCreateEntityParserCtxt(), and xmlParseExternalEntityPrivate().

◆ xmlCreateFileParserCtxt()

xmlParserCtxtPtr xmlCreateFileParserCtxt ( const char filename)

xmlCreateFileParserCtxt: @filename: the filename

Create a parser context for a file content. Automatic support for ZLIB/Compress compressed document is provided by default if found at compile-time.

Returns the new parser context or NULL

Definition at line 14093 of file parser.c.

14094{
14095 return(xmlCreateURLParserCtxt(filename, 0));
14096}
const char * filename
Definition: ioapi.h:137
xmlParserCtxtPtr xmlCreateURLParserCtxt(const char *filename, int options)
Definition: parser.c:14051

◆ xmlCreateIOParserCtxt()

xmlParserCtxtPtr xmlCreateIOParserCtxt ( xmlSAXHandlerPtr  sax,
void user_data,
xmlInputReadCallback  ioread,
xmlInputCloseCallback  ioclose,
void ioctx,
xmlCharEncoding  enc 
)

xmlCreateIOParserCtxt: @sax: a SAX handler @user_data: The user data returned on SAX callbacks @ioread: an I/O read function @ioclose: an I/O close function @ioctx: an I/O handler @enc: the charset encoding if known

Create a parser context for using the XML parser with an existing I/O stream

Returns the new parser context or NULL

Definition at line 12605 of file parser.c.

12607 {
12608 xmlParserCtxtPtr ctxt;
12609 xmlParserInputPtr inputStream;
12611
12612 if (ioread == NULL) return(NULL);
12613
12614 buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
12615 if (buf == NULL) {
12616 if (ioclose != NULL)
12617 ioclose(ioctx);
12618 return (NULL);
12619 }
12620
12621 ctxt = xmlNewParserCtxt();
12622 if (ctxt == NULL) {
12624 return(NULL);
12625 }
12626 if (sax != NULL) {
12627#ifdef LIBXML_SAX1_ENABLED
12629#endif /* LIBXML_SAX1_ENABLED */
12630 xmlFree(ctxt->sax);
12631 ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
12632 if (ctxt->sax == NULL) {
12634 xmlErrMemory(ctxt, NULL);
12635 xmlFreeParserCtxt(ctxt);
12636 return(NULL);
12637 }
12638 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
12639 if (sax->initialized == XML_SAX2_MAGIC)
12640 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
12641 else
12642 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
12643 if (user_data != NULL)
12644 ctxt->userData = user_data;
12645 }
12646
12647 inputStream = xmlNewIOInputStream(ctxt, buf, enc);
12648 if (inputStream == NULL) {
12649 xmlFreeParserCtxt(ctxt);
12650 return(NULL);
12651 }
12652 inputPush(ctxt, inputStream);
12653
12654 return(ctxt);
12655}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler
Definition: globals.h:312
XMLPUBFUN xmlParserInputPtr XMLCALL xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input, xmlCharEncoding enc)
#define XML_SAX2_MAGIC
Definition: parser.h:671
xmlSAXHandler * xmlSAXHandlerPtr
Definition: tree.h:45
#define memset(x, y, z)
Definition: compat.h:39
void * userData
Definition: parser.h:186
XMLPUBFUN void XMLCALL xmlFreeParserInputBuffer(xmlParserInputBufferPtr in)
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, xmlCharEncoding enc)
static int sax
Definition: xmllint.c:193

◆ xmlCreateMemoryParserCtxt()

xmlParserCtxtPtr xmlCreateMemoryParserCtxt ( const char buffer,
int  size 
)

xmlCreateMemoryParserCtxt: @buffer: a pointer to a char array @size: the size of the array

Create a parser context for an XML in-memory document.

Returns the new parser context or NULL

Definition at line 14339 of file parser.c.

14339 {
14340 xmlParserCtxtPtr ctxt;
14343
14344 if (buffer == NULL)
14345 return(NULL);
14346 if (size <= 0)
14347 return(NULL);
14348
14349 ctxt = xmlNewParserCtxt();
14350 if (ctxt == NULL)
14351 return(NULL);
14352
14353 /* TODO: xmlParserInputBufferCreateStatic, requires some serious changes */
14355 if (buf == NULL) {
14356 xmlFreeParserCtxt(ctxt);
14357 return(NULL);
14358 }
14359
14360 input = xmlNewInputStream(ctxt);
14361 if (input == NULL) {
14363 xmlFreeParserCtxt(ctxt);
14364 return(NULL);
14365 }
14366
14367 input->filename = NULL;
14368 input->buf = buf;
14369 xmlBufResetInput(input->buf->buffer, input);
14370
14371 inputPush(ctxt, input);
14372 return(ctxt);
14373}
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1094
@ XML_CHAR_ENCODING_NONE
Definition: encoding.h:58
GLsizeiptr size
Definition: glext.h:5919
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBFUN xmlParserInputPtr XMLCALL xmlNewInputStream(xmlParserCtxtPtr ctxt)
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc)

Referenced by xmlCreateDocParserCtxt(), xmlParseBalancedChunkMemoryInternal(), xmlParseInNodeContext(), and xmlReadMemory().

◆ xmlCreateURLParserCtxt()

xmlParserCtxtPtr xmlCreateURLParserCtxt ( const char filename,
int  options 
)

xmlCreateURLParserCtxt: @filename: the filename or URL @options: a combination of xmlParserOption

Create a parser context for a file or URL content. Automatic support for ZLIB/Compress compressed document is provided by default if found at compile-time and for file accesses

Returns the new parser context or NULL

Definition at line 14051 of file parser.c.

14052{
14053 xmlParserCtxtPtr ctxt;
14054 xmlParserInputPtr inputStream;
14055 char *directory = NULL;
14056
14057 ctxt = xmlNewParserCtxt();
14058 if (ctxt == NULL) {
14059 xmlErrMemory(NULL, "cannot allocate parser context");
14060 return(NULL);
14061 }
14062
14063 if (options)
14065 ctxt->linenumbers = 1;
14066
14067 inputStream = xmlLoadExternalEntity(filename, NULL, ctxt);
14068 if (inputStream == NULL) {
14069 xmlFreeParserCtxt(ctxt);
14070 return(NULL);
14071 }
14072
14073 inputPush(ctxt, inputStream);
14074 if ((ctxt->directory == NULL) && (directory == NULL))
14076 if ((ctxt->directory == NULL) && (directory != NULL))
14077 ctxt->directory = directory;
14078
14079 return(ctxt);
14080}
static int xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int options, const char *encoding)
Definition: parser.c:15000
int linenumbers
Definition: parser.h:259

Referenced by xmlCreateFileParserCtxt(), and xmlReadFile().

◆ xmlCtxtGrowAttrs()

static int xmlCtxtGrowAttrs ( xmlParserCtxtPtr  ctxt,
int  nr 
)
static

Definition at line 1702 of file parser.c.

1702 {
1703 const xmlChar **atts;
1704 int *attallocs;
1705 int maxatts;
1706
1707 if (ctxt->atts == NULL) {
1708 maxatts = 55; /* allow for 10 attrs by default */
1709 atts = (const xmlChar **)
1710 xmlMalloc(maxatts * sizeof(xmlChar *));
1711 if (atts == NULL) goto mem_error;
1712 ctxt->atts = atts;
1713 attallocs = (int *) xmlMalloc((maxatts / 5) * sizeof(int));
1714 if (attallocs == NULL) goto mem_error;
1715 ctxt->attallocs = attallocs;
1716 ctxt->maxatts = maxatts;
1717 } else if (nr + 5 > ctxt->maxatts) {
1718 maxatts = (nr + 5) * 2;
1719 atts = (const xmlChar **) xmlRealloc((void *) ctxt->atts,
1720 maxatts * sizeof(const xmlChar *));
1721 if (atts == NULL) goto mem_error;
1722 ctxt->atts = atts;
1723 attallocs = (int *) xmlRealloc((void *) ctxt->attallocs,
1724 (maxatts / 5) * sizeof(int));
1725 if (attallocs == NULL) goto mem_error;
1726 ctxt->attallocs = attallocs;
1727 ctxt->maxatts = maxatts;
1728 }
1729 return(ctxt->maxatts);
1730mem_error:
1731 xmlErrMemory(ctxt, NULL);
1732 return(-1);
1733}
_In_ uint16_t _Out_ ULONG * atts
Definition: btrfs_drv.h:1107
const xmlChar ** atts
Definition: parser.h:264
int * attallocs
Definition: parser.h:282

Referenced by xmlParseStartTag2().

◆ xmlCtxtReadDoc()

xmlDocPtr xmlCtxtReadDoc ( xmlParserCtxtPtr  ctxt,
const xmlChar cur,
const char URL,
const char encoding,
int  options 
)

xmlCtxtReadDoc: @ctxt: an XML parser context @cur: a pointer to a zero terminated string @URL: the base URL to use for the document @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML in-memory document and build a tree. This reuses the existing @ctxt parser context

Returns the resulting document tree

Definition at line 15368 of file parser.c.

15370{
15371 if (cur == NULL)
15372 return (NULL);
15373 return (xmlCtxtReadMemory(ctxt, (const char *) cur, xmlStrlen(cur), URL,
15374 encoding, options));
15375}
xmlDocPtr xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size, const char *URL, const char *encoding, int options)
Definition: parser.c:15426
static char * encoding
Definition: xmllint.c:155

◆ xmlCtxtReadFd()

xmlDocPtr xmlCtxtReadFd ( xmlParserCtxtPtr  ctxt,
int  fd,
const char URL,
const char encoding,
int  options 
)

xmlCtxtReadFd: @ctxt: an XML parser context @fd: an open file descriptor @URL: the base URL to use for the document @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML from a file descriptor and build a tree. This reuses the existing @ctxt parser context NOTE that the file descriptor will not be closed when the reader is closed or reset.

Returns the resulting document tree

Definition at line 15471 of file parser.c.

15473{
15476
15477 if (fd < 0)
15478 return (NULL);
15479 if (ctxt == NULL)
15480 return (NULL);
15481 xmlInitParser();
15482
15483 xmlCtxtReset(ctxt);
15484
15485
15487 if (input == NULL)
15488 return (NULL);
15489 input->closecallback = NULL;
15491 if (stream == NULL) {
15493 return (NULL);
15494 }
15495 inputPush(ctxt, stream);
15496 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15497}
void xmlInitParser(void)
Definition: parser.c:14676
static xmlDocPtr xmlDoRead(xmlParserCtxtPtr ctxt, const char *URL, const char *encoding, int options, int reuse)
Definition: parser.c:15159
void xmlCtxtReset(xmlParserCtxtPtr ctxt)
Definition: parser.c:14801
static int fd
Definition: io.c:51
Definition: parse.h:23
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc)

◆ xmlCtxtReadFile()

xmlDocPtr xmlCtxtReadFile ( xmlParserCtxtPtr  ctxt,
const char filename,
const char encoding,
int  options 
)

xmlCtxtReadFile: @ctxt: an XML parser context @filename: a file or URL @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML file from the filesystem or the network. This reuses the existing @ctxt parser context

Returns the resulting document tree

Definition at line 15390 of file parser.c.

15392{
15394
15395 if (filename == NULL)
15396 return (NULL);
15397 if (ctxt == NULL)
15398 return (NULL);
15399 xmlInitParser();
15400
15401 xmlCtxtReset(ctxt);
15402
15404 if (stream == NULL) {
15405 return (NULL);
15406 }
15407 inputPush(ctxt, stream);
15408 return (xmlDoRead(ctxt, NULL, encoding, options, 1));
15409}

Referenced by parseAndPrintFile().

◆ xmlCtxtReadIO()

xmlDocPtr xmlCtxtReadIO ( xmlParserCtxtPtr  ctxt,
xmlInputReadCallback  ioread,
xmlInputCloseCallback  ioclose,
void ioctx,
const char URL,
const char encoding,
int  options 
)

xmlCtxtReadIO: @ctxt: an XML parser context @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 @options: a combination of xmlParserOption

parse an XML document from I/O functions and source and build a tree. This reuses the existing @ctxt parser context

Returns the resulting document tree

Definition at line 15515 of file parser.c.

15519{
15522
15523 if (ioread == NULL)
15524 return (NULL);
15525 if (ctxt == NULL)
15526 return (NULL);
15527 xmlInitParser();
15528
15529 xmlCtxtReset(ctxt);
15530
15531 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
15533 if (input == NULL) {
15534 if (ioclose != NULL)
15535 ioclose(ioctx);
15536 return (NULL);
15537 }
15539 if (stream == NULL) {
15541 return (NULL);
15542 }
15543 inputPush(ctxt, stream);
15544 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15545}

Referenced by parseAndPrintFile().

◆ xmlCtxtReadMemory()

xmlDocPtr xmlCtxtReadMemory ( xmlParserCtxtPtr  ctxt,
const char buffer,
int  size,
const char URL,
const char encoding,
int  options 
)

xmlCtxtReadMemory: @ctxt: an XML parser context @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 @options: a combination of xmlParserOption

parse an XML in-memory document and build a tree. This reuses the existing @ctxt parser context

Returns the resulting document tree

Definition at line 15426 of file parser.c.

15428{
15431
15432 if (ctxt == NULL)
15433 return (NULL);
15434 if (buffer == NULL)
15435 return (NULL);
15436 xmlInitParser();
15437
15438 xmlCtxtReset(ctxt);
15439
15441 if (input == NULL) {
15442 return(NULL);
15443 }
15444
15446 if (stream == NULL) {
15448 return(NULL);
15449 }
15450
15451 inputPush(ctxt, stream);
15452 return (xmlDoRead(ctxt, URL, encoding, options, 1));
15453}

Referenced by parseAndPrintFile(), and xmlCtxtReadDoc().

◆ xmlCtxtReset()

void xmlCtxtReset ( xmlParserCtxtPtr  ctxt)

xmlCtxtReset: @ctxt: an XML parser context

Reset a parser context

Definition at line 14801 of file parser.c.

14802{
14804 xmlDictPtr dict;
14805
14806 if (ctxt == NULL)
14807 return;
14808
14809 dict = ctxt->dict;
14810
14811 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
14813 }
14814 ctxt->inputNr = 0;
14815 ctxt->input = NULL;
14816
14817 ctxt->spaceNr = 0;
14818 if (ctxt->spaceTab != NULL) {
14819 ctxt->spaceTab[0] = -1;
14820 ctxt->space = &ctxt->spaceTab[0];
14821 } else {
14822 ctxt->space = NULL;
14823 }
14824
14825
14826 ctxt->nodeNr = 0;
14827 ctxt->node = NULL;
14828
14829 ctxt->nameNr = 0;
14830 ctxt->name = NULL;
14831
14832 ctxt->nsNr = 0;
14833
14834 DICT_FREE(ctxt->version);
14835 ctxt->version = NULL;
14836 DICT_FREE(ctxt->encoding);
14837 ctxt->encoding = NULL;
14838 DICT_FREE(ctxt->directory);
14839 ctxt->directory = NULL;
14840 DICT_FREE(ctxt->extSubURI);
14841 ctxt->extSubURI = NULL;
14842 DICT_FREE(ctxt->extSubSystem);
14843 ctxt->extSubSystem = NULL;
14844 if (ctxt->myDoc != NULL)
14845 xmlFreeDoc(ctxt->myDoc);
14846 ctxt->myDoc = NULL;
14847
14848 ctxt->standalone = -1;
14849 ctxt->hasExternalSubset = 0;
14850 ctxt->hasPErefs = 0;
14851 ctxt->html = 0;
14852 ctxt->external = 0;
14853 ctxt->instate = XML_PARSER_START;
14854 ctxt->token = 0;
14855
14856 ctxt->wellFormed = 1;
14857 ctxt->nsWellFormed = 1;
14858 ctxt->disableSAX = 0;
14859 ctxt->valid = 1;
14860#if 0
14861 ctxt->vctxt.userData = ctxt;
14862 ctxt->vctxt.error = xmlParserValidityError;
14863 ctxt->vctxt.warning = xmlParserValidityWarning;
14864#endif
14865 ctxt->record_info = 0;
14866 ctxt->checkIndex = 0;
14867 ctxt->inSubset = 0;
14868 ctxt->errNo = XML_ERR_OK;
14869 ctxt->depth = 0;
14871 ctxt->catalogs = NULL;
14872 ctxt->nbentities = 0;
14873 ctxt->sizeentities = 0;
14874 ctxt->sizeentcopy = 0;
14876
14877 if (ctxt->attsDefault != NULL) {
14879 ctxt->attsDefault = NULL;
14880 }
14881 if (ctxt->attsSpecial != NULL) {
14883 ctxt->attsSpecial = NULL;
14884 }
14885
14886#ifdef LIBXML_CATALOG_ENABLED
14887 if (ctxt->catalogs != NULL)
14888 xmlCatalogFreeLocal(ctxt->catalogs);
14889#endif
14890 if (ctxt->lastError.code != XML_ERR_OK)
14891 xmlResetError(&ctxt->lastError);
14892}
@ XML_CHAR_ENCODING_UTF8
Definition: encoding.h:59
XMLPUBFUN void XMLCALL xmlFreeInputStream(xmlParserInputPtr input)
XMLPUBFUN void XMLCALL xmlHashDefaultDeallocator(void *entry, const xmlChar *name)
@ XML_PARSER_START
Definition: parser.h:112
XMLPUBFUN void XMLCALL xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
#define DICT_FREE(str)
Definition: parser.c:14789
xmlParserInputPtr inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1774
Definition: dict.c:111
int code
Definition: xmlerror.h:80
xmlError lastError
Definition: parser.h:301
int nsWellFormed
Definition: parser.h:286
int hasPErefs
Definition: parser.h:216
xmlValidCtxt vctxt
Definition: parser.h:221
int wellFormed
Definition: parser.h:188
int disableSAX
Definition: parser.h:237
xmlChar * extSubSystem
Definition: parser.h:241
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211
int hasExternalSubset
Definition: parser.h:215
long checkIndex
Definition: parser.h:235
xmlParserInputState instate
Definition: parser.h:223
const xmlChar * encoding
Definition: parser.h:191
void * catalogs
Definition: parser.h:260
xmlChar * extSubURI
Definition: parser.h:240
unsigned long sizeentities
Definition: parser.h:304
const xmlChar * version
Definition: parser.h:190
int record_info
Definition: parser.h:210
int inSubset
Definition: parser.h:238
int standalone
Definition: parser.h:192
unsigned long sizeentcopy
Definition: parser.h:313
unsigned long nbentities
Definition: parser.h:303
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityWarning(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityError(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
XMLPUBFUN void XMLCALL xmlResetError(xmlErrorPtr err)
@ XML_ERR_OK
Definition: xmlerror.h:100

Referenced by xmlClearParserCtxt(), xmlCtxtReadFd(), xmlCtxtReadFile(), xmlCtxtReadIO(), xmlCtxtReadMemory(), and xmlCtxtResetPush().

◆ xmlCtxtResetPush()

int xmlCtxtResetPush ( xmlParserCtxtPtr  ctxt,
const char chunk,
int  size,
const char filename,
const char encoding 
)

xmlCtxtResetPush: @ctxt: an XML parser context @chunk: a pointer to an array of chars @size: number of chars in the array @filename: an optional file name or URI @encoding: the document encoding, or NULL

Reset a push parser context

Returns 0 in case of success and 1 in case of error

Definition at line 14907 of file parser.c.

14909{
14910 xmlParserInputPtr inputStream;
14913
14914 if (ctxt == NULL)
14915 return(1);
14916
14917 if ((encoding == NULL) && (chunk != NULL) && (size >= 4))
14918 enc = xmlDetectCharEncoding((const xmlChar *) chunk, size);
14919
14921 if (buf == NULL)
14922 return(1);
14923
14924 if (ctxt == NULL) {
14926 return(1);
14927 }
14928
14929 xmlCtxtReset(ctxt);
14930
14931 if (filename == NULL) {
14932 ctxt->directory = NULL;
14933 } else {
14935 }
14936
14937 inputStream = xmlNewInputStream(ctxt);
14938 if (inputStream == NULL) {
14940 return(1);
14941 }
14942
14943 if (filename == NULL)
14944 inputStream->filename = NULL;
14945 else
14946 inputStream->filename = (char *)
14947 xmlCanonicPath((const xmlChar *) filename);
14948 inputStream->buf = buf;
14949 xmlBufResetInput(buf->buffer, inputStream);
14950
14951 inputPush(ctxt, inputStream);
14952
14953 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
14954 (ctxt->input->buf != NULL)) {
14955 size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
14956 size_t cur = ctxt->input->cur - ctxt->input->base;
14957
14959
14961#ifdef DEBUG_PUSH
14962 xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
14963#endif
14964 }
14965
14966 if (encoding != NULL) {
14968
14969 if (ctxt->encoding != NULL)
14970 xmlFree((xmlChar *) ctxt->encoding);
14971 ctxt->encoding = xmlStrdup((const xmlChar *) encoding);
14972
14974 if (hdlr != NULL) {
14975 xmlSwitchToEncoding(ctxt, hdlr);
14976 } else {
14977 xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
14978 "Unsupported encoding %s\n", BAD_CAST encoding);
14979 }
14980 } else if (enc != XML_CHAR_ENCODING_NONE) {
14981 xmlSwitchEncoding(ctxt, enc);
14982 }
14983
14984 return(0);
14985}
size_t xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1113
int xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, size_t base, size_t cur)
Definition: buf.c:1144
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL xmlFindCharEncodingHandler(const char *name)
Definition: encoding.c:1678
xmlCharEncoding
Definition: encoding.h:56
XMLPUBFUN xmlCharEncoding XMLCALL xmlDetectCharEncoding(const unsigned char *in, int len)
Definition: encoding.c:952
XMLPUBFUN int XMLCALL xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
XMLPUBFUN int XMLCALL xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
xmlBufPtr buffer
Definition: xmlIO.h:132
const char * filename
Definition: parser.h:56
const xmlChar * base
Definition: parser.h:58
xmlParserInputBufferPtr buf
Definition: parser.h:54
const xmlChar * cur
Definition: parser.h:59
XMLPUBFUN xmlChar *XMLCALL xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2380
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlAllocParserInputBuffer(xmlCharEncoding enc)
XMLPUBFUN int XMLCALL xmlParserInputBufferPush(xmlParserInputBufferPtr in, int len, const char *buf)
@ XML_ERR_UNSUPPORTED_ENCODING
Definition: xmlerror.h:132
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67

◆ xmlCtxtUseOptions()

int xmlCtxtUseOptions ( xmlParserCtxtPtr  ctxt,
int  options 
)

xmlCtxtUseOptions: @ctxt: an XML parser context @options: a combination of xmlParserOption

Applies the options to the parser context

Returns 0 in case of success, the set of unknown or unimplemented options in case of error.

Definition at line 15141 of file parser.c.

15142{
15143 return(xmlCtxtUseOptionsInternal(ctxt, options, NULL));
15144}

Referenced by parseAndPrintFile(), and xsltDocDefaultLoaderFunc().

◆ xmlCtxtUseOptionsInternal()

static int xmlCtxtUseOptionsInternal ( xmlParserCtxtPtr  ctxt,
int  options,
const char encoding 
)
static

xmlCtxtUseOptionsInternal: @ctxt: an XML parser context @options: a combination of xmlParserOption @encoding: the user provided encoding to use

Applies the options to the parser context

Returns 0 in case of success, the set of unknown or unimplemented options in case of error.

Definition at line 15000 of file parser.c.

15001{
15002 if (ctxt == NULL)
15003 return(-1);
15004 if (encoding != NULL) {
15005 if (ctxt->encoding != NULL)
15006 xmlFree((xmlChar *) ctxt->encoding);
15007 ctxt->encoding = xmlStrdup((const xmlChar *) encoding);
15008 }
15009 if (options & XML_PARSE_RECOVER) {
15010 ctxt->recovery = 1;
15012 ctxt->options |= XML_PARSE_RECOVER;
15013 } else
15014 ctxt->recovery = 0;
15015 if (options & XML_PARSE_DTDLOAD) {
15016 ctxt->loadsubset = XML_DETECT_IDS;
15018 ctxt->options |= XML_PARSE_DTDLOAD;
15019 } else
15020 ctxt->loadsubset = 0;
15021 if (options & XML_PARSE_DTDATTR) {
15024 ctxt->options |= XML_PARSE_DTDATTR;
15025 }
15026 if (options & XML_PARSE_NOENT) {
15027 ctxt->replaceEntities = 1;
15028 /* ctxt->loadsubset |= XML_DETECT_IDS; */
15030 ctxt->options |= XML_PARSE_NOENT;
15031 } else
15032 ctxt->replaceEntities = 0;
15034 ctxt->pedantic = 1;
15036 ctxt->options |= XML_PARSE_PEDANTIC;
15037 } else
15038 ctxt->pedantic = 0;
15040 ctxt->keepBlanks = 0;
15041 ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
15043 ctxt->options |= XML_PARSE_NOBLANKS;
15044 } else
15045 ctxt->keepBlanks = 1;
15047 ctxt->validate = 1;
15049 ctxt->vctxt.warning = NULL;
15051 ctxt->vctxt.error = NULL;
15053 ctxt->options |= XML_PARSE_DTDVALID;
15054 } else
15055 ctxt->validate = 0;
15057 ctxt->sax->warning = NULL;
15059 }
15060 if (options & XML_PARSE_NOERROR) {
15061 ctxt->sax->error = NULL;
15062 ctxt->sax->fatalError = NULL;
15064 }
15065#ifdef LIBXML_SAX1_ENABLED
15066 if (options & XML_PARSE_SAX1) {
15067 ctxt->sax->startElement = xmlSAX2StartElement;
15068 ctxt->sax->endElement = xmlSAX2EndElement;
15069 ctxt->sax->startElementNs = NULL;
15070 ctxt->sax->endElementNs = NULL;
15071 ctxt->sax->initialized = 1;
15073 ctxt->options |= XML_PARSE_SAX1;
15074 }
15075#endif /* LIBXML_SAX1_ENABLED */
15076 if (options & XML_PARSE_NODICT) {
15077 ctxt->dictNames = 0;
15079 ctxt->options |= XML_PARSE_NODICT;
15080 } else {
15081 ctxt->dictNames = 1;
15082 }
15083 if (options & XML_PARSE_NOCDATA) {
15084 ctxt->sax->cdataBlock = NULL;
15086 ctxt->options |= XML_PARSE_NOCDATA;
15087 }
15088 if (options & XML_PARSE_NSCLEAN) {
15089 ctxt->options |= XML_PARSE_NSCLEAN;
15091 }
15092 if (options & XML_PARSE_NONET) {
15093 ctxt->options |= XML_PARSE_NONET;
15095 }
15096 if (options & XML_PARSE_COMPACT) {
15097 ctxt->options |= XML_PARSE_COMPACT;
15099 }
15100 if (options & XML_PARSE_OLD10) {
15101 ctxt->options |= XML_PARSE_OLD10;
15103 }
15107 }
15108 if (options & XML_PARSE_HUGE) {
15109 ctxt->options |= XML_PARSE_HUGE;
15111 if (ctxt->dict != NULL)
15112 xmlDictSetLimit(ctxt->dict, 0);
15113 }
15114 if (options & XML_PARSE_OLDSAX) {
15115 ctxt->options |= XML_PARSE_OLDSAX;
15117 }
15121 }
15125 }
15126 ctxt->linenumbers = 1;
15127 return (options);
15128}
XMLPUBFUN void XMLCALL xmlSAX2IgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
XMLPUBFUN size_t XMLCALL xmlDictSetLimit(xmlDictPtr dict, size_t limit)
Definition: dict.c:1265
#define XML_DETECT_IDS
Definition: parser.h:137
#define XML_COMPLETE_ATTRS
Definition: parser.h:146
@ XML_PARSE_SAX1
Definition: parser.h:1102
@ XML_PARSE_DTDVALID
Definition: parser.h:1097
@ XML_PARSE_NOWARNING
Definition: parser.h:1099
@ XML_PARSE_NOCDATA
Definition: parser.h:1107
@ XML_PARSE_COMPACT
Definition: parser.h:1109
@ XML_PARSE_NONET
Definition: parser.h:1104
@ XML_PARSE_NOBLANKS
Definition: parser.h:1101
@ XML_PARSE_IGNORE_ENC
Definition: parser.h:1116
@ XML_PARSE_NOBASEFIX
Definition: parser.h:1113
@ XML_PARSE_DTDLOAD
Definition: parser.h:1095
@ XML_PARSE_RECOVER
Definition: parser.h:1093
@ XML_PARSE_NODICT
Definition: parser.h:1105
@ XML_PARSE_BIG_LINES
Definition: parser.h:1117
@ XML_PARSE_DTDATTR
Definition: parser.h:1096
@ XML_PARSE_OLD10
Definition: parser.h:1112
@ XML_PARSE_OLDSAX
Definition: parser.h:1115
@ XML_PARSE_NOERROR
Definition: parser.h:1098
@ XML_PARSE_NOENT
Definition: parser.h:1094
@ XML_PARSE_PEDANTIC
Definition: parser.h:1100
int replaceEntities
Definition: parser.h:189
int keepBlanks
Definition: parser.h:236
int loadsubset
Definition: parser.h:258
int dictNames
Definition: parser.h:292
int pedantic
Definition: parser.h:255
int recovery
Definition: parser.h:261
int validate
Definition: parser.h:220

Referenced by xmlCreateURLParserCtxt(), xmlCtxtUseOptions(), xmlDoRead(), and xmlParseInNodeContext().

◆ xmlDetectSAX2()

static void xmlDetectSAX2 ( xmlParserCtxtPtr  ctxt)
static

xmlDetectSAX2: @ctxt: an XML parser context

Do the SAX2 detection and specific initialization

Definition at line 1094 of file parser.c.

1094 {
1096
1097 /* Avoid unused variable warning if features are disabled. */
1098 (void) sax;
1099
1100 if (ctxt == NULL) return;
1101 sax = ctxt->sax;
1102#ifdef LIBXML_SAX1_ENABLED
1103 if ((sax) && (sax->initialized == XML_SAX2_MAGIC) &&
1104 ((sax->startElementNs != NULL) ||
1105 (sax->endElementNs != NULL) ||
1106 ((sax->startElement == NULL) && (sax->endElement == NULL))))
1107 ctxt->sax2 = 1;
1108#else
1109 ctxt->sax2 = 1;
1110#endif /* LIBXML_SAX1_ENABLED */
1111
1112 ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
1113 ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
1114 ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
1115 if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||
1116 (ctxt->str_xml_ns == NULL)) {
1117 xmlErrMemory(ctxt, NULL);
1118 }
1119}
#define XML_XML_NAMESPACE
Definition: tree.h:140
const xmlChar * str_xml
Definition: parser.h:271
const xmlChar * str_xml_ns
Definition: parser.h:273
const xmlChar * str_xmlns
Definition: parser.h:272

Referenced by xmlParseBalancedChunkMemoryInternal(), xmlParseDocument(), xmlParseExternalEntityPrivate(), xmlParseExternalSubset(), xmlParseExtParsedEnt(), and xmlParseInNodeContext().

◆ xmlDoRead()

static xmlDocPtr xmlDoRead ( xmlParserCtxtPtr  ctxt,
const char URL,
const char encoding,
int  options,
int  reuse 
)
static

xmlDoRead: @ctxt: an XML parser context @URL: the base URL to use for the document @encoding: the document encoding, or NULL @options: a combination of xmlParserOption @reuse: keep the context for reuse

Common front-end for the xmlRead functions

Returns the resulting document tree or NULL

Definition at line 15159 of file parser.c.

15161{
15162 xmlDocPtr ret;
15163
15165 if (encoding != NULL) {
15167
15169 if (hdlr != NULL)
15170 xmlSwitchToEncoding(ctxt, hdlr);
15171 }
15172 if ((URL != NULL) && (ctxt->input != NULL) &&
15173 (ctxt->input->filename == NULL))
15174 ctxt->input->filename = (char *) xmlStrdup((const xmlChar *) URL);
15175 xmlParseDocument(ctxt);
15176 if ((ctxt->wellFormed) || ctxt->recovery)
15177 ret = ctxt->myDoc;
15178 else {
15179 ret = NULL;
15180 if (ctxt->myDoc != NULL) {
15181 xmlFreeDoc(ctxt->myDoc);
15182 }
15183 }
15184 ctxt->myDoc = NULL;
15185 if (!reuse) {
15186 xmlFreeParserCtxt(ctxt);
15187 }
15188
15189 return (ret);
15190}
int xmlParseDocument(xmlParserCtxtPtr ctxt)
Definition: parser.c:10697
Definition: tree.h:551

Referenced by xmlCtxtReadFd(), xmlCtxtReadFile(), xmlCtxtReadIO(), xmlCtxtReadMemory(), xmlReadDoc(), xmlReadFd(), xmlReadFile(), xmlReadIO(), and xmlReadMemory().

◆ xmlErrAttributeDup()

static void xmlErrAttributeDup ( xmlParserCtxtPtr  ctxt,
const xmlChar prefix,
const xmlChar localname 
)
static

xmlErrAttributeDup: @ctxt: an XML parser context @prefix: the attribute prefix @localname: the attribute localname

Handle a redefinition of attribute error

Definition at line 342 of file parser.c.

344{
345 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
346 (ctxt->instate == XML_PARSER_EOF))
347 return;
348 if (ctxt != NULL)
350
351 if (prefix == NULL)
352 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
354 (const char *) localname, NULL, NULL, 0, 0,
355 "Attribute %s redefined\n", localname);
356 else
357 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
359 (const char *) prefix, (const char *) localname,
360 NULL, 0, 0, "Attribute %s:%s redefined\n", prefix,
361 localname);
362 if (ctxt != NULL) {
363 ctxt->wellFormed = 0;
364 if (ctxt->recovery == 0)
365 ctxt->disableSAX = 1;
366 }
367}
@ XML_ERR_ATTRIBUTE_REDEFINED
Definition: xmlerror.h:142

Referenced by xmlParseStartTag2().

◆ xmlFatalErr()

static void xmlFatalErr ( xmlParserCtxtPtr  ctxt,
xmlParserErrors  error,
const char info 
)
static

xmlFatalErr: @ctxt: an XML parser context @error: the error number @extra: extra information string

Handle a fatal parser error, i.e. violating Well-Formedness constraints

Definition at line 378 of file parser.c.

379{
380 const char *errmsg;
381
382 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
383 (ctxt->instate == XML_PARSER_EOF))
384 return;
385 switch (error) {
387 errmsg = "CharRef: invalid hexadecimal value";
388 break;
390 errmsg = "CharRef: invalid decimal value";
391 break;
393 errmsg = "CharRef: invalid value";
394 break;
396 errmsg = "internal error";
397 break;
399 errmsg = "PEReference at end of document";
400 break;
402 errmsg = "PEReference in prolog";
403 break;
405 errmsg = "PEReference in epilog";
406 break;
408 errmsg = "PEReference: no name";
409 break;
411 errmsg = "PEReference: expecting ';'";
412 break;
414 errmsg = "Detected an entity reference loop";
415 break;
417 errmsg = "EntityValue: \" or ' expected";
418 break;
420 errmsg = "PEReferences forbidden in internal subset";
421 break;
423 errmsg = "EntityValue: \" or ' expected";
424 break;
426 errmsg = "AttValue: \" or ' expected";
427 break;
429 errmsg = "Unescaped '<' not allowed in attributes values";
430 break;
432 errmsg = "SystemLiteral \" or ' expected";
433 break;
435 errmsg = "Unfinished System or Public ID \" or ' expected";
436 break;
438 errmsg = "Sequence ']]>' not allowed in content";
439 break;
441 errmsg = "SYSTEM or PUBLIC, the URI is missing";
442 break;
444 errmsg = "PUBLIC, the Public Identifier is missing";
445 break;
447 errmsg = "Comment must not contain '--' (double-hyphen)";
448 break;
450 errmsg = "xmlParsePI : no target name";
451 break;
453 errmsg = "Invalid PI name";
454 break;
456 errmsg = "NOTATION: Name expected here";
457 break;
459 errmsg = "'>' required to close NOTATION declaration";
460 break;
462 errmsg = "Entity value required";
463 break;
465 errmsg = "Fragment not allowed";
466 break;
468 errmsg = "'(' required to start ATTLIST enumeration";
469 break;
471 errmsg = "NmToken expected in ATTLIST enumeration";
472 break;
474 errmsg = "')' required to finish ATTLIST enumeration";
475 break;
477 errmsg = "MixedContentDecl : '|' or ')*' expected";
478 break;
480 errmsg = "MixedContentDecl : '#PCDATA' expected";
481 break;
483 errmsg = "ContentDecl : Name or '(' expected";
484 break;
486 errmsg = "ContentDecl : ',' '|' or ')' expected";
487 break;
489 errmsg =
490 "PEReference: forbidden within markup decl in internal subset";
491 break;
493 errmsg = "expected '>'";
494 break;
496 errmsg = "XML conditional section '[' expected";
497 break;
499 errmsg = "Content error in the external subset";
500 break;
502 errmsg =
503 "conditional section INCLUDE or IGNORE keyword expected";
504 break;
506 errmsg = "XML conditional section not closed";
507 break;
509 errmsg = "Text declaration '<?xml' required";
510 break;
512 errmsg = "parsing XML declaration: '?>' expected";
513 break;
515 errmsg = "external parsed entities cannot be standalone";
516 break;
518 errmsg = "EntityRef: expecting ';'";
519 break;
521 errmsg = "DOCTYPE improperly terminated";
522 break;
524 errmsg = "EndTag: '</' not found";
525 break;
527 errmsg = "expected '='";
528 break;
530 errmsg = "String not closed expecting \" or '";
531 break;
533 errmsg = "String not started expecting ' or \"";
534 break;
536 errmsg = "Invalid XML encoding name";
537 break;
539 errmsg = "standalone accepts only 'yes' or 'no'";
540 break;
542 errmsg = "Document is empty";
543 break;
545 errmsg = "Extra content at the end of the document";
546 break;
548 errmsg = "chunk is not well balanced";
549 break;
551 errmsg = "extra content at the end of well balanced chunk";
552 break;
554 errmsg = "Malformed declaration expecting version";
555 break;
557 errmsg = "Name too long";
558 break;
559#if 0
560 case:
561 errmsg = "";
562 break;
563#endif
564 default:
565 errmsg = "Unregistered error message";
566 }
567 if (ctxt != NULL)
568 ctxt->errNo = error;
569 if (info == NULL) {
570 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
571 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s\n",
572 errmsg);
573 } else {
574 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
575 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s: %s\n",
576 errmsg, info);
577 }
578 if (ctxt != NULL) {
579 ctxt->wellFormed = 0;
580 if (ctxt->recovery == 0)
581 ctxt->disableSAX = 1;
582 }
583}
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
@ XML_ERR_PEREF_NO_NAME
Definition: xmlerror.h:124
@ XML_ERR_NOT_WELL_BALANCED
Definition: xmlerror.h:185
@ XML_ERR_ENCODING_NAME
Definition: xmlerror.h:179
@ XML_ERR_ENTITY_NOT_FINISHED
Definition: xmlerror.h:137
@ XML_ERR_ENTITYREF_SEMICOL_MISSING
Definition: xmlerror.h:123
@ XML_ERR_PEREF_IN_PROLOG
Definition: xmlerror.h:119
@ XML_ERR_LT_IN_ATTRIBUTE
Definition: xmlerror.h:138
@ XML_ERR_ENTITY_PE_INTERNAL
Definition: xmlerror.h:188
@ XML_ERR_ATTLIST_NOT_STARTED
Definition: xmlerror.h:150
@ XML_ERR_LITERAL_NOT_FINISHED
Definition: xmlerror.h:144
@ XML_ERR_XMLDECL_NOT_FINISHED
Definition: xmlerror.h:157
@ XML_ERR_DOCUMENT_END
Definition: xmlerror.h:105
@ XML_ERR_ELEMCONTENT_NOT_STARTED
Definition: xmlerror.h:154
@ XML_ERR_LTSLASH_REQUIRED
Definition: xmlerror.h:174
@ XML_ERR_PI_NOT_STARTED
Definition: xmlerror.h:146
@ XML_ERR_MIXED_NOT_STARTED
Definition: xmlerror.h:152
@ XML_ERR_PEREF_IN_EPILOG
Definition: xmlerror.h:120
@ XML_ERR_DOCTYPE_NOT_FINISHED
Definition: xmlerror.h:161
@ XML_ERR_CONDSEC_INVALID
Definition: xmlerror.h:183
@ XML_ERR_ENTITY_LOOP
Definition: xmlerror.h:189
@ XML_ERR_EXT_ENTITY_STANDALONE
Definition: xmlerror.h:182
@ XML_ERR_RESERVED_XML_NAME
Definition: xmlerror.h:164
@ XML_ERR_HYPHEN_IN_COMMENT
Definition: xmlerror.h:180
@ XML_ERR_MISPLACED_CDATA_END
Definition: xmlerror.h:162
@ XML_ERR_CONDSEC_INVALID_KEYWORD
Definition: xmlerror.h:195
@ XML_ERR_URI_FRAGMENT
Definition: xmlerror.h:192
@ XML_ERR_VALUE_REQUIRED
Definition: xmlerror.h:184
@ XML_ERR_PEREF_AT_EOF
Definition: xmlerror.h:118
@ XML_ERR_INVALID_CHARREF
Definition: xmlerror.h:108
@ XML_ERR_NMTOKEN_REQUIRED
Definition: xmlerror.h:167
@ XML_ERR_PEREF_IN_INT_SUBSET
Definition: xmlerror.h:121
@ XML_ERR_GT_REQUIRED
Definition: xmlerror.h:173
@ XML_ERR_ELEMCONTENT_NOT_FINISHED
Definition: xmlerror.h:155
@ XML_ERR_PCDATA_REQUIRED
Definition: xmlerror.h:169
@ XML_ERR_NOTATION_NOT_STARTED
Definition: xmlerror.h:148
@ XML_ERR_STRING_NOT_CLOSED
Definition: xmlerror.h:134
@ XML_ERR_ATTRIBUTE_NOT_STARTED
Definition: xmlerror.h:139
@ XML_ERR_CONDSEC_NOT_FINISHED
Definition: xmlerror.h:159
@ XML_ERR_DOCUMENT_EMPTY
Definition: xmlerror.h:104
@ XML_ERR_INVALID_DEC_CHARREF
Definition: xmlerror.h:107
@ XML_ERR_LITERAL_NOT_STARTED
Definition: xmlerror.h:143
@ XML_ERR_PUBID_REQUIRED
Definition: xmlerror.h:171
@ XML_ERR_URI_REQUIRED
Definition: xmlerror.h:170
@ XML_ERR_STRING_NOT_STARTED
Definition: xmlerror.h:133
@ XML_ERR_INVALID_HEX_CHARREF
Definition: xmlerror.h:106
@ XML_ERR_VERSION_MISSING
Definition: xmlerror.h:196
@ XML_ERR_EXT_SUBSET_NOT_FINISHED
Definition: xmlerror.h:160
@ XML_ERR_STANDALONE_VALUE
Definition: xmlerror.h:178
@ XML_ERR_EQUAL_REQUIRED
Definition: xmlerror.h:175
@ XML_ERR_ATTLIST_NOT_FINISHED
Definition: xmlerror.h:151
@ XML_ERR_XMLDECL_NOT_STARTED
Definition: xmlerror.h:156
@ XML_ERR_PEREF_SEMICOL_MISSING
Definition: xmlerror.h:125
@ XML_ERR_EXTRA_CONTENT
Definition: xmlerror.h:186
@ XML_ERR_NOTATION_NOT_FINISHED
Definition: xmlerror.h:149
@ XML_ERR_NAME_TOO_LONG
Definition: xmlerror.h:210
@ XML_ERR_ENTITY_NOT_STARTED
Definition: xmlerror.h:136

Referenced by xmlGROW(), xmlLoadEntityContent(), xmlParseAttValueComplex(), xmlParseAttValueInternal(), xmlParseBalancedChunkMemoryInternal(), xmlParseCDSect(), xmlParseCharData(), xmlParseCharDataComplex(), xmlParseCharRef(), xmlParseCommentComplex(), xmlParseConditionalSections(), xmlParseContentInternal(), xmlParseDocTypeDecl(), xmlParseDocument(), xmlParseElementChildrenContentDeclPriv(), xmlParseElementDecl(), xmlParseElementMixedContentDecl(), xmlParseEncName(), xmlParseEncodingDecl(), xmlParseEndTag2(), xmlParseEntityDecl(), xmlParseEntityRef(), xmlParseEntityValue(), xmlParseEnumerationType(), xmlParseExternalEntityPrivate(), xmlParseExternalID(), xmlParseExternalSubset(), xmlParseExtParsedEnt(), xmlParseInNodeContext(), xmlParseInternalSubset(), xmlParseName(), xmlParseNameComplex(), xmlParseNCName(), xmlParseNCNameComplex(), xmlParseNmtoken(), xmlParseNotationDecl(), xmlParseNotationType(), xmlParsePEReference(), xmlParsePI(), xmlParsePITarget(), xmlParsePubidLiteral(), xmlParseReference(), xmlParserEntityCheck(), xmlParserHandlePEReference(), xmlParseSDDecl(), xmlParseStartTag2(), xmlParseStringCharRef(), xmlParseStringEntityRef(), xmlParseStringName(), xmlParseStringPEReference(), xmlParseSystemLiteral(), xmlParseTextDecl(), xmlParseVersionInfo(), xmlParseXMLDecl(), xmlPopInput(), xmlPushInput(), and xmlStringLenDecodeEntities().

◆ xmlGenericErrorDefaultFunc()

void XMLCDECL xmlGenericErrorDefaultFunc ( void ctx,
const char msg,
  ... 
)

Referenced by xmlInitParser().

◆ xmlGetNamespace()

static const xmlChar * xmlGetNamespace ( xmlParserCtxtPtr  ctxt,
const xmlChar prefix 
)
static

Definition at line 8760 of file parser.c.

8760 {
8761 int i;
8762
8763 if (prefix == ctxt->str_xml) return(ctxt->str_xml_ns);
8764 for (i = ctxt->nsNr - 2;i >= 0;i-=2)
8765 if (ctxt->nsTab[i] == prefix) {
8766 if ((prefix == NULL) && (*ctxt->nsTab[i + 1] == 0))
8767 return(NULL);
8768 return(ctxt->nsTab[i + 1]);
8769 }
8770 return(NULL);
8771}

Referenced by xmlParseInNodeContext(), and xmlParseStartTag2().

◆ xmlGROW()

static void xmlGROW ( xmlParserCtxtPtr  ctxt)
static

Definition at line 2121 of file parser.c.

2121 {
2122 ptrdiff_t curEnd = ctxt->input->end - ctxt->input->cur;
2123 ptrdiff_t curBase = ctxt->input->cur - ctxt->input->base;
2124
2125 if (((curEnd > XML_MAX_LOOKUP_LIMIT) ||
2126 (curBase > XML_MAX_LOOKUP_LIMIT)) &&
2127 ((ctxt->input->buf) &&
2129 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
2130 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
2131 xmlHaltParser(ctxt);
2132 return;
2133 }
2135 if ((ctxt->input->cur > ctxt->input->end) ||
2136 (ctxt->input->cur < ctxt->input->base)) {
2137 xmlHaltParser(ctxt);
2138 xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound");
2139 return;
2140 }
2141 if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0))
2143}
int xmlInputReadCallbackNop(void *context, char *buffer, int len)
#define XML_MAX_LOOKUP_LIMIT
XMLPUBFUN int XMLCALL xmlParserInputGrow(xmlParserInputPtr in, int len)
static void xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
Definition: parser.c:378
xmlInputReadCallback readcallback
Definition: xmlIO.h:127
const xmlChar * end
Definition: parser.h:60

◆ xmlHaltParser()

static void xmlHaltParser ( xmlParserCtxtPtr  ctxt)
static

xmlHaltParser: @ctxt: an XML parser context

Blocks further parser processing don't override error for internal use

Definition at line 12549 of file parser.c.

12549 {
12550 if (ctxt == NULL)
12551 return;
12552 ctxt->instate = XML_PARSER_EOF;
12553 ctxt->disableSAX = 1;
12554 while (ctxt->inputNr > 1)
12556 if (ctxt->input != NULL) {
12557 /*
12558 * in case there was a specific allocation deallocate before
12559 * overriding base
12560 */
12561 if (ctxt->input->free != NULL) {
12562 ctxt->input->free((xmlChar *) ctxt->input->base);
12563 ctxt->input->free = NULL;
12564 }
12565 if (ctxt->input->buf != NULL) {
12567 ctxt->input->buf = NULL;
12568 }
12569 ctxt->input->cur = BAD_CAST"";
12570 ctxt->input->length = 0;
12571 ctxt->input->base = ctxt->input->cur;
12572 ctxt->input->end = ctxt->input->cur;
12573 }
12574}
xmlParserInputDeallocate free
Definition: parser.h:70

Referenced by nodePush(), xmlGROW(), xmlParseConditionalSections(), xmlParseContentInternal(), xmlParseElementStart(), xmlParseEntityDecl(), xmlParseExternalSubset(), xmlParseReference(), and xmlStopParser().

◆ xmlHasFeature()

int xmlHasFeature ( xmlFeature  feature)

xmlHasFeature: @feature: the feature to be examined

Examines if the library has been compiled with a given feature.

Returns a non-zero value if the feature exist, otherwise zero. Returns zero (0) if the feature does not exist or an unknown unknown feature is requested, non-zero otherwise.

Definition at line 874 of file parser.c.

875{
876 switch (feature) {
877 case XML_WITH_THREAD:
878#ifdef LIBXML_THREAD_ENABLED
879 return(1);
880#else
881 return(0);
882#endif
883 case XML_WITH_TREE:
884#ifdef LIBXML_TREE_ENABLED
885 return(1);
886#else
887 return(0);
888#endif
889 case XML_WITH_OUTPUT:
890#ifdef LIBXML_OUTPUT_ENABLED
891 return(1);
892#else
893 return(0);
894#endif
895 case XML_WITH_PUSH:
896#ifdef LIBXML_PUSH_ENABLED
897 return(1);
898#else
899 return(0);
900#endif
901 case XML_WITH_READER:
902#ifdef LIBXML_READER_ENABLED
903 return(1);
904#else
905 return(0);
906#endif
907 case XML_WITH_PATTERN:
908#ifdef LIBXML_PATTERN_ENABLED
909 return(1);
910#else
911 return(0);
912#endif
913 case XML_WITH_WRITER:
914#ifdef LIBXML_WRITER_ENABLED
915 return(1);
916#else
917 return(0);
918#endif
919 case XML_WITH_SAX1:
920#ifdef LIBXML_SAX1_ENABLED
921 return(1);
922#else
923 return(0);
924#endif
925 case XML_WITH_FTP:
926#ifdef LIBXML_FTP_ENABLED
927 return(1);
928#else
929 return(0);
930#endif
931 case XML_WITH_HTTP:
932#ifdef LIBXML_HTTP_ENABLED
933 return(1);
934#else
935 return(0);
936#endif
937 case XML_WITH_VALID:
938#ifdef LIBXML_VALID_ENABLED
939 return(1);
940#else
941 return(0);
942#endif
943 case XML_WITH_HTML:
944#ifdef LIBXML_HTML_ENABLED
945 return(1);
946#else
947 return(0);
948#endif
949 case XML_WITH_LEGACY:
950#ifdef LIBXML_LEGACY_ENABLED
951 return(1);
952#else
953 return(0);
954#endif
955 case XML_WITH_C14N:
956#ifdef LIBXML_C14N_ENABLED
957 return(1);
958#else
959 return(0);
960#endif
961 case XML_WITH_CATALOG:
962#ifdef LIBXML_CATALOG_ENABLED
963 return(1);
964#else
965 return(0);
966#endif
967 case XML_WITH_XPATH:
968#ifdef LIBXML_XPATH_ENABLED
969 return(1);
970#else
971 return(0);
972#endif
973 case XML_WITH_XPTR:
974#ifdef LIBXML_XPTR_ENABLED
975 return(1);
976#else
977 return(0);
978#endif
980#ifdef LIBXML_XINCLUDE_ENABLED
981 return(1);
982#else
983 return(0);
984#endif
985 case XML_WITH_ICONV:
986#ifdef LIBXML_ICONV_ENABLED
987 return(1);
988#else
989 return(0);
990#endif
992#ifdef LIBXML_ISO8859X_ENABLED
993 return(1);
994#else
995 return(0);
996#endif
997 case XML_WITH_UNICODE:
998#ifdef LIBXML_UNICODE_ENABLED
999 return(1);
1000#else
1001 return(0);
1002#endif
1003 case XML_WITH_REGEXP:
1004#ifdef LIBXML_REGEXP_ENABLED
1005 return(1);
1006#else
1007 return(0);
1008#endif
1009 case XML_WITH_AUTOMATA:
1010#ifdef LIBXML_AUTOMATA_ENABLED
1011 return(1);
1012#else
1013 return(0);
1014#endif
1015 case XML_WITH_EXPR:
1016#ifdef LIBXML_EXPR_ENABLED
1017 return(1);
1018#else
1019 return(0);
1020#endif
1021 case XML_WITH_SCHEMAS:
1022#ifdef LIBXML_SCHEMAS_ENABLED
1023 return(1);
1024#else
1025 return(0);
1026#endif
1028#ifdef LIBXML_SCHEMATRON_ENABLED
1029 return(1);
1030#else
1031 return(0);
1032#endif
1033 case XML_WITH_MODULES:
1034#ifdef LIBXML_MODULES_ENABLED
1035 return(1);
1036#else
1037 return(0);
1038#endif
1039 case XML_WITH_DEBUG:
1040#ifdef LIBXML_DEBUG_ENABLED
1041 return(1);
1042#else
1043 return(0);
1044#endif
1045 case XML_WITH_DEBUG_MEM:
1046#ifdef DEBUG_MEMORY_LOCATION
1047 return(1);
1048#else
1049 return(0);
1050#endif
1051 case XML_WITH_DEBUG_RUN:
1052#ifdef LIBXML_DEBUG_RUNTIME
1053 return(1);
1054#else
1055 return(0);
1056#endif
1057 case XML_WITH_ZLIB:
1058#ifdef LIBXML_ZLIB_ENABLED
1059 return(1);
1060#else
1061 return(0);
1062#endif
1063 case XML_WITH_LZMA:
1064#ifdef LIBXML_LZMA_ENABLED
1065 return(1);
1066#else
1067 return(0);
1068#endif
1069 case XML_WITH_ICU:
1070#ifdef LIBXML_ICU_ENABLED
1071 return(1);
1072#else
1073 return(0);
1074#endif
1075 default:
1076 break;
1077 }
1078 return(0);
1079}
INTERNETFEATURELIST feature
Definition: misc.c:1719
@ XML_WITH_DEBUG
Definition: parser.h:1229
@ XML_WITH_LEGACY
Definition: parser.h:1214
@ XML_WITH_CATALOG
Definition: parser.h:1216
@ XML_WITH_XPATH
Definition: parser.h:1217
@ XML_WITH_TREE
Definition: parser.h:1203
@ XML_WITH_DEBUG_MEM
Definition: parser.h:1230
@ XML_WITH_DEBUG_RUN
Definition: parser.h:1231
@ XML_WITH_XPTR
Definition: parser.h:1218
@ XML_WITH_OUTPUT
Definition: parser.h:1204
@ XML_WITH_EXPR
Definition: parser.h:1225
@ XML_WITH_VALID
Definition: parser.h:1212
@ XML_WITH_THREAD
Definition: parser.h:1202
@ XML_WITH_SCHEMAS
Definition: parser.h:1226
@ XML_WITH_C14N
Definition: parser.h:1215
@ XML_WITH_MODULES
Definition: parser.h:1228
@ XML_WITH_UNICODE
Definition: parser.h:1222
@ XML_WITH_REGEXP
Definition: parser.h:1223
@ XML_WITH_HTML
Definition: parser.h:1213
@ XML_WITH_LZMA
Definition: parser.h:1234
@ XML_WITH_AUTOMATA
Definition: parser.h:1224
@ XML_WITH_ISO8859X
Definition: parser.h:1221
@ XML_WITH_PUSH
Definition: parser.h:1205
@ XML_WITH_ICONV
Definition: parser.h:1220
@ XML_WITH_ZLIB
Definition: parser.h:1232
@ XML_WITH_SAX1
Definition: parser.h:1209
@ XML_WITH_PATTERN
Definition: parser.h:1207
@ XML_WITH_WRITER
Definition: parser.h:1208
@ XML_WITH_FTP
Definition: parser.h:1210
@ XML_WITH_HTTP
Definition: parser.h:1211
@ XML_WITH_READER
Definition: parser.h:1206
@ XML_WITH_XINCLUDE
Definition: parser.h:1219
@ XML_WITH_SCHEMATRON
Definition: parser.h:1227
@ XML_WITH_ICU
Definition: parser.h:1233

Referenced by showVersion().

◆ xmlInitParser()

void xmlInitParser ( void  )

xmlInitParser:

Initialization function for the XML parser. This is not reentrant. Call once before processing in case of use in multithreaded programs.

Definition at line 14676 of file parser.c.

14676 {
14677 if (xmlParserInitialized != 0)
14678 return;
14679
14680#if defined(_WIN32) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
14681 if (xmlFree == free)
14683#endif
14684
14685#ifdef LIBXML_THREAD_ENABLED
14687 if (xmlParserInitialized == 0) {
14688#endif
14692 (xmlGenericError == NULL))
14694 xmlInitMemory();
14699#ifdef LIBXML_OUTPUT_ENABLED
14700 xmlRegisterDefaultOutputCallbacks();
14701#endif /* LIBXML_OUTPUT_ENABLED */
14702#ifdef LIBXML_HTML_ENABLED
14703 htmlInitAutoClose();
14704 htmlDefaultSAXHandlerInit();
14705#endif
14706#ifdef LIBXML_XPATH_ENABLED
14707 xmlXPathInit();
14708#endif
14710#ifdef LIBXML_THREAD_ENABLED
14711 }
14713#endif
14714}
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlDefaultSAXHandlerInit(void)
Definition: SAX2.c:2934
#define free
Definition: debug_ros.c:5
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlInitCharEncodingHandlers(void)
Definition: encoding.c:1420
int __cdecl atexit(void(__cdecl *)(void))
Definition: atonexit.c:97
void void __xmlGlobalInitMutexLock(void)
Definition: threads.c:413
void __xmlGlobalInitMutexUnlock(void)
Definition: threads.c:488
XML_DEPRECATED XMLPUBFUN int XMLCALL xmlInitializeDict(void)
Definition: dict.c:157
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlInitGlobals(void)
Definition: globals.c:48
void xmlCleanupParser(void)
Definition: parser.c:14739
void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg,...)
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlInitThreads(void)
Definition: threads.c:847
XMLPUBFUN void XMLCALL xmlRegisterDefaultInputCallbacks(void)
XMLPUBFUN void XMLCALL initGenericErrorDefaultFunc(xmlGenericErrorFunc *handler)
Definition: error.c:90
XML_DEPRECATED XMLPUBFUN int XMLCALL xmlInitMemory(void)
Definition: xmlmemory.c:946

Referenced by DllMain(), xmlCheckVersion(), xmlCtxtReadFd(), xmlCtxtReadFile(), xmlCtxtReadIO(), xmlCtxtReadMemory(), xmlInitParserCtxt(), xmlParseDocument(), xmlReadDoc(), xmlReadFd(), xmlReadFile(), xmlReadIO(), and xmlReadMemory().

◆ xmlIsNameChar()

static int xmlIsNameChar ( xmlParserCtxtPtr  ctxt,
int  c 
)
static

Definition at line 3161 of file parser.c.

3161 {
3162 if ((ctxt->options & XML_PARSE_OLD10) == 0) {
3163 /*
3164 * Use the new checks of production [4] [4a] amd [5] of the
3165 * Update 5 of XML-1.0
3166 */
3167 if ((c != ' ') && (c != '>') && (c != '/') && /* accelerators */
3168 (((c >= 'a') && (c <= 'z')) ||
3169 ((c >= 'A') && (c <= 'Z')) ||
3170 ((c >= '0') && (c <= '9')) || /* !start */
3171 (c == '_') || (c == ':') ||
3172 (c == '-') || (c == '.') || (c == 0xB7) || /* !start */
3173 ((c >= 0xC0) && (c <= 0xD6)) ||
3174 ((c >= 0xD8) && (c <= 0xF6)) ||
3175 ((c >= 0xF8) && (c <= 0x2FF)) ||
3176 ((c >= 0x300) && (c <= 0x36F)) || /* !start */
3177 ((c >= 0x370) && (c <= 0x37D)) ||
3178 ((c >= 0x37F) && (c <= 0x1FFF)) ||
3179 ((c >= 0x200C) && (c <= 0x200D)) ||
3180 ((c >= 0x203F) && (c <= 0x2040)) || /* !start */
3181 ((c >= 0x2070) && (c <= 0x218F)) ||
3182 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3183 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3184 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3185 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3186 ((c >= 0x10000) && (c <= 0xEFFFF))))
3187 return(1);
3188 } else {
3189 if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
3190 (c == '.') || (c == '-') ||
3191 (c == '_') || (c == ':') ||
3192 (IS_COMBINING(c)) ||
3193 (IS_EXTENDER(c)))
3194 return(1);
3195 }
3196 return(0);
3197}
const GLubyte * c
Definition: glext.h:8905
#define IS_COMBINING(c)
#define IS_DIGIT(c)
#define IS_EXTENDER(c)
#define IS_LETTER(c)

Referenced by xmlParseNCNameComplex(), xmlParseNmtoken(), and xmlParseStringName().

◆ xmlIsNameStartChar()

static int xmlIsNameStartChar ( xmlParserCtxtPtr  ctxt,
int  c 
)
static

Definition at line 3130 of file parser.c.

3130 {
3131 if ((ctxt->options & XML_PARSE_OLD10) == 0) {
3132 /*
3133 * Use the new checks of production [4] [4a] amd [5] of the
3134 * Update 5 of XML-1.0
3135 */
3136 if ((c != ' ') && (c != '>') && (c != '/') && /* accelerators */
3137 (((c >= 'a') && (c <= 'z')) ||
3138 ((c >= 'A') && (c <= 'Z')) ||
3139 (c == '_') || (c == ':') ||
3140 ((c >= 0xC0) && (c <= 0xD6)) ||
3141 ((c >= 0xD8) && (c <= 0xF6)) ||
3142 ((c >= 0xF8) && (c <= 0x2FF)) ||
3143 ((c >= 0x370) && (c <= 0x37D)) ||
3144 ((c >= 0x37F) && (c <= 0x1FFF)) ||
3145 ((c >= 0x200C) && (c <= 0x200D)) ||
3146 ((c >= 0x2070) && (c <= 0x218F)) ||
3147 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3148 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3149 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3150 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3151 ((c >= 0x10000) && (c <= 0xEFFFF))))
3152 return(1);
3153 } else {
3154 if (IS_LETTER(c) || (c == '_') || (c == ':'))
3155 return(1);
3156 }
3157 return(0);
3158}

Referenced by xmlParseNCNameComplex(), and xmlParseStringName().

◆ xmlLoadEntityContent()

static int xmlLoadEntityContent ( xmlParserCtxtPtr  ctxt,
xmlEntityPtr  entity 
)
static

xmlLoadEntityContent: @ctxt: an XML parser context @entity: an unloaded system entity

Load the original content of the given system entity from the ExternalID/SystemID given. This is to be used for Included in Literal http://www.w3.org/TR/REC-xml/#inliteral processing of entities references

Returns 0 in case of success and -1 in case of failure

Definition at line 8060 of file parser.c.

8060 {
8063 int l, c;
8064 int count = 0;
8065
8066 if ((ctxt == NULL) || (entity == NULL) ||
8069 (entity->content != NULL)) {
8071 "xmlLoadEntityContent parameter error");
8072 return(-1);
8073 }
8074
8077 "Reading %s entity content input\n", entity->name);
8078
8079 buf = xmlBufferCreate();
8080 if (buf == NULL) {
8082 "xmlLoadEntityContent parameter error");
8083 return(-1);
8084 }
8086
8088 if (input == NULL) {
8090 "xmlLoadEntityContent input error");
8092 return(-1);
8093 }
8094
8095 /*
8096 * Push the entity as the current input, read char by char
8097 * saving to the buffer until the end of the entity or an error
8098 */
8099 if (xmlPushInput(ctxt, input) < 0) {
8102 return(-1);
8103 }
8104
8105 GROW;
8106 c = CUR_CHAR(l);
8107 while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) &&
8108 (IS_CHAR(c))) {
8109 xmlBufferAdd(buf, ctxt->input->cur, l);
8110 if (count++ > XML_PARSER_CHUNK_SIZE) {
8111 count = 0;
8112 GROW;
8113 if (ctxt->instate == XML_PARSER_EOF) {
8115 return(-1);
8116 }
8117 }
8118 NEXTL(l);
8119 c = CUR_CHAR(l);
8120 if (c == 0) {
8121 count = 0;
8122 GROW;
8123 if (ctxt->instate == XML_PARSER_EOF) {
8125 return(-1);
8126 }
8127 c = CUR_CHAR(l);
8128 }
8129 }
8130
8131 if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) {
8132 xmlPopInput(ctxt);
8133 } else if (!IS_CHAR(c)) {
8134 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
8135 "xmlLoadEntityContent: invalid char value %d\n",
8136 c);
8138 return(-1);
8139 }
8140 entity->content = buf->content;
8141 buf->content = NULL;
8143
8144 return(0);
8145}
@ XML_EXTERNAL_GENERAL_PARSED_ENTITY
Definition: entities.h:26
@ XML_EXTERNAL_PARAMETER_ENTITY
Definition: entities.h:29
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define c
Definition: ke_i.h:80
#define IS_CHAR(c)
XMLPUBFUN xmlParserInputPtr XMLCALL xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:423
XMLPUBFUN void XMLCALL xmlBufferFree(xmlBufferPtr buf)
XMLPUBFUN int XMLCALL xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len)
XMLPUBFUN xmlBufferPtr XMLCALL xmlBufferCreate(void)
@ XML_BUFFER_ALLOC_DOUBLEIT
Definition: tree.h:75
XMLPUBFUN void XMLCALL xmlBufferSetAllocationScheme(xmlBufferPtr buf, xmlBufferAllocationScheme scheme)
#define NEXTL(l)
Definition: parser.c:2156
xmlChar xmlPopInput(xmlParserCtxtPtr ctxt)
Definition: parser.c:2265
#define XML_PARSER_CHUNK_SIZE
Definition: parser.c:288
int xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input)
Definition: parser.c:2290
#define CUR_CHAR(l)
Definition: parser.c:2163
Definition: actctx.c:388
WCHAR * name
Definition: actctx.c:405
@ XML_ERR_INVALID_CHAR
Definition: xmlerror.h:109

Referenced by xmlStringLenDecodeEntities().

◆ xmlParseAttribute2()

static const xmlChar * xmlParseAttribute2 ( xmlParserCtxtPtr  ctxt,
const xmlChar pref,
const xmlChar elem,
const xmlChar **  prefix,
xmlChar **  value,
int len,
int alloc 
)
static

xmlParseAttribute2: @ctxt: an XML parser context @pref: the element prefix @elem: the element name @prefix: a xmlChar ** used to store the value of the attribute prefix @value: a xmlChar ** used to store the value of the attribute @len: an int * to save the length of the attribute @alloc: an int * to indicate if the attribute was allocated

parse an attribute in the new SAX2 framework.

Returns the attribute name, and the value in *value, .

Definition at line 9125 of file parser.c.

9129{
9130 const xmlChar *name;
9131 xmlChar *val, *internal_val = NULL;
9132 int normalize = 0;
9133
9134 *value = NULL;
9135 GROW;
9136 name = xmlParseQName(ctxt, prefix);
9137 if (name == NULL) {
9138 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
9139 "error parsing attribute name\n");
9140 return (NULL);
9141 }
9142
9143 /*
9144 * get the type if needed
9145 */
9146 if (ctxt->attsSpecial != NULL) {
9147 int type;
9148
9150 pref, elem, *prefix, name);
9151 if (type != 0)
9152 normalize = 1;
9153 }
9154
9155 /*
9156 * read the value
9157 */
9159 if (RAW == '=') {
9160 NEXT;
9163 if (normalize) {
9164 /*
9165 * Sometimes a second normalisation pass for spaces is needed
9166 * but that only happens if charrefs or entities references
9167 * have been used in the attribute value, i.e. the attribute
9168 * value have been extracted in an allocated string already.
9169 */
9170 if (*alloc) {
9171 const xmlChar *val2;
9172
9173 val2 = xmlAttrNormalizeSpace2(ctxt, val, len);
9174 if ((val2 != NULL) && (val2 != val)) {
9175 xmlFree(val);
9176 val = (xmlChar *) val2;
9177 }
9178 }
9179 }
9181 } else {
9182 xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE,
9183 "Specification mandates value for attribute %s\n",
9184 name);
9185 return (NULL);
9186 }
9187
9188 if (*prefix == ctxt->str_xml) {
9189 /*
9190 * Check that xml:lang conforms to the specification
9191 * No more registered as an error, just generate a warning now
9192 * since this was deprecated in XML second edition
9193 */
9194 if ((ctxt->pedantic) && (xmlStrEqual(name, BAD_CAST "lang"))) {
9195 internal_val = xmlStrndup(val, *len);
9196 if (!xmlCheckLanguageID(internal_val)) {
9197 xmlWarningMsg(ctxt, XML_WAR_LANG_VALUE,
9198 "Malformed value for xml:lang : %s\n",
9199 internal_val, NULL);
9200 }
9201 }
9202
9203 /*
9204 * Check that xml:space conforms to the specification
9205 */
9206 if (xmlStrEqual(name, BAD_CAST "space")) {
9207 internal_val = xmlStrndup(val, *len);
9208 if (xmlStrEqual(internal_val, BAD_CAST "default"))
9209 *(ctxt->space) = 0;
9210 else if (xmlStrEqual(internal_val, BAD_CAST "preserve"))
9211 *(ctxt->space) = 1;
9212 else {
9213 xmlWarningMsg(ctxt, XML_WAR_SPACE_VALUE,
9214 "Invalid value \"%s\" for xml:space : \"default\" or \"preserve\" expected\n",
9215 internal_val, NULL);
9216 }
9217 }
9218 if (internal_val) {
9219 xmlFree(internal_val);
9220 }
9221 }
9222
9223 *value = val;
9224 return (name);
9225}
static void normalize(float vec[3])
Definition: bezierEval.cc:234
static size_t elem
Definition: string.c:68
#define alloc
Definition: rosglue.h:13
XMLPUBFUN void *XMLCALL xmlHashQLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *prefix, const xmlChar *name2, const xmlChar *prefix2)
Definition: hash.c:510
@ XML_PARSER_CONTENT
Definition: parser.h:119
static xmlChar * xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc, int normalize)
Definition: parser.c:8960
#define NEXT
Definition: parser.c:2147
#define SKIP_BLANKS
Definition: parser.c:2145
static const xmlChar * xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **prefix)
Definition: parser.c:8788
int xmlCheckLanguageID(const xmlChar *lang)
Definition: parser.c:1474
static const xmlChar * xmlAttrNormalizeSpace2(xmlParserCtxtPtr ctxt, xmlChar *src, int *len)
Definition: parser.c:1185
@ XML_WAR_LANG_VALUE
Definition: xmlerror.h:198
@ XML_ERR_ATTRIBUTE_WITHOUT_VALUE
Definition: xmlerror.h:141
@ XML_ERR_NAME_REQUIRED
Definition: xmlerror.h:168
@ XML_WAR_SPACE_VALUE
Definition: xmlerror.h:202
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:160

Referenced by xmlParseStartTag2().

◆ xmlParseAttributeListDecl()

void xmlParseAttributeListDecl ( xmlParserCtxtPtr  ctxt)

xmlParseAttributeListDecl: @ctxt: an XML parser context

: parse the Attribute list def for an element

[52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'

[53] AttDef ::= S Name S AttType S DefaultDecl

Definition at line 5976 of file parser.c.

5976 {
5977 const xmlChar *elemName;
5978 const xmlChar *attrName;
5980
5981 if (CMP9(CUR_PTR, '<', '!', 'A', 'T', 'T', 'L', 'I', 'S', 'T')) {
5982 int inputid = ctxt->input->id;
5983
5984 SKIP(9);
5985 if (SKIP_BLANKS == 0) {
5986 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5987 "Space required after '<!ATTLIST'\n");
5988 }
5989 elemName = xmlParseName(ctxt);
5990 if (elemName == NULL) {
5991 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
5992 "ATTLIST: no name for Element\n");
5993 return;
5994 }
5996 GROW;
5997 while ((RAW != '>') && (ctxt->instate != XML_PARSER_EOF)) {
5998 int type;
5999 int def;
6000 xmlChar *defaultValue = NULL;
6001
6002 GROW;
6003 tree = NULL;
6004 attrName = xmlParseName(ctxt);
6005 if (attrName == NULL) {
6006 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
6007 "ATTLIST: no name for Attribute\n");
6008 break;
6009 }
6010 GROW;
6011 if (SKIP_BLANKS == 0) {
6012 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6013 "Space required after the attribute name\n");
6014 break;
6015 }
6016
6018 if (type <= 0) {
6019 break;
6020 }
6021
6022 GROW;
6023 if (SKIP_BLANKS == 0) {
6024 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6025 "Space required after the attribute type\n");
6026 if (tree != NULL)
6028 break;
6029 }
6030
6031 def = xmlParseDefaultDecl(ctxt, &defaultValue);
6032 if (def <= 0) {
6033 if (defaultValue != NULL)
6034 xmlFree(defaultValue);
6035 if (tree != NULL)
6037 break;
6038 }
6039 if ((type != XML_ATTRIBUTE_CDATA) && (defaultValue != NULL))
6040 xmlAttrNormalizeSpace(defaultValue, defaultValue);
6041
6042 GROW;
6043 if (RAW != '>') {
6044 if (SKIP_BLANKS == 0) {
6045 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6046 "Space required after the attribute default value\n");
6047 if (defaultValue != NULL)
6048 xmlFree(defaultValue);
6049 if (tree != NULL)
6051 break;
6052 }
6053 }
6054 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
6055 (ctxt->sax->attributeDecl != NULL))
6056 ctxt->sax->attributeDecl(ctxt->userData, elemName, attrName,
6057 type, def, defaultValue, tree);
6058 else if (tree != NULL)
6060
6061 if ((ctxt->sax2) && (defaultValue != NULL) &&
6062 (def != XML_ATTRIBUTE_IMPLIED) &&
6063 (def != XML_ATTRIBUTE_REQUIRED)) {
6064 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue);
6065 }
6066 if (ctxt->sax2) {
6067 xmlAddSpecialAttr(ctxt, elemName, attrName, type);
6068 }
6069 if (defaultValue != NULL)
6070 xmlFree(defaultValue);
6071 GROW;
6072 }
6073 if (RAW == '>') {
6074 if (inputid != ctxt->input->id) {
6075 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6076 "Attribute list declaration doesn't start and"
6077 " stop in the same entity\n");
6078 }
6079 NEXT;
6080 }
6081 }
6082}
struct _tree tree
@ XML_ATTRIBUTE_REQUIRED
Definition: tree.h:227
@ XML_ATTRIBUTE_IMPLIED
Definition: tree.h:228
int xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value)
Definition: parser.c:5682
static void xmlAddDefAttrs(xmlParserCtxtPtr ctxt, const xmlChar *fullname, const xmlChar *fullattr, const xmlChar *value)
Definition: parser.c:1242
const xmlChar * xmlParseName(xmlParserCtxtPtr ctxt)
Definition: parser.c:3344
int xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree)
Definition: parser.c:5934
static void xmlAddSpecialAttr(xmlParserCtxtPtr ctxt, const xmlChar *fullname, const xmlChar *fullattr, int type)
Definition: parser.c:1353
#define SKIP(val)
Definition: parser.c:2088
#define CUR_PTR
Definition: parser.c:2067
XMLPUBFUN void XMLCALL xmlFreeEnumeration(xmlEnumerationPtr cur)
Definition: valid.c:1817
@ XML_ERR_ENTITY_BOUNDARY
Definition: xmlerror.h:190
@ XML_ERR_SPACE_REQUIRED
Definition: xmlerror.h:165

Referenced by xmlParseMarkupDecl().

◆ xmlParseAttributeType()

int xmlParseAttributeType ( xmlParserCtxtPtr  ctxt,
xmlEnumerationPtr tree 
)

xmlParseAttributeType: @ctxt: an XML parser context @tree: the enumeration tree built while parsing

parse the Attribute list def for an element

[54] AttType ::= StringType | TokenizedType | EnumeratedType

[55] StringType ::= 'CDATA'

[56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'

Validity constraints for attribute values syntax are checked in xmlValidateAttributeValue()

[ VC: ID ] Values of type ID must match the Name production. A name must not appear more than once in an XML document as a value of this type; i.e., ID values must uniquely identify the elements which bear them.

[ VC: One ID per Element Type ] No element type may have more than one ID attribute specified.

[ VC: ID Attribute Default ] An ID attribute must have a declared default of #IMPLIED or #REQUIRED.

[ VC: IDREF ] Values of type IDREF must match the Name production, and values of type IDREFS must match Names; each IDREF Name must match the value of an ID attribute on some element in the XML document; i.e. IDREF values must match the value of some ID attribute.

[ VC: Entity Name ] Values of type ENTITY must match the Name production, values of type ENTITIES must match Names; each Entity Name must match the name of an unparsed entity declared in the DTD.

[ VC: Name Token ] Values of type NMTOKEN must match the Nmtoken production; values of type NMTOKENS must match Nmtokens.

Returns the attribute type

Definition at line 5934 of file parser.c.

5934 {
5935 SHRINK;
5936 if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) {
5937 SKIP(5);
5938 return(XML_ATTRIBUTE_CDATA);
5939 } else if (CMP6(CUR_PTR, 'I', 'D', 'R', 'E', 'F', 'S')) {
5940 SKIP(6);
5941 return(XML_ATTRIBUTE_IDREFS);
5942 } else if (CMP5(CUR_PTR, 'I', 'D', 'R', 'E', 'F')) {
5943 SKIP(5);
5944 return(XML_ATTRIBUTE_IDREF);
5945 } else if ((RAW == 'I') && (NXT(1) == 'D')) {
5946 SKIP(2);
5947 return(XML_ATTRIBUTE_ID);
5948 } else if (CMP6(CUR_PTR, 'E', 'N', 'T', 'I', 'T', 'Y')) {
5949 SKIP(6);
5950 return(XML_ATTRIBUTE_ENTITY);
5951 } else if (CMP8(CUR_PTR, 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S')) {
5952 SKIP(8);
5953 return(XML_ATTRIBUTE_ENTITIES);
5954 } else if (CMP8(CUR_PTR, 'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S')) {
5955 SKIP(8);
5956 return(XML_ATTRIBUTE_NMTOKENS);
5957 } else if (CMP7(CUR_PTR, 'N', 'M', 'T', 'O', 'K', 'E', 'N')) {
5958 SKIP(7);
5959 return(XML_ATTRIBUTE_NMTOKEN);
5960 }
5961 return(xmlParseEnumeratedType(ctxt, tree));
5962}
@ XML_ATTRIBUTE_NMTOKENS
Definition: tree.h:214
@ XML_ATTRIBUTE_IDREF
Definition: tree.h:209
@ XML_ATTRIBUTE_ENTITIES
Definition: tree.h:212
@ XML_ATTRIBUTE_IDREFS
Definition: tree.h:210
@ XML_ATTRIBUTE_ID
Definition: tree.h:208
@ XML_ATTRIBUTE_NMTOKEN
Definition: tree.h:213
@ XML_ATTRIBUTE_ENTITY
Definition: tree.h:211
#define SHRINK
Definition: parser.c:2106
#define CMP7(s, c1, c2, c3, c4, c5, c6, c7)
Definition: parser.c:2077
int xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree)
Definition: parser.c:5871
#define CMP5(s, c1, c2, c3, c4, c5)
Definition: parser.c:2073
#define CMP6(s, c1, c2, c3, c4, c5, c6)
Definition: parser.c:2075

Referenced by xmlParseAttributeListDecl().

◆ xmlParseAttValue()

xmlChar * xmlParseAttValue ( xmlParserCtxtPtr  ctxt)

xmlParseAttValue: @ctxt: an XML parser context

parse a value for an attribute Note: the parser won't do substitution of entities here, this will be handled later in xmlStringGetNodeList

[10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"

3.3.3 Attribute-Value Normalization: Before the value of an attribute is passed to the application or checked for validity, the XML processor must normalize it as follows:

  • a character reference is processed by appending the referenced character to the attribute value
  • an entity reference is processed by recursively processing the replacement text of the entity
  • a whitespace character (#x20, #xD, #xA, #x9) is processed by appending #x20 to the normalized value, except that only a single #x20 is appended for a "#xD#xA" sequence that is part of an external parsed entity or the literal entity value of an internal parsed entity
  • other characters are processed by appending them to the normalized value If the declared value is not CDATA, then the XML processor must further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character. All attributes for which no declaration has been read should be treated by a non-validating parser as if declared CDATA.

Returns the AttValue parsed or NULL. The value has to be freed by the caller.

Definition at line 4182 of file parser.c.

4182 {
4183 if ((ctxt == NULL) || (ctxt->input == NULL)) return(NULL);
4184 return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0));
4185}

Referenced by xmlParseDefaultDecl().

◆ xmlParseAttValueComplex()

static xmlChar * xmlParseAttValueComplex ( xmlParserCtxtPtr  ctxt,
int attlen,
int  normalize 
)
static

xmlParseAttValueComplex: @ctxt: an XML parser context @len: the resulting attribute len @normalize: whether to apply the inner normalization

parse a value for an attribute, this is the fallback function of xmlParseAttValue() when the attribute parsing requires handling of non-ASCII characters, or normalization compaction.

Returns the AttValue parsed or NULL. The value has to be freed by the caller.

Definition at line 3921 of file parser.c.

3921 {
3922 xmlChar limit = 0;
3923 xmlChar *buf = NULL;
3924 xmlChar *rep = NULL;
3925 size_t len = 0;
3926 size_t buf_size = 0;
3927 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3930 int c, l, in_space = 0;
3931 xmlChar *current = NULL;
3932 xmlEntityPtr ent;
3933
3934 if (NXT(0) == '"') {
3936 limit = '"';
3937 NEXT;
3938 } else if (NXT(0) == '\'') {
3939 limit = '\'';
3941 NEXT;
3942 } else {
3944 return(NULL);
3945 }
3946
3947 /*
3948 * allocate a translation buffer.
3949 */
3950 buf_size = XML_PARSER_BUFFER_SIZE;
3951 buf = (xmlChar *) xmlMallocAtomic(buf_size);
3952 if (buf == NULL) goto mem_error;
3953
3954 /*
3955 * OK loop until we reach one of the ending char or a size limit.
3956 */
3957 c = CUR_CHAR(l);
3958 while (((NXT(0) != limit) && /* checked */
3959 (IS_CHAR(c)) && (c != '<')) &&
3960 (ctxt->instate != XML_PARSER_EOF)) {
3961 if (c == '&') {
3962 in_space = 0;
3963 if (NXT(1) == '#') {
3964 int val = xmlParseCharRef(ctxt);
3965
3966 if (val == '&') {
3967 if (ctxt->replaceEntities) {
3968 if (len + 10 > buf_size) {
3969 growBuffer(buf, 10);
3970 }
3971 buf[len++] = '&';
3972 } else {
3973 /*
3974 * The reparsing will be done in xmlStringGetNodeList()
3975 * called by the attribute() function in SAX.c
3976 */
3977 if (len + 10 > buf_size) {
3978 growBuffer(buf, 10);
3979 }
3980 buf[len++] = '&';
3981 buf[len++] = '#';
3982 buf[len++] = '3';
3983 buf[len++] = '8';
3984 buf[len++] = ';';
3985 }
3986 } else if (val != 0) {
3987 if (len + 10 > buf_size) {
3988 growBuffer(buf, 10);
3989 }
3990 len += xmlCopyChar(0, &buf[len], val);
3991 }
3992 } else {
3993 ent = xmlParseEntityRef(ctxt);
3994 ctxt->nbentities++;
3995 if (ent != NULL)
3996 ctxt->nbentities += ent->owner;
3997 if ((ent != NULL) &&
3999 if (len + 10 > buf_size) {
4000 growBuffer(buf, 10);
4001 }
4002 if ((ctxt->replaceEntities == 0) &&
4003 (ent->content[0] == '&')) {
4004 buf[len++] = '&';
4005 buf[len++] = '#';
4006 buf[len++] = '3';
4007 buf[len++] = '8';
4008 buf[len++] = ';';
4009 } else {
4010 buf[len++] = ent->content[0];
4011 }
4012 } else if ((ent != NULL) &&
4013 (ctxt->replaceEntities != 0)) {
4015 ++ctxt->depth;
4016 rep = xmlStringDecodeEntities(ctxt, ent->content,
4018 0, 0, 0);
4019 --ctxt->depth;
4020 if (rep != NULL) {
4021 current = rep;
4022 while (*current != 0) { /* non input consuming */
4023 if ((*current == 0xD) || (*current == 0xA) ||
4024 (*current == 0x9)) {
4025 buf[len++] = 0x20;
4026 current++;
4027 } else
4028 buf[len++] = *current++;
4029 if (len + 10 > buf_size) {
4030 growBuffer(buf, 10);
4031 }
4032 }
4033 xmlFree(rep);
4034 rep = NULL;
4035 }
4036 } else {
4037 if (len + 10 > buf_size) {
4038 growBuffer(buf, 10);
4039 }
4040 if (ent->content != NULL)
4041 buf[len++] = ent->content[0];
4042 }
4043 } else if (ent != NULL) {
4044 int i = xmlStrlen(ent->name);
4045 const xmlChar *cur = ent->name;
4046
4047 /*
4048 * This may look absurd but is needed to detect
4049 * entities problems
4050 */
4051 if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
4052 (ent->content != NULL) && (ent->checked == 0)) {
4053 unsigned long oldnbent = ctxt->nbentities, diff;
4054
4055 ++ctxt->depth;
4056 rep = xmlStringDecodeEntities(ctxt, ent->content,
4057 XML_SUBSTITUTE_REF, 0, 0, 0);
4058 --ctxt->depth;
4059
4060 diff = ctxt->nbentities - oldnbent + 1;
4061 if (diff > INT_MAX / 2)
4062 diff = INT_MAX / 2;
4063 ent->checked = diff * 2;
4064 if (rep != NULL) {
4065 if (xmlStrchr(rep, '<'))
4066 ent->checked |= 1;
4067 xmlFree(rep);
4068 rep = NULL;
4069 } else {
4070 ent->content[0] = 0;
4071 }
4072 }
4073
4074 /*
4075 * Just output the reference
4076 */
4077 buf[len++] = '&';
4078 while (len + i + 10 > buf_size) {
4079 growBuffer(buf, i + 10);
4080 }
4081 for (;i > 0;i--)
4082 buf[len++] = *cur++;
4083 buf[len++] = ';';
4084 }
4085 }
4086 } else {
4087 if ((c == 0x20) || (c == 0xD) || (c == 0xA) || (c == 0x9)) {
4088 if ((len != 0) || (!normalize)) {
4089 if ((!normalize) || (!in_space)) {
4090 COPY_BUF(l,buf,len,0x20);
4091 while (len + 10 > buf_size) {
4092 growBuffer(buf, 10);
4093 }
4094 }
4095 in_space = 1;
4096 }
4097 } else {
4098 in_space = 0;
4099 COPY_BUF(l,buf,len,c);
4100 if (len + 10 > buf_size) {
4101 growBuffer(buf, 10);
4102 }
4103 }
4104 NEXTL(l);
4105 }
4106 GROW;
4107 c = CUR_CHAR(l);
4108 if (len > maxLength) {
4109 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
4110 "AttValue length too long\n");
4111 goto mem_error;
4112 }
4113 }
4114 if (ctxt->instate == XML_PARSER_EOF)
4115 goto error;
4116
4117 if ((in_space) && (normalize)) {
4118 while ((len > 0) && (buf[len - 1] == 0x20)) len--;
4119 }
4120 buf[len] = 0;
4121 if (RAW == '<') {
4123 } else if (RAW != limit) {
4124 if ((c != 0) && (!IS_CHAR(c))) {
4125 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_CHAR,
4126 "invalid character in attribute value\n");
4127 } else {
4128 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
4129 "AttValue: ' expected\n");
4130 }
4131 } else
4132 NEXT;
4133
4134 if (attlen != NULL) *attlen = (int) len;
4135 return(buf);
4136
4137mem_error:
4138 xmlErrMemory(ctxt, NULL);
4139error:
4140 if (buf != NULL)
4141 xmlFree(buf);
4142 if (rep != NULL)
4143 xmlFree(rep);
4144 return(NULL);
4145}
@ XML_INTERNAL_PREDEFINED_ENTITY
Definition: entities.h:30
GLsizei maxLength
Definition: glext.h:6877
GLint limit
Definition: glext.h:10326
#define INT_MAX
Definition: limits.h:40
struct task_struct * current
Definition: linux.c:32
#define XML_MAX_TEXT_LENGTH
#define XML_SUBSTITUTE_REF
XMLPUBFUN int XMLCALL xmlCopyChar(int len, xmlChar *out, int val)
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:249
@ XML_PARSER_ATTRIBUTE_VALUE
Definition: parser.h:124
#define growBuffer(buffer, n)
Definition: parser.c:2613
#define XML_PARSER_BUFFER_SIZE
Definition: parser.c:276
xmlChar * xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, xmlChar end, xmlChar end2, xmlChar end3)
Definition: parser.c:2839
xmlEntityPtr xmlParseEntityRef(xmlParserCtxtPtr ctxt)
Definition: parser.c:7531
#define COPY_BUF(l, b, i, v)
Definition: parser.c:2166
#define XML_MAX_HUGE_LENGTH
Definition: parser.c:105
int xmlParseCharRef(xmlParserCtxtPtr ctxt)
Definition: parser.c:2332
xmlChar * content
Definition: entities.h:50
xmlEntityType etype
Definition: entities.h:52
const xmlChar * name
Definition: entities.h:41
int checked
Definition: entities.h:59
int owner
Definition: entities.h:58
@ XML_ERR_ATTRIBUTE_NOT_FINISHED
Definition: xmlerror.h:140
XMLPUBFUN const xmlChar *XMLCALL xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:325

Referenced by xmlParseAttValueInternal().

◆ xmlParseAttValueInternal()

static xmlChar * xmlParseAttValueInternal ( xmlParserCtxtPtr  ctxt,
int len,
int alloc,
int  normalize 
)
static

Definition at line 8960 of file parser.c.

8962{
8963 xmlChar limit = 0;
8964 const xmlChar *in = NULL, *start, *end, *last;
8965 xmlChar *ret = NULL;
8966 int line, col;
8967 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
8970
8971 GROW;
8972 in = (xmlChar *) CUR_PTR;
8973 line = ctxt->input->line;
8974 col = ctxt->input->col;
8975 if (*in != '"' && *in != '\'') {
8977 return (NULL);
8978 }
8980
8981 /*
8982 * try to handle in this routine the most common case where no
8983 * allocation of a new string is required and where content is
8984 * pure ASCII.
8985 */
8986 limit = *in++;
8987 col++;
8988 end = ctxt->input->end;
8989 start = in;
8990 if (in >= end) {
8992 }
8993 if (normalize) {
8994 /*
8995 * Skip any leading spaces
8996 */
8997 while ((in < end) && (*in != limit) &&
8998 ((*in == 0x20) || (*in == 0x9) ||
8999 (*in == 0xA) || (*in == 0xD))) {
9000 if (*in == 0xA) {
9001 line++; col = 1;
9002 } else {
9003 col++;
9004 }
9005 in++;
9006 start = in;
9007 if (in >= end) {
9009 if ((in - start) > maxLength) {
9010 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9011 "AttValue length too long\n");
9012 return(NULL);
9013 }
9014 }
9015 }
9016 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
9017 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
9018 col++;
9019 if ((*in++ == 0x20) && (*in == 0x20)) break;
9020 if (in >= end) {
9022 if ((in - start) > maxLength) {
9023 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9024 "AttValue length too long\n");
9025 return(NULL);
9026 }
9027 }
9028 }
9029 last = in;
9030 /*
9031 * skip the trailing blanks
9032 */
9033 while ((last[-1] == 0x20) && (last > start)) last--;
9034 while ((in < end) && (*in != limit) &&
9035 ((*in == 0x20) || (*in == 0x9) ||
9036 (*in == 0xA) || (*in == 0xD))) {
9037 if (*in == 0xA) {
9038 line++, col = 1;
9039 } else {
9040 col++;
9041 }
9042 in++;
9043 if (in >= end) {
9044 const xmlChar *oldbase = ctxt->input->base;
9045 GROW;
9046 if (ctxt->instate == XML_PARSER_EOF)
9047 return(NULL);
9048 if (oldbase != ctxt->input->base) {
9049 ptrdiff_t delta = ctxt->input->base - oldbase;
9050 start = start + delta;
9051 in = in + delta;
9052 last = last + delta;
9053 }
9054 end = ctxt->input->end;
9055 if ((in - start) > maxLength) {
9056 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9057 "AttValue length too long\n");
9058 return(NULL);
9059 }
9060 }
9061 }
9062 if ((in - start) > maxLength) {
9063 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9064 "AttValue length too long\n");
9065 return(NULL);
9066 }
9067 if (*in != limit) goto need_complex;
9068 } else {
9069 while ((in < end) && (*in != limit) && (*in >= 0x20) &&
9070 (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
9071 in++;
9072 col++;
9073 if (in >= end) {
9075 if ((in - start) > maxLength) {
9076 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9077 "AttValue length too long\n");
9078 return(NULL);
9079 }
9080 }
9081 }
9082 last = in;
9083 if ((in - start) > maxLength) {
9084 xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
9085 "AttValue length too long\n");
9086 return(NULL);
9087 }
9088 if (*in != limit) goto need_complex;
9089 }
9090 in++;
9091 col++;
9092 if (len != NULL) {
9093 *len = last - start;
9094 ret = (xmlChar *) start;
9095 } else {
9096 if (alloc) *alloc = 1;
9098 }
9099 CUR_PTR = in;
9100 ctxt->input->line = line;
9101 ctxt->input->col = col;
9102 if (alloc) *alloc = 0;
9103 return ret;
9104need_complex:
9105 if (alloc) *alloc = 1;
9106 return xmlParseAttValueComplex(ctxt, len, normalize);
9107}
static UINT UINT last
Definition: font.c:45
static xmlChar * xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize)
Definition: parser.c:3921
#define GROW_PARSE_ATT_VALUE_INTERNAL(ctxt, in, start, end)
Definition: parser.c:8947

Referenced by xmlParseAttribute2(), and xmlParseAttValue().

◆ xmlParseBalancedChunkMemoryInternal()

static xmlParserErrors xmlParseBalancedChunkMemoryInternal ( xmlParserCtxtPtr  oldctxt,
const xmlChar string,
void user_data,
xmlNodePtr lst 
)
static

xmlParseBalancedChunkMemoryInternal: @oldctxt: the existing parsing context @string: the input string in UTF8 or ISO-Latin (zero terminated) @user_data: the user data field for the parser context @lst: the return value for the set of parsed nodes

Parse a well-balanced chunk of an XML document called by the parser The allowed sequence for the Well Balanced Chunk is the one defined by the content production in the XML grammar:

[43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*

Returns XML_ERR_OK if the chunk is well balanced, and the parser error code otherwise

In case recover is set to 1, the nodelist will not be empty even if the parsed chunk is not well balanced.

Definition at line 13303 of file parser.c.

13304 {
13305 xmlParserCtxtPtr ctxt;
13306 xmlDocPtr newDoc = NULL;
13307 xmlNodePtr newRoot;
13308 xmlSAXHandlerPtr oldsax = NULL;
13311 int size;
13313#ifdef SAX2
13314 int i;
13315#endif
13316
13317 if (((oldctxt->depth > 40) && ((oldctxt->options & XML_PARSE_HUGE) == 0)) ||
13318 (oldctxt->depth > 1024)) {
13319 return(XML_ERR_ENTITY_LOOP);
13320 }
13321
13322
13323 if (lst != NULL)
13324 *lst = NULL;
13325 if (string == NULL)
13326 return(XML_ERR_INTERNAL_ERROR);
13327
13328 size = xmlStrlen(string);
13329
13330 ctxt = xmlCreateMemoryParserCtxt((char *) string, size);
13331 if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY);
13332 if (user_data != NULL)
13333 ctxt->userData = user_data;
13334 else
13335 ctxt->userData = ctxt;
13336 if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
13337 ctxt->dict = oldctxt->dict;
13338 ctxt->input_id = oldctxt->input_id + 1;
13339 ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
13340 ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
13341 ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
13342
13343#ifdef SAX2
13344 /* propagate namespaces down the entity */
13345 for (i = 0;i < oldctxt->nsNr;i += 2) {
13346 nsPush(ctxt, oldctxt->nsTab[i], oldctxt->nsTab[i+1]);
13347 }
13348#endif
13349
13350 oldsax = ctxt->sax;
13351 ctxt->sax = oldctxt->sax;
13352 xmlDetectSAX2(ctxt);
13353 ctxt->replaceEntities = oldctxt->replaceEntities;
13354 ctxt->options = oldctxt->options;
13355
13356 ctxt->_private = oldctxt->_private;
13357 if (oldctxt->myDoc == NULL) {
13358 newDoc = xmlNewDoc(BAD_CAST "1.0");
13359 if (newDoc == NULL) {
13360 ctxt->sax = oldsax;
13361 ctxt->dict = NULL;
13362 xmlFreeParserCtxt(ctxt);
13363 return(XML_ERR_INTERNAL_ERROR);
13364 }
13365 newDoc->properties = XML_DOC_INTERNAL;
13366 newDoc->dict = ctxt->dict;
13367 xmlDictReference(newDoc->dict);
13368 ctxt->myDoc = newDoc;
13369 } else {
13370 ctxt->myDoc = oldctxt->myDoc;
13371 content = ctxt->myDoc->children;
13372 last = ctxt->myDoc->last;
13373 }
13374 newRoot = xmlNewDocNode(ctxt->myDoc, NULL, BAD_CAST "pseudoroot", NULL);
13375 if (newRoot == NULL) {
13376 ctxt->sax = oldsax;
13377 ctxt->dict = NULL;
13378 xmlFreeParserCtxt(ctxt);
13379 if (newDoc != NULL) {
13380 xmlFreeDoc(newDoc);
13381 }
13382 return(XML_ERR_INTERNAL_ERROR);
13383 }
13384 ctxt->myDoc->children = NULL;
13385 ctxt->myDoc->last = NULL;
13386 xmlAddChild((xmlNodePtr) ctxt->myDoc, newRoot);
13387 nodePush(ctxt, ctxt->myDoc->children);
13389 ctxt->depth = oldctxt->depth + 1;
13390
13391 ctxt->validate = 0;
13392 ctxt->loadsubset = oldctxt->loadsubset;
13393 if ((oldctxt->validate) || (oldctxt->replaceEntities != 0)) {
13394 /*
13395 * ID/IDREF registration will be done in xmlValidateElement below
13396 */
13397 ctxt->loadsubset |= XML_SKIP_IDS;
13398 }
13399 ctxt->dictNames = oldctxt->dictNames;
13400 ctxt->attsDefault = oldctxt->attsDefault;
13401 ctxt->attsSpecial = oldctxt->attsSpecial;
13402
13403 xmlParseContent(ctxt);
13404 if ((RAW == '<') && (NXT(1) == '/')) {
13406 } else if (RAW != 0) {
13408 }
13409 if (ctxt->node != ctxt->myDoc->children) {
13411 }
13412
13413 if (!ctxt->wellFormed) {
13414 if (ctxt->errNo == 0)
13416 else
13417 ret = (xmlParserErrors)ctxt->errNo;
13418 } else {
13419 ret = XML_ERR_OK;
13420 }
13421
13422 if ((lst != NULL) && (ret == XML_ERR_OK)) {
13424
13425 /*
13426 * Return the newly created nodeset after unlinking it from
13427 * they pseudo parent.
13428 */
13429 cur = ctxt->myDoc->children->children;
13430 *lst = cur;
13431 while (cur != NULL) {
13432#ifdef LIBXML_VALID_ENABLED
13433 if ((oldctxt->validate) && (oldctxt->wellFormed) &&
13434 (oldctxt->myDoc) && (oldctxt->myDoc->intSubset) &&
13435 (cur->type == XML_ELEMENT_NODE)) {
13436 oldctxt->valid &= xmlValidateElement(&oldctxt->vctxt,
13437 oldctxt->myDoc, cur);
13438 }
13439#endif /* LIBXML_VALID_ENABLED */
13440 cur->parent = NULL;
13441 cur = cur->next;
13442 }
13443 ctxt->myDoc->children->children = NULL;
13444 }
13445 if (ctxt->myDoc != NULL) {
13446 xmlFreeNode(ctxt->myDoc->children);
13447 ctxt->myDoc->children = content;
13448 ctxt->myDoc->last = last;
13449 }
13450
13451 /*
13452 * Record in the parent context the number of entities replacement
13453 * done when parsing that reference.
13454 */
13455 if (oldctxt != NULL)
13456 oldctxt->nbentities += ctxt->nbentities;
13457
13458 /*
13459 * Also record the last error if any
13460 */
13461 if (ctxt->lastError.code != XML_ERR_OK)
13462 xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
13463
13464 ctxt->sax = oldsax;
13465 ctxt->dict = NULL;
13466 ctxt->attsDefault = NULL;
13467 ctxt->attsSpecial = NULL;
13468 xmlFreeParserCtxt(ctxt);
13469 if (newDoc != NULL) {
13470 xmlFreeDoc(newDoc);
13471 }
13472
13473 return(ret);
13474}
content
Definition: atl_ax.c:994
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:802
XMLPUBFUN int XMLCALL xmlDictReference(xmlDictPtr dict)
Definition: dict.c:647
#define XML_SKIP_IDS
Definition: parser.h:154
XMLPUBFUN xmlNodePtr XMLCALL xmlAddChild(xmlNodePtr parent, xmlNodePtr cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content)
XMLPUBFUN xmlDocPtr XMLCALL xmlNewDoc(const xmlChar *version)
@ XML_DOC_INTERNAL
Definition: tree.h:540
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
int nodePush(xmlParserCtxtPtr ctxt, xmlNodePtr value)
Definition: parser.c:1801
static int nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *URL)
Definition: parser.c:1631
void xmlParseContent(xmlParserCtxtPtr ctxt)
Definition: parser.c:9958
static void xmlDetectSAX2(xmlParserCtxtPtr ctxt)
Definition: parser.c:1094
struct _xmlDtd * intSubset
Definition: tree.h:570
struct _xmlNode * last
Definition: tree.h:556
int properties
Definition: tree.h:584
struct _xmlDict * dict
Definition: tree.h:580
struct _xmlNode * children
Definition: tree.h:555
XMLPUBFUN int XMLCALL xmlCopyError(xmlErrorPtr from, xmlErrorPtr to)
xmlParserErrors
Definition: xmlerror.h:99
@ XML_WAR_UNDECLARED_ENTITY
Definition: xmlerror.h:127

Referenced by xmlParseReference().

◆ xmlParseCDSect()

void xmlParseCDSect ( xmlParserCtxtPtr  ctxt)

xmlParseCDSect: @ctxt: an XML parser context

Parse escaped pure raw content.

[18] CDSect ::= CDStart CData CDEnd

[19] CDStart ::= ''

[20] Data ::= (Char* - (Char* '' Char*))

[21] CDEnd ::= ']]>'

Definition at line 9765 of file parser.c.

9765 {
9766 xmlChar *buf = NULL;
9767 int len = 0;
9769 int r, rl;
9770 int s, sl;
9771 int cur, l;
9772 int count = 0;
9773 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
9776
9777 /* Check 2.6.0 was NXT(0) not RAW */
9778 if (CMP9(CUR_PTR, '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '[')) {
9779 SKIP(9);
9780 } else
9781 return;
9782
9784 r = CUR_CHAR(rl);
9785 if (!IS_CHAR(r)) {
9788 return;
9789 }
9790 NEXTL(rl);
9791 s = CUR_CHAR(sl);
9792 if (!IS_CHAR(s)) {
9795 return;
9796 }
9797 NEXTL(sl);
9798 cur = CUR_CHAR(l);
9799 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
9800 if (buf == NULL) {
9801 xmlErrMemory(ctxt, NULL);
9802 return;
9803 }
9804 while (IS_CHAR(cur) &&
9805 ((r != ']') || (s != ']') || (cur != '>'))) {
9806 if (len + 5 >= size) {
9807 xmlChar *tmp;
9808
9809 tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar));
9810 if (tmp == NULL) {
9811 xmlFree(buf);
9812 xmlErrMemory(ctxt, NULL);
9813 return;
9814 }
9815 buf = tmp;
9816 size *= 2;
9817 }
9818 COPY_BUF(rl,buf,len,r);
9819 r = s;
9820 rl = sl;
9821 s = cur;
9822 sl = l;
9823 count++;
9824 if (count > 50) {
9825 SHRINK;
9826 GROW;
9827 if (ctxt->instate == XML_PARSER_EOF) {
9828 xmlFree(buf);
9829 return;
9830 }
9831 count = 0;
9832 }
9833 NEXTL(l);
9834 cur = CUR_CHAR(l);
9835 if (len > maxLength) {
9836 xmlFatalErrMsg(ctxt, XML_ERR_CDATA_NOT_FINISHED,
9837 "CData section too big found\n");
9838 xmlFree(buf);
9839 return;
9840 }
9841 }
9842 buf[len] = 0;
9844 if (cur != '>') {
9845 xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED,
9846 "CData section not finished\n%.50s\n", buf);
9847 xmlFree(buf);
9848 return;
9849 }
9850 NEXTL(l);
9851
9852 /*
9853 * OK the buffer is to be consumed as cdata.
9854 */
9855 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
9856 if (ctxt->sax->cdataBlock != NULL)
9857 ctxt->sax->cdataBlock(ctxt->userData, buf, len);
9858 else if (ctxt->sax->characters != NULL)
9859 ctxt->sax->characters(ctxt->userData, buf, len);
9860 }
9861 xmlFree(buf);
9862}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
@ XML_PARSER_CDATA_SECTION
Definition: parser.h:120
@ XML_ERR_CDATA_NOT_FINISHED
Definition: xmlerror.h:163

Referenced by xmlParseContentInternal().

◆ xmlParseCharData()

void xmlParseCharData ( xmlParserCtxtPtr  ctxt,
int  cdata 
)

xmlParseCharData: @ctxt: an XML parser context @cdata: int indicating whether we are within a CDATA section

parse a CharData section. if we are within a CDATA section ']]>' marks an end of section.

The right angle bracket (>) may be represented using the string "&gt;", and must, for compatibility, be escaped using "&gt;" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section.

[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)

Definition at line 4425 of file parser.c.

4425 {
4426 const xmlChar *in;
4427 int nbchar = 0;
4428 int line = ctxt->input->line;
4429 int col = ctxt->input->col;
4430 int ccol;
4431
4432 SHRINK;
4433 GROW;
4434 /*
4435 * Accelerated common case where input don't need to be
4436 * modified before passing it to the handler.
4437 */
4438 if (!cdata) {
4439 in = ctxt->input->cur;
4440 do {
4441get_more_space:
4442 while (*in == 0x20) { in++; ctxt->input->col++; }
4443 if (*in == 0xA) {
4444 do {
4445 ctxt->input->line++; ctxt->input->col = 1;
4446 in++;
4447 } while (*in == 0xA);
4448 goto get_more_space;
4449 }
4450 if (*in == '<') {
4451 nbchar = in - ctxt->input->cur;
4452 if (nbchar > 0) {
4453 const xmlChar *tmp = ctxt->input->cur;
4454 ctxt->input->cur = in;
4455
4456 if ((ctxt->sax != NULL) &&
4457 (ctxt->sax->ignorableWhitespace !=
4458 ctxt->sax->characters)) {
4459 if (areBlanks(ctxt, tmp, nbchar, 1)) {
4460 if (ctxt->sax->ignorableWhitespace != NULL)
4461 ctxt->sax->ignorableWhitespace(ctxt->userData,
4462 tmp, nbchar);
4463 } else {
4464 if (ctxt->sax->characters != NULL)
4465 ctxt->sax->characters(ctxt->userData,
4466 tmp, nbchar);
4467 if (*ctxt->space == -1)
4468 *ctxt->space = -2;
4469 }
4470 } else if ((ctxt->sax != NULL) &&
4471 (ctxt->sax->characters != NULL)) {
4472 ctxt->sax->characters(ctxt->userData,
4473 tmp, nbchar);
4474 }
4475 }
4476 return;
4477 }
4478
4479get_more:
4480 ccol = ctxt->input->col;
4481 while (test_char_data[*in]) {
4482 in++;
4483 ccol++;
4484 }
4485 ctxt->input->col = ccol;
4486 if (*in == 0xA) {
4487 do {
4488 ctxt->input->line++; ctxt->input->col = 1;
4489 in++;
4490 } while (*in == 0xA);
4491 goto get_more;
4492 }
4493 if (*in == ']') {
4494 if ((in[1] == ']') && (in[2] == '>')) {
4496 ctxt->input->cur = in + 1;
4497 return;
4498 }
4499 in++;
4500 ctxt->input->col++;
4501 goto get_more;
4502 }
4503 nbchar = in - ctxt->input->cur;
4504 if (nbchar > 0) {
4505 if ((ctxt->sax != NULL) &&
4506 (ctxt->sax->ignorableWhitespace !=
4507 ctxt->sax->characters) &&
4508 (IS_BLANK_CH(*ctxt->input->cur))) {
4509 const xmlChar *tmp = ctxt->input->cur;
4510 ctxt->input->cur = in;
4511
4512 if (areBlanks(ctxt, tmp, nbchar, 0)) {
4513 if (ctxt->sax->ignorableWhitespace != NULL)
4514 ctxt->sax->ignorableWhitespace(ctxt->userData,
4515 tmp, nbchar);
4516 } else {
4517 if (ctxt->sax->characters != NULL)
4518 ctxt->sax->characters(ctxt->userData,
4519 tmp, nbchar);
4520 if (*ctxt->space == -1)
4521 *ctxt->space = -2;
4522 }
4523 line = ctxt->input->line;
4524 col = ctxt->input->col;
4525 } else if (ctxt->sax != NULL) {
4526 if (ctxt->sax->characters != NULL)
4527 ctxt->sax->characters(ctxt->userData,
4528 ctxt->input->cur, nbchar);
4529 line = ctxt->input->line;
4530 col = ctxt->input->col;
4531 }
4532 /* something really bad happened in the SAX callback */
4533 if (ctxt->instate != XML_PARSER_CONTENT)
4534 return;
4535 }
4536 ctxt->input->cur = in;
4537 if (*in == 0xD) {
4538 in++;
4539 if (*in == 0xA) {
4540 ctxt->input->cur = in;
4541 in++;
4542 ctxt->input->line++; ctxt->input->col = 1;
4543 continue; /* while */
4544 }
4545 in--;
4546 }
4547 if (*in == '<') {
4548 return;
4549 }
4550 if (*in == '&') {
4551 return;
4552 }
4553 SHRINK;
4554 GROW;
4555 if (ctxt->instate == XML_PARSER_EOF)
4556 return;
4557 in = ctxt->input->cur;
4558 } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09) || (*in == 0x0a));
4559 nbchar = 0;
4560 }
4561 ctxt->input->line = line;
4562 ctxt->input->col = col;
4563 xmlParseCharDataComplex(ctxt, cdata);
4564}
static int areBlanks(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int blank_chars)
Definition: parser.c:2864
static void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata)
Definition: parser.c:4576
static const unsigned char test_char_data[256]
Definition: parser.c:4373

Referenced by xmlParseContentInternal().

◆ xmlParseCharDataComplex()

static void xmlParseCharDataComplex ( xmlParserCtxtPtr  ctxt,
int  cdata 
)
static

xmlParseCharDataComplex: @ctxt: an XML parser context @cdata: int indicating whether we are within a CDATA section

parse a CharData section.this is the fallback function of xmlParseCharData() when the parsing requires handling of non-ASCII characters.

Definition at line 4576 of file parser.c.

4576 {
4578 int nbchar = 0;
4579 int cur, l;
4580 int count = 0;
4581
4582 SHRINK;
4583 GROW;
4584 cur = CUR_CHAR(l);
4585 while ((cur != '<') && /* checked */
4586 (cur != '&') &&
4587 (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ {
4588 if ((cur == ']') && (NXT(1) == ']') &&
4589 (NXT(2) == '>')) {
4590 if (cdata) break;
4591 else {
4593 }
4594 }
4595 COPY_BUF(l,buf,nbchar,cur);
4596 /* move current position before possible calling of ctxt->sax->characters */
4597 NEXTL(l);
4598 cur = CUR_CHAR(l);
4599 if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) {
4600 buf[nbchar] = 0;
4601
4602 /*
4603 * OK the segment is to be consumed as chars.
4604 */
4605 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
4606 if (areBlanks(ctxt, buf, nbchar, 0)) {
4607 if (ctxt->sax->ignorableWhitespace != NULL)
4608 ctxt->sax->ignorableWhitespace(ctxt->userData,
4609 buf, nbchar);
4610 } else {
4611 if (ctxt->sax->characters != NULL)
4612 ctxt->sax->characters(ctxt->userData, buf, nbchar);
4613 if ((ctxt->sax->characters !=
4614 ctxt->sax->ignorableWhitespace) &&
4615 (*ctxt->space == -1))
4616 *ctxt->space = -2;
4617 }
4618 }
4619 nbchar = 0;
4620 /* something really bad happened in the SAX callback */
4621 if (ctxt->instate != XML_PARSER_CONTENT)
4622 return;
4623 }
4624 count++;
4625 if (count > 50) {
4626 SHRINK;
4627 GROW;
4628 count = 0;
4629 if (ctxt->instate == XML_PARSER_EOF)
4630 return;
4631 }
4632 }
4633 if (nbchar != 0) {
4634 buf[nbchar] = 0;
4635 /*
4636 * OK the segment is to be consumed as chars.
4637 */
4638 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
4639 if (areBlanks(ctxt, buf, nbchar, 0)) {
4640 if (ctxt->sax->ignorableWhitespace != NULL)
4641 ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar);
4642 } else {
4643 if (ctxt->sax->characters != NULL)
4644 ctxt->sax->characters(ctxt->userData, buf, nbchar);
4645 if ((ctxt->sax->characters != ctxt->sax->ignorableWhitespace) &&
4646 (*ctxt->space == -1))
4647 *ctxt->space = -2;
4648 }
4649 }
4650 }
4651 if ((cur != 0) && (!IS_CHAR(cur))) {
4652 /* Generate the error and skip the offending character */
4653 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
4654 "PCDATA invalid Char value %d\n",
4655 cur);
4656 NEXTL(l);
4657 }
4658}
#define XML_PARSER_BIG_BUFFER_SIZE
Definition: parser.c:275

Referenced by xmlParseCharData().

◆ xmlParseCharRef()

int xmlParseCharRef ( xmlParserCtxtPtr  ctxt)

xmlParseCharRef: @ctxt: an XML parser context

parse Reference declarations

[66] CharRef ::= '&#' [0-9]+ ';' | '&x' [0-9a-fA-F]+ ';'

[ WFC: Legal Character ] Characters referred to using character references must match the production for Char.

Returns the value parsed (as an int), 0 in case of error

Definition at line 2332 of file parser.c.

2332 {
2333 int val = 0;
2334 int count = 0;
2335
2336 /*
2337 * Using RAW/CUR/NEXT is okay since we are working on ASCII range here
2338 */
2339 if ((RAW == '&') && (NXT(1) == '#') &&
2340 (NXT(2) == 'x')) {
2341 SKIP(3);
2342 GROW;
2343 while (RAW != ';') { /* loop blocked by count */
2344 if (count++ > 20) {
2345 count = 0;
2346 GROW;
2347 if (ctxt->instate == XML_PARSER_EOF)
2348 return(0);
2349 }
2350 if ((RAW >= '0') && (RAW <= '9'))
2351 val = val * 16 + (CUR - '0');
2352 else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20))
2353 val = val * 16 + (CUR - 'a') + 10;
2354 else if ((RAW >= 'A') && (RAW <= 'F') && (count < 20))
2355 val = val * 16 + (CUR - 'A') + 10;
2356 else {
2358 val = 0;
2359 break;
2360 }
2361 if (val > 0x110000)
2362 val = 0x110000;
2363
2364 NEXT;
2365 count++;
2366 }
2367 if (RAW == ';') {
2368 /* on purpose to avoid reentrancy problems with NEXT and SKIP */
2369 ctxt->input->col++;
2370 ctxt->input->cur++;
2371 }
2372 } else if ((RAW == '&') && (NXT(1) == '#')) {
2373 SKIP(2);
2374 GROW;
2375 while (RAW != ';') { /* loop blocked by count */
2376 if (count++ > 20) {
2377 count = 0;
2378 GROW;
2379 if (ctxt->instate == XML_PARSER_EOF)
2380 return(0);
2381 }
2382 if ((RAW >= '0') && (RAW <= '9'))
2383 val = val * 10 + (CUR - '0');
2384 else {
2386 val = 0;
2387 break;
2388 }
2389 if (val > 0x110000)
2390 val = 0x110000;
2391
2392 NEXT;
2393 count++;
2394 }
2395 if (RAW == ';') {
2396 /* on purpose to avoid reentrancy problems with NEXT and SKIP */
2397 ctxt->input->col++;
2398 ctxt->input->cur++;
2399 }
2400 } else {
2402 }
2403
2404 /*
2405 * [ WFC: Legal Character ]
2406 * Characters referred to using character references must match the
2407 * production for Char.
2408 */
2409 if (val >= 0x110000) {
2410 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2411 "xmlParseCharRef: character reference out of bounds\n",
2412 val);
2413 } else if (IS_CHAR(val)) {
2414 return(val);
2415 } else {
2416 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2417 "xmlParseCharRef: invalid xmlChar value %d\n",
2418 val);
2419 }
2420 return(0);
2421}
#define CUR
Definition: parser.c:2065

Referenced by xmlParseAttValueComplex(), and xmlParseReference().

◆ xmlParseComment()

void xmlParseComment ( xmlParserCtxtPtr  ctxt)

xmlParseComment: @ctxt: an XML parser context

Skip an XML (SGML) comment The spec says that "For compatibility, the string "–" (double-hyphen) must not occur within comments. "

[15] Comment ::= ''

Definition at line 4888 of file parser.c.

4888 {
4889 xmlChar *buf = NULL;
4891 size_t len = 0;
4892 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
4896 const xmlChar *in;
4897 size_t nbchar = 0;
4898 int ccol;
4899 int inputid;
4900
4901 /*
4902 * Check that there is a comment right here.
4903 */
4904 if ((RAW != '<') || (NXT(1) != '!') ||
4905 (NXT(2) != '-') || (NXT(3) != '-')) return;
4906 state = ctxt->instate;
4908 inputid = ctxt->input->id;
4909 SKIP(4);
4910 SHRINK;
4911 GROW;
4912
4913 /*
4914 * Accelerated common case where input don't need to be
4915 * modified before passing it to the handler.
4916 */
4917 in = ctxt->input->cur;
4918 do {
4919 if (*in == 0xA) {
4920 do {
4921 ctxt->input->line++; ctxt->input->col = 1;
4922 in++;
4923 } while (*in == 0xA);
4924 }
4925get_more:
4926 ccol = ctxt->input->col;
4927 while (((*in > '-') && (*in <= 0x7F)) ||
4928 ((*in >= 0x20) && (*in < '-')) ||
4929 (*in == 0x09)) {
4930 in++;
4931 ccol++;
4932 }
4933 ctxt->input->col = ccol;
4934 if (*in == 0xA) {
4935 do {
4936 ctxt->input->line++; ctxt->input->col = 1;
4937 in++;
4938 } while (*in == 0xA);
4939 goto get_more;
4940 }
4941 nbchar = in - ctxt->input->cur;
4942 /*
4943 * save current set of data
4944 */
4945 if (nbchar > 0) {
4946 if ((ctxt->sax != NULL) &&
4947 (ctxt->sax->comment != NULL)) {
4948 if (buf == NULL) {
4949 if ((*in == '-') && (in[1] == '-'))
4950 size = nbchar + 1;
4951 else
4952 size = XML_PARSER_BUFFER_SIZE + nbchar;
4953 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
4954 if (buf == NULL) {
4955 xmlErrMemory(ctxt, NULL);
4956 ctxt->instate = state;
4957 return;
4958 }
4959 len = 0;
4960 } else if (len + nbchar + 1 >= size) {
4961 xmlChar *new_buf;
4962 size += len + nbchar + XML_PARSER_BUFFER_SIZE;
4963 new_buf = (xmlChar *) xmlRealloc(buf,
4964 size * sizeof(xmlChar));
4965 if (new_buf == NULL) {
4966 xmlFree (buf);
4967 xmlErrMemory(ctxt, NULL);
4968 ctxt->instate = state;
4969 return;
4970 }
4971 buf = new_buf;
4972 }
4973 memcpy(&buf[len], ctxt->input->cur, nbchar);
4974 len += nbchar;
4975 buf[len] = 0;
4976 }
4977 }
4978 if (len > maxLength) {
4979 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
4980 "Comment too big found", NULL);
4981 xmlFree (buf);
4982 return;
4983 }
4984 ctxt->input->cur = in;
4985 if (*in == 0xA) {
4986 in++;
4987 ctxt->input->line++; ctxt->input->col = 1;
4988 }
4989 if (*in == 0xD) {
4990 in++;
4991 if (*in == 0xA) {
4992 ctxt->input->cur = in;
4993 in++;
4994 ctxt->input->line++; ctxt->input->col = 1;
4995 goto get_more;
4996 }
4997 in--;
4998 }
4999 SHRINK;
5000 GROW;
5001 if (ctxt->instate == XML_PARSER_EOF) {
5002 xmlFree(buf);
5003 return;
5004 }
5005 in = ctxt->input->cur;
5006 if (*in == '-') {
5007 if (in[1] == '-') {
5008 if (in[2] == '>') {
5009 if (ctxt->input->id != inputid) {
5010 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5011 "comment doesn't start and stop in the"
5012 " same entity\n");
5013 }
5014 SKIP(3);
5015 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
5016 (!ctxt->disableSAX)) {
5017 if (buf != NULL)
5018 ctxt->sax->comment(ctxt->userData, buf);
5019 else
5020 ctxt->sax->comment(ctxt->userData, BAD_CAST "");
5021 }
5022 if (buf != NULL)
5023 xmlFree(buf);
5024 if (ctxt->instate != XML_PARSER_EOF)
5025 ctxt->instate = state;
5026 return;
5027 }
5028 if (buf != NULL) {
5029 xmlFatalErrMsgStr(ctxt, XML_ERR_HYPHEN_IN_COMMENT,
5030 "Double hyphen within comment: "
5031 "<!--%.50s\n",
5032 buf);
5033 } else
5034 xmlFatalErrMsgStr(ctxt, XML_ERR_HYPHEN_IN_COMMENT,
5035 "Double hyphen within comment\n", NULL);
5036 if (ctxt->instate == XML_PARSER_EOF) {
5037 xmlFree(buf);
5038 return;
5039 }
5040 in++;
5041 ctxt->input->col++;
5042 }
5043 in++;
5044 ctxt->input->col++;
5045 goto get_more;
5046 }
5047 } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09) || (*in == 0x0a));
5049 ctxt->instate = state;
5050 return;
5051}
static int state
Definition: maze.c:121
xmlParserInputState
Definition: parser.h:110
@ XML_PARSER_COMMENT
Definition: parser.h:117
static void xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, size_t len, size_t size)
Definition: parser.c:4750
@ XML_ERR_COMMENT_NOT_FINISHED
Definition: xmlerror.h:145

Referenced by xmlParseContentInternal(), xmlParseMarkupDecl(), and xmlParseMisc().

◆ xmlParseCommentComplex()

static void xmlParseCommentComplex ( xmlParserCtxtPtr  ctxt,
xmlChar buf,
size_t  len,
size_t  size 
)
static

xmlParseCommentComplex: @ctxt: an XML parser context @buf: the already parsed part of the buffer @len: number of bytes in the buffer @size: allocated size of the buffer

Skip an XML (SGML) comment The spec says that "For compatibility, the string "–" (double-hyphen) must not occur within comments. " This is the slow routine in case the accelerator for ascii didn't work

[15] Comment ::= ''

Definition at line 4750 of file parser.c.

4751 {
4752 int q, ql;
4753 int r, rl;
4754 int cur, l;
4755 size_t count = 0;
4756 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
4759 int inputid;
4760
4761 inputid = ctxt->input->id;
4762
4763 if (buf == NULL) {
4764 len = 0;
4766 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
4767 if (buf == NULL) {
4768 xmlErrMemory(ctxt, NULL);
4769 return;
4770 }
4771 }
4772 GROW; /* Assure there's enough input data */
4773 q = CUR_CHAR(ql);
4774 if (q == 0)
4775 goto not_terminated;
4776 if (!IS_CHAR(q)) {
4777 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
4778 "xmlParseComment: invalid xmlChar value %d\n",
4779 q);
4780 xmlFree (buf);
4781 return;
4782 }
4783 NEXTL(ql);
4784 r = CUR_CHAR(rl);
4785 if (r == 0)
4786 goto not_terminated;
4787 if (!IS_CHAR(r)) {
4788 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
4789 "xmlParseComment: invalid xmlChar value %d\n",
4790 q);
4791 xmlFree (buf);
4792 return;
4793 }
4794 NEXTL(rl);
4795 cur = CUR_CHAR(l);
4796 if (cur == 0)
4797 goto not_terminated;
4798 while (IS_CHAR(cur) && /* checked */
4799 ((cur != '>') ||
4800 (r != '-') || (q != '-'))) {
4801 if ((r == '-') && (q == '-')) {
4803 }
4804 if (len + 5 >= size) {
4805 xmlChar *new_buf;
4806 size_t new_size;
4807
4808 new_size = size * 2;
4809 new_buf = (xmlChar *) xmlRealloc(buf, new_size);
4810 if (new_buf == NULL) {
4811 xmlFree (buf);
4812 xmlErrMemory(ctxt, NULL);
4813 return;
4814 }
4815 buf = new_buf;
4816 size = new_size;
4817 }
4818 COPY_BUF(ql,buf,len,q);
4819 q = r;
4820 ql = rl;
4821 r = cur;
4822 rl = l;
4823
4824 count++;
4825 if (count > 50) {
4826 SHRINK;
4827 GROW;
4828 count = 0;
4829 if (ctxt->instate == XML_PARSER_EOF) {
4830 xmlFree(buf);
4831 return;
4832 }
4833 }
4834 NEXTL(l);
4835 cur = CUR_CHAR(l);
4836 if (cur == 0) {
4837 SHRINK;
4838 GROW;
4839 cur = CUR_CHAR(l);
4840 }
4841
4842 if (len > maxLength) {
4843 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
4844 "Comment too big found", NULL);
4845 xmlFree (buf);
4846 return;
4847 }
4848 }
4849 buf[len] = 0;
4850 if (cur == 0) {
4851 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
4852 "Comment not terminated \n<!--%.50s\n", buf);
4853 } else if (!IS_CHAR(cur)) {
4854 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
4855 "xmlParseComment: invalid xmlChar value %d\n",
4856 cur);
4857 } else {
4858 if (inputid != ctxt->input->id) {
4859 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
4860 "Comment doesn't start and stop in the same"
4861 " entity\n");
4862 }
4863 NEXT;
4864 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
4865 (!ctxt->disableSAX))
4866 ctxt->sax->comment(ctxt->userData, buf);
4867 }
4868 xmlFree(buf);
4869 return;
4870not_terminated:
4871 xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
4872 "Comment not terminated\n", NULL);
4873 xmlFree(buf);
4874 return;
4875}
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Referenced by xmlParseComment().

◆ xmlParseConditionalSections()

static void xmlParseConditionalSections ( xmlParserCtxtPtr  ctxt)
static

xmlParseConditionalSections @ctxt: an XML parser context

[61] conditionalSect ::= includeSect | ignoreSect [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)

Definition at line 6703 of file parser.c.

6703 {
6704 int *inputIds = NULL;
6705 size_t inputIdsSize = 0;
6706 size_t depth = 0;
6707
6708 while (ctxt->instate != XML_PARSER_EOF) {
6709 if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
6710 int id = ctxt->input->id;
6711
6712 SKIP(3);
6714
6715 if (CMP7(CUR_PTR, 'I', 'N', 'C', 'L', 'U', 'D', 'E')) {
6716 SKIP(7);
6718 if (RAW != '[') {
6720 xmlHaltParser(ctxt);
6721 goto error;
6722 }
6723 if (ctxt->input->id != id) {
6724 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6725 "All markup of the conditional section is"
6726 " not in the same entity\n");
6727 }
6728 NEXT;
6729
6730 if (inputIdsSize <= depth) {
6731 int *tmp;
6732
6733 inputIdsSize = (inputIdsSize == 0 ? 4 : inputIdsSize * 2);
6734 tmp = (int *) xmlRealloc(inputIds,
6735 inputIdsSize * sizeof(int));
6736 if (tmp == NULL) {
6737 xmlErrMemory(ctxt, NULL);
6738 goto error;
6739 }
6740 inputIds = tmp;
6741 }
6742 inputIds[depth] = id;
6743 depth++;
6744 } else if (CMP6(CUR_PTR, 'I', 'G', 'N', 'O', 'R', 'E')) {
6745 int state;
6746 xmlParserInputState instate;
6747 size_t ignoreDepth = 0;
6748
6749 SKIP(6);
6751 if (RAW != '[') {
6753 xmlHaltParser(ctxt);
6754 goto error;
6755 }
6756 if (ctxt->input->id != id) {
6757 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6758 "All markup of the conditional section is"
6759 " not in the same entity\n");
6760 }
6761 NEXT;
6762
6763 /*
6764 * Parse up to the end of the conditional section but disable
6765 * SAX event generating DTD building in the meantime
6766 */
6767 state = ctxt->disableSAX;
6768 instate = ctxt->instate;
6769 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
6770 ctxt->instate = XML_PARSER_IGNORE;
6771
6772 while (RAW != 0) {
6773 if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
6774 SKIP(3);
6775 ignoreDepth++;
6776 /* Check for integer overflow */
6777 if (ignoreDepth == 0) {
6778 xmlErrMemory(ctxt, NULL);
6779 goto error;
6780 }
6781 } else if ((RAW == ']') && (NXT(1) == ']') &&
6782 (NXT(2) == '>')) {
6783 if (ignoreDepth == 0)
6784 break;
6785 SKIP(3);
6786 ignoreDepth--;
6787 } else {
6788 NEXT;
6789 }
6790 }
6791
6792 ctxt->disableSAX = state;
6793 ctxt->instate = instate;
6794
6795 if (RAW == 0) {
6797 goto error;
6798 }
6799 if (ctxt->input->id != id) {
6800 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6801 "All markup of the conditional section is"
6802 " not in the same entity\n");
6803 }
6804 SKIP(3);
6805 } else {
6807 xmlHaltParser(ctxt);
6808 goto error;
6809 }
6810 } else if ((depth > 0) &&
6811 (RAW == ']') && (NXT(1) == ']') && (NXT(2) == '>')) {
6812 depth--;
6813 if (ctxt->input->id != inputIds[depth]) {
6814 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6815 "All markup of the conditional section is not"
6816 " in the same entity\n");
6817 }
6818 SKIP(3);
6819 } else {
6820 int id = ctxt->input->id;
6821 unsigned long cons = CUR_CONSUMED;
6822
6823 xmlParseMarkupDecl(ctxt);
6824
6825 if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) {
6827 xmlHaltParser(ctxt);
6828 goto error;
6829 }
6830 }
6831
6832 if (depth == 0)
6833 break;
6834
6836 GROW;
6837 }
6838
6839error:
6840 xmlFree(inputIds);
6841}
pair cons(caddr_t car, pair cdr)
Definition: tree.c:57
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint id
Definition: glext.h:5910
@ XML_PARSER_IGNORE
Definition: parser.h:127
#define CUR_CONSUMED
Definition: parser.c:2170
void xmlParseMarkupDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:6866

Referenced by xmlParseExternalSubset(), and xmlParseInternalSubset().

◆ xmlParseContent()

void xmlParseContent ( xmlParserCtxtPtr  ctxt)

xmlParseContent: @ctxt: an XML parser context

Parse a content sequence. Stops at EOF or '</'.

[43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*

Definition at line 9958 of file parser.c.

9958 {
9959 int nameNr = ctxt->nameNr;
9960
9962
9963 if ((ctxt->instate != XML_PARSER_EOF) && (ctxt->nameNr > nameNr)) {
9964 const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
9965 int line = ctxt->pushTab[ctxt->nameNr - 1].line;
9966 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
9967 "Premature end of data in tag %s line %d\n",
9968 name, line, NULL);
9969 }
9970}
static void xmlParseContentInternal(xmlParserCtxtPtr ctxt)
Definition: parser.c:9873
int line
Definition: parser.c:80
@ XML_ERR_TAG_NOT_FINISHED
Definition: xmlerror.h:177

Referenced by xmlParseBalancedChunkMemoryInternal(), xmlParseExternalEntityPrivate(), xmlParseExtParsedEnt(), and xmlParseInNodeContext().

◆ xmlParseContentInternal()

static void xmlParseContentInternal ( xmlParserCtxtPtr  ctxt)
static

xmlParseContentInternal: @ctxt: an XML parser context

Parse a content sequence. Stops at EOF or '</'. Leaves checking of unexpected EOF to the caller.

Definition at line 9873 of file parser.c.

9873 {
9874 int nameNr = ctxt->nameNr;
9875
9876 GROW;
9877 while ((RAW != 0) &&
9878 (ctxt->instate != XML_PARSER_EOF)) {
9879 int id = ctxt->input->id;
9880 unsigned long cons = CUR_CONSUMED;
9881 const xmlChar *cur = ctxt->input->cur;
9882
9883 /*
9884 * First case : a Processing Instruction.
9885 */
9886 if ((*cur == '<') && (cur[1] == '?')) {
9887 xmlParsePI(ctxt);
9888 }
9889
9890 /*
9891 * Second case : a CDSection
9892 */
9893 /* 2.6.0 test was *cur not RAW */
9894 else if (CMP9(CUR_PTR, '<', '!', '[', 'C', 'D', 'A', 'T', 'A', '[')) {
9895 xmlParseCDSect(ctxt);
9896 }
9897
9898 /*
9899 * Third case : a comment
9900 */
9901 else if ((*cur == '<') && (NXT(1) == '!') &&
9902 (NXT(2) == '-') && (NXT(3) == '-')) {
9903 xmlParseComment(ctxt);
9905 }
9906
9907 /*
9908 * Fourth case : a sub-element.
9909 */
9910 else if (*cur == '<') {
9911 if (NXT(1) == '/') {
9912 if (ctxt->nameNr <= nameNr)
9913 break;
9914 xmlParseElementEnd(ctxt);
9915 } else {
9917 }
9918 }
9919
9920 /*
9921 * Fifth case : a reference. If if has not been resolved,
9922 * parsing returns it's Name, create the node
9923 */
9924
9925 else if (*cur == '&') {
9926 xmlParseReference(ctxt);
9927 }
9928
9929 /*
9930 * Last case, text. Note that References are handled directly.
9931 */
9932 else {
9933 xmlParseCharData(ctxt, 0);
9934 }
9935
9936 GROW;
9937 SHRINK;
9938
9939 if ((cons == CUR_CONSUMED) && (id == ctxt->input->id)) {
9941 "detected an error in element content\n");
9942 xmlHaltParser(ctxt);
9943 break;
9944 }
9945 }
9946}
static int xmlParseElementStart(xmlParserCtxtPtr ctxt)
Definition: parser.c:10015
static void xmlParseElementEnd(xmlParserCtxtPtr ctxt)
Definition: parser.c:10144
void xmlParsePI(xmlParserCtxtPtr ctxt)
Definition: parser.c:5174
void xmlParseCDSect(xmlParserCtxtPtr ctxt)
Definition: parser.c:9765
void xmlParseReference(xmlParserCtxtPtr ctxt)
Definition: parser.c:7078
void xmlParseComment(xmlParserCtxtPtr ctxt)
Definition: parser.c:4888
void xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata)
Definition: parser.c:4425

Referenced by xmlParseContent(), and xmlParseElement().

◆ xmlParseCtxtExternalEntity()

int xmlParseCtxtExternalEntity ( xmlParserCtxtPtr  ctx,
const xmlChar URL,
const xmlChar ID,
xmlNodePtr lst 
)

xmlParseCtxtExternalEntity: @ctx: the existing parsing context @URL: the URL for the entity to load @ID: the System ID for the entity to load @lst: the return value for the set of parsed nodes

Parse an external general entity within an existing parsing context An external general parsed entity is well-formed if it matches the production labeled extParsedEnt.

[78] extParsedEnt ::= TextDecl? content

Returns 0 if the entity is well formed, -1 in case of args problem and the parser error code otherwise

Definition at line 12968 of file parser.c.

12969 {
12970 void *userData;
12971
12972 if (ctx == NULL) return(-1);
12973 /*
12974 * If the user provided their own SAX callbacks, then reuse the
12975 * userData callback field, otherwise the expected setup in a
12976 * DOM builder is to have userData == ctxt
12977 */
12978 if (ctx->userData == ctx)
12979 userData = NULL;
12980 else
12981 userData = ctx->userData;
12982 return xmlParseExternalEntityPrivate(ctx->myDoc, ctx, ctx->sax,
12983 userData, ctx->depth + 1,
12984 URL, ID, lst);
12985}
static xmlParserErrors xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt, xmlSAXHandlerPtr sax, void *user_data, int depth, const xmlChar *URL, const xmlChar *ID, xmlNodePtr *list)
Definition: parser.c:13005

◆ xmlParseDefaultDecl()

int xmlParseDefaultDecl ( xmlParserCtxtPtr  ctxt,
xmlChar **  value 
)

xmlParseDefaultDecl: @ctxt: an XML parser context @value: Receive a possible fixed default value for the attribute

Parse an attribute default declaration

[60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('FIXED' S)? AttValue)

[ VC: Required Attribute ] if the default declaration is the keyword #REQUIRED, then the attribute must be specified for all elements of the type in the attribute-list declaration.

[ VC: Attribute Default Legal ] The declared default value must meet the lexical constraints of the declared attribute type c.f. xmlValidateAttributeDecl()

[ VC: Fixed Attribute Default ] if an attribute has a default value declared with the FIXED keyword, instances of that attribute must match the default value.

[ WFC: No < in Attribute Values ] handled in xmlParseAttValue()

returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED or XML_ATTRIBUTE_FIXED.

Definition at line 5682 of file parser.c.

5682 {
5683 int val;
5684 xmlChar *ret;
5685
5686 *value = NULL;
5687 if (CMP9(CUR_PTR, '#', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D')) {
5688 SKIP(9);
5689 return(XML_ATTRIBUTE_REQUIRED);
5690 }
5691 if (CMP8(CUR_PTR, '#', 'I', 'M', 'P', 'L', 'I', 'E', 'D')) {
5692 SKIP(8);
5693 return(XML_ATTRIBUTE_IMPLIED);
5694 }
5696 if (CMP6(CUR_PTR, '#', 'F', 'I', 'X', 'E', 'D')) {
5697 SKIP(6);
5699 if (SKIP_BLANKS == 0) {
5700 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5701 "Space required after '#FIXED'\n");
5702 }
5703 }
5704 ret = xmlParseAttValue(ctxt);
5705 ctxt->instate = XML_PARSER_DTD;
5706 if (ret == NULL) {
5707 xmlFatalErrMsg(ctxt, (xmlParserErrors)ctxt->errNo,
5708 "Attribute default value declaration error\n");
5709 } else
5710 *value = ret;
5711 return(val);
5712}
@ XML_PARSER_DTD
Definition: parser.h:115
@ XML_ATTRIBUTE_NONE
Definition: tree.h:226
@ XML_ATTRIBUTE_FIXED
Definition: tree.h:229
xmlChar * xmlParseAttValue(xmlParserCtxtPtr ctxt)
Definition: parser.c:4182

Referenced by xmlParseAttributeListDecl().

◆ xmlParseDocTypeDecl()

void xmlParseDocTypeDecl ( xmlParserCtxtPtr  ctxt)

xmlParseDocTypeDecl: @ctxt: an XML parser context

parse a DOCTYPE declaration

[28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>'

[ VC: Root Element Type ] The Name in the document type declaration must match the element type of the root element.

Definition at line 8282 of file parser.c.

8282 {
8283 const xmlChar *name = NULL;
8284 xmlChar *ExternalID = NULL;
8285 xmlChar *URI = NULL;
8286
8287 /*
8288 * We know that '<!DOCTYPE' has been detected.
8289 */
8290 SKIP(9);
8291
8293
8294 /*
8295 * Parse the DOCTYPE name.
8296 */
8297 name = xmlParseName(ctxt);
8298 if (name == NULL) {
8299 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
8300 "xmlParseDocTypeDecl : no DOCTYPE name !\n");
8301 }
8302 ctxt->intSubName = name;
8303
8305
8306 /*
8307 * Check for SystemID and ExternalID
8308 */
8309 URI = xmlParseExternalID(ctxt, &ExternalID, 1);
8310
8311 if ((URI != NULL) || (ExternalID != NULL)) {
8312 ctxt->hasExternalSubset = 1;
8313 }
8314 ctxt->extSubURI = URI;
8315 ctxt->extSubSystem = ExternalID;
8316
8318
8319 /*
8320 * Create and update the internal subset.
8321 */
8322 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
8323 (!ctxt->disableSAX))
8324 ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI);
8325 if (ctxt->instate == XML_PARSER_EOF)
8326 return;
8327
8328 /*
8329 * Is there any internal subset declarations ?
8330 * they are handled separately in xmlParseInternalSubset()
8331 */
8332 if (RAW == '[')
8333 return;
8334
8335 /*
8336 * We should be at the end of the DOCTYPE declaration.
8337 */
8338 if (RAW != '>') {
8340 }
8341 NEXT;
8342}
xmlChar * xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int strict)
Definition: parser.c:4683
const xmlChar * intSubName
Definition: parser.h:239

Referenced by xmlParseDocument().

◆ xmlParseDocument()

int xmlParseDocument ( xmlParserCtxtPtr  ctxt)

xmlParseDocument: @ctxt: an XML parser context

parse an XML document (and build a tree if using the standard SAX interface).

[1] document ::= prolog element Misc*

[22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?

Returns 0, -1 in case of error. the parser context is augmented as a result of the parsing.

Definition at line 10697 of file parser.c.

10697 {
10698 xmlChar start[4];
10699 xmlCharEncoding enc;
10700
10701 xmlInitParser();
10702
10703 if ((ctxt == NULL) || (ctxt->input == NULL))
10704 return(-1);
10705
10706 GROW;
10707
10708 /*
10709 * SAX: detecting the level.
10710 */
10711 xmlDetectSAX2(ctxt);
10712
10713 /*
10714 * SAX: beginning of the document processing.
10715 */
10716 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10717 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10718 if (ctxt->instate == XML_PARSER_EOF)
10719 return(-1);
10720
10721 if ((ctxt->encoding == NULL) &&
10722 ((ctxt->input->end - ctxt->input->cur) >= 4)) {
10723 /*
10724 * Get the 4 first bytes and decode the charset
10725 * if enc != XML_CHAR_ENCODING_NONE
10726 * plug some encoding conversion routines.
10727 */
10728 start[0] = RAW;
10729 start[1] = NXT(1);
10730 start[2] = NXT(2);
10731 start[3] = NXT(3);
10732 enc = xmlDetectCharEncoding(&start[0], 4);
10733 if (enc != XML_CHAR_ENCODING_NONE) {
10734 xmlSwitchEncoding(ctxt, enc);
10735 }
10736 }
10737
10738
10739 if (CUR == 0) {
10741 return(-1);
10742 }
10743
10744 /*
10745 * Check for the XMLDecl in the Prolog.
10746 * do not GROW here to avoid the detected encoder to decode more
10747 * than just the first line, unless the amount of data is really
10748 * too small to hold "<?xml version="1.0" encoding="foo"
10749 */
10750 if ((ctxt->input->end - ctxt->input->cur) < 35) {
10751 GROW;
10752 }
10753 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
10754
10755 /*
10756 * Note that we will switch encoding on the fly.
10757 */
10758 xmlParseXMLDecl(ctxt);
10759 if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
10760 (ctxt->instate == XML_PARSER_EOF)) {
10761 /*
10762 * The XML REC instructs us to stop parsing right here
10763 */
10764 return(-1);
10765 }
10766 ctxt->standalone = ctxt->input->standalone;
10768 } else {
10770 }
10771 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
10772 ctxt->sax->startDocument(ctxt->userData);
10773 if (ctxt->instate == XML_PARSER_EOF)
10774 return(-1);
10775 if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
10776 (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
10777 ctxt->myDoc->compression = ctxt->input->buf->compressed;
10778 }
10779
10780 /*
10781 * The Misc part of the Prolog
10782 */
10783 xmlParseMisc(ctxt);
10784
10785 /*
10786 * Then possibly doc type declaration(s) and more Misc
10787 * (doctypedecl Misc*)?
10788 */
10789 GROW;
10790 if (CMP9(CUR_PTR, '<', '!', 'D', 'O', 'C', 'T', 'Y', 'P', 'E')) {
10791
10792 ctxt->inSubset = 1;
10793 xmlParseDocTypeDecl(ctxt);
10794 if (RAW == '[') {
10795 ctxt->instate = XML_PARSER_DTD;
10797 if (ctxt->instate == XML_PARSER_EOF)
10798 return(-1);
10799 }
10800
10801 /*
10802 * Create and update the external subset.
10803 */
10804 ctxt->inSubset = 2;
10805 if ((ctxt->sax != NULL) && (ctxt->sax->externalSubset != NULL) &&
10806 (!ctxt->disableSAX))
10807 ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName,
10808 ctxt->extSubSystem, ctxt->extSubURI);
10809 if (ctxt->instate == XML_PARSER_EOF)
10810 return(-1);
10811 ctxt->inSubset = 0;
10812
10813 xmlCleanSpecialAttr(ctxt);
10814
10815 ctxt->instate = XML_PARSER_PROLOG;
10816 xmlParseMisc(ctxt);
10817 }
10818
10819 /*
10820 * Time to start parsing the tree itself
10821 */
10822 GROW;
10823 if (RAW != '<') {
10824 xmlFatalErrMsg(ctxt, XML_ERR_DOCUMENT_EMPTY,
10825 "Start tag expected, '<' not found\n");
10826 } else {
10828 xmlParseElement(ctxt);
10829 ctxt->instate = XML_PARSER_EPILOG;
10830
10831
10832 /*
10833 * The Misc part at the end
10834 */
10835 xmlParseMisc(ctxt);
10836
10837 if (RAW != 0) {
10839 }
10840 ctxt->instate = XML_PARSER_EOF;
10841 }
10842
10843 /*
10844 * SAX: end of the document processing.
10845 */
10846 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10847 ctxt->sax->endDocument(ctxt->userData);
10848
10849 /*
10850 * Remove locally kept entity definitions if the tree was not built
10851 */
10852 if ((ctxt->myDoc != NULL) &&
10854 xmlFreeDoc(ctxt->myDoc);
10855 ctxt->myDoc = NULL;
10856 }
10857
10858 if ((ctxt->wellFormed) && (ctxt->myDoc != NULL)) {
10860 if (ctxt->valid)
10862 if (ctxt->nsWellFormed)
10864 if (ctxt->options & XML_PARSE_OLD10)
10865 ctxt->myDoc->properties |= XML_DOC_OLD10;
10866 }
10867 if (! ctxt->wellFormed) {
10868 ctxt->valid = 0;
10869 return(-1);
10870 }
10871 return(0);
10872}
XMLPUBVAR xmlSAXLocator xmlDefaultSAXLocator
Definition: globals.h:320
@ XML_PARSER_PROLOG
Definition: parser.h:116
@ XML_PARSER_EPILOG
Definition: parser.h:126
#define XML_DEFAULT_VERSION
Definition: parser.h:31
@ XML_DOC_WELLFORMED
Definition: tree.h:533
@ XML_DOC_NSVALID
Definition: tree.h:534
@ XML_DOC_OLD10
Definition: tree.h:535
@ XML_DOC_DTDVALID
Definition: tree.h:536
void xmlParseElement(xmlParserCtxtPtr ctxt)
Definition: parser.c:9987
void xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:8282
static void xmlParseInternalSubset(xmlParserCtxtPtr ctxt)
Definition: parser.c:8354
void xmlParseMisc(xmlParserCtxtPtr ctxt)
Definition: parser.c:10667
static void xmlCleanSpecialAttr(xmlParserCtxtPtr ctxt)
Definition: parser.c:1401
#define SAX_COMPAT_MODE
Definition: parser.c:277
void xmlParseXMLDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:10552
const xmlChar * version
Definition: tree.h:573
int compression
Definition: tree.h:563
int standalone
Definition: parser.h:73
XMLPUBFUN xmlChar *XMLCALL xmlCharStrdup(const char *cur)
Definition: xmlstring.c:114

Referenced by testSAX(), xmlDoRead(), and xsltDocDefaultLoaderFunc().

◆ xmlParseElement()

void xmlParseElement ( xmlParserCtxtPtr  ctxt)

xmlParseElement: @ctxt: an XML parser context

parse an XML element

[39] element ::= EmptyElemTag | STag content ETag

[ WFC: Element Type Match ] The Name in an element's end-tag must match the element type in the start-tag.

Definition at line 9987 of file parser.c.

9987 {
9988 if (xmlParseElementStart(ctxt) != 0)
9989 return;
9990
9992 if (ctxt->instate == XML_PARSER_EOF)
9993 return;
9994
9995 if (CUR == 0) {
9996 const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
9997 int line = ctxt->pushTab[ctxt->nameNr - 1].line;
9998 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
9999 "Premature end of data in tag %s line %d\n",
10000 name, line, NULL);
10001 return;
10002 }
10003
10004 xmlParseElementEnd(ctxt);
10005}

Referenced by xmlParseDocument().

◆ xmlParseElementChildrenContentDecl()

xmlElementContentPtr xmlParseElementChildrenContentDecl ( xmlParserCtxtPtr  ctxt,
int  inputchk 
)

xmlParseElementChildrenContentDecl: @ctxt: an XML parser context @inputchk: the input used for the current entity, needed for boundary checks

parse the declaration for a Mixed Element content The leading '(' and spaces have been skipped in xmlParseElementContentDecl

[47] children ::= (choice | seq) ('?' | '*' | '+')?

[48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?

[49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'

[50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'

[ VC: Proper Group/PE Nesting ] applies to [49] and [50] TODO Parameter-entity replacement text must be properly nested with parenthesized groups. That is to say, if either of the opening or closing parentheses in a choice, seq, or Mixed construct is contained in the replacement text for a parameter entity, both must be contained in the same replacement text. For interoperability, if a parameter-entity reference appears in a choice, seq, or Mixed construct, its replacement text should not be empty, and neither the first nor last non-blank character of the replacement text should be a connector (| or ,).

Returns the tree of xmlElementContentPtr describing the element hierarchy.

Definition at line 6533 of file parser.c.

6533 {
6534 /* stub left for API/ABI compat */
6535 return(xmlParseElementChildrenContentDeclPriv(ctxt, inputchk, 1));
6536}
static xmlElementContentPtr xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int inputchk, int depth)
Definition: parser.c:6230

◆ xmlParseElementChildrenContentDeclPriv()

static xmlElementContentPtr xmlParseElementChildrenContentDeclPriv ( xmlParserCtxtPtr  ctxt,
int  inputchk,
int  depth 
)
static

xmlParseElementChildrenContentDeclPriv: @ctxt: an XML parser context @inputchk: the input used for the current entity, needed for boundary checks @depth: the level of recursion

parse the declaration for a Mixed Element content The leading '(' and spaces have been skipped in xmlParseElementContentDecl

[47] children ::= (choice | seq) ('?' | '*' | '+')?

[48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?

[49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'

[50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'

[ VC: Proper Group/PE Nesting ] applies to [49] and [50] TODO Parameter-entity replacement text must be properly nested with parenthesized groups. That is to say, if either of the opening or closing parentheses in a choice, seq, or Mixed construct is contained in the replacement text for a parameter entity, both must be contained in the same replacement text. For interoperability, if a parameter-entity reference appears in a choice, seq, or Mixed construct, its replacement text should not be empty, and neither the first nor last non-blank character of the replacement text should be a connector (| or ,).

Returns the tree of xmlElementContentPtr describing the element hierarchy.

Definition at line 6230 of file parser.c.

6231 {
6233 const xmlChar *elem;
6234 xmlChar type = 0;
6235
6236 if (((depth > 128) && ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
6237 (depth > 2048)) {
6238 xmlFatalErrMsgInt(ctxt, XML_ERR_ELEMCONTENT_NOT_FINISHED,
6239"xmlParseElementChildrenContentDecl : depth %d too deep, use XML_PARSE_HUGE\n",
6240 depth);
6241 return(NULL);
6242 }
6244 GROW;
6245 if (RAW == '(') {
6246 int inputid = ctxt->input->id;
6247
6248 /* Recurse on first child */
6249 NEXT;
6252 depth + 1);
6253 if (cur == NULL)
6254 return(NULL);
6256 GROW;
6257 } else {
6258 elem = xmlParseName(ctxt);
6259 if (elem == NULL) {
6261 return(NULL);
6262 }
6264 if (cur == NULL) {
6265 xmlErrMemory(ctxt, NULL);
6266 return(NULL);
6267 }
6268 GROW;
6269 if (RAW == '?') {
6271 NEXT;
6272 } else if (RAW == '*') {
6274 NEXT;
6275 } else if (RAW == '+') {
6277 NEXT;
6278 } else {
6280 }
6281 GROW;
6282 }
6284 SHRINK;
6285 while ((RAW != ')') && (ctxt->instate != XML_PARSER_EOF)) {
6286 /*
6287 * Each loop we parse one separator and one element.
6288 */
6289 if (RAW == ',') {
6290 if (type == 0) type = CUR;
6291
6292 /*
6293 * Detect "Name | Name , Name" error
6294 */
6295 else if (type != CUR) {
6296 xmlFatalErrMsgInt(ctxt, XML_ERR_SEPARATOR_REQUIRED,
6297 "xmlParseElementChildrenContentDecl : '%c' expected\n",
6298 type);
6299 if ((last != NULL) && (last != ret))
6301 if (ret != NULL)
6303 return(NULL);
6304 }
6305 NEXT;
6306
6308 if (op == NULL) {
6309 if ((last != NULL) && (last != ret))
6312 return(NULL);
6313 }
6314 if (last == NULL) {
6315 op->c1 = ret;
6316 if (ret != NULL)
6317 ret->parent = op;
6318 ret = cur = op;
6319 } else {
6320 cur->c2 = op;
6321 if (op != NULL)
6322 op->parent = cur;
6323 op->c1 = last;
6324 if (last != NULL)
6325 last->parent = op;
6326 cur =op;
6327 last = NULL;
6328 }
6329 } else if (RAW == '|') {
6330 if (type == 0) type = CUR;
6331
6332 /*
6333 * Detect "Name , Name | Name" error
6334 */
6335 else if (type != CUR) {
6336 xmlFatalErrMsgInt(ctxt, XML_ERR_SEPARATOR_REQUIRED,
6337 "xmlParseElementChildrenContentDecl : '%c' expected\n",
6338 type);
6339 if ((last != NULL) && (last != ret))
6341 if (ret != NULL)
6343 return(NULL);
6344 }
6345 NEXT;
6346
6348 if (op == NULL) {
6349 if ((last != NULL) && (last != ret))
6351 if (ret != NULL)
6353 return(NULL);
6354 }
6355 if (last == NULL) {
6356 op->c1 = ret;
6357 if (ret != NULL)
6358 ret->parent = op;
6359 ret = cur = op;
6360 } else {
6361 cur->c2 = op;
6362 if (op != NULL)
6363 op->parent = cur;
6364 op->c1 = last;
6365 if (last != NULL)
6366 last->parent = op;
6367 cur =op;
6368 last = NULL;
6369 }
6370 } else {
6372 if ((last != NULL) && (last != ret))
6374 if (ret != NULL)
6376 return(NULL);
6377 }
6378 GROW;
6380 GROW;
6381 if (RAW == '(') {
6382 int inputid = ctxt->input->id;
6383 /* Recurse on second child */
6384 NEXT;
6387 depth + 1);
6388 if (last == NULL) {
6389 if (ret != NULL)
6391 return(NULL);
6392 }
6394 } else {
6395 elem = xmlParseName(ctxt);
6396 if (elem == NULL) {
6398 if (ret != NULL)
6400 return(NULL);
6401 }
6403 if (last == NULL) {
6404 if (ret != NULL)
6406 return(NULL);
6407 }
6408 if (RAW == '?') {
6410 NEXT;
6411 } else if (RAW == '*') {
6413 NEXT;
6414 } else if (RAW == '+') {
6416 NEXT;
6417 } else {
6419 }
6420 }
6422 GROW;
6423 }
6424 if ((cur != NULL) && (last != NULL)) {
6425 cur->c2 = last;
6426 if (last != NULL)
6427 last->parent = cur;
6428 }
6429 if (ctxt->input->id != inputchk) {
6430 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6431 "Element content declaration doesn't start and stop in"
6432 " the same entity\n");
6433 }
6434 NEXT;
6435 if (RAW == '?') {
6436 if (ret != NULL) {
6437 if ((ret->ocur == XML_ELEMENT_CONTENT_PLUS) ||
6438 (ret->ocur == XML_ELEMENT_CONTENT_MULT))
6440 else
6442 }
6443 NEXT;
6444 } else if (RAW == '*') {
6445 if (ret != NULL) {
6447 cur = ret;
6448 /*
6449 * Some normalization:
6450 * (a | b* | c?)* == (a | b | c)*
6451 */
6452 while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) {
6453 if ((cur->c1 != NULL) &&
6454 ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) ||
6455 (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT)))
6456 cur->c1->ocur = XML_ELEMENT_CONTENT_ONCE;
6457 if ((cur->c2 != NULL) &&
6458 ((cur->c2->ocur == XML_ELEMENT_CONTENT_OPT) ||
6459 (cur->c2->ocur == XML_ELEMENT_CONTENT_MULT)))
6460 cur->c2->ocur = XML_ELEMENT_CONTENT_ONCE;
6461 cur = cur->c2;
6462 }
6463 }
6464 NEXT;
6465 } else if (RAW == '+') {
6466 if (ret != NULL) {
6467 int found = 0;
6468
6469 if ((ret->ocur == XML_ELEMENT_CONTENT_OPT) ||
6470 (ret->ocur == XML_ELEMENT_CONTENT_MULT))
6472 else
6474 /*
6475 * Some normalization:
6476 * (a | b*)+ == (a | b)*
6477 * (a | b?)+ == (a | b)*
6478 */
6479 while ((cur != NULL) && (cur->type == XML_ELEMENT_CONTENT_OR)) {
6480 if ((cur->c1 != NULL) &&
6481 ((cur->c1->ocur == XML_ELEMENT_CONTENT_OPT) ||
6482 (cur->c1->ocur == XML_ELEMENT_CONTENT_MULT))) {
6483 cur->c1->ocur = XML_ELEMENT_CONTENT_ONCE;
6484 found = 1;
6485 }
6486 if ((cur->c2 != NULL) &&
6487 ((cur->c2->ocur == XML_ELEMENT_CONTENT_OPT) ||
6488 (cur->c2->ocur == XML_ELEMENT_CONTENT_MULT))) {
6489 cur->c2->ocur = XML_ELEMENT_CONTENT_ONCE;
6490 found = 1;
6491 }
6492 cur = cur->c2;
6493 }
6494 if (found)
6496 }
6497 NEXT;
6498 }
6499 return(ret);
6500}
UINT op
Definition: effect.c:236
@ XML_ELEMENT_CONTENT_OPT
Definition: tree.h:292
@ XML_ELEMENT_CONTENT_ONCE
Definition: tree.h:291
@ XML_ELEMENT_CONTENT_PLUS
Definition: tree.h:294
@ XML_ELEMENT_CONTENT_MULT
Definition: tree.h:293
@ XML_ELEMENT_CONTENT_ELEMENT
Definition: tree.h:280
@ XML_ELEMENT_CONTENT_OR
Definition: tree.h:282
@ XML_ELEMENT_CONTENT_SEQ
Definition: tree.h:281
XMLPUBFUN xmlElementContentPtr XMLCALL xmlNewDocElementContent(xmlDocPtr doc, const xmlChar *name, xmlElementContentType type)
Definition: valid.c:908
XMLPUBFUN void XMLCALL xmlFreeDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur)
Definition: valid.c:1089
@ XML_ERR_SEPARATOR_REQUIRED
Definition: xmlerror.h:166

Referenced by xmlParseElementChildrenContentDecl(), xmlParseElementChildrenContentDeclPriv(), and xmlParseElementContentDecl().

◆ xmlParseElementContentDecl()

int xmlParseElementContentDecl ( xmlParserCtxtPtr  ctxt,
const xmlChar name,
xmlElementContentPtr result 
)

Definition at line 6553 of file parser.c.

6554 {
6555
6557 int inputid = ctxt->input->id;
6558 int res;
6559
6560 *result = NULL;
6561
6562 if (RAW != '(') {
6563 xmlFatalErrMsgStr(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED,
6564 "xmlParseElementContentDecl : %s '(' expected\n", name);
6565 return(-1);
6566 }
6567 NEXT;
6568 GROW;
6569 if (ctxt->instate == XML_PARSER_EOF)
6570 return(-1);
6572 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {
6573 tree = xmlParseElementMixedContentDecl(ctxt, inputid);
6575 } else {
6576 tree = xmlParseElementChildrenContentDeclPriv(ctxt, inputid, 1);
6578 }
6580 *result = tree;
6581 return(res);
6582}
GLuint res
Definition: glext.h:9613
GLuint64EXT * result
Definition: glext.h:11304
@ XML_ELEMENT_TYPE_MIXED
Definition: tree.h:326
@ XML_ELEMENT_TYPE_ELEMENT
Definition: tree.h:327
xmlElementContentPtr xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk)
Definition: parser.c:6104

Referenced by xmlParseElementDecl().

◆ xmlParseElementDecl()

int xmlParseElementDecl ( xmlParserCtxtPtr  ctxt)

xmlParseElementDecl: @ctxt: an XML parser context

parse an Element declaration.

[45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'

[ VC: Unique Element Type Declaration ] No element type may be declared more than once

Returns the type of the element, or -1 in case of error

Definition at line 6598 of file parser.c.

6598 {
6599 const xmlChar *name;
6600 int ret = -1;
6602
6603 /* GROW; done in the caller */
6604 if (CMP9(CUR_PTR, '<', '!', 'E', 'L', 'E', 'M', 'E', 'N', 'T')) {
6605 int inputid = ctxt->input->id;
6606
6607 SKIP(9);
6608 if (SKIP_BLANKS == 0) {
6609 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6610 "Space required after 'ELEMENT'\n");
6611 return(-1);
6612 }
6613 name = xmlParseName(ctxt);
6614 if (name == NULL) {
6615 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
6616 "xmlParseElementDecl: no name for Element\n");
6617 return(-1);
6618 }
6619 if (SKIP_BLANKS == 0) {
6620 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6621 "Space required after the element name\n");
6622 }
6623 if (CMP5(CUR_PTR, 'E', 'M', 'P', 'T', 'Y')) {
6624 SKIP(5);
6625 /*
6626 * Element must always be empty.
6627 */
6629 } else if ((RAW == 'A') && (NXT(1) == 'N') &&
6630 (NXT(2) == 'Y')) {
6631 SKIP(3);
6632 /*
6633 * Element is a generic container.
6634 */
6636 } else if (RAW == '(') {
6638 } else {
6639 /*
6640 * [ WFC: PEs in Internal Subset ] error handling.
6641 */
6642 if ((RAW == '%') && (ctxt->external == 0) &&
6643 (ctxt->inputNr == 1)) {
6644 xmlFatalErrMsg(ctxt, XML_ERR_PEREF_IN_INT_SUBSET,
6645 "PEReference: forbidden within markup decl in internal subset\n");
6646 } else {
6647 xmlFatalErrMsg(ctxt, XML_ERR_ELEMCONTENT_NOT_STARTED,
6648 "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n");
6649 }
6650 return(-1);
6651 }
6652
6654
6655 if (RAW != '>') {
6657 if (content != NULL) {
6659 }
6660 } else {
6661 if (inputid != ctxt->input->id) {
6662 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6663 "Element declaration doesn't start and stop in"
6664 " the same entity\n");
6665 }
6666
6667 NEXT;
6668 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
6669 (ctxt->sax->elementDecl != NULL)) {
6670 if (content != NULL)
6671 content->parent = NULL;
6672 ctxt->sax->elementDecl(ctxt->userData, name, ret,
6673 content);
6674 if ((content != NULL) && (content->parent == NULL)) {
6675 /*
6676 * this is a trick: if xmlAddElementDecl is called,
6677 * instead of copying the full tree it is plugged directly
6678 * if called from the parser. Avoid duplicating the
6679 * interfaces or change the API/ABI
6680 */
6682 }
6683 } else if (content != NULL) {
6685 }
6686 }
6687 }
6688 return(ret);
6689}
@ XML_ELEMENT_TYPE_EMPTY
Definition: tree.h:324
@ XML_ELEMENT_TYPE_ANY
Definition: tree.h:325
int xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlElementContentPtr *result)
Definition: parser.c:6553

Referenced by xmlParseMarkupDecl().

◆ xmlParseElementEnd()

static void xmlParseElementEnd ( xmlParserCtxtPtr  ctxt)
static

xmlParseElementEnd: @ctxt: an XML parser context

Parse the end of an XML element.

Definition at line 10144 of file parser.c.

10144 {
10145 xmlParserNodeInfo node_info;
10146 xmlNodePtr ret = ctxt->node;
10147
10148 if (ctxt->nameNr <= 0)
10149 return;
10150
10151 /*
10152 * parse the end of tag: '</' should be here.
10153 */
10154 if (ctxt->sax2) {
10155 xmlParseEndTag2(ctxt, &ctxt->pushTab[ctxt->nameNr - 1]);
10156 namePop(ctxt);
10157 }
10158#ifdef LIBXML_SAX1_ENABLED
10159 else
10160 xmlParseEndTag1(ctxt, 0);
10161#endif /* LIBXML_SAX1_ENABLED */
10162
10163 /*
10164 * Capture end position and add node
10165 */
10166 if ( ret != NULL && ctxt->record_info ) {
10167 node_info.end_pos = ctxt->input->consumed +
10168 (CUR_PTR - ctxt->input->base);
10169 node_info.end_line = ctxt->input->line;
10170 node_info.node = ret;
10171 xmlParserAddNodeInfo(ctxt, &node_info);
10172 }
10173}
XMLPUBFUN void XMLCALL xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, const xmlParserNodeInfoPtr info)
static void xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlStartTag *tag)
Definition: parser.c:9697
const xmlChar * namePop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1981
unsigned long consumed
Definition: parser.h:69
const struct _xmlNode * node
Definition: parser.h:88
unsigned long end_pos
Definition: parser.h:92
unsigned long end_line
Definition: parser.h:93

Referenced by xmlParseContentInternal(), and xmlParseElement().

◆ xmlParseElementMixedContentDecl()

xmlElementContentPtr xmlParseElementMixedContentDecl ( xmlParserCtxtPtr  ctxt,
int  inputchk 
)

xmlParseElementMixedContentDecl: @ctxt: an XML parser context @inputchk: the input used for the current entity, needed for boundary checks

parse the declaration for a Mixed Element content The leading '(' and spaces have been skipped in xmlParseElementContentDecl

[51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'

[ VC: Proper Group/PE Nesting ] applies to [51] too (see [49])

[ VC: No Duplicate Types ] The same name must not appear more than once in a single mixed-content declaration.

returns: the list of the xmlElementContentPtr describing the element choices

Definition at line 6104 of file parser.c.

6104 {
6106 const xmlChar *elem = NULL;
6107
6108 GROW;
6109 if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {
6110 SKIP(7);
6112 SHRINK;
6113 if (RAW == ')') {
6114 if (ctxt->input->id != inputchk) {
6115 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6116 "Element content declaration doesn't start and"
6117 " stop in the same entity\n");
6118 }
6119 NEXT;
6121 if (ret == NULL)
6122 return(NULL);
6123 if (RAW == '*') {
6125 NEXT;
6126 }
6127 return(ret);
6128 }
6129 if ((RAW == '(') || (RAW == '|')) {
6131 if (ret == NULL) return(NULL);
6132 }
6133 while ((RAW == '|') && (ctxt->instate != XML_PARSER_EOF)) {
6134 NEXT;
6135 if (elem == NULL) {
6137 if (ret == NULL) {
6139 return(NULL);
6140 }
6141 ret->c1 = cur;
6142 if (cur != NULL)
6143 cur->parent = ret;
6144 cur = ret;
6145 } else {
6147 if (n == NULL) {
6149 return(NULL);
6150 }
6152 if (n->c1 != NULL)
6153 n->c1->parent = n;
6154 cur->c2 = n;
6155 if (n != NULL)
6156 n->parent = cur;
6157 cur = n;
6158 }
6160 elem = xmlParseName(ctxt);
6161 if (elem == NULL) {
6162 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
6163 "xmlParseElementMixedContentDecl : Name expected\n");
6165 return(NULL);
6166 }
6168 GROW;
6169 }
6170 if ((RAW == ')') && (NXT(1) == '*')) {
6171 if (elem != NULL) {
6174 if (cur->c2 != NULL)
6175 cur->c2->parent = cur;
6176 }
6177 if (ret != NULL)
6179 if (ctxt->input->id != inputchk) {
6180 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
6181 "Element content declaration doesn't start and"
6182 " stop in the same entity\n");
6183 }
6184 SKIP(2);
6185 } else {
6188 return(NULL);
6189 }
6190
6191 } else {
6193 }
6194 return(ret);
6195}
@ XML_ELEMENT_CONTENT_PCDATA
Definition: tree.h:279

Referenced by xmlParseElementContentDecl().

◆ xmlParseElementStart()

static int xmlParseElementStart ( xmlParserCtxtPtr  ctxt)
static

xmlParseElementStart: @ctxt: an XML parser context

Parse the start of an XML element. Returns -1 in case of error, 0 if an opening tag was parsed, 1 if an empty element was parsed.

Definition at line 10015 of file parser.c.

10015 {
10016 const xmlChar *name;
10017 const xmlChar *prefix = NULL;
10018 const xmlChar *URI = NULL;
10019 xmlParserNodeInfo node_info;
10020 int line, tlen = 0;
10022 int nsNr = ctxt->nsNr;
10023
10024 if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) &&
10025 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
10026 xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
10027 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
10029 xmlHaltParser(ctxt);
10030 return(-1);
10031 }
10032
10033 /* Capture start position */
10034 if (ctxt->record_info) {
10035 node_info.begin_pos = ctxt->input->consumed +
10036 (CUR_PTR - ctxt->input->base);
10037 node_info.begin_line = ctxt->input->line;
10038 }
10039
10040 if (ctxt->spaceNr == 0)
10041 spacePush(ctxt, -1);
10042 else if (*ctxt->space == -2)
10043 spacePush(ctxt, -1);
10044 else
10045 spacePush(ctxt, *ctxt->space);
10046
10047 line = ctxt->input->line;
10048#ifdef LIBXML_SAX1_ENABLED
10049 if (ctxt->sax2)
10050#endif /* LIBXML_SAX1_ENABLED */
10051 name = xmlParseStartTag2(ctxt, &prefix, &URI, &tlen);
10052#ifdef LIBXML_SAX1_ENABLED
10053 else
10054 name = xmlParseStartTag(ctxt);
10055#endif /* LIBXML_SAX1_ENABLED */
10056 if (ctxt->instate == XML_PARSER_EOF)
10057 return(-1);
10058 if (name == NULL) {
10059 spacePop(ctxt);
10060 return(-1);
10061 }
10062 nameNsPush(ctxt, name, prefix, URI, line, ctxt->nsNr - nsNr);
10063 ret = ctxt->node;
10064
10065#ifdef LIBXML_VALID_ENABLED
10066 /*
10067 * [ VC: Root Element Type ]
10068 * The Name in the document type declaration must match the element
10069 * type of the root element.
10070 */
10071 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
10072 ctxt->node && (ctxt->node == ctxt->myDoc->children))
10073 ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
10074#endif /* LIBXML_VALID_ENABLED */
10075
10076 /*
10077 * Check for an Empty Element.
10078 */
10079 if ((RAW == '/') && (NXT(1) == '>')) {
10080 SKIP(2);
10081 if (ctxt->sax2) {
10082 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) &&
10083 (!ctxt->disableSAX))
10084 ctxt->sax->endElementNs(ctxt->userData, name, prefix, URI);
10085#ifdef LIBXML_SAX1_ENABLED
10086 } else {
10087 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL) &&
10088 (!ctxt->disableSAX))
10089 ctxt->sax->endElement(ctxt->userData, name);
10090#endif /* LIBXML_SAX1_ENABLED */
10091 }
10092 namePop(ctxt);
10093 spacePop(ctxt);
10094 if (nsNr != ctxt->nsNr)
10095 nsPop(ctxt, ctxt->nsNr - nsNr);
10096 if ( ret != NULL && ctxt->record_info ) {
10097 node_info.end_pos = ctxt->input->consumed +
10098 (CUR_PTR - ctxt->input->base);
10099 node_info.end_line = ctxt->input->line;
10100 node_info.node = ret;
10101 xmlParserAddNodeInfo(ctxt, &node_info);
10102 }
10103 return(1);
10104 }
10105 if (RAW == '>') {
10106 NEXT1;
10107 } else {
10108 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_GT_REQUIRED,
10109 "Couldn't find end of Start Tag %s line %d\n",
10110 name, line, NULL);
10111
10112 /*
10113 * end of parsing of this node.
10114 */
10115 nodePop(ctxt);
10116 namePop(ctxt);
10117 spacePop(ctxt);
10118 if (nsNr != ctxt->nsNr)
10119 nsPop(ctxt, ctxt->nsNr - nsNr);
10120
10121 /*
10122 * Capture end position and add node
10123 */
10124 if ( ret != NULL && ctxt->record_info ) {
10125 node_info.end_pos = ctxt->input->consumed +
10126 (CUR_PTR - ctxt->input->base);
10127 node_info.end_line = ctxt->input->line;
10128 node_info.node = ret;
10129 xmlParserAddNodeInfo(ctxt, &node_info);
10130 }
10131 return(-1);
10132 }
10133
10134 return(0);
10135}
static const xmlChar * xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, const xmlChar **URI, int *tlen)
Definition: parser.c:9256
static int spacePop(xmlParserCtxtPtr ctxt)
Definition: parser.c:2016
static int nsPop(xmlParserCtxtPtr ctxt, int nr)
Definition: parser.c:1681
static int nameNsPush(xmlParserCtxtPtr ctxt, const xmlChar *value, const xmlChar *prefix, const xmlChar *URI, int line, int nsNr)
Definition: parser.c:1870
#define NEXT1
Definition: parser.c:2149
static int spacePush(xmlParserCtxtPtr ctxt, int val)
Definition: parser.c:1997
xmlNodePtr nodePop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1839
unsigned long begin_line
Definition: parser.h:91
unsigned long begin_pos
Definition: parser.h:90

Referenced by xmlParseContentInternal(), and xmlParseElement().

◆ xmlParseEncName()

xmlChar * xmlParseEncName ( xmlParserCtxtPtr  ctxt)

xmlParseEncName: @ctxt: an XML parser context

parse the XML encoding name

[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*

Returns the encoding name value or NULL

Definition at line 10293 of file parser.c.

10293 {
10294 xmlChar *buf = NULL;
10295 int len = 0;
10296 int size = 10;
10297 xmlChar cur;
10298
10299 cur = CUR;
10300 if (((cur >= 'a') && (cur <= 'z')) ||
10301 ((cur >= 'A') && (cur <= 'Z'))) {
10302 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
10303 if (buf == NULL) {
10304 xmlErrMemory(ctxt, NULL);
10305 return(NULL);
10306 }
10307
10308 buf[len++] = cur;
10309 NEXT;
10310 cur = CUR;
10311 while (((cur >= 'a') && (cur <= 'z')) ||
10312 ((cur >= 'A') && (cur <= 'Z')) ||
10313 ((cur >= '0') && (cur <= '9')) ||
10314 (cur == '.') || (cur == '_') ||
10315 (cur == '-')) {
10316 if (len + 1 >= size) {
10317 xmlChar *tmp;
10318
10319 size *= 2;
10320 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
10321 if (tmp == NULL) {
10322 xmlErrMemory(ctxt, NULL);
10323 xmlFree(buf);
10324 return(NULL);
10325 }
10326 buf = tmp;
10327 }
10328 buf[len++] = cur;
10329 NEXT;
10330 cur = CUR;
10331 if (cur == 0) {
10332 SHRINK;
10333 GROW;
10334 cur = CUR;
10335 }
10336 }
10337 buf[len] = 0;
10338 } else {
10340 }
10341 return(buf);
10342}

Referenced by xmlParseEncodingDecl().

◆ xmlParseEncodingDecl()

const xmlChar * xmlParseEncodingDecl ( xmlParserCtxtPtr  ctxt)

xmlParseEncodingDecl: @ctxt: an XML parser context

parse the XML encoding declaration

[80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'")

this setups the conversion filters.

Returns the encoding value or NULL

Definition at line 10358 of file parser.c.

10358 {
10360
10362 if (CMP8(CUR_PTR, 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g')) {
10363 SKIP(8);
10365 if (RAW != '=') {
10367 return(NULL);
10368 }
10369 NEXT;
10371 if (RAW == '"') {
10372 NEXT;
10373 encoding = xmlParseEncName(ctxt);
10374 if (RAW != '"') {
10377 return(NULL);
10378 } else
10379 NEXT;
10380 } else if (RAW == '\''){
10381 NEXT;
10382 encoding = xmlParseEncName(ctxt);
10383 if (RAW != '\'') {
10386 return(NULL);
10387 } else
10388 NEXT;
10389 } else {
10391 }
10392
10393 /*
10394 * Non standard parsing, allowing the user to ignore encoding
10395 */
10396 if (ctxt->options & XML_PARSE_IGNORE_ENC) {
10398 return(NULL);
10399 }
10400
10401 /*
10402 * UTF-16 encoding switch has already taken place at this stage,
10403 * more over the little-endian/big-endian selection is already done
10404 */
10405 if ((encoding != NULL) &&
10406 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-16")) ||
10407 (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) {
10408 /*
10409 * If no encoding was passed to the parser, that we are
10410 * using UTF-16 and no decoder is present i.e. the
10411 * document is apparently UTF-8 compatible, then raise an
10412 * encoding mismatch fatal error
10413 */
10414 if ((ctxt->encoding == NULL) &&
10415 (ctxt->input->buf != NULL) &&
10416 (ctxt->input->buf->encoder == NULL)) {
10417 xmlFatalErrMsg(ctxt, XML_ERR_INVALID_ENCODING,
10418 "Document labelled UTF-16 but has UTF-8 content\n");
10419 }
10420 if (ctxt->encoding != NULL)
10421 xmlFree((xmlChar *) ctxt->encoding);
10422 ctxt->encoding = encoding;
10423 }
10424 /*
10425 * UTF-8 encoding is handled natively
10426 */
10427 else if ((encoding != NULL) &&
10428 ((!xmlStrcasecmp(encoding, BAD_CAST "UTF-8")) ||
10429 (!xmlStrcasecmp(encoding, BAD_CAST "UTF8")))) {
10430 if (ctxt->encoding != NULL)
10431 xmlFree((xmlChar *) ctxt->encoding);
10432 ctxt->encoding = encoding;
10433 }
10434 else if (encoding != NULL) {
10436
10437 if (ctxt->input->encoding != NULL)
10438 xmlFree((xmlChar *) ctxt->input->encoding);
10439 ctxt->input->encoding = encoding;
10440
10442 if (handler != NULL) {
10443 if (xmlSwitchToEncoding(ctxt, handler) < 0) {
10444 /* failed to convert */
10446 return(NULL);
10447 }
10448 } else {
10449 xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
10450 "Unsupported encoding %s\n", encoding);
10451 return(NULL);
10452 }
10453 }
10454 }
10455 return(encoding);
10456}
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
xmlChar * xmlParseEncName(xmlParserCtxtPtr ctxt)
Definition: parser.c:10293
xmlCharEncodingHandlerPtr encoder
Definition: xmlIO.h:130
const xmlChar * encoding
Definition: parser.h:71
@ XML_ERR_INVALID_ENCODING
Definition: xmlerror.h:181
XMLPUBFUN int XMLCALL xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:275

Referenced by xmlParseTextDecl(), and xmlParseXMLDecl().

◆ xmlParseEndTag2()

static void xmlParseEndTag2 ( xmlParserCtxtPtr  ctxt,
const xmlStartTag tag 
)
static

xmlParseEndTag2: @ctxt: an XML parser context line of the start tag @nsNr: number of namespaces on the start tag

parse an end of tag

[42] ETag ::= '</' Name S? '>'

With namespace

[NS 9] ETag ::= '</' QName S? '>'

Definition at line 9697 of file parser.c.

9697 {
9698 const xmlChar *name;
9699
9700 GROW;
9701 if ((RAW != '<') || (NXT(1) != '/')) {
9703 return;
9704 }
9705 SKIP(2);
9706
9707 if (tag->prefix == NULL)
9708 name = xmlParseNameAndCompare(ctxt, ctxt->name);
9709 else
9710 name = xmlParseQNameAndCompare(ctxt, ctxt->name, tag->prefix);
9711
9712 /*
9713 * We should definitely be at the ending "S? '>'" part
9714 */
9715 GROW;
9716 if (ctxt->instate == XML_PARSER_EOF)
9717 return;
9719 if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
9721 } else
9722 NEXT1;
9723
9724 /*
9725 * [ WFC: Element Type Match ]
9726 * The Name in an element's end-tag must match the element type in the
9727 * start-tag.
9728 *
9729 */
9730 if (name != (xmlChar*)1) {
9731 if (name == NULL) name = BAD_CAST "unparsable";
9732 xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NAME_MISMATCH,
9733 "Opening and ending tag mismatch: %s line %d and %s\n",
9734 ctxt->name, tag->line, name);
9735 }
9736
9737 /*
9738 * SAX: End of Tag
9739 */
9740 if ((ctxt->sax != NULL) && (ctxt->sax->endElementNs != NULL) &&
9741 (!ctxt->disableSAX))
9742 ctxt->sax->endElementNs(ctxt->userData, ctxt->name, tag->prefix,
9743 tag->URI);
9744
9745 spacePop(ctxt);
9746 if (tag->nsNr != 0)
9747 nsPop(ctxt, tag->nsNr);
9748}
#define IS_BYTE_CHAR(c)
static const xmlChar * xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *other)
Definition: parser.c:3525
static const xmlChar * xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name, xmlChar const *prefix)
Definition: parser.c:8873
@ XML_ERR_TAG_NAME_MISMATCH
Definition: xmlerror.h:176

Referenced by xmlParseElementEnd().

◆ xmlParseEntityDecl()

void xmlParseEntityDecl ( xmlParserCtxtPtr  ctxt)

xmlParseEntityDecl: @ctxt: an XML parser context

parse <!ENTITY declarations

[70] EntityDecl ::= GEDecl | PEDecl

[71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'

[72] PEDecl ::= '<!ENTITY' S '' S Name S PEDef S? '>'

[73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)

[74] PEDef ::= EntityValue | ExternalID

[76] NDataDecl ::= S 'NDATA' S Name

[ VC: Notation Declared ] The Name must match the declared name of a notation.

Definition at line 5409 of file parser.c.

5409 {
5410 const xmlChar *name = NULL;
5411 xmlChar *value = NULL;
5412 xmlChar *URI = NULL, *literal = NULL;
5413 const xmlChar *ndata = NULL;
5414 int isParameter = 0;
5415 xmlChar *orig = NULL;
5416
5417 /* GROW; done in the caller */
5418 if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) {
5419 int inputid = ctxt->input->id;
5420 SHRINK;
5421 SKIP(8);
5422 if (SKIP_BLANKS == 0) {
5423 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5424 "Space required after '<!ENTITY'\n");
5425 }
5426
5427 if (RAW == '%') {
5428 NEXT;
5429 if (SKIP_BLANKS == 0) {
5430 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5431 "Space required after '%%'\n");
5432 }
5433 isParameter = 1;
5434 }
5435
5436 name = xmlParseName(ctxt);
5437 if (name == NULL) {
5438 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
5439 "xmlParseEntityDecl: no name\n");
5440 return;
5441 }
5442 if (xmlStrchr(name, ':') != NULL) {
5443 xmlNsErr(ctxt, XML_NS_ERR_COLON,
5444 "colons are forbidden from entities names '%s'\n",
5445 name, NULL, NULL);
5446 }
5447 if (SKIP_BLANKS == 0) {
5448 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5449 "Space required after the entity name\n");
5450 }
5451
5453 /*
5454 * handle the various case of definitions...
5455 */
5456 if (isParameter) {
5457 if ((RAW == '"') || (RAW == '\'')) {
5458 value = xmlParseEntityValue(ctxt, &orig);
5459 if (value) {
5460 if ((ctxt->sax != NULL) &&
5461 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
5462 ctxt->sax->entityDecl(ctxt->userData, name,
5464 NULL, NULL, value);
5465 }
5466 } else {
5467 URI = xmlParseExternalID(ctxt, &literal, 1);
5468 if ((URI == NULL) && (literal == NULL)) {
5470 }
5471 if (URI) {
5472 xmlURIPtr uri;
5473
5474 uri = xmlParseURI((const char *) URI);
5475 if (uri == NULL) {
5476 xmlErrMsgStr(ctxt, XML_ERR_INVALID_URI,
5477 "Invalid URI: %s\n", URI);
5478 /*
5479 * This really ought to be a well formedness error
5480 * but the XML Core WG decided otherwise c.f. issue
5481 * E26 of the XML erratas.
5482 */
5483 } else {
5484 if (uri->fragment != NULL) {
5485 /*
5486 * Okay this is foolish to block those but not
5487 * invalid URIs.
5488 */
5490 } else {
5491 if ((ctxt->sax != NULL) &&
5492 (!ctxt->disableSAX) &&
5493 (ctxt->sax->entityDecl != NULL))
5494 ctxt->sax->entityDecl(ctxt->userData, name,
5496 literal, URI, NULL);
5497 }
5498 xmlFreeURI(uri);
5499 }
5500 }
5501 }
5502 } else {
5503 if ((RAW == '"') || (RAW == '\'')) {
5504 value = xmlParseEntityValue(ctxt, &orig);
5505 if ((ctxt->sax != NULL) &&
5506 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
5507 ctxt->sax->entityDecl(ctxt->userData, name,
5509 NULL, NULL, value);
5510 /*
5511 * For expat compatibility in SAX mode.
5512 */
5513 if ((ctxt->myDoc == NULL) ||
5515 if (ctxt->myDoc == NULL) {
5517 if (ctxt->myDoc == NULL) {
5518 xmlErrMemory(ctxt, "New Doc failed");
5519 return;
5520 }
5522 }
5523 if (ctxt->myDoc->intSubset == NULL)
5524 ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
5525 BAD_CAST "fake", NULL, NULL);
5526
5528 NULL, NULL, value);
5529 }
5530 } else {
5531 URI = xmlParseExternalID(ctxt, &literal, 1);
5532 if ((URI == NULL) && (literal == NULL)) {
5534 }
5535 if (URI) {
5536 xmlURIPtr uri;
5537
5538 uri = xmlParseURI((const char *)URI);
5539 if (uri == NULL) {
5540 xmlErrMsgStr(ctxt, XML_ERR_INVALID_URI,
5541 "Invalid URI: %s\n", URI);
5542 /*
5543 * This really ought to be a well formedness error
5544 * but the XML Core WG decided otherwise c.f. issue
5545 * E26 of the XML erratas.
5546 */
5547 } else {
5548 if (uri->fragment != NULL) {
5549 /*
5550 * Okay this is foolish to block those but not
5551 * invalid URIs.
5552 */
5554 }
5555 xmlFreeURI(uri);
5556 }
5557 }
5558 if ((RAW != '>') && (SKIP_BLANKS == 0)) {
5559 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5560 "Space required before 'NDATA'\n");
5561 }
5562 if (CMP5(CUR_PTR, 'N', 'D', 'A', 'T', 'A')) {
5563 SKIP(5);
5564 if (SKIP_BLANKS == 0) {
5565 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5566 "Space required after 'NDATA'\n");
5567 }
5568 ndata = xmlParseName(ctxt);
5569 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
5570 (ctxt->sax->unparsedEntityDecl != NULL))
5571 ctxt->sax->unparsedEntityDecl(ctxt->userData, name,
5572 literal, URI, ndata);
5573 } else {
5574 if ((ctxt->sax != NULL) &&
5575 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
5576 ctxt->sax->entityDecl(ctxt->userData, name,
5578 literal, URI, NULL);
5579 /*
5580 * For expat compatibility in SAX mode.
5581 * assuming the entity replacement was asked for
5582 */
5583 if ((ctxt->replaceEntities != 0) &&
5584 ((ctxt->myDoc == NULL) ||
5586 if (ctxt->myDoc == NULL) {
5588 if (ctxt->myDoc == NULL) {
5589 xmlErrMemory(ctxt, "New Doc failed");
5590 return;
5591 }
5593 }
5594
5595 if (ctxt->myDoc->intSubset == NULL)
5596 ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
5597 BAD_CAST "fake", NULL, NULL);
5598 xmlSAX2EntityDecl(ctxt, name,
5600 literal, URI, NULL);
5601 }
5602 }
5603 }
5604 }
5605 if (ctxt->instate == XML_PARSER_EOF)
5606 goto done;
5608 if (RAW != '>') {
5609 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
5610 "xmlParseEntityDecl: entity %s not terminated\n", name);
5611 xmlHaltParser(ctxt);
5612 } else {
5613 if (inputid != ctxt->input->id) {
5614 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5615 "Entity declaration doesn't start and stop in"
5616 " the same entity\n");
5617 }
5618 NEXT;
5619 }
5620 if (orig != NULL) {
5621 /*
5622 * Ugly mechanism to save the raw entity value.
5623 */
5625
5626 if (isParameter) {
5627 if ((ctxt->sax != NULL) &&
5628 (ctxt->sax->getParameterEntity != NULL))
5629 cur = ctxt->sax->getParameterEntity(ctxt->userData, name);
5630 } else {
5631 if ((ctxt->sax != NULL) &&
5632 (ctxt->sax->getEntity != NULL))
5633 cur = ctxt->sax->getEntity(ctxt->userData, name);
5634 if ((cur == NULL) && (ctxt->userData==ctxt)) {
5635 cur = xmlSAX2GetEntity(ctxt, name);
5636 }
5637 }
5638 if ((cur != NULL) && (cur->orig == NULL)) {
5639 cur->orig = orig;
5640 orig = NULL;
5641 }
5642 }
5643
5644done:
5645 if (value != NULL) xmlFree(value);
5646 if (URI != NULL) xmlFree(URI);
5647 if (literal != NULL) xmlFree(literal);
5648 if (orig != NULL) xmlFree(orig);
5649 }
5650}
XMLPUBFUN void XMLCALL xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Definition: SAX2.c:604
XMLPUBFUN xmlEntityPtr XMLCALL xmlSAX2GetEntity(void *ctx, const xmlChar *name)
Definition: SAX2.c:526
@ XML_INTERNAL_GENERAL_ENTITY
Definition: entities.h:25
@ XML_INTERNAL_PARAMETER_ENTITY
Definition: entities.h:28
@ XML_PARSER_ENTITY_DECL
Definition: parser.h:122
XMLPUBFUN xmlDtdPtr XMLCALL xmlNewDtd(xmlDocPtr doc, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
xmlChar * xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig)
Definition: parser.c:3767
Definition: uri.h:33
XMLPUBFUN xmlURIPtr XMLCALL xmlParseURI(const char *str)
Definition: uri.c:940
XMLPUBFUN void XMLCALL xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1387
@ XML_ERR_INVALID_URI
Definition: xmlerror.h:191
@ XML_NS_ERR_COLON
Definition: xmlerror.h:218

Referenced by xmlParseMarkupDecl().

◆ xmlParseEntityRef()

xmlEntityPtr xmlParseEntityRef ( xmlParserCtxtPtr  ctxt)

xmlParseEntityRef: @ctxt: an XML parser context

parse ENTITY references declarations

[68] EntityRef ::= '&' Name ';'

[ WFC: Entity Declared ] In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with "standalone='yes'", the Name given in the entity reference must match that in an entity declaration, except that well-formed documents need not declare any of the following entities: amp, lt, gt, apos, quot. The declaration of a parameter entity must precede any reference to it. Similarly, the declaration of a general entity must precede any reference to it which appears in a default value in an attribute-list declaration. Note that if entities are declared in the external subset or in external parameter entities, a non-validating processor is not obligated to read and process their declarations; for such documents, the rule that an entity must be declared is a well-formedness constraint only if standalone='yes'.

[ WFC: Parsed Entity ] An entity reference must not contain the name of an unparsed entity

Returns the xmlEntityPtr if found, or NULL otherwise.

Definition at line 7531 of file parser.c.

7531 {
7532 const xmlChar *name;
7533 xmlEntityPtr ent = NULL;
7534
7535 GROW;
7536 if (ctxt->instate == XML_PARSER_EOF)
7537 return(NULL);
7538
7539 if (RAW != '&')
7540 return(NULL);
7541 NEXT;
7542 name = xmlParseName(ctxt);
7543 if (name == NULL) {
7544 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
7545 "xmlParseEntityRef: no name\n");
7546 return(NULL);
7547 }
7548 if (RAW != ';') {
7550 return(NULL);
7551 }
7552 NEXT;
7553
7554 /*
7555 * Predefined entities override any extra definition
7556 */
7557 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7559 if (ent != NULL)
7560 return(ent);
7561 }
7562
7563 /*
7564 * Increase the number of entity references parsed
7565 */
7566 ctxt->nbentities++;
7567
7568 /*
7569 * Ask first SAX for entity resolution, otherwise try the
7570 * entities which may have stored in the parser context.
7571 */
7572 if (ctxt->sax != NULL) {
7573 if (ctxt->sax->getEntity != NULL)
7574 ent = ctxt->sax->getEntity(ctxt->userData, name);
7575 if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7576 (ctxt->options & XML_PARSE_OLDSAX))
7578 if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
7579 (ctxt->userData==ctxt)) {
7580 ent = xmlSAX2GetEntity(ctxt, name);
7581 }
7582 }
7583 if (ctxt->instate == XML_PARSER_EOF)
7584 return(NULL);
7585 /*
7586 * [ WFC: Entity Declared ]
7587 * In a document without any DTD, a document with only an
7588 * internal DTD subset which contains no parameter entity
7589 * references, or a document with "standalone='yes'", the
7590 * Name given in the entity reference must match that in an
7591 * entity declaration, except that well-formed documents
7592 * need not declare any of the following entities: amp, lt,
7593 * gt, apos, quot.
7594 * The declaration of a parameter entity must precede any
7595 * reference to it.
7596 * Similarly, the declaration of a general entity must
7597 * precede any reference to it which appears in a default
7598 * value in an attribute-list declaration. Note that if
7599 * entities are declared in the external subset or in
7600 * external parameter entities, a non-validating processor
7601 * is not obligated to read and process their declarations;
7602 * for such documents, the rule that an entity must be
7603 * declared is a well-formedness constraint only if
7604 * standalone='yes'.
7605 */
7606 if (ent == NULL) {
7607 if ((ctxt->standalone == 1) ||
7608 ((ctxt->hasExternalSubset == 0) &&
7609 (ctxt->hasPErefs == 0))) {
7610 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7611 "Entity '%s' not defined\n", name);
7612 } else {
7613 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7614 "Entity '%s' not defined\n", name);
7615 if ((ctxt->inSubset == 0) &&
7616 (ctxt->sax != NULL) &&
7617 (ctxt->sax->reference != NULL)) {
7618 ctxt->sax->reference(ctxt->userData, name);
7619 }
7620 }
7621 xmlParserEntityCheck(ctxt, 0, ent, 0);
7622 ctxt->valid = 0;
7623 }
7624
7625 /*
7626 * [ WFC: Parsed Entity ]
7627 * An entity reference must not contain the name of an
7628 * unparsed entity
7629 */
7631 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
7632 "Entity reference to unparsed entity %s\n", name);
7633 }
7634
7635 /*
7636 * [ WFC: No External Entity References ]
7637 * Attribute values cannot contain direct or indirect
7638 * entity references to external entities.
7639 */
7640 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7642 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL,
7643 "Attribute references external entity '%s'\n", name);
7644 }
7645 /*
7646 * [ WFC: No < in Attribute Values ]
7647 * The replacement text of any entity referred to directly or
7648 * indirectly in an attribute value (other than "&lt;") must
7649 * not contain a <.
7650 */
7651 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7652 (ent != NULL) &&
7654 if (((ent->checked & 1) || (ent->checked == 0)) &&
7655 (ent->content != NULL) && (xmlStrchr(ent->content, '<'))) {
7656 xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
7657 "'<' in entity '%s' is not allowed in attributes values\n", name);
7658 }
7659 }
7660
7661 /*
7662 * Internal check, no parameter entities here ...
7663 */
7664 else {
7665 switch (ent->etype) {
7668 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER,
7669 "Attempt to reference the parameter entity '%s'\n",
7670 name);
7671 break;
7672 default:
7673 break;
7674 }
7675 }
7676
7677 /*
7678 * [ WFC: No Recursion ]
7679 * A parsed entity must not contain a recursive reference
7680 * to itself, either directly or indirectly.
7681 * Done somewhere else
7682 */
7683 return(ent);
7684}
@ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
Definition: entities.h:27
XMLPUBFUN xmlEntityPtr XMLCALL xmlGetPredefinedEntity(const xmlChar *name)
static int xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size, xmlEntityPtr ent, size_t replacement)
Definition: parser.c:128
@ XML_ERR_ENTITY_IS_PARAMETER
Definition: xmlerror.h:130
@ XML_ERR_ENTITY_IS_EXTERNAL
Definition: xmlerror.h:129
@ XML_ERR_UNDECLARED_ENTITY
Definition: xmlerror.h:126
@ XML_ERR_UNPARSED_ENTITY
Definition: xmlerror.h:128

Referenced by xmlParseAttValueComplex(), and xmlParseReference().

◆ xmlParseEntityValue()

xmlChar * xmlParseEntityValue ( xmlParserCtxtPtr  ctxt,
xmlChar **  orig 
)

xmlParseEntityValue: @ctxt: an XML parser context @orig: if non-NULL store a copy of the original entity value

parse a value for ENTITY declarations

[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | "'" ([^%&'] | PEReference | Reference)* "'"

Returns the EntityValue parsed with reference substituted or NULL

Definition at line 3767 of file parser.c.

3767 {
3768 xmlChar *buf = NULL;
3769 int len = 0;
3771 int c, l;
3772 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3775 xmlChar stop;
3776 xmlChar *ret = NULL;
3777 const xmlChar *cur = NULL;
3779
3780 if (RAW == '"') stop = '"';
3781 else if (RAW == '\'') stop = '\'';
3782 else {
3784 return(NULL);
3785 }
3786 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
3787 if (buf == NULL) {
3788 xmlErrMemory(ctxt, NULL);
3789 return(NULL);
3790 }
3791
3792 /*
3793 * The content of the entity definition is copied in a buffer.
3794 */
3795
3797 input = ctxt->input;
3798 GROW;
3799 if (ctxt->instate == XML_PARSER_EOF)
3800 goto error;
3801 NEXT;
3802 c = CUR_CHAR(l);
3803 /*
3804 * NOTE: 4.4.5 Included in Literal
3805 * When a parameter entity reference appears in a literal entity
3806 * value, ... a single or double quote character in the replacement
3807 * text is always treated as a normal data character and will not
3808 * terminate the literal.
3809 * In practice it means we stop the loop only when back at parsing
3810 * the initial entity and the quote is found
3811 */
3812 while (((IS_CHAR(c)) && ((c != stop) || /* checked */
3813 (ctxt->input != input))) && (ctxt->instate != XML_PARSER_EOF)) {
3814 if (len + 5 >= size) {
3815 xmlChar *tmp;
3816
3817 size *= 2;
3818 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3819 if (tmp == NULL) {
3820 xmlErrMemory(ctxt, NULL);
3821 goto error;
3822 }
3823 buf = tmp;
3824 }
3825 COPY_BUF(l,buf,len,c);
3826 NEXTL(l);
3827
3828 GROW;
3829 c = CUR_CHAR(l);
3830 if (c == 0) {
3831 GROW;
3832 c = CUR_CHAR(l);
3833 }
3834
3835 if (len > maxLength) {
3836 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
3837 "entity value too long\n");
3838 goto error;
3839 }
3840 }
3841 buf[len] = 0;
3842 if (ctxt->instate == XML_PARSER_EOF)
3843 goto error;
3844 if (c != stop) {
3846 goto error;
3847 }
3848 NEXT;
3849
3850 /*
3851 * Raise problem w.r.t. '&' and '%' being used in non-entities
3852 * reference constructs. Note Charref will be handled in
3853 * xmlStringDecodeEntities()
3854 */
3855 cur = buf;
3856 while (*cur != 0) { /* non input consuming */
3857 if ((*cur == '%') || ((*cur == '&') && (cur[1] != '#'))) {
3858 xmlChar *name;
3859 xmlChar tmp = *cur;
3860 int nameOk = 0;
3861
3862 cur++;
3863 name = xmlParseStringName(ctxt, &cur);
3864 if (name != NULL) {
3865 nameOk = 1;
3866 xmlFree(name);
3867 }
3868 if ((nameOk == 0) || (*cur != ';')) {
3869 xmlFatalErrMsgInt(ctxt, XML_ERR_ENTITY_CHAR_ERROR,
3870 "EntityValue: '%c' forbidden except for entities references\n",
3871 tmp);
3872 goto error;
3873 }
3874 if ((tmp == '%') && (ctxt->inSubset == 1) &&
3875 (ctxt->inputNr == 1)) {
3877 goto error;
3878 }
3879 if (*cur == 0)
3880 break;
3881 }
3882 cur++;
3883 }
3884
3885 /*
3886 * Then PEReference entities are substituted.
3887 *
3888 * NOTE: 4.4.7 Bypassed
3889 * When a general entity reference appears in the EntityValue in
3890 * an entity declaration, it is bypassed and left as is.
3891 * so XML_SUBSTITUTE_REF is not set here.
3892 */
3893 ++ctxt->depth;
3895 0, 0, 0);
3896 --ctxt->depth;
3897 if (orig != NULL) {
3898 *orig = buf;
3899 buf = NULL;
3900 }
3901
3902error:
3903 if (buf != NULL)
3904 xmlFree(buf);
3905 return(ret);
3906}
#define XML_SUBSTITUTE_PEREF
@ XML_PARSER_ENTITY_VALUE
Definition: parser.h:123
static xmlChar * xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar **str)
Definition: parser.c:3573
@ XML_ERR_ENTITY_CHAR_ERROR
Definition: xmlerror.h:187

Referenced by xmlParseEntityDecl().

◆ xmlParseEnumeratedType()

int xmlParseEnumeratedType ( xmlParserCtxtPtr  ctxt,
xmlEnumerationPtr tree 
)

xmlParseEnumeratedType: @ctxt: an XML parser context @tree: the enumeration tree built while parsing

parse an Enumerated attribute type.

[57] EnumeratedType ::= NotationType | Enumeration

[58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'

Returns: XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION

Definition at line 5871 of file parser.c.

5871 {
5872 if (CMP8(CUR_PTR, 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) {
5873 SKIP(8);
5874 if (SKIP_BLANKS == 0) {
5875 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5876 "Space required after 'NOTATION'\n");
5877 return(0);
5878 }
5879 *tree = xmlParseNotationType(ctxt);
5880 if (*tree == NULL) return(0);
5881 return(XML_ATTRIBUTE_NOTATION);
5882 }
5884 if (*tree == NULL) return(0);
5886}
@ XML_ATTRIBUTE_NOTATION
Definition: tree.h:216
@ XML_ATTRIBUTE_ENUMERATION
Definition: tree.h:215
xmlEnumerationPtr xmlParseNotationType(xmlParserCtxtPtr ctxt)
Definition: parser.c:5732
xmlEnumerationPtr xmlParseEnumerationType(xmlParserCtxtPtr ctxt)
Definition: parser.c:5802

Referenced by xmlParseAttributeType().

◆ xmlParseEnumerationType()

xmlEnumerationPtr xmlParseEnumerationType ( xmlParserCtxtPtr  ctxt)

xmlParseEnumerationType: @ctxt: an XML parser context

parse an Enumeration attribute type.

[59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'

[ VC: Enumeration ] Values of this type must match one of the Nmtoken tokens in the declaration

Returns: the enumeration attribute tree built while parsing

Definition at line 5802 of file parser.c.

5802 {
5803 xmlChar *name;
5805
5806 if (RAW != '(') {
5808 return(NULL);
5809 }
5810 SHRINK;
5811 do {
5812 NEXT;
5814 name = xmlParseNmtoken(ctxt);
5815 if (name == NULL) {
5817 return(ret);
5818 }
5819 tmp = ret;
5820 while (tmp != NULL) {
5821 if (xmlStrEqual(name, tmp->name)) {
5822 xmlValidityError(ctxt, XML_DTD_DUP_TOKEN,
5823 "standalone: attribute enumeration value token %s duplicated\n",
5824 name, NULL);
5825 if (!xmlDictOwns(ctxt->dict, name))
5826 xmlFree(name);
5827 break;
5828 }
5829 tmp = tmp->next;
5830 }
5831 if (tmp == NULL) {
5833 if (!xmlDictOwns(ctxt->dict, name))
5834 xmlFree(name);
5835 if (cur == NULL) {
5837 return(NULL);
5838 }
5839 if (last == NULL) ret = last = cur;
5840 else {
5841 last->next = cur;
5842 last = cur;
5843 }
5844 }
5846 } while (RAW == '|');
5847 if (RAW != ')') {
5849 return(ret);
5850 }
5851 NEXT;
5852 return(ret);
5853}
xmlChar * xmlParseNmtoken(xmlParserCtxtPtr ctxt)
Definition: parser.c:3662
WCHAR * name
Definition: name.c:42
XMLPUBFUN xmlEnumerationPtr XMLCALL xmlCreateEnumeration(const xmlChar *name)
Definition: valid.c:1795
@ XML_DTD_DUP_TOKEN
Definition: xmlerror.h:260

Referenced by xmlParseEnumeratedType().

◆ xmlParseExternalEntityPrivate()

static xmlParserErrors xmlParseExternalEntityPrivate ( xmlDocPtr  doc,
xmlParserCtxtPtr  oldctxt,
xmlSAXHandlerPtr  sax,
void user_data,
int  depth,
const xmlChar URL,
const xmlChar ID,
xmlNodePtr list 
)
static

xmlParseExternalEntityPrivate: @doc: the document the chunk pertains to @oldctxt: the previous parser context if available @sax: the SAX handler block (possibly NULL) @user_data: The user data returned on SAX callbacks (possibly NULL) @depth: Used for loop detection, use 0 @URL: the URL for the entity to load @ID: the System ID for the entity to load @list: the return value for the set of parsed nodes

Private version of xmlParseExternalEntity()

Returns 0 if the entity is well formed, -1 in case of args problem and the parser error code otherwise

Definition at line 13005 of file parser.c.

13008 {
13009 xmlParserCtxtPtr ctxt;
13010 xmlDocPtr newDoc;
13011 xmlNodePtr newRoot;
13012 xmlSAXHandlerPtr oldsax = NULL;
13014 xmlChar start[4];
13015 xmlCharEncoding enc;
13016
13017 if (((depth > 40) &&
13018 ((oldctxt == NULL) || (oldctxt->options & XML_PARSE_HUGE) == 0)) ||
13019 (depth > 1024)) {
13020 return(XML_ERR_ENTITY_LOOP);
13021 }
13022
13023 if (list != NULL)
13024 *list = NULL;
13025 if ((URL == NULL) && (ID == NULL))
13026 return(XML_ERR_INTERNAL_ERROR);
13027 if (doc == NULL)
13028 return(XML_ERR_INTERNAL_ERROR);
13029
13030
13031 ctxt = xmlCreateEntityParserCtxtInternal(URL, ID, NULL, oldctxt);
13032 if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY);
13033 ctxt->userData = ctxt;
13034 if (sax != NULL) {
13035 oldsax = ctxt->sax;
13036 ctxt->sax = sax;
13037 if (user_data != NULL)
13038 ctxt->userData = user_data;
13039 }
13040 xmlDetectSAX2(ctxt);
13041 newDoc = xmlNewDoc(BAD_CAST "1.0");
13042 if (newDoc == NULL) {
13043 xmlFreeParserCtxt(ctxt);
13044 return(XML_ERR_INTERNAL_ERROR);
13045 }
13046 newDoc->properties = XML_DOC_INTERNAL;
13047 if (doc) {
13048 newDoc->intSubset = doc->intSubset;
13049 newDoc->extSubset = doc->extSubset;
13050 if (doc->dict) {
13051 newDoc->dict = doc->dict;
13052 xmlDictReference(newDoc->dict);
13053 }
13054 if (doc->URL != NULL) {
13055 newDoc->URL = xmlStrdup(doc->URL);
13056 }
13057 }
13058 newRoot = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL);
13059 if (newRoot == NULL) {
13060 if (sax != NULL)
13061 ctxt->sax = oldsax;
13062 xmlFreeParserCtxt(ctxt);
13063 newDoc->intSubset = NULL;
13064 newDoc->extSubset = NULL;
13065 xmlFreeDoc(newDoc);
13066 return(XML_ERR_INTERNAL_ERROR);
13067 }
13068 xmlAddChild((xmlNodePtr) newDoc, newRoot);
13069 nodePush(ctxt, newDoc->children);
13070 if (doc == NULL) {
13071 ctxt->myDoc = newDoc;
13072 } else {
13073 ctxt->myDoc = doc;
13074 newRoot->doc = doc;
13075 }
13076
13077 /*
13078 * Get the 4 first bytes and decode the charset
13079 * if enc != XML_CHAR_ENCODING_NONE
13080 * plug some encoding conversion routines.
13081 */
13082 GROW;
13083 if ((ctxt->input->end - ctxt->input->cur) >= 4) {
13084 start[0] = RAW;
13085 start[1] = NXT(1);
13086 start[2] = NXT(2);
13087 start[3] = NXT(3);
13088 enc = xmlDetectCharEncoding(start, 4);
13089 if (enc != XML_CHAR_ENCODING_NONE) {
13090 xmlSwitchEncoding(ctxt, enc);
13091 }
13092 }
13093
13094 /*
13095 * Parse a possible text declaration first
13096 */
13097 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
13098 xmlParseTextDecl(ctxt);
13099 /*
13100 * An XML-1.0 document can't reference an entity not XML-1.0
13101 */
13102 if ((xmlStrEqual(oldctxt->version, BAD_CAST "1.0")) &&
13103 (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) {
13104 xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH,
13105 "Version mismatch between document and entity\n");
13106 }
13107 }
13108
13110 ctxt->depth = depth;
13111 if (oldctxt != NULL) {
13112 ctxt->_private = oldctxt->_private;
13113 ctxt->loadsubset = oldctxt->loadsubset;
13114 ctxt->validate = oldctxt->validate;
13115 ctxt->valid = oldctxt->valid;
13116 ctxt->replaceEntities = oldctxt->replaceEntities;
13117 if (oldctxt->validate) {
13118 ctxt->vctxt.error = oldctxt->vctxt.error;
13119 ctxt->vctxt.warning = oldctxt->vctxt.warning;
13120 ctxt->vctxt.userData = oldctxt->vctxt.userData;
13121 }
13122 ctxt->external = oldctxt->external;
13123 if (ctxt->dict) xmlDictFree(ctxt->dict);
13124 ctxt->dict = oldctxt->dict;
13125 ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
13126 ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
13127 ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
13128 ctxt->dictNames = oldctxt->dictNames;
13129 ctxt->attsDefault = oldctxt->attsDefault;
13130 ctxt->attsSpecial = oldctxt->attsSpecial;
13131 ctxt->linenumbers = oldctxt->linenumbers;
13132 ctxt->record_info = oldctxt->record_info;
13133 ctxt->node_seq.maximum = oldctxt->node_seq.maximum;
13134 ctxt->node_seq.length = oldctxt->node_seq.length;
13135 ctxt->node_seq.buffer = oldctxt->node_seq.buffer;
13136 } else {
13137 /*
13138 * Doing validity checking on chunk without context
13139 * doesn't make sense
13140 */
13141 ctxt->_private = NULL;
13142 ctxt->validate = 0;
13143 ctxt->external = 2;
13144 ctxt->loadsubset = 0;
13145 }
13146
13147 xmlParseContent(ctxt);
13148
13149 if ((RAW == '<') && (NXT(1) == '/')) {
13151 } else if (RAW != 0) {
13153 }
13154 if (ctxt->node != newDoc->children) {
13156 }
13157
13158 if (!ctxt->wellFormed) {
13159 if (ctxt->errNo == 0)
13161 else
13162 ret = (xmlParserErrors)ctxt->errNo;
13163 } else {
13164 if (list != NULL) {
13166
13167 /*
13168 * Return the newly created nodeset after unlinking it from
13169 * they pseudo parent.
13170 */
13171 cur = newDoc->children->children;
13172 *list = cur;
13173 while (cur != NULL) {
13174 cur->parent = NULL;
13175 cur = cur->next;
13176 }
13177 newDoc->children->children = NULL;
13178 }
13179 ret = XML_ERR_OK;
13180 }
13181
13182 /*
13183 * Record in the parent context the number of entities replacement
13184 * done when parsing that reference.
13185 */
13186 if (oldctxt != NULL)
13187 oldctxt->nbentities += ctxt->nbentities;
13188
13189 /*
13190 * Also record the size of the entity parsed
13191 */
13192 if (ctxt->input != NULL && oldctxt != NULL) {
13193 oldctxt->sizeentities += ctxt->input->consumed;
13194 oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base);
13195 }
13196 /*
13197 * And record the last error if any
13198 */
13199 if ((oldctxt != NULL) && (ctxt->lastError.code != XML_ERR_OK))
13200 xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
13201
13202 if (sax != NULL)
13203 ctxt->sax = oldsax;
13204 if (oldctxt != NULL) {
13205 ctxt->dict = NULL;
13206 ctxt->attsDefault = NULL;
13207 ctxt->attsSpecial = NULL;
13208 oldctxt->validate = ctxt->validate;
13209 oldctxt->valid = ctxt->valid;
13210 oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
13211 oldctxt->node_seq.length = ctxt->node_seq.length;
13212 oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
13213 }
13214 ctxt->node_seq.maximum = 0;
13215 ctxt->node_seq.length = 0;
13216 ctxt->node_seq.buffer = NULL;
13217 xmlFreeParserCtxt(ctxt);
13218 newDoc->intSubset = NULL;
13219 newDoc->extSubset = NULL;
13220 xmlFreeDoc(newDoc);
13221
13222 return(ret);
13223}
Definition: list.h:37
void xmlParseTextDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:6915
const xmlChar * URL
Definition: tree.h:577
struct _xmlDtd * extSubset
Definition: tree.h:571
struct _xmlDoc * doc
Definition: tree.h:498
const xmlChar * version
Definition: parser.h:72
unsigned long length
Definition: parser.h:100
unsigned long maximum
Definition: parser.h:99
xmlParserNodeInfo * buffer
Definition: parser.h:101
@ XML_ERR_VERSION_MISMATCH
Definition: xmlerror.h:209

Referenced by xmlParseCtxtExternalEntity(), and xmlParseReference().

◆ xmlParseExternalID()

xmlChar * xmlParseExternalID ( xmlParserCtxtPtr  ctxt,
xmlChar **  publicID,
int  strict 
)

xmlParseExternalID: @ctxt: an XML parser context @publicID: a xmlChar** receiving PubidLiteral @strict: indicate whether we should restrict parsing to only production [75], see NOTE below

Parse an External ID or a Public ID

NOTE: Productions [75] and [83] interact badly since [75] can generate 'PUBLIC' S PubidLiteral S SystemLiteral

[75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral

[83] PublicID ::= 'PUBLIC' S PubidLiteral

Returns the function returns SystemLiteral and in the second case publicID receives PubidLiteral, is strict is off it is possible to return NULL and have publicID set.

Definition at line 4683 of file parser.c.

4683 {
4684 xmlChar *URI = NULL;
4685
4686 SHRINK;
4687
4688 *publicID = NULL;
4689 if (CMP6(CUR_PTR, 'S', 'Y', 'S', 'T', 'E', 'M')) {
4690 SKIP(6);
4691 if (SKIP_BLANKS == 0) {
4692 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
4693 "Space required after 'SYSTEM'\n");
4694 }
4695 URI = xmlParseSystemLiteral(ctxt);
4696 if (URI == NULL) {
4698 }
4699 } else if (CMP6(CUR_PTR, 'P', 'U', 'B', 'L', 'I', 'C')) {
4700 SKIP(6);
4701 if (SKIP_BLANKS == 0) {
4702 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
4703 "Space required after 'PUBLIC'\n");
4704 }
4705 *publicID = xmlParsePubidLiteral(ctxt);
4706 if (*publicID == NULL) {
4708 }
4709 if (strict) {
4710 /*
4711 * We don't handle [83] so "S SystemLiteral" is required.
4712 */
4713 if (SKIP_BLANKS == 0) {
4714 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
4715 "Space required after the Public Identifier\n");
4716 }
4717 } else {
4718 /*
4719 * We handle [83] so we return immediately, if
4720 * "S SystemLiteral" is not detected. We skip blanks if no
4721 * system literal was found, but this is harmless since we must
4722 * be at the end of a NotationDecl.
4723 */
4724 if (SKIP_BLANKS == 0) return(NULL);
4725 if ((CUR != '\'') && (CUR != '"')) return(NULL);
4726 }
4727 URI = xmlParseSystemLiteral(ctxt);
4728 if (URI == NULL) {
4730 }
4731 }
4732 return(URI);
4733}
static int strict
Definition: error.c:51
xmlChar * xmlParsePubidLiteral(xmlParserCtxtPtr ctxt)
Definition: parser.c:4291
xmlChar * xmlParseSystemLiteral(xmlParserCtxtPtr ctxt)
Definition: parser.c:4199

Referenced by xmlParseDocTypeDecl(), xmlParseEntityDecl(), and xmlParseNotationDecl().

◆ xmlParseExternalSubset()

void xmlParseExternalSubset ( xmlParserCtxtPtr  ctxt,
const xmlChar ExternalID,
const xmlChar SystemID 
)

xmlParseExternalSubset: @ctxt: an XML parser context @ExternalID: the external identifier @SystemID: the system identifier (or URL)

parse Markup declarations from an external subset

[30] extSubset ::= textDecl? extSubsetDecl

[31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) *

Definition at line 6998 of file parser.c.

6999 {
7000 xmlDetectSAX2(ctxt);
7001 GROW;
7002
7003 if ((ctxt->encoding == NULL) &&
7004 (ctxt->input->end - ctxt->input->cur >= 4)) {
7005 xmlChar start[4];
7006 xmlCharEncoding enc;
7007
7008 start[0] = RAW;
7009 start[1] = NXT(1);
7010 start[2] = NXT(2);
7011 start[3] = NXT(3);
7012 enc = xmlDetectCharEncoding(start, 4);
7013 if (enc != XML_CHAR_ENCODING_NONE)
7014 xmlSwitchEncoding(ctxt, enc);
7015 }
7016
7017 if (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) {
7018 xmlParseTextDecl(ctxt);
7019 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
7020 /*
7021 * The XML REC instructs us to stop parsing right here
7022 */
7023 xmlHaltParser(ctxt);
7024 return;
7025 }
7026 }
7027 if (ctxt->myDoc == NULL) {
7028 ctxt->myDoc = xmlNewDoc(BAD_CAST "1.0");
7029 if (ctxt->myDoc == NULL) {
7030 xmlErrMemory(ctxt, "New Doc failed");
7031 return;
7032 }
7034 }
7035 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL))
7036 xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID);
7037
7038 ctxt->instate = XML_PARSER_DTD;
7039 ctxt->external = 1;
7041 while (((RAW == '<') && (NXT(1) == '?')) ||
7042 ((RAW == '<') && (NXT(1) == '!')) ||
7043 (RAW == '%')) {
7044 int id = ctxt->input->id;
7045 unsigned long cons = CUR_CONSUMED;
7046
7047 GROW;
7048 if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
7050 } else
7051 xmlParseMarkupDecl(ctxt);
7053
7054 if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) {
7056 break;
7057 }
7058 }
7059
7060 if (RAW != 0) {
7062 }
7063
7064}
XMLPUBFUN xmlDtdPtr XMLCALL xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID)
static void xmlParseConditionalSections(xmlParserCtxtPtr ctxt)
Definition: parser.c:6703

Referenced by xmlSAX2ExternalSubset().

◆ xmlParseExtParsedEnt()

int xmlParseExtParsedEnt ( xmlParserCtxtPtr  ctxt)

xmlParseExtParsedEnt: @ctxt: an XML parser context

parse a general parsed entity An external general parsed entity is well-formed if it matches the production labeled extParsedEnt.

[78] extParsedEnt ::= TextDecl? content

Returns 0, -1 in case of error. the parser context is augmented as a result of the parsing.

Definition at line 10889 of file parser.c.

10889 {
10890 xmlChar start[4];
10891 xmlCharEncoding enc;
10892
10893 if ((ctxt == NULL) || (ctxt->input == NULL))
10894 return(-1);
10895
10896 xmlDetectSAX2(ctxt);
10897
10898 GROW;
10899
10900 /*
10901 * SAX: beginning of the document processing.
10902 */
10903 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
10904 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
10905
10906 /*
10907 * Get the 4 first bytes and decode the charset
10908 * if enc != XML_CHAR_ENCODING_NONE
10909 * plug some encoding conversion routines.
10910 */
10911 if ((ctxt->input->end - ctxt->input->cur) >= 4) {
10912 start[0] = RAW;
10913 start[1] = NXT(1);
10914 start[2] = NXT(2);
10915 start[3] = NXT(3);
10916 enc = xmlDetectCharEncoding(start, 4);
10917 if (enc != XML_CHAR_ENCODING_NONE) {
10918 xmlSwitchEncoding(ctxt, enc);
10919 }
10920 }
10921
10922
10923 if (CUR == 0) {
10925 }
10926
10927 /*
10928 * Check for the XMLDecl in the Prolog.
10929 */
10930 GROW;
10931 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
10932
10933 /*
10934 * Note that we will switch encoding on the fly.
10935 */
10936 xmlParseXMLDecl(ctxt);
10937 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
10938 /*
10939 * The XML REC instructs us to stop parsing right here
10940 */
10941 return(-1);
10942 }
10944 } else {
10946 }
10947 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
10948 ctxt->sax->startDocument(ctxt->userData);
10949 if (ctxt->instate == XML_PARSER_EOF)
10950 return(-1);
10951
10952 /*
10953 * Doing validity checking on chunk doesn't make sense
10954 */
10956 ctxt->validate = 0;
10957 ctxt->loadsubset = 0;
10958 ctxt->depth = 0;
10959
10960 xmlParseContent(ctxt);
10961 if (ctxt->instate == XML_PARSER_EOF)
10962 return(-1);
10963
10964 if ((RAW == '<') && (NXT(1) == '/')) {
10966 } else if (RAW != 0) {
10968 }
10969
10970 /*
10971 * SAX: end of the document processing.
10972 */
10973 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
10974 ctxt->sax->endDocument(ctxt->userData);
10975
10976 if (! ctxt->wellFormed) return(-1);
10977 return(0);
10978}

◆ xmlParseInNodeContext()

xmlParserErrors xmlParseInNodeContext ( xmlNodePtr  node,
const char data,
int  datalen,
int  options,
xmlNodePtr lst 
)

xmlParseInNodeContext: @node: the context node @data: the input string @datalen: the input string length in bytes @options: a combination of xmlParserOption @lst: the return value for the set of parsed nodes

Parse a well-balanced chunk of an XML document within the context (DTD, namespaces, etc ...) of the given node.

The allowed sequence for the data is a Well Balanced Chunk defined by the content production in the XML grammar:

[43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*

Returns XML_ERR_OK if the chunk is well balanced, and the parser error code otherwise

Definition at line 13496 of file parser.c.

13497 {
13498#ifdef SAX2
13499 xmlParserCtxtPtr ctxt;
13500 xmlDocPtr doc = NULL;
13501 xmlNodePtr fake, cur;
13502 int nsnr = 0;
13503
13505
13506 /*
13507 * check all input parameters, grab the document
13508 */
13509 if ((lst == NULL) || (node == NULL) || (data == NULL) || (datalen < 0))
13510 return(XML_ERR_INTERNAL_ERROR);
13511 switch (node->type) {
13512 case XML_ELEMENT_NODE:
13513 case XML_ATTRIBUTE_NODE:
13514 case XML_TEXT_NODE:
13517 case XML_PI_NODE:
13518 case XML_COMMENT_NODE:
13519 case XML_DOCUMENT_NODE:
13521 break;
13522 default:
13523 return(XML_ERR_INTERNAL_ERROR);
13524
13525 }
13526 while ((node != NULL) && (node->type != XML_ELEMENT_NODE) &&
13527 (node->type != XML_DOCUMENT_NODE) &&
13528 (node->type != XML_HTML_DOCUMENT_NODE))
13529 node = node->parent;
13530 if (node == NULL)
13531 return(XML_ERR_INTERNAL_ERROR);
13532 if (node->type == XML_ELEMENT_NODE)
13533 doc = node->doc;
13534 else
13535 doc = (xmlDocPtr) node;
13536 if (doc == NULL)
13537 return(XML_ERR_INTERNAL_ERROR);
13538
13539 /*
13540 * allocate a context and set-up everything not related to the
13541 * node position in the tree
13542 */
13543 if (doc->type == XML_DOCUMENT_NODE)
13544 ctxt = xmlCreateMemoryParserCtxt((char *) data, datalen);
13545#ifdef LIBXML_HTML_ENABLED
13546 else if (doc->type == XML_HTML_DOCUMENT_NODE) {
13547 ctxt = htmlCreateMemoryParserCtxt((char *) data, datalen);
13548 /*
13549 * When parsing in context, it makes no sense to add implied
13550 * elements like html/body/etc...
13551 */
13552 options |= HTML_PARSE_NOIMPLIED;
13553 }
13554#endif
13555 else
13556 return(XML_ERR_INTERNAL_ERROR);
13557
13558 if (ctxt == NULL)
13559 return(XML_ERR_NO_MEMORY);
13560
13561 /*
13562 * Use input doc's dict if present, else assure XML_PARSE_NODICT is set.
13563 * We need a dictionary for xmlDetectSAX2, so if there's no doc dict
13564 * we must wait until the last moment to free the original one.
13565 */
13566 if (doc->dict != NULL) {
13567 if (ctxt->dict != NULL)
13568 xmlDictFree(ctxt->dict);
13569 ctxt->dict = doc->dict;
13570 } else
13572
13573 if (doc->encoding != NULL) {
13575
13576 if (ctxt->encoding != NULL)
13577 xmlFree((xmlChar *) ctxt->encoding);
13578 ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding);
13579
13580 hdlr = xmlFindCharEncodingHandler((const char *) doc->encoding);
13581 if (hdlr != NULL) {
13582 xmlSwitchToEncoding(ctxt, hdlr);
13583 } else {
13585 }
13586 }
13587
13589 xmlDetectSAX2(ctxt);
13590 ctxt->myDoc = doc;
13591 /* parsing in context, i.e. as within existing content */
13592 ctxt->input_id = 2;
13594
13595 fake = xmlNewDocComment(node->doc, NULL);
13596 if (fake == NULL) {
13597 xmlFreeParserCtxt(ctxt);
13598 return(XML_ERR_NO_MEMORY);
13599 }
13600 xmlAddChild(node, fake);
13601
13602 if (node->type == XML_ELEMENT_NODE) {
13603 nodePush(ctxt, node);
13604 /*
13605 * initialize the SAX2 namespaces stack
13606 */
13607 cur = node;
13608 while ((cur != NULL) && (cur->type == XML_ELEMENT_NODE)) {
13609 xmlNsPtr ns = cur->nsDef;
13610 const xmlChar *iprefix, *ihref;
13611
13612 while (ns != NULL) {
13613 if (ctxt->dict) {
13614 iprefix = xmlDictLookup(ctxt->dict, ns->prefix, -1);
13615 ihref = xmlDictLookup(ctxt->dict, ns->href, -1);
13616 } else {
13617 iprefix = ns->prefix;
13618 ihref = ns->href;
13619 }
13620
13621 if (xmlGetNamespace(ctxt, iprefix) == NULL) {
13622 nsPush(ctxt, iprefix, ihref);
13623 nsnr++;
13624 }
13625 ns = ns->next;
13626 }
13627 cur = cur->parent;
13628 }
13629 }
13630
13631 if ((ctxt->validate) || (ctxt->replaceEntities != 0)) {
13632 /*
13633 * ID/IDREF registration will be done in xmlValidateElement below
13634 */
13635 ctxt->loadsubset |= XML_SKIP_IDS;
13636 }
13637
13638#ifdef LIBXML_HTML_ENABLED
13639 if (doc->type == XML_HTML_DOCUMENT_NODE)
13640 __htmlParseContent(ctxt);
13641 else
13642#endif
13643 xmlParseContent(ctxt);
13644
13645 nsPop(ctxt, nsnr);
13646 if ((RAW == '<') && (NXT(1) == '/')) {
13648 } else if (RAW != 0) {
13650 }
13651 if ((ctxt->node != NULL) && (ctxt->node != node)) {
13653 ctxt->wellFormed = 0;
13654 }
13655
13656 if (!ctxt->wellFormed) {
13657 if (ctxt->errNo == 0)
13659 else
13660 ret = (xmlParserErrors)ctxt->errNo;
13661 } else {
13662 ret = XML_ERR_OK;
13663 }
13664
13665 /*
13666 * Return the newly created nodeset after unlinking it from
13667 * the pseudo sibling.
13668 */
13669
13670 cur = fake->next;
13671 fake->next = NULL;
13672 node->last = fake;
13673
13674 if (cur != NULL) {
13675 cur->prev = NULL;
13676 }
13677
13678 *lst = cur;
13679
13680 while (cur != NULL) {
13681 cur->parent = NULL;
13682 cur = cur->next;
13683 }
13684
13685 xmlUnlinkNode(fake);
13686 xmlFreeNode(fake);
13687
13688
13689 if (ret != XML_ERR_OK) {
13690 xmlFreeNodeList(*lst);
13691 *lst = NULL;
13692 }
13693
13694 if (doc->dict != NULL)
13695 ctxt->dict = NULL;
13696 xmlFreeParserCtxt(ctxt);
13697
13698 return(ret);
13699#else /* !SAX2 */
13700 return(XML_ERR_INTERNAL_ERROR);
13701#endif
13702}
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1031
xmlDoc * xmlDocPtr
Definition: tree.h:550
@ XML_ATTRIBUTE_NODE
Definition: tree.h:161
@ XML_DOCUMENT_NODE
Definition: tree.h:168
@ XML_CDATA_SECTION_NODE
Definition: tree.h:163
@ XML_TEXT_NODE
Definition: tree.h:162
@ XML_PI_NODE
Definition: tree.h:166
@ XML_COMMENT_NODE
Definition: tree.h:167
@ XML_HTML_DOCUMENT_NODE
Definition: tree.h:172
@ XML_ENTITY_REF_NODE
Definition: tree.h:164
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocComment(xmlDocPtr doc, const xmlChar *content)
XMLPUBFUN void XMLCALL xmlFreeNodeList(xmlNodePtr cur)
static const xmlChar * xmlGetNamespace(xmlParserCtxtPtr ctxt, const xmlChar *prefix)
Definition: parser.c:8760
const xmlChar * encoding
Definition: tree.h:574
xmlElementType type
Definition: tree.h:553
struct _xmlNode * next
Definition: tree.h:496
Definition: tree.h:389
Definition: mxnamespace.c:45
BSTR prefix
Definition: mxnamespace.c:46
Definition: dlist.c:348
@ XML_ERR_NO_MEMORY
Definition: xmlerror.h:102

◆ xmlParseInternalSubset()

static void xmlParseInternalSubset ( xmlParserCtxtPtr  ctxt)
static

xmlParseInternalSubset: @ctxt: an XML parser context

parse the internal subset declaration

[28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>'

Definition at line 8354 of file parser.c.

8354 {
8355 /*
8356 * Is there any DTD definition ?
8357 */
8358 if (RAW == '[') {
8359 int baseInputNr = ctxt->inputNr;
8360 ctxt->instate = XML_PARSER_DTD;
8361 NEXT;
8362 /*
8363 * Parse the succession of Markup declarations and
8364 * PEReferences.
8365 * Subsequence (markupdecl | PEReference | S)*
8366 */
8367 while (((RAW != ']') || (ctxt->inputNr > baseInputNr)) &&
8368 (ctxt->instate != XML_PARSER_EOF)) {
8369 int id = ctxt->input->id;
8370 unsigned long cons = CUR_CONSUMED;
8371
8373 xmlParseMarkupDecl(ctxt);
8374 xmlParsePEReference(ctxt);
8375
8376 /*
8377 * Conditional sections are allowed from external entities included
8378 * by PE References in the internal subset.
8379 */
8380 if ((ctxt->inputNr > 1) && (ctxt->input->filename != NULL) &&
8381 (RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
8383 }
8384
8385 if ((id == ctxt->input->id) && (cons == CUR_CONSUMED)) {
8387 "xmlParseInternalSubset: error detected in Markup declaration\n");
8388 if (ctxt->inputNr > baseInputNr)
8389 xmlPopInput(ctxt);
8390 else
8391 break;
8392 }
8393 }
8394 if (RAW == ']') {
8395 NEXT;
8397 }
8398 }
8399
8400 /*
8401 * We should be at the end of the DOCTYPE declaration.
8402 */
8403 if (RAW != '>') {
8405 return;
8406 }
8407 NEXT;
8408}
void xmlParsePEReference(xmlParserCtxtPtr ctxt)
Definition: parser.c:7912

Referenced by xmlParseDocument().

◆ xmlParseMarkupDecl()

void xmlParseMarkupDecl ( xmlParserCtxtPtr  ctxt)

xmlParseMarkupDecl: @ctxt: an XML parser context

parse Markup declarations

[29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment

[ VC: Proper Declaration/PE Nesting ] Parameter-entity replacement text must be properly nested with markup declarations. That is to say, if either the first character or the last character of a markup declaration (markupdecl above) is contained in the replacement text for a parameter-entity reference, both must be contained in the same replacement text.

[ WFC: PEs in Internal Subset ] In the internal DTD subset, parameter-entity references can occur only where markup declarations can occur, not within markup declarations. (This does not apply to references that occur in external parameter entities or to the external subset.)

Definition at line 6866 of file parser.c.

6866 {
6867 GROW;
6868 if (CUR == '<') {
6869 if (NXT(1) == '!') {
6870 switch (NXT(2)) {
6871 case 'E':
6872 if (NXT(3) == 'L')
6873 xmlParseElementDecl(ctxt);
6874 else if (NXT(3) == 'N')
6875 xmlParseEntityDecl(ctxt);
6876 break;
6877 case 'A':
6879 break;
6880 case 'N':
6882 break;
6883 case '-':
6884 xmlParseComment(ctxt);
6885 break;
6886 default:
6887 /* there is an error but it will be detected later */
6888 break;
6889 }
6890 } else if (NXT(1) == '?') {
6891 xmlParsePI(ctxt);
6892 }
6893 }
6894
6895 /*
6896 * detect requirement to exit there and act accordingly
6897 * and avoid having instate overridden later on
6898 */
6899 if (ctxt->instate == XML_PARSER_EOF)
6900 return;
6901
6902 ctxt->instate = XML_PARSER_DTD;
6903}
int xmlParseElementDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:6598
void xmlParseEntityDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:5409
void xmlParseNotationDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:5331
void xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:5976

Referenced by xmlParseConditionalSections(), xmlParseExternalSubset(), and xmlParseInternalSubset().

◆ xmlParseMisc()

void xmlParseMisc ( xmlParserCtxtPtr  ctxt)

xmlParseMisc: @ctxt: an XML parser context

parse an XML Misc* optional field.

[27] Misc ::= Comment | PI | S

Definition at line 10667 of file parser.c.

10667 {
10668 while (ctxt->instate != XML_PARSER_EOF) {
10670 GROW;
10671 if ((RAW == '<') && (NXT(1) == '?')) {
10672 xmlParsePI(ctxt);
10673 } else if (CMP4(CUR_PTR, '<', '!', '-', '-')) {
10674 xmlParseComment(ctxt);
10675 } else {
10676 break;
10677 }
10678 }
10679}
#define CMP4(s, c1, c2, c3, c4)
Definition: parser.c:2070

Referenced by xmlParseDocument().

◆ xmlParseName()

const xmlChar * xmlParseName ( xmlParserCtxtPtr  ctxt)

xmlParseName: @ctxt: an XML parser context

parse an XML name.

[4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender

[5] Name ::= (Letter | '_' | ':') (NameChar)*

[6] Names ::= Name (#x20 Name)*

Returns the Name parsed or NULL

Definition at line 3344 of file parser.c.

3344 {
3345 const xmlChar *in;
3346 const xmlChar *ret;
3347 size_t count = 0;
3348 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3351
3352 GROW;
3353
3354#ifdef DEBUG
3355 nbParseName++;
3356#endif
3357
3358 /*
3359 * Accelerator for simple ASCII names
3360 */
3361 in = ctxt->input->cur;
3362 if (((*in >= 0x61) && (*in <= 0x7A)) ||
3363 ((*in >= 0x41) && (*in <= 0x5A)) ||
3364 (*in == '_') || (*in == ':')) {
3365 in++;
3366 while (((*in >= 0x61) && (*in <= 0x7A)) ||
3367 ((*in >= 0x41) && (*in <= 0x5A)) ||
3368 ((*in >= 0x30) && (*in <= 0x39)) ||
3369 (*in == '_') || (*in == '-') ||
3370 (*in == ':') || (*in == '.'))
3371 in++;
3372 if ((*in > 0) && (*in < 0x80)) {
3373 count = in - ctxt->input->cur;
3374 if (count > maxLength) {
3375 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
3376 return(NULL);
3377 }
3378 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
3379 ctxt->input->cur = in;
3380 ctxt->input->col += count;
3381 if (ret == NULL)
3382 xmlErrMemory(ctxt, NULL);
3383 return(ret);
3384 }
3385 }
3386 /* accelerator for special cases */
3387 return(xmlParseNameComplex(ctxt));
3388}
#define XML_MAX_NAME_LENGTH
static const xmlChar * xmlParseNameComplex(xmlParserCtxtPtr ctxt)
Definition: parser.c:3203

Referenced by xmlParseAttributeListDecl(), xmlParseDocTypeDecl(), xmlParseElementChildrenContentDeclPriv(), xmlParseElementDecl(), xmlParseElementMixedContentDecl(), xmlParseEntityDecl(), xmlParseEntityRef(), xmlParseNameAndCompare(), xmlParseNotationDecl(), xmlParseNotationType(), xmlParsePEReference(), xmlParsePITarget(), and xmlParseQName().

◆ xmlParseNameAndCompare()

static const xmlChar * xmlParseNameAndCompare ( xmlParserCtxtPtr  ctxt,
xmlChar const other 
)
static

xmlParseNameAndCompare: @ctxt: an XML parser context

parse an XML name and compares for match (specialized for endtag parsing)

Returns NULL for an illegal name, (xmlChar*) 1 for success and the name for mismatch

Definition at line 3525 of file parser.c.

3525 {
3526 register const xmlChar *cmp = other;
3527 register const xmlChar *in;
3528 const xmlChar *ret;
3529
3530 GROW;
3531 if (ctxt->instate == XML_PARSER_EOF)
3532 return(NULL);
3533
3534 in = ctxt->input->cur;
3535 while (*in != 0 && *in == *cmp) {
3536 ++in;
3537 ++cmp;
3538 }
3539 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
3540 /* success */
3541 ctxt->input->col += in - ctxt->input->cur;
3542 ctxt->input->cur = in;
3543 return (const xmlChar*) 1;
3544 }
3545 /* failure (or end of input buffer), check with full function */
3546 ret = xmlParseName (ctxt);
3547 /* strings coming from the dictionary direct compare possible */
3548 if (ret == other) {
3549 return (const xmlChar*) 1;
3550 }
3551 return ret;
3552}
#define cmp(status, error)
Definition: error.c:114
int other
Definition: msacm.c:1376

Referenced by xmlParseEndTag2(), and xmlParseQNameAndCompare().

◆ xmlParseNameComplex()

static const xmlChar * xmlParseNameComplex ( xmlParserCtxtPtr  ctxt)
static

Definition at line 3203 of file parser.c.

3203 {
3204 int len = 0, l;
3205 int c;
3206 int count = 0;
3207 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3210
3211#ifdef DEBUG
3212 nbParseNameComplex++;
3213#endif
3214
3215 /*
3216 * Handler for more complex cases
3217 */
3218 GROW;
3219 if (ctxt->instate == XML_PARSER_EOF)
3220 return(NULL);
3221 c = CUR_CHAR(l);
3222 if ((ctxt->options & XML_PARSE_OLD10) == 0) {
3223 /*
3224 * Use the new checks of production [4] [4a] amd [5] of the
3225 * Update 5 of XML-1.0
3226 */
3227 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3228 (!(((c >= 'a') && (c <= 'z')) ||
3229 ((c >= 'A') && (c <= 'Z')) ||
3230 (c == '_') || (c == ':') ||
3231 ((c >= 0xC0) && (c <= 0xD6)) ||
3232 ((c >= 0xD8) && (c <= 0xF6)) ||
3233 ((c >= 0xF8) && (c <= 0x2FF)) ||
3234 ((c >= 0x370) && (c <= 0x37D)) ||
3235 ((c >= 0x37F) && (c <= 0x1FFF)) ||
3236 ((c >= 0x200C) && (c <= 0x200D)) ||
3237 ((c >= 0x2070) && (c <= 0x218F)) ||
3238 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3239 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3240 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3241 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3242 ((c >= 0x10000) && (c <= 0xEFFFF))))) {
3243 return(NULL);
3244 }
3245 len += l;
3246 NEXTL(l);
3247 c = CUR_CHAR(l);
3248 while ((c != ' ') && (c != '>') && (c != '/') && /* accelerators */
3249 (((c >= 'a') && (c <= 'z')) ||
3250 ((c >= 'A') && (c <= 'Z')) ||
3251 ((c >= '0') && (c <= '9')) || /* !start */
3252 (c == '_') || (c == ':') ||
3253 (c == '-') || (c == '.') || (c == 0xB7) || /* !start */
3254 ((c >= 0xC0) && (c <= 0xD6)) ||
3255 ((c >= 0xD8) && (c <= 0xF6)) ||
3256 ((c >= 0xF8) && (c <= 0x2FF)) ||
3257 ((c >= 0x300) && (c <= 0x36F)) || /* !start */
3258 ((c >= 0x370) && (c <= 0x37D)) ||
3259 ((c >= 0x37F) && (c <= 0x1FFF)) ||
3260 ((c >= 0x200C) && (c <= 0x200D)) ||
3261 ((c >= 0x203F) && (c <= 0x2040)) || /* !start */
3262 ((c >= 0x2070) && (c <= 0x218F)) ||
3263 ((c >= 0x2C00) && (c <= 0x2FEF)) ||
3264 ((c >= 0x3001) && (c <= 0xD7FF)) ||
3265 ((c >= 0xF900) && (c <= 0xFDCF)) ||
3266 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
3267 ((c >= 0x10000) && (c <= 0xEFFFF))
3268 )) {
3269 if (count++ > XML_PARSER_CHUNK_SIZE) {
3270 count = 0;
3271 GROW;
3272 if (ctxt->instate == XML_PARSER_EOF)
3273 return(NULL);
3274 }
3275 if (len <= INT_MAX - l)
3276 len += l;
3277 NEXTL(l);
3278 c = CUR_CHAR(l);
3279 }
3280 } else {
3281 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3282 (!IS_LETTER(c) && (c != '_') &&
3283 (c != ':'))) {
3284 return(NULL);
3285 }
3286 len += l;
3287 NEXTL(l);
3288 c = CUR_CHAR(l);
3289
3290 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
3291 ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
3292 (c == '.') || (c == '-') ||
3293 (c == '_') || (c == ':') ||
3294 (IS_COMBINING(c)) ||
3295 (IS_EXTENDER(c)))) {
3296 if (count++ > XML_PARSER_CHUNK_SIZE) {
3297 count = 0;
3298 GROW;
3299 if (ctxt->instate == XML_PARSER_EOF)
3300 return(NULL);
3301 }
3302 if (len <= INT_MAX - l)
3303 len += l;
3304 NEXTL(l);
3305 c = CUR_CHAR(l);
3306 }
3307 }
3308 if (len > maxLength) {
3309 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
3310 return(NULL);
3311 }
3312 if (ctxt->input->cur - ctxt->input->base < len) {
3313 /*
3314 * There were a couple of bugs where PERefs lead to to a change
3315 * of the buffer. Check the buffer size to avoid passing an invalid
3316 * pointer to xmlDictLookup.
3317 */
3319 "unexpected change of input buffer");
3320 return (NULL);
3321 }
3322 if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r'))
3323 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len));
3324 return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
3325}

Referenced by xmlParseName().

◆ xmlParseNCName()

static const xmlChar * xmlParseNCName ( xmlParserCtxtPtr  ctxt)
static

xmlParseNCName: @ctxt: an XML parser context @len: length of the string parsed

parse an XML name.

[4NS] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender

[5NS] NCName ::= (Letter | '_') (NCNameChar)*

Returns the Name parsed or NULL

Definition at line 3465 of file parser.c.

3465 {
3466 const xmlChar *in, *e;
3467 const xmlChar *ret;
3468 size_t count = 0;
3469 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3472
3473#ifdef DEBUG
3474 nbParseNCName++;
3475#endif
3476
3477 /*
3478 * Accelerator for simple ASCII names
3479 */
3480 in = ctxt->input->cur;
3481 e = ctxt->input->end;
3482 if ((((*in >= 0x61) && (*in <= 0x7A)) ||
3483 ((*in >= 0x41) && (*in <= 0x5A)) ||
3484 (*in == '_')) && (in < e)) {
3485 in++;
3486 while ((((*in >= 0x61) && (*in <= 0x7A)) ||
3487 ((*in >= 0x41) && (*in <= 0x5A)) ||
3488 ((*in >= 0x30) && (*in <= 0x39)) ||
3489 (*in == '_') || (*in == '-') ||
3490 (*in == '.')) && (in < e))
3491 in++;
3492 if (in >= e)
3493 goto complex;
3494 if ((*in > 0) && (*in < 0x80)) {
3495 count = in - ctxt->input->cur;
3496 if (count > maxLength) {
3497 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3498 return(NULL);
3499 }
3500 ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
3501 ctxt->input->cur = in;
3502 ctxt->input->col += count;
3503 if (ret == NULL) {
3504 xmlErrMemory(ctxt, NULL);
3505 }
3506 return(ret);
3507 }
3508 }
3509complex:
3510 return(xmlParseNCNameComplex(ctxt));
3511}
#define complex
Definition: complex.h:37
#define e
Definition: ke_i.h:82
static const xmlChar * xmlParseNCNameComplex(xmlParserCtxtPtr ctxt)
Definition: parser.c:3391

Referenced by xmlParseQName().

◆ xmlParseNCNameComplex()

static const xmlChar * xmlParseNCNameComplex ( xmlParserCtxtPtr  ctxt)
static

Definition at line 3391 of file parser.c.

3391 {
3392 int len = 0, l;
3393 int c;
3394 int count = 0;
3395 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3398 size_t startPosition = 0;
3399
3400#ifdef DEBUG
3401 nbParseNCNameComplex++;
3402#endif
3403
3404 /*
3405 * Handler for more complex cases
3406 */
3407 GROW;
3408 startPosition = CUR_PTR - BASE_PTR;
3409 c = CUR_CHAR(l);
3410 if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
3411 (!xmlIsNameStartChar(ctxt, c) || (c == ':'))) {
3412 return(NULL);
3413 }
3414
3415 while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
3416 (xmlIsNameChar(ctxt, c) && (c != ':'))) {
3417 if (count++ > XML_PARSER_CHUNK_SIZE) {
3418 count = 0;
3419 GROW;
3420 if (ctxt->instate == XML_PARSER_EOF)
3421 return(NULL);
3422 }
3423 if (len <= INT_MAX - l)
3424 len += l;
3425 NEXTL(l);
3426 c = CUR_CHAR(l);
3427 if (c == 0) {
3428 count = 0;
3429 /*
3430 * when shrinking to extend the buffer we really need to preserve
3431 * the part of the name we already parsed. Hence rolling back
3432 * by current length.
3433 */
3434 ctxt->input->cur -= l;
3435 GROW;
3436 if (ctxt->instate == XML_PARSER_EOF)
3437 return(NULL);
3438 ctxt->input->cur += l;
3439 c = CUR_CHAR(l);
3440 }
3441 }
3442 if (len > maxLength) {
3443 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3444 return(NULL);
3445 }
3446 return(xmlDictLookup(ctxt->dict, (BASE_PTR + startPosition), len));
3447}
#define BASE_PTR
Definition: parser.c:2068
static int xmlIsNameStartChar(xmlParserCtxtPtr ctxt, int c)
Definition: parser.c:3130
static int xmlIsNameChar(xmlParserCtxtPtr ctxt, int c)
Definition: parser.c:3161

Referenced by xmlParseNCName().

◆ xmlParseNmtoken()

xmlChar * xmlParseNmtoken ( xmlParserCtxtPtr  ctxt)

xmlParseNmtoken: @ctxt: an XML parser context

parse an XML Nmtoken.

[7] Nmtoken ::= (NameChar)+

[8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*

Returns the Nmtoken parsed or NULL

Definition at line 3662 of file parser.c.

3662 {
3664 int len = 0, l;
3665 int c;
3666 int count = 0;
3667 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3670
3671#ifdef DEBUG
3672 nbParseNmToken++;
3673#endif
3674
3675 GROW;
3676 if (ctxt->instate == XML_PARSER_EOF)
3677 return(NULL);
3678 c = CUR_CHAR(l);
3679
3680 while (xmlIsNameChar(ctxt, c)) {
3681 if (count++ > XML_PARSER_CHUNK_SIZE) {
3682 count = 0;
3683 GROW;
3684 }
3685 COPY_BUF(l,buf,len,c);
3686 NEXTL(l);
3687 c = CUR_CHAR(l);
3688 if (c == 0) {
3689 count = 0;
3690 GROW;
3691 if (ctxt->instate == XML_PARSER_EOF)
3692 return(NULL);
3693 c = CUR_CHAR(l);
3694 }
3695 if (len >= XML_MAX_NAMELEN) {
3696 /*
3697 * Okay someone managed to make a huge token, so he's ready to pay
3698 * for the processing speed.
3699 */
3700 xmlChar *buffer;
3701 int max = len * 2;
3702
3703 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
3704 if (buffer == NULL) {
3705 xmlErrMemory(ctxt, NULL);
3706 return(NULL);
3707 }
3708 memcpy(buffer, buf, len);
3709 while (xmlIsNameChar(ctxt, c)) {
3710 if (count++ > XML_PARSER_CHUNK_SIZE) {
3711 count = 0;
3712 GROW;
3713 if (ctxt->instate == XML_PARSER_EOF) {
3714 xmlFree(buffer);
3715 return(NULL);
3716 }
3717 }
3718 if (len + 10 > max) {
3719 xmlChar *tmp;
3720
3721 max *= 2;
3722 tmp = (xmlChar *) xmlRealloc(buffer,
3723 max * sizeof(xmlChar));
3724 if (tmp == NULL) {
3725 xmlErrMemory(ctxt, NULL);
3726 xmlFree(buffer);
3727 return(NULL);
3728 }
3729 buffer = tmp;
3730 }
3732 NEXTL(l);
3733 c = CUR_CHAR(l);
3734 if (len > maxLength) {
3735 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
3736 xmlFree(buffer);
3737 return(NULL);
3738 }
3739 }
3740 buffer[len] = 0;
3741 return(buffer);
3742 }
3743 }
3744 if (len == 0)
3745 return(NULL);
3746 if (len > maxLength) {
3747 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
3748 return(NULL);
3749 }
3750 return(xmlStrndup(buf, len));
3751}
#define XML_MAX_NAMELEN
#define max(a, b)
Definition: svc.c:63

Referenced by xmlParseEnumerationType(), and xmlParseQName().

◆ xmlParseNotationDecl()

void xmlParseNotationDecl ( xmlParserCtxtPtr  ctxt)

xmlParseNotationDecl: @ctxt: an XML parser context

parse a notation declaration

[82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'

Hence there is actually 3 choices: 'PUBLIC' S PubidLiteral 'PUBLIC' S PubidLiteral S SystemLiteral and 'SYSTEM' S SystemLiteral

See the NOTE on xmlParseExternalID().

Definition at line 5331 of file parser.c.

5331 {
5332 const xmlChar *name;
5333 xmlChar *Pubid;
5334 xmlChar *Systemid;
5335
5336 if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) {
5337 int inputid = ctxt->input->id;
5338 SHRINK;
5339 SKIP(10);
5340 if (SKIP_BLANKS == 0) {
5341 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5342 "Space required after '<!NOTATION'\n");
5343 return;
5344 }
5345
5346 name = xmlParseName(ctxt);
5347 if (name == NULL) {
5349 return;
5350 }
5351 if (xmlStrchr(name, ':') != NULL) {
5352 xmlNsErr(ctxt, XML_NS_ERR_COLON,
5353 "colons are forbidden from notation names '%s'\n",
5354 name, NULL, NULL);
5355 }
5356 if (SKIP_BLANKS == 0) {
5357 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
5358 "Space required after the NOTATION name'\n");
5359 return;
5360 }
5361
5362 /*
5363 * Parse the IDs.
5364 */
5365 Systemid = xmlParseExternalID(ctxt, &Pubid, 0);
5367
5368 if (RAW == '>') {
5369 if (inputid != ctxt->input->id) {
5370 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5371 "Notation declaration doesn't start and stop"
5372 " in the same entity\n");
5373 }
5374 NEXT;
5375 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
5376 (ctxt->sax->notationDecl != NULL))
5377 ctxt->sax->notationDecl(ctxt->userData, name, Pubid, Systemid);
5378 } else {
5380 }
5381 if (Systemid != NULL) xmlFree(Systemid);
5382 if (Pubid != NULL) xmlFree(Pubid);
5383 }
5384}
#define CMP10(s, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)
Definition: parser.c:2084

Referenced by xmlParseMarkupDecl().

◆ xmlParseNotationType()

xmlEnumerationPtr xmlParseNotationType ( xmlParserCtxtPtr  ctxt)

xmlParseNotationType: @ctxt: an XML parser context

parse an Notation attribute type.

Note: the leading 'NOTATION' S part has already being parsed...

[58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'

[ VC: Notation Attributes ] Values of this type must match one of the notation names included in the declaration; all notation names in the declaration must be declared.

Returns: the notation attribute tree built while parsing

Definition at line 5732 of file parser.c.

5732 {
5733 const xmlChar *name;
5735
5736 if (RAW != '(') {
5738 return(NULL);
5739 }
5740 SHRINK;
5741 do {
5742 NEXT;
5744 name = xmlParseName(ctxt);
5745 if (name == NULL) {
5746 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
5747 "Name expected in NOTATION declaration\n");
5749 return(NULL);
5750 }
5751 tmp = ret;
5752 while (tmp != NULL) {
5753 if (xmlStrEqual(name, tmp->name)) {
5754 xmlValidityError(ctxt, XML_DTD_DUP_TOKEN,
5755 "standalone: attribute notation value token %s duplicated\n",
5756 name, NULL);
5757 if (!xmlDictOwns(ctxt->dict, name))
5758 xmlFree((xmlChar *) name);
5759 break;
5760 }
5761 tmp = tmp->next;
5762 }
5763 if (tmp == NULL) {
5765 if (cur == NULL) {
5767 return(NULL);
5768 }
5769 if (last == NULL) ret = last = cur;
5770 else {
5771 last->next = cur;
5772 last = cur;
5773 }
5774 }
5776 } while (RAW == '|');
5777 if (RAW != ')') {
5780 return(NULL);
5781 }
5782 NEXT;
5783 return(ret);
5784}

Referenced by xmlParseEnumeratedType().

◆ xmlParsePEReference()

void xmlParsePEReference ( xmlParserCtxtPtr  ctxt)

xmlParsePEReference: @ctxt: an XML parser context

parse PEReference declarations The entity content is handled directly by pushing it's content as a new input stream.

[69] PEReference ::= '' Name ';'

[ WFC: No Recursion ] A parsed entity must not contain a recursive reference to itself, either directly or indirectly.

[ WFC: Entity Declared ] In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with "standalone='yes'", ... ... The declaration of a parameter entity must precede any reference to it...

[ VC: Entity Declared ] In a document with an external subset or external parameter entities with "standalone='no'", ... ... The declaration of a parameter entity must precede any reference to it...

[ WFC: In DTD ] Parameter-entity references may only appear in the DTD. NOTE: misleading but this is handled.

Definition at line 7912 of file parser.c.

7913{
7914 const xmlChar *name;
7917
7918 if (RAW != '%')
7919 return;
7920 NEXT;
7921 name = xmlParseName(ctxt);
7922 if (name == NULL) {
7923 xmlFatalErrMsg(ctxt, XML_ERR_PEREF_NO_NAME, "PEReference: no name\n");
7924 return;
7925 }
7928 "PEReference: %s\n", name);
7929 if (RAW != ';') {
7931 return;
7932 }
7933
7934 NEXT;
7935
7936 /*
7937 * Increase the number of entity references parsed
7938 */
7939 ctxt->nbentities++;
7940
7941 /*
7942 * Request the entity from SAX
7943 */
7944 if ((ctxt->sax != NULL) &&
7945 (ctxt->sax->getParameterEntity != NULL))
7946 entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
7947 if (ctxt->instate == XML_PARSER_EOF)
7948 return;
7949 if (entity == NULL) {
7950 /*
7951 * [ WFC: Entity Declared ]
7952 * In a document without any DTD, a document with only an
7953 * internal DTD subset which contains no parameter entity
7954 * references, or a document with "standalone='yes'", ...
7955 * ... The declaration of a parameter entity must precede
7956 * any reference to it...
7957 */
7958 if ((ctxt->standalone == 1) ||
7959 ((ctxt->hasExternalSubset == 0) &&
7960 (ctxt->hasPErefs == 0))) {
7961 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7962 "PEReference: %%%s; not found\n",
7963 name);
7964 } else {
7965 /*
7966 * [ VC: Entity Declared ]
7967 * In a document with an external subset or external
7968 * parameter entities with "standalone='no'", ...
7969 * ... The declaration of a parameter entity must
7970 * precede any reference to it...
7971 */
7972 if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
7973 xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
7974 "PEReference: %%%s; not found\n",
7975 name, NULL);
7976 } else
7977 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7978 "PEReference: %%%s; not found\n",
7979 name, NULL);
7980 ctxt->valid = 0;
7981 }
7982 xmlParserEntityCheck(ctxt, 0, NULL, 0);
7983 } else {
7984 /*
7985 * Internal checking in case the entity quest barfed
7986 */
7987 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
7989 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
7990 "Internal: %%%s; is not a parameter entity\n",
7991 name, NULL);
7992 } else {
7993 xmlChar start[4];
7994 xmlCharEncoding enc;
7995
7996 if (xmlParserEntityCheck(ctxt, 0, entity, 0))
7997 return;
7998
7999 if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
8000 ((ctxt->options & XML_PARSE_NOENT) == 0) &&
8001 ((ctxt->options & XML_PARSE_DTDVALID) == 0) &&
8002 ((ctxt->options & XML_PARSE_DTDLOAD) == 0) &&
8003 ((ctxt->options & XML_PARSE_DTDATTR) == 0) &&
8004 (ctxt->replaceEntities == 0) &&
8005 (ctxt->validate == 0))
8006 return;
8007
8009 if (xmlPushInput(ctxt, input) < 0) {
8011 return;
8012 }
8013
8014 if (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) {
8015 /*
8016 * Get the 4 first bytes and decode the charset
8017 * if enc != XML_CHAR_ENCODING_NONE
8018 * plug some encoding conversion routines.
8019 * Note that, since we may have some non-UTF8
8020 * encoding (like UTF16, bug 135229), the 'length'
8021 * is not known, but we can calculate based upon
8022 * the amount of data in the buffer.
8023 */
8024 GROW
8025 if (ctxt->instate == XML_PARSER_EOF)
8026 return;
8027 if ((ctxt->input->end - ctxt->input->cur)>=4) {
8028 start[0] = RAW;
8029 start[1] = NXT(1);
8030 start[2] = NXT(2);
8031 start[3] = NXT(3);
8032 enc = xmlDetectCharEncoding(start, 4);
8033 if (enc != XML_CHAR_ENCODING_NONE) {
8034 xmlSwitchEncoding(ctxt, enc);
8035 }
8036 }
8037
8038 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) &&
8039 (IS_BLANK_CH(NXT(5)))) {
8040 xmlParseTextDecl(ctxt);
8041 }
8042 }
8043 }
8044 }
8045 ctxt->hasPErefs = 1;
8046}

Referenced by xmlParseInternalSubset(), xmlParserHandlePEReference(), and xmlSkipBlankChars().

◆ xmlParsePI()

void xmlParsePI ( xmlParserCtxtPtr  ctxt)

xmlParsePI: @ctxt: an XML parser context

parse an XML Processing Instruction.

[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'

The processing is transferred to SAX once parsed.

Definition at line 5174 of file parser.c.

5174 {
5175 xmlChar *buf = NULL;
5176 size_t len = 0;
5178 size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ?
5181 int cur, l;
5182 const xmlChar *target;
5184 int count = 0;
5185
5186 if ((RAW == '<') && (NXT(1) == '?')) {
5187 int inputid = ctxt->input->id;
5188 state = ctxt->instate;
5189 ctxt->instate = XML_PARSER_PI;
5190 /*
5191 * this is a Processing Instruction.
5192 */
5193 SKIP(2);
5194 SHRINK;
5195
5196 /*
5197 * Parse the target name and check for special support like
5198 * namespace.
5199 */
5200 target = xmlParsePITarget(ctxt);
5201 if (target != NULL) {
5202 if ((RAW == '?') && (NXT(1) == '>')) {
5203 if (inputid != ctxt->input->id) {
5204 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5205 "PI declaration doesn't start and stop in"
5206 " the same entity\n");
5207 }
5208 SKIP(2);
5209
5210 /*
5211 * SAX: PI detected.
5212 */
5213 if ((ctxt->sax) && (!ctxt->disableSAX) &&
5214 (ctxt->sax->processingInstruction != NULL))
5215 ctxt->sax->processingInstruction(ctxt->userData,
5216 target, NULL);
5217 if (ctxt->instate != XML_PARSER_EOF)
5218 ctxt->instate = state;
5219 return;
5220 }
5221 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
5222 if (buf == NULL) {
5223 xmlErrMemory(ctxt, NULL);
5224 ctxt->instate = state;
5225 return;
5226 }
5227 if (SKIP_BLANKS == 0) {
5228 xmlFatalErrMsgStr(ctxt, XML_ERR_SPACE_REQUIRED,
5229 "ParsePI: PI %s space expected\n", target);
5230 }
5231 cur = CUR_CHAR(l);
5232 while (IS_CHAR(cur) && /* checked */
5233 ((cur != '?') || (NXT(1) != '>'))) {
5234 if (len + 5 >= size) {
5235 xmlChar *tmp;
5236 size_t new_size = size * 2;
5237 tmp = (xmlChar *) xmlRealloc(buf, new_size);
5238 if (tmp == NULL) {
5239 xmlErrMemory(ctxt, NULL);
5240 xmlFree(buf);
5241 ctxt->instate = state;
5242 return;
5243 }
5244 buf = tmp;
5245 size = new_size;
5246 }
5247 count++;
5248 if (count > 50) {
5249 SHRINK;
5250 GROW;
5251 if (ctxt->instate == XML_PARSER_EOF) {
5252 xmlFree(buf);
5253 return;
5254 }
5255 count = 0;
5256 }
5257 COPY_BUF(l,buf,len,cur);
5258 NEXTL(l);
5259 cur = CUR_CHAR(l);
5260 if (cur == 0) {
5261 SHRINK;
5262 GROW;
5263 cur = CUR_CHAR(l);
5264 }
5265 if (len > maxLength) {
5266 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
5267 "PI %s too big found", target);
5268 xmlFree(buf);
5269 ctxt->instate = state;
5270 return;
5271 }
5272 }
5273 buf[len] = 0;
5274 if (cur != '?') {
5275 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
5276 "ParsePI: PI %s never end ...\n", target);
5277 } else {
5278 if (inputid != ctxt->input->id) {
5279 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
5280 "PI declaration doesn't start and stop in"
5281 " the same entity\n");
5282 }
5283 SKIP(2);
5284
5285#ifdef LIBXML_CATALOG_ENABLED
5286 if (((state == XML_PARSER_MISC) ||
5287 (state == XML_PARSER_START)) &&
5288 (xmlStrEqual(target, XML_CATALOG_PI))) {
5289 xmlCatalogAllow allow = xmlCatalogGetDefaults();
5290 if ((allow == XML_CATA_ALLOW_DOCUMENT) ||
5291 (allow == XML_CATA_ALLOW_ALL))
5292 xmlParseCatalogPI(ctxt, buf);
5293 }
5294#endif
5295
5296
5297 /*
5298 * SAX: PI detected.
5299 */
5300 if ((ctxt->sax) && (!ctxt->disableSAX) &&
5301 (ctxt->sax->processingInstruction != NULL))
5302 ctxt->sax->processingInstruction(ctxt->userData,
5303 target, buf);
5304 }
5305 xmlFree(buf);
5306 } else {
5308 }
5309 if (ctxt->instate != XML_PARSER_EOF)
5310 ctxt->instate = state;
5311 }
5312}
GLenum target
Definition: glext.h:7315
@ XML_PARSER_PI
Definition: parser.h:114
@ XML_PARSER_MISC
Definition: parser.h:113
const xmlChar * xmlParsePITarget(xmlParserCtxtPtr ctxt)
Definition: parser.c:5066
@ XML_ERR_PI_NOT_FINISHED
Definition: xmlerror.h:147

Referenced by xmlParseContentInternal(), xmlParseMarkupDecl(), and xmlParseMisc().

◆ xmlParsePITarget()

const xmlChar * xmlParsePITarget ( xmlParserCtxtPtr  ctxt)

xmlParsePITarget: @ctxt: an XML parser context

parse the name of a PI

[17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))

Returns the PITarget name or NULL

Definition at line 5066 of file parser.c.

5066 {
5067 const xmlChar *name;
5068
5069 name = xmlParseName(ctxt);
5070 if ((name != NULL) &&
5071 ((name[0] == 'x') || (name[0] == 'X')) &&
5072 ((name[1] == 'm') || (name[1] == 'M')) &&
5073 ((name[2] == 'l') || (name[2] == 'L'))) {
5074 int i;
5075 if ((name[0] == 'x') && (name[1] == 'm') &&
5076 (name[2] == 'l') && (name[3] == 0)) {
5077 xmlFatalErrMsg(ctxt, XML_ERR_RESERVED_XML_NAME,
5078 "XML declaration allowed only at the start of the document\n");
5079 return(name);
5080 } else if (name[3] == 0) {
5082 return(name);
5083 }
5084 for (i = 0;;i++) {
5085 if (xmlW3CPIs[i] == NULL) break;
5086 if (xmlStrEqual(name, (const xmlChar *)xmlW3CPIs[i]))
5087 return(name);
5088 }
5089 xmlWarningMsg(ctxt, XML_ERR_RESERVED_XML_NAME,
5090 "xmlParsePITarget: invalid name prefix 'xml'\n",
5091 NULL, NULL);
5092 }
5093 if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) {
5094 xmlNsErr(ctxt, XML_NS_ERR_COLON,
5095 "colons are forbidden from PI names '%s'\n", name, NULL, NULL);
5096 }
5097 return(name);
5098}
static const char *const xmlW3CPIs[]
Definition: parser.c:294

Referenced by xmlParsePI().

◆ xmlParsePubidLiteral()

xmlChar * xmlParsePubidLiteral ( xmlParserCtxtPtr  ctxt)

xmlParsePubidLiteral: @ctxt: an XML parser context

parse an XML public literal

[12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"

Returns the PubidLiteral parsed or NULL.

Definition at line 4291 of file parser.c.

4291 {
4292 xmlChar *buf = NULL;
4293 int len = 0;
4295 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
4298 xmlChar cur;
4299 xmlChar stop;
4300 int count = 0;
4301 xmlParserInputState oldstate = ctxt->instate;
4302
4303 SHRINK;
4304 if (RAW == '"') {
4305 NEXT;
4306 stop = '"';
4307 } else if (RAW == '\'') {
4308 NEXT;
4309 stop = '\'';
4310 } else {
4312 return(NULL);
4313 }
4314 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
4315 if (buf == NULL) {
4316 xmlErrMemory(ctxt, NULL);
4317 return(NULL);
4318 }
4320 cur = CUR;
4321 while ((IS_PUBIDCHAR_CH(cur)) && (cur != stop)) { /* checked */
4322 if (len + 1 >= size) {
4323 xmlChar *tmp;
4324
4325 size *= 2;
4326 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
4327 if (tmp == NULL) {
4328 xmlErrMemory(ctxt, NULL);
4329 xmlFree(buf);
4330 return(NULL);
4331 }
4332 buf = tmp;
4333 }
4334 buf[len++] = cur;
4335 count++;
4336 if (count > 50) {
4337 SHRINK;
4338 GROW;
4339 count = 0;
4340 if (ctxt->instate == XML_PARSER_EOF) {
4341 xmlFree(buf);
4342 return(NULL);
4343 }
4344 }
4345 NEXT;
4346 cur = CUR;
4347 if (cur == 0) {
4348 GROW;
4349 SHRINK;
4350 cur = CUR;
4351 }
4352 if (len > maxLength) {
4353 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Public ID");
4354 xmlFree(buf);
4355 return(NULL);
4356 }
4357 }
4358 buf[len] = 0;
4359 if (cur != stop) {
4361 } else {
4362 NEXT;
4363 }
4364 ctxt->instate = oldstate;
4365 return(buf);
4366}
#define IS_PUBIDCHAR_CH(c)
@ XML_PARSER_PUBLIC_LITERAL
Definition: parser.h:128

Referenced by xmlParseExternalID().

◆ xmlParseQName()

static const xmlChar * xmlParseQName ( xmlParserCtxtPtr  ctxt,
const xmlChar **  prefix 
)
static

xmlParseQName: @ctxt: an XML parser context @prefix: pointer to store the prefix part

parse an XML Namespace QName

[6] QName ::= (Prefix ':')? LocalPart [7] Prefix ::= NCName [8] LocalPart ::= NCName

Returns the Name parsed or NULL

Definition at line 8788 of file parser.c.

8788 {
8789 const xmlChar *l, *p;
8790
8791 GROW;
8792
8793 l = xmlParseNCName(ctxt);
8794 if (l == NULL) {
8795 if (CUR == ':') {
8796 l = xmlParseName(ctxt);
8797 if (l != NULL) {
8798 xmlNsErr(ctxt, XML_NS_ERR_QNAME,
8799 "Failed to parse QName '%s'\n", l, NULL, NULL);
8800 *prefix = NULL;
8801 return(l);
8802 }
8803 }
8804 return(NULL);
8805 }
8806 if (CUR == ':') {
8807 NEXT;
8808 p = l;
8809 l = xmlParseNCName(ctxt);
8810 if (l == NULL) {
8811 xmlChar *tmp;
8812
8813 if (ctxt->instate == XML_PARSER_EOF)
8814 return(NULL);
8815 xmlNsErr(ctxt, XML_NS_ERR_QNAME,
8816 "Failed to parse QName '%s:'\n", p, NULL, NULL);
8817 l = xmlParseNmtoken(ctxt);
8818 if (l == NULL) {
8819 if (ctxt->instate == XML_PARSER_EOF)
8820 return(NULL);
8821 tmp = xmlBuildQName(BAD_CAST "", p, NULL, 0);
8822 } else {
8823 tmp = xmlBuildQName(l, p, NULL, 0);
8824 xmlFree((char *)l);
8825 }
8826 p = xmlDictLookup(ctxt->dict, tmp, -1);
8827 if (tmp != NULL) xmlFree(tmp);
8828 *prefix = NULL;
8829 return(p);
8830 }
8831 if (CUR == ':') {
8832 xmlChar *tmp;
8833
8834 xmlNsErr(ctxt, XML_NS_ERR_QNAME,
8835 "Failed to parse QName '%s:%s:'\n", p, l, NULL);
8836 NEXT;
8837 tmp = (xmlChar *) xmlParseName(ctxt);
8838 if (tmp != NULL) {
8839 tmp = xmlBuildQName(tmp, l, NULL, 0);
8840 l = xmlDictLookup(ctxt->dict, tmp, -1);
8841 if (tmp != NULL) xmlFree(tmp);
8842 *prefix = p;
8843 return(l);
8844 }
8845 if (ctxt->instate == XML_PARSER_EOF)
8846 return(NULL);
8847 tmp = xmlBuildQName(BAD_CAST "", l, NULL, 0);
8848 l = xmlDictLookup(ctxt->dict, tmp, -1);
8849 if (tmp != NULL) xmlFree(tmp);
8850 *prefix = p;
8851 return(l);
8852 }
8853 *prefix = p;
8854 } else
8855 *prefix = NULL;
8856 return(l);
8857}
GLfloat GLfloat p
Definition: glext.h:8902
XMLPUBFUN xmlChar *XMLCALL xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix, xmlChar *memory, int len)
static const xmlChar * xmlParseNCName(xmlParserCtxtPtr ctxt)
Definition: parser.c:3465
@ XML_NS_ERR_QNAME
Definition: xmlerror.h:215

Referenced by xmlParseAttribute2(), xmlParseQNameAndCompare(), and xmlParseStartTag2().

◆ xmlParseQNameAndCompare()

static const xmlChar * xmlParseQNameAndCompare ( xmlParserCtxtPtr  ctxt,
xmlChar const name,
xmlChar const prefix 
)
static

Definition at line 8873 of file parser.c.

8874 {
8875 const xmlChar *cmp;
8876 const xmlChar *in;
8877 const xmlChar *ret;
8878 const xmlChar *prefix2;
8879
8880 if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name));
8881
8882 GROW;
8883 in = ctxt->input->cur;
8884
8885 cmp = prefix;
8886 while (*in != 0 && *in == *cmp) {
8887 ++in;
8888 ++cmp;
8889 }
8890 if ((*cmp == 0) && (*in == ':')) {
8891 in++;
8892 cmp = name;
8893 while (*in != 0 && *in == *cmp) {
8894 ++in;
8895 ++cmp;
8896 }
8897 if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
8898 /* success */
8899 ctxt->input->col += in - ctxt->input->cur;
8900 ctxt->input->cur = in;
8901 return((const xmlChar*) 1);
8902 }
8903 }
8904 /*
8905 * all strings coms from the dictionary, equality can be done directly
8906 */
8907 ret = xmlParseQName (ctxt, &prefix2);
8908 if ((ret == name) && (prefix == prefix2))
8909 return((const xmlChar*) 1);
8910 return ret;
8911}

Referenced by xmlParseEndTag2().

◆ xmlParseReference()

void xmlParseReference ( xmlParserCtxtPtr  ctxt)

xmlParseReference: @ctxt: an XML parser context

parse and handle entity references in content, depending on the SAX interface, this may end-up in a call to character() if this is a CharRef, a predefined entity, if there is no reference() callback. or if the parser was asked to switch to that mode.

[67] Reference ::= EntityRef | CharRef

Definition at line 7078 of file parser.c.

7078 {
7079 xmlEntityPtr ent;
7080 xmlChar *val;
7081 int was_checked;
7084
7085
7086 if (RAW != '&')
7087 return;
7088
7089 /*
7090 * Simple case of a CharRef
7091 */
7092 if (NXT(1) == '#') {
7093 int i = 0;
7094 xmlChar out[16];
7095 int hex = NXT(2);
7096 int value = xmlParseCharRef(ctxt);
7097
7098 if (value == 0)
7099 return;
7100 if (ctxt->charset != XML_CHAR_ENCODING_UTF8) {
7101 /*
7102 * So we are using non-UTF-8 buffers
7103 * Check that the char fit on 8bits, if not
7104 * generate a CharRef.
7105 */
7106 if (value <= 0xFF) {
7107 out[0] = value;
7108 out[1] = 0;
7109 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
7110 (!ctxt->disableSAX))
7111 ctxt->sax->characters(ctxt->userData, out, 1);
7112 } else {
7113 if ((hex == 'x') || (hex == 'X'))
7114 snprintf((char *)out, sizeof(out), "#x%X", value);
7115 else
7116 snprintf((char *)out, sizeof(out), "#%d", value);
7117 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
7118 (!ctxt->disableSAX))
7119 ctxt->sax->reference(ctxt->userData, out);
7120 }
7121 } else {
7122 /*
7123 * Just encode the value in UTF-8
7124 */
7125 COPY_BUF(0 ,out, i, value);
7126 out[i] = 0;
7127 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
7128 (!ctxt->disableSAX))
7129 ctxt->sax->characters(ctxt->userData, out, i);
7130 }
7131 return;
7132 }
7133
7134 /*
7135 * We are seeing an entity reference
7136 */
7137 ent = xmlParseEntityRef(ctxt);
7138 if (ent == NULL) return;
7139 if (!ctxt->wellFormed)
7140 return;
7141 was_checked = ent->checked;
7142
7143 /* special case of predefined entities */
7144 if ((ent->name == NULL) ||
7146 val = ent->content;
7147 if (val == NULL) return;
7148 /*
7149 * inline the entity.
7150 */
7151 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
7152 (!ctxt->disableSAX))
7153 ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val));
7154 return;
7155 }
7156
7157 /*
7158 * The first reference to the entity trigger a parsing phase
7159 * where the ent->children is filled with the result from
7160 * the parsing.
7161 * Note: external parsed entities will not be loaded, it is not
7162 * required for a non-validating parser, unless the parsing option
7163 * of validating, or substituting entities were given. Doing so is
7164 * far more secure as the parser will only process data coming from
7165 * the document entity by default.
7166 */
7167 if (((ent->checked == 0) ||
7168 ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&
7171 unsigned long oldnbent = ctxt->nbentities, diff;
7172
7173 /*
7174 * This is a bit hackish but this seems the best
7175 * way to make sure both SAX and DOM entity support
7176 * behaves okay.
7177 */
7178 void *user_data;
7179 if (ctxt->userData == ctxt)
7180 user_data = NULL;
7181 else
7182 user_data = ctxt->userData;
7183
7184 /*
7185 * Check that this entity is well formed
7186 * 4.3.2: An internal general parsed entity is well-formed
7187 * if its replacement text matches the production labeled
7188 * content.
7189 */
7190 if (ent->etype == XML_INTERNAL_GENERAL_ENTITY) {
7191 ctxt->depth++;
7193 user_data, &list);
7194 ctxt->depth--;
7195
7196 } else if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) {
7197 ctxt->depth++;
7198 ret = xmlParseExternalEntityPrivate(ctxt->myDoc, ctxt, ctxt->sax,
7199 user_data, ctxt->depth, ent->URI,
7200 ent->ExternalID, &list);
7201 ctxt->depth--;
7202 } else {
7204 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR,
7205 "invalid entity type found\n", NULL);
7206 }
7207
7208 /*
7209 * Store the number of entities needing parsing for this entity
7210 * content and do checkings
7211 */
7212 diff = ctxt->nbentities - oldnbent + 1;
7213 if (diff > INT_MAX / 2)
7214 diff = INT_MAX / 2;
7215 ent->checked = diff * 2;
7216 if ((ent->content != NULL) && (xmlStrchr(ent->content, '<')))
7217 ent->checked |= 1;
7218 if (ret == XML_ERR_ENTITY_LOOP) {
7220 xmlHaltParser(ctxt);
7222 return;
7223 }
7224 if (xmlParserEntityCheck(ctxt, 0, ent, 0)) {
7226 return;
7227 }
7228
7229 if ((ret == XML_ERR_OK) && (list != NULL)) {
7230 if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) ||
7232 (ent->children == NULL)) {
7233 ent->children = list;
7234 /*
7235 * Prune it directly in the generated document
7236 * except for single text nodes.
7237 */
7238 if ((ctxt->replaceEntities == 0) ||
7239 (ctxt->parseMode == XML_PARSE_READER) ||
7240 ((list->type == XML_TEXT_NODE) &&
7241 (list->next == NULL))) {
7242 ent->owner = 1;
7243 while (list != NULL) {
7244 list->parent = (xmlNodePtr) ent;
7245 if (list->doc != ent->doc)
7246 xmlSetTreeDoc(list, ent->doc);
7247 if (list->next == NULL)
7248 ent->last = list;
7249 list = list->next;
7250 }
7251 list = NULL;
7252 } else {
7253 ent->owner = 0;
7254 while (list != NULL) {
7255 list->parent = (xmlNodePtr) ctxt->node;
7256 list->doc = ctxt->myDoc;
7257 if (list->next == NULL)
7258 ent->last = list;
7259 list = list->next;
7260 }
7261 list = ent->children;
7262#ifdef LIBXML_LEGACY_ENABLED
7264 xmlAddEntityReference(ent, list, NULL);
7265#endif /* LIBXML_LEGACY_ENABLED */
7266 }
7267 } else {
7269 list = NULL;
7270 }
7271 } else if ((ret != XML_ERR_OK) &&
7273 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7274 "Entity '%s' failed to parse\n", ent->name);
7275 if (ent->content != NULL)
7276 ent->content[0] = 0;
7277 xmlParserEntityCheck(ctxt, 0, ent, 0);
7278 } else if (list != NULL) {
7280 list = NULL;
7281 }
7282 if (ent->checked == 0)
7283 ent->checked = 2;
7284
7285 /* Prevent entity from being parsed and expanded twice (Bug 760367). */
7286 was_checked = 0;
7287 } else if (ent->checked != 1) {
7288 ctxt->nbentities += ent->checked / 2;
7289 }
7290
7291 /*
7292 * Now that the entity content has been gathered
7293 * provide it to the application, this can take different forms based
7294 * on the parsing modes.
7295 */
7296 if (ent->children == NULL) {
7297 /*
7298 * Probably running in SAX mode and the callbacks don't
7299 * build the entity content. So unless we already went
7300 * though parsing for first checking go though the entity
7301 * content to generate callbacks associated to the entity
7302 */
7303 if (was_checked != 0) {
7304 void *user_data;
7305 /*
7306 * This is a bit hackish but this seems the best
7307 * way to make sure both SAX and DOM entity support
7308 * behaves okay.
7309 */
7310 if (ctxt->userData == ctxt)
7311 user_data = NULL;
7312 else
7313 user_data = ctxt->userData;
7314
7315 if (ent->etype == XML_INTERNAL_GENERAL_ENTITY) {
7316 ctxt->depth++;
7318 ent->content, user_data, NULL);
7319 ctxt->depth--;
7320 } else if (ent->etype ==
7322 ctxt->depth++;
7324 ctxt->sax, user_data, ctxt->depth,
7325 ent->URI, ent->ExternalID, NULL);
7326 ctxt->depth--;
7327 } else {
7329 xmlErrMsgStr(ctxt, XML_ERR_INTERNAL_ERROR,
7330 "invalid entity type found\n", NULL);
7331 }
7332 if (ret == XML_ERR_ENTITY_LOOP) {
7334 return;
7335 }
7336 }
7337 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
7338 (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) {
7339 /*
7340 * Entity reference callback comes second, it's somewhat
7341 * superfluous but a compatibility to historical behaviour
7342 */
7343 ctxt->sax->reference(ctxt->userData, ent->name);
7344 }
7345 return;
7346 }
7347
7348 /*
7349 * If we didn't get any children for the entity being built
7350 */
7351 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
7352 (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) {
7353 /*
7354 * Create a node.
7355 */
7356 ctxt->sax->reference(ctxt->userData, ent->name);
7357 return;
7358 }
7359
7360 if ((ctxt->replaceEntities) || (ent->children == NULL)) {
7361 /*
7362 * There is a problem on the handling of _private for entities
7363 * (bug 155816): Should we copy the content of the field from
7364 * the entity (possibly overwriting some value set by the user
7365 * when a copy is created), should we leave it alone, or should
7366 * we try to take care of different situations? The problem
7367 * is exacerbated by the usage of this field by the xmlReader.
7368 * To fix this bug, we look at _private on the created node
7369 * and, if it's NULL, we copy in whatever was in the entity.
7370 * If it's not NULL we leave it alone. This is somewhat of a
7371 * hack - maybe we should have further tests to determine
7372 * what to do.
7373 */
7374 if ((ctxt->node != NULL) && (ent->children != NULL)) {
7375 /*
7376 * Seems we are generating the DOM content, do
7377 * a simple tree copy for all references except the first
7378 * In the first occurrence list contains the replacement.
7379 */
7380 if (((list == NULL) && (ent->owner == 0)) ||
7381 (ctxt->parseMode == XML_PARSE_READER)) {
7382 xmlNodePtr nw = NULL, cur, firstChild = NULL;
7383
7384 /*
7385 * We are copying here, make sure there is no abuse
7386 */
7387 ctxt->sizeentcopy += ent->length + 5;
7388 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7389 return;
7390
7391 /*
7392 * when operating on a reader, the entities definitions
7393 * are always owning the entities subtree.
7394 if (ctxt->parseMode == XML_PARSE_READER)
7395 ent->owner = 1;
7396 */
7397
7398 cur = ent->children;
7399 while (cur != NULL) {
7400 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
7401 if (nw != NULL) {
7402 if (nw->_private == NULL)
7403 nw->_private = cur->_private;
7404 if (firstChild == NULL){
7405 firstChild = nw;
7406 }
7407 nw = xmlAddChild(ctxt->node, nw);
7408 }
7409 if (cur == ent->last) {
7410 /*
7411 * needed to detect some strange empty
7412 * node cases in the reader tests
7413 */
7414 if ((ctxt->parseMode == XML_PARSE_READER) &&
7415 (nw != NULL) &&
7416 (nw->type == XML_ELEMENT_NODE) &&
7417 (nw->children == NULL))
7418 nw->extra = 1;
7419
7420 break;
7421 }
7422 cur = cur->next;
7423 }
7424#ifdef LIBXML_LEGACY_ENABLED
7426 xmlAddEntityReference(ent, firstChild, nw);
7427#endif /* LIBXML_LEGACY_ENABLED */
7428 } else if ((list == NULL) || (ctxt->inputNr > 0)) {
7429 xmlNodePtr nw = NULL, cur, next, last,
7430 firstChild = NULL;
7431
7432 /*
7433 * We are copying here, make sure there is no abuse
7434 */
7435 ctxt->sizeentcopy += ent->length + 5;
7436 if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
7437 return;
7438
7439 /*
7440 * Copy the entity child list and make it the new
7441 * entity child list. The goal is to make sure any
7442 * ID or REF referenced will be the one from the
7443 * document content and not the entity copy.
7444 */
7445 cur = ent->children;
7446 ent->children = NULL;
7447 last = ent->last;
7448 ent->last = NULL;
7449 while (cur != NULL) {
7450 next = cur->next;
7451 cur->next = NULL;
7452 cur->parent = NULL;
7453 nw = xmlDocCopyNode(cur, ctxt->myDoc, 1);
7454 if (nw != NULL) {
7455 if (nw->_private == NULL)
7456 nw->_private = cur->_private;
7457 if (firstChild == NULL){
7458 firstChild = cur;
7459 }
7460 xmlAddChild((xmlNodePtr) ent, nw);
7461 xmlAddChild(ctxt->node, cur);
7462 }
7463 if (cur == last)
7464 break;
7465 cur = next;
7466 }
7467 if (ent->owner == 0)
7468 ent->owner = 1;
7469#ifdef LIBXML_LEGACY_ENABLED
7471 xmlAddEntityReference(ent, firstChild, nw);
7472#endif /* LIBXML_LEGACY_ENABLED */
7473 } else {
7474 const xmlChar *nbktext;
7475
7476 /*
7477 * the name change is to avoid coalescing of the
7478 * node with a possible previous text one which
7479 * would make ent->children a dangling pointer
7480 */
7481 nbktext = xmlDictLookup(ctxt->dict, BAD_CAST "nbktext",
7482 -1);
7483 if (ent->children->type == XML_TEXT_NODE)
7484 ent->children->name = nbktext;
7485 if ((ent->last != ent->children) &&
7486 (ent->last->type == XML_TEXT_NODE))
7487 ent->last->name = nbktext;
7488 xmlAddChildList(ctxt->node, ent->children);
7489 }
7490
7491 /*
7492 * This is to avoid a nasty side effect, see
7493 * characters() in SAX.c
7494 */
7495 ctxt->nodemem = 0;
7496 ctxt->nodelen = 0;
7497 return;
7498 }
7499 }
7500}
struct list * next
Definition: list.h:38
int hex(char ch)
if(dx< 0)
Definition: linetemp.h:194
static unsigned __int64 next
Definition: rand_nt.c:6
static FILE * out
Definition: regtests2xml.c:44
#define list
Definition: rosglue.h:35
@ XML_PARSE_READER
Definition: parser.h:167
xmlNode * xmlNodePtr
Definition: tree.h:488
XMLPUBFUN void XMLCALL xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc)
XMLPUBFUN xmlNodePtr XMLCALL xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int recursive)
static xmlParserErrors xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, const xmlChar *string, void *user_data, xmlNodePtr *lst)
Definition: parser.c:13303
int length
Definition: entities.h:51
const xmlChar * URI
Definition: entities.h:57
const xmlChar * ExternalID
Definition: entities.h:53
struct _xmlNode * last
Definition: entities.h:43
struct _xmlNode * children
Definition: entities.h:42
struct _xmlDoc * doc
Definition: entities.h:47
void * _private
Definition: tree.h:490
unsigned short extra
Definition: tree.h:507
xmlParserMode parseMode
Definition: parser.h:302
#define snprintf
Definition: wintirpc.h:48

Referenced by xmlParseContentInternal().

◆ xmlParserEntityCheck()

static int xmlParserEntityCheck ( xmlParserCtxtPtr  ctxt,
size_t  size,
xmlEntityPtr  ent,
size_t  replacement 
)
static

Definition at line 128 of file parser.c.

130{
131 size_t consumed = 0;
132 int i;
133
134 if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
135 return (0);
137 return (1);
138
139 /*
140 * This may look absurd but is needed to detect
141 * entities problems
142 */
143 if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
144 (ent->content != NULL) && (ent->checked == 0) &&
145 (ctxt->errNo != XML_ERR_ENTITY_LOOP)) {
146 unsigned long oldnbent = ctxt->nbentities, diff;
147 xmlChar *rep;
148
149 ent->checked = 1;
150
151 ++ctxt->depth;
152 rep = xmlStringDecodeEntities(ctxt, ent->content,
153 XML_SUBSTITUTE_REF, 0, 0, 0);
154 --ctxt->depth;
155 if ((rep == NULL) || (ctxt->errNo == XML_ERR_ENTITY_LOOP)) {
156 ent->content[0] = 0;
157 }
158
159 diff = ctxt->nbentities - oldnbent + 1;
160 if (diff > INT_MAX / 2)
161 diff = INT_MAX / 2;
162 ent->checked = diff * 2;
163 if (rep != NULL) {
164 if (xmlStrchr(rep, '<'))
165 ent->checked |= 1;
166 xmlFree(rep);
167 rep = NULL;
168 }
169 }
170
171 /*
172 * Prevent entity exponential check, not just replacement while
173 * parsing the DTD
174 * The check is potentially costly so do that only once in a thousand
175 */
176 if ((ctxt->instate == XML_PARSER_DTD) && (ctxt->nbentities > 10000) &&
177 (ctxt->nbentities % 1024 == 0)) {
178 for (i = 0;i < ctxt->inputNr;i++) {
179 consumed += ctxt->inputTab[i]->consumed +
180 (ctxt->inputTab[i]->cur - ctxt->inputTab[i]->base);
181 }
184 ctxt->instate = XML_PARSER_EOF;
185 return (1);
186 }
187 consumed = 0;
188 }
189
190
191
192 if (replacement != 0) {
193 if (replacement < XML_MAX_TEXT_LENGTH)
194 return(0);
195
196 /*
197 * If the volume of entity copy reaches 10 times the
198 * amount of parsed data and over the large text threshold
199 * then that's very likely to be an abuse.
200 */
201 if (ctxt->input != NULL) {
202 consumed = ctxt->input->consumed +
203 (ctxt->input->cur - ctxt->input->base);
204 }
205 consumed += ctxt->sizeentities;
206
207 if (replacement < XML_PARSER_NON_LINEAR * consumed)
208 return(0);
209 } else if (size != 0) {
210 /*
211 * Do the check based on the replacement size of the entity
212 */
214 return(0);
215
216 /*
217 * A limit on the amount of text data reasonably used
218 */
219 if (ctxt->input != NULL) {
220 consumed = ctxt->input->consumed +
221 (ctxt->input->cur - ctxt->input->base);
222 }
223 consumed += ctxt->sizeentities;
224
227 return (0);
228 } else if (ent != NULL) {
229 /*
230 * use the number of parsed entities in the replacement
231 */
232 size = ent->checked / 2;
233
234 /*
235 * The amount of data parsed counting entities size only once
236 */
237 if (ctxt->input != NULL) {
238 consumed = ctxt->input->consumed +
239 (ctxt->input->cur - ctxt->input->base);
240 }
241 consumed += ctxt->sizeentities;
242
243 /*
244 * Check the density of entities for the amount of data
245 * knowing an entity reference will take at least 3 bytes
246 */
248 return (0);
249 } else {
250 /*
251 * strange we got no data for checking
252 */
253 if (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&
255 (ctxt->nbentities <= 10000))
256 return (0);
257 }
259 return (1);
260}
int consumed
Definition: scanf.h:134
#define XML_PARSER_NON_LINEAR
Definition: parser.c:116
#define XML_PARSER_BIG_ENTITY
Definition: parser.c:107

Referenced by xmlParseEntityRef(), xmlParsePEReference(), xmlParseReference(), xmlParseStringEntityRef(), xmlParseStringPEReference(), and xmlStringLenDecodeEntities().

◆ xmlParserHandlePEReference()

void xmlParserHandlePEReference ( xmlParserCtxtPtr  ctxt)

xmlParserHandlePEReference: @ctxt: the parser context

[69] PEReference ::= '' Name ';'

[ WFC: No Recursion ] A parsed entity must not contain a recursive reference to itself, either directly or indirectly.

[ WFC: Entity Declared ] In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with "standalone='yes'", ... ... The declaration of a parameter entity must precede any reference to it...

[ VC: Entity Declared ] In a document with an external subset or external parameter entities with "standalone='no'", ... ... The declaration of a parameter entity must precede any reference to it...

[ WFC: In DTD ] Parameter-entity references may only appear in the DTD. NOTE: misleading but this is handled.

A PEReference may have been detected in the current input stream the handling is done accordingly to http://www.w3.org/TR/REC-xml#entproc i.e.

  • Included in literal in entity values
  • Included as Parameter Entity reference within DTDs

Definition at line 2550 of file parser.c.

2550 {
2551 switch(ctxt->instate) {
2553 return;
2554 case XML_PARSER_COMMENT:
2555 return;
2557 return;
2558 case XML_PARSER_END_TAG:
2559 return;
2560 case XML_PARSER_EOF:
2562 return;
2563 case XML_PARSER_PROLOG:
2564 case XML_PARSER_START:
2565 case XML_PARSER_MISC:
2567 return;
2569 case XML_PARSER_CONTENT:
2571 case XML_PARSER_PI:
2574 /* we just ignore it there */
2575 return;
2576 case XML_PARSER_EPILOG:
2578 return;
2580 /*
2581 * NOTE: in the case of entity values, we don't do the
2582 * substitution here since we need the literal
2583 * entity value to be able to save the internal
2584 * subset of the document.
2585 * This will be handled by xmlStringDecodeEntities
2586 */
2587 return;
2588 case XML_PARSER_DTD:
2589 /*
2590 * [WFC: Well-Formedness Constraint: PEs in Internal Subset]
2591 * In the internal DTD subset, parameter-entity references
2592 * can occur only where markup declarations can occur, not
2593 * within markup declarations.
2594 * In that case this is handled in xmlParseMarkupDecl
2595 */
2596 if ((ctxt->external == 0) && (ctxt->inputNr == 1))
2597 return;
2598 if (IS_BLANK_CH(NXT(1)) || NXT(1) == 0)
2599 return;
2600 break;
2601 case XML_PARSER_IGNORE:
2602 return;
2603 }
2604
2605 xmlParsePEReference(ctxt);
2606}
@ XML_PARSER_END_TAG
Definition: parser.h:121
@ XML_PARSER_SYSTEM_LITERAL
Definition: parser.h:125
@ XML_PARSER_START_TAG
Definition: parser.h:118

◆ xmlParseSDDecl()

int xmlParseSDDecl ( xmlParserCtxtPtr  ctxt)

xmlParseSDDecl: @ctxt: an XML parser context

parse the XML standalone declaration

[32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))

[ VC: Standalone Document Declaration ] TODO The standalone document declaration must have the value "no" if any external markup declarations contain declarations of:

  • attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
  • entities (other than amp, lt, gt, apos, quot), if references to those entities appear in the document, or
  • attributes with values subject to normalization, where the attribute appears in the document with a value which will change as a result of normalization, or
  • element types with element content, if white space occurs directly within any instance of those types.

Returns: 1 if standalone="yes" 0 if standalone="no" -2 if standalone attribute is missing or invalid (A standalone value of -2 means that the XML declaration was found, but no value was specified for the standalone attribute).

Definition at line 10490 of file parser.c.

10490 {
10491 int standalone = -2;
10492
10494 if (CMP10(CUR_PTR, 's', 't', 'a', 'n', 'd', 'a', 'l', 'o', 'n', 'e')) {
10495 SKIP(10);
10497 if (RAW != '=') {
10499 return(standalone);
10500 }
10501 NEXT;
10503 if (RAW == '\''){
10504 NEXT;
10505 if ((RAW == 'n') && (NXT(1) == 'o')) {
10506 standalone = 0;
10507 SKIP(2);
10508 } else if ((RAW == 'y') && (NXT(1) == 'e') &&
10509 (NXT(2) == 's')) {
10510 standalone = 1;
10511 SKIP(3);
10512 } else {
10514 }
10515 if (RAW != '\'') {
10517 } else
10518 NEXT;
10519 } else if (RAW == '"'){
10520 NEXT;
10521 if ((RAW == 'n') && (NXT(1) == 'o')) {
10522 standalone = 0;
10523 SKIP(2);
10524 } else if ((RAW == 'y') && (NXT(1) == 'e') &&
10525 (NXT(2) == 's')) {
10526 standalone = 1;
10527 SKIP(3);
10528 } else {
10530 }
10531 if (RAW != '"') {
10533 } else
10534 NEXT;
10535 } else {
10537 }
10538 }
10539 return(standalone);
10540}

Referenced by xmlParseXMLDecl().

◆ xmlParseStartTag2()

static const xmlChar * xmlParseStartTag2 ( xmlParserCtxtPtr  ctxt,
const xmlChar **  pref,
const xmlChar **  URI,
int tlen 
)
static

xmlParseStartTag2: @ctxt: an XML parser context

parse a start of tag either for rule element or EmptyElement. In both case we don't parse the tag closing chars. This routine is called when running SAX2 parsing

[40] STag ::= '<' Name (S Attribute)* S? '>'

[ WFC: Unique Att Spec ] No attribute name may appear more than once in the same start-tag or empty-element tag.

[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'

[ WFC: Unique Att Spec ] No attribute name may appear more than once in the same start-tag or empty-element tag.

With namespace:

[NS 8] STag ::= '<' QName (S Attribute)* S? '>'

[NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'

Returns the element name parsed

Definition at line 9256 of file parser.c.

9257 {
9258 const xmlChar *localname;
9259 const xmlChar *prefix;
9260 const xmlChar *attname;
9261 const xmlChar *aprefix;
9262 const xmlChar *nsname;
9263 xmlChar *attvalue;
9264 const xmlChar **atts = ctxt->atts;
9265 int maxatts = ctxt->maxatts;
9266 int nratts, nbatts, nbdef, inputid;
9267 int i, j, nbNs, attval;
9268 unsigned long cur;
9269 int nsNr = ctxt->nsNr;
9270
9271 if (RAW != '<') return(NULL);
9272 NEXT1;
9273
9274 /*
9275 * NOTE: it is crucial with the SAX2 API to never call SHRINK beyond that
9276 * point since the attribute values may be stored as pointers to
9277 * the buffer and calling SHRINK would destroy them !
9278 * The Shrinking is only possible once the full set of attribute
9279 * callbacks have been done.
9280 */
9281 SHRINK;
9282 cur = ctxt->input->cur - ctxt->input->base;
9283 inputid = ctxt->input->id;
9284 nbatts = 0;
9285 nratts = 0;
9286 nbdef = 0;
9287 nbNs = 0;
9288 attval = 0;
9289 /* Forget any namespaces added during an earlier parse of this element. */
9290 ctxt->nsNr = nsNr;
9291
9292 localname = xmlParseQName(ctxt, &prefix);
9293 if (localname == NULL) {
9294 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
9295 "StartTag: invalid element name\n");
9296 return(NULL);
9297 }
9298 *tlen = ctxt->input->cur - ctxt->input->base - cur;
9299
9300 /*
9301 * Now parse the attributes, it ends up with the ending
9302 *
9303 * (S Attribute)* S?
9304 */
9306 GROW;
9307
9308 while (((RAW != '>') &&
9309 ((RAW != '/') || (NXT(1) != '>')) &&
9310 (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
9311 int id = ctxt->input->id;
9312 unsigned long cons = CUR_CONSUMED;
9313 int len = -1, alloc = 0;
9314
9315 attname = xmlParseAttribute2(ctxt, prefix, localname,
9316 &aprefix, &attvalue, &len, &alloc);
9317 if ((attname == NULL) || (attvalue == NULL))
9318 goto next_attr;
9319 if (len < 0) len = xmlStrlen(attvalue);
9320
9321 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
9322 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
9323 xmlURIPtr uri;
9324
9325 if (URL == NULL) {
9326 xmlErrMemory(ctxt, "dictionary allocation failure");
9327 if ((attvalue != NULL) && (alloc != 0))
9328 xmlFree(attvalue);
9329 localname = NULL;
9330 goto done;
9331 }
9332 if (*URL != 0) {
9333 uri = xmlParseURI((const char *) URL);
9334 if (uri == NULL) {
9335 xmlNsErr(ctxt, XML_WAR_NS_URI,
9336 "xmlns: '%s' is not a valid URI\n",
9337 URL, NULL, NULL);
9338 } else {
9339 if (uri->scheme == NULL) {
9340 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
9341 "xmlns: URI %s is not absolute\n",
9342 URL, NULL, NULL);
9343 }
9344 xmlFreeURI(uri);
9345 }
9346 if (URL == ctxt->str_xml_ns) {
9347 if (attname != ctxt->str_xml) {
9348 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9349 "xml namespace URI cannot be the default namespace\n",
9350 NULL, NULL, NULL);
9351 }
9352 goto next_attr;
9353 }
9354 if ((len == 29) &&
9355 (xmlStrEqual(URL,
9356 BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
9357 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9358 "reuse of the xmlns namespace name is forbidden\n",
9359 NULL, NULL, NULL);
9360 goto next_attr;
9361 }
9362 }
9363 /*
9364 * check that it's not a defined namespace
9365 */
9366 for (j = 1;j <= nbNs;j++)
9367 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
9368 break;
9369 if (j <= nbNs)
9370 xmlErrAttributeDup(ctxt, NULL, attname);
9371 else
9372 if (nsPush(ctxt, NULL, URL) > 0) nbNs++;
9373
9374 } else if (aprefix == ctxt->str_xmlns) {
9375 const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
9376 xmlURIPtr uri;
9377
9378 if (attname == ctxt->str_xml) {
9379 if (URL != ctxt->str_xml_ns) {
9380 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9381 "xml namespace prefix mapped to wrong URI\n",
9382 NULL, NULL, NULL);
9383 }
9384 /*
9385 * Do not keep a namespace definition node
9386 */
9387 goto next_attr;
9388 }
9389 if (URL == ctxt->str_xml_ns) {
9390 if (attname != ctxt->str_xml) {
9391 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9392 "xml namespace URI mapped to wrong prefix\n",
9393 NULL, NULL, NULL);
9394 }
9395 goto next_attr;
9396 }
9397 if (attname == ctxt->str_xmlns) {
9398 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9399 "redefinition of the xmlns prefix is forbidden\n",
9400 NULL, NULL, NULL);
9401 goto next_attr;
9402 }
9403 if ((len == 29) &&
9404 (xmlStrEqual(URL,
9405 BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
9406 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9407 "reuse of the xmlns namespace name is forbidden\n",
9408 NULL, NULL, NULL);
9409 goto next_attr;
9410 }
9411 if ((URL == NULL) || (URL[0] == 0)) {
9412 xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
9413 "xmlns:%s: Empty XML namespace is not allowed\n",
9414 attname, NULL, NULL);
9415 goto next_attr;
9416 } else {
9417 uri = xmlParseURI((const char *) URL);
9418 if (uri == NULL) {
9419 xmlNsErr(ctxt, XML_WAR_NS_URI,
9420 "xmlns:%s: '%s' is not a valid URI\n",
9421 attname, URL, NULL);
9422 } else {
9423 if ((ctxt->pedantic) && (uri->scheme == NULL)) {
9424 xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
9425 "xmlns:%s: URI %s is not absolute\n",
9426 attname, URL, NULL);
9427 }
9428 xmlFreeURI(uri);
9429 }
9430 }
9431
9432 /*
9433 * check that it's not a defined namespace
9434 */
9435 for (j = 1;j <= nbNs;j++)
9436 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
9437 break;
9438 if (j <= nbNs)
9439 xmlErrAttributeDup(ctxt, aprefix, attname);
9440 else
9441 if (nsPush(ctxt, attname, URL) > 0) nbNs++;
9442
9443 } else {
9444 /*
9445 * Add the pair to atts
9446 */
9447 if ((atts == NULL) || (nbatts + 5 > maxatts)) {
9448 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
9449 goto next_attr;
9450 }
9451 maxatts = ctxt->maxatts;
9452 atts = ctxt->atts;
9453 }
9454 ctxt->attallocs[nratts++] = alloc;
9455 atts[nbatts++] = attname;
9456 atts[nbatts++] = aprefix;
9457 /*
9458 * The namespace URI field is used temporarily to point at the
9459 * base of the current input buffer for non-alloced attributes.
9460 * When the input buffer is reallocated, all the pointers become
9461 * invalid, but they can be reconstructed later.
9462 */
9463 if (alloc)
9464 atts[nbatts++] = NULL;
9465 else
9466 atts[nbatts++] = ctxt->input->base;
9467 atts[nbatts++] = attvalue;
9468 attvalue += len;
9469 atts[nbatts++] = attvalue;
9470 /*
9471 * tag if some deallocation is needed
9472 */
9473 if (alloc != 0) attval = 1;
9474 attvalue = NULL; /* moved into atts */
9475 }
9476
9477next_attr:
9478 if ((attvalue != NULL) && (alloc != 0)) {
9479 xmlFree(attvalue);
9480 attvalue = NULL;
9481 }
9482
9483 GROW
9484 if (ctxt->instate == XML_PARSER_EOF)
9485 break;
9486 if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
9487 break;
9488 if (SKIP_BLANKS == 0) {
9489 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
9490 "attributes construct error\n");
9491 break;
9492 }
9493 if ((cons == CUR_CONSUMED) && (id == ctxt->input->id) &&
9494 (attname == NULL) && (attvalue == NULL)) {
9496 "xmlParseStartTag: problem parsing attributes\n");
9497 break;
9498 }
9499 GROW;
9500 }
9501
9502 if (ctxt->input->id != inputid) {
9504 "Unexpected change of input\n");
9505 localname = NULL;
9506 goto done;
9507 }
9508
9509 /* Reconstruct attribute value pointers. */
9510 for (i = 0, j = 0; j < nratts; i += 5, j++) {
9511 if (atts[i+2] != NULL) {
9512 /*
9513 * Arithmetic on dangling pointers is technically undefined
9514 * behavior, but well...
9515 */
9516 ptrdiff_t offset = ctxt->input->base - atts[i+2];
9517 atts[i+2] = NULL; /* Reset repurposed namespace URI */
9518 atts[i+3] += offset; /* value */
9519 atts[i+4] += offset; /* valuend */
9520 }
9521 }
9522
9523 /*
9524 * The attributes defaulting
9525 */
9526 if (ctxt->attsDefault != NULL) {
9528
9529 defaults = xmlHashLookup2(ctxt->attsDefault, localname, prefix);
9530 if (defaults != NULL) {
9531 for (i = 0;i < defaults->nbAttrs;i++) {
9532 attname = defaults->values[5 * i];
9533 aprefix = defaults->values[5 * i + 1];
9534
9535 /*
9536 * special work for namespaces defaulted defs
9537 */
9538 if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
9539 /*
9540 * check that it's not a defined namespace
9541 */
9542 for (j = 1;j <= nbNs;j++)
9543 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
9544 break;
9545 if (j <= nbNs) continue;
9546
9547 nsname = xmlGetNamespace(ctxt, NULL);
9548 if (nsname != defaults->values[5 * i + 2]) {
9549 if (nsPush(ctxt, NULL,
9550 defaults->values[5 * i + 2]) > 0)
9551 nbNs++;
9552 }
9553 } else if (aprefix == ctxt->str_xmlns) {
9554 /*
9555 * check that it's not a defined namespace
9556 */
9557 for (j = 1;j <= nbNs;j++)
9558 if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
9559 break;
9560 if (j <= nbNs) continue;
9561
9562 nsname = xmlGetNamespace(ctxt, attname);
9563 if (nsname != defaults->values[2]) {
9564 if (nsPush(ctxt, attname,
9565 defaults->values[5 * i + 2]) > 0)
9566 nbNs++;
9567 }
9568 } else {
9569 /*
9570 * check that it's not a defined attribute
9571 */
9572 for (j = 0;j < nbatts;j+=5) {
9573 if ((attname == atts[j]) && (aprefix == atts[j+1]))
9574 break;
9575 }
9576 if (j < nbatts) continue;
9577
9578 if ((atts == NULL) || (nbatts + 5 > maxatts)) {
9579 if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
9580 localname = NULL;
9581 goto done;
9582 }
9583 maxatts = ctxt->maxatts;
9584 atts = ctxt->atts;
9585 }
9586 atts[nbatts++] = attname;
9587 atts[nbatts++] = aprefix;
9588 if (aprefix == NULL)
9589 atts[nbatts++] = NULL;
9590 else
9591 atts[nbatts++] = xmlGetNamespace(ctxt, aprefix);
9592 atts[nbatts++] = defaults->values[5 * i + 2];
9593 atts[nbatts++] = defaults->values[5 * i + 3];
9594 if ((ctxt->standalone == 1) &&
9595 (defaults->values[5 * i + 4] != NULL)) {
9596 xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
9597 "standalone: attribute %s on %s defaulted from external subset\n",
9598 attname, localname);
9599 }
9600 nbdef++;
9601 }
9602 }
9603 }
9604 }
9605
9606 /*
9607 * The attributes checkings
9608 */
9609 for (i = 0; i < nbatts;i += 5) {
9610 /*
9611 * The default namespace does not apply to attribute names.
9612 */
9613 if (atts[i + 1] != NULL) {
9614 nsname = xmlGetNamespace(ctxt, atts[i + 1]);
9615 if (nsname == NULL) {
9616 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
9617 "Namespace prefix %s for %s on %s is not defined\n",
9618 atts[i + 1], atts[i], localname);
9619 }
9620 atts[i + 2] = nsname;
9621 } else
9622 nsname = NULL;
9623 /*
9624 * [ WFC: Unique Att Spec ]
9625 * No attribute name may appear more than once in the same
9626 * start-tag or empty-element tag.
9627 * As extended by the Namespace in XML REC.
9628 */
9629 for (j = 0; j < i;j += 5) {
9630 if (atts[i] == atts[j]) {
9631 if (atts[i+1] == atts[j+1]) {
9632 xmlErrAttributeDup(ctxt, atts[i+1], atts[i]);
9633 break;
9634 }
9635 if ((nsname != NULL) && (atts[j + 2] == nsname)) {
9636 xmlNsErr(ctxt, XML_NS_ERR_ATTRIBUTE_REDEFINED,
9637 "Namespaced Attribute %s in '%s' redefined\n",
9638 atts[i], nsname, NULL);
9639 break;
9640 }
9641 }
9642 }
9643 }
9644
9645 nsname = xmlGetNamespace(ctxt, prefix);
9646 if ((prefix != NULL) && (nsname == NULL)) {
9647 xmlNsErr(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
9648 "Namespace prefix %s on %s is not defined\n",
9649 prefix, localname, NULL);
9650 }
9651 *pref = prefix;
9652 *URI = nsname;
9653
9654 /*
9655 * SAX: Start of Element !
9656 */
9657 if ((ctxt->sax != NULL) && (ctxt->sax->startElementNs != NULL) &&
9658 (!ctxt->disableSAX)) {
9659 if (nbNs > 0)
9660 ctxt->sax->startElementNs(ctxt->userData, localname, prefix,
9661 nsname, nbNs, &ctxt->nsTab[ctxt->nsNr - 2 * nbNs],
9662 nbatts / 5, nbdef, atts);
9663 else
9664 ctxt->sax->startElementNs(ctxt->userData, localname, prefix,
9665 nsname, 0, NULL, nbatts / 5, nbdef, atts);
9666 }
9667
9668done:
9669 /*
9670 * Free up attribute allocated strings if needed
9671 */
9672 if (attval != 0) {
9673 for (i = 3,j = 0; j < nratts;i += 5,j++)
9674 if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL))
9675 xmlFree((xmlChar *) atts[i]);
9676 }
9677
9678 return(localname);
9679}
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static int xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr)
Definition: parser.c:1702
static const xmlChar * xmlParseAttribute2(xmlParserCtxtPtr ctxt, const xmlChar *pref, const xmlChar *elem, const xmlChar **prefix, xmlChar **value, int *len, int *alloc)
Definition: parser.c:9125
static void xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *localname)
Definition: parser.c:342
@ XML_WAR_NS_URI
Definition: xmlerror.h:199
@ XML_DTD_STANDALONE_DEFAULTED
Definition: xmlerror.h:257
@ XML_NS_ERR_UNDEFINED_NAMESPACE
Definition: xmlerror.h:214
@ XML_NS_ERR_XML_NAMESPACE
Definition: xmlerror.h:213
@ XML_NS_ERR_ATTRIBUTE_REDEFINED
Definition: xmlerror.h:216
@ XML_WAR_NS_URI_RELATIVE
Definition: xmlerror.h:200

Referenced by xmlParseElementStart().

◆ xmlParseStringCharRef()

static int xmlParseStringCharRef ( xmlParserCtxtPtr  ctxt,
const xmlChar **  str 
)
static

xmlParseStringCharRef: @ctxt: an XML parser context @str: a pointer to an index in the string

parse Reference declarations, variant parsing from a string rather than an an input flow.

[66] CharRef ::= '&#' [0-9]+ ';' | '&x' [0-9a-fA-F]+ ';'

[ WFC: Legal Character ] Characters referred to using character references must match the production for Char.

Returns the value parsed (as an int), 0 in case of error, str will be updated to the current value of the index

Definition at line 2442 of file parser.c.

2442 {
2443 const xmlChar *ptr;
2444 xmlChar cur;
2445 int val = 0;
2446
2447 if ((str == NULL) || (*str == NULL)) return(0);
2448 ptr = *str;
2449 cur = *ptr;
2450 if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) {
2451 ptr += 3;
2452 cur = *ptr;
2453 while (cur != ';') { /* Non input consuming loop */
2454 if ((cur >= '0') && (cur <= '9'))
2455 val = val * 16 + (cur - '0');
2456 else if ((cur >= 'a') && (cur <= 'f'))
2457 val = val * 16 + (cur - 'a') + 10;
2458 else if ((cur >= 'A') && (cur <= 'F'))
2459 val = val * 16 + (cur - 'A') + 10;
2460 else {
2462 val = 0;
2463 break;
2464 }
2465 if (val > 0x110000)
2466 val = 0x110000;
2467
2468 ptr++;
2469 cur = *ptr;
2470 }
2471 if (cur == ';')
2472 ptr++;
2473 } else if ((cur == '&') && (ptr[1] == '#')){
2474 ptr += 2;
2475 cur = *ptr;
2476 while (cur != ';') { /* Non input consuming loops */
2477 if ((cur >= '0') && (cur <= '9'))
2478 val = val * 10 + (cur - '0');
2479 else {
2481 val = 0;
2482 break;
2483 }
2484 if (val > 0x110000)
2485 val = 0x110000;
2486
2487 ptr++;
2488 cur = *ptr;
2489 }
2490 if (cur == ';')
2491 ptr++;
2492 } else {
2494 return(0);
2495 }
2496 *str = ptr;
2497
2498 /*
2499 * [ WFC: Legal Character ]
2500 * Characters referred to using character references must match the
2501 * production for Char.
2502 */
2503 if (val >= 0x110000) {
2504 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2505 "xmlParseStringCharRef: character reference out of bounds\n",
2506 val);
2507 } else if (IS_CHAR(val)) {
2508 return(val);
2509 } else {
2510 xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
2511 "xmlParseStringCharRef: invalid xmlChar value %d\n",
2512 val);
2513 }
2514 return(0);
2515}
static PVOID ptr
Definition: dispmode.c:27

Referenced by xmlStringLenDecodeEntities().

◆ xmlParseStringEntityRef()

static xmlEntityPtr xmlParseStringEntityRef ( xmlParserCtxtPtr  ctxt,
const xmlChar **  str 
)
static

xmlParseStringEntityRef: @ctxt: an XML parser context @str: a pointer to an index in the string

parse ENTITY references declarations, but this version parses it from a string value.

[68] EntityRef ::= '&' Name ';'

[ WFC: Entity Declared ] In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with "standalone='yes'", the Name given in the entity reference must match that in an entity declaration, except that well-formed documents need not declare any of the following entities: amp, lt, gt, apos, quot. The declaration of a parameter entity must precede any reference to it. Similarly, the declaration of a general entity must precede any reference to it which appears in a default value in an attribute-list declaration. Note that if entities are declared in the external subset or in external parameter entities, a non-validating processor is not obligated to read and process their declarations; for such documents, the rule that an entity must be declared is a well-formedness constraint only if standalone='yes'.

[ WFC: Parsed Entity ] An entity reference must not contain the name of an unparsed entity

Returns the xmlEntityPtr if found, or NULL otherwise. The str pointer is updated to the current location in the string.

Definition at line 7718 of file parser.c.

7718 {
7719 xmlChar *name;
7720 const xmlChar *ptr;
7721 xmlChar cur;
7722 xmlEntityPtr ent = NULL;
7723
7724 if ((str == NULL) || (*str == NULL))
7725 return(NULL);
7726 ptr = *str;
7727 cur = *ptr;
7728 if (cur != '&')
7729 return(NULL);
7730
7731 ptr++;
7732 name = xmlParseStringName(ctxt, &ptr);
7733 if (name == NULL) {
7734 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
7735 "xmlParseStringEntityRef: no name\n");
7736 *str = ptr;
7737 return(NULL);
7738 }
7739 if (*ptr != ';') {
7741 xmlFree(name);
7742 *str = ptr;
7743 return(NULL);
7744 }
7745 ptr++;
7746
7747
7748 /*
7749 * Predefined entities override any extra definition
7750 */
7751 if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
7753 if (ent != NULL) {
7754 xmlFree(name);
7755 *str = ptr;
7756 return(ent);
7757 }
7758 }
7759
7760 /*
7761 * Increase the number of entity references parsed
7762 */
7763 ctxt->nbentities++;
7764
7765 /*
7766 * Ask first SAX for entity resolution, otherwise try the
7767 * entities which may have stored in the parser context.
7768 */
7769 if (ctxt->sax != NULL) {
7770 if (ctxt->sax->getEntity != NULL)
7771 ent = ctxt->sax->getEntity(ctxt->userData, name);
7772 if ((ent == NULL) && (ctxt->options & XML_PARSE_OLDSAX))
7774 if ((ent == NULL) && (ctxt->userData==ctxt)) {
7775 ent = xmlSAX2GetEntity(ctxt, name);
7776 }
7777 }
7778 if (ctxt->instate == XML_PARSER_EOF) {
7779 xmlFree(name);
7780 return(NULL);
7781 }
7782
7783 /*
7784 * [ WFC: Entity Declared ]
7785 * In a document without any DTD, a document with only an
7786 * internal DTD subset which contains no parameter entity
7787 * references, or a document with "standalone='yes'", the
7788 * Name given in the entity reference must match that in an
7789 * entity declaration, except that well-formed documents
7790 * need not declare any of the following entities: amp, lt,
7791 * gt, apos, quot.
7792 * The declaration of a parameter entity must precede any
7793 * reference to it.
7794 * Similarly, the declaration of a general entity must
7795 * precede any reference to it which appears in a default
7796 * value in an attribute-list declaration. Note that if
7797 * entities are declared in the external subset or in
7798 * external parameter entities, a non-validating processor
7799 * is not obligated to read and process their declarations;
7800 * for such documents, the rule that an entity must be
7801 * declared is a well-formedness constraint only if
7802 * standalone='yes'.
7803 */
7804 if (ent == NULL) {
7805 if ((ctxt->standalone == 1) ||
7806 ((ctxt->hasExternalSubset == 0) &&
7807 (ctxt->hasPErefs == 0))) {
7808 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
7809 "Entity '%s' not defined\n", name);
7810 } else {
7811 xmlErrMsgStr(ctxt, XML_WAR_UNDECLARED_ENTITY,
7812 "Entity '%s' not defined\n",
7813 name);
7814 }
7815 xmlParserEntityCheck(ctxt, 0, ent, 0);
7816 /* TODO ? check regressions ctxt->valid = 0; */
7817 }
7818
7819 /*
7820 * [ WFC: Parsed Entity ]
7821 * An entity reference must not contain the name of an
7822 * unparsed entity
7823 */
7825 xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY,
7826 "Entity reference to unparsed entity %s\n", name);
7827 }
7828
7829 /*
7830 * [ WFC: No External Entity References ]
7831 * Attribute values cannot contain direct or indirect
7832 * entity references to external entities.
7833 */
7834 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7836 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL,
7837 "Attribute references external entity '%s'\n", name);
7838 }
7839 /*
7840 * [ WFC: No < in Attribute Values ]
7841 * The replacement text of any entity referred to directly or
7842 * indirectly in an attribute value (other than "&lt;") must
7843 * not contain a <.
7844 */
7845 else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
7846 (ent != NULL) && (ent->content != NULL) &&
7848 (xmlStrchr(ent->content, '<'))) {
7849 xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
7850 "'<' in entity '%s' is not allowed in attributes values\n",
7851 name);
7852 }
7853
7854 /*
7855 * Internal check, no parameter entities here ...
7856 */
7857 else {
7858 switch (ent->etype) {
7861 xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER,
7862 "Attempt to reference the parameter entity '%s'\n",
7863 name);
7864 break;
7865 default:
7866 break;
7867 }
7868 }
7869
7870 /*
7871 * [ WFC: No Recursion ]
7872 * A parsed entity must not contain a recursive reference
7873 * to itself, either directly or indirectly.
7874 * Done somewhere else
7875 */
7876
7877 xmlFree(name);
7878 *str = ptr;
7879 return(ent);
7880}

Referenced by xmlStringLenDecodeEntities().

◆ xmlParseStringName()

static xmlChar * xmlParseStringName ( xmlParserCtxtPtr  ctxt,
const xmlChar **  str 
)
static

xmlParseStringName: @ctxt: an XML parser context @str: a pointer to the string pointer (IN/OUT)

parse an XML name.

[4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender

[5] Name ::= (Letter | '_' | ':') (NameChar)*

[6] Names ::= Name (#x20 Name)*

Returns the Name parsed or NULL. The @str pointer is updated to the current location in the string.

Definition at line 3573 of file parser.c.

3573 {
3575 const xmlChar *cur = *str;
3576 int len = 0, l;
3577 int c;
3578 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3581
3582#ifdef DEBUG
3583 nbParseStringName++;
3584#endif
3585
3586 c = CUR_SCHAR(cur, l);
3587 if (!xmlIsNameStartChar(ctxt, c)) {
3588 return(NULL);
3589 }
3590
3591 COPY_BUF(l,buf,len,c);
3592 cur += l;
3593 c = CUR_SCHAR(cur, l);
3594 while (xmlIsNameChar(ctxt, c)) {
3595 COPY_BUF(l,buf,len,c);
3596 cur += l;
3597 c = CUR_SCHAR(cur, l);
3598 if (len >= XML_MAX_NAMELEN) { /* test bigentname.xml */
3599 /*
3600 * Okay someone managed to make a huge name, so he's ready to pay
3601 * for the processing speed.
3602 */
3603 xmlChar *buffer;
3604 int max = len * 2;
3605
3606 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
3607 if (buffer == NULL) {
3608 xmlErrMemory(ctxt, NULL);
3609 return(NULL);
3610 }
3611 memcpy(buffer, buf, len);
3612 while (xmlIsNameChar(ctxt, c)) {
3613 if (len + 10 > max) {
3614 xmlChar *tmp;
3615
3616 max *= 2;
3617 tmp = (xmlChar *) xmlRealloc(buffer,
3618 max * sizeof(xmlChar));
3619 if (tmp == NULL) {
3620 xmlErrMemory(ctxt, NULL);
3621 xmlFree(buffer);
3622 return(NULL);
3623 }
3624 buffer = tmp;
3625 }
3627 cur += l;
3628 c = CUR_SCHAR(cur, l);
3629 if (len > maxLength) {
3630 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3631 xmlFree(buffer);
3632 return(NULL);
3633 }
3634 }
3635 buffer[len] = 0;
3636 *str = cur;
3637 return(buffer);
3638 }
3639 }
3640 if (len > maxLength) {
3641 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3642 return(NULL);
3643 }
3644 *str = cur;
3645 return(xmlStrndup(buf, len));
3646}
#define CUR_SCHAR(s, l)
Definition: parser.c:2164

Referenced by xmlParseEntityValue(), xmlParseStringEntityRef(), and xmlParseStringPEReference().

◆ xmlParseStringPEReference()

static xmlEntityPtr xmlParseStringPEReference ( xmlParserCtxtPtr  ctxt,
const xmlChar **  str 
)
static

xmlParseStringPEReference: @ctxt: an XML parser context @str: a pointer to an index in the string

parse PEReference declarations

[69] PEReference ::= '' Name ';'

[ WFC: No Recursion ] A parsed entity must not contain a recursive reference to itself, either directly or indirectly.

[ WFC: Entity Declared ] In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with "standalone='yes'", ... ... The declaration of a parameter entity must precede any reference to it...

[ VC: Entity Declared ] In a document with an external subset or external parameter entities with "standalone='no'", ... ... The declaration of a parameter entity must precede any reference to it...

[ WFC: In DTD ] Parameter-entity references may only appear in the DTD. NOTE: misleading but this is handled.

Returns the string of the entity content. str is updated to the current value of the index

Definition at line 8179 of file parser.c.

8179 {
8180 const xmlChar *ptr;
8181 xmlChar cur;
8182 xmlChar *name;
8184
8185 if ((str == NULL) || (*str == NULL)) return(NULL);
8186 ptr = *str;
8187 cur = *ptr;
8188 if (cur != '%')
8189 return(NULL);
8190 ptr++;
8191 name = xmlParseStringName(ctxt, &ptr);
8192 if (name == NULL) {
8193 xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
8194 "xmlParseStringPEReference: no name\n");
8195 *str = ptr;
8196 return(NULL);
8197 }
8198 cur = *ptr;
8199 if (cur != ';') {
8201 xmlFree(name);
8202 *str = ptr;
8203 return(NULL);
8204 }
8205 ptr++;
8206
8207 /*
8208 * Increase the number of entity references parsed
8209 */
8210 ctxt->nbentities++;
8211
8212 /*
8213 * Request the entity from SAX
8214 */
8215 if ((ctxt->sax != NULL) &&
8216 (ctxt->sax->getParameterEntity != NULL))
8217 entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
8218 if (ctxt->instate == XML_PARSER_EOF) {
8219 xmlFree(name);
8220 *str = ptr;
8221 return(NULL);
8222 }
8223 if (entity == NULL) {
8224 /*
8225 * [ WFC: Entity Declared ]
8226 * In a document without any DTD, a document with only an
8227 * internal DTD subset which contains no parameter entity
8228 * references, or a document with "standalone='yes'", ...
8229 * ... The declaration of a parameter entity must precede
8230 * any reference to it...
8231 */
8232 if ((ctxt->standalone == 1) ||
8233 ((ctxt->hasExternalSubset == 0) && (ctxt->hasPErefs == 0))) {
8234 xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
8235 "PEReference: %%%s; not found\n", name);
8236 } else {
8237 /*
8238 * [ VC: Entity Declared ]
8239 * In a document with an external subset or external
8240 * parameter entities with "standalone='no'", ...
8241 * ... The declaration of a parameter entity must
8242 * precede any reference to it...
8243 */
8244 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
8245 "PEReference: %%%s; not found\n",
8246 name, NULL);
8247 ctxt->valid = 0;
8248 }
8249 xmlParserEntityCheck(ctxt, 0, NULL, 0);
8250 } else {
8251 /*
8252 * Internal checking in case the entity quest barfed
8253 */
8254 if ((entity->etype != XML_INTERNAL_PARAMETER_ENTITY) &&
8256 xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
8257 "%%%s; is not a parameter entity\n",
8258 name, NULL);
8259 }
8260 }
8261 ctxt->hasPErefs = 1;
8262 xmlFree(name);
8263 *str = ptr;
8264 return(entity);
8265}

Referenced by xmlStringLenDecodeEntities().

◆ xmlParseSystemLiteral()

xmlChar * xmlParseSystemLiteral ( xmlParserCtxtPtr  ctxt)

xmlParseSystemLiteral: @ctxt: an XML parser context

parse an XML Literal

[11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")

Returns the SystemLiteral parsed or NULL

Definition at line 4199 of file parser.c.

4199 {
4200 xmlChar *buf = NULL;
4201 int len = 0;
4203 int cur, l;
4204 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
4207 xmlChar stop;
4208 int state = ctxt->instate;
4209 int count = 0;
4210
4211 SHRINK;
4212 if (RAW == '"') {
4213 NEXT;
4214 stop = '"';
4215 } else if (RAW == '\'') {
4216 NEXT;
4217 stop = '\'';
4218 } else {
4220 return(NULL);
4221 }
4222
4223 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
4224 if (buf == NULL) {
4225 xmlErrMemory(ctxt, NULL);
4226 return(NULL);
4227 }
4229 cur = CUR_CHAR(l);
4230 while ((IS_CHAR(cur)) && (cur != stop)) { /* checked */
4231 if (len + 5 >= size) {
4232 xmlChar *tmp;
4233
4234 size *= 2;
4235 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
4236 if (tmp == NULL) {
4237 xmlFree(buf);
4238 xmlErrMemory(ctxt, NULL);
4240 return(NULL);
4241 }
4242 buf = tmp;
4243 }
4244 count++;
4245 if (count > 50) {
4246 SHRINK;
4247 GROW;
4248 count = 0;
4249 if (ctxt->instate == XML_PARSER_EOF) {
4250 xmlFree(buf);
4251 return(NULL);
4252 }
4253 }
4254 COPY_BUF(l,buf,len,cur);
4255 NEXTL(l);
4256 cur = CUR_CHAR(l);
4257 if (cur == 0) {
4258 GROW;
4259 SHRINK;
4260 cur = CUR_CHAR(l);
4261 }
4262 if (len > maxLength) {
4263 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "SystemLiteral");
4264 xmlFree(buf);
4266 return(NULL);
4267 }
4268 }
4269 buf[len] = 0;
4271 if (!IS_CHAR(cur)) {
4273 } else {
4274 NEXT;
4275 }
4276 return(buf);
4277}

Referenced by xmlParseExternalID().

◆ xmlParseTextDecl()

void xmlParseTextDecl ( xmlParserCtxtPtr  ctxt)

xmlParseTextDecl: @ctxt: an XML parser context

parse an XML declaration header for external entities

[77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'

Definition at line 6915 of file parser.c.

6915 {
6917 const xmlChar *encoding;
6918 int oldstate;
6919
6920 /*
6921 * We know that '<?xml' is here.
6922 */
6923 if ((CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l')) && (IS_BLANK_CH(NXT(5)))) {
6924 SKIP(5);
6925 } else {
6927 return;
6928 }
6929
6930 /* Avoid expansion of parameter entities when skipping blanks. */
6931 oldstate = ctxt->instate;
6932 ctxt->instate = XML_PARSER_START;
6933
6934 if (SKIP_BLANKS == 0) {
6935 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6936 "Space needed after '<?xml'\n");
6937 }
6938
6939 /*
6940 * We may have the VersionInfo here.
6941 */
6943 if (version == NULL)
6945 else {
6946 if (SKIP_BLANKS == 0) {
6947 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
6948 "Space needed here\n");
6949 }
6950 }
6951 ctxt->input->version = version;
6952
6953 /*
6954 * We must have the encoding declaration
6955 */
6957 if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
6958 /*
6959 * The XML REC instructs us to stop parsing right here
6960 */
6961 ctxt->instate = oldstate;
6962 return;
6963 }
6964 if ((encoding == NULL) && (ctxt->errNo == XML_ERR_OK)) {
6965 xmlFatalErrMsg(ctxt, XML_ERR_MISSING_ENCODING,
6966 "Missing encoding in text declaration\n");
6967 }
6968
6970 if ((RAW == '?') && (NXT(1) == '>')) {
6971 SKIP(2);
6972 } else if (RAW == '>') {
6973 /* Deprecated old WD ... */
6975 NEXT;
6976 } else {
6979 NEXT;
6980 }
6981
6982 ctxt->instate = oldstate;
6983}
static const WCHAR version[]
Definition: asmname.c:66
#define MOVETO_ENDTAG(p)
xmlChar * xmlParseVersionInfo(xmlParserCtxtPtr ctxt)
Definition: parser.c:10249
const xmlChar * xmlParseEncodingDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:10358
@ XML_ERR_MISSING_ENCODING
Definition: xmlerror.h:201

Referenced by xmlParseExternalEntityPrivate(), xmlParseExternalSubset(), and xmlParsePEReference().

◆ xmlParseVersionInfo()

xmlChar * xmlParseVersionInfo ( xmlParserCtxtPtr  ctxt)

xmlParseVersionInfo: @ctxt: an XML parser context

parse the XML version.

[24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")

[25] Eq ::= S? '=' S?

Returns the version string, e.g. "1.0"

Definition at line 10249 of file parser.c.

10249 {
10250 xmlChar *version = NULL;
10251
10252 if (CMP7(CUR_PTR, 'v', 'e', 'r', 's', 'i', 'o', 'n')) {
10253 SKIP(7);
10255 if (RAW != '=') {
10257 return(NULL);
10258 }
10259 NEXT;
10261 if (RAW == '"') {
10262 NEXT;
10264 if (RAW != '"') {
10266 } else
10267 NEXT;
10268 } else if (RAW == '\''){
10269 NEXT;
10271 if (RAW != '\'') {
10273 } else
10274 NEXT;
10275 } else {
10277 }
10278 }
10279 return(version);
10280}
xmlChar * xmlParseVersionNum(xmlParserCtxtPtr ctxt)
Definition: parser.c:10188

Referenced by xmlParseTextDecl(), and xmlParseXMLDecl().

◆ xmlParseVersionNum()

xmlChar * xmlParseVersionNum ( xmlParserCtxtPtr  ctxt)

xmlParseVersionNum: @ctxt: an XML parser context

parse the XML version value.

[26] VersionNum ::= '1.' [0-9]+

In practice allow [0-9].[0-9]+ at that level

Returns the string giving the XML version number, or NULL

Definition at line 10188 of file parser.c.

10188 {
10189 xmlChar *buf = NULL;
10190 int len = 0;
10191 int size = 10;
10192 xmlChar cur;
10193
10194 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
10195 if (buf == NULL) {
10196 xmlErrMemory(ctxt, NULL);
10197 return(NULL);
10198 }
10199 cur = CUR;
10200 if (!((cur >= '0') && (cur <= '9'))) {
10201 xmlFree(buf);
10202 return(NULL);
10203 }
10204 buf[len++] = cur;
10205 NEXT;
10206 cur=CUR;
10207 if (cur != '.') {
10208 xmlFree(buf);
10209 return(NULL);
10210 }
10211 buf[len++] = cur;
10212 NEXT;
10213 cur=CUR;
10214 while ((cur >= '0') && (cur <= '9')) {
10215 if (len + 1 >= size) {
10216 xmlChar *tmp;
10217
10218 size *= 2;
10219 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
10220 if (tmp == NULL) {
10221 xmlFree(buf);
10222 xmlErrMemory(ctxt, NULL);
10223 return(NULL);
10224 }
10225 buf = tmp;
10226 }
10227 buf[len++] = cur;
10228 NEXT;
10229 cur=CUR;
10230 }
10231 buf[len] = 0;
10232 return(buf);
10233}

Referenced by xmlParseVersionInfo().

◆ xmlParseXMLDecl()

void xmlParseXMLDecl ( xmlParserCtxtPtr  ctxt)

xmlParseXMLDecl: @ctxt: an XML parser context

parse an XML declaration header

[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

Definition at line 10552 of file parser.c.

10552 {
10554
10555 /*
10556 * This value for standalone indicates that the document has an
10557 * XML declaration but it does not have a standalone attribute.
10558 * It will be overwritten later if a standalone attribute is found.
10559 */
10560 ctxt->input->standalone = -2;
10561
10562 /*
10563 * We know that '<?xml' is here.
10564 */
10565 SKIP(5);
10566
10567 if (!IS_BLANK_CH(RAW)) {
10568 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
10569 "Blank needed after '<?xml'\n");
10570 }
10572
10573 /*
10574 * We must have the VersionInfo here.
10575 */
10577 if (version == NULL) {
10579 } else {
10581 /*
10582 * Changed here for XML-1.0 5th edition
10583 */
10584 if (ctxt->options & XML_PARSE_OLD10) {
10585 xmlFatalErrMsgStr(ctxt, XML_ERR_UNKNOWN_VERSION,
10586 "Unsupported version '%s'\n",
10587 version);
10588 } else {
10589 if ((version[0] == '1') && ((version[1] == '.'))) {
10590 xmlWarningMsg(ctxt, XML_WAR_UNKNOWN_VERSION,
10591 "Unsupported version '%s'\n",
10592 version, NULL);
10593 } else {
10594 xmlFatalErrMsgStr(ctxt, XML_ERR_UNKNOWN_VERSION,
10595 "Unsupported version '%s'\n",
10596 version);
10597 }
10598 }
10599 }
10600 if (ctxt->version != NULL)
10601 xmlFree((void *) ctxt->version);
10602 ctxt->version = version;
10603 }
10604
10605 /*
10606 * We may have the encoding declaration
10607 */
10608 if (!IS_BLANK_CH(RAW)) {
10609 if ((RAW == '?') && (NXT(1) == '>')) {
10610 SKIP(2);
10611 return;
10612 }
10613 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n");
10614 }
10616 if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
10617 (ctxt->instate == XML_PARSER_EOF)) {
10618 /*
10619 * The XML REC instructs us to stop parsing right here
10620 */
10621 return;
10622 }
10623
10624 /*
10625 * We may have the standalone status.
10626 */
10627 if ((ctxt->input->encoding != NULL) && (!IS_BLANK_CH(RAW))) {
10628 if ((RAW == '?') && (NXT(1) == '>')) {
10629 SKIP(2);
10630 return;
10631 }
10632 xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n");
10633 }
10634
10635 /*
10636 * We can grow the input buffer freely at that point
10637 */
10638 GROW;
10639
10641 ctxt->input->standalone = xmlParseSDDecl(ctxt);
10642
10644 if ((RAW == '?') && (NXT(1) == '>')) {
10645 SKIP(2);
10646 } else if (RAW == '>') {
10647 /* Deprecated old WD ... */
10649 NEXT;
10650 } else {
10653 NEXT;
10654 }
10655}
int xmlParseSDDecl(xmlParserCtxtPtr ctxt)
Definition: parser.c:10490
@ XML_WAR_UNKNOWN_VERSION
Definition: xmlerror.h:197
@ XML_ERR_UNKNOWN_VERSION
Definition: xmlerror.h:208

Referenced by xmlParseDocument(), and xmlParseExtParsedEnt().

◆ xmlPopInput()

xmlChar xmlPopInput ( xmlParserCtxtPtr  ctxt)

xmlPopInput: @ctxt: an XML parser context

xmlPopInput: the current input pointed by ctxt->input came to an end pop it and return the next char.

Returns the current xmlChar in the parser context

Definition at line 2265 of file parser.c.

2265 {
2266 if ((ctxt == NULL) || (ctxt->inputNr <= 1)) return(0);
2269 "Popping input %d\n", ctxt->inputNr);
2270 if ((ctxt->inputNr > 1) && (ctxt->inSubset == 0) &&
2271 (ctxt->instate != XML_PARSER_EOF))
2273 "Unfinished entity outside the DTD");
2275 if (*ctxt->input->cur == 0)
2277 return(CUR);
2278}

Referenced by xmlLoadEntityContent(), xmlParseInternalSubset(), xmlSAX2ExternalSubset(), and xmlSkipBlankChars().

◆ xmlPushInput()

int xmlPushInput ( xmlParserCtxtPtr  ctxt,
xmlParserInputPtr  input 
)

xmlPushInput: @ctxt: an XML parser context @input: an XML parser input fragment (entity, XML fragment ...).

xmlPushInput: switch to a new input stream which is stacked on top of the previous one(s). Returns -1 in case of error or the index in the input stack

Definition at line 2290 of file parser.c.

2290 {
2291 int ret;
2292 if (input == NULL) return(-1);
2293
2295 if ((ctxt->input != NULL) && (ctxt->input->filename))
2297 "%s(%d): ", ctxt->input->filename,
2298 ctxt->input->line);
2300 "Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur);
2301 }
2302 if (((ctxt->inputNr > 40) && ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
2303 (ctxt->inputNr > 1024)) {
2305 while (ctxt->inputNr > 1)
2307 return(-1);
2308 }
2309 ret = inputPush(ctxt, input);
2310 if (ctxt->instate == XML_PARSER_EOF)
2311 return(-1);
2312 GROW;
2313 return(ret);
2314}

Referenced by xmlLoadEntityContent(), xmlParsePEReference(), and xmlSAX2ExternalSubset().

◆ xmlReadDoc()

xmlDocPtr xmlReadDoc ( const xmlChar cur,
const char URL,
const char encoding,
int  options 
)

xmlReadDoc: @cur: a pointer to a zero terminated string @URL: the base URL to use for the document @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML in-memory document and build a tree.

Returns the resulting document tree

Definition at line 15204 of file parser.c.

15205{
15206 xmlParserCtxtPtr ctxt;
15207
15208 if (cur == NULL)
15209 return (NULL);
15210 xmlInitParser();
15211
15213 if (ctxt == NULL)
15214 return (NULL);
15215 return (xmlDoRead(ctxt, URL, encoding, options, 0));
15216}
xmlParserCtxtPtr xmlCreateDocParserCtxt(const xmlChar *cur)
Definition: parser.c:14542

◆ xmlReadFd()

xmlDocPtr xmlReadFd ( int  fd,
const char URL,
const char encoding,
int  options 
)

xmlReadFd: @fd: an open file descriptor @URL: the base URL to use for the document @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML from a file descriptor and build a tree. NOTE that the file descriptor will not be closed when the reader is closed or reset.

Returns the resulting document tree

Definition at line 15278 of file parser.c.

15279{
15280 xmlParserCtxtPtr ctxt;
15283
15284 if (fd < 0)
15285 return (NULL);
15286 xmlInitParser();
15287
15289 if (input == NULL)
15290 return (NULL);
15291 input->closecallback = NULL;
15292 ctxt = xmlNewParserCtxt();
15293 if (ctxt == NULL) {
15295 return (NULL);
15296 }
15298 if (stream == NULL) {
15300 xmlFreeParserCtxt(ctxt);
15301 return (NULL);
15302 }
15303 inputPush(ctxt, stream);
15304 return (xmlDoRead(ctxt, URL, encoding, options, 0));
15305}

Referenced by parseAndPrintFile().

◆ xmlReadFile()

xmlDocPtr xmlReadFile ( const char filename,
const char encoding,
int  options 
)

xmlReadFile: @filename: a file or URL @encoding: the document encoding, or NULL @options: a combination of xmlParserOption

parse an XML file from the filesystem or the network.

Returns the resulting document tree

Definition at line 15229 of file parser.c.

15230{
15231 xmlParserCtxtPtr ctxt;
15232
15233 xmlInitParser();
15235 if (ctxt == NULL)
15236 return (NULL);
15237 return (xmlDoRead(ctxt, NULL, encoding, options, 0));
15238}

Referenced by parseAndPrintFile().

◆ xmlReadIO()

xmlDocPtr xmlReadIO ( xmlInputReadCallback  ioread,
xmlInputCloseCallback  ioclose,
void ioctx,
const char URL,
const char encoding,
int  options 
)

xmlReadIO: @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 @options: a combination of xmlParserOption

parse an XML document from I/O functions and source and build a tree.

Returns the resulting document tree

Definition at line 15321 of file parser.c.

15323{
15324 xmlParserCtxtPtr ctxt;
15327
15328 if (ioread == NULL)
15329 return (NULL);
15330 xmlInitParser();
15331
15332 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
15334 if (input == NULL) {
15335 if (ioclose != NULL)
15336 ioclose(ioctx);
15337 return (NULL);
15338 }
15339 ctxt = xmlNewParserCtxt();
15340 if (ctxt == NULL) {
15342 return (NULL);
15343 }
15345 if (stream == NULL) {
15347 xmlFreeParserCtxt(ctxt);
15348 return (NULL);
15349 }
15350 inputPush(ctxt, stream);
15351 return (xmlDoRead(ctxt, URL, encoding, options, 0));
15352}

Referenced by parseAndPrintFile().

◆ xmlReadMemory()

xmlDocPtr xmlReadMemory ( const char buffer,
int  size,
const char URL,
const char encoding,
int  options 
)

xmlReadMemory: @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 @options: a combination of xmlParserOption

parse an XML in-memory document and build a tree.

Returns the resulting document tree

Definition at line 15253 of file parser.c.

15254{
15255 xmlParserCtxtPtr ctxt;
15256
15257 xmlInitParser();
15259 if (ctxt == NULL)
15260 return (NULL);
15261 return (xmlDoRead(ctxt, URL, encoding, options, 0));
15262}

Referenced by parseAndPrintFile().

◆ xmlSHRINK()

static void xmlSHRINK ( xmlParserCtxtPtr  ctxt)
static

Definition at line 2111 of file parser.c.

2111 {
2113 if (*ctxt->input->cur == 0)
2115}
XMLPUBFUN void XMLCALL xmlParserInputShrink(xmlParserInputPtr in)

◆ xmlSkipBlankChars()

int xmlSkipBlankChars ( xmlParserCtxtPtr  ctxt)

xmlSkipBlankChars: @ctxt: the XML parser context

skip all blanks character found at that point in the input streams. It pops up finished entities in the process if allowable at that point.

Returns the number of space chars skipped

Definition at line 2184 of file parser.c.

2184 {
2185 int res = 0;
2186
2187 /*
2188 * It's Okay to use CUR/NEXT here since all the blanks are on
2189 * the ASCII range.
2190 */
2191 if (((ctxt->inputNr == 1) && (ctxt->instate != XML_PARSER_DTD)) ||
2192 (ctxt->instate == XML_PARSER_START)) {
2193 const xmlChar *cur;
2194 /*
2195 * if we are in the document content, go really fast
2196 */
2197 cur = ctxt->input->cur;
2198 while (IS_BLANK_CH(*cur)) {
2199 if (*cur == '\n') {
2200 ctxt->input->line++; ctxt->input->col = 1;
2201 } else {
2202 ctxt->input->col++;
2203 }
2204 cur++;
2205 if (res < INT_MAX)
2206 res++;
2207 if (*cur == 0) {
2208 ctxt->input->cur = cur;
2210 cur = ctxt->input->cur;
2211 }
2212 }
2213 ctxt->input->cur = cur;
2214 } else {
2215 int expandPE = ((ctxt->external != 0) || (ctxt->inputNr != 1));
2216
2217 while (1) {
2218 if (IS_BLANK_CH(CUR)) { /* CHECKED tstblanks.xml */
2219 NEXT;
2220 } else if (CUR == '%') {
2221 /*
2222 * Need to handle support of entities branching here
2223 */
2224 if ((expandPE == 0) || (IS_BLANK_CH(NXT(1))) || (NXT(1) == 0))
2225 break;
2226 xmlParsePEReference(ctxt);
2227 } else if (CUR == 0) {
2228 if (ctxt->inputNr <= 1)
2229 break;
2230 xmlPopInput(ctxt);
2231 } else {
2232 break;
2233 }
2234
2235 /*
2236 * Also increase the counter when entering or exiting a PERef.
2237 * The spec says: "When a parameter-entity reference is recognized
2238 * in the DTD and included, its replacement text MUST be enlarged
2239 * by the attachment of one leading and one following space (#x20)
2240 * character."
2241 */
2242 if (res < INT_MAX)
2243 res++;
2244 }
2245 }
2246 return(res);
2247}

◆ xmlSplitQName()

xmlChar * xmlSplitQName ( xmlParserCtxtPtr  ctxt,
const xmlChar name,
xmlChar **  prefix 
)

Namespaces.

Definition at line 2946 of file parser.c.

2946 {
2948 xmlChar *buffer = NULL;
2949 int len = 0;
2950 int max = XML_MAX_NAMELEN;
2951 xmlChar *ret = NULL;
2952 const xmlChar *cur = name;
2953 int c;
2954
2955 if (prefix == NULL) return(NULL);
2956 *prefix = NULL;
2957
2958 if (cur == NULL) return(NULL);
2959
2960#ifndef XML_XML_NAMESPACE
2961 /* xml: prefix is not really a namespace */
2962 if ((cur[0] == 'x') && (cur[1] == 'm') &&
2963 (cur[2] == 'l') && (cur[3] == ':'))
2964 return(xmlStrdup(name));
2965#endif
2966
2967 /* nasty but well=formed */
2968 if (cur[0] == ':')
2969 return(xmlStrdup(name));
2970
2971 c = *cur++;
2972 while ((c != 0) && (c != ':') && (len < max)) { /* tested bigname.xml */
2973 buf[len++] = c;
2974 c = *cur++;
2975 }
2976 if (len >= max) {
2977 /*
2978 * Okay someone managed to make a huge name, so he's ready to pay
2979 * for the processing speed.
2980 */
2981 max = len * 2;
2982
2983 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
2984 if (buffer == NULL) {
2985 xmlErrMemory(ctxt, NULL);
2986 return(NULL);
2987 }
2988 memcpy(buffer, buf, len);
2989 while ((c != 0) && (c != ':')) { /* tested bigname.xml */
2990 if (len + 10 > max) {
2991 xmlChar *tmp;
2992
2993 max *= 2;
2994 tmp = (xmlChar *) xmlRealloc(buffer,
2995 max * sizeof(xmlChar));
2996 if (tmp == NULL) {
2997 xmlFree(buffer);
2998 xmlErrMemory(ctxt, NULL);
2999 return(NULL);
3000 }
3001 buffer = tmp;
3002 }
3003 buffer[len++] = c;
3004 c = *cur++;
3005 }
3006 buffer[len] = 0;
3007 }
3008
3009 if ((c == ':') && (*cur == 0)) {
3010 if (buffer != NULL)
3011 xmlFree(buffer);
3012 *prefix = NULL;
3013 return(xmlStrdup(name));
3014 }
3015
3016 if (buffer == NULL)
3017 ret = xmlStrndup(buf, len);
3018 else {
3019 ret = buffer;
3020 buffer = NULL;
3022 }
3023
3024
3025 if (c == ':') {
3026 c = *cur;
3027 *prefix = ret;
3028 if (c == 0) {
3029 return(xmlStrndup(BAD_CAST "", 0));
3030 }
3031 len = 0;
3032
3033 /*
3034 * Check that the first character is proper to start
3035 * a new name
3036 */
3037 if (!(((c >= 0x61) && (c <= 0x7A)) ||
3038 ((c >= 0x41) && (c <= 0x5A)) ||
3039 (c == '_') || (c == ':'))) {
3040 int l;
3041 int first = CUR_SCHAR(cur, l);
3042
3043 if (!IS_LETTER(first) && (first != '_')) {
3044 xmlFatalErrMsgStr(ctxt, XML_NS_ERR_QNAME,
3045 "Name %s is not XML Namespace compliant\n",
3046 name);
3047 }
3048 }
3049 cur++;
3050
3051 while ((c != 0) && (len < max)) { /* tested bigname2.xml */
3052 buf[len++] = c;
3053 c = *cur++;
3054 }
3055 if (len >= max) {
3056 /*
3057 * Okay someone managed to make a huge name, so he's ready to pay
3058 * for the processing speed.
3059 */
3060 max = len * 2;
3061
3062 buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
3063 if (buffer == NULL) {
3064 xmlErrMemory(ctxt, NULL);
3065 return(NULL);
3066 }
3067 memcpy(buffer, buf, len);
3068 while (c != 0) { /* tested bigname2.xml */
3069 if (len + 10 > max) {
3070 xmlChar *tmp;
3071
3072 max *= 2;
3073 tmp = (xmlChar *) xmlRealloc(buffer,
3074 max * sizeof(xmlChar));
3075 if (tmp == NULL) {
3076 xmlErrMemory(ctxt, NULL);
3077 xmlFree(buffer);
3078 return(NULL);
3079 }
3080 buffer = tmp;
3081 }
3082 buffer[len++] = c;
3083 c = *cur++;
3084 }
3085 buffer[len] = 0;
3086 }
3087
3088 if (buffer == NULL)
3089 ret = xmlStrndup(buf, len);
3090 else {
3091 ret = buffer;
3092 }
3093 }
3094
3095 return(ret);
3096}
const GLint * first
Definition: glext.h:5794

Referenced by xmlSAX2AttributeDecl().

◆ xmlStopParser()

void xmlStopParser ( xmlParserCtxtPtr  ctxt)

xmlStopParser: @ctxt: an XML parser context

Blocks further parser processing

Definition at line 12583 of file parser.c.

12583 {
12584 if (ctxt == NULL)
12585 return;
12586 xmlHaltParser(ctxt);
12587 ctxt->errNo = XML_ERR_USER_STOP;
12588}
@ XML_ERR_USER_STOP
Definition: xmlerror.h:211

Referenced by xmlNextChar(), and xmlSwitchEncoding().

◆ xmlStringDecodeEntities()

xmlChar * xmlStringDecodeEntities ( xmlParserCtxtPtr  ctxt,
const xmlChar str,
int  what,
xmlChar  end,
xmlChar  end2,
xmlChar  end3 
)

xmlStringDecodeEntities: @ctxt: the parser context @str: the input string @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF @end: an end marker xmlChar, 0 if none @end2: an end marker xmlChar, 0 if none @end3: an end marker xmlChar, 0 if none

Takes a entity string content and process to do the adequate substitutions.

[67] Reference ::= EntityRef | CharRef

[69] PEReference ::= '' Name ';'

Returns A newly allocated string with the substitution done. The caller must deallocate it !

Definition at line 2839 of file parser.c.

2840 {
2841 if ((ctxt == NULL) || (str == NULL)) return(NULL);
2842 return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlen(str), what,
2843 end, end2, end3));
2844}
xmlChar * xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, int what, xmlChar end, xmlChar end2, xmlChar end3)
Definition: parser.c:2643

Referenced by xmlParseAttValueComplex(), xmlParseEntityValue(), xmlParserEntityCheck(), and xmlStringLenDecodeEntities().

◆ xmlStringLenDecodeEntities()

xmlChar * xmlStringLenDecodeEntities ( xmlParserCtxtPtr  ctxt,
const xmlChar str,
int  len,
int  what,
xmlChar  end,
xmlChar  end2,
xmlChar  end3 
)

xmlStringLenDecodeEntities: @ctxt: the parser context @str: the input string @len: the string length @what: combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF @end: an end marker xmlChar, 0 if none @end2: an end marker xmlChar, 0 if none @end3: an end marker xmlChar, 0 if none

Takes a entity string content and process to do the adequate substitutions.

[67] Reference ::= EntityRef | CharRef

[69] PEReference ::= '' Name ';'

Returns A newly allocated string with the substitution done. The caller must deallocate it !

Definition at line 2643 of file parser.c.

2644 {
2645 xmlChar *buffer = NULL;
2646 size_t buffer_size = 0;
2647 size_t nbchars = 0;
2648
2649 xmlChar *current = NULL;
2650 xmlChar *rep = NULL;
2651 const xmlChar *last;
2652 xmlEntityPtr ent;
2653 int c,l;
2654
2655 if ((ctxt == NULL) || (str == NULL) || (len < 0))
2656 return(NULL);
2657 last = str + len;
2658
2659 if (((ctxt->depth > 40) &&
2660 ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
2661 (ctxt->depth > 1024)) {
2663 return(NULL);
2664 }
2665
2666 /*
2667 * allocate a translation buffer.
2668 */
2671 if (buffer == NULL) goto mem_error;
2672
2673 /*
2674 * OK loop until we reach one of the ending char or a size limit.
2675 * we are operating on already parsed values.
2676 */
2677 if (str < last)
2678 c = CUR_SCHAR(str, l);
2679 else
2680 c = 0;
2681 while ((c != 0) && (c != end) && /* non input consuming loop */
2682 (c != end2) && (c != end3) &&
2683 (ctxt->instate != XML_PARSER_EOF)) {
2684
2685 if (c == 0) break;
2686 if ((c == '&') && (str[1] == '#')) {
2687 int val = xmlParseStringCharRef(ctxt, &str);
2688 if (val == 0)
2689 goto int_error;
2690 COPY_BUF(0,buffer,nbchars,val);
2691 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2693 }
2694 } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {
2697 "String decoding Entity Reference: %.30s\n",
2698 str);
2699 ent = xmlParseStringEntityRef(ctxt, &str);
2700 xmlParserEntityCheck(ctxt, 0, ent, 0);
2701 if (ent != NULL)
2702 ctxt->nbentities += ent->checked / 2;
2703 if ((ent != NULL) &&
2705 if (ent->content != NULL) {
2706 COPY_BUF(0,buffer,nbchars,ent->content[0]);
2707 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2709 }
2710 } else {
2711 xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
2712 "predefined entity has no content\n");
2713 goto int_error;
2714 }
2715 } else if ((ent != NULL) && (ent->content != NULL)) {
2716 ctxt->depth++;
2717 rep = xmlStringDecodeEntities(ctxt, ent->content, what,
2718 0, 0, 0);
2719 ctxt->depth--;
2720 if (rep == NULL) {
2721 ent->content[0] = 0;
2722 goto int_error;
2723 }
2724
2725 current = rep;
2726 while (*current != 0) { /* non input consuming loop */
2727 buffer[nbchars++] = *current++;
2728 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2729 if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
2730 goto int_error;
2732 }
2733 }
2734 xmlFree(rep);
2735 rep = NULL;
2736 } else if (ent != NULL) {
2737 int i = xmlStrlen(ent->name);
2738 const xmlChar *cur = ent->name;
2739
2740 buffer[nbchars++] = '&';
2741 if (nbchars + i + XML_PARSER_BUFFER_SIZE > buffer_size) {
2743 }
2744 for (;i > 0;i--)
2745 buffer[nbchars++] = *cur++;
2746 buffer[nbchars++] = ';';
2747 }
2748 } else if (c == '%' && (what & XML_SUBSTITUTE_PEREF)) {
2751 "String decoding PE Reference: %.30s\n", str);
2752 ent = xmlParseStringPEReference(ctxt, &str);
2753 xmlParserEntityCheck(ctxt, 0, ent, 0);
2754 if (ent != NULL)
2755 ctxt->nbentities += ent->checked / 2;
2756 if (ent != NULL) {
2757 if (ent->content == NULL) {
2758 /*
2759 * Note: external parsed entities will not be loaded,
2760 * it is not required for a non-validating parser to
2761 * complete external PEReferences coming from the
2762 * internal subset
2763 */
2764 if (((ctxt->options & XML_PARSE_NOENT) != 0) ||
2765 ((ctxt->options & XML_PARSE_DTDVALID) != 0) ||
2766 (ctxt->validate != 0)) {
2767 xmlLoadEntityContent(ctxt, ent);
2768 } else {
2769 xmlWarningMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
2770 "not validating will not read content for PE entity %s\n",
2771 ent->name, NULL);
2772 }
2773 }
2774 ctxt->depth++;
2775 rep = xmlStringDecodeEntities(ctxt, ent->content, what,
2776 0, 0, 0);
2777 ctxt->depth--;
2778 if (rep == NULL) {
2779 if (ent->content != NULL)
2780 ent->content[0] = 0;
2781 goto int_error;
2782 }
2783 current = rep;
2784 while (*current != 0) { /* non input consuming loop */
2785 buffer[nbchars++] = *current++;
2786 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2787 if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
2788 goto int_error;
2790 }
2791 }
2792 xmlFree(rep);
2793 rep = NULL;
2794 }
2795 } else {
2796 COPY_BUF(l,buffer,nbchars,c);
2797 str += l;
2798 if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
2800 }
2801 }
2802 if (str < last)
2803 c = CUR_SCHAR(str, l);
2804 else
2805 c = 0;
2806 }
2807 buffer[nbchars] = 0;
2808 return(buffer);
2809
2810mem_error:
2811 xmlErrMemory(ctxt, NULL);
2812int_error:
2813 if (rep != NULL)
2814 xmlFree(rep);
2815 if (buffer != NULL)
2816 xmlFree(buffer);
2817 return(NULL);
2818}
static int xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str)
Definition: parser.c:2442
static int xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
Definition: parser.c:8060
static xmlEntityPtr xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar **str)
Definition: parser.c:7718
static xmlEntityPtr xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str)
Definition: parser.c:8179
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:888
@ XML_ERR_ENTITY_PROCESSING
Definition: xmlerror.h:204

Referenced by xmlStringDecodeEntities().

Variable Documentation

◆ test_char_data

const unsigned char test_char_data[256]
static

Definition at line 4373 of file parser.c.

Referenced by xmlParseCharData().

◆ xmlParserInitialized

int xmlParserInitialized = 0
static

Definition at line 14665 of file parser.c.

Referenced by xmlCleanupParser(), and xmlInitParser().

◆ xmlParserMaxDepth

unsigned int xmlParserMaxDepth = 256

xmlParserMaxDepth:

arbitrary depth limit for the XML documents that we allow to process. This is not a limitation of the parser but a safety boundary feature. It can be disabled with the XML_PARSE_HUGE parser option.

Definition at line 270 of file parser.c.

Referenced by nodePush(), and xmlParseElementStart().

◆ xmlW3CPIs

const char* const xmlW3CPIs[]
static
Initial value:
= {
"xml-stylesheet",
"xml-model",
}

Definition at line 294 of file parser.c.

Referenced by xmlParsePITarget().