1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

final error handling cleanup converted XInclude to the new error handling

* xmlIO.c: final error handling cleanup
* xinclude.c error.c: converted XInclude to the new error handling
* include/libxml/xmlerror.h: added XInclude errors
Daniel
This commit is contained in:
Daniel Veillard
2003-10-08 22:38:13 +00:00
parent b65e12e3c5
commit cd6ff28211
7 changed files with 1013 additions and 283 deletions

50
xmlIO.c
View File

@ -194,7 +194,7 @@ xmlIOErrMemory(const char *extra)
* @code: the error number
* @extra: extra informations
*
* Handle an out of memory condition
* Handle an I/O error
*/
static void
xmlIOErr(int code, const char *extra)
@ -340,6 +340,37 @@ xmlIOErr(int code, const char *extra)
__xmlSimpleError(XML_FROM_IO, code, NULL, IOerr[idx], extra);
}
/**
* xmlLoaderErr:
* @ctxt: the parser context
* @extra: extra informations
*
* Handle a resource access error
*/
static void
xmlLoaderErr(xmlParserCtxtPtr ctxt, const char *msg, const char *filename)
{
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
xmlErrorLevel level = XML_ERR_ERROR;
if ((ctxt != NULL) && (ctxt->sax != NULL)) {
if (ctxt->validate) {
channel = ctxt->sax->error;
level = XML_ERR_ERROR;
} else {
channel = ctxt->sax->warning;
level = XML_ERR_WARNING;
}
data = ctxt->userData;
}
__xmlRaiseError(channel, data, ctxt, NULL, XML_FROM_IO,
XML_IO_LOAD_ERROR, level, NULL, 0,
filename, NULL, NULL, 0, 0,
msg, filename);
}
/************************************************************************
* *
* Tree memory error handler *
@ -2986,24 +3017,13 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
if (resource == NULL) {
if (ID == NULL)
ID = "NULL";
if ((ctxt->validate) && (ctxt->sax != NULL) &&
(ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"failed to load external entity \"%s\"\n", ID);
else if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"failed to load external entity \"%s\"\n", ID);
xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n", ID);
return(NULL);
}
ret = xmlNewInputFromFile(ctxt, (const char *)resource);
if (ret == NULL) {
if ((ctxt->validate) && (ctxt->sax != NULL) &&
(ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"failed to load external entity \"%s\"\n", resource);
else if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"failed to load external entity \"%s\"\n", resource);
xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
(const char *) resource);
}
if ((resource != NULL) && (resource != (xmlChar *) URL))
xmlFree(resource);