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