diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2005-08-24 12:46:09 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2005-08-24 12:46:09 +0000 |
commit | 1fc3ed02806f6725c97a70f1f4ed3e85a93a768a (patch) | |
tree | ab5037512fde1ad0a98db847ceb475e548336c53 /encoding.c | |
parent | 8bda20f73c908fc08b40ad7a1d1df2c35a8d362d (diff) | |
download | libxml2-1fc3ed02806f6725c97a70f1f4ed3e85a93a768a.tar.gz |
finally converted the encoding module to the common error reporting
* 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
Daniel
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 95 |
1 files changed, 63 insertions, 32 deletions
@@ -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; |