src/server/safs/pathcheck.c

changeset 142
55298bc9ed28
parent 141
ff311b63c3af
child 143
6bf5d2f37425
--- a/src/server/safs/pathcheck.c	Fri Dec 30 14:15:52 2016 +0100
+++ b/src/server/safs/pathcheck.c	Fri Dec 30 18:47:26 2016 +0100
@@ -37,6 +37,8 @@
 #include "../daemon/session.h"
 #include "../daemon/vserver.h"
 
+#include "../daemon/vfs.h"
+
 #include "../config/acl.h"
 
 int require_auth(pblock *pb, Session *sn, Request *rq) {
@@ -157,3 +159,32 @@
     
     return ret;
 }
+
+int dir_redirect(pblock *pb, Session *sn, Request *rq) {
+    char *path = pblock_findkeyval(pb_key_path, rq->vars);
+    
+    // TODO: VFS support
+    
+    struct stat s;
+    if(stat(path, &s) != 0) {
+        return REQ_NOACTION;
+    }
+    
+    // TODO: remove code duplication (service.c)
+    if(S_ISDIR(s.st_mode) && path[strlen(path)-1] != '/') {
+        pblock_nvinsert("content-length", "0", rq->srvhdrs);
+        pblock_removekey(pb_key_content_type, rq->srvhdrs);
+        char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
+        size_t urilen = strlen(uri);
+        char *location = pool_malloc(sn->pool, urilen + 2);
+        memcpy(location, uri, urilen);
+        location[urilen] = '/';
+        location[urilen+1] = '\0';
+        pblock_kvinsert(pb_key_location, location, urilen + 1, rq->srvhdrs);
+        protocol_status(sn, rq, 302, NULL);
+        http_start_response(sn, rq);
+        return REQ_ABORTED;
+    }
+    
+    return REQ_PROCEED;
+}

mercurial