started some serious testing and fixed a few bug and optmization needs.
* catalog.c xmlIO.c: started some serious testing and fixed
a few bug and optmization needs.
Daniel
diff --git a/xmlIO.c b/xmlIO.c
index 9aca472..b8be560 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2359,6 +2359,34 @@
* *
****************************************************************/
+#ifdef LIBXML_CATALOG_ENABLED
+static int xmlSysIDExists(const char *URL) {
+#ifdef HAVE_STAT
+ int ret;
+ struct stat info;
+ const char *path;
+
+ if (URL == NULL)
+ return(0);
+
+ if (!strncmp(URL, "file://localhost", 16))
+ path = &URL[16];
+ else if (!strncmp(URL, "file:///", 8)) {
+#ifdef _WIN32
+ path = &URL[8];
+#else
+ path = &URL[7];
+#endif
+ } else
+ path = URL;
+ ret = stat(path, &info);
+ if (ret == 0)
+ return(1);
+#endif
+ return(0);
+}
+#endif
+
/**
* xmlDefaultExternalEntityLoader:
* @URL: the URL for the entity to load
@@ -2376,9 +2404,6 @@
xmlParserInputPtr ret = NULL;
xmlChar *resource = NULL;
#ifdef LIBXML_CATALOG_ENABLED
-#ifdef HAVE_STAT
- struct stat info;
-#endif
xmlCatalogAllow pref;
#endif
@@ -2393,11 +2418,7 @@
*/
pref = xmlCatalogGetDefaults();
- if ((pref != XML_CATA_ALLOW_NONE)
-#ifdef HAVE_STAT
- && ((URL == NULL) || (stat(URL, &info) < 0))
-#endif
- ) {
+ if ((pref != XML_CATA_ALLOW_NONE) && (!xmlSysIDExists(URL))) {
/*
* Do a local lookup
*/
@@ -2423,11 +2444,7 @@
/*
* TODO: do an URI lookup on the reference
*/
- if ((resource != NULL)
-#ifdef HAVE_STAT
- && (stat((const char *) resource, &info) < 0)
-#endif
- ) {
+ if ((resource != NULL) && (!xmlSysIDExists((const char *)resource))) {
xmlChar *tmp = NULL;
if ((ctxt->catalogs != NULL) &&