src/server/plugins/postgresql/webdav.c

Sat, 14 May 2022 15:22:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 14 May 2022 15:22:37 +0200
branch
webdav
changeset 360
79ddd772e807
parent 356
eebc3d32c7c1
child 366
47bc686fafe4
permissions
-rw-r--r--

check if service SAFs sent a response, terminate connection in case no response was sent

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

mercurial