From 69d2c171fa5105364168d663467f6834c8216155 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 9 Oct 2003 11:46:07 +0000 Subject: [PATCH] comment fix migrating the catalog code to the new infrastructure Daniel * xinclude.c: comment fix * catalog.c include/libxml/xmlerror.h: migrating the catalog code to the new infrastructure Daniel --- ChangeLog | 6 +++ catalog.c | 100 ++++++++++++++++++++++++++------------ include/libxml/xmlerror.h | 7 ++- xinclude.c | 2 +- 4 files changed, 82 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ec9d9e5..31fc99bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Oct 9 13:44:57 CEST 2003 Daniel Veillard + + * xinclude.c: comment fix + * catalog.c include/libxml/xmlerror.h: migrating the catalog code + to the new infrastructure + Thu Oct 9 00:36:03 CEST 2003 Daniel Veillard * xmlIO.c: final error handling cleanup diff --git a/catalog.c b/catalog.c index 6ff22a1b..c013c97a 100644 --- a/catalog.c +++ b/catalog.c @@ -182,6 +182,48 @@ static xmlRMutexPtr xmlCatalogMutex = NULL; */ static int xmlCatalogInitialized = 0; +/************************************************************************ + * * + * Catalog error handlers * + * * + ************************************************************************/ + +/** + * xmlCatalogErrMemory: + * @extra: extra informations + * + * Handle an out of memory condition + */ +static void +xmlCatalogErrMemory(const char *extra) +{ + __xmlRaiseError(NULL, NULL, NULL, NULL, XML_FROM_CATALOG, + XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0, + extra, NULL, NULL, 0, 0, + "Memory allocation failed : %s\n", extra); +} + +/** + * xmlCatalogErr: + * @catal: the Catalog entry + * @node: the context node + * @msg: the error message + * @extra: extra informations + * + * Handle a catalog error + */ +static void +xmlCatalogErr(xmlCatalogEntryPtr catal, xmlNodePtr node, int error, + const char *msg, const xmlChar *str1, const xmlChar *str2, + const xmlChar *str3) +{ + __xmlRaiseError(NULL, NULL, catal, node, XML_FROM_CATALOG, + error, XML_ERR_ERROR, NULL, 0, + (const char *) str1, (const char *) str2, + (const char *) str3, 0, 0, + msg, str1, str2, str3); +} + /************************************************************************ * * @@ -208,8 +250,7 @@ xmlNewCatalogEntry(xmlCatalogEntryType type, const xmlChar *name, ret = (xmlCatalogEntryPtr) xmlMalloc(sizeof(xmlCatalogEntry)); if (ret == NULL) { - xmlGenericError(xmlGenericErrorContext, - "malloc of %d byte failed\n", sizeof(xmlCatalogEntry)); + xmlCatalogErrMemory("allocating catalog entry"); return(NULL); } ret->next = NULL; @@ -336,8 +377,7 @@ xmlCreateNewCatalog(xmlCatalogType type, xmlCatalogPrefer prefer) { ret = (xmlCatalogPtr) xmlMalloc(sizeof(xmlCatalog)); if (ret == NULL) { - xmlGenericError(xmlGenericErrorContext, - "malloc of %d byte failed\n", sizeof(xmlCatalog)); + xmlCatalogErrMemory("allocating catalog"); return(NULL); } memset(ret, 0, sizeof(xmlCatalog)); @@ -874,8 +914,7 @@ xmlLoadFileContent(const char *filename) #endif content = xmlMallocAtomic(size + 10); if (content == NULL) { - xmlGenericError(xmlGenericErrorContext, - "malloc of %d byte failed\n", size + 10); + xmlCatalogErrMemory("allocating catalog data"); return (NULL); } #ifdef HAVE_STAT @@ -977,15 +1016,15 @@ xmlParseXMLCatalogOneNode(xmlNodePtr cur, xmlCatalogEntryType type, if (attrName != NULL) { nameValue = xmlGetProp(cur, attrName); if (nameValue == NULL) { - xmlGenericError(xmlGenericErrorContext, - "%s entry lacks '%s'\n", name, attrName); + xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR, + "%s entry lacks '%s'\n", name, attrName, NULL); ok = 0; } } uriValue = xmlGetProp(cur, uriAttrName); if (uriValue == NULL) { - xmlGenericError(xmlGenericErrorContext, - "%s entry lacks '%s'\n", name, uriAttrName); + xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR, + "%s entry lacks '%s'\n", name, uriAttrName, NULL); ok = 0; } if (!ok) { @@ -1009,7 +1048,7 @@ xmlParseXMLCatalogOneNode(xmlNodePtr cur, xmlCatalogEntryType type, } ret = xmlNewCatalogEntry(type, nameValue, uriValue, URL, prefer); } else { - xmlGenericError(xmlGenericErrorContext, + xmlCatalogErr(ret, cur, XML_CATALOG_ENTRY_BROKEN, "%s entry '%s' broken ?: %s\n", name, uriAttrName, uriValue); } if (nameValue != NULL) @@ -1054,8 +1093,9 @@ xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, } else if (xmlStrEqual(prop, BAD_CAST "public")) { prefer = XML_CATA_PREFER_PUBLIC; } else { - xmlGenericError(xmlGenericErrorContext, - "Invalid value for prefer: '%s'\n", prop); + xmlCatalogErr(parent, cur, XML_CATALOG_PREFER_VALUE, + "Invalid value for prefer: '%s'\n", + prop, NULL, NULL); } xmlFree(prop); } @@ -1194,17 +1234,18 @@ xmlParseXMLCatalogFile(xmlCatalogPrefer prefer, const xmlChar *filename) { } else if (xmlStrEqual(prop, BAD_CAST "public")) { prefer = XML_CATA_PREFER_PUBLIC; } else { - xmlGenericError(xmlGenericErrorContext, - "Invalid value for prefer: '%s'\n", - prop); + xmlCatalogErr(NULL, cur, XML_CATALOG_PREFER_VALUE, + "Invalid value for prefer: '%s'\n", + prop, NULL, NULL); } xmlFree(prop); } cur = cur->children; xmlParseXMLCatalogNodeList(cur, prefer, parent); } else { - xmlGenericError(xmlGenericErrorContext, - "File %s is not an XML Catalog\n", filename); + xmlCatalogErr(NULL, (xmlNodePtr) doc, XML_CATALOG_NOT_CATALOG, + "File %s is not an XML Catalog\n", + filename, NULL, NULL); xmlFreeDoc(doc); return(NULL); } @@ -1451,12 +1492,9 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, * protection against loops */ if (catal->depth > MAX_CATAL_DEPTH) { - if (catal->name != NULL) - xmlGenericError(xmlGenericErrorContext, - "Detected recursion in catalog %s\n", catal->name); - else - xmlGenericError(xmlGenericErrorContext, - "Detected recursion in catalog\n"); + xmlCatalogErr(catal, NULL, XML_CATALOG_RECURSION, + "Detected recursion in catalog %s\n", + catal->name, NULL, NULL); return(NULL); } catal->depth++; @@ -1969,7 +2007,7 @@ xmlParseSGMLCatalogComment(const xmlChar *cur) { */ static const xmlChar * xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) { - xmlChar *buf = NULL; + xmlChar *buf = NULL, *tmp; int len = 0; int size = 50; xmlChar stop; @@ -1988,8 +2026,7 @@ xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) { } buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); if (buf == NULL) { - xmlGenericError(xmlGenericErrorContext, - "malloc of %d byte failed\n", size); + xmlCatalogErrMemory("allocating public ID"); return(NULL); } while (xmlIsPubidChar(*cur) || (*cur == '?')) { @@ -1999,12 +2036,13 @@ xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) { break; if (len + 1 >= size) { size *= 2; - buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); - if (buf == NULL) { - xmlGenericError(xmlGenericErrorContext, - "realloc of %d byte failed\n", size); + tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + if (tmp == NULL) { + xmlCatalogErrMemory("allocating public ID"); + xmlFree(buf); return(NULL); } + buf = tmp; } buf[len++] = *cur; count++; diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h index b3ba2857..fcfc8771 100644 --- a/include/libxml/xmlerror.h +++ b/include/libxml/xmlerror.h @@ -472,7 +472,12 @@ typedef enum { XML_XINCLUDE_XPTR_RESULT, XML_XINCLUDE_INCLUDE_IN_INCLUDE, XML_XINCLUDE_FALLBACKS_IN_INCLUDE, - XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE + XML_XINCLUDE_FALLBACK_NOT_IN_INCLUDE, + XML_CATALOG_MISSING_ATTR = 1650, + XML_CATALOG_ENTRY_BROKEN, + XML_CATALOG_PREFER_VALUE, + XML_CATALOG_NOT_CATALOG, + XML_CATALOG_RECURSION } xmlParserErrors; /** diff --git a/xinclude.c b/xinclude.c index 8a336dc2..04d827fb 100644 --- a/xinclude.c +++ b/xinclude.c @@ -96,7 +96,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree); /************************************************************************ * * - * Tree memory error handler * + * XInclude error handler * * * ************************************************************************/