ReactOS  0.4.14-dev-52-g6116262
parserInternals.c File Reference
#include "libxml.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <libxml/xmlmemory.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 <libxml/dict.h>
#include <libxml/SAX.h>
#include <libxml/globals.h>
#include <libxml/chvalid.h>
#include "buf.h"
#include "enc.h"
#include "elfgcchack.h"
Include dependency graph for parserInternals.c:

Go to the source code of this file.

Macros

#define IN_LIBXML
 
#define XML_DIR_SEP   '/'
 
#define CUR(ctxt)   ctxt->input->cur
 
#define END(ctxt)   ctxt->input->end
 
#define VALID_CTXT(ctxt)   (CUR(ctxt) <= END(ctxt))
 
#define LINE_LEN   80
 
#define CHECK_BUFFER(in)
 
#define bottom_parserInternals
 

Functions

void xmlCheckVersion (int version)
 
void xmlErrMemory (xmlParserCtxtPtr ctxt, const char *extra)
 
void __xmlErrEncoding (xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
 
static void LIBXML_ATTR_FORMAT (2, 0)
 
static void LIBXML_ATTR_FORMAT (3, 0)
 
int xmlIsLetter (int c)
 
int xmlParserInputRead (xmlParserInputPtr in ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
 
int xmlParserInputGrow (xmlParserInputPtr in, int len)
 
void xmlParserInputShrink (xmlParserInputPtr in)
 
void xmlNextChar (xmlParserCtxtPtr ctxt)
 
int xmlCurrentChar (xmlParserCtxtPtr ctxt, int *len)
 
int xmlStringCurrentChar (xmlParserCtxtPtr ctxt, const xmlChar *cur, int *len)
 
int xmlCopyCharMultiByte (xmlChar *out, int val)
 
int xmlCopyChar (int len ATTRIBUTE_UNUSED, xmlChar *out, int val)
 
static int xmlSwitchToEncodingInt (xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler, int len)
 
static int xmlSwitchInputEncodingInt (xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler, int len)
 
int xmlSwitchEncoding (xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
 
int xmlSwitchInputEncoding (xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler)
 
int xmlSwitchToEncoding (xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
 
void xmlFreeInputStream (xmlParserInputPtr input)
 
xmlParserInputPtr xmlNewInputStream (xmlParserCtxtPtr ctxt)
 
xmlParserInputPtr xmlNewIOInputStream (xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input, xmlCharEncoding enc)
 
xmlParserInputPtr xmlNewEntityInputStream (xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
 
xmlParserInputPtr xmlNewStringInputStream (xmlParserCtxtPtr ctxt, const xmlChar *buffer)
 
xmlParserInputPtr xmlNewInputFromFile (xmlParserCtxtPtr ctxt, const char *filename)
 
int xmlInitParserCtxt (xmlParserCtxtPtr ctxt)
 
void xmlFreeParserCtxt (xmlParserCtxtPtr ctxt)
 
xmlParserCtxtPtr xmlNewParserCtxt (void)
 
void xmlClearParserCtxt (xmlParserCtxtPtr ctxt)
 
const xmlParserNodeInfoxmlParserFindNodeInfo (const xmlParserCtxtPtr ctx, const xmlNodePtr node)
 
void xmlInitNodeInfoSeq (xmlParserNodeInfoSeqPtr seq)
 
void xmlClearNodeInfoSeq (xmlParserNodeInfoSeqPtr seq)
 
unsigned long xmlParserFindNodeInfoIndex (const xmlParserNodeInfoSeqPtr seq, const xmlNodePtr node)
 
void xmlParserAddNodeInfo (xmlParserCtxtPtr ctxt, const xmlParserNodeInfoPtr info)
 
int xmlPedanticParserDefault (int val)
 
int xmlLineNumbersDefault (int val)
 
int xmlSubstituteEntitiesDefault (int val)
 
int xmlKeepBlanksDefault (int val)
 

Macro Definition Documentation

◆ bottom_parserInternals

#define bottom_parserInternals

Definition at line 2164 of file parserInternals.c.

◆ CHECK_BUFFER

#define CHECK_BUFFER (   in)

Definition at line 270 of file parserInternals.c.

◆ CUR

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

Definition at line 58 of file parserInternals.c.

◆ END

#define END (   ctxt)    ctxt->input->end

Definition at line 59 of file parserInternals.c.

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 10 of file parserInternals.c.

◆ LINE_LEN

#define LINE_LEN   80

Definition at line 245 of file parserInternals.c.

◆ VALID_CTXT

#define VALID_CTXT (   ctxt)    (CUR(ctxt) <= END(ctxt))

Definition at line 60 of file parserInternals.c.

◆ XML_DIR_SEP

#define XML_DIR_SEP   '/'

Definition at line 16 of file parserInternals.c.

Function Documentation

◆ __xmlErrEncoding()

void __xmlErrEncoding ( xmlParserCtxtPtr  ctxt,
xmlParserErrors  xmlerr,
const char msg,
const xmlChar str1,
const xmlChar str2 
)

__xmlErrEncoding: @ctxt: an XML parser context @xmlerr: the error number @msg: the error message @str1: an string info @str2: an string info

Handle an encoding error

Definition at line 145 of file parserInternals.c.

147 {
148  if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
149  (ctxt->instate == XML_PARSER_EOF))
150  return;
151  if (ctxt != NULL)
152  ctxt->errNo = xmlerr;
153  __xmlRaiseError(NULL, NULL, NULL,
154  ctxt, NULL, XML_FROM_PARSER, xmlerr, XML_ERR_FATAL,
155  NULL, 0, (const char *) str1, (const char *) str2,
156  NULL, 0, 0, msg, str1, str2);
157  if (ctxt != NULL) {
158  ctxt->wellFormed = 0;
159  if (ctxt->recovery == 0)
160  ctxt->disableSAX = 1;
161  }
162 }
xmlParserInputState instate
Definition: parser.h:223
int disableSAX
Definition: parser.h:237
int recovery
Definition: parser.h:261
smooth NULL
Definition: ftsmooth.c:416
int wellFormed
Definition: parser.h:188
#define msg(x)
Definition: auth_time.c:54

Referenced by xmlCurrentChar(), xmlNextChar(), xmlStringCurrentChar(), and xmlSwitchEncoding().

◆ LIBXML_ATTR_FORMAT() [1/2]

static void LIBXML_ATTR_FORMAT ( ,
 
)
static

xmlErrInternal: @ctxt: an XML parser context @msg: the error message @str: error informations

Handle an internal error

Definition at line 172 of file parserInternals.c.

174 {
175  if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
176  (ctxt->instate == XML_PARSER_EOF))
177  return;
178  if (ctxt != NULL)
179  ctxt->errNo = XML_ERR_INTERNAL_ERROR;
180  __xmlRaiseError(NULL, NULL, NULL,
182  XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
183  0, 0, msg, str);
184  if (ctxt != NULL) {
185  ctxt->wellFormed = 0;
186  if (ctxt->recovery == 0)
187  ctxt->disableSAX = 1;
188  }
189 }
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define msg(x)
Definition: auth_time.c:54

◆ LIBXML_ATTR_FORMAT() [2/2]

static void LIBXML_ATTR_FORMAT ( ,
 
)
static

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

n encoding error

Definition at line 200 of file parserInternals.c.

203 {
204  if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
205  (ctxt->instate == XML_PARSER_EOF))
206  return;
207  if (ctxt != NULL)
208  ctxt->errNo = error;
209  __xmlRaiseError(NULL, NULL, NULL,
211  NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
212  if (ctxt != NULL) {
213  ctxt->wellFormed = 0;
214  if (ctxt->recovery == 0)
215  ctxt->disableSAX = 1;
216  }
217 }
#define error(str)
Definition: mkdosfs.c:1605
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
#define msg(x)
Definition: auth_time.c:54

◆ xmlCheckVersion()

void xmlCheckVersion ( int  version)

xmlCheckVersion:

Version
: the include version number

check the compiled lib version against the include one. This can warn or immediately kill the application

Definition at line 77 of file parserInternals.c.

77  {
78  int myversion = (int) LIBXML_VERSION;
79 
80  xmlInitParser();
81 
82  if ((myversion / 10000) != (version / 10000)) {
84  "Fatal: program compiled against libxml %d using libxml %d\n",
85  (version / 10000), (myversion / 10000));
87  "Fatal: program compiled against libxml %d using libxml %d\n",
88  (version / 10000), (myversion / 10000));
89  }
90  if ((myversion / 100) < (version / 100)) {
92  "Warning: program compiled against libxml %d using older %d\n",
93  (version / 100), (myversion / 100));
94  }
95 }
#define LIBXML_VERSION
Definition: xmlversion.h:39
XMLPUBFUN void XMLCALL xmlInitParser(void)
Definition: parser.c:14706
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
static const WCHAR version[]
Definition: asmname.c:64
FILE * stderr
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

◆ xmlClearNodeInfoSeq()

void xmlClearNodeInfoSeq ( xmlParserNodeInfoSeqPtr  seq)

xmlClearNodeInfoSeq: @seq: a node info sequence pointer

– Clear (release memory and reinitialize) node info sequence

Definition at line 1951 of file parserInternals.c.

1952 {
1953  if (seq == NULL)
1954  return;
1955  if (seq->buffer != NULL)
1956  xmlFree(seq->buffer);
1957  xmlInitNodeInfoSeq(seq);
1958 }
xmlParserNodeInfo * buffer
Definition: parser.h:103
smooth NULL
Definition: ftsmooth.c:416
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)

Referenced by xmlClearParserCtxt().

◆ xmlClearParserCtxt()

void xmlClearParserCtxt ( xmlParserCtxtPtr  ctxt)

xmlClearParserCtxt: @ctxt: an XML parser context

Clear (release owned resources) and reinitialize a parser context

Definition at line 1892 of file parserInternals.c.

1893 {
1894  if (ctxt==NULL)
1895  return;
1896  xmlClearNodeInfoSeq(&ctxt->node_seq);
1897  xmlCtxtReset(ctxt);
1898 }
void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
XMLPUBFUN void XMLCALL xmlCtxtReset(xmlParserCtxtPtr ctxt)
Definition: parser.c:14813
smooth NULL
Definition: ftsmooth.c:416
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211

◆ xmlCopyChar()

int xmlCopyChar ( int len  ATTRIBUTE_UNUSED,
xmlChar out,
int  val 
)

xmlCopyChar: @len: Ignored, compatibility @out: pointer to an array of xmlChar @val: the char value

append the char value in the array

Returns the number of xmlChar written

Definition at line 900 of file parserInternals.c.

900  {
901  if (out == NULL) return(0);
902  /* the len parameter is ignored */
903  if (val >= 0x80) {
904  return(xmlCopyCharMultiByte (out, val));
905  }
906  *out = (xmlChar) val;
907  return 1;
908 }
int xmlCopyCharMultiByte(xmlChar *out, int val)
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
static FILE * out
Definition: regtests2xml.c:44
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlParseAttValueComplex().

◆ xmlCopyCharMultiByte()

int xmlCopyCharMultiByte ( xmlChar out,
int  val 
)

xmlCopyCharMultiByte: @out: pointer to an array of xmlChar @val: the char value

append the char value in the array

Returns the number of xmlChar written

Definition at line 857 of file parserInternals.c.

857  {
858  if (out == NULL) return(0);
859  /*
860  * We are supposed to handle UTF8, check it's valid
861  * From rfc2044: encoding of the Unicode values on UTF-8:
862  *
863  * UCS-4 range (hex.) UTF-8 octet sequence (binary)
864  * 0000 0000-0000 007F 0xxxxxxx
865  * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
866  * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
867  */
868  if (val >= 0x80) {
869  xmlChar *savedout = out;
870  int bits;
871  if (val < 0x800) { *out++= (val >> 6) | 0xC0; bits= 0; }
872  else if (val < 0x10000) { *out++= (val >> 12) | 0xE0; bits= 6;}
873  else if (val < 0x110000) { *out++= (val >> 18) | 0xF0; bits= 12; }
874  else {
875  xmlErrEncodingInt(NULL, XML_ERR_INVALID_CHAR,
876  "Internal error, xmlCopyCharMultiByte 0x%X out of bound\n",
877  val);
878  return(0);
879  }
880  for ( ; bits >= 0; bits-= 6)
881  *out++= ((val >> bits) & 0x3F) | 0x80 ;
882  return (out - savedout);
883  }
884  *out = (xmlChar) val;
885  return 1;
886 }
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
static FILE * out
Definition: regtests2xml.c:44
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlCopyChar(), and xsltNumberFormatDecimal().

◆ xmlCurrentChar()

int xmlCurrentChar ( xmlParserCtxtPtr  ctxt,
int len 
)

xmlCurrentChar: @ctxt: the XML parser context @len: pointer to the length of the char read

The current char value, if using UTF-8 this may actually span multiple bytes in the input buffer. Implement the end of line normalization: 2.11 End-of-Line Handling Wherever an external parsed entity or the literal entity value of an internal parsed entity contains either the literal two-character sequence "#xD#xA" or a standalone literal #xD, an XML processor must pass to the application the single character #xA. This behavior can conveniently be produced by normalizing all line breaks to #xA on input, before parsing.)

Returns the current char value and its length

Definition at line 588 of file parserInternals.c.

588  {
589  if ((ctxt == NULL) || (len == NULL) || (ctxt->input == NULL)) return(0);
590  if (ctxt->instate == XML_PARSER_EOF)
591  return(0);
592 
593  if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
594  *len = 1;
595  return((int) *ctxt->input->cur);
596  }
597  if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
598  /*
599  * We are supposed to handle UTF8, check it's valid
600  * From rfc2044: encoding of the Unicode values on UTF-8:
601  *
602  * UCS-4 range (hex.) UTF-8 octet sequence (binary)
603  * 0000 0000-0000 007F 0xxxxxxx
604  * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
605  * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
606  *
607  * Check for the 0x110000 limit too
608  */
609  const unsigned char *cur = ctxt->input->cur;
610  unsigned char c;
611  unsigned int val;
612 
613  c = *cur;
614  if (c & 0x80) {
615  if (((c & 0x40) == 0) || (c == 0xC0))
616  goto encoding_error;
617  if (cur[1] == 0) {
619  cur = ctxt->input->cur;
620  }
621  if ((cur[1] & 0xc0) != 0x80)
622  goto encoding_error;
623  if ((c & 0xe0) == 0xe0) {
624  if (cur[2] == 0) {
626  cur = ctxt->input->cur;
627  }
628  if ((cur[2] & 0xc0) != 0x80)
629  goto encoding_error;
630  if ((c & 0xf0) == 0xf0) {
631  if (cur[3] == 0) {
633  cur = ctxt->input->cur;
634  }
635  if (((c & 0xf8) != 0xf0) ||
636  ((cur[3] & 0xc0) != 0x80))
637  goto encoding_error;
638  /* 4-byte code */
639  *len = 4;
640  val = (cur[0] & 0x7) << 18;
641  val |= (cur[1] & 0x3f) << 12;
642  val |= (cur[2] & 0x3f) << 6;
643  val |= cur[3] & 0x3f;
644  if (val < 0x10000)
645  goto encoding_error;
646  } else {
647  /* 3-byte code */
648  *len = 3;
649  val = (cur[0] & 0xf) << 12;
650  val |= (cur[1] & 0x3f) << 6;
651  val |= cur[2] & 0x3f;
652  if (val < 0x800)
653  goto encoding_error;
654  }
655  } else {
656  /* 2-byte code */
657  *len = 2;
658  val = (cur[0] & 0x1f) << 6;
659  val |= cur[1] & 0x3f;
660  if (val < 0x80)
661  goto encoding_error;
662  }
663  if (!IS_CHAR(val)) {
664  xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
665  "Char 0x%X out of allowed range\n", val);
666  }
667  return(val);
668  } else {
669  /* 1-byte code */
670  *len = 1;
671  if (*ctxt->input->cur == 0)
673  if ((*ctxt->input->cur == 0) &&
674  (ctxt->input->end > ctxt->input->cur)) {
675  xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
676  "Char 0x0 out of allowed range\n", 0);
677  }
678  if (*ctxt->input->cur == 0xD) {
679  if (ctxt->input->cur[1] == 0xA) {
680  ctxt->nbChars++;
681  ctxt->input->cur++;
682  }
683  return(0xA);
684  }
685  return((int) *ctxt->input->cur);
686  }
687  }
688  /*
689  * Assume it's a fixed length encoding (1) with
690  * a compatible encoding for the ASCII set, since
691  * XML constructs only use < 128 chars
692  */
693  *len = 1;
694  if (*ctxt->input->cur == 0xD) {
695  if (ctxt->input->cur[1] == 0xA) {
696  ctxt->nbChars++;
697  ctxt->input->cur++;
698  }
699  return(0xA);
700  }
701  return((int) *ctxt->input->cur);
702 encoding_error:
703  /*
704  * An encoding problem may arise from a truncated input buffer
705  * splitting a character in the middle. In that case do not raise
706  * an error but return 0 to endicate an end of stream problem
707  */
708  if (ctxt->input->end - ctxt->input->cur < 4) {
709  *len = 0;
710  return(0);
711  }
712 
713  /*
714  * If we detect an UTF8 error that probably mean that the
715  * input encoding didn't get properly advertised in the
716  * declaration header. Report the error and switch the encoding
717  * to ISO-Latin-1 (if you don't like this policy, just declare the
718  * encoding !)
719  */
720  {
721  char buffer[150];
722 
723  snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
724  ctxt->input->cur[0], ctxt->input->cur[1],
725  ctxt->input->cur[2], ctxt->input->cur[3]);
727  "Input is not proper UTF-8, indicate encoding !\n%s",
728  BAD_CAST buffer, NULL);
729  }
731  *len = 1;
732  return((int) *ctxt->input->cur);
733 }
xmlParserInputState instate
Definition: parser.h:223
const xmlChar * cur
Definition: parser.h:61
#define snprintf
Definition: wintirpc.h:48
GLuint buffer
Definition: glext.h:5915
long nbChars
Definition: parser.h:234
xmlParserInputPtr input
Definition: parser.h:199
#define IS_CHAR(c)
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
const GLubyte * c
Definition: glext.h:8905
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
GLenum GLsizei len
Definition: glext.h:6722
#define INPUT_CHUNK
int xmlParserInputGrow(xmlParserInputPtr in, int len)
#define c
Definition: ke_i.h:80
const xmlChar * end
Definition: parser.h:62

◆ xmlErrMemory()

void xmlErrMemory ( xmlParserCtxtPtr  ctxt,
const char extra 
)

xmlErrMemory: @ctxt: an XML parser context @extra: extra informations

Handle a redefinition of attribute error

Definition at line 113 of file parserInternals.c.

114 {
115  if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
116  (ctxt->instate == XML_PARSER_EOF))
117  return;
118  if (ctxt != NULL) {
119  ctxt->errNo = XML_ERR_NO_MEMORY;
120  ctxt->instate = XML_PARSER_EOF;
121  ctxt->disableSAX = 1;
122  }
123  if (extra)
124  __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
126  NULL, NULL, 0, 0,
127  "Memory allocation failed : %s\n", extra);
128  else
129  __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
131  NULL, NULL, 0, 0, "Memory allocation failed\n");
132 }
xmlParserInputState instate
Definition: parser.h:223
int disableSAX
Definition: parser.h:237
smooth NULL
Definition: ftsmooth.c:416
Definition: id3.c:18

Referenced by inputPush(), namePush(), nodePush(), nsPush(), spacePush(), xmlAddDefAttrs(), xmlAddSpecialAttr(), xmlAttrNormalizeSpace2(), xmlCharStrndup(), xmlCreateIOParserCtxt(), xmlCreateURLParserCtxt(), xmlCtxtGrowAttrs(), xmlCtxtResetPush(), xmlDetectSAX2(), xmlEscapeFormatString(), xmlInitParserCtxt(), xmlNewInputStream(), xmlNewParserCtxt(), xmlNewStringInputStream(), xmlParseAttValueComplex(), xmlParseCDSect(), xmlParseComment(), xmlParseCommentComplex(), xmlParseElementChildrenContentDeclPriv(), xmlParseEncName(), xmlParseEntityDecl(), xmlParseEntityValue(), xmlParseExternalSubset(), xmlParseName(), xmlParseNCName(), xmlParseNmtoken(), xmlParsePI(), xmlParsePubidLiteral(), xmlParserAddNodeInfo(), xmlParseStartTag2(), xmlParseStringName(), xmlParseSystemLiteral(), xmlParseVersionNum(), xmlSAX2AttributeNs(), xmlSAX2TextNode(), xmlSplitQName(), xmlStringLenDecodeEntities(), xmlStrncat(), xmlStrncatNew(), and xmlStrndup().

◆ xmlFreeInputStream()

void xmlFreeInputStream ( xmlParserInputPtr  input)

xmlFreeInputStream: @input: an xmlParserInputPtr

Free up an input stream.

Definition at line 1339 of file parserInternals.c.

1339  {
1340  if (input == NULL) return;
1341 
1342  if (input->filename != NULL) xmlFree((char *) input->filename);
1343  if (input->directory != NULL) xmlFree((char *) input->directory);
1344  if (input->encoding != NULL) xmlFree((char *) input->encoding);
1345  if (input->version != NULL) xmlFree((char *) input->version);
1346  if ((input->free != NULL) && (input->base != NULL))
1347  input->free((xmlChar *) input->base);
1348  if (input->buf != NULL)
1350  xmlFree(input);
1351 }
XMLPUBFUN void XMLCALL xmlFreeParserInputBuffer(xmlParserInputBufferPtr in)
smooth NULL
Definition: ftsmooth.c:416
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLenum GLenum input
Definition: glext.h:9031

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

◆ xmlFreeParserCtxt()

void xmlFreeParserCtxt ( xmlParserCtxtPtr  ctxt)

xmlFreeParserCtxt: @ctxt: an XML parser context

Free all the memory used by a parser context. However the parsed document in ctxt->myDoc is not freed.

Definition at line 1775 of file parserInternals.c.

1776 {
1778 
1779  if (ctxt == NULL) return;
1780 
1781  while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1783  }
1784  if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
1785  if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
1786  if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
1787  if (ctxt->nodeInfoTab != NULL) xmlFree(ctxt->nodeInfoTab);
1788  if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
1789  if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
1790  if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
1791  if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
1792  if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
1793 #ifdef LIBXML_SAX1_ENABLED
1794  if ((ctxt->sax != NULL) &&
1796 #else
1797  if (ctxt->sax != NULL)
1798 #endif /* LIBXML_SAX1_ENABLED */
1799  xmlFree(ctxt->sax);
1800  if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
1801  if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
1802  if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
1803  if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
1804  if (ctxt->nsTab != NULL) xmlFree((char *) ctxt->nsTab);
1805  if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);
1806  if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);
1807  if (ctxt->attsDefault != NULL)
1809  if (ctxt->attsSpecial != NULL)
1810  xmlHashFree(ctxt->attsSpecial, NULL);
1811  if (ctxt->freeElems != NULL) {
1812  xmlNodePtr cur, next;
1813 
1814  cur = ctxt->freeElems;
1815  while (cur != NULL) {
1816  next = cur->next;
1817  xmlFree(cur);
1818  cur = next;
1819  }
1820  }
1821  if (ctxt->freeAttrs != NULL) {
1822  xmlAttrPtr cur, next;
1823 
1824  cur = ctxt->freeAttrs;
1825  while (cur != NULL) {
1826  next = cur->next;
1827  xmlFree(cur);
1828  cur = next;
1829  }
1830  }
1831  /*
1832  * cleanup the error strings
1833  */
1834  if (ctxt->lastError.message != NULL)
1835  xmlFree(ctxt->lastError.message);
1836  if (ctxt->lastError.file != NULL)
1837  xmlFree(ctxt->lastError.file);
1838  if (ctxt->lastError.str1 != NULL)
1839  xmlFree(ctxt->lastError.str1);
1840  if (ctxt->lastError.str2 != NULL)
1841  xmlFree(ctxt->lastError.str2);
1842  if (ctxt->lastError.str3 != NULL)
1843  xmlFree(ctxt->lastError.str3);
1844 
1845 #ifdef LIBXML_CATALOG_ENABLED
1846  if (ctxt->catalogs != NULL)
1847  xmlCatalogFreeLocal(ctxt->catalogs);
1848 #endif
1849  xmlFree(ctxt);
1850 }
int * attallocs
Definition: parser.h:282
int * spaceTab
Definition: parser.h:247
xmlChar * extSubURI
Definition: parser.h:240
char * file
Definition: xmlerror.h:83
xmlParserInputPtr * inputTab
Definition: parser.h:202
struct _xmlAttr * next
Definition: tree.h:441
xmlAttrPtr freeAttrs
Definition: parser.h:296
xmlNodePtr * nodeTab
Definition: parser.h:208
xmlNodePtr * nodeTab
Definition: valid.h:91
xmlError lastError
Definition: parser.h:301
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
Definition: hash.c:320
char * message
Definition: xmlerror.h:81
xmlHashTablePtr attsDefault
Definition: parser.h:284
smooth NULL
Definition: ftsmooth.c:416
xmlChar * extSubSystem
Definition: parser.h:241
xmlDictPtr dict
Definition: parser.h:263
void ** pushTab
Definition: parser.h:283
char * str2
Definition: xmlerror.h:86
XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler
Definition: globals.h:321
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
void xmlFreeInputStream(xmlParserInputPtr input)
Definition: tree.h:489
const xmlChar * encoding
Definition: parser.h:191
unsigned char xmlChar
Definition: xmlstring.h:28
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:793
struct _xmlSAXHandler * sax
Definition: parser.h:185
const xmlChar * version
Definition: parser.h:190
void * catalogs
Definition: parser.h:260
XMLPUBFUN xmlParserInputPtr XMLCALL inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1740
const xmlChar ** atts
Definition: parser.h:264
char * str3
Definition: xmlerror.h:87
static unsigned __int64 next
Definition: rand_nt.c:6
GLenum GLenum GLenum input
Definition: glext.h:9031
xmlParserNodeInfo * nodeInfoTab
Definition: parser.h:310
struct _xmlNode * next
Definition: tree.h:496
xmlHashTablePtr attsSpecial
Definition: parser.h:285
char * directory
Definition: parser.h:226
const xmlChar ** nsTab
Definition: parser.h:281
Definition: tree.h:434
const xmlChar ** nameTab
Definition: parser.h:232
xmlValidCtxt vctxt
Definition: parser.h:221
xmlNodePtr freeElems
Definition: parser.h:294
XMLPUBFUN void XMLCALL xmlHashDefaultDeallocator(void *entry, const xmlChar *name)
char * str1
Definition: xmlerror.h:85

Referenced by main(), parseAndPrintFile(), testSAX(), xmlCreateEntityParserCtxtInternal(), xmlCreateIOParserCtxt(), xmlCreateMemoryParserCtxt(), xmlCreateURLParserCtxt(), xmlDoRead(), xmlNewParserCtxt(), xmlParseBalancedChunkMemoryInternal(), xmlParseCtxtExternalEntity(), xmlParseExternalEntityPrivate(), xmlParseInNodeContext(), xmlReadFd(), xmlReadIO(), and xsltDocDefaultLoaderFunc().

◆ xmlInitNodeInfoSeq()

void xmlInitNodeInfoSeq ( xmlParserNodeInfoSeqPtr  seq)

xmlInitNodeInfoSeq: @seq: a node info sequence pointer

– Initialize (set to initial state) node info sequence

Definition at line 1934 of file parserInternals.c.

1935 {
1936  if (seq == NULL)
1937  return;
1938  seq->length = 0;
1939  seq->maximum = 0;
1940  seq->buffer = NULL;
1941 }
xmlParserNodeInfo * buffer
Definition: parser.h:103
smooth NULL
Definition: ftsmooth.c:416
unsigned long length
Definition: parser.h:102
unsigned long maximum
Definition: parser.h:101

Referenced by xmlClearNodeInfoSeq(), xmlCtxtReset(), and xmlInitParserCtxt().

◆ xmlInitParserCtxt()

int xmlInitParserCtxt ( xmlParserCtxtPtr  ctxt)

xmlInitParserCtxt: @ctxt: an XML parser context

Initialize a parser context

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

Definition at line 1589 of file parserInternals.c.

1590 {
1592 
1593  if(ctxt==NULL) {
1594  xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
1595  return(-1);
1596  }
1597 
1599 
1600  if (ctxt->dict == NULL)
1601  ctxt->dict = xmlDictCreate();
1602  if (ctxt->dict == NULL) {
1603  xmlErrMemory(NULL, "cannot initialize parser context\n");
1604  return(-1);
1605  }
1607 
1608  if (ctxt->sax == NULL)
1609  ctxt->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
1610  if (ctxt->sax == NULL) {
1611  xmlErrMemory(NULL, "cannot initialize parser context\n");
1612  return(-1);
1613  }
1614  else
1615  xmlSAXVersion(ctxt->sax, 2);
1616 
1617  ctxt->maxatts = 0;
1618  ctxt->atts = NULL;
1619  /* Allocate the Input stack */
1620  if (ctxt->inputTab == NULL) {
1621  ctxt->inputTab = (xmlParserInputPtr *)
1622  xmlMalloc(5 * sizeof(xmlParserInputPtr));
1623  ctxt->inputMax = 5;
1624  }
1625  if (ctxt->inputTab == NULL) {
1626  xmlErrMemory(NULL, "cannot initialize parser context\n");
1627  ctxt->inputNr = 0;
1628  ctxt->inputMax = 0;
1629  ctxt->input = NULL;
1630  return(-1);
1631  }
1632  while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1634  }
1635  ctxt->inputNr = 0;
1636  ctxt->input = NULL;
1637 
1638  ctxt->version = NULL;
1639  ctxt->encoding = NULL;
1640  ctxt->standalone = -1;
1641  ctxt->hasExternalSubset = 0;
1642  ctxt->hasPErefs = 0;
1643  ctxt->html = 0;
1644  ctxt->external = 0;
1645  ctxt->instate = XML_PARSER_START;
1646  ctxt->token = 0;
1647  ctxt->directory = NULL;
1648 
1649  /* Allocate the Node stack */
1650  if (ctxt->nodeTab == NULL) {
1651  ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
1652  ctxt->nodeMax = 10;
1653  }
1654  if (ctxt->nodeTab == NULL) {
1655  xmlErrMemory(NULL, "cannot initialize parser context\n");
1656  ctxt->nodeNr = 0;
1657  ctxt->nodeMax = 0;
1658  ctxt->node = NULL;
1659  ctxt->inputNr = 0;
1660  ctxt->inputMax = 0;
1661  ctxt->input = NULL;
1662  return(-1);
1663  }
1664  ctxt->nodeNr = 0;
1665  ctxt->node = NULL;
1666 
1667  /* Allocate the Name stack */
1668  if (ctxt->nameTab == NULL) {
1669  ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
1670  ctxt->nameMax = 10;
1671  }
1672  if (ctxt->nameTab == NULL) {
1673  xmlErrMemory(NULL, "cannot initialize parser context\n");
1674  ctxt->nodeNr = 0;
1675  ctxt->nodeMax = 0;
1676  ctxt->node = NULL;
1677  ctxt->inputNr = 0;
1678  ctxt->inputMax = 0;
1679  ctxt->input = NULL;
1680  ctxt->nameNr = 0;
1681  ctxt->nameMax = 0;
1682  ctxt->name = NULL;
1683  return(-1);
1684  }
1685  ctxt->nameNr = 0;
1686  ctxt->name = NULL;
1687 
1688  /* Allocate the space stack */
1689  if (ctxt->spaceTab == NULL) {
1690  ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
1691  ctxt->spaceMax = 10;
1692  }
1693  if (ctxt->spaceTab == NULL) {
1694  xmlErrMemory(NULL, "cannot initialize parser context\n");
1695  ctxt->nodeNr = 0;
1696  ctxt->nodeMax = 0;
1697  ctxt->node = NULL;
1698  ctxt->inputNr = 0;
1699  ctxt->inputMax = 0;
1700  ctxt->input = NULL;
1701  ctxt->nameNr = 0;
1702  ctxt->nameMax = 0;
1703  ctxt->name = NULL;
1704  ctxt->spaceNr = 0;
1705  ctxt->spaceMax = 0;
1706  ctxt->space = NULL;
1707  return(-1);
1708  }
1709  ctxt->spaceNr = 1;
1710  ctxt->spaceMax = 10;
1711  ctxt->spaceTab[0] = -1;
1712  ctxt->space = &ctxt->spaceTab[0];
1713  ctxt->userData = ctxt;
1714  ctxt->myDoc = NULL;
1715  ctxt->wellFormed = 1;
1716  ctxt->nsWellFormed = 1;
1717  ctxt->valid = 1;
1719  if (ctxt->loadsubset) {
1720  ctxt->options |= XML_PARSE_DTDLOAD;
1721  }
1724  if (ctxt->pedantic) {
1725  ctxt->options |= XML_PARSE_PEDANTIC;
1726  }
1729  if (ctxt->keepBlanks == 0) {
1730  ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
1731  ctxt->options |= XML_PARSE_NOBLANKS;
1732  }
1733 
1734  ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0;
1735  ctxt->vctxt.userData = ctxt;
1738  if (ctxt->validate) {
1739  if (xmlGetWarningsDefaultValue == 0)
1740  ctxt->vctxt.warning = NULL;
1741  else
1743  ctxt->vctxt.nodeMax = 0;
1744  ctxt->options |= XML_PARSE_DTDVALID;
1745  }
1747  if (ctxt->replaceEntities) {
1748  ctxt->options |= XML_PARSE_NOENT;
1749  }
1750  ctxt->record_info = 0;
1751  ctxt->nbChars = 0;
1752  ctxt->checkIndex = 0;
1753  ctxt->inSubset = 0;
1754  ctxt->errNo = XML_ERR_OK;
1755  ctxt->depth = 0;
1757  ctxt->catalogs = NULL;
1758  ctxt->nbentities = 0;
1759  ctxt->sizeentities = 0;
1760  ctxt->sizeentcopy = 0;
1761  ctxt->input_id = 1;
1762  xmlInitNodeInfoSeq(&ctxt->node_seq);
1763  return(0);
1764 }
int nodeMax
Definition: valid.h:90
xmlParserInputState instate
Definition: parser.h:223
unsigned long sizeentities
Definition: parser.h:304
XMLPUBVAR int xmlGetWarningsDefaultValue
Definition: globals.h:378
int * spaceTab
Definition: parser.h:247
xmlParserInputPtr * inputTab
Definition: parser.h:202
unsigned int finishDtd
Definition: valid.h:93
XMLPUBFUN xmlDictPtr XMLCALL xmlDictCreate(void)
Definition: dict.c:568
long checkIndex
Definition: parser.h:235
int pedantic
Definition: parser.h:255
XMLPUBFUN size_t XMLCALL xmlDictSetLimit(xmlDictPtr dict, size_t limit)
Definition: dict.c:1256
int nsWellFormed
Definition: parser.h:286
xmlValidityErrorFunc error
Definition: valid.h:84
xmlNodePtr * nodeTab
Definition: parser.h:208
XMLPUBVAR int xmlSubstituteEntitiesDefaultValue
Definition: globals.h:467
int external
Definition: parser.h:217
XMLPUBVAR int xmlLoadExtDtdDefaultValue
Definition: globals.h:423
long nbChars
Definition: parser.h:234
const xmlChar * name
Definition: parser.h:229
int input_id
Definition: parser.h:312
xmlParserInputPtr input
Definition: parser.h:199
int spaceMax
Definition: parser.h:246
XMLPUBFUN int XMLCALL xmlSAXVersion(xmlSAXHandler *hdlr, int version)
Definition: SAX2.c:2866
int standalone
Definition: parser.h:192
XMLPUBVAR int xmlLineNumbersDefaultValue
Definition: globals.h:414
int linenumbers
Definition: parser.h:259
int replaceEntities
Definition: parser.h:189
smooth NULL
Definition: ftsmooth.c:416
xmlDictPtr dict
Definition: parser.h:263
#define XML_MAX_DICTIONARY_LIMIT
int validate
Definition: parser.h:220
XMLPUBFUN void XMLCALL xmlSAX2IgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
int inputMax
Definition: parser.h:201
XMLPUBVAR int xmlKeepBlanksDefaultValue
Definition: globals.h:405
int wellFormed
Definition: parser.h:188
xmlNodePtr node
Definition: parser.h:205
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
int record_info
Definition: parser.h:210
int hasPErefs
Definition: parser.h:216
XMLPUBVAR int xmlPedanticParserDefaultValue
Definition: globals.h:449
XMLPUBVAR int xmlDoValidityCheckingDefaultValue
Definition: globals.h:337
void xmlFreeInputStream(xmlParserInputPtr input)
Definition: tree.h:489
xmlDocPtr myDoc
Definition: parser.h:187
const xmlChar * encoding
Definition: parser.h:191
unsigned char xmlChar
Definition: xmlstring.h:28
struct _xmlSAXHandler * sax
Definition: parser.h:185
const xmlChar * version
Definition: parser.h:190
void * catalogs
Definition: parser.h:260
int loadsubset
Definition: parser.h:258
int hasExternalSubset
Definition: parser.h:215
XMLPUBFUN xmlParserInputPtr XMLCALL inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1740
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityWarning(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
unsigned long sizeentcopy
Definition: parser.h:313
const xmlChar ** atts
Definition: parser.h:264
GLenum GLenum GLenum input
Definition: glext.h:9031
void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
int inSubset
Definition: parser.h:238
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
char * directory
Definition: parser.h:226
XMLPUBFUN void XMLCALL xmlDefaultSAXHandlerInit(void)
Definition: SAX2.c:2939
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityError(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
int keepBlanks
Definition: parser.h:236
void * userData
Definition: valid.h:83
const xmlChar ** nameTab
Definition: parser.h:232
xmlValidCtxt vctxt
Definition: parser.h:221
int * space
Definition: parser.h:244
void * userData
Definition: parser.h:186
xmlValidityWarningFunc warning
Definition: valid.h:85
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211
unsigned long nbentities
Definition: parser.h:303

Referenced by xmlNewParserCtxt().

◆ xmlIsLetter()

int xmlIsLetter ( int  c)

xmlIsLetter: : an unicode character (int)

Check whether the character is allowed by the production [84] Letter ::= BaseChar | Ideographic

Returns 0 if not, non-zero otherwise

Definition at line 229 of file parserInternals.c.

229  {
230  return(IS_BASECHAR(c) || IS_IDEOGRAPHIC(c));
231 }
#define IS_IDEOGRAPHIC(c)
#define IS_BASECHAR(c)
const GLubyte * c
Definition: glext.h:8905

◆ xmlKeepBlanksDefault()

int xmlKeepBlanksDefault ( int  val)

xmlKeepBlanksDefault: @val: int 0 or 1

Set and return the previous value for default blanks text nodes support. The 1.x version of the parser used an heuristic to try to detect ignorable white spaces. As a result the SAX callback was generating xmlSAX2IgnorableWhitespace() callbacks instead of characters() one, and when using the DOM output text nodes containing those blanks were not generated. The 2.x and later version will switch to the XML standard way and ignorableWhitespace() are only generated when running the parser in validating mode and when the current element doesn't allow CDATA or mixed content. This function is provided as a way to force the standard behavior on 1.X libs and to switch back to the old mode for compatibility when running 1.X client code on 2.X . Upgrade of 1.X code should be done by using xmlIsBlankNode() commodity function to detect the "empty" nodes generated. This value also affect autogeneration of indentation when saving code if blanks sections are kept, indentation is not generated.

Returns the last value for 0 for no substitution, 1 for substitution.

Definition at line 2156 of file parserInternals.c.

2156  {
2157  int old = xmlKeepBlanksDefaultValue;
2158 
2160  if (!val) xmlIndentTreeOutput = 1;
2161  return(old);
2162 }
XMLPUBVAR int xmlIndentTreeOutput
Definition: globals.h:387
GLuint GLfloat * val
Definition: glext.h:7180
XMLPUBVAR int xmlKeepBlanksDefaultValue
Definition: globals.h:405

Referenced by main().

◆ xmlLineNumbersDefault()

int xmlLineNumbersDefault ( int  val)

xmlLineNumbersDefault: @val: int 0 or 1

Set and return the previous value for enabling line numbers in elements contents. This may break on old application and is turned off by default.

Returns the last value for 0 for no substitution, 1 for substitution.

Definition at line 2102 of file parserInternals.c.

2102  {
2103  int old = xmlLineNumbersDefaultValue;
2104 
2106  return(old);
2107 }
XMLPUBVAR int xmlLineNumbersDefaultValue
Definition: globals.h:414
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by main().

◆ xmlNewEntityInputStream()

xmlParserInputPtr xmlNewEntityInputStream ( xmlParserCtxtPtr  ctxt,
xmlEntityPtr  entity 
)

xmlNewEntityInputStream: @ctxt: an XML parser context @entity: an Entity pointer

Create a new input stream based on an xmlEntityPtr

Returns the new input stream or NULL

Definition at line 1430 of file parserInternals.c.

1430  {
1432 
1433  if (entity == NULL) {
1434  xmlErrInternal(ctxt, "xmlNewEntityInputStream entity = NULL\n",
1435  NULL);
1436  return(NULL);
1437  }
1440  "new input from entity: %s\n", entity->name);
1441  if (entity->content == NULL) {
1442  switch (entity->etype) {
1444  xmlErrInternal(ctxt, "Cannot parse entity %s\n",
1445  entity->name);
1446  break;
1449  return(xmlLoadExternalEntity((char *) entity->URI,
1450  (char *) entity->ExternalID, ctxt));
1452  xmlErrInternal(ctxt,
1453  "Internal entity %s without content !\n",
1454  entity->name);
1455  break;
1457  xmlErrInternal(ctxt,
1458  "Internal parameter entity %s without content !\n",
1459  entity->name);
1460  break;
1462  xmlErrInternal(ctxt,
1463  "Predefined entity %s without content !\n",
1464  entity->name);
1465  break;
1466  }
1467  return(NULL);
1468  }
1469  input = xmlNewInputStream(ctxt);
1470  if (input == NULL) {
1471  return(NULL);
1472  }
1473  if (entity->URI != NULL)
1474  input->filename = (char *) xmlStrdup((xmlChar *) entity->URI);
1475  input->base = entity->content;
1476  if (entity->length == 0)
1477  entity->length = xmlStrlen(entity->content);
1478  input->cur = entity->content;
1479  input->length = entity->length;
1480  input->end = &entity->content[input->length];
1481  return(input);
1482 }
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
Definition: actctx.c:371
WCHAR * name
Definition: actctx.c:389
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
unsigned char xmlChar
Definition: xmlstring.h:28
XMLPUBFUN xmlParserInputPtr XMLCALL xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:432
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlLoadEntityContent(), and xmlParsePEReference().

◆ xmlNewInputFromFile()

xmlParserInputPtr xmlNewInputFromFile ( xmlParserCtxtPtr  ctxt,
const char filename 
)

xmlNewInputFromFile: @ctxt: an XML parser context @filename: the filename to use as entity

Create a new input stream based on a file or an URL.

Returns the new input stream or NULL in case of error

Definition at line 1526 of file parserInternals.c.

1526  {
1528  xmlParserInputPtr inputStream;
1529  char *directory = NULL;
1530  xmlChar *URI = NULL;
1531 
1534  "new input from file: %s\n", filename);
1535  if (ctxt == NULL) return(NULL);
1537  if (buf == NULL) {
1538  if (filename == NULL)
1539  __xmlLoaderErr(ctxt,
1540  "failed to load external entity: NULL filename \n",
1541  NULL);
1542  else
1543  __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
1544  (const char *) filename);
1545  return(NULL);
1546  }
1547 
1548  inputStream = xmlNewInputStream(ctxt);
1549  if (inputStream == NULL)
1550  return(NULL);
1551 
1552  inputStream->buf = buf;
1553  inputStream = xmlCheckHTTPInput(ctxt, inputStream);
1554  if (inputStream == NULL)
1555  return(NULL);
1556 
1557  if (inputStream->filename == NULL)
1558  URI = xmlStrdup((xmlChar *) filename);
1559  else
1560  URI = xmlStrdup((xmlChar *) inputStream->filename);
1561  directory = xmlParserGetDirectory((const char *) URI);
1562  if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
1563  inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
1564  if (URI != NULL) xmlFree((char *) URI);
1565  inputStream->directory = directory;
1566 
1567  xmlBufResetInput(inputStream->buf->buffer, inputStream);
1568  if ((ctxt->directory == NULL) && (directory != NULL))
1569  ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
1570  return(inputStream);
1571 }
void __xmlLoaderErr(void *ctx, const char *msg, const char *filename) LIBXML_ATTR_FORMAT(2
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
XMLPUBFUN char *XMLCALL xmlParserGetDirectory(const char *filename)
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1283
const char * filename
Definition: ioapi.h:135
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
XMLPUBFUN xmlChar *XMLCALL xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2370
smooth NULL
Definition: ftsmooth.c:416
xmlBufPtr buffer
Definition: xmlIO.h:132
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc)
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
unsigned char xmlChar
Definition: xmlstring.h:28
XMLPUBFUN xmlParserInputPtr XMLCALL xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret)
xmlParserInputBufferPtr buf
Definition: parser.h:56
const char * filename
Definition: parser.h:58
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:432
char * directory
Definition: parser.h:226
const char * directory
Definition: parser.h:59
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

◆ xmlNewInputStream()

xmlParserInputPtr xmlNewInputStream ( xmlParserCtxtPtr  ctxt)

xmlNewInputStream: @ctxt: an XML parser context

Create a new input stream structure.

Returns the new input stream or NULL

Definition at line 1362 of file parserInternals.c.

1362  {
1364 
1366  if (input == NULL) {
1367  xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1368  return(NULL);
1369  }
1370  memset(input, 0, sizeof(xmlParserInput));
1371  input->line = 1;
1372  input->col = 1;
1373  input->standalone = -1;
1374 
1375  /*
1376  * If the context is NULL the id cannot be initialized, but that
1377  * should not happen while parsing which is the situation where
1378  * the id is actually needed.
1379  */
1380  if (ctxt != NULL)
1381  input->id = ctxt->input_id++;
1382 
1383  return(input);
1384 }
xmlParserInput * xmlParserInputPtr
Definition: tree.h:36
int input_id
Definition: parser.h:312
smooth NULL
Definition: ftsmooth.c:416
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
#define memset(x, y, z)
Definition: compat.h:39

Referenced by xmlCreateMemoryParserCtxt(), xmlCtxtResetPush(), xmlNewEntityInputStream(), xmlNewInputFromFile(), xmlNewIOInputStream(), and xmlNewStringInputStream().

◆ xmlNewIOInputStream()

xmlParserInputPtr xmlNewIOInputStream ( xmlParserCtxtPtr  ctxt,
xmlParserInputBufferPtr  input,
xmlCharEncoding  enc 
)

xmlNewIOInputStream: @ctxt: an XML parser context @input: an I/O Input @enc: the charset encoding if known

Create a new input stream structure encapsulating the @input into a stream suitable for the parser.

Returns the new input stream or NULL

Definition at line 1398 of file parserInternals.c.

1399  {
1400  xmlParserInputPtr inputStream;
1401 
1402  if (input == NULL) return(NULL);
1404  xmlGenericError(xmlGenericErrorContext, "new input from I/O\n");
1405  inputStream = xmlNewInputStream(ctxt);
1406  if (inputStream == NULL) {
1407  return(NULL);
1408  }
1409  inputStream->filename = NULL;
1410  inputStream->buf = input;
1411  xmlBufResetInput(inputStream->buf->buffer, inputStream);
1412 
1413  if (enc != XML_CHAR_ENCODING_NONE) {
1414  xmlSwitchEncoding(ctxt, enc);
1415  }
1416 
1417  return(inputStream);
1418 }
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1283
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
xmlBufPtr buffer
Definition: xmlIO.h:132
int xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
xmlParserInputBufferPtr buf
Definition: parser.h:56
const char * filename
Definition: parser.h:58
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:432
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by testSAX(), xmlCreateIOParserCtxt(), xmlCtxtReadFd(), xmlCtxtReadIO(), xmlCtxtReadMemory(), xmlReadFd(), and xmlReadIO().

◆ xmlNewParserCtxt()

xmlParserCtxtPtr xmlNewParserCtxt ( void  )

xmlNewParserCtxt:

Allocate and initialize a new parser context.

Returns the xmlParserCtxtPtr or NULL

Definition at line 1861 of file parserInternals.c.

1862 {
1863  xmlParserCtxtPtr ctxt;
1864 
1865  ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
1866  if (ctxt == NULL) {
1867  xmlErrMemory(NULL, "cannot allocate parser context\n");
1868  return(NULL);
1869  }
1870  memset(ctxt, 0, sizeof(xmlParserCtxt));
1871  if (xmlInitParserCtxt(ctxt) < 0) {
1872  xmlFreeParserCtxt(ctxt);
1873  return(NULL);
1874  }
1875  return(ctxt);
1876 }
void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
smooth NULL
Definition: ftsmooth.c:416
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
xmlParserCtxt * xmlParserCtxtPtr
Definition: tree.h:39
#define memset(x, y, z)
Definition: compat.h:39
int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)

Referenced by main(), parseAndPrintFile(), testSAX(), xmlCreateEntityParserCtxtInternal(), xmlCreateIOParserCtxt(), xmlCreateMemoryParserCtxt(), xmlCreateURLParserCtxt(), xmlReadFd(), xmlReadIO(), and xsltDocDefaultLoaderFunc().

◆ xmlNewStringInputStream()

xmlParserInputPtr xmlNewStringInputStream ( xmlParserCtxtPtr  ctxt,
const xmlChar buffer 
)

xmlNewStringInputStream: @ctxt: an XML parser context @buffer: an memory buffer

Create a new input stream based on a memory buffer. Returns the new input stream

Definition at line 1493 of file parserInternals.c.

1493  {
1495 
1496  if (buffer == NULL) {
1497  xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
1498  NULL);
1499  return(NULL);
1500  }
1503  "new fixed input: %.30s\n", buffer);
1504  input = xmlNewInputStream(ctxt);
1505  if (input == NULL) {
1506  xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1507  return(NULL);
1508  }
1509  input->base = buffer;
1510  input->cur = buffer;
1511  input->length = xmlStrlen(buffer);
1512  input->end = &buffer[input->length];
1513  return(input);
1514 }
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
GLuint buffer
Definition: glext.h:5915
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:432
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlCtxtReadDoc().

◆ xmlNextChar()

void xmlNextChar ( xmlParserCtxtPtr  ctxt)

xmlNextChar: @ctxt: the XML parser context

Skip to the next char input char.

Definition at line 423 of file parserInternals.c.

424 {
425  if ((ctxt == NULL) || (ctxt->instate == XML_PARSER_EOF) ||
426  (ctxt->input == NULL))
427  return;
428 
429  if (!(VALID_CTXT(ctxt))) {
430  xmlErrInternal(ctxt, "Parser input data memory error\n", NULL);
432  xmlStopParser(ctxt);
433  return;
434  }
435 
436  if ((*ctxt->input->cur == 0) &&
437  (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
438  return;
439  }
440 
441  if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
442  const unsigned char *cur;
443  unsigned char c;
444 
445  /*
446  * 2.11 End-of-Line Handling
447  * the literal two-character sequence "#xD#xA" or a standalone
448  * literal #xD, an XML processor must pass to the application
449  * the single character #xA.
450  */
451  if (*(ctxt->input->cur) == '\n') {
452  ctxt->input->line++; ctxt->input->col = 1;
453  } else
454  ctxt->input->col++;
455 
456  /*
457  * We are supposed to handle UTF8, check it's valid
458  * From rfc2044: encoding of the Unicode values on UTF-8:
459  *
460  * UCS-4 range (hex.) UTF-8 octet sequence (binary)
461  * 0000 0000-0000 007F 0xxxxxxx
462  * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
463  * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
464  *
465  * Check for the 0x110000 limit too
466  */
467  cur = ctxt->input->cur;
468 
469  c = *cur;
470  if (c & 0x80) {
471  if (c == 0xC0)
472  goto encoding_error;
473  if (cur[1] == 0) {
475  cur = ctxt->input->cur;
476  }
477  if ((cur[1] & 0xc0) != 0x80)
478  goto encoding_error;
479  if ((c & 0xe0) == 0xe0) {
480  unsigned int val;
481 
482  if (cur[2] == 0) {
484  cur = ctxt->input->cur;
485  }
486  if ((cur[2] & 0xc0) != 0x80)
487  goto encoding_error;
488  if ((c & 0xf0) == 0xf0) {
489  if (cur[3] == 0) {
491  cur = ctxt->input->cur;
492  }
493  if (((c & 0xf8) != 0xf0) ||
494  ((cur[3] & 0xc0) != 0x80))
495  goto encoding_error;
496  /* 4-byte code */
497  ctxt->input->cur += 4;
498  val = (cur[0] & 0x7) << 18;
499  val |= (cur[1] & 0x3f) << 12;
500  val |= (cur[2] & 0x3f) << 6;
501  val |= cur[3] & 0x3f;
502  } else {
503  /* 3-byte code */
504  ctxt->input->cur += 3;
505  val = (cur[0] & 0xf) << 12;
506  val |= (cur[1] & 0x3f) << 6;
507  val |= cur[2] & 0x3f;
508  }
509  if (((val > 0xd7ff) && (val < 0xe000)) ||
510  ((val > 0xfffd) && (val < 0x10000)) ||
511  (val >= 0x110000)) {
512  xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
513  "Char 0x%X out of allowed range\n",
514  val);
515  }
516  } else
517  /* 2-byte code */
518  ctxt->input->cur += 2;
519  } else
520  /* 1-byte code */
521  ctxt->input->cur++;
522 
523  ctxt->nbChars++;
524  } else {
525  /*
526  * Assume it's a fixed length encoding (1) with
527  * a compatible encoding for the ASCII set, since
528  * XML constructs only use < 128 chars
529  */
530 
531  if (*(ctxt->input->cur) == '\n') {
532  ctxt->input->line++; ctxt->input->col = 1;
533  } else
534  ctxt->input->col++;
535  ctxt->input->cur++;
536  ctxt->nbChars++;
537  }
538  if (*ctxt->input->cur == 0)
540  return;
541 encoding_error:
542  /*
543  * If we detect an UTF8 error that probably mean that the
544  * input encoding didn't get properly advertised in the
545  * declaration header. Report the error and switch the encoding
546  * to ISO-Latin-1 (if you don't like this policy, just declare the
547  * encoding !)
548  */
549  if ((ctxt == NULL) || (ctxt->input == NULL) ||
550  (ctxt->input->end - ctxt->input->cur < 4)) {
552  "Input is not proper UTF-8, indicate encoding !\n",
553  NULL, NULL);
554  } else {
555  char buffer[150];
556 
557  snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
558  ctxt->input->cur[0], ctxt->input->cur[1],
559  ctxt->input->cur[2], ctxt->input->cur[3]);
561  "Input is not proper UTF-8, indicate encoding !\n%s",
562  BAD_CAST buffer, NULL);
563  }
565  ctxt->input->cur++;
566  return;
567 }
xmlParserInputState instate
Definition: parser.h:223
#define VALID_CTXT(ctxt)
const xmlChar * cur
Definition: parser.h:61
#define snprintf
Definition: wintirpc.h:48
GLuint buffer
Definition: glext.h:5915
XMLPUBFUN void XMLCALL xmlStopParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12483
long nbChars
Definition: parser.h:234
xmlParserInputPtr input
Definition: parser.h:199
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
const GLubyte * c
Definition: glext.h:8905
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
#define INPUT_CHUNK
int xmlParserInputGrow(xmlParserInputPtr in, int len)
#define c
Definition: ke_i.h:80
const xmlChar * end
Definition: parser.h:62

◆ xmlParserAddNodeInfo()

void xmlParserAddNodeInfo ( xmlParserCtxtPtr  ctxt,
const xmlParserNodeInfoPtr  info 
)

xmlParserAddNodeInfo: @ctxt: an XML parser context @info: a node info sequence pointer

Insert node info record into the sorted sequence

Definition at line 2011 of file parserInternals.c.

2013 {
2014  unsigned long pos;
2015 
2016  if ((ctxt == NULL) || (info == NULL)) return;
2017 
2018  /* Find pos and check to see if node is already in the sequence */
2020  info->node);
2021 
2022  if ((pos < ctxt->node_seq.length) &&
2023  (ctxt->node_seq.buffer != NULL) &&
2024  (ctxt->node_seq.buffer[pos].node == info->node)) {
2025  ctxt->node_seq.buffer[pos] = *info;
2026  }
2027 
2028  /* Otherwise, we need to add new node to buffer */
2029  else {
2030  if ((ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) ||
2031  (ctxt->node_seq.buffer == NULL)) {
2032  xmlParserNodeInfo *tmp_buffer;
2033  unsigned int byte_size;
2034 
2035  if (ctxt->node_seq.maximum == 0)
2036  ctxt->node_seq.maximum = 2;
2037  byte_size = (sizeof(*ctxt->node_seq.buffer) *
2038  (2 * ctxt->node_seq.maximum));
2039 
2040  if (ctxt->node_seq.buffer == NULL)
2041  tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
2042  else
2043  tmp_buffer =
2045  byte_size);
2046 
2047  if (tmp_buffer == NULL) {
2048  xmlErrMemory(ctxt, "failed to allocate buffer\n");
2049  return;
2050  }
2051  ctxt->node_seq.buffer = tmp_buffer;
2052  ctxt->node_seq.maximum *= 2;
2053  }
2054 
2055  /* If position is not at end, move elements out of the way */
2056  if (pos != ctxt->node_seq.length) {
2057  unsigned long i;
2058 
2059  for (i = ctxt->node_seq.length; i > pos; i--)
2060  ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
2061  }
2062 
2063  /* Copy element and increase length */
2064  ctxt->node_seq.buffer[pos] = *info;
2065  ctxt->node_seq.length++;
2066  }
2067 }
struct _test_info info[]
Definition: SetCursorPos.c:19
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq, const xmlNodePtr node)
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
xmlParserNodeInfo * buffer
Definition: parser.h:103
smooth NULL
Definition: ftsmooth.c:416
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:249
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
Definition: tree.h:489
const struct _xmlNode * node
Definition: parser.h:90
unsigned long length
Definition: parser.h:102
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
unsigned long maximum
Definition: parser.h:101
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211

Referenced by xmlParseElement(), and xmlSAX2EndElementNs().

◆ xmlParserFindNodeInfo()

const xmlParserNodeInfo* xmlParserFindNodeInfo ( const xmlParserCtxtPtr  ctx,
const xmlNodePtr  node 
)

xmlParserFindNodeInfo: @ctx: an XML parser context @node: an XML node within the tree

Find the parser node info struct for a given node

Returns an xmlParserNodeInfo block pointer or NULL

Definition at line 1911 of file parserInternals.c.

1912 {
1913  unsigned long pos;
1914 
1915  if ((ctx == NULL) || (node == NULL))
1916  return (NULL);
1917  /* Find position where node should be at */
1919  if (pos < ctx->node_seq.length
1920  && ctx->node_seq.buffer[pos].node == node)
1921  return &ctx->node_seq.buffer[pos];
1922  else
1923  return NULL;
1924 }
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq, const xmlNodePtr node)
xmlParserNodeInfo * buffer
Definition: parser.h:103
smooth NULL
Definition: ftsmooth.c:416
const struct _xmlNode * node
Definition: parser.h:90
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211
Definition: dlist.c:348

◆ xmlParserFindNodeInfoIndex()

unsigned long xmlParserFindNodeInfoIndex ( const xmlParserNodeInfoSeqPtr  seq,
const xmlNodePtr  node 
)

xmlParserFindNodeInfoIndex: @seq: a node info sequence pointer @node: an XML node pointer

xmlParserFindNodeInfoIndex : Find the index that the info record for the given node is or should be at in a sorted sequence

Returns a long indicating the position of the record

Definition at line 1972 of file parserInternals.c.

1974 {
1975  unsigned long upper, lower, middle;
1976  int found = 0;
1977 
1978  if ((seq == NULL) || (node == NULL))
1979  return ((unsigned long) -1);
1980 
1981  /* Do a binary search for the key */
1982  lower = 1;
1983  upper = seq->length;
1984  middle = 0;
1985  while (lower <= upper && !found) {
1986  middle = lower + (upper - lower) / 2;
1987  if (node == seq->buffer[middle - 1].node)
1988  found = 1;
1989  else if (node < seq->buffer[middle - 1].node)
1990  upper = middle - 1;
1991  else
1992  lower = middle + 1;
1993  }
1994 
1995  /* Return position */
1996  if (middle == 0 || seq->buffer[middle - 1].node < node)
1997  return middle;
1998  else
1999  return middle - 1;
2000 }
GLuint buffer
Definition: glext.h:5915
xmlParserNodeInfo * buffer
Definition: parser.h:103
smooth NULL
Definition: ftsmooth.c:416
const struct _xmlNode * node
Definition: parser.h:90
unsigned long length
Definition: parser.h:102
Definition: dlist.c:348

Referenced by xmlParserAddNodeInfo(), and xmlParserFindNodeInfo().

◆ xmlParserInputGrow()

int xmlParserInputGrow ( xmlParserInputPtr  in,
int  len 
)

xmlParserInputGrow: @in: an XML parser input @len: an indicative size for the lookahead

This function increase the input for the parser. It tries to preserve pointers to the input buffer, and keep already read data

Returns the amount of char read, or -1 in case of error, 0 indicate the end of this entity

Definition at line 300 of file parserInternals.c.

300  {
301  int ret;
302  size_t indx;
303  const xmlChar *content;
304 
305  if ((in == NULL) || (len < 0)) return(-1);
306 #ifdef DEBUG_INPUT
308 #endif
309  if (in->buf == NULL) return(-1);
310  if (in->base == NULL) return(-1);
311  if (in->cur == NULL) return(-1);
312  if (in->buf->buffer == NULL) return(-1);
313 
314  CHECK_BUFFER(in);
315 
316  indx = in->cur - in->base;
317  if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) {
318 
319  CHECK_BUFFER(in);
320 
321  return(0);
322  }
323  if (in->buf->readcallback != NULL) {
325  } else
326  return(0);
327 
328  /*
329  * NOTE : in->base may be a "dangling" i.e. freed pointer in this
330  * block, but we use it really as an integer to do some
331  * pointer arithmetic. Insure will raise it as a bug but in
332  * that specific case, that's not !
333  */
334 
335  content = xmlBufContent(in->buf->buffer);
336  if (in->base != content) {
337  /*
338  * the buffer has been reallocated
339  */
340  indx = in->cur - in->base;
341  in->base = content;
342  in->cur = &content[indx];
343  }
344  in->end = xmlBufEnd(in->buf->buffer);
345 
346  CHECK_BUFFER(in);
347 
348  return(ret);
349 }
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:582
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:600
content
Definition: atl_ax.c:994
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
#define INPUT_CHUNK
GLuint in
Definition: glext.h:9616
XMLPUBFUN int XMLCALL xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len)
#define CHECK_BUFFER(in)
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:687
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlCurrentChar(), xmlGROW(), xmlNextChar(), xmlPopInput(), xmlSHRINK(), and xmlSkipBlankChars().

◆ xmlParserInputRead()

int xmlParserInputRead ( xmlParserInputPtr in  ATTRIBUTE_UNUSED,
int len  ATTRIBUTE_UNUSED 
)

xmlParserInputRead: @in: an XML parser input @len: an indicative size for the lookahead

This function was internal and is deprecated.

Returns -1 as this is an error to use it.

Definition at line 284 of file parserInternals.c.

284  {
285  return(-1);
286 }

◆ xmlParserInputShrink()

void xmlParserInputShrink ( xmlParserInputPtr  in)

xmlParserInputShrink: @in: an XML parser input

This function removes used input for the parser.

Definition at line 358 of file parserInternals.c.

358  {
359  size_t used;
360  size_t ret;
361  size_t indx;
362  const xmlChar *content;
363 
364 #ifdef DEBUG_INPUT
366 #endif
367  if (in == NULL) return;
368  if (in->buf == NULL) return;
369  if (in->base == NULL) return;
370  if (in->cur == NULL) return;
371  if (in->buf->buffer == NULL) return;
372 
373  CHECK_BUFFER(in);
374 
375  used = in->cur - xmlBufContent(in->buf->buffer);
376  /*
377  * Do not shrink on large buffers whose only a tiny fraction
378  * was consumed
379  */
380  if (used > INPUT_CHUNK) {
381  ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
382  if (ret > 0) {
383  in->cur -= ret;
384  in->consumed += ret;
385  }
386  in->end = xmlBufEnd(in->buf->buffer);
387  }
388 
389  CHECK_BUFFER(in);
390 
391  if (xmlBufUse(in->buf->buffer) > INPUT_CHUNK) {
392  return;
393  }
395  content = xmlBufContent(in->buf->buffer);
396  if (in->base != content) {
397  /*
398  * the buffer has been reallocated
399  */
400  indx = in->cur - in->base;
401  in->base = content;
402  in->cur = &content[indx];
403  }
404  in->end = xmlBufEnd(in->buf->buffer);
405 
406  CHECK_BUFFER(in);
407 }
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:582
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:600
content
Definition: atl_ax.c:994
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
c used
Definition: write.c:2877
#define LINE_LEN
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
#define INPUT_CHUNK
GLuint in
Definition: glext.h:9616
XMLPUBFUN int XMLCALL xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len)
#define CHECK_BUFFER(in)
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:687
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:388
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlSHRINK().

◆ xmlPedanticParserDefault()

int xmlPedanticParserDefault ( int  val)

xmlPedanticParserDefault: @val: int 0 or 1

Set and return the previous value for enabling pedantic warnings.

Returns the last value for 0 for no substitution, 1 for substitution.

Definition at line 2084 of file parserInternals.c.

2084  {
2086 
2088  return(old);
2089 }
GLuint GLfloat * val
Definition: glext.h:7180
XMLPUBVAR int xmlPedanticParserDefaultValue
Definition: globals.h:449

Referenced by main().

◆ xmlStringCurrentChar()

int xmlStringCurrentChar ( xmlParserCtxtPtr  ctxt,
const xmlChar cur,
int len 
)

xmlStringCurrentChar: @ctxt: the XML parser context @cur: pointer to the beginning of the char @len: pointer to the length of the char read

The current char value, if using UTF-8 this may actually span multiple bytes in the input buffer.

Returns the current char value and its length

Definition at line 748 of file parserInternals.c.

749 {
750  if ((len == NULL) || (cur == NULL)) return(0);
751  if ((ctxt == NULL) || (ctxt->charset == XML_CHAR_ENCODING_UTF8)) {
752  /*
753  * We are supposed to handle UTF8, check it's valid
754  * From rfc2044: encoding of the Unicode values on UTF-8:
755  *
756  * UCS-4 range (hex.) UTF-8 octet sequence (binary)
757  * 0000 0000-0000 007F 0xxxxxxx
758  * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
759  * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
760  *
761  * Check for the 0x110000 limit too
762  */
763  unsigned char c;
764  unsigned int val;
765 
766  c = *cur;
767  if (c & 0x80) {
768  if ((cur[1] & 0xc0) != 0x80)
769  goto encoding_error;
770  if ((c & 0xe0) == 0xe0) {
771 
772  if ((cur[2] & 0xc0) != 0x80)
773  goto encoding_error;
774  if ((c & 0xf0) == 0xf0) {
775  if (((c & 0xf8) != 0xf0) || ((cur[3] & 0xc0) != 0x80))
776  goto encoding_error;
777  /* 4-byte code */
778  *len = 4;
779  val = (cur[0] & 0x7) << 18;
780  val |= (cur[1] & 0x3f) << 12;
781  val |= (cur[2] & 0x3f) << 6;
782  val |= cur[3] & 0x3f;
783  } else {
784  /* 3-byte code */
785  *len = 3;
786  val = (cur[0] & 0xf) << 12;
787  val |= (cur[1] & 0x3f) << 6;
788  val |= cur[2] & 0x3f;
789  }
790  } else {
791  /* 2-byte code */
792  *len = 2;
793  val = (cur[0] & 0x1f) << 6;
794  val |= cur[1] & 0x3f;
795  }
796  if (!IS_CHAR(val)) {
797  xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
798  "Char 0x%X out of allowed range\n", val);
799  }
800  return (val);
801  } else {
802  /* 1-byte code */
803  *len = 1;
804  return ((int) *cur);
805  }
806  }
807  /*
808  * Assume it's a fixed length encoding (1) with
809  * a compatible encoding for the ASCII set, since
810  * XML constructs only use < 128 chars
811  */
812  *len = 1;
813  return ((int) *cur);
814 encoding_error:
815 
816  /*
817  * An encoding problem may arise from a truncated input buffer
818  * splitting a character in the middle. In that case do not raise
819  * an error but return 0 to endicate an end of stream problem
820  */
821  if ((ctxt == NULL) || (ctxt->input == NULL) ||
822  (ctxt->input->end - ctxt->input->cur < 4)) {
823  *len = 0;
824  return(0);
825  }
826  /*
827  * If we detect an UTF8 error that probably mean that the
828  * input encoding didn't get properly advertised in the
829  * declaration header. Report the error and switch the encoding
830  * to ISO-Latin-1 (if you don't like this policy, just declare the
831  * encoding !)
832  */
833  {
834  char buffer[150];
835 
836  snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
837  ctxt->input->cur[0], ctxt->input->cur[1],
838  ctxt->input->cur[2], ctxt->input->cur[3]);
840  "Input is not proper UTF-8, indicate encoding !\n%s",
841  BAD_CAST buffer, NULL);
842  }
843  *len = 1;
844  return ((int) *cur);
845 }
const xmlChar * cur
Definition: parser.h:61
#define snprintf
Definition: wintirpc.h:48
GLuint buffer
Definition: glext.h:5915
xmlParserInputPtr input
Definition: parser.h:199
#define IS_CHAR(c)
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
const GLubyte * c
Definition: glext.h:8905
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
GLenum GLsizei len
Definition: glext.h:6722
#define c
Definition: ke_i.h:80
const xmlChar * end
Definition: parser.h:62

Referenced by xsltNumberFormatTokenize(), xsltScanLiteral(), and xsltScanNCName().

◆ xmlSubstituteEntitiesDefault()

int xmlSubstituteEntitiesDefault ( int  val)

xmlSubstituteEntitiesDefault: @val: int 0 or 1

Set and return the previous value for default entity support. Initially the parser always keep entity references instead of substituting entity values in the output. This function has to be used to change the default parser behavior SAX::substituteEntities() has to be used for changing that on a file by file basis.

Returns the last value for 0 for no substitution, 1 for substitution.

Definition at line 2124 of file parserInternals.c.

2124  {
2126 
2128  return(old);
2129 }
XMLPUBVAR int xmlSubstituteEntitiesDefaultValue
Definition: globals.h:467
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by main().

◆ xmlSwitchEncoding()

int xmlSwitchEncoding ( xmlParserCtxtPtr  ctxt,
xmlCharEncoding  enc 
)

xmlSwitchEncoding: @ctxt: the parser context @enc: the encoding value (number)

change the input functions when discovering the character encoding of a given entity.

Returns 0 in case of success, -1 otherwise

Definition at line 933 of file parserInternals.c.

934 {
936  int len = -1;
937  int ret;
938 
939  if (ctxt == NULL) return(-1);
940  switch (enc) {
943  "encoding unknown\n", NULL, NULL);
944  return(-1);
946  /* let's assume it's UTF-8 without the XML decl */
948  return(0);
950  /* default encoding, no conversion should be needed */
952 
953  /*
954  * Errata on XML-1.0 June 20 2001
955  * Specific handling of the Byte Order Mark for
956  * UTF-8
957  */
958  if ((ctxt->input != NULL) &&
959  (ctxt->input->cur[0] == 0xEF) &&
960  (ctxt->input->cur[1] == 0xBB) &&
961  (ctxt->input->cur[2] == 0xBF)) {
962  ctxt->input->cur += 3;
963  }
964  return(0);
967  /*The raw input characters are encoded
968  *in UTF-16. As we expect this function
969  *to be called after xmlCharEncInFunc, we expect
970  *ctxt->input->cur to contain UTF-8 encoded characters.
971  *So the raw UTF16 Byte Order Mark
972  *has also been converted into
973  *an UTF-8 BOM. Let's skip that BOM.
974  */
975  if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) &&
976  (ctxt->input->cur[0] == 0xEF) &&
977  (ctxt->input->cur[1] == 0xBB) &&
978  (ctxt->input->cur[2] == 0xBF)) {
979  ctxt->input->cur += 3;
980  }
981  len = 90;
982  break;
984  len = 90;
985  break;
990  len = 180;
991  break;
1006  len = 45;
1007  break;
1008  }
1010  if (handler == NULL) {
1011  /*
1012  * Default handlers.
1013  */
1014  switch (enc) {
1016  /* default encoding, no conversion should be needed */
1018  return(0);
1020  break;
1022  break;
1025  "encoding not supported %s\n",
1026  BAD_CAST "USC4 little endian", NULL);
1027  break;
1030  "encoding not supported %s\n",
1031  BAD_CAST "USC4 big endian", NULL);
1032  break;
1035  "encoding not supported %s\n",
1036  BAD_CAST "EBCDIC", NULL);
1037  break;
1040  "encoding not supported %s\n",
1041  BAD_CAST "UCS4 2143", NULL);
1042  break;
1045  "encoding not supported %s\n",
1046  BAD_CAST "UCS4 3412", NULL);
1047  break;
1050  "encoding not supported %s\n",
1051  BAD_CAST "UCS2", NULL);
1052  break;
1062  /*
1063  * We used to keep the internal content in the
1064  * document encoding however this turns being unmaintainable
1065  * So xmlGetCharEncodingHandler() will return non-null
1066  * values for this now.
1067  */
1068  if ((ctxt->inputNr == 1) &&
1069  (ctxt->encoding == NULL) &&
1070  (ctxt->input != NULL) &&
1071  (ctxt->input->encoding != NULL)) {
1072  ctxt->encoding = xmlStrdup(ctxt->input->encoding);
1073  }
1074  ctxt->charset = enc;
1075  return(0);
1078  "encoding not supported %s\n",
1079  BAD_CAST "ISO-2022-JP", NULL);
1080  break;
1083  "encoding not supported %s\n",
1084  BAD_CAST "Shift_JIS", NULL);
1085  break;
1088  "encoding not supported %s\n",
1089  BAD_CAST "EUC-JP", NULL);
1090  break;
1091  default:
1092  break;
1093  }
1094  }
1095  /*
1096  * TODO: We could recover from errors in external entites if we
1097  * didn't stop the parser. But most callers of this function don't
1098  * check the return value.
1099  */
1100  if (handler == NULL) {
1101  xmlStopParser(ctxt);
1102  return(-1);
1103  }
1106  if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
1107  /*
1108  * on encoding conversion errors, stop the parser
1109  */
1110  xmlStopParser(ctxt);
1111  ctxt->errNo = XML_I18N_CONV_FAILED;
1112  }
1113  return(ret);
1114 }
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL xmlGetCharEncodingHandler(xmlCharEncoding enc)
Definition: encoding.c:1507
const xmlChar * cur
Definition: parser.h:61
XMLPUBFUN void XMLCALL xmlStopParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12483
xmlParserInputPtr input
Definition: parser.h:199
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
int ret
static int xmlSwitchToEncodingInt(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler, int len)
const xmlChar * encoding
Definition: parser.h:191
GLenum GLsizei len
Definition: glext.h:6722
const xmlChar * encoding
Definition: parser.h:73
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66

Referenced by xmlCtxtResetPush(), xmlNewIOInputStream(), xmlParseCtxtExternalEntity(), xmlParseDocument(), xmlParseExternalEntityPrivate(), xmlParseExternalSubset(), xmlParseExtParsedEnt(), xmlParsePEReference(), and xmlSAX2ExternalSubset().

◆ xmlSwitchInputEncoding()

int xmlSwitchInputEncoding ( xmlParserCtxtPtr  ctxt,
xmlParserInputPtr  input,
xmlCharEncodingHandlerPtr  handler 
)

xmlSwitchInputEncoding: @ctxt: the parser context @input: the input stream @handler: the encoding handler

change the input functions when discovering the character encoding of a given entity.

Returns 0 in case of success, -1 otherwise

Definition at line 1270 of file parserInternals.c.

1271  {
1272  return(xmlSwitchInputEncodingInt(ctxt, input, handler, -1));
1273 }
static int xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler, int len)
GLenum GLenum GLenum input
Definition: glext.h:9031
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786

◆ xmlSwitchInputEncodingInt()

static int xmlSwitchInputEncodingInt ( xmlParserCtxtPtr  ctxt,
xmlParserInputPtr  input,
xmlCharEncodingHandlerPtr  handler,
int  len 
)
static

xmlSwitchInputEncoding: @ctxt: the parser context @input: the input stream @handler: the encoding handler @len: the number of bytes to convert for the first line or -1

change the input functions when discovering the character encoding of a given entity.

Returns 0 in case of success, -1 otherwise

Definition at line 1129 of file parserInternals.c.

1131 {
1132  int nbchars;
1133 
1134  if (handler == NULL)
1135  return (-1);
1136  if (input == NULL)
1137  return (-1);
1138  if (input->buf != NULL) {
1139  if (input->buf->encoder != NULL) {
1140  /*
1141  * Check in case the auto encoding detetection triggered
1142  * in already.
1143  */
1144  if (input->buf->encoder == handler)
1145  return (0);
1146 
1147  /*
1148  * "UTF-16" can be used for both LE and BE
1149  if ((!xmlStrncmp(BAD_CAST input->buf->encoder->name,
1150  BAD_CAST "UTF-16", 6)) &&
1151  (!xmlStrncmp(BAD_CAST handler->name,
1152  BAD_CAST "UTF-16", 6))) {
1153  return(0);
1154  }
1155  */
1156 
1157  /*
1158  * Note: this is a bit dangerous, but that's what it
1159  * takes to use nearly compatible signature for different
1160  * encodings.
1161  */
1162  xmlCharEncCloseFunc(input->buf->encoder);
1163  input->buf->encoder = handler;
1164  return (0);
1165  }
1166  input->buf->encoder = handler;
1167 
1168  /*
1169  * Is there already some content down the pipe to convert ?
1170  */
1171  if (xmlBufIsEmpty(input->buf->buffer) == 0) {
1172  int processed;
1173  unsigned int use;
1174 
1175  /*
1176  * Specific handling of the Byte Order Mark for
1177  * UTF-16
1178  */
1179  if ((handler->name != NULL) &&
1180  (!strcmp(handler->name, "UTF-16LE") ||
1181  !strcmp(handler->name, "UTF-16")) &&
1182  (input->cur[0] == 0xFF) && (input->cur[1] == 0xFE)) {
1183  input->cur += 2;
1184  }
1185  if ((handler->name != NULL) &&
1186  (!strcmp(handler->name, "UTF-16BE")) &&
1187  (input->cur[0] == 0xFE) && (input->cur[1] == 0xFF)) {
1188  input->cur += 2;
1189  }
1190  /*
1191  * Errata on XML-1.0 June 20 2001
1192  * Specific handling of the Byte Order Mark for
1193  * UTF-8
1194  */
1195  if ((handler->name != NULL) &&
1196  (!strcmp(handler->name, "UTF-8")) &&
1197  (input->cur[0] == 0xEF) &&
1198  (input->cur[1] == 0xBB) && (input->cur[2] == 0xBF)) {
1199  input->cur += 3;
1200  }
1201 
1202  /*
1203  * Shrink the current input buffer.
1204  * Move it as the raw buffer and create a new input buffer
1205  */
1206  processed = input->cur - input->base;
1207  xmlBufShrink(input->buf->buffer, processed);
1208  input->buf->raw = input->buf->buffer;
1209  input->buf->buffer = xmlBufCreate();
1210  input->buf->rawconsumed = processed;
1211  use = xmlBufUse(input->buf->raw);
1212 
1213  if (ctxt->html) {
1214  /*
1215  * convert as much as possible of the buffer
1216  */
1217  nbchars = xmlCharEncInput(input->buf, 1);
1218  } else {
1219  /*
1220  * convert just enough to get
1221  * '<?xml version="1.0" encoding="xxx"?>'
1222  * parsed with the autodetected encoding
1223  * into the parser reading buffer.
1224  */
1225  nbchars = xmlCharEncFirstLineInput(input->buf, len);
1226  }
1227  xmlBufResetInput(input->buf->buffer, input);
1228  if (nbchars < 0) {
1229  xmlErrInternal(ctxt,
1230  "switching encoding: encoder error\n",
1231  NULL);
1232  return (-1);
1233  }
1234  input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
1235  }
1236  return (0);
1237  } else if (input->length == 0) {
1238  /*
1239  * When parsing a static memory array one must know the
1240  * size to be able to convert the buffer.
1241  */
1242  xmlErrInternal(ctxt, "switching encoding : no input\n", NULL);
1243  /*
1244  * Callers assume that the input buffer takes ownership of the
1245  * encoding handler. xmlCharEncCloseFunc frees unregistered
1246  * handlers and avoids a memory leak.
1247  */
1249  return (-1);
1250  }
1251  /*
1252  * We should actually raise an error here, see issue #34.
1253  */
1255  return (0);
1256 }
int xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
Definition: encoding.c:2096
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1283
int xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
Definition: encoding.c:2203
smooth NULL
Definition: ftsmooth.c:416
int xmlBufIsEmpty(const xmlBufPtr buf)
Definition: buf.c:726
XMLPUBFUN int XMLCALL xmlCharEncCloseFunc(xmlCharEncodingHandler *handler)
Definition: encoding.c:2720
GLenum GLsizei len
Definition: glext.h:6722
xmlBufPtr xmlBufCreate(void)
Definition: buf.c:122
GLenum GLenum GLenum input
Definition: glext.h:9031
static int processed(const type_t *type)
Definition: typegen.c:2236
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:687
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:388

Referenced by xmlSwitchInputEncoding(), and xmlSwitchToEncodingInt().

◆ xmlSwitchToEncoding()

int xmlSwitchToEncoding ( xmlParserCtxtPtr  ctxt,
xmlCharEncodingHandlerPtr  handler 
)

xmlSwitchToEncoding: @ctxt: the parser context @handler: the encoding handler

change the input functions when discovering the character encoding of a given entity.

Returns 0 in case of success, -1 otherwise

Definition at line 1321 of file parserInternals.c.

1322 {
1323  return (xmlSwitchToEncodingInt(ctxt, handler, -1));
1324 }
static int xmlSwitchToEncodingInt(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler, int len)
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786

Referenced by xmlCtxtResetPush(), xmlDoRead(), xmlParseEncodingDecl(), and xmlParseInNodeContext().

◆ xmlSwitchToEncodingInt()

static int xmlSwitchToEncodingInt ( xmlParserCtxtPtr  ctxt,
xmlCharEncodingHandlerPtr  handler,
int  len 
)
static

xmlSwitchToEncodingInt: @ctxt: the parser context @handler: the encoding handler @len: the length to convert or -1

change the input functions when discovering the character encoding of a given entity, and convert only @len bytes of the output, this is needed on auto detect to allows any declared encoding later to convert the actual content after the xmlDecl

Returns 0 in case of success, -1 otherwise

Definition at line 1289 of file parserInternals.c.

1290  {
1291  int ret = 0;
1292 
1293  if (handler != NULL) {
1294  if (ctxt->input != NULL) {
1295  ret = xmlSwitchInputEncodingInt(ctxt, ctxt->input, handler, len);
1296  } else {
1297  xmlErrInternal(ctxt, "xmlSwitchToEncoding : no input\n",
1298  NULL);
1299  return(-1);
1300  }
1301  /*
1302  * The parsing is now done in UTF8 natively
1303  */
1305  } else
1306  return(-1);
1307  return(ret);
1308 }
static int xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler, int len)
xmlParserInputPtr input
Definition: parser.h:199
smooth NULL
Definition: ftsmooth.c:416
int ret
GLenum GLsizei len
Definition: glext.h:6722
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786

Referenced by xmlSwitchEncoding(), and xmlSwitchToEncoding().