add support for getstat parameter in pg readdir webdav

Tue, 01 Feb 2022 20:07:42 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 01 Feb 2022 20:07:42 +0100
branch
webdav
changeset 282
cfb588e27198
parent 281
e9dc53661df4
child 283
25e5b771677d

add support for getstat parameter in pg readdir

src/server/plugins/postgresql/vfs.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/vfs.h file | annotate | diff | comparison | revisions
src/server/util/util.c file | annotate | diff | comparison | revisions
src/server/util/util.h file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/vfs.c	Tue Feb 01 17:47:50 2022 +0100
+++ b/src/server/plugins/postgresql/vfs.c	Tue Feb 01 20:07:42 2022 +0100
@@ -221,24 +221,7 @@
         }
         
         if(s) {
-            memset(s, 0, sizeof(struct stat));
-            
-            s->st_ino = *resource_id;
-            if(iscol) {
-                s->st_mode |= 0x4000;
-            }
-            if(lastmodified) {
-                // TODO
-            }
-            if(creationdate) {
-                // TODO
-            }
-            if(contentlength) {
-                int64_t len;
-                if(util_strtoint(contentlength, &len)) {
-                    s->st_size = len;
-                }
-            }
+            pg_set_stat(s, iscol, lastmodified, creationdate, contentlength);
         }
     } else {
         ctx->vfs_errno = ENOENT;
@@ -250,6 +233,29 @@
 }
 
 
+void pg_set_stat(
+        struct stat *s,
+        const char *iscollection,
+        const char *lastmodified,
+        const char *creationdate,
+        const char *contentlength)
+{
+    memset(s, 0, sizeof(struct stat));
+    if(iscollection) {
+        WSBool iscol = iscollection[0] == 't' ? TRUE : FALSE;
+        if(iscol) {
+            s->st_mode |= 0x4000;
+        }
+    }
+    // TODO: lastmodified, creationdate
+    if(contentlength) {
+        int64_t len;
+        if(util_strtoint(contentlength, &len)) {
+            s->st_size = len;
+        }
+    }
+}
+
 /* -------------------------- VFS functions -------------------------- */
 
 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) {
@@ -338,42 +344,46 @@
 }
 
 int pg_vfs_mkdir(VFSContext *ctx, const char *path) {
-    
+    return 1;
 }
 
 int pg_vfs_unlink(VFSContext *ctx, const char *path) {
-    
+    return 1;
 }
 
 int pg_vfs_rmdir(VFSContext *Ctx, const char *path) {
-    
+    return 1;
 }
 
 
 /* -------------------------- VFS_IO functions -------------------------- */
 
 ssize_t pg_vfs_io_read(SYS_FILE fd, void *buf, size_t nbyte) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_write(SYS_FILE fd, const void *buf, size_t nbyte) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) {
-    
+    return 0;
 }
 
 ssize_t pg_vfs_io_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) {
-    
+    return 0;
 }
 
 off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence) {
-    
+    return 0;
 }
 
 void pg_vfs_io_close(SYS_FILE fd) {
+    pool_handle_t *pool = fd->ctx->pool;
+    PgFile *pg = fd->data;
     
+    pool_free(pool, pg);
+    pool_free(pool, fd);
 }
 
 
@@ -420,7 +430,15 @@
     
     entry->name = PQgetvalue(pg->result, pg->row, 1);
         
-    // TODO: stat
+    if(getstat) {
+        memset(&entry->stat, 0, sizeof(struct stat));
+        
+        char *iscollection = PQgetvalue(pg->result, pg->row, 2);
+        char *lastmodified = PQgetvalue(pg->result, pg->row, 3);
+        char *creationdate = PQgetvalue(pg->result, pg->row, 4);
+        char *contentlength = PQgetvalue(pg->result, pg->row, 5);
+        pg_set_stat(&entry->stat, iscollection, lastmodified, creationdate, contentlength);
+    }
 
     pg->row++;
     return 1;
--- a/src/server/plugins/postgresql/vfs.h	Tue Feb 01 17:47:50 2022 +0100
+++ b/src/server/plugins/postgresql/vfs.h	Tue Feb 01 20:07:42 2022 +0100
@@ -76,6 +76,13 @@
         const char **resource_name,
         WSBool *iscollection,
         struct stat *s);
+
+void pg_set_stat(
+        struct stat *s,
+        const char *iscollection,
+        const char *lastmodified,
+        const char *creationdate,
+        const char *contentlength);
     
 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags);
 int pg_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf);
--- a/src/server/util/util.c	Tue Feb 01 17:47:50 2022 +0100
+++ b/src/server/util/util.c	Tue Feb 01 20:07:42 2022 +0100
@@ -407,7 +407,7 @@
     return def;
 }
 
-NSAPI_PUBLIC int util_strtoint(char *str, int64_t *value) {
+NSAPI_PUBLIC int util_strtoint(const char *str, int64_t *value) {
     char *end;
     errno = 0;
     int64_t val = strtoll(str, &end, 0);
--- a/src/server/util/util.h	Tue Feb 01 17:47:50 2022 +0100
+++ b/src/server/util/util.h	Tue Feb 01 20:07:42 2022 +0100
@@ -200,7 +200,7 @@
 int util_getboolean_s(scstr_t s, int def);
 
 // new
-NSAPI_PUBLIC int util_strtoint(char *str, int64_t *value);
+NSAPI_PUBLIC int util_strtoint(const char *str, int64_t *value);
 NSAPI_PUBLIC const char* util_resource_name(const char *url);
 
 // TODO

mercurial