src/server/plugins/postgresql/webdav.c

Sat, 13 Aug 2022 15:56:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Aug 2022 15:56:51 +0200
branch
webdav
changeset 373
f78a585e1a2f
parent 372
1d2538a1ba8f
child 374
77506ec632a4
permissions
-rw-r--r--

add parser for extended postgresql webdav config

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) {
372
1d2538a1ba8f add config option for pg root node lookup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
274 return pg_init_repo(cfg, pool, config);
366
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) {
370
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
278 PgRepository *repo = initData;
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
279
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
280 char *resource_pool;
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
281 if(repo) {
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
282 resource_pool = repo->resourcepool.ptr;
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
283 } else {
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
284 // resourcepool is required
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
285 resource_pool = pblock_findval("resourcepool", pb);
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
286 if(!resource_pool) {
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
287 log_ereport(LOG_MISCONFIG, "pg_webdav_create: missing resourcepool parameter");
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
288 return NULL;
d6d8c86c95c3 adjust pg plugin to new dav initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
289 }
303
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 // 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
293 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
294 if(!resdata) {
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
295 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
296 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
297 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
298
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
299 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
300 }
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 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
303 WebdavBackend *webdav = pool_malloc(sn->pool, sizeof(WebdavBackend));
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
304 if(!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 = pg_webdav_backend;
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 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
310 if(!instance) {
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
311 pool_free(sn->pool, webdav);
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
312 return NULL;
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 webdav->instance = instance;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
315
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
316 instance->pg_resource = resdata;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
317 instance->connection = resdata->data;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
318
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
319 return webdav;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
320 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
321
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
322 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
323 return NULL;
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
324 }
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
325
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
326 /*
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
327 * adds str to the buffer
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
328 * some characters will be escaped: \,{}
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 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
331 size_t len = strlen(str);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
332 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
333 char c = str[i];
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
334 if(c == '{' || c == '}' || c == ',' || c == '\\') {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
335 ucx_buffer_putc(buf, '\\');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
336 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
337 ucx_buffer_putc(buf, c);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
338 }
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
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 * 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
343 * array format: {elm1,elm2,elm3}
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
344 * xmlns: buffer for the xmlns array
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
345 * 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
346 *
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
347 * returns 0 on success, 1 otherwise
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
348 */
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
349 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
350 ucx_buffer_putc(xmlns, '{');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
351 ucx_buffer_putc(pname, '{');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
352 while(plist) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
353 WebdavProperty *property = plist->property;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
354 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
355 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
356 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
357 if(plist->next) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
358 ucx_buffer_putc(xmlns, ',');
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
359 ucx_buffer_putc(pname, ',');
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 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
362 plist = plist->next;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
363 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
364 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
365 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
366 return r1+r2 != 0;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
367 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
368
303
ad9ba51c8634 add pg webdav backend initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 300
diff changeset
369
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 int pg_dav_propfind_init(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 const char *path,
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
373 const char *href,
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 WebdavPList **outplist)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
376 PgWebdavBackend *pgdav = rq->dav->instance;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
377
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
378 // check if the resource exists
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
379 int64_t parent_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
380 int64_t resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
381 const char *resourcename;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
382 WSBool iscollection;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
383 int res_errno = 0;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
384 int err = pg_resolve_path(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
385 pgdav->connection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
386 path,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
387 &parent_id,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
388 &resource_id,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
389 NULL, // OID
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
390 &resourcename,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
391 &iscollection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
392 NULL, // stat
346
784b24381bed extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
393 NULL, // etag
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
394 &res_errno);
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 if(err) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
397 if(res_errno == ENOENT) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
398 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
399 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
400 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
401 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
402
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
403 // choose sql query
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
404 const char *query = NULL;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
405 if(!iscollection || rq->depth == 0) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
406 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
407 } else if(rq->depth == 1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
408 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
409 } else if(rq->depth == -1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
410 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
411 } else {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
412 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
413 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
414 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
415
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
416 // get all resources and properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
417 char resource_id_str[32];
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
418 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
419
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
420 size_t href_len = strlen(href);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
421 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
422 memcpy(href_param, href, href_len);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
423 if(href_param[href_len-1] == '/') {
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
424 href_len--;
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
425 }
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
426 href_param[href_len] = '\0';
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
427
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
428 // 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
429 UcxBuffer *xmlns_buf = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
430 UcxBuffer *pname_buf = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
431 char *xmlns_param = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
432 char *pname_param = NULL;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
433 int nparam = 2;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
434 if(!rq->allprop) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
435 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
436 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
437 if(!xmlns_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
438 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
439 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
440 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
441 if(!pname_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
442 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
443 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
444 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
445 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
446 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
447 ucx_buffer_free(pname_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
448 return 1;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
449 }
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
450 xmlns_param = xmlns_buf->space;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
451 pname_param = pname_buf->space;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
452 nparam = 4;
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
453 }
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
454
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
455 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
456 PGresult *result = PQexecParams(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
457 pgdav->connection,
315
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
458 query,
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
459 nparam, // number of parameters
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
460 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
461 params, // parameter value
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
462 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
463 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
464 0); // 0: result in text format
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
465 int nrows = PQntuples(result);
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
466 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
467 if(xmlns_buf) {
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
468 ucx_buffer_free(xmlns_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
469 ucx_buffer_free(pname_buf);
b608b7aa43a6 fix sql query for selecting specific properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
470 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
471 if(nrows < 1) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
472 PQclear(result);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
473 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
474 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
475
300
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
476 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
477 rq->userdata = pg;
0e3f275b2492 add instance field to webdav backend struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
478
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
479 pg->path = path;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
480 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
481 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
482 pg->result = result;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
483 pg->nrows = nrows;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
484
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
485 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 int pg_dav_propfind_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489 WebdavPropfindRequest *rq,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 WebdavResponse *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 VFS_DIR parent,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 WebdavResource *resource,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 struct stat *s)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
495 PgPropfind *pg = rq->userdata;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
496 pool_handle_t *pool = rq->sn->pool;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
497 PGresult *result = pg->result;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
498 WebdavVFSProperties vfsprops = pg->vfsproperties;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
499
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
500 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
501 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
502 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
503 // columns:
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
504 // 0: path
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
505 // 1: resource_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
506 // 2: parent_id
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
507 // 3: nodename
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
508 // 4: iscollection
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
509 // 5: lastmodified
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
510 // 6: creationdate
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
511 // 7: contentlength
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
512 // 8: etag
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
513 // 9: property prefix
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
514 // 10: property xmlns
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
515 // 11: property name
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
516 // 12: property lang
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
517 // 13: property nsdeflist
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
518 // 14: property value
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
519
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
520 char *path = PQgetvalue(result, r, 0);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
521 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
522 char *iscollection_str = PQgetvalue(result, r, 4);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
523 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
524 int64_t resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
525 if(!util_strtoint(res_id, &resource_id)) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
526 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
527 return 1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
528 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
529
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
530 if(resource_id != current_resource_id) {
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
531 // 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
532 // 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
533 size_t pathlen = strlen(path);
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
534 if(pathlen == 0) {
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
535 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
536 return 1;
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
537 }
356
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
538 if(pathlen > PG_MAX_PATH_LEN) {
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
539 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
540 return 1;
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
541 }
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
542 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
543 util_uri_escape(newres_href, path);
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
544 if(iscollection && path[pathlen-1] != '/') {
356
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
545 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
546 newres_href[newres_href_len] = '/';
eebc3d32c7c1 escape child href in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 348
diff changeset
547 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
548 }
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
549
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
550 // new resource
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
551 resource = response->addresource(response, newres_href);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
552 vfsprops_set = FALSE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
553 current_resource_id = resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
554 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
555
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
556 // standard webdav live properties
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
557 if(!vfsprops_set) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
558 if(vfsprops.getresourcetype) {
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
559 if(iscollection) {
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
560 resource->addproperty(resource, webdav_resourcetype_collection(), 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
561 } else {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
562 resource->addproperty(resource, webdav_resourcetype_empty(), 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
563 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
564 }
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
565
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
566 char *lastmodified = PQgetvalue(result, r, 5);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
567 char *contentlength = PQgetvalue(result, r, 7);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
568 time_t t = pg_convert_timestamp(lastmodified);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
569
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
570 if(vfsprops.getlastmodified) {
311
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
571 struct tm tm;
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
572 gmtime_r(&t, &tm);
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
573
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
574 char buf[HTTP_DATE_LEN+1];
e676ed461b5b implement pg getlastmodified propfind (and prepare creationdate)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 309
diff changeset
575 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
576 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
577 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
578 if(vfsprops.creationdate) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
579 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
580 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
581 }
314
6b1a6066ee43 fix pg propfind for getlastmodified property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 313
diff changeset
582 if(vfsprops.getcontentlength && !iscollection) {
309
fc021bd576d4 implement pg getcontentlength property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
583 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
584 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
585 if(vfsprops.getetag) {
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
586 char *etag = PQgetvalue(result, r, 8);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
587 if(!PQgetisnull(result, r, 8)) {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
588 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
589 } else {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
590 int64_t ctlen;
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
591 if(util_strtoint(contentlength, &ctlen)) {
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
592 char etag[MAX_ETAG];
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
593 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
594 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
595 }
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
596 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
597 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
598
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
599 vfsprops_set = TRUE;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
600 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
601
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
602 // dead properties
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
603 if(!PQgetisnull(result, r, 9)) {
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
604 char *prefix = PQgetvalue(result, r, 9);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
605 char *xmlns = PQgetvalue(result, r, 10);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
606 char *pname = PQgetvalue(result, r, 11);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
607 char *lang = PQgetvalue(result, r, 12);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
608 char *nsdef = PQgetvalue(result, r, 13);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
609 char *pvalue = PQgetvalue(result, r, 14);
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
610
348
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
611 int pvalue_len = PQgetlength(result, r, 14);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
612 WSBool lang_isnull = PQgetisnull(result, r, 12);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
613 WSBool nsdef_isnull = PQgetisnull(result, r, 13);
bdd31584141f implement etag in pg propfind
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 346
diff changeset
614 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
615
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
616 WebdavProperty *property = pool_malloc(pool, sizeof(WebdavProperty));
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
617 property->lang = NULL;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
618 property->name = pool_strdup(pool, pname);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
619
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
620 xmlNs *namespace = pool_malloc(pool, sizeof(xmlNs));
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
621 memset(namespace, 0, sizeof(struct _xmlNs));
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
622 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
623 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
624 property->namespace = namespace;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
625
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
626 if(!lang_isnull) {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
627 property->lang = pool_strdup(pool, lang);
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
628 }
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
629
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
630 if(!pvalue_isnull) {
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
631 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
632 memcpy(content, pvalue, pvalue_len);
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
633 content[pvalue_len] = '\0';
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
634
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
635 if(nsdef_isnull) {
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
636 property->vtype = WS_VALUE_TEXT;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
637 property->value.text.str = content;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
638 property->value.text.length = pvalue_len;
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
639 } else {
324
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
640 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
641 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
642 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
643 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
644 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
645
317
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
646 }
09676b559091 store property prefix in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 315
diff changeset
647 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
648
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
649 resource->addproperty(resource, property, 200);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
650 }
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 312
diff changeset
651 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
652
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
653 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
654 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
655
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
656 int pg_dav_propfind_finish(WebdavPropfindRequest *rq) {
312
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
657 PgPropfind *pg = rq->userdata;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
658 pool_handle_t *pool = rq->sn->pool;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
659 PGresult *result = pg->result;
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
660
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
661 PQclear(result);
f7544e220a0f add pg propfind cleanup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 311
diff changeset
662
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 303
diff changeset
663 return 0;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
664 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
665
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
666 enum PgDavProp {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
667 PG_DAV_PROPPATCH_NOT_ALLOWED = 0,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
668 PG_DAV_CREATIONDATE,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
669 PG_DAV_DISPLAYNAME,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
670 PG_DAV_DEADPROP
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
671 };
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
672 /*
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
673 * checks if the property can be manipulated
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
674 */
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
675 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
676 if(!strcmp(name, "getlastmodified")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
677 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
678 } else if(!strcmp(name, "getcontentlength")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
679 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
680 } else if(!strcmp(name, "resourcetype")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
681 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
682 } else if(!strcmp(name, "getetag")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
683 return PG_DAV_PROPPATCH_NOT_ALLOWED;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
684 } else if(!strcmp(name, "creationdate")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
685 return PG_DAV_CREATIONDATE;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
686 } else if(!strcmp(name, "displayname")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
687 return PG_DAV_DISPLAYNAME;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
688 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
689 return PG_DAV_DEADPROP;
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
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
692 typedef struct {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
693 WebdavProperty *creationdate;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
694 WebdavProperty *displayname;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
695 int error;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
696 } PgProppatchOpResult;
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 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
699
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 * This function iterates the property list 'plist',
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
702 * 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
703 * and calls opfunc for the each property
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
704 *
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
705 * 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
706 * 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
707 */
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
708 static PgProppatchOpResult pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
709 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
710 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
711 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
712 WebdavPList **plist,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
713 enum PgDavProp forbidden_extra,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
714 pg_proppatch_func opfunc,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
715 void *op_userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
716 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
717 PgProppatchOpResult result;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
718 result.creationdate = NULL;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
719 result.displayname = NULL;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
720 result.error = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
721
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
722 WebdavPListIterator i = webdav_plist_iterator(plist);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
723 WebdavPList *cur;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
724 while(webdav_plist_iterator_next(&i, &cur)) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
725 WebdavProperty *property = cur->property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
726 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
727 if(!ns) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
728 continue; // maybe we should abort
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
729 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
730
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
731 // 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
732 // handling
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
733 // get* properties can't be manipulated
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
734 // some properties can't be removed
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
735 if(!strcmp((const char*)ns->href, "DAV:")) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
736 const char *name = property->name;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
737 enum PgDavProp davprop = proppatch_check_dav_prop(name);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
738 if(davprop != PG_DAV_DEADPROP) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
739 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
740 response->addproperty(response, property, 409);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
741 } else if(davprop == PG_DAV_CREATIONDATE) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
742 result.creationdate = property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
743 } else if(davprop == PG_DAV_DISPLAYNAME) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
744 result.displayname = property;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
745 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
746 webdav_plist_iterator_remove_current(&i);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
747 continue;
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
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
751 // call op func (set, remove specific code)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
752 if(opfunc(pgdav, request, response, property, op_userdata)) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
753 result.error = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
754 break;
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
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
757 webdav_plist_iterator_remove_current(&i);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
758 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
759
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
760 return result;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
761 }
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 static int pg_dav_set_property(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
764 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
765 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
766 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
767 WebdavProperty *property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
768 void *userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
769 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
770 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
771 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
772 char *resource_id_str = userdata;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
773 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
774
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
775 // convert the property value to WSXmlData
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
776 // 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
777 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
778 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
779 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
780 if(property_value) {
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
781 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
782 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
783 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
784 if(!nsdef_str) {
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
785 return 1; // OOM
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
786 }
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
787 }
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
788 }
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
789
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
790 // exec sql
324
44cf877b3d9f add support for xml properties in propfind/proppatch requests (pg)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
791 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
792 PGresult *result = PQexecParams(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
793 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
794 sql_proppatch_set,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
795 7, // number of parameters
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
796 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
797 params, // parameter value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
798 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
799 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
800 0); // 0: result in text format
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
801
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
802 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
803 response->addproperty(response, property, 500);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
804 //printf(PQerrorMessage(pgdav->connection));
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
805 //fflush(stdout);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
806 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
807 } else {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
808 response->addproperty(response, property, 200);
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 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
811 if(value_str) pool_free(pool, value_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
812
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
813 return ret;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
814 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
815
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 static int pg_dav_remove_property(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
818 PgWebdavBackend *pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
819 WebdavProppatchRequest *request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
820 WebdavResource *response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
821 WebdavProperty *property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
822 void *userdata)
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
823 {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
824 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
825 WSNamespace *ns = property->namespace;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
826 char *resource_id_str = userdata;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
827 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
828
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
829 // exec sql
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
830 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
831 PGresult *result = PQexecParams(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
832 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
833 sql_proppatch_remove,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
834 3, // number of parameters
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
835 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
836 params, // parameter value
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
837 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
838 NULL,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
839 0); // 0: result in text format
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
840
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
841 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
842 response->addproperty(response, property, 500);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
843 //printf(PQerrorMessage(pgdav->connection));
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
844 //fflush(stdout);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
845 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
846 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
847 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
848
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
849 return ret;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
850 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
851
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
852 int pg_dav_proppatch_do(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
853 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
854 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
855 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
856 WebdavPList **out_set,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
857 WebdavPList **out_remove)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
858 {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
859 PgWebdavBackend *pgdav = request->dav->instance;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
860 pool_handle_t *pool = request->sn->pool;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
861 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
862
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
863 // 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
864 int64_t parent_id;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
865 int64_t resource_id;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
866 const char *resourcename;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
867 WSBool iscollection;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
868 int res_errno = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
869 int err = pg_resolve_path(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
870 pgdav->connection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
871 path,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
872 &parent_id,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
873 &resource_id,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
874 NULL, // OID
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
875 &resourcename,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
876 &iscollection,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
877 NULL, // stat
346
784b24381bed extend postgresql vfs to store an etag in the file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
878 NULL, // etag
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
879 &res_errno);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
880
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
881 if(err) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
882 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
883 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
884
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
885 // 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
886 // 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
887 // we need the possibility to reverse all changes
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
888 // we use a transaction savepoint for this
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
889 PGresult *result = PQexec(pgdav->connection, "savepoint proppatch;");
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
890 ExecStatusType execStatus = PQresultStatus(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
891 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
892 if(execStatus != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
893 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
894 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
895
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
896 char resource_id_str[32];
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
897 snprintf(resource_id_str, 32, "%" PRId64, resource_id);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
898
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
899 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
900 PgProppatchOpResult set_res = pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
901 pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
902 request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
903 response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
904 out_set,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
905 PG_DAV_PROPPATCH_NOT_ALLOWED,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
906 pg_dav_set_property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
907 resource_id_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
908 if(set_res.error) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
909 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
910 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
911 PgProppatchOpResult rm_res = pg_proppatch_op(
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
912 pgdav,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
913 request,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
914 response,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
915 out_remove,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
916 PG_DAV_CREATIONDATE, // creationdate can't be removed
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
917 pg_dav_remove_property,
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
918 resource_id_str);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
919 if(rm_res.error) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
920 return 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
921 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
922
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
923 return ret;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
924 }
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
925
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
926 int pg_dav_proppatch_finish(
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
927 WebdavProppatchRequest *request,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
928 WebdavResource *response,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
929 VFSFile *file,
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
930 WSBool commit)
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
931 {
318
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
932 PgWebdavBackend *pgdav = request->dav->instance;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
933 int ret = 0;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
934 if(!commit) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
935 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
936 if(PQresultStatus(result) != PGRES_COMMAND_OK) {
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
937 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
938 ret = 1;
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
939 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
940 PQclear(result);
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
941 }
60870dbac94f add basic pg proppatch implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 317
diff changeset
942 return ret;
299
f927ef81a12b add empty pg webdav funcs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
943 }

mercurial