# HG changeset patch # User Olaf Wintermann # Date 1652028936 -7200 # Node ID 5832e10fc59a8e959dd53024a12cbab1ad462439 # Parent 70a9b945206a32bdc1b262d8c6e31a35996611f6 add optional getetag function to VFS API diff -r 70a9b945206a -r 5832e10fc59a src/server/daemon/http.c --- a/src/server/daemon/http.c Sun May 08 12:27:43 2022 +0200 +++ b/src/server/daemon/http.c Sun May 08 18:55:36 2022 +0200 @@ -198,7 +198,7 @@ /* ---------------------------- http_set_finfo ---------------------------- */ -static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime) +static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime, const char *etag) { struct tm mtms; struct tm *mtm = system_gmtime(&mtime, &mtms); @@ -223,15 +223,19 @@ snprintf(pp->value, content_length_size, "%lld", (long long)size); pblock_kpinsert(pb_key_content_length, pp, rq->srvhdrs); - char *etag; if (http_etag) { /* Insert Etag */ - pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG); - if (!pp || !pp->value) - return REQ_ABORTED; - http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime); - pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs); - etag = pp->value; + if(etag) { + pblock_kvinsert(pb_key_etag, etag, strlen(etag), rq->srvhdrs); + } else { + pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG); + if (!pp || !pp->value) + return REQ_ABORTED; + http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime); + pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs); + etag = pp->value; + } + } else { etag = NULL; } @@ -242,7 +246,11 @@ NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo) { - return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime); + return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, NULL); +} + +NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq, struct stat *finfo, const char *etag) { + return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, etag); } diff -r 70a9b945206a -r 5832e10fc59a src/server/daemon/vfs.c --- a/src/server/daemon/vfs.c Sun May 08 12:27:43 2022 +0200 +++ b/src/server/daemon/vfs.c Sun May 08 18:55:36 2022 +0200 @@ -69,8 +69,9 @@ sys_file_close, //sys_file_aioread, //sys_file_aiowrite, - NULL, - NULL + NULL, // aioread + NULL, // aiowrite + NULL // getetag }; static VFS_DIRIO sys_dir_io = { @@ -200,6 +201,15 @@ return ret; } +const char * vfs_getetag(SYS_FILE fd) { + WS_ASSERT(fd); + + if(fd->io->opt_getetag) { + return fd->io->opt_getetag(fd); + } + return NULL; +} + void vfs_close(SYS_FILE fd) { WS_ASSERT(fd); diff -r 70a9b945206a -r 5832e10fc59a src/server/plugins/postgresql/vfs.c --- a/src/server/plugins/postgresql/vfs.c Sun May 08 12:27:43 2022 +0200 +++ b/src/server/plugins/postgresql/vfs.c Sun May 08 18:55:36 2022 +0200 @@ -51,7 +51,8 @@ pg_vfs_io_seek, pg_vfs_io_close, NULL, // no pg aio implementation yet - NULL + NULL, + pg_vfs_io_getetag }; static VFS_DIRIO pg_vfs_dirio_class = { @@ -805,6 +806,9 @@ pool_free(pool, fd); } +const char *pg_vfs_io_getetag(SYS_FILE fd) { + return NULL; +} /* -------------------------- VFS_DIRIO functions -------------------------- */ diff -r 70a9b945206a -r 5832e10fc59a src/server/plugins/postgresql/vfs.h --- a/src/server/plugins/postgresql/vfs.h Sun May 08 12:27:43 2022 +0200 +++ b/src/server/plugins/postgresql/vfs.h Sun May 08 18:55:36 2022 +0200 @@ -128,6 +128,7 @@ off_t pg_vfs_io_seek(SYS_FILE fd, off_t offset, int whence); off_t pg_vfs_io_tell(SYS_FILE fd); void pg_vfs_io_close(SYS_FILE fd); +const char *pg_vfs_io_getetag(SYS_FILE fd); int pg_vfs_dirio_readdir(VFS_DIR dir, VFS_ENTRY *entry, int getstat); diff -r 70a9b945206a -r 5832e10fc59a src/server/public/nsapi.h --- a/src/server/public/nsapi.h Sun May 08 12:27:43 2022 +0200 +++ b/src/server/public/nsapi.h Sun May 08 18:55:36 2022 +0200 @@ -1514,6 +1514,7 @@ NSAPI_PUBLIC void http_format_etag(Session *sn, Request *rq, char *etagp, int etaglen, off_t size, time_t mtime); NSAPI_PUBLIC int http_check_preconditions(Session *sn, Request *rq, struct tm *mtm, const char *etag); NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo); +NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq, struct stat *finfo, const char *etag); NSAPI_PUBLIC char **http_hdrs2env(pblock *pb); diff -r 70a9b945206a -r 5832e10fc59a src/server/public/vfs.h --- a/src/server/public/vfs.h Sun May 08 12:27:43 2022 +0200 +++ b/src/server/public/vfs.h Sun May 08 18:55:36 2022 +0200 @@ -102,6 +102,7 @@ void (*close)(SYS_FILE fd); int (*opt_aioread)(aiocb_s *aiocb); int (*opt_aiowrite)(aiocb_s *aiocb); + const char* (*opt_getetag)(SYS_FILE fd); }; struct VFS_DIRIO { @@ -133,6 +134,7 @@ SYS_FILE vfs_openRW(VFSContext *ctx, const char *path); int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf); int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf); +const char * vfs_getetag(SYS_FILE fd); void vfs_close(SYS_FILE fd); VFS_DIR vfs_opendir(VFSContext *ctx, const char *path); VFS_DIR vfs_fdopendir(VFSContext *ctx, SYS_FILE fd);