src/server/plugins/postgresql/webdav.c

Wed, 10 Aug 2022 20:32:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 10 Aug 2022 20:32:49 +0200
branch
webdav
changeset 368
69dbcc7e7f93
parent 366
47bc686fafe4
child 370
d6d8c86c95c3
permissions
-rw-r--r--

implement named dav repositories

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"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
30 #include "vfs.h"
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
31 #include "config.h"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
32
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
33 #include "../../util/util.h"
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
34 #include "../../util/pblock.h"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
35
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
36 #include "../../daemon/http.h" // etag
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
37
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
38 #include <ucx/buffer.h>
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
39 #include <libxml/tree.h>
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
41
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 static WebdavBackend pg_webdav_backend = {
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 pg_dav_propfind_init,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 pg_dav_propfind_do,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 pg_dav_propfind_finish,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 pg_dav_proppatch_do,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 pg_dav_proppatch_finish,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 NULL, // opt_mkcol
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 NULL, // opt_mkcol_finish
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 NULL, // opt_delete
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 NULL, // opt_delete_finish
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 0,
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
53 NULL,
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 NULL
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 };
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
57
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
58 /*
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
59 * SQL Queries
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
60 */
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
61
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
62 // propfind with depth = 0
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
63 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
64 static const char *sql_propfind_allprop_depth0 = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
65 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
66 $2::text as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
67 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
68 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
69 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
70 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
71 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
72 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
73 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
74 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
75 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
76 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
77 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
78 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
79 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
80 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
81 from Resource r\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
82 left join Property p on r.resource_id = p.resource_id\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
83 where r.resource_id = $1;";
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
84
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
85 // propfind with depth = 0 for specific properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
86 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
87 static const char *sql_propfind_depth0 = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
88 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
89 $2::text as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
90 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
91 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
92 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
93 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
94 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
95 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
96 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
97 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
98 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
99 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
100 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
101 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
102 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
103 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
104 from Resource r\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
105 left join (\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
106 select p.* from Property p\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
107 inner join (select unnest($3::text[]) as xmlns, unnest($4::text[]) as pname) n\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
108 on p.xmlns = n.xmlns and p.pname = n.pname\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
109 ) p on r.resource_id = p.resource_id\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
110 where r.resource_id = $1;";
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
111
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
112 // propfind with depth = 1
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
113 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
114 static const char *sql_propfind_allprop_depth1 = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
115 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
116 case when r.resource_id = $1 then $2\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
117 else $2 || '/' || r.nodename\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
118 end as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
119 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
120 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
121 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
122 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
123 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
124 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
125 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
126 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
127 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
128 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
129 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
130 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
131 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
132 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
133 from Resource r\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
134 left join Property p on r.resource_id = p.resource_id\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
135 where r.resource_id = $1 or r.parent_id = $1\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
136 order by case when r.resource_id = $1 then 0 else 1 end, nodename, resource_id;";
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
137
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
138
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
139 // propfind with depth = 1 for specific properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
140 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
141 static const char *sql_propfind_depth1 = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
142 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
143 case when r.resource_id = $1 then $2\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
144 else $2 || '/' || r.nodename\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
145 end as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
146 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
147 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
148 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
149 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
150 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
151 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
152 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
153 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
154 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
155 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
156 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
157 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
158 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
159 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
160 from Resource r\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
161 left join (\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
162 select p.* from Property p\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
163 inner join (select unnest($3::text[]) as xmlns, unnest($4::text[]) as pname) n\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
164 on p.xmlns = n.xmlns and p.pname = n.pname\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
165 ) p on r.resource_id = p.resource_id\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
166 where r.resource_id = $1 or r.parent_id = $1\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
167 order by case when r.resource_id = $1 then 0 else 1 end, nodename, resource_id;";
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
168
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
169 // recursive propfind
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
170 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
171 static const char *sql_propfind_allprop_recursive = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
172 with recursive resolvepath as (\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
173 select\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
174 '' as ppath,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
175 *\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
176 from Resource\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
177 where resource_id = $1 \n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
178 union\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
179 select\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
180 p.ppath || '/' || r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
181 r.*\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
182 from Resource r\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
183 inner join resolvepath p on r.parent_id = p.resource_id\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
184 )\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
185 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
186 case when r.resource_id = $1 then $2\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
187 else $2 || r.ppath\n\
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
188 end as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
189 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
190 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
191 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
192 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
193 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
194 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
195 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
196 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
197 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
198 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
199 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
200 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
201 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
202 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
203 from resolvepath r\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
204 left join Property p on r.resource_id = p.resource_id\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
205 order by replace(ppath, '/', chr(1)), resource_id;";
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
206
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
207 // recursive propfind for specific properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
208 // params: $1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
209 // $2: array of property xmlns
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
210 // $3: array of property names
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
211 static const char *sql_propfind_recursive = "\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
212 with recursive resolvepath as (\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
213 select\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
214 '' as ppath,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
215 *\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
216 from Resource\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
217 where resource_id = $1 \n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
218 union\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
219 select\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
220 p.ppath || '/' || r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
221 r.*\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
222 from Resource r\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
223 inner join resolvepath p on r.parent_id = p.resource_id\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
224 )\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
225 select\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
226 case when r.resource_id = $1 then $2\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
227 else $2 || r.ppath\n\
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
228 end as ppath,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
229 r.resource_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
230 r.parent_id,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
231 r.nodename,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
232 r.iscollection,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
233 r.lastmodified,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
234 r.creationdate,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
235 r.contentlength,\n\
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
236 r.etag,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
237 p.prefix,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
238 p.xmlns,\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
239 p.pname,\n\
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
240 p.lang,\n\
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
241 p.nsdeflist,\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
242 p.pvalue\n\
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
243 from resolvepath r\n\
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
244 left join (\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
245 select p.* from Property p\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
246 inner join (select unnest($3::text[]) as xmlns, unnest($4::text[]) as pname) n\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
247 on p.xmlns = n.xmlns and p.pname = n.pname\n\
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
248 ) p on r.resource_id = p.resource_id\n\
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
249 order by replace(ppath, '/', chr(1)), resource_id;";
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
250
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
251 // proppatch: set property
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
252 // params: $1: resource_id
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
253 // $2: xmlns prefix
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
254 // $3: xmlns href
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
255 // $4: property name
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
256 // $5: lang attribute value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
257 // $6: namespace list string
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
258 // $7: property value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
259 static const char *sql_proppatch_set = "\
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
260 insert into Property(resource_id, prefix, xmlns, pname, lang, nsdeflist, pvalue)\n\
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
261 values($1, $2, $3, $4, $5, $6, $7)\n\
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
262 on conflict (resource_id, xmlns, pname) do\n\
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
263 update set prefix=$2, lang=$5, nsdeflist=$6, pvalue=$7;";
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
264
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
265 // proppatch: remove property
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
266 // params: $1: resource_id
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
267 // $2: xmlns href
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
268 // $3: property name
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
269 static const char *sql_proppatch_remove = "\
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
270 delete from Property where resource_id = $1 and xmlns = $2 and pname = $3";
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
271
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
272
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
273 void* pg_webdav_init(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
274 return pg_init_repo(pool, config);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
275 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
276
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 356
diff changeset
277 WebdavBackend* pg_webdav_create(Session *sn, Request *rq, pblock *pb, void *initData) {
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
278 // resourcepool is required
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
279 char *resource_pool = pblock_findval("resourcepool", pb);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
280 if(!resource_pool) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
281 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
282 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
283 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
284
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
285 // 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
286 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
287 if(!resdata) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
288 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
289 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
290 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
291
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
292 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
293 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
294
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
295 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
296 WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend));
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
297 if(!webdav) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
298 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
299 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
300 *webdav = pg_webdav_backend;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
301
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
302 PgWebdavBackend *instance = pool_malloc(sn->pool, sizeof(PgWebdavBackend));
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
303 if(!instance) {
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
304 pool_free(sn->pool, webdav);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
305 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
306 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
307 webdav->instance = instance;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
308
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
309 instance->pg_resource = resdata;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
310 instance->connection = resdata->data;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
311
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
312 return webdav;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
313 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
314
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
315 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
316 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
317 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
318
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
319 /*
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
320 * adds str to the buffer
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
321 * some characters will be escaped: \,{}
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
322 */
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
323 static void buf_addstr_escaped(UcxBuffer *buf, const char *str) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
324 size_t len = strlen(str);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
325 for(size_t i=0;i<len;i++) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
326 char c = str[i];
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
327 if(c == '{' || c == '}' || c == ',' || c == '\\') {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
328 ucx_buffer_putc(buf, '\\');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
329 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
330 ucx_buffer_putc(buf, c);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
331 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
332 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
333
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
334 /*
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
335 * convert a property list to two pg array parameter strings
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
336 * array format: {elm1,elm2,elm3}
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
337 * xmlns: buffer for the xmlns array
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
338 * pname: buffer for the property name array
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
339 *
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
340 * returns 0 on success, 1 otherwise
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
341 */
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
342 int pg_create_property_param_arrays(WebdavPList *plist, UcxBuffer *xmlns, UcxBuffer *pname) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
343 ucx_buffer_putc(xmlns, '{');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
344 ucx_buffer_putc(pname, '{');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
345 while(plist) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
346 WebdavProperty *property = plist->property;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
347 if(property && property->namespace && property->namespace->href && property->name) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
348 buf_addstr_escaped(xmlns, (const char*)property->namespace->href);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
349 buf_addstr_escaped(pname, (const char*)property->name);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
350 if(plist->next) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
351 ucx_buffer_putc(xmlns, ',');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
352 ucx_buffer_putc(pname, ',');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
353 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
354 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
355 plist = plist->next;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
356 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
357 int r1 = ucx_buffer_write("}\0", 2, 1, xmlns) == 0;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
358 int r2 = ucx_buffer_write("}\0", 2, 1, pname) == 0;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
359 return r1+r2 != 0;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
360 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
361
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
362
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 int pg_dav_propfind_init(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 const char *path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
366 const char *href,
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 WebdavPList **outplist)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
369 PgWebdavBackend *pgdav = rq->dav->instance;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
370
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
371 // check if the resource exists
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
372 int64_t parent_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
373 int64_t resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
374 const char *resourcename;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
375 WSBool iscollection;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
376 int res_errno = 0;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
377 int err = pg_resolve_path(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
378 pgdav->connection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
379 path,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
380 &parent_id,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
381 &resource_id,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
382 NULL, // OID
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
383 &resourcename,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
384 &iscollection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
385 NULL, // stat
346
784b24381bed extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
386 NULL, // etag
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
387 &res_errno);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
388
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
389 if(err) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
390 if(res_errno == ENOENT) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
391 protocol_status(rq->sn, rq->rq, PROTOCOL_NOT_FOUND, NULL);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
392 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
393 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
394 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
395
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
396 // choose sql query
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
397 const char *query = NULL;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
398 if(!iscollection || rq->depth == 0) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
399 query = rq->allprop ? sql_propfind_allprop_depth0 : sql_propfind_depth0;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
400 } else if(rq->depth == 1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
401 query = rq->allprop ? sql_propfind_allprop_depth1 : sql_propfind_depth1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
402 } else if(rq->depth == -1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
403 query = rq->allprop ? sql_propfind_allprop_recursive : sql_propfind_recursive;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
404 } else {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
405 log_ereport(LOG_FAILURE, "%s", "pg_dav_propfind_init: invalid depth");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
406 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
407 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
408
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
409 // get all resources and properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
410 char resource_id_str[32];
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
411 snprintf(resource_id_str, 32, "%" PRId64, resource_id);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
412
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
413 size_t href_len = strlen(href);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
414 char *href_param = pool_malloc(rq->sn->pool, href_len + 1);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
415 memcpy(href_param, href, href_len);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
416 if(href_param[href_len-1] == '/') {
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
417 href_len--;
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
418 }
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
419 href_param[href_len] = '\0';
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
420
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
421 // if allprop is false, create array pair for xmlns/property names
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
422 UcxBuffer *xmlns_buf = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
423 UcxBuffer *pname_buf = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
424 char *xmlns_param = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
425 char *pname_param = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
426 int nparam = 2;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
427 if(!rq->allprop) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
428 size_t bufsize = rq->propcount < 200 ? 8 + rq->propcount * 32 : 4096;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
429 xmlns_buf = ucx_buffer_new(NULL, bufsize, UCX_BUFFER_AUTOEXTEND);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
430 if(!xmlns_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
431 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
432 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
433 pname_buf = ucx_buffer_new(NULL, bufsize, UCX_BUFFER_AUTOEXTEND);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
434 if(!pname_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
435 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
436 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
437 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
438 if(pg_create_property_param_arrays(rq->properties, xmlns_buf, pname_buf)) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
439 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
440 ucx_buffer_free(pname_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
441 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
442 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
443 xmlns_param = xmlns_buf->space;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
444 pname_param = pname_buf->space;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
445 nparam = 4;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
446 }
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
447
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
448 const char* params[4] = { resource_id_str, href_param, xmlns_param, pname_param };
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
449 PGresult *result = PQexecParams(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
450 pgdav->connection,
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
451 query,
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
452 nparam, // number of parameters
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
453 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
454 params, // parameter value
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
455 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
456 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
457 0); // 0: result in text format
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
458 int nrows = PQntuples(result);
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
459 pool_free(rq->sn->pool, href_param);
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
460 if(xmlns_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
461 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
462 ucx_buffer_free(pname_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
463 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
464 if(nrows < 1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
465 PQclear(result);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
466 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
467 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
468
300
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
469 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
470 rq->userdata = pg;
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
471
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
472 pg->path = path;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
473 pg->resource_id = resource_id;
331
ab26980faad6 implement allprop in default and postgresql webdav backends
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 324
diff changeset
474 pg->vfsproperties = webdav_vfs_properties(outplist, TRUE, rq->allprop, 0);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
475 pg->result = result;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
476 pg->nrows = nrows;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
477
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
478 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 int pg_dav_propfind_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 WebdavResponse *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 VFS_DIR parent,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 WebdavResource *resource,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 struct stat *s)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
488 PgPropfind *pg = rq->userdata;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
489 pool_handle_t *pool = rq->sn->pool;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
490 PGresult *result = pg->result;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
491 WebdavVFSProperties vfsprops = pg->vfsproperties;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
492
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
493 WSBool vfsprops_set = 0; // are live properties added to the response?
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
494 int64_t current_resource_id = pg->resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
495 for(int r=0;r<pg->nrows;r++) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
496 // columns:
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
497 // 0: path
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
498 // 1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
499 // 2: parent_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
500 // 3: nodename
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
501 // 4: iscollection
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
502 // 5: lastmodified
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
503 // 6: creationdate
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
504 // 7: contentlength
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
505 // 8: etag
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
506 // 9: property prefix
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
507 // 10: property xmlns
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
508 // 11: property name
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
509 // 12: property lang
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
510 // 13: property nsdeflist
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
511 // 14: property value
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
512
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
513 char *path = PQgetvalue(result, r, 0);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
514 char *res_id = PQgetvalue(result, r, 1);
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
515 char *iscollection_str = PQgetvalue(result, r, 4);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
516 WSBool iscollection = iscollection_str && iscollection_str[0] == 't';
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
517 int64_t resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
518 if(!util_strtoint(res_id, &resource_id)) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
519 log_ereport(LOG_FAILURE, "pg_dav_propfind_do: cannot convert resource_id '%s' to int", res_id);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
520 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
521 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
522
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
523 if(resource_id != current_resource_id) {
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
524 // create a href string for the new resource
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
525 // if the resource is a collection, it should have a trailing '/'
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
526 size_t pathlen = strlen(path);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
527 if(pathlen == 0) {
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
528 log_ereport(LOG_FAILURE, "pg_dav_propfind_do: query returned invalid path");
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
529 return 1;
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
530 }
356
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
531 if(pathlen > PG_MAX_PATH_LEN) {
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
532 log_ereport(LOG_FAILURE, "pg_dav_propfind_do: path too long: resource_id: %s", res_id);
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
533 return 1;
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
534 }
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
535 char *newres_href = pool_malloc(pool, (pathlen*3)+2);
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
536 util_uri_escape(newres_href, path);
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
537 if(iscollection && path[pathlen-1] != '/') {
356
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
538 size_t newres_href_len = strlen(newres_href);
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
539 newres_href[newres_href_len] = '/';
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
540 newres_href[newres_href_len+1] = '\0';
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
541 }
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
542
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
543 // new resource
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
544 resource = response->addresource(response, newres_href);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
545 vfsprops_set = FALSE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
546 current_resource_id = resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
547 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
548
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
549 // standard webdav live properties
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
550 if(!vfsprops_set) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
551 if(vfsprops.getresourcetype) {
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
552 if(iscollection) {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
553 resource->addproperty(resource, webdav_resourcetype_collection(), 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
554 } else {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
555 resource->addproperty(resource, webdav_resourcetype_empty(), 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
556 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
557 }
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
558
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
559 char *lastmodified = PQgetvalue(result, r, 5);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
560 char *contentlength = PQgetvalue(result, r, 7);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
561 time_t t = pg_convert_timestamp(lastmodified);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
562
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
563 if(vfsprops.getlastmodified) {
311
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
564 struct tm tm;
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
565 gmtime_r(&t, &tm);
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
566
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
567 char buf[HTTP_DATE_LEN+1];
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
568 strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, &tm);
314
6b1a6066ee43 fix pg propfind for getlastmodified property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 313
diff changeset
569 webdav_resource_add_dav_stringproperty(resource, pool, "getlastmodified", buf, strlen(buf));
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
570 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
571 if(vfsprops.creationdate) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
572 char *creationdate = PQgetvalue(result, r, 6);
311
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
573 webdav_resource_add_dav_stringproperty(resource, pool, "creationdate", creationdate, strlen(creationdate));
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
574 }
314
6b1a6066ee43 fix pg propfind for getlastmodified property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 313
diff changeset
575 if(vfsprops.getcontentlength && !iscollection) {
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
576 webdav_resource_add_dav_stringproperty(resource, pool, "getcontentlength", contentlength, strlen(contentlength));
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
577 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
578 if(vfsprops.getetag) {
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
579 char *etag = PQgetvalue(result, r, 8);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
580 if(!PQgetisnull(result, r, 8)) {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
581 webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag));
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
582 } else {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
583 int64_t ctlen;
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
584 if(util_strtoint(contentlength, &ctlen)) {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
585 char etag[MAX_ETAG];
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
586 http_format_etag(rq->sn, rq->rq, etag, MAX_ETAG, ctlen, t);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
587 webdav_resource_add_dav_stringproperty(resource, pool, "getetag", etag, strlen(etag));
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
588 }
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
589 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
590 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
591
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
592 vfsprops_set = TRUE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
593 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
594
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
595 // dead properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
596 if(!PQgetisnull(result, r, 9)) {
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
597 char *prefix = PQgetvalue(result, r, 9);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
598 char *xmlns = PQgetvalue(result, r, 10);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
599 char *pname = PQgetvalue(result, r, 11);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
600 char *lang = PQgetvalue(result, r, 12);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
601 char *nsdef = PQgetvalue(result, r, 13);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
602 char *pvalue = PQgetvalue(result, r, 14);
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
603
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
604 int pvalue_len = PQgetlength(result, r, 14);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
605 WSBool lang_isnull = PQgetisnull(result, r, 12);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
606 WSBool nsdef_isnull = PQgetisnull(result, r, 13);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
607 WSBool pvalue_isnull = PQgetisnull(result, r, 14);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
608
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
609 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty));
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
610 property->lang = NULL;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
611 property->name = pool_strdup(pool, pname);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
612
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
613 xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs));
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
614 memset(namespace, 0, sizeof(struct _xmlNs));
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
615 namespace->href = (xmlChar*)pool_strdup(pool, xmlns);
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
616 namespace->prefix = (xmlChar*)pool_strdup(pool, prefix);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
617 property->namespace = namespace;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
618
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
619 if(!lang_isnull) {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
620 property->lang = pool_strdup(pool, lang);
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
621 }
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
622
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
623 if(!pvalue_isnull) {
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
624 char *content = pool_malloc(pool, pvalue_len+1);
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
625 memcpy(content, pvalue, pvalue_len);
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
626 content[pvalue_len] = '\0';
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
627
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
628 if(nsdef_isnull) {
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
629 property->vtype = WS_VALUE_TEXT;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
630 property->value.text.str = content;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
631 property->value.text.length = pvalue_len;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
632 } else {
324
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
633 WebdavNSList *nslist = wsxml_string2nslist(pool, nsdef);
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
634 property->vtype = WS_VALUE_XML_DATA;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
635 property->value.data->data = content;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
636 property->value.data->length = pvalue_len;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
637 property->value.data->namespaces = nslist;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
638
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
639 }
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
640 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
641
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
642 resource->addproperty(resource, property, 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
643 }
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
644 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
645
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
646 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
647 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
648
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
649 int pg_dav_propfind_finish(WebdavPropfindRequest *rq) {
312
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
650 PgPropfind *pg = rq->userdata;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
651 pool_handle_t *pool = rq->sn->pool;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
652 PGresult *result = pg->result;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
653
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
654 PQclear(result);
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
655
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
656 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
657 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
658
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
659 enum PgDavProp {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
660 PG_DAV_PROPPATCH_NOT_ALLOWED = 0,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
661 PG_DAV_CREATIONDATE,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
662 PG_DAV_DISPLAYNAME,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
663 PG_DAV_DEADPROP
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
664 };
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
665 /*
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
666 * checks if the property can be manipulated
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
667 */
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
668 static enum PgDavProp proppatch_check_dav_prop(const char *name) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
669 if(!strcmp(name, "getlastmodified")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
670 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
671 } else if(!strcmp(name, "getcontentlength")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
672 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
673 } else if(!strcmp(name, "resourcetype")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
674 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
675 } else if(!strcmp(name, "getetag")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
676 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
677 } else if(!strcmp(name, "creationdate")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
678 return PG_DAV_CREATIONDATE;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
679 } else if(!strcmp(name, "displayname")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
680 return PG_DAV_DISPLAYNAME;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
681 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
682 return PG_DAV_DEADPROP;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
683 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
684
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
685 typedef struct {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
686 WebdavProperty *creationdate;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
687 WebdavProperty *displayname;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
688 int error;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
689 } PgProppatchOpResult;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
690
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
691 typedef int(*pg_proppatch_func)(PgWebdavBackend*, WebdavProppatchRequest*, WebdavResource*, WebdavProperty*, void*);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
692
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
693 /*
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
694 * This function iterates the property list 'plist',
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
695 * analyses if any DAV: property is in the list
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
696 * and calls opfunc for the each property
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
697 *
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
698 * If the property list contains the properties creationdate or displayname,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
699 * the pointers to these properties will be stored in the result structure
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
700 */
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
701 static PgProppatchOpResult pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
702 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
703 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
704 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
705 WebdavPList **plist,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
706 enum PgDavProp forbidden_extra,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
707 pg_proppatch_func opfunc,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
708 void *op_userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
709 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
710 PgProppatchOpResult result;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
711 result.creationdate = NULL;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
712 result.displayname = NULL;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
713 result.error = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
714
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
715 WebdavPListIterator i = webdav_plist_iterator(plist);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
716 WebdavPList *cur;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
717 while(webdav_plist_iterator_next(&i, &cur)) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
718 WebdavProperty *property = cur->property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
719 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
720 if(!ns) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
721 continue; // maybe we should abort
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
722 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
723
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
724 // check if the property is a DAV: property that requires special
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
725 // handling
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
726 // get* properties can't be manipulated
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
727 // some properties can't be removed
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
728 if(!strcmp((const char*)ns->href, "DAV:")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
729 const char *name = property->name;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
730 enum PgDavProp davprop = proppatch_check_dav_prop(name);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
731 if(davprop != PG_DAV_DEADPROP) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
732 if(davprop == PG_DAV_PROPPATCH_NOT_ALLOWED || davprop == forbidden_extra) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
733 response->addproperty(response, property, 409);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
734 } else if(davprop == PG_DAV_CREATIONDATE) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
735 result.creationdate = property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
736 } else if(davprop == PG_DAV_DISPLAYNAME) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
737 result.displayname = property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
738 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
739 webdav_plist_iterator_remove_current(&i);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
740 continue;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
741 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
742 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
743
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
744 // call op func (set, remove specific code)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
745 if(opfunc(pgdav, request, response, property, op_userdata)) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
746 result.error = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
747 break;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
748 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
749
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
750 webdav_plist_iterator_remove_current(&i);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
751 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
752
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
753 return result;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
754 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
755
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
756 static int pg_dav_set_property(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
757 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
758 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
759 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
760 WebdavProperty *property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
761 void *userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
762 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
763 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
764 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
765 char *resource_id_str = userdata;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
766 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
767
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
768 // convert the property value to WSXmlData
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
769 // property->vtype == WS_VALUE_XML_NODE should always be true
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
770 WSXmlData *property_value = property->vtype == WS_VALUE_XML_NODE ? wsxml_node2data(pool, property->value.node) : NULL;
324
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
771 char *value_str = NULL;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
772 char *nsdef_str = NULL;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
773 if(property_value) {
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
774 value_str = property_value->data;
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
775 if(property_value->namespaces) {
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
776 nsdef_str = wsxml_nslist2string(pool, property_value->namespaces);
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
777 if(!nsdef_str) {
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
778 return 1; // OOM
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
779 }
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
780 }
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
781 }
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
782
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
783 // exec sql
324
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
784 const char* params[7] = { resource_id_str, (const char*)ns->prefix, (const char*)ns->href, property->name, NULL, nsdef_str, value_str};
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
785 PGresult *result = PQexecParams(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
786 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
787 sql_proppatch_set,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
788 7, // number of parameters
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
789 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
790 params, // parameter value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
791 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
792 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
793 0); // 0: result in text format
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
794
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
795 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
796 response->addproperty(response, property, 500);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
797 //printf(PQerrorMessage(pgdav->connection));
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
798 //fflush(stdout);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
799 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
800 } else {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
801 response->addproperty(response, property, 200);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
802 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
803 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
804 if(value_str) pool_free(pool, value_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
805
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
806 return ret;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
807 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
808
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
809
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
810 static int pg_dav_remove_property(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
811 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
812 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
813 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
814 WebdavProperty *property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
815 void *userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
816 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
817 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
818 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
819 char *resource_id_str = userdata;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
820 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
821
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
822 // exec sql
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
823 const char* params[3] = { resource_id_str, (const char*)ns->href, property->name };
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
824 PGresult *result = PQexecParams(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
825 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
826 sql_proppatch_remove,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
827 3, // number of parameters
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
828 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
829 params, // parameter value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
830 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
831 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
832 0); // 0: result in text format
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
833
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
834 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
835 response->addproperty(response, property, 500);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
836 //printf(PQerrorMessage(pgdav->connection));
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
837 //fflush(stdout);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
838 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
839 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
840 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
841
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
842 return ret;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
843 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
844
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
845 int pg_dav_proppatch_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
846 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
847 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
848 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
849 WebdavPList **out_set,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
850 WebdavPList **out_remove)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
851 {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
852 PgWebdavBackend *pgdav = request->dav->instance;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
853 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
854 char *path = pblock_findkeyval(pb_key_path, request->rq->vars);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
855
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
856 // check if the resource exists, we also need the resource_id
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
857 int64_t parent_id;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
858 int64_t resource_id;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
859 const char *resourcename;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
860 WSBool iscollection;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
861 int res_errno = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
862 int err = pg_resolve_path(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
863 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
864 path,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
865 &parent_id,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
866 &resource_id,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
867 NULL, // OID
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
868 &resourcename,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
869 &iscollection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
870 NULL, // stat
346
784b24381bed extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
871 NULL, // etag
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
872 &res_errno);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
873
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
874 if(err) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
875 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
876 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
877
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
878 // because proppatch must be atomic and we have multiple sql
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
879 // queries and other backends that do stuff that could fail
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
880 // we need the possibility to reverse all changes
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
881 // we use a transaction savepoint for this
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
882 PGresult *result = PQexec(pgdav->connection, "savepoint proppatch;");
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
883 ExecStatusType execStatus = PQresultStatus(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
884 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
885 if(execStatus != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
886 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
887 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
888
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
889 char resource_id_str[32];
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
890 snprintf(resource_id_str, 32, "%" PRId64, resource_id);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
891
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
892 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
893 PgProppatchOpResult set_res = pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
894 pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
895 request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
896 response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
897 out_set,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
898 PG_DAV_PROPPATCH_NOT_ALLOWED,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
899 pg_dav_set_property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
900 resource_id_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
901 if(set_res.error) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
902 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
903 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
904 PgProppatchOpResult rm_res = pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
905 pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
906 request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
907 response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
908 out_remove,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
909 PG_DAV_CREATIONDATE, // creationdate can't be removed
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
910 pg_dav_remove_property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
911 resource_id_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
912 if(rm_res.error) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
913 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
914 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
915
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
916 return ret;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
917 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
918
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
919 int pg_dav_proppatch_finish(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
920 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
921 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
922 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
923 WSBool commit)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
924 {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
925 PgWebdavBackend *pgdav = request->dav->instance;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
926 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
927 if(!commit) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
928 PGresult *result = PQexec(pgdav->connection, "rollback to savepoint proppatch;");
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
929 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
930 log_ereport(LOG_FAILURE, "pg_dav_proppatch_finish: rollback failed: %s", PQerrorMessage(pgdav->connection));
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
931 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
932 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
933 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
934 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
935 return ret;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
936 }

mercurial