# HG changeset patch # User Olaf Wintermann # Date 1650907732 -7200 # Node ID e676ed461b5b541a50319f2bcf12e735ad93926f # Parent 523fe96baeca0e4cf01518460f429096dc9eccf9 implement pg getlastmodified propfind (and prepare creationdate) diff -r 523fe96baeca -r e676ed461b5b src/server/plugins/postgresql/pgtest.h --- 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 @@ \ \ \ + \ \ \ \ diff -r 523fe96baeca -r e676ed461b5b src/server/plugins/postgresql/vfs.c --- 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; } diff -r 523fe96baeca -r e676ed461b5b src/server/plugins/postgresql/vfs.h --- 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 } diff -r 523fe96baeca -r e676ed461b5b src/server/plugins/postgresql/webdav.c --- 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);