diff --git a/ChangeLog b/ChangeLog index 90fadfe0..2331fd77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,14 @@ +Sat May 29 13:34:42 CEST 1999 Daniel Veillard + + * tree.[ch]: unified the XML_NO_CORBA defines. + * parser.c encoding.[ch]: started plugging in char encoding detection + Fri May 28 22:58:42 EDT 1999 Manish Vachharajani * tree.c: (xmlSaveFile) - removed double call of xmlContentDump. Also freed allocated buffer. -Wed Apr 21 22:07:35 CEST 1999 - +Wed Apr 21 22:07:35 CEST 1999 Daniel Veillard * parser.[ch] tree.[ch] entities.[ch] valid.[ch] : removed the main reentrancy problem at printing. One is left in entities.c, to remove ASAP diff --git a/SAX.c b/SAX.c index 7f9ea18a..596f6682 100644 --- a/SAX.c +++ b/SAX.c @@ -26,8 +26,9 @@ * Returns a CHAR * */ const CHAR * -getPublicId(xmlParserCtxtPtr ctxt) +getPublicId(void *ctx) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ return(NULL); } @@ -41,8 +42,9 @@ getPublicId(xmlParserCtxtPtr ctxt) * Returns a CHAR * */ const CHAR * -getSystemId(xmlParserCtxtPtr ctxt) +getSystemId(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->input->filename); } @@ -55,8 +57,9 @@ getSystemId(xmlParserCtxtPtr ctxt) * Returns an int */ int -getLineNumber(xmlParserCtxtPtr ctxt) +getLineNumber(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->input->line); } @@ -69,8 +72,9 @@ getLineNumber(xmlParserCtxtPtr ctxt) * Returns an int */ int -getColumnNumber(xmlParserCtxtPtr ctxt) +getColumnNumber(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->input->col); } @@ -91,8 +95,9 @@ xmlSAXLocator xmlDefaultSAXLocator = { * Returns 1 if true */ int -isStandalone(xmlParserCtxtPtr ctxt) +isStandalone(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->myDoc->standalone == 1); } @@ -105,8 +110,9 @@ isStandalone(xmlParserCtxtPtr ctxt) * Returns 1 if true */ int -hasInternalSubset(xmlParserCtxtPtr ctxt) +hasInternalSubset(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->myDoc->intSubset != NULL); } @@ -119,8 +125,9 @@ hasInternalSubset(xmlParserCtxtPtr ctxt) * Returns 1 if true */ int -hasExternalSubset(xmlParserCtxtPtr ctxt) +hasExternalSubset(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; return(ctxt->myDoc->extSubset != NULL); } @@ -131,9 +138,10 @@ hasExternalSubset(xmlParserCtxtPtr ctxt) * Does this document has an internal subset */ void -internalSubset(xmlParserCtxtPtr ctxt, const CHAR *name, +internalSubset(void *ctx, const CHAR *name, const CHAR *ExternalID, const CHAR *SystemID) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.internalSubset(%s, %s, %s)\n", name, ExternalID, SystemID); @@ -156,8 +164,9 @@ internalSubset(xmlParserCtxtPtr ctxt, const CHAR *name, * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */ xmlParserInputPtr -resolveEntity(xmlParserCtxtPtr ctxt, const CHAR *publicId, const CHAR *systemId) +resolveEntity(void *ctx, const CHAR *publicId, const CHAR *systemId) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId); @@ -179,8 +188,9 @@ resolveEntity(xmlParserCtxtPtr ctxt, const CHAR *publicId, const CHAR *systemId) * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */ xmlEntityPtr -getEntity(xmlParserCtxtPtr ctxt, const CHAR *name) +getEntity(void *ctx, const CHAR *name) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlEntityPtr ret; #ifdef DEBUG_SAX @@ -204,9 +214,10 @@ getEntity(xmlParserCtxtPtr ctxt, const CHAR *name) * An entity definition has been parsed */ void -entityDecl(xmlParserCtxtPtr ctxt, const CHAR *name, int type, +entityDecl(void *ctx, const CHAR *name, int type, const CHAR *publicId, const CHAR *systemId, CHAR *content) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", @@ -227,10 +238,11 @@ entityDecl(xmlParserCtxtPtr ctxt, const CHAR *name, int type, * An attribute definition has been parsed */ void -attributeDecl(xmlParserCtxtPtr ctxt, const CHAR *elem, const CHAR *name, +attributeDecl(void *ctx, const CHAR *elem, const CHAR *name, int type, int def, const CHAR *defaultValue, xmlEnumerationPtr tree) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", @@ -252,9 +264,10 @@ attributeDecl(xmlParserCtxtPtr ctxt, const CHAR *elem, const CHAR *name, * An element definition has been parsed */ void -elementDecl(xmlParserCtxtPtr ctxt, const CHAR *name, int type, +elementDecl(void *ctx, const CHAR *name, int type, xmlElementContentPtr content) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.elementDecl(%s, %d, ...)\n", @@ -274,9 +287,10 @@ elementDecl(xmlParserCtxtPtr ctxt, const CHAR *name, int type, * TODO Not handled currently. */ void -notationDecl(xmlParserCtxtPtr ctxt, const CHAR *name, +notationDecl(void *ctx, const CHAR *name, const CHAR *publicId, const CHAR *systemId) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId); #endif @@ -295,10 +309,11 @@ notationDecl(xmlParserCtxtPtr ctxt, const CHAR *name, * TODO Create an Entity node. */ void -unparsedEntityDecl(xmlParserCtxtPtr ctxt, const CHAR *name, +unparsedEntityDecl(void *ctx, const CHAR *name, const CHAR *publicId, const CHAR *systemId, const CHAR *notationName) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", name, publicId, systemId, notationName); @@ -314,8 +329,9 @@ unparsedEntityDecl(xmlParserCtxtPtr ctxt, const CHAR *name, * Everything is available on the context, so this is useless in our case. */ void -setDocumentLocator(xmlParserCtxtPtr ctxt, xmlSAXLocatorPtr loc) +setDocumentLocator(void *ctx, xmlSAXLocatorPtr loc) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.setDocumentLocator()\n"); #endif @@ -328,8 +344,9 @@ setDocumentLocator(xmlParserCtxtPtr ctxt, xmlSAXLocatorPtr loc) * called when the document start being processed. */ void -startDocument(xmlParserCtxtPtr ctxt) +startDocument(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlDocPtr doc; #ifdef DEBUG_SAX @@ -352,8 +369,9 @@ startDocument(xmlParserCtxtPtr ctxt) * called when the document end has been detected. */ void -endDocument(xmlParserCtxtPtr ctxt) +endDocument(void *ctx) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.endDocument()\n"); #endif @@ -371,8 +389,9 @@ endDocument(xmlParserCtxtPtr ctxt) * the element. */ void -attribute(xmlParserCtxtPtr ctxt, const CHAR *fullname, const CHAR *value) +attribute(void *ctx, const CHAR *fullname, const CHAR *value) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlAttrPtr ret; CHAR *name; CHAR *ns; @@ -428,8 +447,9 @@ attribute(xmlParserCtxtPtr ctxt, const CHAR *fullname, const CHAR *value) * TODO We currently have a small pblm with the arguments ... */ void -startElement(xmlParserCtxtPtr ctxt, const CHAR *fullname, const CHAR **atts) +startElement(void *ctx, const CHAR *fullname, const CHAR **atts) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr ret; xmlNodePtr parent = ctxt->node; xmlNsPtr ns; @@ -515,8 +535,9 @@ startElement(xmlParserCtxtPtr ctxt, const CHAR *fullname, const CHAR **atts) * called when the end of an element has been detected. */ void -endElement(xmlParserCtxtPtr ctxt, const CHAR *name) +endElement(void *ctx, const CHAR *name) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserNodeInfo node_info; xmlNodePtr cur = ctxt->node; @@ -549,8 +570,9 @@ endElement(xmlParserCtxtPtr ctxt, const CHAR *name) * called when an entity reference is detected. */ void -reference(xmlParserCtxtPtr ctxt, const CHAR *name) +reference(void *ctx, const CHAR *name) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr ret; #ifdef DEBUG_SAX @@ -570,8 +592,9 @@ reference(xmlParserCtxtPtr ctxt, const CHAR *name) * Question: how much at a time ??? */ void -characters(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) +characters(void *ctx, const CHAR *ch, int len) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr lastChild; #ifdef DEBUG_SAX @@ -606,8 +629,9 @@ characters(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) * Question: how much at a time ??? */ void -ignorableWhitespace(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) +ignorableWhitespace(void *ctx, const CHAR *ch, int len) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.ignorableWhitespace(%.30s, %d)\n", ch, len); #endif @@ -623,9 +647,10 @@ ignorableWhitespace(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) * A processing instruction has been parsed. */ void -processingInstruction(xmlParserCtxtPtr ctxt, const CHAR *target, +processingInstruction(void *ctx, const CHAR *target, const CHAR *data) { + /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ #ifdef DEBUG_SAX fprintf(stderr, "SAX.processingInstruction(%s, %s)\n", target, data); #endif @@ -640,8 +665,9 @@ processingInstruction(xmlParserCtxtPtr ctxt, const CHAR *target, * An old global namespace has been parsed. */ void -globalNamespace(xmlParserCtxtPtr ctxt, const CHAR *href, const CHAR *prefix) +globalNamespace(void *ctx, const CHAR *href, const CHAR *prefix) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.globalNamespace(%s, %s)\n", href, prefix); #endif @@ -656,8 +682,9 @@ globalNamespace(xmlParserCtxtPtr ctxt, const CHAR *href, const CHAR *prefix) * Set the current element namespace. */ void -setNamespace(xmlParserCtxtPtr ctxt, const CHAR *name) +setNamespace(void *ctx, const CHAR *name) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNsPtr ns; xmlNodePtr parent; @@ -682,8 +709,9 @@ setNamespace(xmlParserCtxtPtr ctxt, const CHAR *name) * Get the current element namespace. */ xmlNsPtr -getNamespace(xmlParserCtxtPtr ctxt) +getNamespace(void *ctx) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNsPtr ret; #ifdef DEBUG_SAX @@ -702,8 +730,9 @@ getNamespace(xmlParserCtxtPtr ctxt) * one read upon parsing. */ int -checkNamespace(xmlParserCtxtPtr ctxt, CHAR *namespace) +checkNamespace(void *ctx, CHAR *namespace) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlNodePtr cur = ctxt->node; #ifdef DEBUG_SAX @@ -749,8 +778,9 @@ checkNamespace(xmlParserCtxtPtr ctxt, CHAR *namespace) * A namespace has been parsed. */ void -namespaceDecl(xmlParserCtxtPtr ctxt, const CHAR *href, const CHAR *prefix) +namespaceDecl(void *ctx, const CHAR *href, const CHAR *prefix) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX if (prefix == NULL) fprintf(stderr, "SAX.namespaceDecl(%s, NULL)\n", href); @@ -768,8 +798,9 @@ namespaceDecl(xmlParserCtxtPtr ctxt, const CHAR *href, const CHAR *prefix) * A comment has been parsed. */ void -comment(xmlParserCtxtPtr ctxt, const CHAR *value) +comment(void *ctx, const CHAR *value) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.comment(%s)\n", value); #endif diff --git a/encoding.c b/encoding.c index 0db110cf..a7e984e0 100644 --- a/encoding.c +++ b/encoding.c @@ -19,6 +19,7 @@ * Daniel.Veillard@w3.org */ +#include #include "encoding.h" /* @@ -204,3 +205,109 @@ UTF8ToUTF16(unsigned short* out, int outlen, unsigned char* in, int inlen) } +/** + * xmlDetectCharEncoding: + * @in: a pointer to the first bytes of the XML entity, must be at least + * 4 bytes long. + * + * Guess the encoding of the entity using the first bytes of the entity content + * accordingly of the non-normative appendix F of the XML-1.0 recommendation. + * + * Returns one of the XML_CHAR_ENCODING_... values. + */ +xmlCharEncoding +xmlDetectCharEncoding(unsigned char* in) +{ + if ((in[0] == 0x00) && (in[1] == 0x00) && + (in[2] == 0x00) && (in[3] == 0x3C)) + return(XML_CHAR_ENCODING_UCS4BE); + if ((in[0] == 0x3C) && (in[1] == 0x00) && + (in[2] == 0x00) && (in[3] == 0x00)) + return(XML_CHAR_ENCODING_UCS4LE); + if ((in[0] == 0x00) && (in[1] == 0x00) && + (in[2] == 0x3C) && (in[3] == 0x00)) + return(XML_CHAR_ENCODING_UCS4_2143); + if ((in[0] == 0x00) && (in[1] == 0x3C) && + (in[2] == 0x00) && (in[3] == 0x00)) + return(XML_CHAR_ENCODING_UCS4_3412); + if ((in[0] == 0xFE) && (in[1] == 0xFF)) + return(XML_CHAR_ENCODING_UTF16BE); + if ((in[0] == 0xFF) && (in[1] == 0xFE)) + return(XML_CHAR_ENCODING_UTF16LE); + if ((in[0] == 0x4C) && (in[1] == 0x6F) && + (in[2] == 0xA7) && (in[3] == 0x94)) + return(XML_CHAR_ENCODING_EBCDIC); + if ((in[0] == 0x3C) && (in[1] == 0x3F) && + (in[2] == 0x78) && (in[3] == 0x6D)) + return(XML_CHAR_ENCODING_UTF8); + return(XML_CHAR_ENCODING_NONE); +} + +/** + * xmlParseCharEncoding: + * @name: the encoding name as parsed, in UTF-8 format (ASCCI actually) + * + * Conpare the string to the known encoding schemes already known. Note + * that the comparison is case insensitive accordingly to the section + * [XML] 4.3.3 Character Encoding in Entities. + * + * Returns one of the XML_CHAR_ENCODING_... values or XML_CHAR_ENCODING_NONE + * if not recognized. + */ +xmlCharEncoding +xmlParseCharEncoding(char* name) +{ + char upper[500]; + int i; + + for (i = 0;i < 499;i++) { + upper[i] = toupper(name[i]); + if (upper[i] == 0) break; + } + upper[i] = 0; + + if (!strcmp(upper, "")) return(XML_CHAR_ENCODING_NONE); + if (!strcmp(upper, "UTF-8")) return(XML_CHAR_ENCODING_UTF8); + if (!strcmp(upper, "UTF8")) return(XML_CHAR_ENCODING_UTF8); + + /* + * NOTE: if we were able to parse this, the endianness of UTF16 is + * already found and in use + */ + if (!strcmp(upper, "UTF-16")) return(XML_CHAR_ENCODING_UTF16LE); + if (!strcmp(upper, "UTF16")) return(XML_CHAR_ENCODING_UTF16LE); + + if (!strcmp(upper, "ISO-10646-UCS-2")) return(XML_CHAR_ENCODING_UCS2); + if (!strcmp(upper, "UCS-2")) return(XML_CHAR_ENCODING_UCS2); + if (!strcmp(upper, "UCS2")) return(XML_CHAR_ENCODING_UCS2); + + /* + * NOTE: if we were able to parse this, the endianness of UCS4 is + * already found and in use + */ + if (!strcmp(upper, "ISO-10646-UCS-4")) return(XML_CHAR_ENCODING_UCS4LE); + if (!strcmp(upper, "UCS-4")) return(XML_CHAR_ENCODING_UCS4LE); + if (!strcmp(upper, "UCS4")) return(XML_CHAR_ENCODING_UCS4LE); + + + if (!strcmp(upper, "ISO-8859-1")) return(XML_CHAR_ENCODING_8859_1); + if (!strcmp(upper, "ISO-LATIN-1")) return(XML_CHAR_ENCODING_8859_1); + if (!strcmp(upper, "ISO LATIN 1")) return(XML_CHAR_ENCODING_8859_1); + + if (!strcmp(upper, "ISO-8859-2")) return(XML_CHAR_ENCODING_8859_2); + if (!strcmp(upper, "ISO-LATIN-2")) return(XML_CHAR_ENCODING_8859_2); + if (!strcmp(upper, "ISO LATIN 2")) return(XML_CHAR_ENCODING_8859_2); + + if (!strcmp(upper, "ISO-8859-3")) return(XML_CHAR_ENCODING_8859_3); + if (!strcmp(upper, "ISO-8859-4")) return(XML_CHAR_ENCODING_8859_4); + if (!strcmp(upper, "ISO-8859-5")) return(XML_CHAR_ENCODING_8859_5); + if (!strcmp(upper, "ISO-8859-6")) return(XML_CHAR_ENCODING_8859_6); + if (!strcmp(upper, "ISO-8859-7")) return(XML_CHAR_ENCODING_8859_7); + if (!strcmp(upper, "ISO-8859-8")) return(XML_CHAR_ENCODING_8859_8); + if (!strcmp(upper, "ISO-8859-9")) return(XML_CHAR_ENCODING_8859_9); + + if (!strcmp(upper, "ISO-2022-JP")) return(XML_CHAR_ENCODING_2022_JP); + if (!strcmp(upper, "Shift_JIS")) return(XML_CHAR_ENCODING_SHIFT_JIS); + if (!strcmp(upper, "EUC-JP")) return(XML_CHAR_ENCODING_EUC_JP); + return(XML_CHAR_ENCODING_ERROR); +} diff --git a/encoding.h b/encoding.h index b5a11f99..217edbca 100644 --- a/encoding.h +++ b/encoding.h @@ -13,22 +13,49 @@ * [US-ASCII] Coded Character Set--7-bit American Standard Code for * Information Interchange, ANSI X3.4-1986. * - * Original code from "Martin J. Duerst" - * * See Copyright for the status of this software. * * Daniel.Veillard@w3.org */ -#ifndef __XML_ENCODING_H__ -#define __XML_ENCODING_H__ +#ifndef __XML_CHAR_ENCODING_H__ +#define __XML_CHAR_ENCODING_H__ #ifdef __cplusplus extern "C" { #endif +typedef enum { + XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */ + XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */ + XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */ + XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */ + XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */ + XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */ + XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */ + XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */ + XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */ + XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */ + XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */ + XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */ + XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */ + XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */ + XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */ + XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */ + XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */ + XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */ + XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */ + XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */ + XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */ + XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */ + XML_CHAR_ENCODING_EUC_JP= 21,/* EUC-JP */ +} xmlCharEncoding; + +extern xmlCharEncoding xmlDetectCharEncoding(unsigned char* in); +extern xmlCharEncoding xmlParseCharEncoding(char* name); + #ifdef __cplusplus } #endif -#endif /* __XML_ENCODING_H__ */ +#endif /* __XML_CHAR_ENCODING_H__ */ diff --git a/error.c b/error.c index 3aaaca34..a9f0a0b3 100644 --- a/error.c +++ b/error.c @@ -20,8 +20,9 @@ * extra parameters. */ void -xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) +xmlParserError(void *ctx, const char *msg, ...) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; const CHAR *cur, *base; va_list args; int n; @@ -73,8 +74,9 @@ xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) * extra parameters. */ void -xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...) +xmlParserWarning(void *ctx, const char *msg, ...) { + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; const CHAR *cur, *base; va_list args; int n; diff --git a/include/libxml/encoding.h b/include/libxml/encoding.h index b5a11f99..217edbca 100644 --- a/include/libxml/encoding.h +++ b/include/libxml/encoding.h @@ -13,22 +13,49 @@ * [US-ASCII] Coded Character Set--7-bit American Standard Code for * Information Interchange, ANSI X3.4-1986. * - * Original code from "Martin J. Duerst" - * * See Copyright for the status of this software. * * Daniel.Veillard@w3.org */ -#ifndef __XML_ENCODING_H__ -#define __XML_ENCODING_H__ +#ifndef __XML_CHAR_ENCODING_H__ +#define __XML_CHAR_ENCODING_H__ #ifdef __cplusplus extern "C" { #endif +typedef enum { + XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */ + XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */ + XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */ + XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */ + XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */ + XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */ + XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */ + XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */ + XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */ + XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */ + XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */ + XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */ + XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */ + XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */ + XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */ + XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */ + XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */ + XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */ + XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */ + XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */ + XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */ + XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */ + XML_CHAR_ENCODING_EUC_JP= 21,/* EUC-JP */ +} xmlCharEncoding; + +extern xmlCharEncoding xmlDetectCharEncoding(unsigned char* in); +extern xmlCharEncoding xmlParseCharEncoding(char* name); + #ifdef __cplusplus } #endif -#endif /* __XML_ENCODING_H__ */ +#endif /* __XML_CHAR_ENCODING_H__ */ diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 3e433a26..20756076 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -81,10 +81,10 @@ typedef xmlParserCtxt *xmlParserCtxtPtr; */ typedef struct xmlSAXLocator { - const CHAR *(*getPublicId)(xmlParserCtxtPtr ctxt); - const CHAR *(*getSystemId)(xmlParserCtxtPtr ctxt); - int (*getLineNumber)(xmlParserCtxtPtr ctxt); - int (*getColumnNumber)(xmlParserCtxtPtr ctxt); + const CHAR *(*getPublicId)(void *ctx); + const CHAR *(*getSystemId)(void *ctx); + int (*getLineNumber)(void *ctx); + int (*getColumnNumber)(void *ctx); } _xmlSAXLocator; typedef _xmlSAXLocator xmlSAXLocator; typedef xmlSAXLocator *xmlSAXLocatorPtr; @@ -95,48 +95,48 @@ typedef xmlSAXLocator *xmlSAXLocatorPtr; #include "entities.h" -typedef xmlParserInputPtr (*resolveEntitySAXFunc) (xmlParserCtxtPtr ctxt, +typedef xmlParserInputPtr (*resolveEntitySAXFunc) (void *ctx, const CHAR *publicId, const CHAR *systemId); -typedef void (*internalSubsetSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name, +typedef void (*internalSubsetSAXFunc) (void *ctx, const CHAR *name, const CHAR *ExternalID, const CHAR *SystemID); -typedef xmlEntityPtr (*getEntitySAXFunc) (xmlParserCtxtPtr ctxt, +typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx, const CHAR *name); -typedef void (*entityDeclSAXFunc) (xmlParserCtxtPtr ctxt, +typedef void (*entityDeclSAXFunc) (void *ctx, const CHAR *name, int type, const CHAR *publicId, const CHAR *systemId, CHAR *content); -typedef void (*notationDeclSAXFunc)(xmlParserCtxtPtr ctxt, const CHAR *name, +typedef void (*notationDeclSAXFunc)(void *ctx, const CHAR *name, const CHAR *publicId, const CHAR *systemId); -typedef void (*attributeDeclSAXFunc)(xmlParserCtxtPtr ctxt, const CHAR *elem, +typedef void (*attributeDeclSAXFunc)(void *ctx, const CHAR *elem, const CHAR *name, int type, int def, const CHAR *defaultValue, xmlEnumerationPtr tree); -typedef void (*elementDeclSAXFunc)(xmlParserCtxtPtr ctxt, const CHAR *name, +typedef void (*elementDeclSAXFunc)(void *ctx, const CHAR *name, int type, xmlElementContentPtr content); -typedef void (*unparsedEntityDeclSAXFunc)(xmlParserCtxtPtr ctxt, +typedef void (*unparsedEntityDeclSAXFunc)(void *ctx, const CHAR *name, const CHAR *publicId, const CHAR *systemId, const CHAR *notationName); -typedef void (*setDocumentLocatorSAXFunc) (xmlParserCtxtPtr ctxt, +typedef void (*setDocumentLocatorSAXFunc) (void *ctx, xmlSAXLocatorPtr loc); -typedef void (*startDocumentSAXFunc) (xmlParserCtxtPtr ctxt); -typedef void (*endDocumentSAXFunc) (xmlParserCtxtPtr ctxt); -typedef void (*startElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name, +typedef void (*startDocumentSAXFunc) (void *ctx); +typedef void (*endDocumentSAXFunc) (void *ctx); +typedef void (*startElementSAXFunc) (void *ctx, const CHAR *name, const CHAR **atts); -typedef void (*endElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name); -typedef void (*attributeSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name, +typedef void (*endElementSAXFunc) (void *ctx, const CHAR *name); +typedef void (*attributeSAXFunc) (void *ctx, const CHAR *name, const CHAR *value); -typedef void (*referenceSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name); -typedef void (*charactersSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *ch, +typedef void (*referenceSAXFunc) (void *ctx, const CHAR *name); +typedef void (*charactersSAXFunc) (void *ctx, const CHAR *ch, int len); -typedef void (*ignorableWhitespaceSAXFunc) (xmlParserCtxtPtr ctxt, +typedef void (*ignorableWhitespaceSAXFunc) (void *ctx, const CHAR *ch, int len); -typedef void (*processingInstructionSAXFunc) (xmlParserCtxtPtr ctxt, +typedef void (*processingInstructionSAXFunc) (void *ctx, const CHAR *target, const CHAR *data); -typedef void (*commentSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *value); -typedef void (*warningSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...); -typedef void (*errorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...); -typedef void (*fatalErrorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...); -typedef int (*isStandaloneSAXFunc) (xmlParserCtxtPtr ctxt); -typedef int (*hasInternalSubsetSAXFunc) (xmlParserCtxtPtr ctxt); -typedef int (*hasExternalSubsetSAXFunc) (xmlParserCtxtPtr ctxt); +typedef void (*commentSAXFunc) (void *ctx, const CHAR *value); +typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...); +typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...); +typedef void (*fatalErrorSAXFunc) (void *ctx, const char *msg, ...); +typedef int (*isStandaloneSAXFunc) (void *ctx); +typedef int (*hasInternalSubsetSAXFunc) (void *ctx); +typedef int (*hasExternalSubsetSAXFunc) (void *ctx); typedef struct xmlSAXHandler { internalSubsetSAXFunc internalSubset; diff --git a/parser.c b/parser.c index 0e4eafc8..d934f824 100644 --- a/parser.c +++ b/parser.c @@ -30,6 +30,7 @@ #include "tree.h" #include "parser.h" #include "entities.h" +#include "encoding.h" #include "valid.h" #include "parserInternals.h" @@ -181,20 +182,20 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { if (entity == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "internal: xmlNewEntityInputStream entity = NULL\n"); return(NULL); } if (entity->content == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "internal: xmlNewEntityInputStream entity->input = NULL\n"); return(NULL); } input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); if (input == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "malloc: couldn't allocate a new input stream\n"); + ctxt->sax->error(ctxt->userData, "malloc: couldn't allocate a new input stream\n"); return(NULL); } input->filename = entity->SystemID; /* TODO !!! char <- CHAR */ @@ -220,14 +221,14 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, CHAR *string) { if (string == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "internal: xmlNewStringInputStream string = NULL\n"); return(NULL); } input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); if (input == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "malloc: couldn't allocate a new input stream\n"); + ctxt->sax->error(ctxt->userData, "malloc: couldn't allocate a new input stream\n"); return(NULL); } input->filename = NULL; @@ -240,6 +241,139 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, CHAR *string) { } +/************************************************************************ + * * + * Commodity functions to handle encodings * + * * + ************************************************************************/ + +/** + * xmlSwitchEncoding: + * @ctxt: the parser context + * @len: the len of @cur + * + * change the input functions when discovering the character encoding + * of a given entity. + * + */ +void +xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) +{ + switch (enc) { + case XML_CHAR_ENCODING_ERROR: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "encoding unknown\n"); + ctxt->wellFormed = 0; + break; + case XML_CHAR_ENCODING_NONE: + /* let's assume it's UTF-8 without the XML decl */ + return; + case XML_CHAR_ENCODING_UTF8: + /* default encoding, no conversion should be needed */ + return; + case XML_CHAR_ENCODING_UTF16LE: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding UTF16 little endian not supported\n"); + break; + case XML_CHAR_ENCODING_UTF16BE: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding UTF16 big endian not supported\n"); + break; + case XML_CHAR_ENCODING_UCS4LE: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding USC4 little endian not supported\n"); + break; + case XML_CHAR_ENCODING_UCS4BE: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding USC4 big endian not supported\n"); + break; + case XML_CHAR_ENCODING_EBCDIC: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding EBCDIC not supported\n"); + break; + case XML_CHAR_ENCODING_UCS4_2143: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding UCS4 2143 not supported\n"); + break; + case XML_CHAR_ENCODING_UCS4_3412: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding UCS4 3412 not supported\n"); + break; + case XML_CHAR_ENCODING_UCS2: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding UCS2 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_1: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_1 ISO Latin 1 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_2: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_2 ISO Latin 2 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_3: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_3 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_4: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_4 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_5: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_5 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_6: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_6 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_7: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_7 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_8: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_8 not supported\n"); + break; + case XML_CHAR_ENCODING_8859_9: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO_8859_9 not supported\n"); + break; + case XML_CHAR_ENCODING_2022_JP: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding ISO-2022-JPnot supported\n"); + break; + case XML_CHAR_ENCODING_SHIFT_JIS: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding Shift_JISnot supported\n"); + break; + case XML_CHAR_ENCODING_EUC_JP: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "char encoding EUC-JPnot supported\n"); + break; + } +} + /************************************************************************ * * * Commodity functions to handle CHARs * @@ -522,7 +656,7 @@ xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { if (entity->content == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "xmlHandleEntity %s: content == NULL\n", + ctxt->sax->error(ctxt->userData, "xmlHandleEntity %s: content == NULL\n", entity->name); ctxt->wellFormed = 0; return; @@ -542,7 +676,7 @@ handle_as_char: * Just handle the content as a set of chars. */ if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) - ctxt->sax->characters(ctxt, entity->content, len); + ctxt->sax->characters(ctxt->userData, entity->content, len); } @@ -728,7 +862,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { while (IS_CHAR(CUR) && (CUR != '"')) NEXT; if (CUR != '"') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "String not closed \"%.50s\"\n", q); + ctxt->sax->error(ctxt->userData, "String not closed \"%.50s\"\n", q); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -740,7 +874,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { while (IS_CHAR(CUR) && (CUR != '\'')) NEXT; if (CUR != '\'') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "String not closed \"%.50s\"\n", q); + ctxt->sax->error(ctxt->userData, "String not closed \"%.50s\"\n", q); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -833,7 +967,7 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt) { */ if (!garbage) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "xmlParseNamespace found garbage\n"); + ctxt->sax->error(ctxt->userData, "xmlParseNamespace found garbage\n"); ctxt->wellFormed = 0; NEXT; } @@ -846,7 +980,7 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt) { * Register the DTD. if (href != NULL) if ((ctxt->sax != NULL) && (ctxt->sax->globalNamespace != NULL)) - ctxt->sax->globalNamespace(ctxt, href, prefix); + ctxt->sax->globalNamespace(ctxt->userData, href, prefix); */ if (prefix != NULL) free(prefix); @@ -975,7 +1109,7 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt) { } if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished EntityValue\n"); + ctxt->sax->error(ctxt->userData, "Unfinished EntityValue\n"); ctxt->wellFormed = 0; } else { ret = xmlStrncat(ret, q, CUR_PTR - q); @@ -1009,7 +1143,7 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt) { } if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished EntityValue\n"); + ctxt->sax->error(ctxt->userData, "Unfinished EntityValue\n"); ctxt->wellFormed = 0; } else { ret = xmlStrncat(ret, q, CUR_PTR - q); @@ -1017,7 +1151,7 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt) { } } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "xmlParseEntityValue \" or ' expected\n"); + ctxt->sax->error(ctxt->userData, "xmlParseEntityValue \" or ' expected\n"); ctxt->wellFormed = 0; } @@ -1048,7 +1182,7 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { while ((IS_CHAR(CUR)) && (CUR != '"')) { if (CUR == '<') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Unescaped '<' not allowed in attributes values\n"); ctxt->wellFormed = 0; } @@ -1083,7 +1217,7 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished AttValue\n"); + ctxt->sax->error(ctxt->userData, "Unfinished AttValue\n"); ctxt->wellFormed = 0; } else { ret = xmlStrncat(ret, q, CUR_PTR - q); @@ -1095,7 +1229,7 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { while ((IS_CHAR(CUR)) && (CUR != '\'')) { if (CUR == '<') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Unescaped '<' not allowed in attributes values\n"); ctxt->wellFormed = 0; } @@ -1130,7 +1264,7 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished AttValue\n"); + ctxt->sax->error(ctxt->userData, "Unfinished AttValue\n"); ctxt->wellFormed = 0; } else { ret = xmlStrncat(ret, q, CUR_PTR - q); @@ -1138,7 +1272,7 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "AttValue: \" or ' expected\n"); + ctxt->sax->error(ctxt->userData, "AttValue: \" or ' expected\n"); ctxt->wellFormed = 0; } @@ -1168,7 +1302,7 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { NEXT; if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished SystemLiteral\n"); + ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n"); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -1181,7 +1315,7 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { NEXT; if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished SystemLiteral\n"); + ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n"); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -1189,7 +1323,7 @@ xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { } } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "SystemLiteral \" or ' expected\n"); + ctxt->sax->error(ctxt->userData, "SystemLiteral \" or ' expected\n"); ctxt->wellFormed = 0; } @@ -1220,7 +1354,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { while (IS_PUBIDCHAR(CUR)) NEXT; if (CUR != '"') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished PubidLiteral\n"); + ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n"); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -1233,7 +1367,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { NEXT; if (!IS_LETTER(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Unfinished PubidLiteral\n"); + ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n"); ctxt->wellFormed = 0; } else { ret = xmlStrndup(q, CUR_PTR - q); @@ -1241,7 +1375,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { } } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "SystemLiteral \" or ' expected\n"); + ctxt->sax->error(ctxt->userData, "SystemLiteral \" or ' expected\n"); ctxt->wellFormed = 0; } @@ -1271,7 +1405,7 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { if (cdata) break; else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Sequence ']]>' not allowed in content\n"); ctxt->wellFormed = 0; } @@ -1286,10 +1420,10 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { if (ctxt->sax != NULL) { if (areBlanks(ctxt, q, CUR_PTR - q)) { if (ctxt->sax->ignorableWhitespace != NULL) - ctxt->sax->ignorableWhitespace(ctxt, q, CUR_PTR - q); + ctxt->sax->ignorableWhitespace(ctxt->userData, q, CUR_PTR - q); } else { if (ctxt->sax->characters != NULL) - ctxt->sax->characters(ctxt, q, CUR_PTR - q); + ctxt->sax->characters(ctxt->userData, q, CUR_PTR - q); } } } @@ -1326,7 +1460,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { SKIP(6); if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Space required after 'SYSTEM'\n"); ctxt->wellFormed = 0; } @@ -1334,7 +1468,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { URI = xmlParseSystemLiteral(ctxt); if (URI == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "xmlParseExternalID: SYSTEM, no URI\n"); ctxt->wellFormed = 0; } @@ -1344,7 +1478,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { SKIP(6); if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Space required after 'PUBLIC'\n"); ctxt->wellFormed = 0; } @@ -1352,7 +1486,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { *publicID = xmlParsePubidLiteral(ctxt); if (*publicID == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "xmlParseExternalID: PUBLIC, no Public Identifier\n"); ctxt->wellFormed = 0; } @@ -1362,7 +1496,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { */ if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Space required after the Public Identifier\n"); ctxt->wellFormed = 0; } @@ -1382,7 +1516,7 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) { URI = xmlParseSystemLiteral(ctxt); if (URI == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "xmlParseExternalID: PUBLIC, no URI\n"); ctxt->wellFormed = 0; } @@ -1424,7 +1558,7 @@ xmlParseComment(xmlParserCtxtPtr ctxt, int create) { (*r != '-') || (*q != '-'))) { if ((*r == '-') && (*q == '-')) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, + ctxt->sax->error(ctxt->userData, "Comment must not contain '--' (double-hyphen)`\n"); ctxt->wellFormed = 0; } @@ -1432,14 +1566,14 @@ xmlParseComment(xmlParserCtxtPtr ctxt, int create) { } if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt, "Comment not terminated \n