file: fix processing POST data for deferred requests
[project/uhttpd.git] / file.c
diff --git a/file.c b/file.c
index 6b3bb823b981a6f3a0ba26d6f2446b1e3a429762..607282518a5b569138a0058d809da40878e496a0 100644 (file)
--- a/file.c
+++ b/file.c
@@ -26,6 +26,7 @@
 #include <time.h>
 #include <strings.h>
 #include <dirent.h>
+#include <stdint.h>
 
 #include <libubox/blobmsg.h>
 
@@ -287,10 +288,8 @@ static const char * uh_file_mime_lookup(const char *path)
 
 static const char * uh_file_mktag(struct stat *s, char *buf, int len)
 {
-       snprintf(buf, len, "\"%x-%x-%x\"",
-                        (unsigned int) s->st_ino,
-                        (unsigned int) s->st_size,
-                        (unsigned int) s->st_mtime);
+       snprintf(buf, len, "\"%" PRIx64 "-%" PRIx64 "-%" PRIx64 "\"",
+                s->st_ino, s->st_size, (uint64_t)s->st_mtime);
 
        return buf;
 }
@@ -479,11 +478,11 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                bool dir = !!(files[i]->d_type & DT_DIR);
 
                if (name[0] == '.' && name[1] == 0)
-                       continue;
+                       goto next;
 
                sprintf(file, "%s", name);
                if (stat(local_path, &s))
-                       continue;
+                       goto next;
 
                if (!dir) {
                        suffix = "";
@@ -492,7 +491,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                }
 
                if (!(s.st_mode & mode))
-                       continue;
+                       goto next;
 
                uh_chunk_printf(cl,
                                "<li><strong><a href='%s%s%s'>%s</a>%s"
@@ -505,6 +504,7 @@ static void list_entries(struct client *cl, struct dirent **files, int count,
                                type, s.st_size / 1024.0);
 
                *file = 0;
+next:
                free(files[i]);
        }
 }
@@ -579,7 +579,7 @@ static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
        ustream_printf(cl->us, "Content-Type: %s\r\n",
                           uh_file_mime_lookup(pi->name));
 
-       ustream_printf(cl->us, "Content-Length: %i\r\n\r\n",
+       ustream_printf(cl->us, "Content-Length: %" PRIu64 "\r\n\r\n",
                           pi->stat.st_size);
 
 
@@ -614,6 +614,7 @@ static void uh_file_request(struct client *cl, const char *url,
                if (fd < 0)
                        goto error;
 
+               req->respond_chunked = false;
                cl->dispatch.file.hdr = tb;
                uh_file_data(cl, pi, fd);
                cl->dispatch.file.hdr = NULL;
@@ -695,8 +696,11 @@ static void uh_complete_request(struct client *cl)
                dr = list_first_entry(&pending_requests, struct deferred_request, list);
                list_del(&dr->list);
 
+               cl = dr->cl;
                dr->called = true;
-               uh_invoke_script(dr->cl, dr->d, dr->path ? &dr->pi : NULL);
+               cl->dispatch.data_blocked = false;
+               uh_invoke_script(cl, dr->d, dr->path ? &dr->pi : NULL);
+               client_poll_post_data(cl);
        }
 }
 
@@ -755,6 +759,7 @@ uh_defer_script(struct client *cl, struct dispatch_handler *d, struct path_info
        }
 
        cl->dispatch.req_data = dr;
+       cl->dispatch.data_blocked = true;
        dr->cl = cl;
        dr->d = d;
        list_add(&dr->list, &pending_requests);