More verbose log if HTTP file access fails
[yazproxy-moved-to-github.git] / src / yaz-proxy.cpp
index 5d7bded..2b1afbe 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: yaz-proxy.cpp,v 1.15 2004-12-15 11:42:27 adam Exp $
-   Copyright (c) 1998-2004, Index Data.
+/* $Id: yaz-proxy.cpp,v 1.18 2005-01-18 10:49:45 adam Exp $
+   Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
 
@@ -19,18 +19,21 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
  */
 
-#ifdef WIN32
-#else
+#if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-
-#if HAVE_GETTIMEOFDAY
+#if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
 
 #include <assert.h>
 #include <time.h>
-#include <sys/types.h>
 #include <fcntl.h>
 
 #include <yaz/srw.h>
@@ -688,8 +691,8 @@ int Yaz_Proxy::convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu)
 
 void Yaz_Proxy::convert_xsl_delay()
 {
-    Z_NamePlusRecord *npr = m_stylesheet_nprl->records[m_stylesheet_offset];
 #if HAVE_XSLT
+    Z_NamePlusRecord *npr = m_stylesheet_nprl->records[m_stylesheet_offset];
     if (npr->which == Z_NamePlusRecord_databaseRecord)
     {
        Z_External *r = npr->u.databaseRecord;
@@ -1892,26 +1895,35 @@ int Yaz_Proxy::file_access(Z_HTTP_Request *hreq)
     struct stat sbuf;
     if (hreq->path[0] != '/')
     {
-       yaz_log(YLOG_WARN, "Path != /");
+       yaz_log(YLOG_WARN, "Bad path: %s", hreq->path);
        return 0;
     }
     const char *cp = hreq->path;
     while (*cp)
     {
        if (*cp == '/' && strchr("/.", cp[1]))
+       {
+           yaz_log(YLOG_WARN, "Bad path: %s", hreq->path);
            return 0;
+       }
        cp++;
     }
     const char *fname = hreq->path+1;
     if (stat(fname, &sbuf))
     {
-       yaz_log(YLOG_WARN, "stat %s failed", fname);
+       yaz_log(YLOG_WARN|YLOG_ERRNO, "%s: stat failed", fname);
        return 0;
     }
     if ((sbuf.st_mode & S_IFMT) != S_IFREG)
+    {
+       yaz_log(YLOG_WARN, "%s: not a regular file", fname);
        return 0;
+    }
     if (sbuf.st_size > (off_t) 1000000)
+    {
+       yaz_log(YLOG_WARN, "%s: too large for transfer", fname);
        return 0;
+    }
 
     ODR o = odr_encode();
     Yaz_ProxyConfig *cfg = check_reconfigure();