From 0da1279f4cb94a16406cbeca403c939c415ef7bd Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 23 Aug 2001 21:20:28 +0000 Subject: [PATCH] complete test of a DocBook XSLt transform with --nonet, need stat(), added * config.h.in configure.in xsltproc/xsltproc.c: complete test of a DocBook XSLt transform with --nonet, need stat(), added checking in configure. Daniel --- ChangeLog | 6 ++++++ config.h.in | 9 +++++++++ configure.in | 3 ++- xsltproc/xsltproc.c | 43 ++++++++++++++++++++++++++++++------------- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4502952..cfd3a70a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Aug 23 23:18:44 CEST 2001 Daniel Veillard + + * config.h.in configure.in xsltproc/xsltproc.c: complete test + of a DocBook XSLt transform with --nonet, need stat(), added + checking in configure. + Thu Aug 23 17:37:40 CEST 2001 Daniel Veillard * xsltproc/xsltproc.c: catalog integration, cleanup with diff --git a/config.h.in b/config.h.in index db211355..24e09d21 100644 --- a/config.h.in +++ b/config.h.in @@ -12,6 +12,9 @@ #undef HAVE_FLOOR #undef HAVE_FABS +/* Define if you have the _stat function. */ +#undef HAVE__STAT + /* Define if you have the asctime function. */ #undef HAVE_ASCTIME @@ -24,6 +27,9 @@ /* Define if you have the mktime function. */ #undef HAVE_MKTIME +/* Define if you have the stat function. */ +#undef HAVE_STAT + /* Define if you have the header file. */ #undef HAVE_ANSIDECL_H @@ -48,6 +54,9 @@ /* Define if you have the header file. */ #undef HAVE_STRING_H +/* Define if you have the header file. */ +#undef HAVE_SYS_STAT_H + /* Define if you have the header file. */ #undef HAVE_SYS_TIME_H diff --git a/configure.in b/configure.in index 04d1b109..65d9d4b0 100644 --- a/configure.in +++ b/configure.in @@ -77,7 +77,8 @@ dnl AC_CHECK_HEADERS(sys/types.h sys/time.h stdlib.h unistd.h string.h) AC_CHECK_HEADERS(ieeefp.h nan.h math.h fp_class.h float.h ansidecl.h) -AC_CHECK_HEADERS(time.h) +AC_CHECK_HEADERS(time.h sys/stat.h) +AC_CHECK_FUNCS(stat _stat) AC_CHECK_FUNC(isnan, , AC_CHECK_LIB(m, isnan, [M_LIBS="-lm"; AC_DEFINE(HAVE_ISNAN)])) diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c index fdfc2a6a..6d4304c6 100644 --- a/xsltproc/xsltproc.c +++ b/xsltproc/xsltproc.c @@ -90,6 +90,34 @@ static const char *params[16 + 1]; static int nbparams = 0; static const char *output = NULL; +#ifdef LIBXML_CATALOG_ENABLED +static int xsltNoNetExists(const char *URL) { +#ifdef HAVE_STAT + int ret; + struct stat info; + const char *path; + + if (URL == NULL) + return(0); + + if (!xmlStrncmp(BAD_CAST URL, BAD_CAST "file://localhost", 16)) + path = &URL[16]; + else if (!xmlStrncmp(BAD_CAST URL, BAD_CAST "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 + static xmlParserInputPtr xsltNoNetExternalEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt) { @@ -97,9 +125,6 @@ xsltNoNetExternalEntityLoader(const char *URL, const char *ID, xmlChar *resource = NULL; #ifdef LIBXML_CATALOG_ENABLED -#ifdef HAVE_STAT - struct stat info; -#endif xmlCatalogAllow pref; /* @@ -108,11 +133,7 @@ xsltNoNetExternalEntityLoader(const char *URL, const char *ID, */ pref = xmlCatalogGetDefaults(); - if ((pref != XML_CATA_ALLOW_NONE) -#ifdef HAVE_STAT - && ((URL == NULL) || (stat(URL, &info) < 0)) -#endif - ) { + if ((pref != XML_CATA_ALLOW_NONE) && (!xsltNoNetExists(URL))) { /* * Do a local lookup */ @@ -138,11 +159,7 @@ xsltNoNetExternalEntityLoader(const char *URL, const char *ID, /* * TODO: do an URI lookup on the reference */ - if ((resource != NULL) -#ifdef HAVE_STAT - && (stat((const char *) resource, &info) < 0) -#endif - ) { + if ((resource != NULL) && (!xsltNoNetExists((const char *)resource))) { xmlChar *tmp = NULL; if ((ctxt->catalogs != NULL) &&