support of symbolic links to webfiles
authorJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 25 Nov 2011 00:19:33 +0000 (00:19 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 25 Nov 2011 00:19:33 +0000 (00:19 +0000)
NEWS
src/server/server.c

diff --git a/NEWS b/NEWS
index a968a66..656745e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@
    64bits.
 ** added some information in the README (mostly about compilation on
    CentOS).
+** psensor-server: support of symbolic links to webfiles.
 
 * v0.6.2.13
 
index cdd655d..f4cd482 100644 (file)
@@ -203,28 +203,33 @@ create_response_file(const char *nurl,
                     unsigned int *rp_code,
                     const char *fpath)
 {
-       if (is_file(fpath)) {
-               FILE *file = fopen(fpath, "rb");
+       struct stat st;
+       int ret;
+       FILE *file;
 
-               if (file) {
-                       struct stat buf;
+       ret = stat(fpath, &st);
 
-                       stat(fpath, &buf);
+       if (!ret && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) {
+               file = fopen(fpath, "rb");
+
+               if (file) {
                        *rp_code = MHD_HTTP_OK;
 
-                       if (!buf.st_size) {
+                       if (!st.st_size) {
                                fclose(file);
                                return MHD_create_response_from_data
                                        (0, NULL, MHD_NO, MHD_NO);
                        }
 
                        return MHD_create_response_from_callback
-                               (buf.st_size,
+                               (st.st_size,
                                 32 * 1024,
                                 &file_reader,
                                 file,
                                 (MHD_ContentReaderFreeCallback)&fclose);
 
+               } else {
+                       log_printf(LOG_ERR, "Failed to open: %s\n", fpath);
                }
        }