src/server/plugins/postgresql/webdav.c

Thu, 21 Apr 2022 17:16:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 21 Apr 2022 17:16:49 +0200
branch
webdav
changeset 305
4db64fe30588
parent 303
ad9ba51c8634
child 306
e03737cea6e2
permissions
-rw-r--r--

change pg_resolve_path signature to be useable without VFS

299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "webdav.h"
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 static WebdavBackend pg_webdav_backend = {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 pg_dav_propfind_init,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 pg_dav_propfind_do,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 pg_dav_propfind_finish,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 pg_dav_proppatch_do,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 pg_dav_proppatch_finish,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 NULL, // opt_mkcol
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 NULL, // opt_mkcol_finish
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 NULL, // opt_delete
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 NULL, // opt_delete_finish
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 0,
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
42 NULL,
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 NULL
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 };
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
46 WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
47 // resourcepool is required
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
48 char *resource_pool = pblock_findval("resourcepool", pb);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
49 if(!resource_pool) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
50 log_ereport(LOG_MISCONFIG, "pg_webdav_create: missing resourcepool parameter");
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
51 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
52 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
53
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
54 // get the resource first (should only fail in case of misconfig)
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
55 ResourceData *resdata = resourcepool_lookup(sn, rq, resource_pool, 0);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
56 if(!resdata) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
57 log_ereport(LOG_MISCONFIG, "postgresql webdav: resource pool %s not found", resource_pool);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
58 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
59 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
60
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
61 return pg_webdav_create_from_resdata(sn, rq, resdata);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
62 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
63
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
64 WebdavBackend* pg_webdav_create_from_resdata(Session *sn, Request *rq, ResourceData *resdata) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
65 WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend));
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
66 if(!webdav) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
67 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
68 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
69 *webdav = pg_webdav_backend;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
70
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
71 PgWebdavBackend *instance = pool_malloc(sn->pool, sizeof(PgWebdavBackend));
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
72 if(instance) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
73 pool_free(sn->pool, webdav);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
74 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
75 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
76 webdav->instance = instance;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
77
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
78 instance->pg_resource = resdata;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
79 instance->connection = resdata->data;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
80
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
81 return webdav;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
82 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
83
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
84 WebdavBackend* pg_webdav_prop_create(Session *sn, Request *rq, pblock *pb) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
85 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
86 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
87
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
88
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 int pg_dav_propfind_init(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 const char *path,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 WebdavPList **outplist)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 {
300
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
94 PgPropfind *pg = pool_malloc(rq->sn->pool, sizeof(PgPropfind));
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
95 rq->userdata = pg;
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
96
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 return 1;
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 int pg_dav_propfind_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 WebdavResponse *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 VFS_DIR parent,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 WebdavResource *resource,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 struct stat *s)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 return 1;
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 int pg_dav_propfind_finish(WebdavPropfindRequest *rq) {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 return 1;
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 int pg_dav_proppatch_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 WebdavPList **out_set,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 WebdavPList **out_remove)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 return 1;
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 int pg_dav_proppatch_finish(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 WSBool commit)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 return 1;
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }

mercurial