diff --git a/ChangeLog b/ChangeLog index 56b1d6f9..8e919ead 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 24 14:43:34 CEST 2005 Daniel Veillard + + * encoding.c error.c include/libxml/xmlerror.h: finally converted + the encoding module to the common error reporting mechanism + * doc/* doc/html/libxml-xmlerror.html: rebuilt + Wed Aug 24 11:35:26 CEST 2005 Daniel Veillard * xpath.c: removed a potentially uninitialized variable error diff --git a/doc/APIfiles.html b/doc/APIfiles.html index ddf17443..b17f3205 100644 --- a/doc/APIfiles.html +++ b/doc/APIfiles.html @@ -1924,6 +1924,7 @@ A:link, A:visited, A:active { text-decoration: underline } XML_FROM_FTP
XML_FROM_HTML
XML_FROM_HTTP
+XML_FROM_I18N
XML_FROM_IO
XML_FROM_MEMORY
XML_FROM_MODULE
@@ -1952,6 +1953,11 @@ A:link, A:visited, A:active { text-decoration: underline } XML_HTTP_UNKNOWN_HOST
XML_HTTP_URL_SYNTAX
XML_HTTP_USE_IP
+XML_I18N_CONV_FAILED
+XML_I18N_EXCESS_HANDLER
+XML_I18N_NO_HANDLER
+XML_I18N_NO_NAME
+XML_I18N_NO_OUTPUT
XML_IO_BUFFER_FULL
XML_IO_EACCES
XML_IO_EADDRINUSE
diff --git a/doc/APIsymbols.html b/doc/APIsymbols.html index 20915917..820b6f06 100644 --- a/doc/APIsymbols.html +++ b/doc/APIsymbols.html @@ -420,6 +420,7 @@ A:link, A:visited, A:active { text-decoration: underline } XML_FROM_FTP
XML_FROM_HTML
XML_FROM_HTTP
+XML_FROM_I18N
XML_FROM_IO
XML_FROM_MEMORY
XML_FROM_MODULE
@@ -451,6 +452,11 @@ A:link, A:visited, A:active { text-decoration: underline } XML_HTTP_UNKNOWN_HOST
XML_HTTP_URL_SYNTAX
XML_HTTP_USE_IP
+XML_I18N_CONV_FAILED
+XML_I18N_EXCESS_HANDLER
+XML_I18N_NO_HANDLER
+XML_I18N_NO_NAME
+XML_I18N_NO_OUTPUT
XML_INTERNAL_GENERAL_ENTITY
XML_INTERNAL_PARAMETER_ENTITY
XML_INTERNAL_PREDEFINED_ENTITY
diff --git a/doc/html/libxml-xmlerror.html b/doc/html/libxml-xmlerror.html index b8333767..fe92d03f 100644 --- a/doc/html/libxml-xmlerror.html +++ b/doc/html/libxml-xmlerror.html @@ -79,6 +79,7 @@ void xmlStructuredErrorFunc (void * userD XML_FROM_CHECK = 24 : The error checking module XML_FROM_WRITER = 25 : The xmlwriter module XML_FROM_MODULE = 26 : The dynamically loaded module modul + XML_FROM_I18N = 27 : The module handling character conversion }

Enum xmlErrorLevel

Enum xmlErrorLevel {
     XML_ERR_NONE = 0
@@ -795,8 +796,13 @@ void	xmlStructuredErrorFunc		(void * userD
     XML_CHECK_OUTSIDE_DICT = 5035 : 5035
     XML_CHECK_WRONG_NAME = 5036 : 5036
     XML_CHECK_NAME_NOT_NULL = 5037 : 5037
-    XML_CHECK_ = 5038 : 5033
-    XML_CHECK_X = 5039 : 503
+    XML_I18N_NO_NAME = 6000
+    XML_I18N_NO_HANDLER = 6001 : 6001
+    XML_I18N_EXCESS_HANDLER = 6002 : 6002
+    XML_I18N_CONV_FAILED = 6003 : 6003
+    XML_I18N_NO_OUTPUT = 6004 : 6004
+    XML_CHECK_ = 6005 : 5033
+    XML_CHECK_X = 6006 : 503
 }
 

Function: initGenericErrorDefaultFunc

void	initGenericErrorDefaultFunc	(xmlGenericErrorFunc * handler)

Set or reset (if NULL) the default handler for generic errors to the builtin error function.

diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index 27947b9e..9a48431c 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -1945,6 +1945,7 @@ + @@ -2065,7 +2066,7 @@ - + @@ -2107,6 +2108,7 @@ + @@ -2145,7 +2147,7 @@ - + @@ -2184,6 +2186,7 @@ + @@ -2191,6 +2194,7 @@ + @@ -2352,7 +2356,7 @@ - + @@ -2379,6 +2383,7 @@ + @@ -2431,6 +2436,7 @@ + @@ -2551,7 +2557,7 @@ - + @@ -4517,7 +4523,7 @@ - + @@ -4556,7 +4562,7 @@ - + @@ -4742,9 +4748,10 @@ + - + @@ -4771,6 +4778,11 @@ + + + + + diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml index 1d9a86f4..098744f4 100644 --- a/doc/libxml2-refs.xml +++ b/doc/libxml2-refs.xml @@ -414,6 +414,7 @@ + @@ -445,6 +446,11 @@ + + + + + @@ -3845,6 +3851,7 @@ + @@ -3876,6 +3883,11 @@ + + + + + @@ -12262,6 +12274,7 @@ + @@ -12290,6 +12303,11 @@ + + + + + diff --git a/encoding.c b/encoding.c index 3f5d8b49..369c4fb7 100644 --- a/encoding.c +++ b/encoding.c @@ -70,6 +70,32 @@ static void xmlRegisterCharEncodingHandlersISO8859x (void); static int xmlLittleEndian = 1; +/** + * xmlEncodingErrMemory: + * @extra: extra informations + * + * Handle an out of memory condition + */ +static void +xmlEncodingErrMemory(const char *extra) +{ + __xmlSimpleError(XML_FROM_I18N, XML_ERR_NO_MEMORY, NULL, NULL, extra); +} + +/** + * xmlErrEncoding: + * @error: the error number + * @msg: the error message + * + * n encoding error + */ +static void +xmlEncodingErr(xmlParserErrors error, const char *msg, const char *val) +{ + __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, + XML_FROM_I18N, error, XML_ERR_FATAL, + NULL, 0, val, NULL, NULL, 0, 0, msg, val); +} /************************************************************************ * * @@ -1252,8 +1278,8 @@ xmlNewCharEncodingHandler(const char *name, * Keep only the uppercase version of the encoding. */ if (name == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : no name !\n"); + xmlEncodingErr(XML_I18N_NO_NAME, + "xmlNewCharEncodingHandler : no name !\n", NULL); return(NULL); } for (i = 0;i < 499;i++) { @@ -1263,8 +1289,7 @@ xmlNewCharEncodingHandler(const char *name, upper[i] = 0; up = xmlMemStrdup(upper); if (up == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : out of memory !\n"); + xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n"); return(NULL); } @@ -1275,8 +1300,7 @@ xmlNewCharEncodingHandler(const char *name, xmlMalloc(sizeof(xmlCharEncodingHandler)); if (handler == NULL) { xmlFree(up); - xmlGenericError(xmlGenericErrorContext, - "xmlNewCharEncodingHandler : out of memory !\n"); + xmlEncodingErrMemory("xmlNewCharEncodingHandler : out of memory !\n"); return(NULL); } handler->input = input; @@ -1319,12 +1343,13 @@ xmlInitCharEncodingHandlers(void) { if (*ptr == 0x12) xmlLittleEndian = 0; else if (*ptr == 0x34) xmlLittleEndian = 1; - else xmlGenericError(xmlGenericErrorContext, - "Odd problem at endianness detection\n"); + else { + xmlEncodingErr(XML_ERR_INTERNAL_ERROR, + "Odd problem at endianness detection\n", NULL); + } if (handlers == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlInitCharEncodingHandlers : out of memory !\n"); + xmlEncodingErrMemory("xmlInitCharEncodingHandlers : out of memory !\n"); return; } xmlNewCharEncodingHandler("UTF-8", UTF8ToUTF8, UTF8ToUTF8); @@ -1394,16 +1419,15 @@ void xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) { if (handlers == NULL) xmlInitCharEncodingHandlers(); if (handler == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlRegisterCharEncodingHandler: NULL handler !\n"); + xmlEncodingErr(XML_I18N_NO_HANDLER, + "xmlRegisterCharEncodingHandler: NULL handler !\n", NULL); return; } if (nbCharEncodingHandler >= MAX_ENCODING_HANDLERS) { - xmlGenericError(xmlGenericErrorContext, - "xmlRegisterCharEncodingHandler: Too many handler registered\n"); - xmlGenericError(xmlGenericErrorContext, - "\tincrease MAX_ENCODING_HANDLERS : %s\n", __FILE__); + xmlEncodingErr(XML_I18N_EXCESS_HANDLER, + "xmlRegisterCharEncodingHandler: Too many handler registered, see %s\n", + "MAX_ENCODING_HANDLERS"); return; } handlers[nbCharEncodingHandler++] = handler; @@ -1612,7 +1636,7 @@ xmlFindCharEncodingHandler(const char *name) { #endif return enc; } else if ((icv_in != (iconv_t) -1) || icv_out != (iconv_t) -1) { - xmlGenericError(xmlGenericErrorContext, + xmlEncodingErr(XML_ERR_INTERNAL_ERROR, "iconv : problems with filters for '%s'\n", name); } #endif /* LIBXML_ICONV_ENABLED */ @@ -1878,13 +1902,17 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out, toconv, written, in->use); #endif break; - case -2: - xmlGenericError(xmlGenericErrorContext, - "input conversion failed due to input error\n"); - xmlGenericError(xmlGenericErrorContext, - "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", - in->content[0], in->content[1], - in->content[2], in->content[3]); + case -2: { + char buf[50]; + + snprintf(buf, 49, "0x%02X 0x%02X 0x%02X 0x%02X", + in->content[0], in->content[1], + in->content[2], in->content[3]); + buf[49] = 0; + xmlEncodingErr(XML_I18N_CONV_FAILED, + "input conversion failed due to input error, bytes %s\n", + buf); + } } /* * Ignore when input buffer is not on a boundary @@ -1997,8 +2025,8 @@ retry: } #endif /* LIBXML_ICONV_ENABLED */ else { - xmlGenericError(xmlGenericErrorContext, - "xmlCharEncOutFunc: no output function !\n"); + xmlEncodingErr(XML_I18N_NO_OUTPUT, + "xmlCharEncOutFunc: no output function !\n", NULL); return(-1); } @@ -2055,12 +2083,15 @@ retry: goto retry; } else { - xmlGenericError(xmlGenericErrorContext, - "output conversion failed due to conv error\n"); - xmlGenericError(xmlGenericErrorContext, - "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", - in->content[0], in->content[1], - in->content[2], in->content[3]); + char buf[50]; + + snprintf(buf, 49, "0x%02X 0x%02X 0x%02X 0x%02X", + in->content[0], in->content[1], + in->content[2], in->content[3]); + buf[49] = 0; + xmlEncodingErr(XML_I18N_CONV_FAILED, + "output conversion failed due to conv error, bytes %s\n", + buf); in->content[0] = ' '; } break; diff --git a/error.c b/error.c index 7053686b..4c2046a0 100644 --- a/error.c +++ b/error.c @@ -354,6 +354,9 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, case XML_FROM_XSLT: channel(data, "XSLT "); break; + case XML_FROM_I18N: + channel(data, "encoding "); + break; default: break; } diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h index c1b8a962..cc35ca81 100644 --- a/include/libxml/xmlerror.h +++ b/include/libxml/xmlerror.h @@ -60,7 +60,8 @@ typedef enum { XML_FROM_VALID, /* The XML DTD validation with valid context */ XML_FROM_CHECK, /* The error checking module */ XML_FROM_WRITER, /* The xmlwriter module */ - XML_FROM_MODULE /* The dynamically loaded module module*/ + XML_FROM_MODULE, /* The dynamically loaded module module*/ + XML_FROM_I18N /* The module handling character conversion */ } xmlErrorDomain; /** @@ -800,7 +801,12 @@ typedef enum { XML_CHECK_NOT_NCNAME, /* 5034 */ XML_CHECK_OUTSIDE_DICT, /* 5035 */ XML_CHECK_WRONG_NAME, /* 5036 */ - XML_CHECK_NAME_NOT_NULL /* 5037 */ + XML_CHECK_NAME_NOT_NULL, /* 5037 */ + XML_I18N_NO_NAME = 6000, + XML_I18N_NO_HANDLER, /* 6001 */ + XML_I18N_EXCESS_HANDLER, /* 6002 */ + XML_I18N_CONV_FAILED, /* 6003 */ + XML_I18N_NO_OUTPUT /* 6004 */ #if 0 XML_CHECK_, /* 5033 */ XML_CHECK_X /* 503 */