summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2005-09-05 17:10:35 +0000
committerMike Hommey <glandium@debian.org>2005-09-05 17:10:35 +0000
commita464d9993e2acd5b8e1089b218ba74c6fcf215c5 (patch)
tree72fe00eb59147367a1d660b90d08172357e0dffc /encoding.c
parent112cb5bb5475afec1c1cbf1d6728ce4880d0fee8 (diff)
downloadlibxml2-a464d9993e2acd5b8e1089b218ba74c6fcf215c5.tar.gz
Load /usr/tmp/tmp.CMoFff/libxml2-2.6.21 intoupstream/2.6.21
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c101
1 files changed, 66 insertions, 35 deletions
diff --git a/encoding.c b/encoding.c
index 66e63b5..c6cfe91 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);
+}
/************************************************************************
* *
@@ -1239,7 +1265,7 @@ xmlNewCharEncodingHandler(const char *name,
const char *alias;
char upper[500];
int i;
- char *up = 0;
+ char *up = NULL;
/*
* Do the alias resolution
@@ -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,20 +1902,24 @@ 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[0], 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
*/
if (ret == -3)
ret = 0;
- return (written);
+ return (written? written : ret);
}
/**
@@ -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);
}
@@ -2049,18 +2077,21 @@ retry:
* and continue the transcoding phase, hoping the error
* did not mangle the encoder state.
*/
- snprintf((char *) charref, sizeof(charref), "&#%d;", cur);
+ snprintf((char *) &charref[0], sizeof(charref), "&#%d;", cur);
xmlBufferShrink(in, len);
xmlBufferAddHead(in, charref, -1);
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[0], 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;