ReactOS 0.4.16-dev-338-g34e76ad
parserInternals.c File Reference
#include "libxml.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.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 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)
 

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 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

◆ CHECK_BUFFER

#define CHECK_BUFFER (   in)

Definition at line 254 of file parserInternals.c.

◆ CUR

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

Definition at line 42 of file parserInternals.c.

◆ END

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

Definition at line 43 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 229 of file parserInternals.c.

◆ VALID_CTXT

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

Definition at line 44 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 129 of file parserInternals.c.

131{
132 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
133 (ctxt->instate == XML_PARSER_EOF))
134 return;
135 if (ctxt != NULL)
136 ctxt->errNo = xmlerr;
137 __xmlRaiseError(NULL, NULL, NULL,
138 ctxt, NULL, XML_FROM_PARSER, xmlerr, XML_ERR_FATAL,
139 NULL, 0, (const char *) str1, (const char *) str2,
140 NULL, 0, 0, msg, str1, str2);
141 if (ctxt != NULL) {
142 ctxt->wellFormed = 0;
143 if (ctxt->recovery == 0)
144 ctxt->disableSAX = 1;
145 }
146}
#define msg(x)
Definition: auth_time.c:54
#define NULL
Definition: types.h:112
@ XML_PARSER_EOF
Definition: parser.h:111
int wellFormed
Definition: parser.h:188
int disableSAX
Definition: parser.h:237
xmlParserInputState instate
Definition: parser.h:223
int recovery
Definition: parser.h:261
@ XML_ERR_FATAL
Definition: xmlerror.h:28
@ XML_FROM_PARSER
Definition: xmlerror.h:38

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 information

Handle an internal error

Definition at line 156 of file parserInternals.c.

158{
159 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
160 (ctxt->instate == XML_PARSER_EOF))
161 return;
162 if (ctxt != NULL)
163 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
164 __xmlRaiseError(NULL, NULL, NULL,
166 XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
167 0, 0, msg, str);
168 if (ctxt != NULL) {
169 ctxt->wellFormed = 0;
170 if (ctxt->recovery == 0)
171 ctxt->disableSAX = 1;
172 }
173}
const WCHAR * str
@ XML_ERR_INTERNAL_ERROR
Definition: xmlerror.h:101

◆ 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 184 of file parserInternals.c.

187{
188 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
189 (ctxt->instate == XML_PARSER_EOF))
190 return;
191 if (ctxt != NULL)
192 ctxt->errNo = error;
193 __xmlRaiseError(NULL, NULL, NULL,
195 NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
196 if (ctxt != NULL) {
197 ctxt->wellFormed = 0;
198 if (ctxt->recovery == 0)
199 ctxt->disableSAX = 1;
200 }
201}
GLuint GLfloat * val
Definition: glext.h:7180
#define error(str)
Definition: mkdosfs.c:1605

◆ 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 61 of file parserInternals.c.

61 {
62 int myversion = (int) LIBXML_VERSION;
63
65
66 if ((myversion / 10000) != (version / 10000)) {
68 "Fatal: program compiled against libxml %d using libxml %d\n",
69 (version / 10000), (myversion / 10000));
71 "Fatal: program compiled against libxml %d using libxml %d\n",
72 (version / 10000), (myversion / 10000));
73 }
74 if ((myversion / 100) < (version / 100)) {
76 "Warning: program compiled against libxml %d using older %d\n",
77 (version / 100), (myversion / 100));
78 }
79}
static const WCHAR version[]
Definition: asmname.c:66
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
XMLPUBFUN void XMLCALL xmlInitParser(void)
Definition: parser.c:14676
#define LIBXML_VERSION
Definition: xmlversion.h:39

◆ xmlClearNodeInfoSeq()

void xmlClearNodeInfoSeq ( xmlParserNodeInfoSeqPtr  seq)

xmlClearNodeInfoSeq: @seq: a node info sequence pointer

– Clear (release memory and reinitialize) node info sequence

Definition at line 1805 of file parserInternals.c.

1806{
1807 if (seq == NULL)
1808 return;
1809 if (seq->buffer != NULL)
1810 xmlFree(seq->buffer);
1811 xmlInitNodeInfoSeq(seq);
1812}
void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
xmlParserNodeInfo * buffer
Definition: parser.h:101

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 1746 of file parserInternals.c.

1747{
1748 if (ctxt==NULL)
1749 return;
1751 xmlCtxtReset(ctxt);
1752}
void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
XMLPUBFUN void XMLCALL xmlCtxtReset(xmlParserCtxtPtr ctxt)
Definition: parser.c:14801
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 852 of file parserInternals.c.

852 {
853 if (out == NULL) return(0);
854 /* the len parameter is ignored */
855 if (val >= 0x80) {
856 return(xmlCopyCharMultiByte (out, val));
857 }
858 *out = (xmlChar) val;
859 return 1;
860}
int xmlCopyCharMultiByte(xmlChar *out, int val)
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 809 of file parserInternals.c.

809 {
810 if (out == NULL) return(0);
811 /*
812 * We are supposed to handle UTF8, check it's valid
813 * From rfc2044: encoding of the Unicode values on UTF-8:
814 *
815 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
816 * 0000 0000-0000 007F 0xxxxxxx
817 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
818 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
819 */
820 if (val >= 0x80) {
821 xmlChar *savedout = out;
822 int bits;
823 if (val < 0x800) { *out++= (val >> 6) | 0xC0; bits= 0; }
824 else if (val < 0x10000) { *out++= (val >> 12) | 0xE0; bits= 6;}
825 else if (val < 0x110000) { *out++= (val >> 18) | 0xF0; bits= 12; }
826 else {
827 xmlErrEncodingInt(NULL, XML_ERR_INVALID_CHAR,
828 "Internal error, xmlCopyCharMultiByte 0x%X out of bound\n",
829 val);
830 return(0);
831 }
832 for ( ; bits >= 0; bits-= 6)
833 *out++= ((val >> bits) & 0x3F) | 0x80 ;
834 return (out - savedout);
835 }
836 *out = (xmlChar) val;
837 return 1;
838}
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define bits
Definition: infblock.c:15
@ XML_ERR_INVALID_CHAR
Definition: xmlerror.h:109

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 542 of file parserInternals.c.

542 {
543 if ((ctxt == NULL) || (len == NULL) || (ctxt->input == NULL)) return(0);
544 if (ctxt->instate == XML_PARSER_EOF)
545 return(0);
546
547 if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
548 *len = 1;
549 return((int) *ctxt->input->cur);
550 }
551 if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
552 /*
553 * We are supposed to handle UTF8, check it's valid
554 * From rfc2044: encoding of the Unicode values on UTF-8:
555 *
556 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
557 * 0000 0000-0000 007F 0xxxxxxx
558 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
559 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
560 *
561 * Check for the 0x110000 limit too
562 */
563 const unsigned char *cur = ctxt->input->cur;
564 unsigned char c;
565 unsigned int val;
566
567 c = *cur;
568 if (c & 0x80) {
569 if (((c & 0x40) == 0) || (c == 0xC0))
570 goto encoding_error;
571 if (cur[1] == 0) {
573 cur = ctxt->input->cur;
574 }
575 if ((cur[1] & 0xc0) != 0x80)
576 goto encoding_error;
577 if ((c & 0xe0) == 0xe0) {
578 if (cur[2] == 0) {
580 cur = ctxt->input->cur;
581 }
582 if ((cur[2] & 0xc0) != 0x80)
583 goto encoding_error;
584 if ((c & 0xf0) == 0xf0) {
585 if (cur[3] == 0) {
587 cur = ctxt->input->cur;
588 }
589 if (((c & 0xf8) != 0xf0) ||
590 ((cur[3] & 0xc0) != 0x80))
591 goto encoding_error;
592 /* 4-byte code */
593 *len = 4;
594 val = (cur[0] & 0x7) << 18;
595 val |= (cur[1] & 0x3f) << 12;
596 val |= (cur[2] & 0x3f) << 6;
597 val |= cur[3] & 0x3f;
598 if (val < 0x10000)
599 goto encoding_error;
600 } else {
601 /* 3-byte code */
602 *len = 3;
603 val = (cur[0] & 0xf) << 12;
604 val |= (cur[1] & 0x3f) << 6;
605 val |= cur[2] & 0x3f;
606 if (val < 0x800)
607 goto encoding_error;
608 }
609 } else {
610 /* 2-byte code */
611 *len = 2;
612 val = (cur[0] & 0x1f) << 6;
613 val |= cur[1] & 0x3f;
614 if (val < 0x80)
615 goto encoding_error;
616 }
617 if (!IS_CHAR(val)) {
618 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
619 "Char 0x%X out of allowed range\n", val);
620 }
621 return(val);
622 } else {
623 /* 1-byte code */
624 *len = 1;
625 if (*ctxt->input->cur == 0)
627 if ((*ctxt->input->cur == 0) &&
628 (ctxt->input->end > ctxt->input->cur)) {
629 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
630 "Char 0x0 out of allowed range\n", 0);
631 }
632 if (*ctxt->input->cur == 0xD) {
633 if (ctxt->input->cur[1] == 0xA) {
634 ctxt->input->cur++;
635 }
636 return(0xA);
637 }
638 return((int) *ctxt->input->cur);
639 }
640 }
641 /*
642 * Assume it's a fixed length encoding (1) with
643 * a compatible encoding for the ASCII set, since
644 * XML constructs only use < 128 chars
645 */
646 *len = 1;
647 if (*ctxt->input->cur == 0xD) {
648 if (ctxt->input->cur[1] == 0xA) {
649 ctxt->input->cur++;
650 }
651 return(0xA);
652 }
653 return((int) *ctxt->input->cur);
654encoding_error:
655 /*
656 * An encoding problem may arise from a truncated input buffer
657 * splitting a character in the middle. In that case do not raise
658 * an error but return 0 to indicate an end of stream problem
659 */
660 if (ctxt->input->end - ctxt->input->cur < 4) {
661 *len = 0;
662 return(0);
663 }
664
665 /*
666 * If we detect an UTF8 error that probably mean that the
667 * input encoding didn't get properly advertised in the
668 * declaration header. Report the error and switch the encoding
669 * to ISO-Latin-1 (if you don't like this policy, just declare the
670 * encoding !)
671 */
672 {
673 char buffer[150];
674
675 snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
676 ctxt->input->cur[0], ctxt->input->cur[1],
677 ctxt->input->cur[2], ctxt->input->cur[3]);
679 "Input is not proper UTF-8, indicate encoding !\n%s",
681 }
683 *len = 1;
684 return((int) *ctxt->input->cur);
685}
@ XML_CHAR_ENCODING_UTF8
Definition: encoding.h:59
@ XML_CHAR_ENCODING_8859_1
Definition: encoding.h:68
FxCollectionEntry * cur
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLenum GLsizei len
Definition: glext.h:6722
#define c
Definition: ke_i.h:80
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
int xmlParserInputGrow(xmlParserInputPtr in, int len)
#define IS_CHAR(c)
#define INPUT_CHUNK
xmlParserInputPtr input
Definition: parser.h:199
const xmlChar * end
Definition: parser.h:60
const xmlChar * cur
Definition: parser.h:59
#define snprintf
Definition: wintirpc.h:48
#define BAD_CAST
Definition: xmlstring.h:35

◆ xmlErrMemory()

void xmlErrMemory ( xmlParserCtxtPtr  ctxt,
const char extra 
)

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

Handle a redefinition of attribute error

Definition at line 97 of file parserInternals.c.

98{
99 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
100 (ctxt->instate == XML_PARSER_EOF))
101 return;
102 if (ctxt != NULL) {
103 ctxt->errNo = XML_ERR_NO_MEMORY;
104 ctxt->instate = XML_PARSER_EOF;
105 ctxt->disableSAX = 1;
106 }
107 if (extra)
108 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
110 NULL, NULL, 0, 0,
111 "Memory allocation failed : %s\n", extra);
112 else
113 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
115 NULL, NULL, 0, 0, "Memory allocation failed\n");
116}
@ extra
Definition: id3.c:95
@ XML_ERR_NO_MEMORY
Definition: xmlerror.h:102

Referenced by inputPush(), nameNsPush(), namePush(), nodePush(), nsPush(), spacePush(), xmlAddDefAttrs(), xmlAddSpecialAttr(), xmlAttrNormalizeSpace2(), xmlCharStrndup(), xmlCreateIOParserCtxt(), xmlCreateURLParserCtxt(), xmlCtxtGrowAttrs(), xmlDetectSAX2(), xmlEscapeFormatString(), xmlInitParserCtxt(), xmlNewInputStream(), xmlNewParserCtxt(), xmlNewStringInputStream(), xmlParseAttValueComplex(), xmlParseCDSect(), xmlParseComment(), xmlParseCommentComplex(), xmlParseConditionalSections(), 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 1192 of file parserInternals.c.

1192 {
1193 if (input == NULL) return;
1194
1195 if (input->filename != NULL) xmlFree((char *) input->filename);
1196 if (input->directory != NULL) xmlFree((char *) input->directory);
1197 if (input->encoding != NULL) xmlFree((char *) input->encoding);
1198 if (input->version != NULL) xmlFree((char *) input->version);
1199 if ((input->free != NULL) && (input->base != NULL))
1200 input->free((xmlChar *) input->base);
1201 if (input->buf != NULL)
1203 xmlFree(input);
1204}
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBFUN void XMLCALL xmlFreeParserInputBuffer(xmlParserInputBufferPtr in)

Referenced by xmlCtxtReset(), xmlFreeParserCtxt(), xmlHaltParser(), xmlInitParserCtxt(), xmlLoadEntityContent(), 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 1629 of file parserInternals.c.

1630{
1632
1633 if (ctxt == NULL) return;
1634
1635 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1637 }
1638 if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
1639 if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
1640 if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
1641 if (ctxt->nodeInfoTab != NULL) xmlFree(ctxt->nodeInfoTab);
1642 if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
1643 if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
1644 if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
1645 if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
1646 if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
1647#ifdef LIBXML_SAX1_ENABLED
1648 if ((ctxt->sax != NULL) &&
1650#else
1651 if (ctxt->sax != NULL)
1652#endif /* LIBXML_SAX1_ENABLED */
1653 xmlFree(ctxt->sax);
1654 if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
1655 if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
1656 if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
1657 if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
1658 if (ctxt->nsTab != NULL) xmlFree((char *) ctxt->nsTab);
1659 if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);
1660 if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);
1661 if (ctxt->attsDefault != NULL)
1663 if (ctxt->attsSpecial != NULL)
1665 if (ctxt->freeElems != NULL) {
1667
1668 cur = ctxt->freeElems;
1669 while (cur != NULL) {
1670 next = cur->next;
1671 xmlFree(cur);
1672 cur = next;
1673 }
1674 }
1675 if (ctxt->freeAttrs != NULL) {
1677
1678 cur = ctxt->freeAttrs;
1679 while (cur != NULL) {
1680 next = cur->next;
1681 xmlFree(cur);
1682 cur = next;
1683 }
1684 }
1685 /*
1686 * cleanup the error strings
1687 */
1688 if (ctxt->lastError.message != NULL)
1689 xmlFree(ctxt->lastError.message);
1690 if (ctxt->lastError.file != NULL)
1691 xmlFree(ctxt->lastError.file);
1692 if (ctxt->lastError.str1 != NULL)
1693 xmlFree(ctxt->lastError.str1);
1694 if (ctxt->lastError.str2 != NULL)
1695 xmlFree(ctxt->lastError.str2);
1696 if (ctxt->lastError.str3 != NULL)
1697 xmlFree(ctxt->lastError.str3);
1698
1699#ifdef LIBXML_CATALOG_ENABLED
1700 if (ctxt->catalogs != NULL)
1701 xmlCatalogFreeLocal(ctxt->catalogs);
1702#endif
1703 xmlFree(ctxt);
1704}
void xmlFreeInputStream(xmlParserInputPtr input)
XMLPUBFUN xmlParserInputPtr XMLCALL inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1774
static unsigned __int64 next
Definition: rand_nt.c:6
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:802
XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler
Definition: globals.h:312
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
Definition: hash.c:322
XMLPUBFUN void XMLCALL xmlHashDefaultDeallocator(void *entry, const xmlChar *name)
Definition: tree.h:434
char * file
Definition: xmlerror.h:83
char * str3
Definition: xmlerror.h:87
char * str1
Definition: xmlerror.h:85
char * str2
Definition: xmlerror.h:86
char * message
Definition: xmlerror.h:81
Definition: tree.h:489
xmlError lastError
Definition: parser.h:301
char * directory
Definition: parser.h:226
const xmlChar ** atts
Definition: parser.h:264
xmlValidCtxt vctxt
Definition: parser.h:221
xmlStartTag * pushTab
Definition: parser.h:283
xmlNodePtr * nodeTab
Definition: parser.h:208
xmlChar * extSubSystem
Definition: parser.h:241
struct _xmlSAXHandler * sax
Definition: parser.h:185
const xmlChar * encoding
Definition: parser.h:191
xmlDictPtr dict
Definition: parser.h:263
int * attallocs
Definition: parser.h:282
const xmlChar ** nsTab
Definition: parser.h:281
xmlHashTablePtr attsSpecial
Definition: parser.h:285
void * catalogs
Definition: parser.h:260
xmlChar * extSubURI
Definition: parser.h:240
const xmlChar * version
Definition: parser.h:190
xmlAttrPtr freeAttrs
Definition: parser.h:296
int * spaceTab
Definition: parser.h:247
xmlParserInputPtr * inputTab
Definition: parser.h:202
const xmlChar ** nameTab
Definition: parser.h:232
xmlHashTablePtr attsDefault
Definition: parser.h:284
xmlParserNodeInfo * nodeInfoTab
Definition: parser.h:310
xmlNodePtr freeElems
Definition: parser.h:294

Referenced by main(), parseAndPrintFile(), testSAX(), xmlCreateEntityParserCtxtInternal(), xmlCreateIOParserCtxt(), xmlCreateMemoryParserCtxt(), xmlCreateURLParserCtxt(), xmlDoRead(), xmlNewParserCtxt(), xmlParseBalancedChunkMemoryInternal(), 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 1788 of file parserInternals.c.

1789{
1790 if (seq == NULL)
1791 return;
1792 seq->length = 0;
1793 seq->maximum = 0;
1794 seq->buffer = NULL;
1795}
unsigned long length
Definition: parser.h:100
unsigned long maximum
Definition: parser.h:99

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 1444 of file parserInternals.c.

1445{
1447
1448 if(ctxt==NULL) {
1449 xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
1450 return(-1);
1451 }
1452
1453 xmlInitParser();
1454
1455 if (ctxt->dict == NULL)
1456 ctxt->dict = xmlDictCreate();
1457 if (ctxt->dict == NULL) {
1458 xmlErrMemory(NULL, "cannot initialize parser context\n");
1459 return(-1);
1460 }
1462
1463 if (ctxt->sax == NULL)
1464 ctxt->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
1465 if (ctxt->sax == NULL) {
1466 xmlErrMemory(NULL, "cannot initialize parser context\n");
1467 return(-1);
1468 }
1469 else
1470 xmlSAXVersion(ctxt->sax, 2);
1471
1472 ctxt->maxatts = 0;
1473 ctxt->atts = NULL;
1474 /* Allocate the Input stack */
1475 if (ctxt->inputTab == NULL) {
1476 ctxt->inputTab = (xmlParserInputPtr *)
1477 xmlMalloc(5 * sizeof(xmlParserInputPtr));
1478 ctxt->inputMax = 5;
1479 }
1480 if (ctxt->inputTab == NULL) {
1481 xmlErrMemory(NULL, "cannot initialize parser context\n");
1482 ctxt->inputNr = 0;
1483 ctxt->inputMax = 0;
1484 ctxt->input = NULL;
1485 return(-1);
1486 }
1487 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1489 }
1490 ctxt->inputNr = 0;
1491 ctxt->input = NULL;
1492
1493 ctxt->version = NULL;
1494 ctxt->encoding = NULL;
1495 ctxt->standalone = -1;
1496 ctxt->hasExternalSubset = 0;
1497 ctxt->hasPErefs = 0;
1498 ctxt->html = 0;
1499 ctxt->external = 0;
1500 ctxt->instate = XML_PARSER_START;
1501 ctxt->token = 0;
1502 ctxt->directory = NULL;
1503
1504 /* Allocate the Node stack */
1505 if (ctxt->nodeTab == NULL) {
1506 ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
1507 ctxt->nodeMax = 10;
1508 }
1509 if (ctxt->nodeTab == NULL) {
1510 xmlErrMemory(NULL, "cannot initialize parser context\n");
1511 ctxt->nodeNr = 0;
1512 ctxt->nodeMax = 0;
1513 ctxt->node = NULL;
1514 ctxt->inputNr = 0;
1515 ctxt->inputMax = 0;
1516 ctxt->input = NULL;
1517 return(-1);
1518 }
1519 ctxt->nodeNr = 0;
1520 ctxt->node = NULL;
1521
1522 /* Allocate the Name stack */
1523 if (ctxt->nameTab == NULL) {
1524 ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
1525 ctxt->nameMax = 10;
1526 }
1527 if (ctxt->nameTab == NULL) {
1528 xmlErrMemory(NULL, "cannot initialize parser context\n");
1529 ctxt->nodeNr = 0;
1530 ctxt->nodeMax = 0;
1531 ctxt->node = NULL;
1532 ctxt->inputNr = 0;
1533 ctxt->inputMax = 0;
1534 ctxt->input = NULL;
1535 ctxt->nameNr = 0;
1536 ctxt->nameMax = 0;
1537 ctxt->name = NULL;
1538 return(-1);
1539 }
1540 ctxt->nameNr = 0;
1541 ctxt->name = NULL;
1542
1543 /* Allocate the space stack */
1544 if (ctxt->spaceTab == NULL) {
1545 ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
1546 ctxt->spaceMax = 10;
1547 }
1548 if (ctxt->spaceTab == NULL) {
1549 xmlErrMemory(NULL, "cannot initialize parser context\n");
1550 ctxt->nodeNr = 0;
1551 ctxt->nodeMax = 0;
1552 ctxt->node = NULL;
1553 ctxt->inputNr = 0;
1554 ctxt->inputMax = 0;
1555 ctxt->input = NULL;
1556 ctxt->nameNr = 0;
1557 ctxt->nameMax = 0;
1558 ctxt->name = NULL;
1559 ctxt->spaceNr = 0;
1560 ctxt->spaceMax = 0;
1561 ctxt->space = NULL;
1562 return(-1);
1563 }
1564 ctxt->spaceNr = 1;
1565 ctxt->spaceMax = 10;
1566 ctxt->spaceTab[0] = -1;
1567 ctxt->space = &ctxt->spaceTab[0];
1568 ctxt->userData = ctxt;
1569 ctxt->myDoc = NULL;
1570 ctxt->wellFormed = 1;
1571 ctxt->nsWellFormed = 1;
1572 ctxt->valid = 1;
1574 if (ctxt->loadsubset) {
1575 ctxt->options |= XML_PARSE_DTDLOAD;
1576 }
1579 if (ctxt->pedantic) {
1580 ctxt->options |= XML_PARSE_PEDANTIC;
1581 }
1584 if (ctxt->keepBlanks == 0) {
1585 ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
1586 ctxt->options |= XML_PARSE_NOBLANKS;
1587 }
1588
1589 ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
1590 ctxt->vctxt.userData = ctxt;
1591 ctxt->vctxt.error = xmlParserValidityError;
1592 ctxt->vctxt.warning = xmlParserValidityWarning;
1593 if (ctxt->validate) {
1595 ctxt->vctxt.warning = NULL;
1596 else
1597 ctxt->vctxt.warning = xmlParserValidityWarning;
1598 ctxt->vctxt.nodeMax = 0;
1599 ctxt->options |= XML_PARSE_DTDVALID;
1600 }
1602 if (ctxt->replaceEntities) {
1603 ctxt->options |= XML_PARSE_NOENT;
1604 }
1605 ctxt->record_info = 0;
1606 ctxt->checkIndex = 0;
1607 ctxt->inSubset = 0;
1608 ctxt->errNo = XML_ERR_OK;
1609 ctxt->depth = 0;
1611 ctxt->catalogs = NULL;
1612 ctxt->nbentities = 0;
1613 ctxt->sizeentities = 0;
1614 ctxt->sizeentcopy = 0;
1615 ctxt->input_id = 1;
1617 return(0);
1618}
XMLPUBFUN void XMLCALL xmlSAX2IgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
XMLPUBFUN int XMLCALL xmlSAXVersion(xmlSAXHandler *hdlr, int version)
Definition: SAX2.c:2858
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
#define XML_MAX_DICTIONARY_LIMIT
XMLPUBFUN xmlDictPtr XMLCALL xmlDictCreate(void)
Definition: dict.c:577
XMLPUBFUN size_t XMLCALL xmlDictSetLimit(xmlDictPtr dict, size_t limit)
Definition: dict.c:1265
XMLPUBVAR int xmlSubstituteEntitiesDefaultValue
Definition: globals.h:458
XMLPUBVAR int xmlLineNumbersDefaultValue
Definition: globals.h:405
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248
XMLPUBVAR int xmlKeepBlanksDefaultValue
Definition: globals.h:396
XMLPUBVAR int xmlGetWarningsDefaultValue
Definition: globals.h:369
XMLPUBVAR int xmlLoadExtDtdDefaultValue
Definition: globals.h:414
XMLPUBVAR int xmlDoValidityCheckingDefaultValue
Definition: globals.h:328
XMLPUBVAR int xmlPedanticParserDefaultValue
Definition: globals.h:440
@ XML_PARSER_START
Definition: parser.h:112
@ XML_PARSE_DTDVALID
Definition: parser.h:1097
@ XML_PARSE_NOBLANKS
Definition: parser.h:1101
@ XML_PARSE_DTDLOAD
Definition: parser.h:1095
@ XML_PARSE_NOENT
Definition: parser.h:1094
@ XML_PARSE_PEDANTIC
Definition: parser.h:1100
int inputMax
Definition: parser.h:201
int nsWellFormed
Definition: parser.h:286
int replaceEntities
Definition: parser.h:189
int hasPErefs
Definition: parser.h:216
int keepBlanks
Definition: parser.h:236
int external
Definition: parser.h:217
int spaceMax
Definition: parser.h:246
int * space
Definition: parser.h:244
int loadsubset
Definition: parser.h:258
xmlDocPtr myDoc
Definition: parser.h:187
int hasExternalSubset
Definition: parser.h:215
long checkIndex
Definition: parser.h:235
int pedantic
Definition: parser.h:255
int input_id
Definition: parser.h:312
const xmlChar * name
Definition: parser.h:229
unsigned long sizeentities
Definition: parser.h:304
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
void * userData
Definition: parser.h:186
unsigned long nbentities
Definition: parser.h:303
int linenumbers
Definition: parser.h:259
xmlNodePtr node
Definition: parser.h:205
int validate
Definition: parser.h:220
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
@ XML_ERR_OK
Definition: xmlerror.h:100

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 213 of file parserInternals.c.

213 {
214 return(IS_BASECHAR(c) || IS_IDEOGRAPHIC(c));
215}
#define IS_IDEOGRAPHIC(c)
#define IS_BASECHAR(c)

◆ 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 2010 of file parserInternals.c.

2010 {
2011 int old = xmlKeepBlanksDefaultValue;
2012
2014 if (!val) xmlIndentTreeOutput = 1;
2015 return(old);
2016}
XMLPUBVAR int xmlIndentTreeOutput
Definition: globals.h:378

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 1956 of file parserInternals.c.

1956 {
1958
1960 return(old);
1961}

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 1283 of file parserInternals.c.

1283 {
1285
1286 if (entity == NULL) {
1287 xmlErrInternal(ctxt, "xmlNewEntityInputStream entity = NULL\n",
1288 NULL);
1289 return(NULL);
1290 }
1293 "new input from entity: %s\n", entity->name);
1294 if (entity->content == NULL) {
1295 switch (entity->etype) {
1297 xmlErrInternal(ctxt, "Cannot parse entity %s\n",
1298 entity->name);
1299 break;
1302 return(xmlLoadExternalEntity((char *) entity->URI,
1303 (char *) entity->ExternalID, ctxt));
1305 xmlErrInternal(ctxt,
1306 "Internal entity %s without content !\n",
1307 entity->name);
1308 break;
1310 xmlErrInternal(ctxt,
1311 "Internal parameter entity %s without content !\n",
1312 entity->name);
1313 break;
1315 xmlErrInternal(ctxt,
1316 "Predefined entity %s without content !\n",
1317 entity->name);
1318 break;
1319 }
1320 return(NULL);
1321 }
1322 input = xmlNewInputStream(ctxt);
1323 if (input == NULL) {
1324 return(NULL);
1325 }
1326 if (entity->URI != NULL)
1327 input->filename = (char *) xmlStrdup((xmlChar *) entity->URI);
1328 input->base = entity->content;
1329 if (entity->length == 0)
1330 entity->length = xmlStrlen(entity->content);
1331 input->cur = entity->content;
1332 input->length = entity->length;
1333 input->end = &entity->content[input->length];
1334 return(input);
1335}
@ XML_EXTERNAL_GENERAL_PARSED_ENTITY
Definition: entities.h:26
@ XML_INTERNAL_PREDEFINED_ENTITY
Definition: entities.h:30
@ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
Definition: entities.h:27
@ XML_INTERNAL_GENERAL_ENTITY
Definition: entities.h:25
@ XML_INTERNAL_PARAMETER_ENTITY
Definition: entities.h:28
@ XML_EXTERNAL_PARAMETER_ENTITY
Definition: entities.h:29
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:423
XMLPUBFUN xmlParserInputPtr XMLCALL xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
Definition: actctx.c:446
WCHAR * name
Definition: actctx.c:463
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426

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 1379 of file parserInternals.c.

1379 {
1381 xmlParserInputPtr inputStream;
1382 char *directory = NULL;
1383 xmlChar *URI = NULL;
1384
1387 "new input from file: %s\n", filename);
1388 if (ctxt == NULL) return(NULL);
1390 if (buf == NULL) {
1391 if (filename == NULL)
1392 __xmlLoaderErr(ctxt,
1393 "failed to load external entity: NULL filename \n",
1394 NULL);
1395 else
1396 __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
1397 (const char *) filename);
1398 return(NULL);
1399 }
1400
1401 inputStream = xmlNewInputStream(ctxt);
1402 if (inputStream == NULL) {
1404 return(NULL);
1405 }
1406
1407 inputStream->buf = buf;
1408 inputStream = xmlCheckHTTPInput(ctxt, inputStream);
1409 if (inputStream == NULL)
1410 return(NULL);
1411
1412 if (inputStream->filename == NULL)
1413 URI = xmlStrdup((xmlChar *) filename);
1414 else
1415 URI = xmlStrdup((xmlChar *) inputStream->filename);
1416 directory = xmlParserGetDirectory((const char *) URI);
1417 if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
1418 inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
1419 if (URI != NULL) xmlFree((char *) URI);
1420 inputStream->directory = directory;
1421
1422 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1423 if ((ctxt->directory == NULL) && (directory != NULL))
1424 ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
1425 return(inputStream);
1426}
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1094
@ XML_CHAR_ENCODING_NONE
Definition: encoding.h:58
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const char * filename
Definition: ioapi.h:137
void __xmlLoaderErr(void *ctx, const char *msg, const char *filename) LIBXML_ATTR_FORMAT(2
xmlBufPtr buffer
Definition: xmlIO.h:132
const char * filename
Definition: parser.h:56
xmlParserInputBufferPtr buf
Definition: parser.h:54
const char * directory
Definition: parser.h:57
XMLPUBFUN xmlChar *XMLCALL xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2380
XMLPUBFUN char *XMLCALL xmlParserGetDirectory(const char *filename)
XMLPUBFUN xmlParserInputPtr XMLCALL xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret)
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc)

◆ 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 1215 of file parserInternals.c.

1215 {
1217
1219 if (input == NULL) {
1220 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1221 return(NULL);
1222 }
1223 memset(input, 0, sizeof(xmlParserInput));
1224 input->line = 1;
1225 input->col = 1;
1226 input->standalone = -1;
1227
1228 /*
1229 * If the context is NULL the id cannot be initialized, but that
1230 * should not happen while parsing which is the situation where
1231 * the id is actually needed.
1232 */
1233 if (ctxt != NULL)
1234 input->id = ctxt->input_id++;
1235
1236 return(input);
1237}
xmlParserInput * xmlParserInputPtr
Definition: tree.h:36
#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 1251 of file parserInternals.c.

1252 {
1253 xmlParserInputPtr inputStream;
1254
1255 if (input == NULL) return(NULL);
1257 xmlGenericError(xmlGenericErrorContext, "new input from I/O\n");
1258 inputStream = xmlNewInputStream(ctxt);
1259 if (inputStream == NULL) {
1260 return(NULL);
1261 }
1262 inputStream->filename = NULL;
1263 inputStream->buf = input;
1264 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1265
1266 if (enc != XML_CHAR_ENCODING_NONE) {
1267 xmlSwitchEncoding(ctxt, enc);
1268 }
1269
1270 return(inputStream);
1271}
int xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)

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 1715 of file parserInternals.c.

1716{
1717 xmlParserCtxtPtr ctxt;
1718
1719 ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
1720 if (ctxt == NULL) {
1721 xmlErrMemory(NULL, "cannot allocate parser context\n");
1722 return(NULL);
1723 }
1724 memset(ctxt, 0, sizeof(xmlParserCtxt));
1725 if (xmlInitParserCtxt(ctxt) < 0) {
1726 xmlFreeParserCtxt(ctxt);
1727 return(NULL);
1728 }
1729 return(ctxt);
1730}
int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
xmlParserCtxt * xmlParserCtxtPtr
Definition: tree.h:39

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 1346 of file parserInternals.c.

1346 {
1348
1349 if (buffer == NULL) {
1350 xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
1351 NULL);
1352 return(NULL);
1353 }
1356 "new fixed input: %.30s\n", buffer);
1357 input = xmlNewInputStream(ctxt);
1358 if (input == NULL) {
1359 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1360 return(NULL);
1361 }
1362 input->base = buffer;
1363 input->cur = buffer;
1364 input->length = xmlStrlen(buffer);
1365 input->end = &buffer[input->length];
1366 return(input);
1367}

◆ xmlNextChar()

void xmlNextChar ( xmlParserCtxtPtr  ctxt)

xmlNextChar: @ctxt: the XML parser context

Skip to the next char input char.

Definition at line 380 of file parserInternals.c.

381{
382 if ((ctxt == NULL) || (ctxt->instate == XML_PARSER_EOF) ||
383 (ctxt->input == NULL))
384 return;
385
386 if (!(VALID_CTXT(ctxt))) {
387 xmlErrInternal(ctxt, "Parser input data memory error\n", NULL);
389 xmlStopParser(ctxt);
390 return;
391 }
392
393 if ((*ctxt->input->cur == 0) &&
394 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
395 return;
396 }
397
398 if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
399 const unsigned char *cur;
400 unsigned char c;
401
402 /*
403 * 2.11 End-of-Line Handling
404 * the literal two-character sequence "#xD#xA" or a standalone
405 * literal #xD, an XML processor must pass to the application
406 * the single character #xA.
407 */
408 if (*(ctxt->input->cur) == '\n') {
409 ctxt->input->line++; ctxt->input->col = 1;
410 } else
411 ctxt->input->col++;
412
413 /*
414 * We are supposed to handle UTF8, check it's valid
415 * From rfc2044: encoding of the Unicode values on UTF-8:
416 *
417 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
418 * 0000 0000-0000 007F 0xxxxxxx
419 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
420 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
421 *
422 * Check for the 0x110000 limit too
423 */
424 cur = ctxt->input->cur;
425
426 c = *cur;
427 if (c & 0x80) {
428 if (c == 0xC0)
429 goto encoding_error;
430 if (cur[1] == 0) {
432 cur = ctxt->input->cur;
433 }
434 if ((cur[1] & 0xc0) != 0x80)
435 goto encoding_error;
436 if ((c & 0xe0) == 0xe0) {
437 unsigned int val;
438
439 if (cur[2] == 0) {
441 cur = ctxt->input->cur;
442 }
443 if ((cur[2] & 0xc0) != 0x80)
444 goto encoding_error;
445 if ((c & 0xf0) == 0xf0) {
446 if (cur[3] == 0) {
448 cur = ctxt->input->cur;
449 }
450 if (((c & 0xf8) != 0xf0) ||
451 ((cur[3] & 0xc0) != 0x80))
452 goto encoding_error;
453 /* 4-byte code */
454 ctxt->input->cur += 4;
455 val = (cur[0] & 0x7) << 18;
456 val |= (cur[1] & 0x3f) << 12;
457 val |= (cur[2] & 0x3f) << 6;
458 val |= cur[3] & 0x3f;
459 } else {
460 /* 3-byte code */
461 ctxt->input->cur += 3;
462 val = (cur[0] & 0xf) << 12;
463 val |= (cur[1] & 0x3f) << 6;
464 val |= cur[2] & 0x3f;
465 }
466 if (((val > 0xd7ff) && (val < 0xe000)) ||
467 ((val > 0xfffd) && (val < 0x10000)) ||
468 (val >= 0x110000)) {
469 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
470 "Char 0x%X out of allowed range\n",
471 val);
472 }
473 } else
474 /* 2-byte code */
475 ctxt->input->cur += 2;
476 } else
477 /* 1-byte code */
478 ctxt->input->cur++;
479 } else {
480 /*
481 * Assume it's a fixed length encoding (1) with
482 * a compatible encoding for the ASCII set, since
483 * XML constructs only use < 128 chars
484 */
485
486 if (*(ctxt->input->cur) == '\n') {
487 ctxt->input->line++; ctxt->input->col = 1;
488 } else
489 ctxt->input->col++;
490 ctxt->input->cur++;
491 }
492 if (*ctxt->input->cur == 0)
494 return;
495encoding_error:
496 /*
497 * If we detect an UTF8 error that probably mean that the
498 * input encoding didn't get properly advertised in the
499 * declaration header. Report the error and switch the encoding
500 * to ISO-Latin-1 (if you don't like this policy, just declare the
501 * encoding !)
502 */
503 if ((ctxt == NULL) || (ctxt->input == NULL) ||
504 (ctxt->input->end - ctxt->input->cur < 4)) {
506 "Input is not proper UTF-8, indicate encoding !\n",
507 NULL, NULL);
508 } else {
509 char buffer[150];
510
511 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
512 ctxt->input->cur[0], ctxt->input->cur[1],
513 ctxt->input->cur[2], ctxt->input->cur[3]);
515 "Input is not proper UTF-8, indicate encoding !\n%s",
517 }
519 ctxt->input->cur++;
520 return;
521}
#define VALID_CTXT(ctxt)
XMLPUBFUN void XMLCALL xmlStopParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12583

◆ 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 1865 of file parserInternals.c.

1867{
1868 unsigned long pos;
1869
1870 if ((ctxt == NULL) || (info == NULL)) return;
1871
1872 /* Find pos and check to see if node is already in the sequence */
1874 info->node);
1875
1876 if ((pos < ctxt->node_seq.length) &&
1877 (ctxt->node_seq.buffer != NULL) &&
1878 (ctxt->node_seq.buffer[pos].node == info->node)) {
1879 ctxt->node_seq.buffer[pos] = *info;
1880 }
1881
1882 /* Otherwise, we need to add new node to buffer */
1883 else {
1884 if ((ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) ||
1885 (ctxt->node_seq.buffer == NULL)) {
1886 xmlParserNodeInfo *tmp_buffer;
1887 unsigned int byte_size;
1888
1889 if (ctxt->node_seq.maximum == 0)
1890 ctxt->node_seq.maximum = 2;
1891 byte_size = (sizeof(*ctxt->node_seq.buffer) *
1892 (2 * ctxt->node_seq.maximum));
1893
1894 if (ctxt->node_seq.buffer == NULL)
1895 tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
1896 else
1897 tmp_buffer =
1899 byte_size);
1900
1901 if (tmp_buffer == NULL) {
1902 xmlErrMemory(ctxt, "failed to allocate buffer\n");
1903 return;
1904 }
1905 ctxt->node_seq.buffer = tmp_buffer;
1906 ctxt->node_seq.maximum *= 2;
1907 }
1908
1909 /* If position is not at end, move elements out of the way */
1910 if (pos != ctxt->node_seq.length) {
1911 unsigned long i;
1912
1913 for (i = ctxt->node_seq.length; i > pos; i--)
1914 ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
1915 }
1916
1917 /* Copy element and increase length */
1918 ctxt->node_seq.buffer[pos] = *info;
1919 ctxt->node_seq.length++;
1920 }
1921}
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
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq, const xmlNodePtr node)
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250
const struct _xmlNode * node
Definition: parser.h:88

Referenced by xmlParseElementEnd(), xmlParseElementStart(), 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 1765 of file parserInternals.c.

1766{
1767 unsigned long pos;
1768
1769 if ((ctx == NULL) || (node == NULL))
1770 return (NULL);
1771 /* Find position where node should be at */
1772 pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node);
1773 if (pos < ctx->node_seq.length
1774 && ctx->node_seq.buffer[pos].node == node)
1775 return &ctx->node_seq.buffer[pos];
1776 else
1777 return NULL;
1778}
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 1826 of file parserInternals.c.

1828{
1829 unsigned long upper, lower, middle;
1830 int found = 0;
1831
1832 if ((seq == NULL) || (node == NULL))
1833 return ((unsigned long) -1);
1834
1835 /* Do a binary search for the key */
1836 lower = 1;
1837 upper = seq->length;
1838 middle = 0;
1839 while (lower <= upper && !found) {
1840 middle = lower + (upper - lower) / 2;
1841 if (node == seq->buffer[middle - 1].node)
1842 found = 1;
1843 else if (node < seq->buffer[middle - 1].node)
1844 upper = middle - 1;
1845 else
1846 lower = middle + 1;
1847 }
1848
1849 /* Return position */
1850 if (middle == 0 || seq->buffer[middle - 1].node < node)
1851 return middle;
1852 else
1853 return middle - 1;
1854}

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 284 of file parserInternals.c.

284 {
285 int ret;
286 size_t indx;
287
288 if ((in == NULL) || (len < 0)) return(-1);
289#ifdef DEBUG_INPUT
291#endif
292 if (in->buf == NULL) return(-1);
293 if (in->base == NULL) return(-1);
294 if (in->cur == NULL) return(-1);
295 if (in->buf->buffer == NULL) return(-1);
296
298
299 indx = in->cur - in->base;
300 if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) {
301
303
304 return(0);
305 }
306 if (in->buf->readcallback != NULL) {
308 } else
309 return(0);
310
311 in->base = xmlBufContent(in->buf->buffer);
312 in->cur = in->base + indx;
313 in->end = xmlBufEnd(in->buf->buffer);
314
316
317 return(ret);
318}
GLuint in
Definition: glext.h:9616
#define CHECK_BUFFER(in)
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:571
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:633
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:553
int ret
XMLPUBFUN int XMLCALL xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len)

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 268 of file parserInternals.c.

268 {
269 return(-1);
270}

◆ xmlParserInputShrink()

void xmlParserInputShrink ( xmlParserInputPtr  in)

xmlParserInputShrink: @in: an XML parser input

This function removes used input for the parser.

Definition at line 327 of file parserInternals.c.

327 {
328 size_t used;
329 size_t ret;
330
331#ifdef DEBUG_INPUT
333#endif
334 if (in == NULL) return;
335 if (in->buf == NULL) return;
336 if (in->base == NULL) return;
337 if (in->cur == NULL) return;
338 if (in->buf->buffer == NULL) return;
339
341
342 used = in->cur - in->base;
343 /*
344 * Do not shrink on large buffers whose only a tiny fraction
345 * was consumed
346 */
347 if (used > INPUT_CHUNK) {
348 ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
349 if (ret > 0) {
350 used -= ret;
351 in->consumed += ret;
352 }
353 }
354
355 if (xmlBufUse(in->buf->buffer) <= INPUT_CHUNK) {
357 }
358
359 in->base = xmlBufContent(in->buf->buffer);
360 in->cur = in->base + used;
361 in->end = xmlBufEnd(in->buf->buffer);
362
364}
static int used
Definition: adh-main.c:39
#define LINE_LEN
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:381
XMLPUBFUN int XMLCALL xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len)

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 1938 of file parserInternals.c.

1938 {
1940
1942 return(old);
1943}

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 700 of file parserInternals.c.

701{
702 if ((len == NULL) || (cur == NULL)) return(0);
703 if ((ctxt == NULL) || (ctxt->charset == XML_CHAR_ENCODING_UTF8)) {
704 /*
705 * We are supposed to handle UTF8, check it's valid
706 * From rfc2044: encoding of the Unicode values on UTF-8:
707 *
708 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
709 * 0000 0000-0000 007F 0xxxxxxx
710 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
711 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
712 *
713 * Check for the 0x110000 limit too
714 */
715 unsigned char c;
716 unsigned int val;
717
718 c = *cur;
719 if (c & 0x80) {
720 if ((cur[1] & 0xc0) != 0x80)
721 goto encoding_error;
722 if ((c & 0xe0) == 0xe0) {
723
724 if ((cur[2] & 0xc0) != 0x80)
725 goto encoding_error;
726 if ((c & 0xf0) == 0xf0) {
727 if (((c & 0xf8) != 0xf0) || ((cur[3] & 0xc0) != 0x80))
728 goto encoding_error;
729 /* 4-byte code */
730 *len = 4;
731 val = (cur[0] & 0x7) << 18;
732 val |= (cur[1] & 0x3f) << 12;
733 val |= (cur[2] & 0x3f) << 6;
734 val |= cur[3] & 0x3f;
735 } else {
736 /* 3-byte code */
737 *len = 3;
738 val = (cur[0] & 0xf) << 12;
739 val |= (cur[1] & 0x3f) << 6;
740 val |= cur[2] & 0x3f;
741 }
742 } else {
743 /* 2-byte code */
744 *len = 2;
745 val = (cur[0] & 0x1f) << 6;
746 val |= cur[1] & 0x3f;
747 }
748 if (!IS_CHAR(val)) {
749 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
750 "Char 0x%X out of allowed range\n", val);
751 }
752 return (val);
753 } else {
754 /* 1-byte code */
755 *len = 1;
756 return ((int) *cur);
757 }
758 }
759 /*
760 * Assume it's a fixed length encoding (1) with
761 * a compatible encoding for the ASCII set, since
762 * XML constructs only use < 128 chars
763 */
764 *len = 1;
765 return ((int) *cur);
766encoding_error:
767
768 /*
769 * An encoding problem may arise from a truncated input buffer
770 * splitting a character in the middle. In that case do not raise
771 * an error but return 0 to indicate an end of stream problem
772 */
773 if ((ctxt == NULL) || (ctxt->input == NULL) ||
774 (ctxt->input->end - ctxt->input->cur < 4)) {
775 *len = 0;
776 return(0);
777 }
778 /*
779 * If we detect an UTF8 error that probably mean that the
780 * input encoding didn't get properly advertised in the
781 * declaration header. Report the error and switch the encoding
782 * to ISO-Latin-1 (if you don't like this policy, just declare the
783 * encoding !)
784 */
785 {
786 char buffer[150];
787
788 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
789 ctxt->input->cur[0], ctxt->input->cur[1],
790 ctxt->input->cur[2], ctxt->input->cur[3]);
792 "Input is not proper UTF-8, indicate encoding !\n%s",
794 }
795 *len = 1;
796 return ((int) *cur);
797}

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 1978 of file parserInternals.c.

1978 {
1980
1982 return(old);
1983}

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 882 of file parserInternals.c.

883{
885 int len = -1;
886 int ret;
887
888 if (ctxt == NULL) return(-1);
889 switch (enc) {
892 "encoding unknown\n", NULL, NULL);
893 return(-1);
895 /* let's assume it's UTF-8 without the XML decl */
897 return(0);
899 /* default encoding, no conversion should be needed */
901
902 /*
903 * Errata on XML-1.0 June 20 2001
904 * Specific handling of the Byte Order Mark for
905 * UTF-8
906 */
907 if ((ctxt->input != NULL) &&
908 (ctxt->input->cur[0] == 0xEF) &&
909 (ctxt->input->cur[1] == 0xBB) &&
910 (ctxt->input->cur[2] == 0xBF)) {
911 ctxt->input->cur += 3;
912 }
913 return(0);
916 /*The raw input characters are encoded
917 *in UTF-16. As we expect this function
918 *to be called after xmlCharEncInFunc, we expect
919 *ctxt->input->cur to contain UTF-8 encoded characters.
920 *So the raw UTF16 Byte Order Mark
921 *has also been converted into
922 *an UTF-8 BOM. Let's skip that BOM.
923 */
924 if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) &&
925 (ctxt->input->cur[0] == 0xEF) &&
926 (ctxt->input->cur[1] == 0xBB) &&
927 (ctxt->input->cur[2] == 0xBF)) {
928 ctxt->input->cur += 3;
929 }
930 len = 90;
931 break;
933 len = 90;
934 break;
939 len = 180;
940 break;
955 len = 45;
956 break;
957 }
959 if (handler == NULL) {
960 /*
961 * Default handlers.
962 */
963 switch (enc) {
965 /* default encoding, no conversion should be needed */
967 return(0);
969 if ((ctxt->inputNr == 1) &&
970 (ctxt->encoding == NULL) &&
971 (ctxt->input != NULL) &&
972 (ctxt->input->encoding != NULL)) {
973 ctxt->encoding = xmlStrdup(ctxt->input->encoding);
974 }
975 ctxt->charset = enc;
976 return(0);
977 default:
979 "encoding not supported: %s\n",
981 /*
982 * TODO: We could recover from errors in external entities
983 * if we didn't stop the parser. But most callers of this
984 * function don't check the return value.
985 */
986 xmlStopParser(ctxt);
987 return(-1);
988 }
989 }
991 if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
992 /*
993 * on encoding conversion errors, stop the parser
994 */
995 xmlStopParser(ctxt);
997 }
998 return(ret);
999}
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL xmlGetCharEncodingHandler(xmlCharEncoding enc)
Definition: encoding.c:1544
@ XML_CHAR_ENCODING_8859_6
Definition: encoding.h:73
@ XML_CHAR_ENCODING_8859_7
Definition: encoding.h:74
@ XML_CHAR_ENCODING_8859_2
Definition: encoding.h:69
@ XML_CHAR_ENCODING_8859_4
Definition: encoding.h:71
@ XML_CHAR_ENCODING_8859_8
Definition: encoding.h:75
@ XML_CHAR_ENCODING_UTF16BE
Definition: encoding.h:61
@ XML_CHAR_ENCODING_UCS2
Definition: encoding.h:67
@ XML_CHAR_ENCODING_2022_JP
Definition: encoding.h:77
@ XML_CHAR_ENCODING_8859_3
Definition: encoding.h:70
@ XML_CHAR_ENCODING_EBCDIC
Definition: encoding.h:64
@ XML_CHAR_ENCODING_UCS4LE
Definition: encoding.h:62
@ XML_CHAR_ENCODING_ERROR
Definition: encoding.h:57
@ XML_CHAR_ENCODING_UCS4_3412
Definition: encoding.h:66
@ XML_CHAR_ENCODING_UCS4BE
Definition: encoding.h:63
@ XML_CHAR_ENCODING_8859_9
Definition: encoding.h:76
@ XML_CHAR_ENCODING_UTF16LE
Definition: encoding.h:60
@ XML_CHAR_ENCODING_8859_5
Definition: encoding.h:72
@ XML_CHAR_ENCODING_ASCII
Definition: encoding.h:80
@ XML_CHAR_ENCODING_SHIFT_JIS
Definition: encoding.h:78
@ XML_CHAR_ENCODING_UCS4_2143
Definition: encoding.h:65
@ XML_CHAR_ENCODING_EUC_JP
Definition: encoding.h:79
XMLPUBFUN const char *XMLCALL xmlGetCharEncodingName(xmlCharEncoding enc)
Definition: encoding.c:1254
static int xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler, int len)
const xmlChar * encoding
Definition: parser.h:71
@ XML_I18N_CONV_FAILED
Definition: xmlerror.h:833
@ XML_ERR_UNKNOWN_ENCODING
Definition: xmlerror.h:131
@ XML_ERR_UNSUPPORTED_ENCODING
Definition: xmlerror.h:132

Referenced by xmlCtxtResetPush(), xmlNewIOInputStream(), 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

DEPRECATED: Use xmlSwitchToEncoding

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

Returns 0 in case of success, -1 otherwise

Definition at line 1156 of file parserInternals.c.

1157 {
1158 return(xmlSwitchInputEncodingInt(ctxt, input, handler, -1));
1159}

◆ xmlSwitchInputEncodingInt()

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

xmlSwitchInputEncodingInt: @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 1014 of file parserInternals.c.

1016{
1017 int nbchars;
1018
1019 if (handler == NULL)
1020 return (-1);
1021 if (input == NULL)
1022 return (-1);
1023 if (input->buf != NULL) {
1025
1026 if (input->buf->encoder != NULL) {
1027 /*
1028 * Check in case the auto encoding detection triggered
1029 * in already.
1030 */
1031 if (input->buf->encoder == handler)
1032 return (0);
1033
1034 /*
1035 * "UTF-16" can be used for both LE and BE
1036 if ((!xmlStrncmp(BAD_CAST input->buf->encoder->name,
1037 BAD_CAST "UTF-16", 6)) &&
1038 (!xmlStrncmp(BAD_CAST handler->name,
1039 BAD_CAST "UTF-16", 6))) {
1040 return(0);
1041 }
1042 */
1043
1044 /*
1045 * Note: this is a bit dangerous, but that's what it
1046 * takes to use nearly compatible signature for different
1047 * encodings.
1048 *
1049 * FIXME: Encoders might buffer partial byte sequences, so
1050 * this probably can't work. We should return an error and
1051 * make sure that callers never try to switch the encoding
1052 * twice.
1053 */
1054 xmlCharEncCloseFunc(input->buf->encoder);
1055 input->buf->encoder = handler;
1056 return (0);
1057 }
1058 input->buf->encoder = handler;
1059
1060 /*
1061 * Is there already some content down the pipe to convert ?
1062 */
1063 if (xmlBufIsEmpty(input->buf->buffer) == 0) {
1064 int processed;
1065 unsigned int use;
1066
1067 /*
1068 * Specific handling of the Byte Order Mark for
1069 * UTF-16
1070 */
1071 if ((handler->name != NULL) &&
1072 (!strcmp(handler->name, "UTF-16LE") ||
1073 !strcmp(handler->name, "UTF-16")) &&
1074 (input->cur[0] == 0xFF) && (input->cur[1] == 0xFE)) {
1075 input->cur += 2;
1076 }
1077 if ((handler->name != NULL) &&
1078 (!strcmp(handler->name, "UTF-16BE")) &&
1079 (input->cur[0] == 0xFE) && (input->cur[1] == 0xFF)) {
1080 input->cur += 2;
1081 }
1082 /*
1083 * Errata on XML-1.0 June 20 2001
1084 * Specific handling of the Byte Order Mark for
1085 * UTF-8
1086 */
1087 if ((handler->name != NULL) &&
1088 (!strcmp(handler->name, "UTF-8")) &&
1089 (input->cur[0] == 0xEF) &&
1090 (input->cur[1] == 0xBB) && (input->cur[2] == 0xBF)) {
1091 input->cur += 3;
1092 }
1093
1094 /*
1095 * Shrink the current input buffer.
1096 * Move it as the raw buffer and create a new input buffer
1097 */
1098 processed = input->cur - input->base;
1099 xmlBufShrink(input->buf->buffer, processed);
1100 input->buf->raw = input->buf->buffer;
1101 input->buf->buffer = xmlBufCreate();
1102 input->buf->rawconsumed = processed;
1103 use = xmlBufUse(input->buf->raw);
1104
1105 if (ctxt->html) {
1106 /*
1107 * convert as much as possible of the buffer
1108 */
1109 nbchars = xmlCharEncInput(input->buf, 1);
1110 } else {
1111 /*
1112 * convert just enough to get
1113 * '<?xml version="1.0" encoding="xxx"?>'
1114 * parsed with the autodetected encoding
1115 * into the parser reading buffer.
1116 */
1117 nbchars = xmlCharEncFirstLineInput(input->buf, len);
1118 }
1119 xmlBufResetInput(input->buf->buffer, input);
1120 if (nbchars < 0) {
1121 xmlErrInternal(ctxt,
1122 "switching encoding: encoder error\n",
1123 NULL);
1124 return (-1);
1125 }
1126 input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
1127 }
1128 return (0);
1129 } else {
1130 xmlErrInternal(ctxt,
1131 "static memory buffer doesn't support encoding\n", NULL);
1132 /*
1133 * Callers assume that the input buffer takes ownership of the
1134 * encoding handler. xmlCharEncCloseFunc frees unregistered
1135 * handlers and avoids a memory leak.
1136 */
1138 return (-1);
1139 }
1140}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int xmlBufIsEmpty(const xmlBufPtr buf)
Definition: buf.c:673
xmlBufPtr xmlBufCreate(void)
Definition: buf.c:122
int xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
Definition: encoding.c:2181
int xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
Definition: encoding.c:2288
XMLPUBFUN int XMLCALL xmlCharEncCloseFunc(xmlCharEncodingHandler *handler)
Definition: encoding.c:2796
static int processed(const type_t *type)
Definition: typegen.c:2254

Referenced by xmlSwitchEncoding(), xmlSwitchInputEncoding(), and xmlSwitchToEncoding().

◆ 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 1172 of file parserInternals.c.

1173{
1174 if (ctxt == NULL)
1175 return(-1);
1176 return(xmlSwitchInputEncodingInt(ctxt, ctxt->input, handler, -1));
1177}

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