Tue, 19 Apr 2022 20:32:45 +0200
add pg webdav backend initialization
--- a/src/server/plugins/postgresql/init.c Tue Apr 19 19:15:23 2022 +0200 +++ b/src/server/plugins/postgresql/init.c Tue Apr 19 20:32:45 2022 +0200 @@ -30,8 +30,9 @@ #include "resource.h" #include "vfs.h" +#include "webdav.h" -int pg_init(pblock *pb, Session *sn, Request *Rq) { +int pg_init(pblock *pb, Session *sn, Request *rq) { if(resourcepool_register_type("postgresql", pg_get_resource_type())) { log_ereport(LOG_FAILURE, "pg-init: Cannot register resourcepool type"); return REQ_ABORTED; @@ -48,3 +49,11 @@ int pg_register_vfs(pblock *pb) { return vfs_register_type("postgresql", pg_vfs_create); } + +int pg_register_webdav_backend(pblock *pb) { + if(webdav_register_backend("postgresql", pg_webdav_create)) { + return 1; + } + return 0; +} +
--- a/src/server/plugins/postgresql/webdav.c Tue Apr 19 19:15:23 2022 +0200 +++ b/src/server/plugins/postgresql/webdav.c Tue Apr 19 20:32:45 2022 +0200 @@ -39,9 +39,53 @@ NULL, // opt_delete NULL, // opt_delete_finish 0, + NULL, NULL }; +WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb) { + // resourcepool is required + char *resource_pool = pblock_findval("resourcepool", pb); + if(!resource_pool) { + log_ereport(LOG_MISCONFIG, "pg_webdav_create: missing resourcepool parameter"); + return NULL; + } + + // get the resource first (should only fail in case of misconfig) + ResourceData *resdata = resourcepool_lookup(sn, rq, resource_pool, 0); + if(!resdata) { + log_ereport(LOG_MISCONFIG, "postgresql webdav: resource pool %s not found", resource_pool); + return NULL; + } + + return pg_webdav_create_from_resdata(sn, rq, resdata); +} + +WebdavBackend* pg_webdav_create_from_resdata(Session *sn, Request *rq, ResourceData *resdata) { + WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend)); + if(!webdav) { + return NULL; + } + *webdav = pg_webdav_backend; + + PgWebdavBackend *instance = pool_malloc(sn->pool, sizeof(PgWebdavBackend)); + if(instance) { + pool_free(sn->pool, webdav); + return NULL; + } + webdav->instance = instance; + + instance->pg_resource = resdata; + instance->connection = resdata->data; + + return webdav; +} + +WebdavBackend* pg_webdav_prop_create(Session *sn, Request *rq, pblock *pb) { + return NULL; +} + + int pg_dav_propfind_init( WebdavPropfindRequest *rq, const char *path,
--- a/src/server/plugins/postgresql/webdav.h Tue Apr 19 19:15:23 2022 +0200 +++ b/src/server/plugins/postgresql/webdav.h Tue Apr 19 20:32:45 2022 +0200 @@ -38,12 +38,20 @@ extern "C" { #endif +typedef struct PgWebdavBackend { + ResourceData *pg_resource; + PGconn *connection; +} PgWebdavBackend; typedef struct PgPropfind { ResourceData *pg_resource; PGconn *connection; } PgPropfind; +WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb); +WebdavBackend* pg_webdav_create_from_resdata(Session *sn, Request *rq, ResourceData *resdata); + +WebdavBackend* pg_webdav_prop_create(Session *sn, Request *rq, pblock *pb); /* ----------------- webdav backend functions ----------------- */ int pg_dav_propfind_init(