implement pg getlastmodified propfind (and prepare creationdate) webdav

Mon, 25 Apr 2022 19:28:52 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 25 Apr 2022 19:28:52 +0200
branch
webdav
changeset 311
e676ed461b5b
parent 310
523fe96baeca
child 312
f7544e220a0f

implement pg getlastmodified propfind (and prepare creationdate)

src/server/plugins/postgresql/pgtest.h file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/vfs.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/vfs.h file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/pgtest.h	Mon Apr 25 18:33:03 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.h	Mon Apr 25 19:28:52 2022 +0200
@@ -43,6 +43,7 @@
                 <D:getcontentlength/> \
                 <D:getcontenttype/> \
                 <D:getlastmodified/> \
+                <D:creationdate/> \
                 <D:resourcetype/> \
                 <D:getetag/> \
             </D:prop> \
--- a/src/server/plugins/postgresql/vfs.c	Mon Apr 25 18:33:03 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Mon Apr 25 19:28:52 2022 +0200
@@ -862,14 +862,27 @@
 }
 
 time_t pg_convert_timestamp(const char *timestamp) {
+    struct tm tm;
+    if(pg_convert_timestamp_tm(timestamp, &tm)) {
+        return 0;
+    }
+#ifdef __FreeBSD__
+    return timelocal(&tm);
+#else
+    return mktime(&tparts) - timezone;
+#endif
+}
+
+int pg_convert_timestamp_tm(const char *timestamp, struct tm *tm) {
     // TODO: this is a very basic implementation that needs some work
     // format yyyy-mm-dd HH:MM:SS
     
+    memset(tm, 0, sizeof(struct tm));
     size_t len = timestamp ? strlen(timestamp) : 0;
     if(len < 19) {
-        return 0;
+        return 1;
     } else if(len > 63) {
-        return 0;
+        return 1;
     }
     
     char buf[64];
@@ -893,18 +906,12 @@
     char *second_str = buf + 17;
     second_str[2] = '\0';
     
-    struct tm tm;
-    memset(&tm, 0, sizeof(struct tm));
-    tm.tm_year = atoi(year_str) - 1900;
-    tm.tm_mon = atoi(month_str) - 1;
-    tm.tm_mday = atoi(day_str);
-    tm.tm_hour = atoi(hour_str);
-    tm.tm_min = atoi(minute_str);
-    tm.tm_sec = atoi(second_str);
+    tm->tm_year = atoi(year_str) - 1900;
+    tm->tm_mon = atoi(month_str) - 1;
+    tm->tm_mday = atoi(day_str);
+    tm->tm_hour = atoi(hour_str);
+    tm->tm_min = atoi(minute_str);
+    tm->tm_sec = atoi(second_str);
     
-#ifdef __FreeBSD__
-    return timelocal(&tm);
-#else
-    return mktime(&tparts) - timezone;
-#endif
+    return 0;
 }
--- a/src/server/plugins/postgresql/vfs.h	Mon Apr 25 18:33:03 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.h	Mon Apr 25 19:28:52 2022 +0200
@@ -134,6 +134,7 @@
 void pg_vfs_dirio_close(VFS_DIR dir);
 
 time_t pg_convert_timestamp(const char *timestamp);
+int pg_convert_timestamp_tm(const char *timestamp, struct tm *tm);
 
 #ifdef __cplusplus
 }
--- a/src/server/plugins/postgresql/webdav.c	Mon Apr 25 18:33:03 2022 +0200
+++ b/src/server/plugins/postgresql/webdav.c	Mon Apr 25 19:28:52 2022 +0200
@@ -413,9 +413,17 @@
             }
             if(vfsprops.getlastmodified) {
                 char *lastmodified = PQgetvalue(result, r, 5);
+                time_t t = pg_convert_timestamp(lastmodified);
+                struct tm tm;
+                gmtime_r(&t, &tm);
+                
+                char buf[HTTP_DATE_LEN+1];
+                strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, &tm);
+                webdav_resource_add_dav_stringproperty(resource, pool, "getcontentlength", buf, strlen(buf));
             }
             if(vfsprops.creationdate) {
                 char *creationdate = PQgetvalue(result, r, 6);
+                webdav_resource_add_dav_stringproperty(resource, pool, "creationdate", creationdate, strlen(creationdate));
             }
             if(vfsprops.getcontentlength) {
                 char *contentlength = PQgetvalue(result, r, 7);

mercurial